Tải bản đầy đủ - 0 (trang)
Chapter 3. Working with JavaScript and HTML Within Adobe AIR

Chapter 3. Working with JavaScript and HTML Within Adobe AIR

Tải bản đầy đủ - 0trang

W3CDOMLevel2support

Essentially,AdobeAIRhasafullHTMLrenderingengine,and

includessupportforallofthesametechnologiesthatcanbe

usedwhendevelopingwebapplicationsandcontenttargeting

thewebbrowser.Developerscanbuildfull-featuredAIR

applicationsthatleveragethesetechnologies.



NOTE

YoucanfindmoreinformationontheWebKitprojectat:

http://www.webkit.org.



3.1.1.WhyWebKit?

Adobespentaconsiderableamountoftimeresearchingwhich

HTMLenginetousewithinAdobeAIRandusedanumberof

criteriathatultimatelyledthemtosettleonWebKit.



3.1.1.1.Openproject

Adobeknewfromtheverybeginningthatitdidnotwantto

createandmaintainitsownHTMLrenderingengine.Notonly

wouldthisbeanimmenseamountofwork,butitwouldalso

makeitdifficultfordevelopers,whowouldthenhavetobecome

familiarwithallofthequirksofyetanotherHTMLengine.

WebKitprovidesAdobeAIRwithafull-featuredHTMLengine

thatisundercontinuousdevelopmentbyarobustdevelopment

communitythatincludesindividualdevelopersaswellaslarge

companiessuchasNokiaandApple.ThisallowsAdobetofocus

onbugfixesandfeatures,andalsomeansthatAdobecan

activelycontributebacktoWebKit,whilealsotakingadvantage

ofthecontributionsmadebyothermembersoftheWebKit

community.



3.1.1.2.Proventechnologythatwebdevelopers

know



Asdiscussedearlier,oneofthebiggestproblemswithcomplex

webapplicationdevelopmentisensuringthatcontentworks

consistentlyacrossbrowsers.Whilesomethingmaywork

perfectlyinFirefoxontheMac,itmaycompletelyfailin

InternetExploreronWindows.Becauseofthis,testingand

debuggingbrowser-basedcontentcanbeanightmarefor

developers.

Adobewantedtoensurethatdeveloperswerealreadyfamiliar

withtheHTMLengineusedwithinAdobeAIRsotheydidnot

havetolearnallofthequirksandbugsofanewengine.Since

Safari(whichisbuiltontopofWebKit)isthedefaultbrowser

forMacOSX(andisalsoavailableonWindows),developers

shouldbefamiliarwithdevelopingforWebKit.



3.1.1.3.MinimumeffectonAIRruntimesize

ThesizeofAdobeAIRisapproximately11MBonWindowsand

approximately16MBonMAC.TheWebKitcodebasewaswell

writtenandorganizedandhashadaminimalimpactonthe

finalAIRruntimesize.



3.1.1.4.Provenabilitytorunonmobiledevices

WhilethefirstreleaseofAdobeAIRrunsonlyonpersonal

computers,thelong-termvisionistoextendAdobeAIRfrom

thedesktoptocellphonesandotherdevices.WebKithasa

provenabilitytorunonsuchdevicesandhasbeenportedto

cellphonesbybothNokiaandApple.



3.1.2.WebKitversionusedwithinAdobeAIR

TheversionofWebKitincludedinAdobeAIR1.0isbasedoff

theWebKitmainlineversion523.15.

Somechangeswereappliedtothisversioninordertosupport

AIR'sownrenderingpipelineandenforcesomesecurity

restrictions(pleasechecktheSection3.3"andthe"Security"

subchapterstofindmoredetailsaboutthedifferences).



TheUserAgentreportedwhenrunninginAdobeAIRin

Windowsis:

Mozilla/5.0(Windows;U;en)AppleWebKit/420+(KHTML,

likeGecko)AdobeAIR/1.0

andonMac:

Mozilla/5.0(Macintosh;U;IntelMacOSX;en)

AppleWebKit/420+(KHTML,likeGecko)AdobeAIR/1.0

Overall,developersshouldexpectcoderunninginSafari3to

alsoworkinAdobeAIR,withtheexceptionsofthedifferences

discussedinthischapter.



Chapter3.WorkingwithJavaScriptand

HTMLWithinAdobeAIR

ThischapterprovidesanoverviewoftheHTMLandJavaScript

environmentswithinAdobeAIR.Itdiscusses:

TheuseoftheopensourceWebKitHTML-renderingengine

withinAdobeAIR

JavaScriptfunctionalitywithinAdobeAIR

SecurityModel

