WebKitDisplayWebContentWord文档下载推荐.docx
《WebKitDisplayWebContentWord文档下载推荐.docx》由会员分享,可在线阅读,更多相关《WebKitDisplayWebContentWord文档下载推荐.docx(58页珍藏版)》请在冰豆网上搜索。
withrespecttoanyofthetechnologydescribed
inthisdocument.Appleretainsallintellectualpropertyrightsassociatedwiththetechnologydescribedinthisdocument.ThisdocumentisintendedtoassistapplicationdeveloperstodevelopapplicationsonlyforApple-labeledcomputers.
1InfiniteLoop
Cupertino,CA95014
408-996-1010
Apple,theApplelogo,Carbon,Cocoa,Mac,MacOS,Objective-C,Pages,QuickTime,Safari,andXcodearetrademarksofAppleInc.,registeredintheUnitedStatesandothercountries.
WebScriptisatrademarkofAppleInc.
JavaisaregisteredtrademarkofOracleand/oritsaffiliates.
EventhoughApplehasreviewedthisdocument,APPLEMAKESNOWARRANTYORREPRESENTATION,EITHEREXPRESSORIMPLIED,WITHRESPECTTOTHISDOCUMENT,ITSQUALITY,ACCURACY,MERCHANTABILITY,ORFITNESSFORAPARTICULARPURPOSE.ASARESULT,THISDOCUMENTISPROVIDED“ASIS,”ANDYOU,THEREADER,AREASSUMINGTHEENTIRERISKASTOITSQUALITYANDACCURACY.
INNOEVENTWILLAPPLEBELIABLEFORDIRECT,INDIRECT,SPECIAL,INCIDENTAL,ORCONSEQUENTIALDAMAGESRESULTINGFROMANYDEFECTORINACCURACYINTHISDOCUMENT,evenifadvisedofthepossibilityofsuchdamages.
THEWARRANTYANDREMEDIESSETFORTHABOVEAREEXCLUSIVEANDINLIEUOFALLOTHERS,ORALORWRITTEN,EXPRESSORIMPLIED.NoAppledealer,agent,oremployeeisauthorizedtomakeanymodification,extension,oradditiontothiswarranty.
Somestatesdonotallowtheexclusionorlimitationofimpliedwarrantiesorliabilityforincidentalorconsequentialdamages,sotheabovelimitationorexclusionmaynotapplytoyou.Thiswarrantygivesyouspecificlegalrights,andyoumayalsohaveotherrightswhichvaryfromstatetostate.
Contents
IntroductiontoWebKitObjective-CProgrammingGuide9
WhatIstheWebKit?
9
WhoShouldReadThisDocument?
OrganizationofThisDocument10
SeeAlso11
WhyUsetheWebKit?
13
CoreWebKitClasses15
FrameModelandViewClasses15
DataModelandViewClasses16
Provisionalvs.CommittedDataSources17
WebViewDelegates18
SimpleBrowsing21
MultipleWindows23
OpeningWindows23
EnteringURLs23
HandlingNewWindowRequests24
LoadingPages27
SequenceofFrameLoadDelegateMessages27
TestingfortheMainFrame28
DisplayingtheCurrentURL28
DisplayingthePageTitle28
DisplayingLoadStatus29
LoadingResources31
SequenceofResourceLoadDelegateMessages31
IdentifyingResources31
TrackingResourceLoadProgress32
PagingBackandForward35
EnablingandDisablingtheBack-ForwardList35
AddingBackandForwardButtons35
3
2009-07-28|©
2003,2009AppleInc.AllRightsReserved.
SettingthePageCache35
SettingtheCapacity36
TheCurrentItem36
ManagingState36
ManagingHistory37
SharingHistoryObjects37
AddingandRemovingHistoryItems37
LoadingaHistoryItem38
SavingandLoadingHistoryObjects38
MakingPolicyDecisions39
EnablingEditing41
SavingandLoadingWebContent43
ModifyingtheCurrentSelection45
ChangingEditingBehavior47
ShouldMethods47
DidMethods47
UsingUndoWhenEditing49
UsingtheDocumentObjectModelfromObjective-C51
InterpretingtheDOMSpecification51
HandlingExceptions53
UsingtheDocumentObjectModelExtensions55
UsingJavaScriptFromObjective-C57
Spoofing59
AccessingtheWebKitFromCarbonApplications61
DeterminingWebKitAvailability63
TestingforURLLoadingSystemAvailability63
4
TestingforWebKitAvailability63
IsolatingYourWebKitandURLLoadingSystemSymbols64
ConditionallyLoadingCode64
WeakLinkingSymbols64
DocumentRevisionHistory67
5
6
FiguresandListings
Figure1WebViewandWebFrameViewobjects16
Figure2WebFrameandWebDataSourceobjects17
Figure3Typicalwebsite18
Listing1DeterminingiftheURLLoadingsystemisavailable.63
Listing2DeterminingiftheWebKitframeworkisavailable63
Listing3LoadingWebKitconstantsdynamicallyusingCFBundle65
7
8
IntroductiontoWebKitObjective-CProgrammingGuide
ConcurrencyNote:
TheWebKitframeworkisnotthreadsafe.Ifyoucallfunctionsormethodsinthisframework,youmustdosoexclusivelyonthemainprogramthread.
TheWebKitprovidesasetofcoreclassestodisplaywebcontentinwindows,andbydefault,implementsfeaturessuchasfollowinglinksclickedbytheuser.TheWebKitgreatlysimplifiesthecomplicatedprocess
ofloadingwebpages—thatis,asynchronouslyrequestingwebcontentfromanHTTPserveroverthenetworkwheretheresponsemayarriveincrementally,inrandomorder,orpartiallyduetonetworkerrors.TheWebKitalsosimplifiestheprocessofdisplayingcontentthatcancontainvariousMIMEtypes,andmultipleframeseachwiththeirownsetofscrollbars.
YouusetheWebKittodisplaywebcontentinawindowofyourapplication.It’sassimpleascreatingaview,placingitinawindow,andsendingaURLloadrequestmessage.Bydefault,yourWebKitapplicationbehavesasyouwouldexpectwithouterror.TheWebKitconvenientlycreatesandmanagesalltheviewsneededtohandledifferentMIMEtypes.Whentheuserclicksonalinkinapage,theWebKitautomaticallycreatestheviewsneededtodisplaythenextpage.
However,theWebKitdoesn’timplementacompletesetofwebbrowserfeatures.Youcan,however,extendtheWebKitbyimplementingcustomdelegate,view,andmodelobjects.Forexample,youcanimplementadelegatetodisplayloadstatus,andthecurrentURL.
TheWebKitalsoofferswebcontentediting.IfyouenableeditinginyourWebView,userscaneditthewebcontentitdisplays.YoucanprogrammaticallycontrolthecurrentselectionandcontroleditingbehaviorusingaWebViewdelegate.YoucanalsomodifytheDocumentObjectModeldirectlyusinganObjective-CAPI.
YoucanalsoaccessJavaScriptfromObjective-Candviceversa.
TheWebKitObjective-CAPIisspecificallydesignedforembeddingwebcontentinyourCocoaorCarbonapplications—developingwebclientapplicationsnotwebserverapplicationsorwebcontent.Itisalsonotsuitableforimplementingnon-GUIapplicationssuchaswebcrawlers.IfyouareawebcontentcreatororJavaScriptprogrammer,refertoWebKitDOMProgrammingTopics.
9
Important:
Currently,thisAPIisavailableinObjective-Conly.AminimalCAPIisprovidedforembeddingwebbrowserviewsinCarbonapplications.YoucanuseObjective-CincombinationwithC.TheWebKitworkswithallversionsofMacOSX10.2thathaveSafari1.0installed.
OrganizationofThisDocument
ThefollowingarticlescoverkeyconceptsinunderstandinghowtheWebKitworks:
●“WhyUsetheWebKit?
”(page13)describesthepurposeoftheWebKitandwhyyoumightwanttouseitinyourapplications.
●“CoreWebKitClasses”(page15)describesthecoreWebKitclassesandtheobject-orienteddesignthatisfundamentaltounderstandinghowtheWebKitworks.
Thefollowingarticlesexplainhowtodisplaywebcontentinviews:
●“SimpleBrowsing”(page21)showshowtoembedwebcontentinyourapplicationbyfollowingafewsimplesteps.
●“MultipleWindows”(page23)showshowtoaddsupportformultiplewindows,andopenwindowsautomatically.
●“LoadingPages”(page27)showshowtotracktheprogressofloadingframecontent.
●“LoadingResources”(page31)showshowtotracktheprogressofloadingindividualresourcesonapage.
●“PagingBackandForward”(page35)showshowtoimplementaback-forwardlistandaddBackand
Forwardbuttonstoyourapplication.
●“ManagingHistory”(page37)showshowtomaintainahistoryofallthevisitedpages,andallowtheusertogotoapreviouslyvisitedpage.
●“Spoofing”(page59)showshowtouseuser-agentstrings.
●“AccessingtheWebKitFromCarbonApplications”(page61)explainshowtoembedwebcontentin
Carbonapplications.
●“DeterminingWebKitAvailability”(page63)explainshowtodetermineiftheWebKitisavailableonyoursystem.
Thefollowingarticlesexplainhowtoimplementwebcontentediting:
●“EnablingEditing”(page41)showshowtoenableusereditinginaWebView.
●“SavingandLoadingWebContent”(page43)showshowtosaveandloadwebcontenteditedbytheuser.
●“ModifyingtheCurrentSelection”(page45)showshowtoprogrammaticallymodifyth