|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 const Cc = Components.classes; |
|
8 const Ci = Components.interfaces; |
|
9 const Cu = Components.utils; |
|
10 |
|
11 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
12 Cu.import("resource://gre/modules/Services.jsm"); |
|
13 |
|
14 XPCOMUtils.defineLazyGetter(this, "cpmm", function() { |
|
15 return Cc["@mozilla.org/childprocessmessagemanager;1"] |
|
16 .getService(Ci.nsIMessageSender); |
|
17 }); |
|
18 |
|
19 function YoutubeProtocolHandler() { |
|
20 } |
|
21 |
|
22 YoutubeProtocolHandler.prototype = { |
|
23 classID: Components.ID("{c3f1b945-7e71-49c8-95c7-5ae9cc9e2bad}"), |
|
24 QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]), |
|
25 |
|
26 scheme: "vnd.youtube", |
|
27 defaultPort: -1, |
|
28 protocolFlags: Ci.nsIProtocolHandler.URI_NORELATIVE | |
|
29 Ci.nsIProtocolHandler.URI_NOAUTH | |
|
30 Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE, |
|
31 |
|
32 // Sample URL: |
|
33 // vnd.youtube:iNuKL2Gy_QM?vndapp=youtube_mobile&vndclient=mv-google&vndel=watch&vnddnc=1 |
|
34 // Note that there is no hostname, so we use URLTYPE_NO_AUTHORITY |
|
35 newURI: function yt_phNewURI(aSpec, aOriginCharset, aBaseURI) { |
|
36 let uri = Cc["@mozilla.org/network/standard-url;1"] |
|
37 .createInstance(Ci.nsIStandardURL); |
|
38 uri.init(Ci.nsIStandardURL.URLTYPE_NO_AUTHORITY, this.defaultPort, |
|
39 aSpec, aOriginCharset, aBaseURI); |
|
40 return uri.QueryInterface(Ci.nsIURI); |
|
41 }, |
|
42 |
|
43 newChannel: function yt_phNewChannel(aURI) { |
|
44 /* |
|
45 * This isn't a real protocol handler. Instead of creating a channel |
|
46 * we just send a message and throw an exception. This 'content-handler' |
|
47 * message is handled in b2g/chrome/content/shell.js where it starts |
|
48 * an activity request that will open the Video app. The video app |
|
49 * includes code to handle this fake 'video/youtube' mime type |
|
50 */ |
|
51 cpmm.sendAsyncMessage("content-handler", { |
|
52 type: 'video/youtube', // A fake MIME type for the activity handler |
|
53 url: aURI.spec // The path component of this URL is the video id |
|
54 }); |
|
55 |
|
56 throw Components.results.NS_ERROR_ILLEGAL_VALUE; |
|
57 }, |
|
58 |
|
59 allowPort: function yt_phAllowPort(aPort, aScheme) { |
|
60 return false; |
|
61 } |
|
62 }; |
|
63 |
|
64 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([YoutubeProtocolHandler]); |