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