From 3dc926d6daaa23adb23288a3d34ecde169ea2d08 Mon Sep 17 00:00:00 2001 From: Gabor Krizsanits Date: Thu, 7 May 2015 14:01:43 +0200 Subject: [PATCH] Bug 1148188 - part1: defaultShims. r=billm --- js/xpconnect/src/XPCWrappedNativeScope.cpp | 11 ++++++- .../addoncompat/addoncompat.manifest | 2 ++ .../components/addoncompat/defaultShims.js | 30 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 toolkit/components/addoncompat/defaultShims.js diff --git a/js/xpconnect/src/XPCWrappedNativeScope.cpp b/js/xpconnect/src/XPCWrappedNativeScope.cpp index 1d31097e0854..a524f1bea4af 100644 --- a/js/xpconnect/src/XPCWrappedNativeScope.cpp +++ b/js/xpconnect/src/XPCWrappedNativeScope.cpp @@ -131,10 +131,19 @@ XPCWrappedNativeScope::XPCWrappedNativeScope(JSContext* cx, JSAddonId* addonId = JS::AddonIdOfObject(aGlobal); if (gInterpositionMap) { + bool isSystem = nsContentUtils::IsSystemPrincipal(principal); if (InterpositionMap::Ptr p = gInterpositionMap->lookup(addonId)) { - MOZ_RELEASE_ASSERT(nsContentUtils::IsSystemPrincipal(principal)); + MOZ_RELEASE_ASSERT(isSystem); mInterposition = p->value(); } + // We also want multiprocessCompatible add-ons to have a default interposition. + if (!mInterposition && addonId && isSystem) { + bool interpositionEnabled = mozilla::Preferences::GetBool( + "extensions.interposition.enabled", false); + if (interpositionEnabled) { + mInterposition = do_GetService("@mozilla.org/addons/default-addon-shims;1"); + } + } } } diff --git a/toolkit/components/addoncompat/addoncompat.manifest b/toolkit/components/addoncompat/addoncompat.manifest index 4273bf246c30..4228c8a1a09c 100644 --- a/toolkit/components/addoncompat/addoncompat.manifest +++ b/toolkit/components/addoncompat/addoncompat.manifest @@ -1,4 +1,6 @@ component {1363d5f0-d95e-11e3-9c1a-0800200c9a66} multiprocessShims.js contract @mozilla.org/addons/multiprocess-shims;1 {1363d5f0-d95e-11e3-9c1a-0800200c9a66} +component {50bc93ce-602a-4bef-bf3a-61fc749c4caf} defaultShims.js +contract @mozilla.org/addons/default-addon-shims;1 {50bc93ce-602a-4bef-bf3a-61fc749c4caf} component {dfd07380-6083-11e4-9803-0800200c9a66} remoteTagService.js contract @mozilla.org/addons/remote-tag-service;1 {dfd07380-6083-11e4-9803-0800200c9a66} diff --git a/toolkit/components/addoncompat/defaultShims.js b/toolkit/components/addoncompat/defaultShims.js new file mode 100644 index 000000000000..8baf29a00a3d --- /dev/null +++ b/toolkit/components/addoncompat/defaultShims.js @@ -0,0 +1,30 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const Cu = Components.utils; +const Ci = Components.interfaces; + +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); + +/** + * Using multiprocessShims is optional, and if an add-on is e10s compatible it should not + * use it. But in some cases we still want to use the interposition service for various + * features so we have a default shim service. + */ + +function DefaultInterpositionService() { +} + +DefaultInterpositionService.prototype = { + classID: Components.ID("{50bc93ce-602a-4bef-bf3a-61fc749c4caf}"), + QueryInterface: XPCOMUtils.generateQI([Ci.nsIAddonInterposition, Ci.nsISupportsWeakReference]), + + interpose: function(addon, target, iid, prop) { + return null; + }, +}; + +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DefaultInterpositionService]);