Bug 924571 - Address review comments for Shumway integration patch. r=gavin
authorYury Delendik <ydelendik@mozilla.com>
Thu, 17 Oct 2013 16:11:52 -0500
changeset 165220 93e324bc5330445d63fc276e1d9f009c16351743
parent 165219 54355463e47d21ccc2e72c81a9b1a8fe40d87640
child 165221 7b8172aea9ce83d9787bb4466adf997429e02a9d
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs924571
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 924571 - Address review comments for Shumway integration patch. r=gavin
browser/extensions/shumway/chrome.manifest
browser/extensions/shumway/components/FlashStreamConverter.js
browser/extensions/shumway/content/ShumwayStreamConverter.jsm
browser/extensions/shumway/content/ShumwayUtils.jsm
browser/extensions/shumway/content/version.txt
browser/extensions/shumway/content/web/avm-sandbox.js
browser/extensions/shumway/content/web/preview.js
--- a/browser/extensions/shumway/chrome.manifest
+++ b/browser/extensions/shumway/chrome.manifest
@@ -1,2 +1,1 @@
 resource shumway content/
-resource shumway.components components/
rename from browser/extensions/shumway/components/FlashStreamConverter.js
rename to browser/extensions/shumway/content/ShumwayStreamConverter.jsm
--- a/browser/extensions/shumway/components/FlashStreamConverter.js
+++ b/browser/extensions/shumway/content/ShumwayStreamConverter.jsm
@@ -13,24 +13,23 @@
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 'use strict';
 
-var EXPORTED_SYMBOLS = ['FlashStreamConverter1', 'FlashStreamConverter2'];
+var EXPORTED_SYMBOLS = ['ShumwayStreamConverter', 'ShumwayStreamOverlayConverter'];
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 const Cu = Components.utils;
 
-// True only if this is the version of pdf.js that is included with firefox.
 const SHUMWAY_CONTENT_TYPE = 'application/x-shockwave-flash';
 const EXPECTED_PLAYPREVIEW_URI_PREFIX = 'data:application/x-moz-playpreview;,' +
                                         SHUMWAY_CONTENT_TYPE;
 
 const FIREFOX_ID = '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}';
 const SEAMONKEY_ID = '{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}';
 
 const MAX_CLIPBOARD_DATA_SIZE = 8000;
@@ -61,17 +60,17 @@ function getStringPref(pref, def) {
   try {
     return Services.prefs.getComplexValue(pref, Ci.nsISupportsString).data;
   } catch (ex) {
     return def;
   }
 }
 
 function log(aMsg) {
-  let msg = 'FlashStreamConverter.js: ' + (aMsg.join ? aMsg.join('') : aMsg);
+  let msg = 'ShumwayStreamConverter.js: ' + (aMsg.join ? aMsg.join('') : aMsg);
   Services.console.logStringMessage(msg);
   dump(msg + '\n');
 }
 
 function getDOMWindow(aChannel) {
   var requestor = aChannel.notificationCallbacks;
   var win = requestor.getInterface(Components.interfaces.nsIDOMWindow);
   return win;
@@ -631,20 +630,20 @@ function initExternalCom(wrappedWindow, 
     };
   };
   wrappedObject.__flash__unregisterCallback = function (functionName) {
     wrappedWindow.console.log('__flash__unregisterCallback: ' + functionName);
     delete this[functionName];
   };
 }
 
