23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

our lives. And is that not how you want your customers to feel about your apps? Absolutely! Knowing<br />

the delight that a well-architected app can bring to your customers, let’s dive in and find our own<br />

delight in exploring the intricacies!<br />

Local and Web Contexts within the App Host<br />

As described in Chapter 1, “The Life Story of a Windows Store App,” apps written with <strong>HTML</strong>, <strong>CSS</strong>, and<br />

JavaScript are not directly executable like their compiled counterparts written in C#, Visual Basic, or<br />

C++. In our app packages, there are no EXEs, just .html, .css, and .js files (plus resources, of course) that<br />

are, plain and simple, nothing but text. So something has to turn all this text that defines an app into<br />

something that’s actually running in memory. That something is again the app host, wwahost.exe, which<br />

creates what we call the hosted environment for Store apps.<br />

Let’s review what we’ve already learned in Chapter 1 and Chapter 2, “Quickstart,” about the<br />

characteristics of the hosted environment:<br />

• The app host (and the apps in it) use brokered access to sensitive resources.<br />

• Though the app host provides an environment very similar to that of Internet Explorer 10, there<br />

are a number of changes to the DOM API, documented on <strong>HTML</strong> and DOM API changes list and<br />

<strong>HTML</strong>, <strong>CSS</strong>, and JavaScript features and differences. A related topic is Windows Store apps using<br />

JavaScript versus traditional web apps.<br />

• <strong>HTML</strong> content in the app package can be loaded into the local or web context, depending on the<br />

ms-appx:/// and ms-appx-web:/// scheme used to reference that content (the third / again<br />

means “in the app package”). Remote content (referred to with http[s]://) always runs in the<br />

web context.<br />

• The local context has access to the WinRT API, among other things, whereas the web context is<br />

allowed to load and execute remote script but cannot access WinRT.<br />

• ActiveX control plug-ins are generally not allowed in either context.<br />

• The <strong>HTML</strong>5 postMessage function can be used to communicate between an iframe and its<br />

containing parent across contexts. This can be useful to execute remote script within the web<br />

context and pass the results to the local context; script acquired in the web context should not<br />

be itself passed to the local context and executed there. (Windows Store policy actually disallows<br />

this, and apps submitted to the Store will be analyzed for such practices.)<br />

• Further specifics can be found on Features and restrictions by context, including which parts of<br />

WinJS don’t rely on WinRT and can thus be used in the web context. (WinJS, by the way, cannot<br />

be used on web pages outside of an app.)<br />

Now what we’re really after in this chapter is not so much these characteristics themselves but their<br />

impact on the structure of an app. (To explore the characteristics themselves, refer to the Integrating<br />

86

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!