discovery-api/Overview.src.html
author Rich Tibbett <richt@opera.com>
Mon, 12 Aug 2013 16:20:17 +1000
changeset 440 fcbaadc4fd54
parent 438 d66ca00fe7d9
child 441 b4b2569b4e9b
permissions -rw-r--r--
Fix [DAP-ISSUE-135]: Add security and privacy considerations section [Network Service Discovery]
     1 <!DOCTYPE html>
     2 <!--
     3 
     4   THIS IS THE WORKING VERSION OF THE CURRENT SPECIFICATION!
     5 
     6   This specification is built using ReSpec.js <http://dev.w3.org/2009/dap/ReSpec.js/documentation.html>
     7 
     8   From time to time it's necessary to HTML5 Tidy this document using the tool @ <http://w3c.github.com/tidy-html5/>.
     9 
    10   The command used to format this document (Overview.src.html) is as follows (replacing all = signs with - signs!):
    11 
    12   @> tidy ==new-blocklevel-tags section ==char-encoding utf8 ==tidy-mark no ==indent yes ==indent-spaces 2 ==indent-attributes yes ==wrap 120 ==fix-bad-comments yes -m Overview.src.html
    13 
    14   To publish a new compiled version (Overview.html), we need to open this file (Overview.src.html) in any web browser.
    15   Once it has loaded we press 'Ctrl + Shift + S' (or 'Cmd' + 'Shift' + 'S' on Mac) and then select
    16   'Save as HTML (Source)' from the resulting menu.
    17 
    18   We then replace Overview.html with the produced HTML source of this process.
    19 
    20   Next we run HTML5 Tidy over our new Overview.html file with the following command (replacing all = signs with - signs!):
    21 
    22   @> tidy ==new-blocklevel-tags section ==char-encoding utf8 ==tidy-mark no ==indent yes ==indent-spaces 2 ==indent-attributes yes ==wrap 120 ==hide-comments yes -m Overview.html
    23 
    24   Now the specification is ready to be published :)
    25 
    26 -->
    27 <html>
    28   <head>
    29     <title>
    30       Network Service Discovery
    31     </title>
    32     <meta http-equiv='Content-Type'
    33           content='text/html; charset=utf-8'>
    34     <script type="text/javascript"
    35           class='remove'>
    36 var respecConfig = {
    37           specStatus:   "ED",
    38           //publishDate:  "2013-03-29",
    39           shortName:    "discovery-api",
    40           edDraftURI:   "http://dvcs.w3.org/hg/dap/raw-file/tip/discovery-api/Overview.html",
    41           previousMaturity: "FPWD",
    42           previousPublishDate: "2012-10-04",
    43           editors: [
    44             {
    45               name:       "Rich Tibbett",
    46               //url:        "http://richt.me/",
    47               company:    "Opera Software ASA",
    48               companyURL: "http://opera.com/"
    49             }
    50           ],
    51 
    52           wg:           "Device APIs Working Group",
    53           wgURI:        "http://www.w3.org/2009/dap/",
    54           wgPublicList: "public-device-apis",
    55           wgPatentURI:  "http://www.w3.org/2004/01/pp-impl/43696/status",
    56 
    57     //          extraCSS:     ["http://dvcs.w3.org/hg/dap/raw-file/tip/discovery-api/css/respec.nsd.css"],
    58     //          inlineCSS:    true,
    59           noIDLIn:      true
    60 
    61       };
    62     </script>
    63     <script src='http://www.w3.org/Tools/respec/respec-w3c-common'
    64           type="text/javascript"
    65           class='remove'
    66           async="">
    67 </script>
    68     <style>
    69 /* Custom ReSpec CSS (by Rich Tibbett) */
    70 
    71      /* Add better spacing to sections */
    72      section, .section { margin-bottom: 2em; }
    73 
    74      /* Reduce note & issue render size */
    75      .note, .issue { font-size:0.8em; }
    76 
    77      /* Add addition spacing to <ol> and <ul> for rule definition */
    78      ol.rule li, ul.rule li { padding:0.6em; }
    79 
    80      pre.widl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; position: relative; }
    81      pre.widl :link, pre.widl :visited { color: #000; background: transparent; }
    82      pre.widl:before { content: "IDL"; font: bold small sans-serif; padding: 0.5em; background: white; position: absolute; top: 0; margin: -1px 0 0 -4em; width: 1.5em; border: thin solid; border-radius: 0 0 0 0.5em }
    83 
    84      div.example { border: solid thin black; background: #FFFFF0; color: black; padding: 0.5em 1em; position: relative; margin: 1em 0 1em 4.6em; width: auto; }
    85      div.example:before { content: "EXAMPLE"; font: bold small sans-serif; padding: 0.5em; background: white; color: black; position: absolute; top: 0; margin: -1px 0 0 -7.6em; width: 5em; border: thin solid black; border-radius: 0 0 0 0.5em }
    86 
    87      dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #DDFFDD; }
    88      hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
    89      dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
    90      dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
    91      dl.domintro dd p { margin: 0.5em 0; }
    92      dl.domintro code {font-size: inherit; font-style: italic; }
    93      dl.domintro:before { display: table; margin: -1em -0.5em 0.5em auto; width: auto; content: 'This box is non-normative. Implementation requirements are given below this box.'; color: red; border: solid 2px; background: white; padding: 0 0.25em; font-size:0.8em; }
    94 
    95      table { border-collapse:collapse; border-style:hidden hidden none hidden }
    96      table thead { border-bottom:solid }
    97      table tbody th:first-child { border-left:solid }
    98      table td, table th { border-left:solid; border-right:solid; border-bottom:solid thin; vertical-align:top; padding:0.2em }
    99     </style>
   100     <script type="text/javascript"
   101           class="remove">
   102 // RESPEC DEFINITIONS STYLE OVERLOAD
   103         window.addEventListener('load', function() {
   104           var overrideStyleEl = document.createElement('style');
   105           overrideStyleEl.textContent += "\n  a.externalDFN { color: #00C; border-bottom: 1px dashed #00C; }";
   106           overrideStyleEl.textContent += "\n  a.internalDFN { color: #00C; text-decoration: solid; }";
   107           document.querySelector('body').appendChild(overrideStyleEl);
   108         }, false);
   109     </script>
   110   </head>
   111   <body>
   112     <section id='abstract'>
   113       <p>
   114         This specification defines a mechanism for an HTML document to discover and subsequently communicate with
   115         <abbr title="Hypertext Transfer Protocol">HTTP</abbr>-based services advertised via common discovery protocols
   116         within the current network.
   117       </p>
   118     </section>
   119     <section id='sotd'>
   120       <p>
   121         This document represents the early consensus of the group on the scope and features of the proposed API.
   122       </p>
   123     </section>
   124     <section class="informative">
   125       <h3>
   126         Introduction
   127       </h3>
   128       <p>
   129         To enable Web pages to connect and communicate with Local-networked Services provided over HTTP, this
   130         specification introduces the <a href="#navigatornetworkservice"><code>NavigatorNetworkService</code></a>
   131         interface.
   132       </p>
   133       <p>
   134         Using this <abbr title="Application Programming Interface">API</abbr> consists of requesting a well-known
   135         service type, known by developers and advertised by Local-networked Devices. User authorization, where the user
   136         connects the web page to discovered services, is expected before the web page is able to interact with any
   137         Local-networked Services.
   138       </p>
   139       <p>
   140         A web page creates a request to obtain connectivity to services running in the network by specifying a
   141         well-known discovery service type that it wishes to interact with.
   142       </p>
   143       <p>
   144         The user agent, having captured all advertised services on the network from the <a>service discovery
   145         mechanisms</a> included in this recommendation, attempts to match the requested service type to a discovered
   146         service according to the processing described herein.
   147       </p>
   148       <p>
   149         If a service connectivity request is successful then the Web page is provided with a promise-based success
   150         callback with the all necessary information to communicate with the authorized Local-networked Service. If the
   151         request fails then the Web page will receive a promise-based error callback containing an error code describing
   152         the cause of Local-networked Service connectivity failure.
   153       </p>
   154       <p>
   155         Once connected to a Local-networked Service the Web page can send requests and receive responses to the
   156         Local-networked Service via the messaging format and appropriate channel inferred from the service type
   157         authorized via the provided API. The Web page, once connected, can also receive service-pushed events, in the
   158         messaging format supported by the Local-networked Device, if such event subscription functionality is provided
   159         by the connected Local-networked Service.
   160       </p>
   161       <p>
   162         Services available within the local network can connect and disconnect at different times during the execution
   163         of a web page. The user agent can inform a web page when the state of networked services matching any of the
   164         requested valid service types change. Web pages can use this information to enable in-page experiences for
   165         communicating the state of networked services with the ability to change the particular service or set of
   166         services the page is connected to (by re-invoking the <a href=
   167         "#dom-navigator-getnetworkservices"><code>getNetworkServices()</code></a> method defined herein).
   168       </p>
   169       <div class="example">
   170         <p>
   171           Example of requesting a DNS-SD advertised service:
   172         </p>
   173         <hr>
   174         <pre class="highlight">
   175 function showServices( services ) {
   176   // Show a list of all the services provided to the web page
   177   for(var i = 0, l = services.length; i &lt; l; i++) console.log( services[i].name );
   178 }
   179 
   180 navigator.getNetworkServices('zeroconf:_boxee-jsonrpc._tcp').then(showServices);
   181 </pre>
   182       </div>
   183       <div class="example">
   184         <p>
   185           Example of requesting a UPnP advertised service, also handling error conditions:
   186         </p>
   187         <hr>
   188         <pre class="highlight">
   189 function showServices( services ) {
   190   // Show a list of all the services provided to the web page
   191   for(var i = 0, l = services.length; i &lt; l; i++) console.log( services[i].name );
   192 }
   193 
   194 function error( e ) {
   195   console.log( "Error occurred: " + e.code );
   196 }
   197 
   198 navigator.getNetworkServices('upnp:urn:schemas-upnp-org:service:ContentDirectory:1').then(showServices, error);
   199 </pre>
   200       </div>
   201       <div class="example">
   202         <p>
   203           Example of requesting either a DNS-SD or UPnP advertised service:
   204         </p>
   205         <hr>
   206         <pre class="highlight">
   207 function showServices( services ) {
   208   // Show a list of all the services provided to the web page (+ service type)
   209   for(var i = 0, l = services.length; i &lt; l; i++)
   210      console.log( services[i].name + '(' + services[i].type + ')' );
   211 }
   212 
   213 navigator.getNetworkServices([
   214   'zeroconf:_boxee-jsonrpc._tcp',
   215   'upnp:urn:schemas-upnp-org:service:ContentDirectory:1'
   216 ]).then(showServices);
   217 </pre>
   218       </div>
   219       <p>
   220         For more detailed examples, including examples of communicating with obtained networked services, see the
   221         <a href="#examples">Examples</a> section.
   222       </p>
   223     </section>
   224     <section id='conformance'>
   225       <p>
   226         Requirements phrased in the imperative as part of algorithms (such as "strip any leading space characters" or
   227         "return false and abort these steps") are to be interpreted with the meaning of the key word ("must", "should",
   228         "may", etc) used in introducing the algorithm.
   229       </p>
   230       <p>
   231         Some conformance requirements are phrased as requirements on attributes, methods or objects. Such requirements
   232         are to be interpreted as requirements on user agents.
   233       </p>
   234       <p>
   235         Conformance requirements phrased as algorithms or specific steps MAY be implemented in any manner, so long as
   236         the end result is equivalent. (In particular, the algorithms defined in this specification are intended to be
   237         easy to follow, and not intended to be performant.)
   238       </p>
   239       <p>
   240         The only conformance class defined by this specification is a <dfn>user agent</dfn>.
   241       </p>
   242       <p>
   243         User agents MAY impose implementation-specific limits on otherwise unconstrained inputs, e.g. to prevent denial
   244         of service attacks, to guard against running out of memory, or to work around platform-specific limitations.
   245       </p>
   246       <p>
   247         When support for a feature is disabled (e.g. as an emergency measure to mitigate a security problem, or to aid
   248         in development, or for performance reasons), user agents MUST act as if they had no support for the feature
   249         whatsoever, and as if the feature was not mentioned in this specification. For example, if a particular feature
   250         is accessed via an attribute in a Web IDL interface, the attribute itself would be omitted from the objects
   251         that implement that interface - leaving the attribute on the object but making it return null or throw an
   252         exception is insufficient.
   253       </p>
   254       <section>
   255         <h3>
   256           Dependencies
   257         </h3>This specification relies on several other underlying specifications.
   258         <dl>
   259           <dt>
   260             HTML
   261           </dt>
   262           <dd>
   263             Many fundamental concepts from HTML are used by this specification. [[!HTML5]]
   264           </dd>
   265           <dt>
   266             WebIDL
   267           </dt>
   268           <dd>
   269             The IDL blocks in this specification use the semantics of the WebIDL specification. [[!WEBIDL]]
   270           </dd>
   271         </dl>
   272       </section>
   273     </section>
   274     <section>
   275       <h3>
   276         Terminology
   277       </h3>
   278       <p>
   279         The construction "a <code>Foo</code> object", where <code>Foo</code> is actually an interface, is sometimes
   280         used instead of the more accurate "an object implementing the interface <code>Foo</code>".
   281       </p>
   282       <p>
   283         The term DOM is used to refer to the API set made available to scripts in Web applications, and does not
   284         necessarily imply the existence of an actual <code>Document</code> object or of any other <code>Node</code>
   285         objects as defined in the DOM Core specifications. [[!DOM4]]
   286       </p>
   287       <p>
   288         An IDL attribute is said to be <em>getting</em> when its value is being retrieved (e.g. by author script), and
   289         is said to be <em>setting</em> when a new value is assigned to it.
   290       </p>
   291       <p>
   292         A <dfn>valid service type</dfn> is any of the following:
   293       </p>
   294       <ul>
   295         <li>a string that begins with <code>upnp:</code> or <code>zeroconf:</code> followed by one or more characters
   296         in the ranges U+0021, U+0023 to U+0027, U+002A to U+002B, U+002D to U+002E, U+0030 to U+0039, U+0041 to U+005A,
   297         U+005E to U+007E.
   298         </li>
   299         <li>a string that begins with <code>dial:</code> followed by an integer version.
   300         </li>
   301       </ul>
   302       <p>
   303         A <a>valid service type</a> provided in the <code>type</code> attribute of the <a href=
   304         "#dom-navigator-getnetworkservices"><code>getNetworkServices()</code></a> method will be matched against the
   305         services currently contained in the <a>list of available service records</a> according to the algorithms
   306         defined in this specification.
   307       </p>
   308       <p>
   309         A <dfn>user-agent generated callback url</dfn> is a Local-network accessible URL endpoint that a <a>user
   310         agent</a> generates and maintains for receiving HTTP NOTIFY requests from UPnP Event sources. It is only
   311         required when the user agent implements UPnP Service Discovery as defined in this specification.
   312       </p>
   313       <p>
   314         In this specification we use the following terms to describe the processes required for Local-networked
   315         Services management:
   316       </p>
   317       <ul>
   318         <li>A <dfn>new service</dfn> is a Local-networked Service that has not previously been discovered or registered
   319         in the <a>list of available service records</a>.
   320         </li>
   321         <li>An <dfn>existing service</dfn> is a Local-networked Service that has previously been discovered and is
   322         registered in the <a>list of available service records</a>.
   323         </li>
   324         <li>A <dfn>current service</dfn> is a Local-networked Service, represented by a <a href=
   325         "#networkservice"><code>NetworkService</code></a> object, that is currently being shared with a web page via a
   326         <a href="#networkservices"><code>NetworkServices</code></a> object registered in the <a>list of active service
   327         managers</a>.
   328         </li>
   329       </ul>
   330     </section>
   331     <section>
   332       <h2>
   333         Security and privacy considerations
   334       </h2>
   335       <p>
   336         The API defined in this specification can be used to find and connect to devices and services within a user's
   337         current network. This discloses information related to a user's network: devices available on their network and
   338         the publicly-accessible services ("networked services") currently running and available on those devices. The
   339         distribution of this information could potentially compromise the user's privacy. A conforming implementation
   340         of this specification MUST provide a mechanism that protects the user's privacy. This mechanism MUST ensure
   341         that no networked service information is retrievable without the user's express permission.
   342       </p>
   343       <section>
   344         <h3>
   345           Privacy considerations for API implementations
   346         </h3>
   347         <p>
   348           A <a>user agent</a> MUST NOT provide networked service information to web sites without the express
   349           permission of the user. A user agent MUST acquire permission through a user interface, unless they have
   350           prearranged trust relationships with users, as described below. The user interface MUST include the document
   351           base URL. Those permissions that are acquired through the user interface and that are preserved beyond the
   352           current browsing session (i.e. beyond the time when the browsing context is navigated to another URL) MUST be
   353           revocable and a user agent MUST respect revoked permissions.
   354         </p>
   355         <p>
   356           Obtaining the user's express permission to access one API method does not imply the user has granted
   357           permission for the same web site to access any other methods that may be provided by this API, or to access
   358           the same method with a different set of arguments, as part of the same permission context. If a user has
   359           expressed permission for an implementation to, e.g. find a set of existing networked services, the
   360           implementation MUST seek the user's express permission if and when any subsequent functions are called on
   361           this API.
   362         </p>
   363         <p>
   364           A user agent MAY have prearranged trust relationships that do not require such user interfaces. For example,
   365           while a web browser will present a user interface when a web site performs a networked service lookup, a
   366           different runtime may have a prearranged, delegated security relationship with the user and, as such, a
   367           suitable alternative security and privacy mechanism with which to authorise the retrieval of networked
   368           service information.
   369         </p>
   370       </section>
   371       <section class="informative">
   372         <h3>
   373           Additional API implementation considerations
   374         </h3>
   375         <p>
   376           Further to the requirements listed in the previous section, implementors of the Network Service Discovery API
   377           are also advised to consider the following aspects that can negatively affect the privacy of their users: in
   378           certain cases, users can inadvertently grant permission to the user agent to disclose networked services to
   379           Web sites. In other cases, the content hosted at a certain URL changes in such a way that previously granted
   380           networked service permissions no longer apply as far as the user is concerned. Or the users might simply
   381           change their minds.
   382         </p>
   383         <p>
   384           Predicting or preventing these situations is inherently difficult. Mitigation and in-depth defensive measures
   385           are an implementation responsibility and not prescribed by this specification. However, in designing these
   386           measures, implementers are advised to enable user awareness of networked service sharing, and to provide easy
   387           access to interfaces that enable revocation of permissions that web applications have for accessing networked
   388           services via this API.
   389         </p>
   390       </section>
   391     </section>
   392     <section>
   393       <h2>
   394         Requesting networked services
   395       </h2>
   396       <pre class="widl">
   397 [Supplemental, NoInterfaceObject]
   398 interface <dfn id="navigatornetworkservice">NavigatorNetworkService</dfn> {
   399   <a class="externalDFN"
   400      href="http://dom.spec.whatwg.org/#promise">Promise</a> <a href=
   401      "#dom-navigator-getnetworkservices">getNetworkServices</a>( in any type );
   402 };
   403 <a class="externalDFN"
   404      href=
   405      "http://www.whatwg.org/specs/web-apps/current-work/complete/timers.html#navigator">Navigator</a> implements <a href=
   406      "#navigatornetworkservice">NavigatorNetworkService</a>;
   407 
   408 [NoInterfaceObject]
   409 interface <dfn id="navigatornetworkserviceerror">NavigatorNetworkServiceError</dfn> {
   410   const unsigned short <a href="#dom-navigatornetworkserviceerror-permission_denied">PERMISSION_DENIED_ERR</a> = 1;
   411   const unsigned short <a href="#dom-navigatornetworkserviceerror-unknown_type_prefix">UNKNOWN_TYPE_PREFIX_ERR</a> = 2;
   412   readonly attribute unsigned short <a href="#dom-navigatornetworkserviceerror-code">code</a>;
   413 };
   414 </pre>
   415       <section>
   416         <h2>
   417           Methods
   418         </h2>
   419         <dl class="domintro">
   420           <dt>
   421             <var title="">promise</var> = <var title="">window</var> . <code title="dom-navigator"><a href=
   422             "http://www.whatwg.org/specs/web-apps/current-work/complete/timers.html#navigator">navigator</a></code> .
   423             <code title="dom-navigator-getNetworkServices"><a href=
   424             "#dom-navigator-getnetworkservices">getNetworkServices</a></code> ( <var title="">type</var> )
   425           </dt>
   426           <dd>
   427             <p>
   428               Immediately returns a new <a href="http://dom.spec.whatwg.org/#promise"
   429                  class="externalDFN">Promise</a> object and then the user is prompted to select discovered network
   430                  services that have advertised support for the requested service type(s).
   431             </p>
   432             <p>
   433               The <var title="">type</var> argument contains one or more <a>valid service type</a> tokens that the web
   434               page would like to interact with.
   435             </p>
   436             <p>
   437               If the user accepts, the <var title="">promise</var> object is <a class="externalDFN"
   438                  href="http://dom.spec.whatwg.org/#concept-resolver-resolve">resolved</a>, with a <a href=
   439                  "#networkservices"><code>NetworkServices</code></a> object as its argument.
   440             </p>
   441             <p>
   442               If the user declines, or an error occurs, the <var title="">promise</var> object is <a class=
   443               "externalDFN"
   444                  href="http://dom.spec.whatwg.org/#concept-resolver-reject">rejected</a>.
   445             </p>
   446           </dd>
   447         </dl>
   448         <div>
   449           <p>
   450             When the <dfn id="dom-navigator-getnetworkservices"
   451                title="dom-navigator-getnetworkservices"><code>getNetworkServices(type)</code></dfn> method is called,
   452                the <a>user agent</a> MUST run the following steps:
   453           </p>
   454           <ol class="rule">
   455             <li>Let <var>Network Service Promise</var> be a new <a href="http://dom.spec.whatwg.org/#promise"
   456                   class="externalDFN"><code>Promise</code></a> object.
   457             </li>
   458             <li>Let <var>Network Service Promise's Resolver</var> be the default <a href=
   459             "http://dom.spec.whatwg.org/#concept-resolver"
   460                   class="externalDFN">resolver</a> of <var>Network Service Promise</var>.
   461             </li>
   462             <li>Return <var>Network Service Promise</var>, and run the remaining steps asynchronously.
   463             </li>
   464             <li>Let <var>requested control types</var> be initially set to an empty array.
   465             </li>
   466             <li>If <var>type</var> is an array consisting of one or more <a>valid service type</a> tokens, then let
   467             <var>requested control types</var> by the value of <var>type</var>, removing any non-<a>valid service
   468             type</a> tokens from the resulting array.
   469             </li>
   470             <li>If <var>type</var> is a string consisting of one <a>valid service type</a> token, then let
   471             <var>requested control types</var> be an array containing one item with a value of <var>type</var>.
   472             </li>
   473             <li>If <var>requested control types</var> is an array that contains at least one or more <a title=
   474             "valid service type">valid service type</a> tokens then continue to the step labeled <em>process</em>
   475             below. Otherwise, reject <var>Network Service Promise</var> by running the <a href=
   476             "http://dom.spec.whatwg.org/#concept-resolver-reject"
   477                   class="externalDFN">resolver reject algorithm</a> against the <var>Network Service Promise's
   478                   Resolver</var>, passing in a new <a href=
   479                   "#navigatornetworkserviceerror"><code>NavigatorNetworkServiceError</code></a> object whose <a href=
   480                   "#dom-navigatornetworkserviceerror-code"><code>code</code></a> attribute has the numeric value 2
   481                   (<a href=
   482                   "#dom-navigatornetworkserviceerror-unknown_type_prefix"><code>UNKNOWN_TYPE_PREFIX_ERR</code></a>) as
   483                   its argument, abort any remaining steps and return.
   484             </li>
   485             <li>
   486               <em>Process</em>: Let <var>services found</var> be an empty array.
   487             </li>
   488             <li>For each <var>available service</var> in the <a>list of available service records</a> run the following
   489             steps:
   490               <ol class="rule">
   491                 <li>For each <var>requested control type</var> in <var>requested control types</var>: If <var>available
   492                 service</var>'s <code>type</code> attribute equals the <var>requested control type</var> then let <var>
   493                   matched service</var> equal the value of <var>available service</var> and continue at the step
   494                   labeled <var>attach</var> below.
   495                 </li>
   496                 <li>Continue at the next <var>available service</var>.
   497                 </li>
   498                 <li>
   499                   <em>Attach</em>: If <var>matched service</var> is not empty then run the following steps:
   500                   <ol class="rule">
   501                     <li>Let <var>new service object</var> be a new <a href=
   502                     "#networkservice"><code>NetworkService</code></a> object, mapping the parameters of <var>matched
   503                     service</var> to this new object where possible.
   504                     </li>
   505                     <li>Append <var>new service object</var> to the <var>services found</var> array.
   506                     </li>
   507                   </ol>
   508                 </li>
   509               </ol>
   510             </li>
   511             <li>Optionally, e.g. based on a previously-established user preference, for security reasons, or due to
   512             platform limitations, the <a>user agent</a> MAY reject <var>Network Service Promise</var> by running the
   513             <a href="http://dom.spec.whatwg.org/#concept-resolver-reject"
   514                   class="externalDFN">resolver reject algorithm</a> against the <var>Network Service Promise's
   515                   Resolver</var>, passing in a new <a href=
   516                   "#navigatornetworkserviceerror"><code>NavigatorNetworkServiceError</code></a> object whose <a href=
   517                   "#dom-navigatornetworkserviceerror-code"><code>code</code></a> attribute has the numeric value 1
   518                   (<a href=
   519                   "#dom-navigatornetworkserviceerror-permission_denied"><code>PERMISSION_DENIED_ERR</code></a>) as its
   520                   argument, abort any remaining steps and return.
   521             </li>
   522             <li>The user agent MUST NOT provide the entry script's origin with a <a href=
   523             "#networkservices"><code>NetworkServices</code></a> object without prior permission given by the user.
   524               <p>
   525                 If <var>services found</var> is not an empty array then the <a>user agent</a> MAY choose to prompt the
   526                 user in a user-agent-specific manner for permission to provide the <a href=
   527                 "http://www.whatwg.org/specs/web-apps/current-work/complete/browsers.html#entry-script"
   528                    class="externalDFN">entry script</a>'s <a href=
   529                    "http://www.whatwg.org/specs/web-apps/current-work/complete/origin-0.html#origin"
   530                    class="externalDFN">origin</a> with a <a href="#networkservices"><code>NetworkServices</code></a>
   531                    object representing the <a>user-authorized</a> subset of <var>services found</var>.
   532               </p>
   533               <p>
   534                 Alternatively, the user agent MAY wish to skip this user opt-in step and choose to fulfill <var>Network
   535                 Service Promise</var> immediately based on a previously-established user preference, for security
   536                 reasons, or due to platform limitations. In such an implementation, if <var>Network Service
   537                 Promise</var> is to be fulfilled as a result of a previously-established user preference then the
   538                 <a>user agent</a> MUST continue at the next step of this algorithm.
   539               </p>
   540               <p>
   541                 If permission has been granted by the user to access one or more networked services then the <a>user
   542                 agent</a> SHOULD include an "ongoing local-network communication" indicator.
   543               </p>
   544               <p>
   545                 If permission has been denied by the user, <a>user agent</a> or platform, then the <a>user agent</a>
   546                 MUST reject <var>Network Service Promise</var> by running the <a href=
   547                 "http://dom.spec.whatwg.org/#concept-resolver-reject"
   548                    class="externalDFN">resolver reject algorithm</a> against the <var>Network Service Promise's
   549                    Resolver</var>, passing in a new <a href=
   550                    "#navigatornetworkserviceerror"><code>NavigatorNetworkServiceError</code></a> object whose <a href=
   551                    "#dom-navigatornetworkserviceerror-code"><code>code</code></a> attribute has the numeric value 1
   552                    (<a href=
   553                    "#dom-navigatornetworkserviceerror-permission_denied"><code>PERMISSION_DENIED_ERR</code></a>) as its
   554                    argument, abort any remaining steps and return.
   555               </p>
   556               <p>
   557                 If the user never responds or no previously-established user preference has been met, this algorithm
   558                 stalls on this step.
   559               </p>
   560             </li>
   561             <li>Let <var>services</var> be an empty array.
   562             </li>
   563             <li>If <var>services found</var> is not an empty array then set <var>services</var> to be an array of one
   564             or more <a href="#networkservice"><code>NetworkService</code></a> objects for which the user granted
   565             permission above - known as the current objects <dfn>user-authorized</dfn> services.
   566             </li>
   567             <li>Remove all previously whitelisted urls from the <a>entry script origin's URL whitelist</a> granted in
   568             the current <a href="http://www.whatwg.org/specs/web-apps/current-work/complete/browsers.html#entry-script"
   569                   class="externalDFN">entry script</a>'s <a href=
   570                   "http://www.whatwg.org/specs/web-apps/current-work/complete/origin-0.html#origin"
   571                   class="externalDFN">origin</a>.
   572             </li>
   573             <li>For each Object <var>service</var> in <var>services</var>, if any, run the following sub-steps:
   574               <ol class="rule">
   575                 <li>Add the <var>service</var>'s <code>url</code> parameter to the <a>entry script origin's
   576                   <abbr title="Uniform Resource Locator">URL</abbr> whitelist</a>.
   577                 </li>
   578                 <li>If <var>service</var>'s <code>type</code> parameter begins with the DOMString "<code>upnp:</code>"
   579                 and the <var>service</var>'s <code>eventsUrl</code> parameter is not empty then <a>setup a UPnP Events
   580                 Subscription</a> for <var>service</var>.
   581                 </li>
   582               </ol>
   583             </li>
   584             <li>Let <var>services manager</var> be a new <a href="#networkservices"><code>NetworkServices</code></a>
   585             object.
   586             </li>
   587             <li>Store <var>requested control types</var> against <var>services manager</var> as an internal variable.
   588             </li>
   589             <li>Set <var>services manager</var>'s <a href=
   590             "#dom-networkservices-servicesavailable"><code>servicesAvailable</code></a> attribute to the number of
   591             items currently found in the <a>list of available service records</a> whose <code>type</code> property
   592             matches any of the tokens requested in <var>requested control types</var>.
   593             </li>
   594             <li>Add <var>services</var>, if any, to the <var>services manager</var> object as its collection of
   595             <a>indexed properties</a>. If <var>services</var> is an empty array then the <var>services manager</var>
   596             does not have any <var>indexed properties</var>.
   597             </li>
   598             <li>Set <var>services manager</var>'s <a href="#dom-networkservices-length"><code>length</code></a>
   599             attribute to the number of items in <var>services</var>.
   600             </li>
   601             <li>Add <var>services manager</var> to the <a>list of active service managers</a>.
   602             </li>
   603             <li>The <a>user agent</a> MUST fulfill <var>Network Service Promise</var> by running the <a href=
   604             "http://dom.spec.whatwg.org/#concept-resolver-fulfill"
   605                   class="externalDFN">resolver fulfill algorithm</a> against the <var>Network Service Promise's
   606                   Resolver</var>, passing in <var>services manager</var> as its argument.
   607             </li>
   608           </ol>
   609           <p>
   610             The <a href="http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#task-source"
   611                class="externalDFN">task source</a> for these <a href=
   612                "http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#concept-task"
   613                class="externalDFN">tasks</a> is the <a href=
   614                "http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#user-interaction-task-source"
   615                class="externalDFN">user interaction task source</a>.
   616           </p>
   617           <p>
   618             When a <a href="#networkservice"><code>NetworkService</code></a> object is provided to a Web page, the
   619             <a>user agent</a> MUST add the <code>url</code> property to the <dfn>entry script origin's URL
   620             whitelist</dfn>. This list enables the Web page to override and initiate cross-site resource requests
   621             towards these URLs, and any sub-resources of these URLs, within the current <a href=
   622             "http://www.whatwg.org/specs/web-apps/current-work/complete/browsers.html#entry-script"
   623                class="externalDFN">entry script</a>'s <a href=
   624                "http://www.whatwg.org/specs/web-apps/current-work/complete/origin-0.html#origin"
   625                class="externalDFN">origin</a> via various existing mechanisms (e.g. Web Sockets, Server-Sent Events,
   626                Web Messaging, XMLHttpRequest).
   627           </p>
   628           <p>
   629             If the user navigates away from the <a href=
   630             "http://www.whatwg.org/specs/web-apps/current-work/complete/browsers.html#entry-script"
   631                class="externalDFN">entry script</a>'s <a href=
   632                "http://www.whatwg.org/specs/web-apps/current-work/complete/origin-0.html#origin"
   633                class="externalDFN">origin</a> then the <a>user agent</a> <em class="ct">MUST</em> remove all previously
   634                whitelisted urls from the <a>entry script origin's URL whitelist</a>. There is no persistence to network
   635                service selections provided to a web page. It is not possible to access a previously white-listed
   636                networked service without the necessary user authorization in all of the following cases:
   637           </p>
   638           <ul>
   639             <li>If the current script is reloaded at any point in the same or different window.
   640             </li>
   641             <li>if the current script reinvokes the <a href=
   642             "#dom-navigator-getnetworkservices"><code>getNetworkServices()</code></a> method at any point in its
   643             execution.
   644             </li>
   645             <li>If the user navigates forward or back in their history to reload the current page.
   646             </li>
   647             <li>If a script is running in a different origin.
   648             </li>
   649           </ul>
   650         </div>
   651       </section>
   652       <section>
   653         <h3>
   654           Error Handling
   655         </h3>
   656         <dl class="domintro">
   657           <dt>
   658             <var title="">error</var> . <code title="dom-NavigatorNetworkServiceError-code"><a href=
   659             "#dom-navigatornetworkserviceerror-code">code</a></code>
   660           </dt>
   661           <dd>
   662             <p>
   663               Returns the current error's error code. At the current time, this will be <code>1</code> or
   664               <code>2</code>, for which the corresponding error constants <a href=
   665               "#dom-navigatornetworkserviceerror-permission_denied"><code>PERMISSION_DENIED_ERR</code></a> and <a href=
   666               "#dom-navigatornetworkserviceerror-unknown_type_prefix"><code>UNKNOWN_TYPE_PREFIX_ERR</code></a> are
   667               defined.
   668             </p>
   669           </dd>
   670         </dl>
   671         <p>
   672           The <dfn id="dom-navigatornetworkserviceerror-code"
   673              title="dom-navigatornetworkserviceerror-code"><code>code</code></dfn> attribute of a <a href=
   674              "#navigatornetworkserviceerror"><code>NavigatorNetworkServiceError</code></a> object <em class=
   675              "ct">MUST</em> return the code for the error, which will be one of the following:
   676         </p>
   677         <dl>
   678           <dt>
   679             <dfn id="dom-navigatornetworkserviceerror-permission_denied"
   680                 title="dom-navigatornetworkserviceerror-permission_denied"><code>PERMISSION_DENIED_ERR</code></dfn>
   681                 (numeric value 1)
   682           </dt>
   683           <dd>
   684             The user or user agent denied the page permission to access any services.
   685           </dd>
   686           <dt>
   687             <dfn id="dom-navigatornetworkserviceerror-unknown_type_prefix"
   688                 title="dom-navigatornetworkserviceerror-unknown_type_prefix"><code>UNKNOWN_TYPE_PREFIX_ERR</code></dfn>
   689                 (numeric value 2)
   690           </dt>
   691           <dd>
   692             No <a>valid service type</a> tokens were provided in the method invocation.
   693           </dd>
   694         </dl>
   695       </section>
   696     </section>
   697     <section>
   698       <h2>
   699         Obtaining networked services
   700       </h2>
   701       <p>
   702         The <a href="#networkservices"><code>NetworkServices</code></a> interface represents a collection of zero or
   703         more <dfn>indexed properties</dfn> that are each a <a>user-authorized</a> <a href=
   704         "#networkservice"><code>NetworkService</code></a> object.
   705       </p>
   706       <p>
   707         A <a href="#networkservices"><code>NetworkServices</code></a> object is the <a href=
   708         "http://dom.spec.whatwg.org/#concept-promise-result"
   709            class="externalDFN">promise result</a> from a call to <a href=
   710            "#dom-navigator-getnetworkservices"><code>getNetworkServices()</code></a>.
   711       </p>
   712       <pre class="widl">
   713 [NoInterfaceObject]
   714 interface <dfn id="networkservices">NetworkServices</dfn> {
   715   readonly attribute unsigned long    <a href="#dom-networkservices-length">length</a>;
   716   getter <a href="#networkservice">NetworkService</a> (unsigned long index);
   717   <a href="#networkservice">NetworkService</a>? <a href=
   718 "#dom-networkservices-getservicebyid">getServiceById</a>(DOMString id);
   719 
   720   readonly attribute unsigned long    <a href="#dom-networkservices-servicesavailable">servicesAvailable</a>;
   721 
   722   // event handler attributes
   723            attribute <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#eventhandler"
   724      class="externalDFN">EventHandler</a>     <a href="#dom-networkservices-onserviceavailable">onserviceavailable</a>;
   725            attribute <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#eventhandler"
   726      class="externalDFN">EventHandler</a>     <a href=
   727      "#dom-networkservices-onserviceunavailable">onserviceunavailable</a>;
   728 
   729 };
   730 
   731 <a href="#networkservices">NetworkServices</a> implements <a href=
   732 "http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-eventtarget"
   733      class="externalDFN">EventTarget</a>;
   734 </pre>
   735       <section>
   736         <h2>
   737           Attributes
   738         </h2>
   739         <dl class="domintro">
   740           <dt>
   741             <code title="dom-networkservices-length"><a href="#dom-networkservices-length">length</a></code>
   742           </dt>
   743           <dd>
   744             <p>
   745               Returns the current number of <a>indexed properties</a> in the current object's collection.
   746             </p>
   747           </dd>
   748           <dt>
   749             <code title="dom-networkservices-servicesavailable"><a href=
   750             "#dom-networkservices-servicesavailable">servicesAvailable</a></code>
   751           </dt>
   752           <dd>
   753             <p>
   754               Returns the current number of items matching one of the app-requested <a>valid service type</a> tokens in
   755               the <a>list of available service records</a>.
   756             </p>
   757           </dd>
   758         </dl>
   759         <div>
   760           <p>
   761             The <dfn id="dom-networkservices-length"><code>length</code></dfn> attribute MUST return the number of
   762             <a href="#networkservice"><code>NetworkService</code></a> objects represented by the collection.
   763           </p>
   764           <p>
   765             The <dfn id="dom-networkservices-servicesavailable"><code>servicesAvailable</code></dfn> attribute MUST
   766             return the number of services in the <a>list of available service records</a> whose <code>type</code>
   767             attribute matches any of the <a>valid service type</a> tokens that were initially used to create the
   768             current <a href="#networkservices"><code>NetworkServices</code></a> object.
   769           </p>
   770         </div>
   771       </section>
   772       <section>
   773         <h2>
   774           Methods
   775         </h2>
   776         <dl class="domintro">
   777           <dt>
   778             <code title="networkservices-getter"><a href="#networkservices">services</a></code> [ <var title=
   779             "">index</var> ]
   780           </dt>
   781           <dd>
   782             <p>
   783               Returns the specified <a href="#networkservice"><code>NetworkService</code></a> object.
   784             </p>
   785           </dd>
   786           <dt>
   787             <code title="networkservices-getter"><a href="#networkservices">services</a></code> . <code title=
   788             "dom-networkservices-getservicebyid"><a href=
   789             "#dom-networkservices-getservicebyid">getServiceById</a></code> ( <var title="">id</var> )
   790           </dt>
   791           <dd>
   792             <p>
   793               Returns the <a href="#networkservice"><code>NetworkService</code></a> object with the given identifier,
   794               or null if no service has that identifier.
   795             </p>
   796           </dd>
   797         </dl>
   798         <p>
   799           A <a href="#networkservices"><code>NetworkServices</code></a> object represents the current collection of
   800           zero or more <a href="#networkservice"><code>NetworkService</code></a> objects - its <a>indexed
   801           properties</a>. The <a>indexed properties</a> of a <a href=
   802           "#networkservices"><code>NetworkServices</code></a> object are <span>immutable</span> meaning that <a>indexed
   803           properties</a> cannot be added and <a>indexed properties</a> cannot be removed for the lifetime of a <a href=
   804           "#networkservices"><code>NetworkServices</code></a> object.
   805         </p>
   806         <p>
   807           The <a href=
   808           "http://www.whatwg.org/specs/web-apps/current-work/multipage/infrastructure.html#supported-property-indices"
   809              class="externalDFN">supported property indices</a> of <a href=
   810              "#networkservices"><code>NetworkServices</code></a> objects at any instant are the numbers from zero to
   811              the number of the <a href="#networkservice"><code>NetworkService</code></a> objects in the collection
   812              minus one.
   813         </p>
   814         <p class="note">
   815           Each service in a <a href="#networkservices"><code>NetworkServices</code></a> object thus has an index; the
   816           first has the index 0, and each subsequent service is numbered one higher than the previous one.
   817         </p>
   818         <p>
   819           To <a href=
   820           "http://www.whatwg.org/specs/web-apps/current-work/multipage/infrastructure.html#determine-the-value-of-an-indexed-property"
   821              class="externalDFN">determine the value of an indexed property</a> for a given index <var>index</var> in a
   822              <a href="#networkservices"><code>NetworkServices</code></a> object the user agent MUST return the <a href=
   823              "#networkservice"><code>NetworkService</code></a> object that represents the <var>index</var>th item in
   824              the collection.
   825         </p>
   826         <p>
   827           The <dfn id="dom-networkservices-getservicebyid"><code>getServiceById(id)</code></dfn> method <em class=
   828           "ct">MUST</em> return the first <a href="#networkservice"><code>NetworkService</code></a> object in the
   829           collection whose <a href="#dom-networkservice-id"><code>id</code></a> attribute is equal to the value of the
   830           <var>id</var> argument provided. When no <a href="#networkservice"><code>NetworkService</code></a> objects
   831           match the given argument, the method MUST return null.
   832         </p>
   833       </section>
   834       <section>
   835         <h2>
   836           Events
   837         </h2>
   838         <p>
   839           The following are the event handlers (and their corresponding event handler event types) that <em class=
   840           "ct">MUST</em> be supported, as IDL attributes, by all objects implementing the <a href=
   841           "#networkservices"><code>NetworkServices</code></a> interface:
   842         </p>
   843         <table border="1">
   844           <thead>
   845             <tr>
   846               <th>
   847                 <span title="event handlers">Event handler</span>
   848               </th>
   849               <th>
   850                 <span>Event handler event type</span>
   851               </th>
   852             </tr>
   853           </thead>
   854           <tbody>
   855             <tr>
   856               <td>
   857                 <dfn id="dom-networkservices-onserviceavailable"
   858                     title="dom-NetworkServices-onserviceavailable"><code>onserviceavailable</code></dfn>
   859               </td>
   860               <td>
   861                 <a href="#event-serviceavailable"><code>serviceavailable</code></a>
   862               </td>
   863             </tr>
   864             <tr>
   865               <td>
   866                 <dfn id="dom-networkservices-onserviceunavailable"
   867                     title="dom-NetworkServices-onserviceunavailable"><code>onserviceunavailable</code></dfn>
   868               </td>
   869               <td>
   870                 <a href="#event-serviceunavailable"><code>serviceunavailable</code></a>
   871               </td>
   872             </tr>
   873           </tbody>
   874         </table>
   875       </section>
   876     </section>
   877     <section>
   878       <h2>
   879         Communicating with a networked service
   880       </h2>
   881       <p>
   882         The <a href="#networkservice"><code>NetworkService</code></a> interface is used to provide a set of connection
   883         information for an HTTP service endpoint and if available, service events, running on a networked device.
   884       </p>
   885       <pre class="widl">
   886 [NoInterfaceObject]
   887 interface <dfn id="networkservice">NetworkService</dfn> {
   888   readonly attribute DOMString        <a href="#dom-networkservice-id">id</a>;
   889   readonly attribute DOMString        <a href="#dom-networkservice-name">name</a>;
   890   readonly attribute DOMString        <a href="#dom-networkservice-type">type</a>;
   891   readonly attribute DOMString        <a href="#dom-networkservice-url">url</a>;
   892   readonly attribute DOMString        <a href="#dom-networkservice-config">config</a>;
   893 
   894   readonly attribute boolean          <a href="#dom-networkservice-online">online</a>;
   895 
   896   // event handler attributes
   897            attribute <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#eventhandler"
   898      class="externalDFN">EventHandler</a>     <a href="#dom-networkservice-onserviceonline">onserviceonline</a>;
   899            attribute <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#eventhandler"
   900      class="externalDFN">EventHandler</a>     <a href="#dom-networkservice-onserviceoffline">onserviceoffline</a>;
   901 
   902            attribute <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#eventhandler"
   903      class="externalDFN">EventHandler</a>     <a href="#dom-networkservice-onnotify">onnotify</a>;
   904 };
   905 
   906 <a href="#networkservice">NetworkService</a> implements <a href=
   907 "http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-eventtarget"
   908      class="externalDFN">EventTarget</a>;
   909 </pre>
   910       <section>
   911         <h2>
   912           Attributes
   913         </h2>
   914         <dl class="domintro">
   915           <dt>
   916             <var title="">service</var> . <code title="dom-networkservice-id"><a href=
   917             "#dom-networkservice-id">id</a></code>
   918           </dt>
   919           <dd>
   920             <p>
   921               A unique identifier for the given user-selected service instance.
   922             </p>
   923           </dd>
   924           <dt>
   925             <var title="">service</var> . <code title="dom-networkservice-name"><a href=
   926             "#dom-networkservice-name">name</a></code>
   927           </dt>
   928           <dd>
   929             <p>
   930               The name of the user-selected service.
   931             </p>
   932           </dd>
   933           <dt>
   934             <var title="">service</var> . <code title="dom-networkservice-type"><a href=
   935             "#dom-networkservice-type">type</a></code>
   936           </dt>
   937           <dd>
   938             <p>
   939               The <a>valid service type</a> token value of the user-selected service.
   940             </p>
   941           </dd>
   942           <dt>
   943             <var title="">service</var> . <code title="dom-networkservice-url"><a href=
   944             "#dom-networkservice-url">url</a></code>
   945           </dt>
   946           <dd>
   947             <p>
   948               The control URL endpoint (including any required port information) of the user-selected control service
   949               that has been added to the <a>entry script origin's URL whitelist</a>.
   950             </p>
   951           </dd>
   952           <dt>
   953             <var title="">service</var> . <code title="dom-networkservice-config"><a href=
   954             "#dom-networkservice-config">config</a></code>
   955           </dt>
   956           <dd>
   957             <p>
   958               The configuration information associated with the service depending on the requested service type.
   959             </p>
   960           </dd>
   961         </dl>
   962         <p>
   963           The <dfn id="dom-networkservice-id"><code>id</code></dfn> attribute is a unique identifier for the service.
   964           The same service provided at different times or on different objects MUST have the same <a href=
   965           "#dom-networkservice-id"><code>id</code></a> value.
   966         </p>
   967         <p>
   968           The <dfn id="dom-networkservice-name"><code>name</code></dfn> attribute represents a human-readable title for
   969           the service.
   970         </p>
   971         <p>
   972           The <dfn id="dom-networkservice-type"><code>type</code></dfn> attribute reflects the value of the <a>valid
   973           service type</a> of the service.
   974         </p>
   975         <p>
   976           The <dfn id="dom-networkservice-url"><code>url</code></dfn> attribute is an <a href=
   977           "http://www.w3.org/TR/html5/urls.html#absolute-url"
   978              class="externalDFN">absolute URL</a> pointing to the root HTTP endpoint for the service that has been
   979              added to the <a>entry script origin's URL whitelist</a>. Web pages can subsequently use this value for
   980              implicit cross-document messaging via various existing mechanisms (e.g. Web Sockets, Server-Sent Events,
   981              Web Messaging, XMLHttpRequest).
   982         </p>
   983         <p>
   984           The <dfn id="dom-networkservice-config"><code>config</code></dfn> attribute provides the raw configuration
   985           information extracted from the given network service.
   986         </p>
   987       </section>
   988       <section>
   989         <h3>
   990           States
   991         </h3>
   992         <dl class="domintro">
   993           <dt>
   994             <var title="">service</var> . <code title="dom-networkservice-online"><a href=
   995             "#dom-networkservice-online">online</a></code>
   996           </dt>
   997           <dd>
   998             <p>
   999               Returns <code>true</code> if the service is reporting that it is accessible on the local network or
  1000               <code>false</code> if the service is no longer accessible (temporarily or permanently) on the local
  1001               network.
  1002             </p>
  1003           </dd>
  1004         </dl>
  1005         <p>
  1006           The <dfn id="dom-networkservice-online"><code>online</code></dfn> attribute indicates whether the service is
  1007           either <var>online</var>, and therefore accessible on the local network, in which case this attribute will
  1008           return <code>true</code> or, <var>offline</var>, and therefore not accessible on the local network, either
  1009           temporarily or permanently, in which case this attribute will return <code>false</code>. This attribute MUST
  1010           default to <code>true</code>.
  1011         </p>
  1012       </section>
  1013       <section>
  1014         <h3>
  1015           Events
  1016         </h3>
  1017         <p>
  1018           The following are the event handlers (and their corresponding event handler event types) that <em class=
  1019           "ct">MUST</em> be supported, as IDL attributes, by all objects implementing the <a href=
  1020           "#networkservice"><code>NetworkService</code></a> interface:
  1021         </p>
  1022         <table border="1">
  1023           <thead>
  1024             <tr>
  1025               <th>
  1026                 <span title="event handlers">Event handler</span>
  1027               </th>
  1028               <th>
  1029                 <span>Event handler event type</span>
  1030               </th>
  1031             </tr>
  1032           </thead>
  1033           <tbody>
  1034             <tr>
  1035               <td>
  1036                 <dfn id="dom-networkservice-onnotify"
  1037                     title="dom-NetworkService-onnotify"><code>onnotify</code></dfn>
  1038               </td>
  1039               <td>
  1040                 <a href="#event-notify"><code>notify</code></a>
  1041               </td>
  1042             </tr>
  1043             <tr>
  1044               <td>
  1045                 <dfn id="dom-networkservice-onserviceonline"
  1046                     title="dom-NetworkService-onserviceonline"><code>onserviceonline</code></dfn>
  1047               </td>
  1048               <td>
  1049                 <a href="#event-serviceonline"><code>serviceonline</code></a>
  1050               </td>
  1051             </tr>
  1052             <tr>
  1053               <td>
  1054                 <dfn id="dom-networkservice-onserviceoffline"
  1055                     title="dom-NetworkService-onserviceoffline"><code>onserviceoffline</code></dfn>
  1056               </td>
  1057               <td>
  1058                 <a href="#event-serviceoffline"><code>serviceoffline</code></a>
  1059               </td>
  1060             </tr>
  1061           </tbody>
  1062         </table>
  1063       </section>
  1064     </section>
  1065     <section>
  1066       <h2>
  1067         Service Discovery
  1068       </h2>
  1069       <p>
  1070         A <a>user agent</a> conforming to this specification MAY implement <abbr title=
  1071         "Simple Service Discovery Protocol">SSDP</abbr> [[!UPNP-DEVICEARCH11]], Zeroconf [[!DNS-SD]] + [[!MDNS]] and/or
  1072         <abbr title="Discovery and Launch Protocol">DIAL</abbr> [<a href=
  1073         "https://sites.google.com/a/dial-multiscreen.org/dial/dial-protocol-specification">DIAL</a>] <dfn>service
  1074         discovery mechanisms</dfn> - the requirements detailed in this section of the specification - to enable Web
  1075         pages to request and connect with HTTP services running on networked devices, discovered via any of these
  1076         mechanisms, through this API. When a <a>user agent</a> implements any of these <a>service discovery
  1077         mechanisms</a>, then it MUST conform to the corresponding algorithms provided in this section of the
  1078         specification.
  1079       </p>
  1080       <p>
  1081         This section presents how the results of these <a>service discovery mechanisms</a> will be matched to requested
  1082         service types, how the user agent stores available and active services and how their properties are applied to
  1083         any resulting <a href="#networkservice"><code>NetworkService</code></a> objects.
  1084       </p>
  1085       <p>
  1086         It is expected that user agents will perform these <a>service discovery mechanisms</a> asynchronously and
  1087         periodically update the <a>list of available service records</a> as required. The timing of any <a>service
  1088         discovery mechanisms</a> is an implementation detail left to the discretion of the implementer (e.g. by
  1089         continuously monitoring the network as a background process or on invocation of this API from a Web page).
  1090       </p>
  1091       <p>
  1092         The <dfn>list of available service records</dfn> is a single dynamic internal lookup table within user agents
  1093         that is used to track all the services that have been discovered and are available in the current network at
  1094         the current time. At any point during the running of any of the <a>service discovery mechanisms</a> then
  1095         existing entries within this table can be updated, entries can be added and entries can be removed as the
  1096         status of networked services changes according to the rules defined in this specification.
  1097       </p>
  1098       <p>
  1099         The <dfn>list of active service managers</dfn> is an internal list within user agents that is used to track all
  1100         <a href="#networkservices"><code>NetworkServices</code></a> objects currently being shared with any web pages
  1101         at the current time within the user agent. Each <a href="#networkservices"><code>NetworkServices</code></a>
  1102         object in the <a>list of active service managers</a> represents a collection of zero or more <a href=
  1103         "#networkservice"><code>NetworkService</code></a> objects - known as its <dfn>indexed properties</dfn>.
  1104         <a href="#networkservice"><code>NetworkService</code></a> objects are attached as the <a>indexed properties</a>
  1105         of a <a href="#networkservices"><code>NetworkServices</code></a> object as part of the <a href=
  1106         "#dom-navigator-getnetworkservices"><code>getNetworkServices()</code></a> algorithm.
  1107       </p>
  1108       <p>
  1109         The rule for <dfn>adding an available service</dfn> is the process of adding a <a>new service</a> or updating
  1110         an <a>existing service</a> that is generally available on the user's current network in the <a>list of
  1111         available service records</a>. This rule takes one argument, <var>network service record</var>, and consists of
  1112         running the following steps:
  1113       </p>
  1114       <ol class="rule">
  1115         <li>For each <var>existing service record</var> in the current <a>list of available service records</a>, run
  1116         the following sub-steps:
  1117           <ol class="rule">
  1118             <li>If the <var>existing service record</var>'s <code>id</code> property does not equal <var>network
  1119             service record</var>'s <code>id</code> property then abort any remaining sub-steps and continue at the next
  1120             available <var>existing service record</var>.
  1121             </li>
  1122             <li>Replace the value of <var>existing service record</var> in the current <a>list of available service
  1123             records</a> with the value of <var>network service record</var>, aborting any remaining steps in this
  1124             algorithm and return.
  1125             </li>
  1126           </ol>
  1127         </li>
  1128         <li>Add <var>network service record</var> to the <a>list of available service records</a> as a new item.
  1129         </li>
  1130         <li>For each <var>service manager</var> in the <a>list of active service managers</a> run the following steps:
  1131           <ol class="rule">
  1132             <li>For each <var>active service</var> in <var>service manager</var> run the following steps:
  1133               <ol class="rule">
  1134                 <li>If the <var>network service record</var>'s <code>id</code> property equals the <var>active
  1135                 service</var>'s <code>id</code> attribute and <var>active service</var>'s <code>online</code> attribute
  1136                 is currently set to <code>false</code> then set <var>active service</var>'s <a href=
  1137                 "#dom-networkservice-online"><code>online</code></a> attribute to <code>true</code> and then <a href=
  1138                 "http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#queue-a-task"
  1139                       class="externalDFN">queue a task</a> to dispatch a newly created event with the name <a href=
  1140                       "#event-serviceonline"><code>serviceonline</code></a> that uses the <a href=
  1141                       "http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1142                       class="externalDFN"><code>Event</code></a> interface, which does not bubble, is not cancellable,
  1143                       and has no default action, at the current <var>active service</var> object.
  1144                 </li>
  1145               </ol>
  1146             </li>
  1147             <li>Let <var>'service type in current service manager' flag</var> be <code>false</code>.
  1148             </li>
  1149             <li>For each <var>requested control type</var> of the <var>requested control types</var> in <var>service
  1150             manager</var> run the following steps:
  1151               <ol class="rule">
  1152                 <li>If <var>network service record</var>'s <code>type</code> property does not equal <var>requested
  1153                 control type</var> then abort any remaining sub-steps and continue at the next available <var>requested
  1154                 control type</var>.
  1155                 </li>
  1156                 <li>Set the <var>'service type in current service manager' flag</var> to <code>true</code>, abort any
  1157                 remaining sub-steps and continue.
  1158                 </li>
  1159               </ol>
  1160             </li>
  1161             <li>If the <var>'service type in current service manager' flag</var> is set to <code>true</code> then
  1162             increment <var>service manager</var>'s <a href=
  1163             "#dom-networkservices-servicesavailable"><code>servicesAvailable</code></a> attribute by <code>1</code> and
  1164             then <a href="http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#queue-a-task"
  1165                   class="externalDFN">queue a task</a> to dispatch a newly created event with the name <a href=
  1166                   "#event-serviceavailable"><code>serviceavailable</code></a> that uses the <a href=
  1167                   "http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1168                   class="externalDFN"><code>Event</code></a> interface, which does not bubble, is not cancellable, and
  1169                   has no default action, at the current <var>service manager</var> object.
  1170             </li>
  1171           </ol>
  1172         </li>
  1173       </ol>
  1174       <p>
  1175         The rule for <dfn>removing an available service</dfn> is the general process of removing an <a>existing
  1176         service</a> from the <a>list of available service records</a> that has left the user's current network or has
  1177         otherwise expired. This rule takes one argument, <var>service identifier</var>, and consists of running the
  1178         following steps:
  1179       </p>
  1180       <ol class="rule">
  1181         <li>For each <var>existing service record</var> in the current <a>list of available service records</a>, run
  1182         the following sub-steps:
  1183           <ol class="rule">
  1184             <li>If the <var>existing service record</var>'s <code>id</code> property does not match <var>service
  1185             identifier</var> then skip any remaining sub-steps for the current <var>existing service record</var> and
  1186             continue at the next available <var>existing service record</var>.
  1187             </li>
  1188             <li>Let <var>'service type in use' flag</var> be <code>false</code>.
  1189             </li>
  1190             <li>For each <var>service manager</var> in the <a>list of active service managers</a> run the following
  1191             steps:
  1192               <ol class="rule">
  1193                 <li>Let <var>'service type in current service manager' flag</var> be <code>false</code>.
  1194                 </li>
  1195                 <li>For each <var>active service</var> in <var>service manager</var> run the following steps:
  1196                   <ol class="rule">
  1197                     <li>If <var>existing service record</var>'s <code>id</code> property equals the <var>active
  1198                     service</var>'s <code>id</code> attribute and <var>active service</var>'s <a href=
  1199                     "#dom-networkservice-online"><code>online</code></a> attribute is currently set to
  1200                     <code>true</code> then set <var>active service</var>'s <a href="#dom-networkservice-online"><code>
  1201                       online</code></a> attribute to <code>false</code> and then <a href=
  1202                       "http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#queue-a-task"
  1203                           class="externalDFN">queue a task</a> to dispatch a newly created event with the name <a href=
  1204                           "#event-serviceoffline"><code>serviceoffline</code></a> that uses the <a href=
  1205                           "http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1206                           class="externalDFN"><code>Event</code></a> interface, which does not bubble, is not
  1207                           cancellable, and has no default action, at the current <var>active service</var>.
  1208                     </li>
  1209                   </ol>
  1210                 </li>
  1211                 <li>For each <var>requested control type</var> of the <var>requested control types</var> in
  1212                 <var>service manager</var> run the following steps:
  1213                   <ol class="rule">
  1214                     <li>If <var>existing service record</var>'s <code>type</code> property does not equal
  1215                     <var>requested control type</var> then abort any remaining sub-steps and continue at the next
  1216                     available <var>requested control type</var>.
  1217                     </li>
  1218                     <li>Set the <var>'service type in current service manager' flag</var> to <code>true</code> and the
  1219                     <var>'service type in use' flag</var> to <code>true</code>, abort any remaining sub-steps and
  1220                     continue.
  1221                     </li>
  1222                   </ol>
  1223                 </li>
  1224                 <li>If the <var>'service type in current service manager' flag</var> is set to <code>true</code> then
  1225                 decrement <var>service manager</var>'s <a href=
  1226                 "#dom-networkservices-servicesavailable"><code>servicesAvailable</code></a> attribute by <code>1</code>
  1227                 and then <a href=
  1228                 "http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#queue-a-task"
  1229                       class="externalDFN">queue a task</a> to dispatch a newly created event with the name <a href=
  1230                       "#event-serviceunavailable"><code>serviceunavailable</code></a> that uses the <a href=
  1231                       "http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1232                       class="externalDFN"><code>Event</code></a> interface, which does not bubble, is not cancellable,
  1233                       and has no default action, at the current <var>service manager</var> object.
  1234                 </li>
  1235               </ol>
  1236             </li>
  1237             <li>If the <var>'service type in use' flag</var> is <code>false</code> and the <var>existing service
  1238             record</var>'s <code>type</code> property begins with the DOMString "<code>upnp:</code>" and <var>existing
  1239             service record</var>'s <code>eventsURL</code> property is set then run the rule to <a>terminate an existing
  1240             UPnP Events Subscription</a>, if one is currently active (as a result of having previously called <a>setup
  1241             a UPnP Events Subscription</a> against the current <var>existing service record</var>).
  1242             </li>
  1243             <li>Remove <var>existing service record</var> from the current <a>list of available service records</a>.
  1244             </li>
  1245           </ol>
  1246         </li>
  1247       </ol>
  1248       <p>
  1249         User agents SHOULD expire a service record from the <a>list of available service records</a> when its
  1250         <code>expiryTimestamp</code> attribute exceeds the current UTC timestamp. When this condition is met the
  1251         <a>user agent</a> SHOULD run the rule for <a>removing an available service</a>, passing in the expired service
  1252         record's <code>id</code> attribute as the only argument.
  1253       </p>
  1254       <section>
  1255         <h4>
  1256           Zeroconf (<abbr title="Multicast DNS">mDNS</abbr> + <abbr title="Domain Name System">DNS</abbr>-<abbr title=
  1257           "Service Discovery">SD</abbr>)
  1258         </h4>
  1259         <p>
  1260           For each DNS response received from a user-agent-initiated Multicast DNS Browse for <abbr title=
  1261           "DNS Pointer Record">PTR</abbr> records with the name <code>_services._dns-sd._udp</code> on the resolved
  1262           recommended automatic browsing domain [[!MDNS]], the <a>user agent</a> MUST run the following steps:
  1263         </p>
  1264         <ol class="rule">
  1265           <li>Let <var>service mDNS responses</var> be an array of PTR records received by issuing a Multicast DNS
  1266           Browse for PTR records with the name of the current discovered service type.
  1267           </li>
  1268           <li>For each Object <var>service mDNS response</var> in <var>service mDNS responses</var>, run the following
  1269           steps:
  1270             <ol>
  1271               <li>Let <var>network service record</var> be an Object consisting of the following empty properties:
  1272               <code>id</code>, <code>name</code>, <code>type</code>, <code>url</code>, <code>config</code>,
  1273               <code>expiryTimestamp</code>.
  1274               </li>
  1275               <li>Set <var>network service record</var>'s <code>id</code> property to the value of the full PTR Service
  1276               Instance Name [[!MDNS]].
  1277               </li>
  1278               <li>Set <var>network service record</var>'s <code>name</code> property to the value of the PTR Service
  1279               Instance Name's <var>Instance</var> component [[!MDNS]].
  1280               </li>
  1281               <li>Set <var>network service record</var>'s <code>type</code> property to the concatenation of the string
  1282               <code>zeroconf:</code> followed be the value of the PTR Service Instance Name's <var>Service</var>
  1283               component [[!MDNS]].
  1284               </li>
  1285               <li>Set <var>network service record</var>'s <code>url</code> property to the resolvable Service URL
  1286               obtained from performing an DNS-SD Lookup [[!DNS-SD]] of the current service from the PTR record provided
  1287               [[!MDNS]].
  1288               </li>
  1289               <li>Set <var>network service record</var>'s <code>config</code> property to the string value of the
  1290               contents of the first DNS-SD TXT record associated with the <var>service mDNS response</var> as defined
  1291               in [[!DNS-SD]].
  1292               </li>
  1293               <li>Set <var>network service record</var>'s <code>expiryTimestamp</code> property to the value of the
  1294               current date, in UTC timestamp format, plus a value of <code>120</code> seconds.
  1295               </li>
  1296               <li>Run the general rule for <a>adding an available service</a>, passing in the current <var>network
  1297               service record</var> as the only argument.
  1298               </li>
  1299             </ol>
  1300           </li>
  1301         </ol>
  1302       </section>
  1303       <section>
  1304         <h5>
  1305           Simple Service Discovery Protocol (<abbr title="Simple Service Discovery Protocol">SSDP</abbr>)
  1306         </h5>
  1307         <p>
  1308           A user agent that implements UPnP service discovery MUST issue a <dfn>search request for UPnP root
  1309           devices</dfn> against the user's current local network according to the full normative text and timing
  1310           provided in 'Section 1.3.2: Search request with M-SEARCH' detailed in [[!UPNP-DEVICEARCH11]].
  1311         </p>
  1312         <p>
  1313           The user agent MUST issue all <a title="search request for UPnP root devices">search requests for UPnP root
  1314           devices</a> with a HTTP request line equal to <code>M-SEARCH * HTTP/1.1</code>, with a HOST header equal to
  1315           the reserved multicast address and port of <code>239.255.255.250:1900</code> and a MAN header equal to
  1316           <code>ssdp:discover</code>. The <a>user agent</a> must also send an ST header with this HTTP request equal to
  1317           the String value of <code>ssdp:all</code> or <code>upnp:rootdevice</code> or a single <a>valid service
  1318           type</a> token beginning with the String value <code>upnp:</code>. If a single <a>valid service type</a>
  1319           token beginning with the String value <code>upnp:</code> is to be used, the user agent MUST strip the leading
  1320           String <code>upnp:</code> before using this value in this HTTP request. The user-agent MUST also send an MX
  1321           header equal to a <dfn>maximum UPnP advertisement response wait time</dfn> value between <code>1</code> and
  1322           <code>5</code> seconds with this HTTP request.
  1323         </p>
  1324         <p>
  1325           The user agent MUST listen for any incoming responses to any <a>search request for UPnP root devices</a>.
  1326         </p>
  1327         <p>
  1328           For each <dfn>HTTP Response</dfn> following an initial <a>search request for UPnP root devices</a> sent on a
  1329           <a>standard UPnP address and port</a> the user agent MUST run the following steps:
  1330         </p>
  1331         <ol class="rule">
  1332           <li>If the <a>HTTP Response</a> is not a HTTP 200 OK response then this response is invalid and the user
  1333           agent MUST discard this response, abort any remaining steps and return. The user agent MAY issue a new
  1334           <a>search request for UPnP root devices</a> as a result of this error occurring.
  1335           </li>
  1336           <li>If the <a>maximum UPnP advertisement response wait time</a> has been exceeded since the initial <a>search
  1337           request for UPnP root devices</a> was sent then the <a>HTTP Response</a> is invalid and the user agent MUST
  1338           discard this response, abort any remaining steps and return. The user agent MAY stop listening for responses
  1339           from the current <a>search request for UPnP root devices</a> as a result of this error occurring. Equally,
  1340           the user agent MAY issue a new <a>search request for UPnP root devices</a> as a result of this error
  1341           occurring.
  1342           </li>
  1343           <li>Let <var>ssdp device</var> be an Object with a property for each HTTP header received in the <a>HTTP
  1344           Response</a>, with each key being the name of a HTTP response header and each value being that HTTP response
  1345           header's value.
  1346           </li>
  1347           <li>If <var>ssdp device</var> does not contain at least one <var>CACHE-CONTROL</var> entry, at least one
  1348           <var>USN</var> entry, at least one <var>ST</var> entry and at least one <var>LOCATION</var> entry then the
  1349           <a>HTTP Response</a> is invalid and the <a>user agent</a> MUST discard this response, abort any remaining
  1350           steps and return.
  1351           </li>
  1352           <li>The user agent MUST run the rule for <a>obtaining a UPnP Device Description File</a> passing in the first
  1353           occurrence of <var>LOCATION</var> from <var>ssdp device</var> as the <var>device descriptor URL</var>
  1354           argument and the first occurrence of <var>USN</var> from <var>ssdp device</var> as the <var>device
  1355           identifier</var> argument and the first occurrence of <var>CACHE-CONTROL</var> from <var>ssdp device</var>
  1356           (minus the leading string of <code>max-age=</code>) as the <var>device expiry</var> argument.
  1357           </li>
  1358         </ol>
  1359         <p>
  1360           The user agent MUST listen for incoming requests on the <dfn>standard UPnP address and port</dfn> on all
  1361           current local network interface addresses with the port <code>1900</code>.
  1362         </p>
  1363         <p>
  1364           For each <dfn>HTTP Request</dfn> received on a <a>standard UPnP address and port</a> the user agent MUST run
  1365           the following steps:
  1366         </p>
  1367         <ol class="rule">
  1368           <li>If the <a>HTTP Request</a> is not a HTTP NOTIFY request then it is not a valid UPnP Request and the user
  1369           agent MUST discard this request, abort any remaining steps and return.
  1370           </li>
  1371           <li>Let <var>ssdp device</var> be an Object with a property for each HTTP header received in the <a>HTTP
  1372           Request</a>, with each key being the name of a HTTP header and each value being that HTTP header's value.
  1373           </li>
  1374           <li>If <var>ssdp device</var>'s <var>NTS</var> entry is equal to <code>ssdp:alive</code> and the <a>HTTP
  1375           Request</a> does not contain at least one <var>CACHE-CONTROL</var> entry, at least one <var>USN</var> entry,
  1376           at least one <var>NT</var> entry, at least one <var>NTS</var> entry and at least one <var>LOCATION</var>
  1377           entry, then the <a>user agent</a> MUST discard this request, abort any remaining steps and return.
  1378           </li>
  1379           <li>If <var>ssdp device</var>'s <var>NTS</var> entry is equal to <code>ssdp:alive</code> then the user agent
  1380           MUST run the rule for <a>obtaining a UPnP Device Description File</a> passing in the first occurrence of
  1381           <var>LOCATION</var> from <var>ssdp device</var> as the <var>device descriptor URL</var> argument and the
  1382           first occurrence of <var>USN</var> from <var>ssdp device</var> as the <var>device identifier</var> argument
  1383           and the first occurrence of <var>CACHE-CONTROL</var> from <var>ssdp device</var> (minus the leading string of
  1384           <code>max-age=</code>) as the <var>device expiry</var>.<br>
  1385             <br>
  1386             Otherwise, if <var>ssdp device</var>'s <var>NTS</var> entry is equal to <code>ssdp:byebye</code> then the
  1387             user agent MUST run the rule for <a>removing all services from a registered UPnP Device</a> passing in the
  1388             first occurrence of <var>USN</var> from <var>ssdp device</var> as the <var>device identifier</var>
  1389             argument.
  1390           </li>
  1391         </ol>
  1392         <p>
  1393           The rule for <dfn>obtaining a UPnP Device Description File</dfn> is the process of obtaining the contents of
  1394           a standard UPnP Device Description [[!UPNP-DEVICEARCH11]] from a URL-based resource. This rule takes three
  1395           arguments - <var>device descriptor URL</var>, <var>device identifier</var> and <var>device expiry</var> - and
  1396           when called the user agent MUST run the following steps:
  1397         </p>
  1398         <ol class="rule">
  1399           <li>Let <var>device descriptor file</var> contain the contents of the file located at the URL provided in
  1400           <var>device descriptor URL</var> obtained according to the rules defined in 'Section 2.11: Retrieving a
  1401           description using HTTP' in [[!UPNP-DEVICEARCH11]].
  1402           </li>
  1403           <li>If the value provided in <var>device descriptor URL</var> cannot be resolved as a reachable URL on the
  1404           current network or the <var>device descriptor file</var> remains empty then it is invalid and the <a>user
  1405           agent</a> MUST abort any remaining steps and return.
  1406           </li>
  1407           <li>Run the rule for <a>processing a UPnP Device Description File</a>, passing in the current <var>device
  1408           descriptor file</var>, <var>device identifier</var> and <var>device expiry</var> arguments.
  1409           </li>
  1410         </ol>
  1411         <p>
  1412           The rule for <dfn>processing a UPnP Device Description File</dfn> is the process of parsing the contents of a
  1413           standard UPnP Device Description [[!UPNP-DEVICEARCH11]] and registering the UPnP services contained therein
  1414           within the <a>list of available service records</a>.
  1415         </p>
  1416         <p>
  1417           The rule for <a>processing a UPnP Device Description File</a> takes three arguments - <var>device descriptor
  1418           file</var>, <var>device identifier</var> and <var>device expiry</var> - and when called the user agent MUST
  1419           run the following steps:
  1420         </p>
  1421         <ol class="rule">
  1422           <li>Let <var>advertised services</var> be a list of all advertised services obtained from the <var>device
  1423           descriptor file</var> containing the value of the first occurrence of the <code>&lt;serviceList&gt;</code>
  1424           element as it is defined in 'Section 2.3: Device Description' in [[!UPNP-DEVICEARCH11]].
  1425           </li>
  1426           <li>For each <code>&lt;service&gt;</code> element - known as an <var>advertised service</var> - in
  1427           <var>advertised services</var> run the following steps:
  1428             <ol class="rule">
  1429               <li>Let <var>network service record</var> be a new Object consisting of the following empty properties:
  1430               <code>id</code>, <code>deviceId</code>, <code>name</code>, <code>type</code>, <code>url</code>,
  1431               <code>eventsUrl</code>, <code>config</code>, <code>expiryTimestamp</code>.
  1432               </li>
  1433               <li>Set <var>network service record</var>'s <code>id</code> property to the concatenated string value of
  1434               the first occurrence of the <code>&lt;UDN&gt;</code> element in the <var>device descriptor file</var>
  1435               with the <var>advertised service</var>'s <code>&lt;serviceId&gt;</code> sub-element.
  1436               </li>
  1437               <li>Set <var>network service record</var>'s <code>deviceId</code> property to the value of <var>device
  1438               identifier</var>.
  1439               </li>
  1440               <li>Set <var>network service record</var>'s <code>name</code> property to the string value of the first
  1441               occurrence of the <var>advertised service</var>'s <code>&lt;serviceId&gt;</code> sub-element.
  1442               </li>
  1443               <li>Set <var>network service record</var>'s <code>type</code> property to the concatenation of the string
  1444               <code>upnp:</code> followed by the string value of the first occurrence of the <var>advertised
  1445               service</var>'s <code>&lt;serviceType&gt;</code> sub-element.
  1446               </li>
  1447               <li>Set <var>network service record</var>'s <code>url</code> property to the string value of the first
  1448               occurrence of the <var>advertised service</var>'s <code>&lt;controlURL&gt;</code> sub-element.
  1449               </li>
  1450               <li>Set <var>network service record</var>'s <code>config</code> property to the string value of the
  1451               contents of the first occurrence of the <code>&lt;device&gt;</code> element in the <var>device descriptor
  1452               file</var>.
  1453               </li>
  1454               <li>If <var>advertised service</var>'s <code>&lt;eventSubURL&gt;</code> sub-element is not empty, then
  1455               set <var>network service record</var>'s <code>eventsUrl</code> property to the string value of the first
  1456               occurrence of the <var>advertised service</var>'s <code>&lt;eventSubURL&gt;</code> sub-element.
  1457               Otherwise, do not set <var>network service record</var>'s <code>eventsUrl</code> property.
  1458               </li>
  1459               <li>Set <var>network service record</var>'s <code>expiryTimestamp</code> property to the value of the
  1460               current date, in UTC timestamp format, plus the value of <var>device expiry</var>.
  1461               </li>
  1462               <li>Run the general rule for <a>adding an available service</a>, passing in the current <var>network
  1463               service record</var> as the only argument.
  1464               </li>
  1465             </ol>
  1466           </li>
  1467           <li>If <var>device descriptor file</var> contains a <code>&lt;deviceList&gt;</code> element then for each
  1468           <code>&lt;device&gt;</code> element within <code>&lt;deviceList&gt;</code> - herein known as an <var>embedded
  1469           device descriptor file</var> - the user agent MUST run the rule for <a>processing a UPnP Device Description
  1470           File</a>, passing in the current <var>embedded device descriptor file</var> as the <var>device descriptor
  1471           file</var> argument, along with the current <var>device identifier</var> and <var>device expiry</var>
  1472           arguments.
  1473           </li>
  1474         </ol>
  1475         <p>
  1476           The rule for <dfn>removing all services from a registered UPnP Device</dfn> is the process of removing all
  1477           services associated with a device from the <a>list of available service records</a> that has left the user's
  1478           current network or has otherwise timed out or expired. This rule takes one argument, <var>device
  1479           identifier</var>, and consists of running the following steps:
  1480         </p>
  1481         <ol class="rule">
  1482           <li>For each <var>existing service record</var> in the current <a>list of available service records</a>, run
  1483           the following sub-steps:
  1484             <ol class="rule">
  1485               <li>If the <var>existing service record</var>'s <code>deviceId</code> property does not match <var>device
  1486               identifier</var> then skip any remaining sub-steps for the current <var>existing service record</var> and
  1487               continue at the next available <var>existing service record</var>.
  1488               </li>
  1489               <li>Run the general rule for <a>removing an available service</a> passing in <var>existing service
  1490               record</var>'s <code>id</code> property as the only argument.
  1491               </li>
  1492             </ol>
  1493           </li>
  1494         </ol>
  1495         <p>
  1496           When the <a>user agent</a> is to <dfn>setup a UPnP Events Subscription</dfn>, it is to run the following
  1497           steps with the current <var>network service record</var> object as defined in 'Section 4.1.2: SUBSCRIBE with
  1498           NT and CALLBACK' in [[!UPNP-DEVICEARCH11]]:
  1499         </p>
  1500         <ol class="rule">
  1501           <li>If <var>network service record</var>'s <code>eventsUrl</code> property is empty then the <a>user
  1502           agent</a> MUST abort these steps.
  1503           </li>
  1504           <li>Let <var>callback URL</var> be the value of creating a new <a>user-agent generated callback url</a>.
  1505           </li>
  1506           <li>Send a HTTP SUBSCRIBE request with a <em>NT</em> header with a string value of <code>upnp:event</code>, a
  1507           <em>TIMEOUT</em> header with a user-agent defined timeout value (in the form <code>Second-XX</code> where
  1508           <code>XX</code> is the user-agent defined timeout value in seconds) and a <em>CALLBACK</em> header with a
  1509           string value of <var>callback URL</var> towards the <var>network service record</var>'s
  1510           <code>eventsUrl</code> property.
  1511           </li>
  1512           <li>If a non-200 OK response is received from the HTTP SUBSCRIBE request then the <a>user agent</a> MUST
  1513           abort these steps.
  1514           </li>
  1515           <li>On receiving a valid 200 OK response, run the following steps:
  1516             <ol class="rule">
  1517               <li>Let <var>callback ID</var> equal the string value of the first included <em>SID</em> header, if it
  1518               exists.
  1519               </li>
  1520               <li>Let <var>timeout date</var> equal the sum of the current UTC date value plus the integer value of the
  1521               first included <em>TIMEOUT</em> header (minus the leading string of <code>Second-</code>), if it exists.
  1522               </li>
  1523               <li>Run the following steps asynchronously and continue to the step labeled <em>listen</em> below.
  1524               </li>
  1525               <li>
  1526                 <em>Refresh Subscription</em>: Run the following steps at a set interval (X) within the <a>user
  1527                 agent</a>:
  1528                 <ol class="rule">
  1529                   <li>Let <var>current date</var> equal the current UTC date.
  1530                   </li>
  1531                   <li>If <var>current date</var> is less than the <var>timeout date</var> then continue to the step
  1532                   labeled <em>refresh subscription</em> above.
  1533                   </li>
  1534                   <li>Send a HTTP SUBSCRIBE request with a <em>SID</em> header with the string value of <var>callback
  1535                   ID</var> and a user-agent defined <em>TIMEOUT</em> header (in the form <code>Second-XX</code> where
  1536                   <code>XX</code> is the user-agent defined timeout value in seconds) towards the <var>network service
  1537                   record</var>'s <code>eventsUrl</code> property.
  1538                   </li>
  1539                   <li>On receiving a valid 200 OK, update <var>callback ID</var> with the string value of the first
  1540                   included <em>SID</em> header and set <var>timeout date</var> to the sum of the current UTC date value
  1541                   plus the integer value of the first included <em>TIMEOUT</em> header (minus the leading string of
  1542                   <code>Second-</code>), if it exists. If the current date is greater than or equal to <var>timeout
  1543                   date</var> then the <a>user agent</a> SHOULD continue from the step labeled <em>refresh
  1544                   subscription</em> above. For all non 200 OK responses the <a>user agent</a> SHOULD continue from the
  1545                   step labeled <em>refresh subscription</em> above.
  1546                   </li>
  1547                 </ol>
  1548               </li>
  1549               <li>
  1550                 <em>Listen</em>: For each HTTP NOTIFY request received at the <var>callback URL</var> the <a>user
  1551                 agent</a> is to run the following steps:
  1552                 <ol class="rule">
  1553                   <li>Let <var>content clone</var> be the result of obtaining the message body of the HTTP NOTIFY
  1554                   request. If <var>content clone</var> is empty, then the <a>user agent</a> MUST abort these steps.
  1555                   </li>
  1556                   <li>Let <var>notification event</var> be a new simple event that uses the <a href=
  1557                   "http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1558                         class="externalDFN"><code>Event</code></a> interface with the name <a href=
  1559                         "#event-notify"><code>notify</code></a>, which does not bubble, is not cancellable, and has no
  1560                         default action.
  1561                   </li>
  1562                   <li>Let the <code>data</code> attribute of <var>notification event</var> have the DOMString value of
  1563                   <var>content clone</var>.
  1564                   </li>
  1565                   <li>
  1566                     <a href="http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#queue-a-task"
  1567                         class="externalDFN">Queue a task</a> to dispatch <var>notification event</var> at the current
  1568                         <a><code>NetworkService</code></a> object.
  1569                   </li>
  1570                   <li>Return a HTTP 200 OK response to the sender of the HTTP NOTIFY request.
  1571                   </li>
  1572                 </ol>
  1573               </li>
  1574             </ol>
  1575           </li>
  1576         </ol>
  1577         <p>
  1578           A <a>user agent</a> can <dfn>terminate an existing UPnP Events Subscription</dfn> at any time for a
  1579           <var>network service record</var> by sending an HTTP UNSUBSCRIBE request - as defined in 'Section 4.1.4:
  1580           Cancelling a subscription with UNSUBSCRIBE' in [[!UPNP-DEVICEARCH11]] - with a HOST header set to that
  1581           <var>active service</var>'s <code>eventsUrl</code> property and a SID header set to the <var>callback
  1582           ID</var> obtained when the initial <a>setup a UPnP Events Subscription</a> action occurred.
  1583         </p>
  1584       </section>
  1585       <section>
  1586         <h5>
  1587           Discovery and Launch Protocol (<abbr title="Discovery and Launch Protocol">DIAL</abbr>)
  1588         </h5>
  1589         <p>
  1590           A user agent that implements DIAL service discovery MUST issue a <dfn>search request for DIAL-enabled
  1591           devices</dfn> against the user's current local network according to the full normative text and timing
  1592           provided in 'Section 1.3.2: Search request with M-SEARCH' detailed in [[!UPNP-DEVICEARCH11]].
  1593         </p>
  1594         <p>
  1595           Let <var>dial version</var> be the version number specified in the <a>valid service type</a> token. Let
  1596           <var>dial search target</var> be the concatentation of the
  1597           <code>urn:dial-multiscreen-org:service:dial:</code> string constant with the <var>dial version</var>
  1598           (currently, <var>dial version</var> can only be <code>1</code>)
  1599         </p>
  1600         <p>
  1601           The user agent MUST issue all <a title="search request for DIAL devices">search requests for DIAL devices</a>
  1602           with a HTTP request line equal to <code>M-SEARCH * HTTP/1.1</code>, with a HOST header equal to the reserved
  1603           multicast address and port of <code>239.255.255.250:1900</code>, a MAN header equal to
  1604           <code>ssdp:discover</code>, an ST header equal to <var>dial search target</var> and a user-agent defined MX
  1605           header equal to a <dfn>maximum DIAL advertisement response wait time</dfn> value between <code>1</code> and
  1606           <code>5</code> seconds.
  1607         </p>
  1608         <p>
  1609           The user agent MUST listen for any incoming responses to a <a>search request for DIAL devices</a>.
  1610         </p>
  1611         <p>
  1612           For each HTTP Response following an initial <a>search request for DIAL devices</a> sent on a <a>standard UPnP
  1613           address and port</a> the user agent MUST run the following steps:
  1614         </p>
  1615         <ol class="rule">
  1616           <li>If the HTTP Response is not a HTTP 200 OK response then this response is invalid and the user agent MUST
  1617           discard this response, abort any remaining steps and return. The user agent MAY issue a new <a>search request
  1618           for DIAL devices</a> as a result of this error occurring.
  1619           </li>
  1620           <li>If the <a>maximum DIAL advertisement response wait time</a> has been exceeded since the initial <a>search
  1621           request for DIAL devices</a> was sent then the <a>HTTP Response</a> is invalid and the user agent MUST
  1622           discard this response, abort any remaining steps and return. The user agent MAY stop listening for responses
  1623           from the current <a>search request for DIAL devices</a> as a result of this error occurring. Equally, the
  1624           user agent MAY issue a new <a>search request for DIAL devices</a> as a result of this error occurring.
  1625           </li>
  1626           <li>Let <var>dial device</var> be an Object with a property for each HTTP header received in the <a>HTTP
  1627           Response</a>, with each key being the name of a HTTP response header and each value being that HTTP response
  1628           header's value.
  1629           </li>
  1630           <li>If <var>dial device</var> does not contain at least one <var>CACHE-CONTROL</var> entry, at least one
  1631           <var>USN</var> entry, at least one <var>ST</var> entry and at least one <var>LOCATION</var> entry or the
  1632           value of its <var>ST</var> entry is not <var>dial search target</var>, then the <a>HTTP Response</a> is
  1633           invalid and the <a>user agent</a> MUST discard this response, abort any remaining steps and return.
  1634           </li>
  1635           <li>The user agent MUST run the rule for <a>obtaining a UPnP Device Description File</a> passing in the first
  1636           occurrence of <var>LOCATION</var> from <var>dial device</var> as the <var>device descriptor URL</var>
  1637           argument and the first occurrence of <var>USN</var> from <var>dial device</var> as the <var>device
  1638           identifier</var> argument and the first occurrence of <var>CACHE-CONTROL</var> from <var>dial device</var>
  1639           (minus the leading string of <code>max-age=</code>) as the <var>device expiry</var> argument.
  1640           </li>
  1641         </ol>
  1642         <p>
  1643           The rule for <dfn>obtaining a DIAL Device Description File</dfn> is the process of obtaining the contents of
  1644           a standard UPnP Device Description [[!UPNP-DEVICEARCH11]] from a URL-based resource. This rule takes three
  1645           arguments - <var>device descriptor URL</var>, <var>device identifier</var> and <var>device expiry</var> - and
  1646           when called the user agent MUST run the following steps:
  1647         </p>
  1648         <ol class="rule">
  1649           <li>Let <var>device descriptor file</var> contain the contents of the file located at the URL provided in
  1650           <var>device descriptor URL</var> obtained according to the rules defined in 'Section 2.11: Retrieving a
  1651           description using HTTP' in [[!UPNP-DEVICEARCH11]].
  1652           </li>
  1653           <li>Let <var>application url</var> be the value of the first occurrence of the <code>Application-URL</code>
  1654           response header field obtained according to the rules defined in 'Section 5.4: Device Description Response'
  1655           in [<a href="https://sites.google.com/a/dial-multiscreen.org/dial/dial-protocol-specification">DIAL</a>]
  1656           </li>
  1657           <li>If the value provided in <var>device descriptor URL</var> cannot be resolved as a reachable URL on the
  1658           current network or the <var>device descriptor file</var> remains empty or <var>application url</var> is
  1659           undefined then it is invalid and the <a>user agent</a> MUST abort any remaining steps and return.
  1660           </li>
  1661           <li>Run the following steps to add the newly discovered DIAL service:
  1662             <ol class="rule">
  1663               <li>Let <var>network service record</var> be a new Object consisting of the following empty properties:
  1664               <code>id</code>, <code>deviceId</code>, <code>name</code>, <code>type</code>, <code>url</code>,
  1665               <code>expiryTimestamp</code>.
  1666               </li>
  1667               <li>Set <var>network service record</var>'s <code>id</code> property to the first occurrence of the
  1668               <code>&lt;UDN&gt;</code> element in the <var>descriptor file</var> prefixed with the <code>dial:</code>
  1669               string constant
  1670               </li>
  1671               <li>Set <var>network service record</var>'s <code>deviceId</code> property to the value of <var>device
  1672               identifier</var>.
  1673               </li>
  1674               <li>Set <var>network service record</var>'s <code>name</code> property to the string value of the first
  1675               occurrence of the <code>&lt;friendlyName&gt;</code> element in the <var>descriptor file</var>.
  1676               </li>
  1677               <li>Set <var>network service record</var>'s <code>type</code> property to <var>dial search target</var>.
  1678               </li>
  1679               <li>Set <var>network service record</var>'s <code>url</code> property to the string value of the
  1680               <var>application url</var>.
  1681               </li>
  1682               <li>Set <var>network service record</var>'s <code>expiryTimestamp</code> property to the value of the
  1683               current date, in UTC timestamp format, plus the value of <var>device expiry</var>.
  1684               </li>
  1685               <li>Run the general rule for <a>adding an available service</a>, passing in the current <var>network
  1686               service record</var> as the only argument.
  1687               </li>
  1688             </ol>
  1689           </li>
  1690         </ol>
  1691       </section>
  1692       <section>
  1693         <h3>
  1694           Network Topology Monitoring
  1695         </h3>
  1696         <div>
  1697           <p>
  1698             When the <a>user agent</a> detects that the user has dropped from a connected network then, for each
  1699             <var>existing service record</var> in the <a>list of available service records</a> discovered via that
  1700             network connection, the <a>user agent</a> MUST run the general rule for <a>removing an available
  1701             service</a> passing in each <var>existing service record</var>'s <code>id</code> property as the only
  1702             argument for each call.
  1703           </p>
  1704           <p>
  1705             When the <a>user agent</a> detects that the user has connected to a new network or reconnected to an
  1706             existing network, then it SHOULD restart its discovery mechanisms as defined in the <a href=
  1707             "#service-discovery">Service Discovery</a> section of this specification, maintaining the existing <a>list
  1708             of active service managers</a> currently in use.
  1709           </p>
  1710         </div>
  1711       </section>
  1712     </section>
  1713     <section>
  1714       <h3>
  1715         Events Summary
  1716       </h3>
  1717       <p>
  1718         The following events are dispatched on the <a href="#networkservices"><code>NetworkServices</code></a> and/or
  1719         <a href="#networkservice"><code>NetworkService</code></a> objects:
  1720       </p>
  1721       <table border="1">
  1722         <thead>
  1723           <tr>
  1724             <th>
  1725               <span>Event name</span>
  1726             </th>
  1727             <th>
  1728               <span>Interface</span>
  1729             </th>
  1730             <th>
  1731               <span>Dispatched when...</span>
  1732             </th>
  1733           </tr>
  1734         </thead>
  1735         <tbody>
  1736           <tr>
  1737             <td>
  1738               <dfn id="event-serviceavailable"><code>serviceavailable</code></dfn>
  1739             </td>
  1740             <td>
  1741               <a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1742                   class="externalDFN"><code>Event</code></a>
  1743             </td>
  1744             <td>
  1745               When a <a>new service</a> that matches one of the <a>requested type tokens</a> is found in the current
  1746               network.
  1747             </td>
  1748           </tr>
  1749           <tr>
  1750             <td>
  1751               <dfn id="event-serviceunavailable"><code>serviceunavailable</code></dfn>
  1752             </td>
  1753             <td>
  1754               <a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1755                   class="externalDFN"><code>Event</code></a>
  1756             </td>
  1757             <td>
  1758               When an <a>existing service</a> that matches one of the <a>requested type tokens</a> gracefully leaves or
  1759               expires from the current network.
  1760             </td>
  1761           </tr>
  1762           <tr>
  1763             <td>
  1764               <dfn id="event-serviceonline"><code>serviceonline</code></dfn>
  1765             </td>
  1766             <td>
  1767               <a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1768                   class="externalDFN"><code>Event</code></a>
  1769             </td>
  1770             <td>
  1771               When a <a>current service</a> renews its service registration within the current network.
  1772             </td>
  1773           </tr>
  1774           <tr>
  1775             <td>
  1776               <dfn id="event-serviceoffline"><code>serviceoffline</code></dfn>
  1777             </td>
  1778             <td>
  1779               <a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1780                   class="externalDFN"><code>Event</code></a>
  1781             </td>
  1782             <td>
  1783               When a <a>current service</a> gracefully leaves or otherwise expires from the current network.
  1784             </td>
  1785           </tr>
  1786           <tr>
  1787             <td>
  1788               <dfn id="event-notify"><code>notify</code></dfn>
  1789             </td>
  1790             <td>
  1791               <a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1792                   class="externalDFN"><code>Event</code></a>
  1793             </td>
  1794             <td>
  1795               When a valid UPnP Events Subscription Message is received on a <a>user-agent generated callback url</a>
  1796               for a <a>current service</a>. This event never fires for Zeroconf-based services.
  1797             </td>
  1798           </tr>
  1799         </tbody>
  1800       </table>
  1801     </section>
  1802     <section>
  1803       <h3>
  1804         Garbage collection
  1805       </h3>
  1806       <p>
  1807         A user agent MUST only garbage collect a <a><code>NetworkServices</code></a> object and remove its entry from
  1808         the <a>list of active service managers</a> when the user has navigated away from the <a href=
  1809         "http://www.whatwg.org/specs/web-apps/current-work/complete/browsers.html#entry-script"
  1810            class="externalDFN">entry script</a>'s <a href=
  1811            "http://www.whatwg.org/specs/web-apps/current-work/complete/origin-0.html#origin"
  1812            class="externalDFN">origin</a> in which the current <a><code>NetworkServices</code></a> object was provided.
  1813       </p>
  1814       <p>
  1815         A user agent MUST NOT garbage collect individual <a><code>NetworkService</code></a> objects until their parent
  1816         <a><code>NetworkServices</code></a> object has been garbage collected.
  1817       </p>
  1818       <p>
  1819         A user agent MUST garbage collect the <a><code>NetworkService</code></a> <a>indexed properties</a> of a
  1820         <a><code>NetworkServices</code></a> object, passing each indexed property's <code>id</code> attribute as the
  1821         only argument to the rule for <a>removing an available service</a>, when that
  1822         <a><code>NetworkServices</code></a> object itself has been garbage-collected.
  1823       </p>
  1824     </section>
  1825     <section>
  1826       <h3>
  1827         Use Cases and Requirements
  1828       </h3>
  1829       <p>
  1830         This section covers what the requirements are for this API, as well as illustrates some use cases.
  1831       </p>
  1832       <ul class="rule">
  1833         <li>Once a user has given permission, user agents should provide the ability for Web pages to communicate
  1834         directly with a Local-networked Service.
  1835           <ul class="rule">
  1836             <li>Example: A web-based TV remote control. A Web page wants to control the current user's TV, changing the
  1837             programming shown or increasing/decreasing/muting the volume of the Local-networked Device. The Web page
  1838             requests a service type that is known to be implemented by television sets to which it has the application
  1839             logic to communicate. Local devices providing the request service types are discovered and presented to the
  1840             user for authorization. The user selects one or more of the discovered television sets to be accessible to
  1841             the current Web page and then clicks 'Share'. The Web page can now communicate directly with the
  1842             user-authorized Local-networked services.
  1843             </li>
  1844           </ul>
  1845         </li>
  1846         <li>Web pages should be able to communicate with Local-networked Services using the messaging channel supported
  1847         by those Devices.
  1848           <ul class="rule">
  1849             <li>Example: A Web page advertises that it is capable of controlling multiple Home Media Servers. The user
  1850             can select their Home Media Server type from a drop-down list, at which point the Web page sends a request
  1851             to the user agent to connect with the associated service type of the Home Media Server. The Media Server
  1852             selected implements a Web Socket channel for bi-directional service communication and so the Web page opens
  1853             a web socket to the requested Media Server and can communicate as required via that appropriate channel.
  1854             </li>
  1855           </ul>
  1856         </li>
  1857         <li>Web pages should be able to communicate with Local-networked Services using the messaging format supported
  1858         by those Devices.
  1859           <ul class="rule">
  1860             <li>Example: A Web page advertises that it is capable of interacting with and controlling multiple types of
  1861             Home Media Server. The user can select their Home Media Server type from a drop-down list or known Media
  1862             Servers, at which point the Web page sends a request to the user agent to connect with the associated
  1863             service type (and, optionally, the associated event type) of the Home Media Server. The communication
  1864             protocols supported by Home Media Servers typically vary between UPnP, JSON-RPC, Protocol Buffers or other
  1865             messaging formats depending on the Home Media Server requested. The Web page is able to communicate with
  1866             the user-selected Home Media Server in the messaging format supported by that Device, which, in this
  1867             example is a simple key/value pair text format.
  1868             </li>
  1869           </ul>
  1870         </li>
  1871         <li>Web pages should not be able to communicate with Local-networked Services that have not been authorized by
  1872         the user thereby maintaining the user's privacy.
  1873           <ul class="rule">
  1874             <li>Example: A Web page requests access to one type of Local-networked service. The user authorizes access
  1875             to that particular service. Other services running on that same device, and on other devices within the
  1876             network, should not be accessible to the current Web page.
  1877             </li>
  1878           </ul>
  1879         </li>
  1880         <li>A user should be able to share one or more Local-networked Services based on a particular service type
  1881         request from a Web page.
  1882           <ul class="rule">
  1883             <li>Example: A Web page is capable of interacting with a specific profile of Local-networked Service. As
  1884             such, it makes a request to the user agent to access those services, of which multiple matches are found.
  1885             The user is capable of selecting one or more of the discovered services to share with the Web page. The Web
  1886             page can then implement a drag-and-drop interface for the user to drag specific actions on to one or more
  1887             of the authorized Local-networked Services.
  1888             </li>
  1889           </ul>
  1890         </li>
  1891         <li>User agents should provide an API exposed to script that exposes the features above. The user is notified
  1892         by UI anytime interaction with Local-networked Services is requested, giving the user full ability to cancel or
  1893         abort the transaction. The user selects the Local-networked Services to be connected to the current Web page,
  1894         and can cancel these at any time. No invocations to these APIs occur silently without user intervention.
  1895         </li>
  1896       </ul>
  1897     </section>
  1898     <section class="informative appendix">
  1899       <h3>
  1900         Examples
  1901       </h3>
  1902       <div class="example">
  1903         <p>
  1904           This sample code exposes a button. When clicked, this button is disabled and the user is prompted to offer a
  1905           network service. The user may also select multiple network services. When the user has authorized a network
  1906           service to be connected to the web page then the web page issues a simple command to get a list of all the
  1907           albums stored on the connected media player service.
  1908         </p>
  1909         <p>
  1910           The button is re-enabled only when the connected network service disconnects for whatever reason (the service
  1911           becomes unavailable on the network, the user disconnects from their current network or the user revokes
  1912           access to the service from the current web page). At this point the user can re-click the button to select a
  1913           new network service to connect to the web page and the above steps are repeated.
  1914         </p>
  1915         <p>
  1916           The provided service type identifier and service interaction used in this example is based on the
  1917           well-defined service type and messaging format supported by the <a href="http://xbmc.org/about/">XBMC Media
  1918           Server</a>.
  1919         </p>
  1920         <hr>
  1921         <pre class="highlight">
  1922 &lt;input type="button" value="Start" onclick="start()" id="startBtn"/&gt;
  1923 &lt;div id="debugconsole"&gt;&lt;/div&gt;
  1924 
  1925 &lt;script&gt;
  1926  var startBtn = document.getElementById('startBtn'),
  1927      debug = document.getElementById('debugconsole');
  1928 
  1929  function start() {
  1930    if(navigator.getNetworkServices) {
  1931       navigator.getNetworkServices('zeroconf:_xbmc-jsonrpc._tcp').then(gotXBMCService).catch(error);
  1932       startBtn.disabled = true;
  1933    } else {
  1934       debug.innerHTML += "&lt;br&gt;Service Discovery not supported!";
  1935    }
  1936  }
  1937 
  1938  function gotXBMCService(services) {
  1939 
  1940 // Listen for service disconnect messages
  1941 
  1942    services[0].addEventListener('serviceoffline', function ( e ) {
  1943        debug.innerHTML += "&lt;br&gt;" + services[0].name + " disconnected.";
  1944        startBtn.disabled = false;
  1945    }, false);
  1946 
  1947 // Send a service message to get albums list (and process the service response)
  1948 
  1949    var svcXhr = new XMLHttpRequest();
  1950    svcXhr.open("POST", services[0].url + "/getAlbums"); // services[0].url and its sub-resources have been
  1951                                                         // whitelisted for cross-site XHR use in this
  1952                                                         // current browsing context.
  1953 
  1954    svcXhr.setRequestHeader('Content-Type', 'application/json-rpc');
  1955 
  1956    svcXhr.addEventListener('readystatechange', function ( response ) {
  1957      if( response.readyState != 4 || response.status != 200 )
  1958         return;
  1959      debug.innerHTML += "&lt;br&gt;" + services[0].name + " response received: ";
  1960      debug.textContent += JSON.parse(response.responseText);
  1961    }, false);
  1962 
  1963    var svcMsg = [
  1964      { "jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": { "genreid": -1,
  1965          "artistid": -1, "start": -1, "end": -1 }, "id": "1" }
  1966    ];
  1967 
  1968    svcXhr.send(JSON.stringify(svcMsg));
  1969    debug.innerHTML += "&lt;br&gt;" + services[0].name + " request sent: ";
  1970    debug.textContent += JSON.stringify(svcMsg);
  1971 
  1972  }
  1973 
  1974  function error( err ) {
  1975    debug.innerHTML += "&lt;br&gt;An error occurred obtaining a local network service.";
  1976    startBtn.disabled = false;
  1977  }
  1978 &lt;/script&gt;
  1979 </pre>
  1980       </div>
  1981       <div class="example">
  1982         <p>
  1983           This sample exposes a drop-down list containing a number of common Home-based audio devices. When the user
  1984           selects an audio device from the list provided, they are prompted to authorize a network service based on the
  1985           service type requested. The user may also select multiple network services matching the selected service
  1986           type. In this example, the user selects their make as being <var>Sony</var> and their model as being
  1987           <var>Bravia S1000</var> from which the Web page can derive a service type
  1988           (<var>urn:schemas-upnp-org:service:RenderingControl:1</var>).<br>
  1989           <br>
  1990           Once the user has authorized the device, the web page sends a simple mute command according to the messaging
  1991           format supported by the device.
  1992         </p>
  1993         <hr>
  1994         <pre class="highlight">
  1995 &lt;select name="make" id="make"&gt;
  1996   &lt;option selected="selected" disabled="disabled"&gt;Select make&lt;/option&gt;
  1997   &lt;option&gt;Sony&lt;/option&gt;
  1998   &lt;option&gt;Philips&lt;/option&gt;
  1999   &lt;option&gt;Alba&lt;/option&gt;
  2000 &lt;/select&gt;
  2001 &lt;select name="model" id="model"&gt;&lt;/select&gt;
  2002 &lt;div id="debugconsole"&gt;&lt;/div&gt;
  2003 
  2004 &lt;script&gt;
  2005   var debug = document.getElementById('debugconsole');
  2006 
  2007   var models = {
  2008     "Sony": [
  2009       {"name": "Bravia TV S1000", "type": "upnp", "service": "urn:schemas-upnp-org:service:RenderingControl:1" },
  2010       {"name": "Bravia TV S2000", "type": "zeroconf", "service": "_mediarenderer._http._tcp" },
  2011       {"name": "HiFi WD10", "type": "upnp", "service": "urn:schemas-upnp-org:service:RenderingControl:1" }
  2012     ],
  2013     "Philips": [ /* ... */ ],
  2014     "Alba": [ /* ... */ ]
  2015   };
  2016 
  2017   var makeEl = document.getElementById("make"),
  2018       modelEl = document.getElementById("model");
  2019 
  2020   makeEl.addEventListener('change', function() {
  2021     modelEl.innerHTML = ""; // reset
  2022     var defaultOption = document.createElement("option");
  2023     defaultOption.textContent = "Select model";
  2024     defaultOption.setAttribute("disabled", "disabled");
  2025     defaultOption.setAttribute("selected", "selected");
  2026     modelEl.appendChild(defaultOption);
  2027     for(var i = 0, l = models[makeEl.value].length; i &lt; l; i++) {
  2028       var option = document.createElement("option");
  2029       option.textContent = models[makeEl.value][i]["name"];
  2030       option.setAttribute("value", models[makeEl.value][i]["type"] + ":" + models[makeEl.value][i]["service"]);
  2031       modelEl.appendChild(option);
  2032     }
  2033   }, false);
  2034 
  2035   modelEl.addEventListener('change', function() {
  2036     if(navigator.getNetworkServices &amp;&amp;
  2037          modelEl.value == "upnp:urn:schemas-upnp-org:service:RenderingControl:1") {
  2038       var servicesPromise = navigator.getNetworkServices(modelEl.value).then(successCallback, errorCallback);
  2039     } else if (modelEl.value == "zeroconf:_mediarenderer._http._tcp") {
  2040       debug.innerHTML += "&lt;br&gt;Service type is not implemented by this application.";
  2041     } else {
  2042       debug.innerHTML += "&lt;br&gt;Service Discovery is not supported!";
  2043     }
  2044   }, false);
  2045 &lt;/script&gt;
  2046 
  2047 &lt;script&gt;
  2048   function successCallback( services ) {
  2049 
  2050   // Listen for service push notification messages
  2051 
  2052     services[0].addEventListener('notify', function ( msg ) {
  2053          debug.innerHTML += "&lt;br&gt;" + services[0].name + " event received: ";
  2054          debug.textContent += msg.data;
  2055     }, false);
  2056 
  2057  // Send a control signal to mute the service audio
  2058 
  2059     var svcXhr = new XMLHttpRequest();
  2060     svcXhr.open("POST", services[0].url); // services[0].url and its
  2061                                           // sub-resources have been whitelisted for
  2062                                           // cross-site XHR use in this current
  2063                                           // browsing context.
  2064 
  2065     svcXhr.setRequestHeader('SOAPAction', 'urn:schemas-upnp-org:service:RenderingControl:1#SetMute');
  2066     svcXhr.setRequestHeader('Content-Type', 'text/xml; charset="utf-8";');
  2067 
  2068     svcXhr.onreadystatechange = function ( response ) {
  2069       if( response.readyState != 4 || response.status != 200 )
  2070         return;
  2071       debug.innerHTML += "&lt;br&gt;" + services[0].name + " response received: ";
  2072       debug.textContent += response.responseXML;
  2073     }
  2074 
  2075     // Service messaging to mute the provided service
  2076     var svcMsg = '&lt;?xml version="1.0" encoding="utf-8"?&gt;' +
  2077                  '&lt;s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" ' +
  2078                    'xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;' +
  2079                    '&lt;s:Body&gt;' +
  2080                      '&lt;u:SetMute xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"&gt;' +
  2081                        '&lt;InstanceID&gt;0&lt;/InstanceID&gt;' +
  2082                        '&lt;Channel&gt;Master&lt;/Channel&gt;' +
  2083                        '&lt;DesiredMute&gt;true&lt;/DesiredMute&gt;' +
  2084                      '&lt;/u:SetMute&gt;' +
  2085                    '&lt;/s:Body&gt;' +
  2086                  '&lt;/s:Envelope&gt;';
  2087 
  2088     svcXhr.send(svcMsg);
  2089     debug.innerHTML += "&lt;br&gt;" + services[0].name + " request sent: ";
  2090     debug.textContent += svcMsg;
  2091   }
  2092 
  2093   function errorCallback( error ) {
  2094     debug.innerHTML += "&lt;br&gt;An error occurred: " + error.code;
  2095   }
  2096 &lt;/script&gt;
  2097 </pre>
  2098       </div>
  2099     </section>
  2100     <section>
  2101       <h3>
  2102         Acknowledgements
  2103       </h3>
  2104       <p>
  2105         Thanks are expressed by the editor to the following individuals for their feedback on this specification to
  2106         date (in alphabetical order):<br>
  2107         <br>
  2108         Gar Bergstedt, Lars-Erik Bolstad, Cathy Chan, Hari G Kumar, Bob Lund, Giuseppe Pascale, Marcin Simonides,
  2109         Clarke Stevens, Christian Söderström, Mark Vickers.
  2110       </p>
  2111       <p>
  2112         Thanks are also expressed by the editor to the following organizations and groups for their support in
  2113         producing this specification to date (in alphabetical order):<br>
  2114         <br>
  2115         CableLabs, Opera Software ASA, W3C Device APIs Working Group, W3C Web and TV Interest Group.
  2116       </p>
  2117     </section>
  2118   </body>
  2119 </html>