-function FlashStreamConverterBase() {
+function ShumwayStreamConverterBase() {
 }
 
-FlashStreamConverterBase.prototype = {
+ShumwayStreamConverterBase.prototype = {
   QueryInterface: XPCOMUtils.generateQI([
       Ci.nsISupports,
       Ci.nsIStreamConverter,
       Ci.nsIStreamListener,
       Ci.nsIRequestObserver
   ]),
 
   /*
@@ -847,40 +846,37 @@ FlashStreamConverterBase.prototype = {
 
 // properties required for XPCOM registration:
 function copyProperties(obj, template) {
   for (var prop in template) {
     obj[prop] = template[prop];
   }
 }
 
-function FlashStreamConverter1() {}
-FlashStreamConverter1.prototype = new FlashStreamConverterBase();
-copyProperties(FlashStreamConverter1.prototype, {
+function ShumwayStreamConverter() {}
+ShumwayStreamConverter.prototype = new ShumwayStreamConverterBase();
+copyProperties(ShumwayStreamConverter.prototype, {
   classID: Components.ID('{4c6030f7-e20a-264f-5b0e-ada3a9e97384}'),
   classDescription: 'Shumway Content Converter Component',
   contractID: '@mozilla.org/streamconv;1?from=application/x-shockwave-flash&to=*/*'
 });
 
-function FlashStreamConverter2() {}
-FlashStreamConverter2.prototype = new FlashStreamConverterBase();
-copyProperties(FlashStreamConverter2.prototype, {
+function ShumwayStreamOverlayConverter() {}
+ShumwayStreamOverlayConverter.prototype = new ShumwayStreamConverterBase();
+copyProperties(ShumwayStreamOverlayConverter.prototype, {
   classID: Components.ID('{4c6030f7-e20a-264f-5f9b-ada3a9e97384}'),
   classDescription: 'Shumway PlayPreview Component',
   contractID: '@mozilla.org/streamconv;1?from=application/x-moz-playpreview&to=*/*'
 });
-FlashStreamConverter2.prototype.isValidRequest =
+ShumwayStreamOverlayConverter.prototype.isValidRequest =
   (function(aCtxt) {
     try {
       var request = aCtxt;
       request.QueryInterface(Ci.nsIChannel);
       var spec = request.URI.spec;
       return spec.indexOf(EXPECTED_PLAYPREVIEW_URI_PREFIX) === 0;
     } catch (e) {
       return false;
     }
   });
-FlashStreamConverter2.prototype.getUrlHint = function (requestUrl) {
+ShumwayStreamOverlayConverter.prototype.getUrlHint = function (requestUrl) {
   return '';
 };
-
-var NSGetFactory1 = XPCOMUtils.generateNSGetFactory([FlashStreamConverter1]);
-var NSGetFactory2 = XPCOMUtils.generateNSGetFactory([FlashStreamConverter2]);
--- a/browser/extensions/shumway/content/ShumwayUtils.jsm
+++ b/browser/extensions/shumway/content/ShumwayUtils.jsm
@@ -24,17 +24,17 @@ const PREF_IGNORE_CTP = PREF_PREFIX + 'i
 
 let Cc = Components.classes;
 let Ci = Components.interfaces;
 let Cm = Components.manager;
 let Cu = Components.utils;
 
 Cu.import('resource://gre/modules/XPCOMUtils.jsm');
 Cu.import('resource://gre/modules/Services.jsm');
-Cu.import('resource://shumway.components/FlashStreamConverter.js');
+Cu.import('resource://shumway/ShumwayStreamConverter.jsm');
 
 let Svc = {};
 XPCOMUtils.defineLazyServiceGetter(Svc, 'mime',
                                    '@mozilla.org/mime;1',
                                    'nsIMIMEService');
 XPCOMUtils.defineLazyServiceGetter(Svc, 'pluginHost',
                                    '@mozilla.org/plugin/host;1',
                                    'nsIPluginHost');
@@ -46,54 +46,40 @@ function getBoolPref(pref, def) {
     return def;
   }
 }
 
 function log(str) {
   dump(str + '\n');
 }
 
-// Register/unregister a constructor as a component.
+// Register/unregister a constructor as a factory.
 function Factory() {}
-
 Factory.prototype = {
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory]),
-  _targetConstructor: null,
+  register: function register(targetConstructor) {
+    var proto = targetConstructor.prototype;
+    this._classID = proto.classID;
 
-  register: function register(targetConstructor) {
-    this._targetConstructor = targetConstructor;
-    var proto = targetConstructor.prototype;
+    var factory = XPCOMUtils._getFactory(targetConstructor);
+    this._factory = factory;
+
     var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
     registrar.registerFactory(proto.classID, proto.classDescription,
-                              proto.contractID, this);
+                              proto.contractID, factory);
   },
 
   unregister: function unregister() {
-    var proto = this._targetConstructor.prototype;
     var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
-    registrar.unregisterFactory(proto.classID, this);
-    this._targetConstructor = null;
-  },
-
-  // nsIFactory
-  createInstance: function createInstance(aOuter, iid) {
-    if (aOuter !== null)
-      throw Cr.NS_ERROR_NO_AGGREGATION;
-    return (new (this._targetConstructor)).QueryInterface(iid);
-  },
-
-  // nsIFactory
-  lockFactory: function lockFactory(lock) {
-    // No longer used as of gecko 1.7.
-    throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+    registrar.unregisterFactory(this._classID, this._factory);
+    this._factory = null;
   }
 };
 
-let factory1 = new Factory();
-let factory2 = new Factory();
+let converterFactory = new Factory();
+let overlayConverterFactory = new Factory();
 
 let ShumwayUtils = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
   _registered: false,
 
   init: function init() {
     if (this.enabled)
       this._ensureRegistered();
@@ -108,48 +94,47 @@ let ShumwayUtils = {
   observe: function observe(aSubject, aTopic, aData) {
     if (this.enabled)
       this._ensureRegistered();
     else
       this._ensureUnregistered();
   },
   
   /**
-   * shumway is only enabled if it is both selected as the pdf viewer and if the 
-   * global switch enabling it is true.
+   * shumway is only enabled if the global switch enabling is true.
    * @return {boolean} Wether or not it's enabled.
    */
   get enabled() {
     return !getBoolPref(PREF_DISABLED, true);
   },
 
   _ensureRegistered: function _ensureRegistered() {
     if (this._registered)
       return;
 
     // Load the component and register it.
-    factory1.register(FlashStreamConverter1);
-    factory2.register(FlashStreamConverter2);
+    converterFactory.register(ShumwayStreamConverter);
+    overlayConverterFactory.register(ShumwayStreamOverlayConverter);
 
     var ignoreCTP = getBoolPref(PREF_IGNORE_CTP, true);
 
     Svc.pluginHost.registerPlayPreviewMimeType(SWF_CONTENT_TYPE, ignoreCTP);
 
     this._registered = true;
 
     log('Shumway is registered');
   },
 
   _ensureUnregistered: function _ensureUnregistered() {
     if (!this._registered)
       return;
 
     // Remove the contract/component.
-    factory1.unregister();
-    factory2.unregister();
+    converterFactory.unregister();
+    overlayConverterFactory.unregister();
 
     Svc.pluginHost.unregisterPlayPreviewMimeType(SWF_CONTENT_TYPE);
 
     this._registered = false;
 
     log('Shumway is unregistered');
   }
 };
--- a/browser/extensions/shumway/content/version.txt
+++ b/browser/extensions/shumway/content/version.txt
@@ -1,1 +1,1 @@
-0.7.351
+0.7.352
--- a/browser/extensions/shumway/content/web/avm-sandbox.js
+++ b/browser/extensions/shumway/content/web/avm-sandbox.js
@@ -11,17 +11,17 @@
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
-// Extension communication object... as it used in pdf.js
+// Extension communication object
 var FirefoxCom = (function FirefoxComClosure() {
   return {
     /**
      * Creates an event that the extension is listening for and will
      * synchronously respond to.
      * NOTE: It is reccomended to use request() instead since one day we may not
      * be able to synchronously reply.
      * @param {String} action The action to trigger.
--- a/browser/extensions/shumway/content/web/preview.js
+++ b/browser/extensions/shumway/content/web/preview.js
@@ -12,17 +12,17 @@
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 
-// Extenstion communication object... as it used in pdf.js
+// Extenstion communication object
 var FirefoxCom = (function FirefoxComClosure() {
   return {
     /**
      * Creates an event that the extension is listening for and will
      * synchronously respond to.
      * NOTE: It is reccomended to use request() instead since one day we may not
      * be able to synchronously reply.
      * @param {String} action The action to trigger.