Bug 1167197 - Fix GMPProvider on Android r=cpearce
authorJames Willcox <snorp@snorp.net>
Thu, 21 May 2015 11:42:07 -0500
changeset 245193 9e140d3141a83c975051d9384bf1566461adb069
parent 245192 09f33ee98374870f4619c9c6c8e6ac90c7db5a99
child 245194 5b0d7c8c9cdaf61670a11ba50aedf73e9f861e6a
push id28799
push userphilringnalda@gmail.com
push dateSat, 23 May 2015 20:31:44 +0000
treeherdermozilla-central@c3c0928c3cde [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1167197
milestone41.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 1167197 - Fix GMPProvider on Android r=cpearce
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
@@ -153,15 +153,18 @@ this.AppConstants = Object.freeze({
 
   DEBUG:
 #ifdef DEBUG
   true,
 #else
   false,
 #endif
 
+  DLL_PREFIX: "@DLL_PREFIX@",
+  DLL_SUFFIX: "@DLL_SUFFIX@",
+
   MOZ_APP_NAME: "@MOZ_APP_NAME@",
   MOZ_APP_VERSION: "@MOZ_APP_VERSION@",
   MOZ_BUILD_APP: "@MOZ_BUILD_APP@",
   MOZ_UPDATE_CHANNEL: "@MOZ_UPDATE_CHANNEL@",
   MOZ_WIDGET_TOOLKIT: "@MOZ_WIDGET_TOOLKIT@",
   ANDROID_PACKAGE_NAME: "@ANDROID_PACKAGE_NAME@",
 });
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -92,16 +92,18 @@ 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_WIDGET_TOOLKIT'):
+            'MOZ_WIDGET_TOOLKIT',
+            'DLL_PREFIX',
+            'DLL_SUFFIX'):
             DEFINES[var] = CONFIG[var]
 
 for var in ('MOZILLA_OFFICIAL',
             'MOZ_TOOLKIT_SEARCH',
             'MOZ_UPDATER'):
     if CONFIG[var]:
         DEFINES[var] = True
--- 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 id = aPluginId.substring(4);
+  let libName = AppConstants.DLL_PREFIX + id + AppConstants.DLL_SUFFIX;
 
-  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;
-  }
   createFile(libName);
-  createFile(aPluginId.substring(4) + ".info");
+  createFile(id + ".info");
 }
 
 // Array.includes() is only in Nightly channel, so polyfill so we don't fail
 // on other branches.
 if (![].includes) {
   Array.prototype.includes = function(element) {
     return Object(this).indexOf(element) != -1;
   }