Bug 1167197 - Fix GMPProvider on Android r=cpearce a=lizzard
authorJames Willcox <snorp@snorp.net>
Thu, 21 May 2015 11:42:07 -0500
changeset 266181 e2ed03987d19
parent 266180 59793d7e1b7e
child 266182 49e75ecb84f8
push id4777
push usercpearce@mozilla.com
push date2015-06-04 02:16 +0000
treeherdermozilla-beta@e2ed03987d19 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, lizzard
bugs1167197
milestone39.0
Bug 1167197 - Fix GMPProvider on Android r=cpearce a=lizzard
toolkit/modules/AppConstants.jsm
toolkit/modules/moz.build
toolkit/mozapps/extensions/internal/GMPProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js
--- a/toolkit/modules/AppConstants.jsm
+++ b/toolkit/modules/AppConstants.jsm
@@ -110,12 +110,15 @@ let AppConstants = Object.freeze({
 
   E10S_TESTING_ONLY:
 #ifdef E10S_TESTING_ONLY
   true,
 #else
   false,
 #endif
 
+  DLL_PREFIX: "@DLL_PREFIX@",
+  DLL_SUFFIX: "@DLL_SUFFIX@",
+
   MOZ_APP_VERSION: "@MOZ_APP_VERSION@",
 
   ANDROID_PACKAGE_NAME: "@ANDROID_PACKAGE_NAME@",
 });
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -88,17 +88,19 @@ else:
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
     EXTRA_JS_MODULES += [
         'WindowsRegistry.jsm',
     ]
 
 for var in ('ANDROID_PACKAGE_NAME',
             'MOZ_APP_NAME',
-            'MOZ_APP_VERSION'):
+            'MOZ_APP_VERSION',
+            'DLL_PREFIX',
+            'DLL_SUFFIX'):
             DEFINES[var] = CONFIG[var]
 
 for var in ('MOZILLA_OFFICIAL',
             'MOZ_TOOLKIT_SEARCH'):
     if CONFIG[var]:
         DEFINES[var] = True
 
 EXTRA_PP_JS_MODULES += [
--- a/toolkit/mozapps/extensions/internal/GMPProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/GMPProvider.jsm
@@ -13,16 +13,17 @@ this.EXPORTED_SYMBOLS = [];
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/AddonManager.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/osfile.jsm");
 Cu.import("resource://gre/modules/Log.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/GMPUtils.jsm");
+Cu.import("resource://gre/modules/AppConstants.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(
   this, "GMPInstallManager", "resource://gre/modules/GMPInstallManager.jsm");
 XPCOMUtils.defineLazyModuleGetter(
   this, "setTimeout", "resource://gre/modules/Timer.jsm");
 
 const URI_EXTENSION_STRINGS  = "chrome://mozapps/locale/extensions/extensions.properties";
 const STRING_TYPE_NAME       = "type.%ID%.name";
@@ -459,38 +460,21 @@ GMPWrapper.prototype = {
   _arePluginFilesOnDisk: function () {
     let fileExists = function(aGmpPath, aFileName) {
       let f = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
       let path = OS.Path.join(aGmpPath, aFileName);
       f.initWithPath(path);
       return f.exists();
     };
 
-    // Determine the name of the GMP dynamic library; it differs on every
-    // platform. Note: we can't use Services.appInfo.OS here, as that's
-    // "XPCShell" in our tests.
-    let isWindows = ("@mozilla.org/windows-registry-key;1" in Cc);
-    let isOSX = ("nsILocalFileMac" in Ci);
-    let isLinux = ("@mozilla.org/gnome-gconf-service;1" in Cc);
-
-    let libName = "";
-    let id = this._plugin.id;
-    if (isWindows) {
-      libName = id.substring(4) + ".dll";
-    } else if (isOSX) {
-      libName = "lib" + id.substring(4) + ".dylib";
-    } else if (isLinux) {
-      libName = id.substring(4) + ".so";
-    } else {
-      this._info.error("_arePluginFilesOnDisk - unsupported platform.");
-      return false;
-    }
+    let id = this._plugin.id.substring(4);
+    let libName = AppConstants.DLL_PREFIX + id + AppConstants.DLL_SUFFIX;
 
     return fileExists(this.gmpPath, libName) &&
-           fileExists(this.gmpPath, id.substring(4) + ".info");
+           fileExists(this.gmpPath, id + ".info");
   },
 
   validate: function() {
     return !this.isInstalled ||
            this._arePluginFilesOnDisk();
   },
 };
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js
@@ -1,15 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 let GMPScope = Cu.import("resource://gre/modules/addons/GMPProvider.jsm");
+Cu.import("resource://gre/modules/AppConstants.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "pluginsBundle",
   () => Services.strings.createBundle("chrome://global/locale/plugins.properties"));
 
 XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
                                   "resource://gre/modules/FileUtils.jsm");
 
 let gMockAddons = new Map();
@@ -224,34 +225,21 @@ function createMockPluginFilesIfNeeded(a
   function createFile(aFileName) {
     let f = aFile.clone();
     f.append(aFileName);
     if (!f.exists()) {
       f.create(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
     }
   };
 
-  // Note: we can't use Services.appInfo.OS, as that's "XPCShell" in our tests.
-  let isWindows = ("@mozilla.org/windows-registry-key;1" in Components.classes);
-  let isOSX = ("nsILocalFileMac" in Components.interfaces);
-  let isLinux = ("@mozilla.org/gnome-gconf-service;1" in Components.classes);
-
-  let libName = "";
-  if (isWindows) {
-    libName = aPluginId.substring(4) + ".dll";
-  } else if (isOSX) {
-    libName = "lib" + aPluginId.substring(4) + ".dylib";
-  } else if (isLinux) {
-    libName = aPluginId.substring(4) + ".so";
-  } else {
-    // FAIL!
-    return;
-  }
+  let id = aPluginId.substring(4);
+  let libName = AppConstants.DLL_PREFIX + id + AppConstants.DLL_SUFFIX;
+  
   createFile(libName);
-  createFile(aPluginId.substring(4) + ".info");
+  createFile(id + ".info");
 }
 
 // Array.includes is only in 41, so polyfill for 40/39 uplift.
 if (![].includes) {
   Array.prototype.includes = function(element) {
     var O = Object(this);
     return O.indexOf(element) != -1;
   }