WorkingwithAdobeAIR,FlashPlayerandActionScriptAPIs

fromJavaScript

TroubleshootingAIRApplicationswrittenwithHTMLand

JavaScript

Onceyouhavecompletedthischapter,youshouldhaveasolid

understandingoftheHTMLandJavaScriptenvironmentswithin

AdobeAIR.YoushouldalsounderstandhowtoworkwithAIR

andActionScriptAPIswithinHTMLandJavaScript-based

applications.



3.1.WebKitWithinAdobeAIR

AdobeAIRleveragestheopensourceWebKit-renderingengine

toaddsupportforrenderingHTMLcontenttotheruntime.

InadditiontoHTMLrendering,WebKitalsoprovidessupportfor

associatedwebtechnologies,suchas(butnotlimitedto):

JavaScript

XMLHttpRequest

CSS

XHTML



W3CDOMLevel2support

Essentially,AdobeAIRhasafullHTMLrenderingengine,and

includessupportforallofthesametechnologiesthatcanbe

usedwhendevelopingwebapplicationsandcontenttargeting

thewebbrowser.Developerscanbuildfull-featuredAIR

applicationsthatleveragethesetechnologies.



NOTE

YoucanfindmoreinformationontheWebKitprojectat:

http://www.webkit.org.



3.1.1.WhyWebKit?

Adobespentaconsiderableamountoftimeresearchingwhich

HTMLenginetousewithinAdobeAIRandusedanumberof

criteriathatultimatelyledthemtosettleonWebKit.



3.1.1.1.Openproject

Adobeknewfromtheverybeginningthatitdidnotwantto

createandmaintainitsownHTMLrenderingengine.Notonly

wouldthisbeanimmenseamountofwork,butitwouldalso

makeitdifficultfordevelopers,whowouldthenhavetobecome

familiarwithallofthequirksofyetanotherHTMLengine.

WebKitprovidesAdobeAIRwithafull-featuredHTMLengine

thatisundercontinuousdevelopmentbyarobustdevelopment

communitythatincludesindividualdevelopersaswellaslarge

companiessuchasNokiaandApple.ThisallowsAdobetofocus

onbugfixesandfeatures,andalsomeansthatAdobecan

activelycontributebacktoWebKit,whilealsotakingadvantage

ofthecontributionsmadebyothermembersoftheWebKit

community.



3.1.1.2.Proventechnologythatwebdevelopers

know



Asdiscussedearlier,oneofthebiggestproblemswithcomplex

webapplicationdevelopmentisensuringthatcontentworks

consistentlyacrossbrowsers.Whilesomethingmaywork

perfectlyinFirefoxontheMac,itmaycompletelyfailin

InternetExploreronWindows.Becauseofthis,testingand

debuggingbrowser-basedcontentcanbeanightmarefor

developers.

Adobewantedtoensurethatdeveloperswerealreadyfamiliar

withtheHTMLengineusedwithinAdobeAIRsotheydidnot

havetolearnallofthequirksandbugsofanewengine.Since

Safari(whichisbuiltontopofWebKit)isthedefaultbrowser

forMacOSX(andisalsoavailableonWindows),developers

shouldbefamiliarwithdevelopingforWebKit.



3.1.1.3.MinimumeffectonAIRruntimesize

ThesizeofAdobeAIRisapproximately11MBonWindowsand

approximately16MBonMAC.TheWebKitcodebasewaswell

writtenandorganizedandhashadaminimalimpactonthe

finalAIRruntimesize.



3.1.1.4.Provenabilitytorunonmobiledevices

WhilethefirstreleaseofAdobeAIRrunsonlyonpersonal

computers,thelong-termvisionistoextendAdobeAIRfrom

thedesktoptocellphonesandotherdevices.WebKithasa

provenabilitytorunonsuchdevicesandhasbeenportedto

cellphonesbybothNokiaandApple.



3.1.2.WebKitversionusedwithinAdobeAIR

TheversionofWebKitincludedinAdobeAIR1.0isbasedoff

theWebKitmainlineversion523.15.

Somechangeswereappliedtothisversioninordertosupport

AIR'sownrenderingpipelineandenforcesomesecurity

restrictions(pleasechecktheSection3.3"andthe"Security"

subchapterstofindmoredetailsaboutthedifferences).



TheUserAgentreportedwhenrunninginAdobeAIRin

Windowsis:

Mozilla/5.0(Windows;U;en)AppleWebKit/420+(KHTML,

likeGecko)AdobeAIR/1.0

andonMac:

Mozilla/5.0(Macintosh;U;IntelMacOSX;en)

AppleWebKit/420+(KHTML,likeGecko)AdobeAIR/1.0

