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/. */
7 const Cc = Components.classes;
8 const Ci = Components.interfaces;
9 const Cu = Components.utils;
11 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
12 Cu.import("resource://gre/modules/Services.jsm");
14 XPCOMUtils.defineLazyGetter(this, "cpmm", function() {
15 return Cc["@mozilla.org/childprocessmessagemanager;1"]
16 .getService(Ci.nsIMessageSender);
19 function YoutubeProtocolHandler() {
22 YoutubeProtocolHandler.prototype = {
23 classID: Components.ID("{c3f1b945-7e71-49c8-95c7-5ae9cc9e2bad}"),
24 QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),
26 scheme: "vnd.youtube",
28 protocolFlags: Ci.nsIProtocolHandler.URI_NORELATIVE |
29 Ci.nsIProtocolHandler.URI_NOAUTH |
30 Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE,
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);
43 newChannel: function yt_phNewChannel(aURI) {
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
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
56 throw Components.results.NS_ERROR_ILLEGAL_VALUE;
59 allowPort: function yt_phAllowPort(aPort, aScheme) {
64 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([YoutubeProtocolHandler]);