Overall,developersshouldexpectcoderunninginSafari3to

alsoworkinAdobeAIR,withtheexceptionsofthedifferences

discussedinthischapter.



3.2.JavaScriptwithinAdobeAIR

AdobeAIRhasfullsupportforJavaScriptwithinHTMLcontent.

JavaScript1.5,whichcorrespondstoECMA-262issupported.

TheJavaScriptengineisimplementedviaWebKit,andworks

thesameasitdoeswithinWebKit-basedbrowsers.Inaddition

tohavingaccesstotheHTMLDOM,JavaScriptcanalsoaccess

AIRandFlashPlayerAPIsdirectlyviathewindow.runtime

property.Thiswillbediscussedinmoredetaillater.



NOTE

Foranin-depthintroductionanddiscussionof

JavaScript,checkoutJavaScript:theDefinitiveGuide:

5thEdition,publishedbyO'Reilly:

http://www.oreilly.com/catalog/jscript5/



3.3.AIRImplementationofFunctionality

HTMLandJavaScriptfunctionalityisconsistentwiththatfound

inotherWebKit-basedprojectsandbrowsers,suchasApple's

Safaribrowser.WhenexploringdocumentationonHTMLengine

/browserfunctionality,youcanusereferencestotheSafari3

browserasanindicatorofthefunctionalityavailablewithinthe

HTMLenvironmentwithinAIR.

However,becausetheHTMLengineisrunningwithinAdobe

AIR,andnotabrowser,thereareafewdifferencesthatare

usefultounderstandbeforebeginningdevelopmentwithHTML

andJavaScriptwithinAdobeAIR.



3.3.1.URISchemes

WorkingwithUniversalResourceIdentifiers(URIs)withinHTML

contentinAIRapplicationsislargelythesameasworkingwith

URIswithinthebrowser.Thissectiongivesaquickoverviewof

workingwithURIswithinHTMLcontentinAIRapplications,and

introducessomenewURIsmadeavailablebytheruntime.



3.3.1.1.SupportedURIschemes

AdobeAIRprovidessupportforthemostcommonURIschemes

availablewithinthebrowser

Table3-1.SupportedURIschemes

Scheme Description



Example



http://



http://www.adobe.com



URIthatpointstoa

resourceaccessed

viathestandard

HTTPprotocol.



https:// URIthatpointstoa

resourceaccessed

viaaprotocol

encryptedwith



https://secure.example.com



SSL/TLS.

file://



URIthatpointstoa file:///c:/Test/test.txt

resourceonthelocal

oranetworkedfile

system.



mailto:



URIthatopensthe

defaultemail

application.



mailto:john.doe@example.com



3.3.1.2.UnsupportedURIschemes

Thefeed://anddata://URIschemesarenotsupportedby

AdobeAIR1.0,andthereisonlypartialsupportfortheftp://

scheme.

Finally,thejavascript:URIschemeisnotsupportedwithin

applicationsrunningwithintheAdobeAIRapplicationsandbox.

PleasechecktheSecuritymodelsectionlateristhischapterfor

moredetails.



3.3.1.3.AIRURISchemes

AdobeAIRalsoprovidesanumberofadditionalURIsthat

makesiteasytoreferencefilesandcontentwithinspecific

areasoftheuserssystem.

Table3-2.AdobeAIRURIschemes

URI



Description



Example



app:/



Providesareferenceto

therootcontent

directoryofthe

application.Thisshould

beusedwhen

referencingcontent

includedwithintheAIR

file.



app:/images



appProvidesareferenceto

appstorage:/ anapplication-specific

storage:/settings/pref.xml

storageareaonthe

user'ssystem.Thisarea

isusefulforstoringuserspecificapplication

settingsandcontent.



NOTE

TheAIR-specificURIstakeonlyasingleslash,versus

twoslashesintheotherURIs.

WithinHTMLcontent,theseURIschemescanbeusedanywhere

withinHTMLandJavaScriptcontentwhereregularHTTPURIs

areused.



3.3.2.RelativeURLs

You'renotrestrictedtousingjustabsoluteURLswithinAIR

applications.YoucanalsouserelativeURLs,butitisimportant

torememberthatrelativeURLswithinAIRapplicationsare

relativetotheapplication,andnottoaserver(astheywould

bewhendoingtraditionalbrowser-basedclient/server

development).

RelativeURLswillberelativetotherootoftheapplication,and

willresolvetotheapp:/URI.

Forexample:





willresolveto:



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 3. Working with JavaScript and HTML Within Adobe AIR

Tải bản đầy đủ ngay(0 tr)

×