mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Backed out changeset 0ce1cc39aa3d (bug 1295082) for timing out in test_ext_schemas_api_injection.js. r=backout
This commit is contained in:
parent
3b39ae834c
commit
2164cd95c8
@ -77,7 +77,7 @@ function convert(result) {
|
||||
return node;
|
||||
}
|
||||
|
||||
extensions.registerSchemaAPI("bookmarks", context => {
|
||||
extensions.registerSchemaAPI("bookmarks", (extension, context) => {
|
||||
return {
|
||||
bookmarks: {
|
||||
get: function(idOrIdList) {
|
||||
|
@ -259,8 +259,7 @@ extensions.on("shutdown", (type, extension) => {
|
||||
});
|
||||
/* eslint-enable mozilla/balanced-listeners */
|
||||
|
||||
extensions.registerSchemaAPI("browserAction", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("browserAction", (extension, context) => {
|
||||
return {
|
||||
browserAction: {
|
||||
onClicked: new EventManager(context, "browserAction.onClicked", fire => {
|
||||
|
@ -228,8 +228,7 @@ extensions.on("shutdown", (type, extension) => {
|
||||
});
|
||||
/* eslint-enable mozilla/balanced-listeners */
|
||||
|
||||
extensions.registerSchemaAPI("commands", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("commands", (extension, context) => {
|
||||
return {
|
||||
commands: {
|
||||
getAll() {
|
||||
|
@ -485,8 +485,7 @@ extensions.on("shutdown", (type, extension) => {
|
||||
});
|
||||
/* eslint-enable mozilla/balanced-listeners */
|
||||
|
||||
extensions.registerSchemaAPI("contextMenus", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("contextMenus", (extension, context) => {
|
||||
return {
|
||||
contextMenus: {
|
||||
create: function(createProperties, callback) {
|
||||
|
@ -130,7 +130,7 @@ function getObserver() {
|
||||
return _observer;
|
||||
}
|
||||
|
||||
extensions.registerSchemaAPI("history", context => {
|
||||
extensions.registerSchemaAPI("history", (extension, context) => {
|
||||
return {
|
||||
history: {
|
||||
addUrl: function(details) {
|
||||
|
@ -217,8 +217,7 @@ PageAction.for = extension => {
|
||||
|
||||
global.pageActionFor = PageAction.for;
|
||||
|
||||
extensions.registerSchemaAPI("pageAction", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("pageAction", (extension, context) => {
|
||||
return {
|
||||
pageAction: {
|
||||
onClicked: new EventManager(context, "pageAction.onClicked", fire => {
|
||||
|
@ -264,8 +264,7 @@ let tabListener = {
|
||||
},
|
||||
};
|
||||
|
||||
extensions.registerSchemaAPI("tabs", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("tabs", (extension, context) => {
|
||||
let self = {
|
||||
tabs: {
|
||||
onActivated: new WindowEventManager(context, "tabs.onActivated", "TabSelect", (fire, event) => {
|
||||
|
@ -15,8 +15,7 @@ var {
|
||||
EventManager,
|
||||
} = ExtensionUtils;
|
||||
|
||||
extensions.registerSchemaAPI("windows", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("windows", (extension, context) => {
|
||||
return {
|
||||
windows: {
|
||||
onCreated:
|
||||
|
@ -117,8 +117,7 @@ extensions.on("shutdown", (type, extension) => {
|
||||
});
|
||||
/* eslint-enable mozilla/balanced-listeners */
|
||||
|
||||
extensions.registerSchemaAPI("pageAction", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("pageAction", (extension, context) => {
|
||||
return {
|
||||
pageAction: {
|
||||
onClicked: new SingletonEventManager(context, "pageAction.onClicked", fire => {
|
||||
|
@ -187,7 +187,7 @@ var Management = {
|
||||
|
||||
// Mash together into a single object all the APIs registered by the
|
||||
// functions above. Return the merged object.
|
||||
generateAPIs(context, apis, namespaces = null) {
|
||||
generateAPIs(extension, context, apis, namespaces = null) {
|
||||
let obj = {};
|
||||
|
||||
// Recursively copy properties from source to dest.
|
||||
@ -210,16 +210,16 @@ var Management = {
|
||||
continue;
|
||||
}
|
||||
if (api.permission) {
|
||||
if (!context.extension.hasPermission(api.permission)) {
|
||||
if (!extension.hasPermission(api.permission)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
api = api.api(context);
|
||||
api = api.api(extension, context);
|
||||
copy(obj, api);
|
||||
}
|
||||
|
||||
for (let api of context.extension.apis) {
|
||||
for (let api of extension.apis) {
|
||||
copy(obj, api.getAPI(context));
|
||||
}
|
||||
|
||||
@ -254,9 +254,10 @@ var Management = {
|
||||
// |incognito| is the content running in a private context (default: false).
|
||||
ExtensionContext = class extends BaseContext {
|
||||
constructor(extension, params) {
|
||||
super(extension);
|
||||
super(extension.id);
|
||||
|
||||
let {type, uri} = params;
|
||||
this.extension = extension;
|
||||
this.type = type;
|
||||
this.uri = uri || extension.baseURI;
|
||||
this.incognito = params.incognito || false;
|
||||
@ -334,7 +335,7 @@ class ProxyContext extends ExtensionContext {
|
||||
this.principal_ = principal;
|
||||
|
||||
this.apiObj = {};
|
||||
GlobalManager.injectInObject(this, null, this.apiObj, ["storage", "test"]);
|
||||
GlobalManager.injectInObject(extension, this, null, this.apiObj, ["storage", "test"]);
|
||||
|
||||
this.listenerProxies = new Map();
|
||||
|
||||
@ -634,11 +635,11 @@ GlobalManager = {
|
||||
return this.extensionMap.get(extensionId);
|
||||
},
|
||||
|
||||
injectInObject(context, defaultCallback, dest, namespaces = null) {
|
||||
let api = Management.generateAPIs(context, Management.apis, namespaces);
|
||||
injectInObject(extension, context, defaultCallback, dest, namespaces = null) {
|
||||
let api = Management.generateAPIs(extension, context, Management.apis, namespaces);
|
||||
injectAPI(api, dest);
|
||||
|
||||
let schemaApi = Management.generateAPIs(context, Management.schemaApis, namespaces);
|
||||
let schemaApi = Management.generateAPIs(extension, context, Management.schemaApis, namespaces);
|
||||
|
||||
// Add in any extra API namespaces which do not have implementations
|
||||
// outside of their schema file.
|
||||
@ -654,7 +655,7 @@ GlobalManager = {
|
||||
},
|
||||
|
||||
hasPermission(permission) {
|
||||
return context.extension.hasPermission(permission);
|
||||
return extension.hasPermission(permission);
|
||||
},
|
||||
|
||||
callFunction(path, name, args) {
|
||||
@ -717,14 +718,14 @@ GlobalManager = {
|
||||
return;
|
||||
}
|
||||
|
||||
let inject = context => {
|
||||
let inject = (extension, context) => {
|
||||
// We create two separate sets of bindings, one for the `chrome`
|
||||
// global, and one for the `browser` global. The latter returns
|
||||
// Promise objects if a callback is not passed, while the former
|
||||
// does not.
|
||||
let injectObject = (name, defaultCallback) => {
|
||||
let browserObj = Cu.createObjectIn(contentWindow, {defineAs: name});
|
||||
this.injectInObject(context, defaultCallback, browserObj);
|
||||
this.injectInObject(extension, context, defaultCallback, browserObj);
|
||||
};
|
||||
|
||||
injectObject("browser", null);
|
||||
@ -773,7 +774,7 @@ GlobalManager = {
|
||||
let incognito = PrivateBrowsingUtils.isContentWindowPrivate(contentWindow);
|
||||
|
||||
let context = new ExtensionContext(extension, {type, contentWindow, uri, docShell, incognito});
|
||||
inject(context);
|
||||
inject(extension, context);
|
||||
if (type == "background") {
|
||||
this._initializeBackgroundPage(contentWindow);
|
||||
}
|
||||
|
@ -312,12 +312,14 @@ var ExtensionManager;
|
||||
// Cu.Sandbox to run the code. There is a separate scope for each
|
||||
// frame.
|
||||
class ExtensionContext extends BaseContext {
|
||||
constructor(extension, contentWindow, contextOptions = {}) {
|
||||
super(extension);
|
||||
constructor(extensionId, contentWindow, contextOptions = {}) {
|
||||
super(extensionId);
|
||||
|
||||
let {isExtensionPage} = contextOptions;
|
||||
|
||||
this.isExtensionPage = isExtensionPage;
|
||||
this.extension = ExtensionManager.get(extensionId);
|
||||
this.extensionId = extensionId;
|
||||
|
||||
this.setContentWindow(contentWindow);
|
||||
|
||||
@ -336,7 +338,7 @@ class ExtensionContext extends BaseContext {
|
||||
// copy origin attributes from the content window origin attributes to
|
||||
// preserve the user context id. overwrite the addonId.
|
||||
let attrs = contentPrincipal.originAttributes;
|
||||
attrs.addonId = this.extensionId;
|
||||
attrs.addonId = extensionId;
|
||||
let extensionPrincipal = ssm.createCodebasePrincipal(this.extension.baseURI, attrs);
|
||||
Object.defineProperty(this, "principal",
|
||||
{value: extensionPrincipal, enumerable: true, configurable: true});
|
||||
@ -350,7 +352,7 @@ class ExtensionContext extends BaseContext {
|
||||
}
|
||||
|
||||
if (isExtensionPage) {
|
||||
if (ExtensionManagement.getAddonIdForWindow(this.contentWindow) != this.extensionId) {
|
||||
if (ExtensionManagement.getAddonIdForWindow(this.contentWindow) != extensionId) {
|
||||
throw new Error("Invalid target window for this extension context");
|
||||
}
|
||||
// This is an iframe with content script API enabled and its principal should be the
|
||||
@ -398,7 +400,7 @@ class ExtensionContext extends BaseContext {
|
||||
let sender = {id: this.extension.uuid, frameId, url};
|
||||
// Properties in |filter| must match those in the |recipient|
|
||||
// parameter of sendMessage.
|
||||
let filter = {extensionId: this.extensionId, frameId};
|
||||
let filter = {extensionId, frameId};
|
||||
this.messenger = new Messenger(this, [mm], sender, filter, delegate);
|
||||
|
||||
this.chromeObj = Cu.createObjectIn(this.sandbox, {defineAs: "browser"});
|
||||
@ -530,11 +532,9 @@ DocumentManager = {
|
||||
const {CONTENTSCRIPT_PRIVILEGES} = ExtensionManagement.API_LEVELS;
|
||||
let extensionId = ExtensionManagement.getAddonIdForWindow(window);
|
||||
|
||||
if (ExtensionManagement.getAPILevelForWindow(window, extensionId) == CONTENTSCRIPT_PRIVILEGES) {
|
||||
let extension = ExtensionManager.get(extensionId);
|
||||
if (extension) {
|
||||
DocumentManager.getExtensionPageContext(extension, window);
|
||||
}
|
||||
if (ExtensionManagement.getAPILevelForWindow(window, extensionId) == CONTENTSCRIPT_PRIVILEGES &&
|
||||
ExtensionManager.get(extensionId)) {
|
||||
DocumentManager.getExtensionPageContext(extensionId, window);
|
||||
}
|
||||
|
||||
this.trigger("document_start", window);
|
||||
@ -594,7 +594,7 @@ DocumentManager = {
|
||||
let script = new Script(extension, options, deferred);
|
||||
|
||||
if (script.matches(window)) {
|
||||
let context = this.getContentScriptContext(extension, window);
|
||||
let context = this.getContentScriptContext(extensionId, window);
|
||||
context.addScript(script);
|
||||
return deferred.promise;
|
||||
}
|
||||
@ -642,27 +642,27 @@ DocumentManager = {
|
||||
return [];
|
||||
},
|
||||
|
||||
getContentScriptContext(extension, window) {
|
||||
getContentScriptContext(extensionId, window) {
|
||||
let winId = getInnerWindowID(window);
|
||||
if (!this.contentScriptWindows.has(winId)) {
|
||||
this.contentScriptWindows.set(winId, new Map());
|
||||
}
|
||||
|
||||
let extensions = this.contentScriptWindows.get(winId);
|
||||
if (!extensions.has(extension.id)) {
|
||||
let context = new ExtensionContext(extension, window);
|
||||
extensions.set(extension.id, context);
|
||||
if (!extensions.has(extensionId)) {
|
||||
let context = new ExtensionContext(extensionId, window);
|
||||
extensions.set(extensionId, context);
|
||||
}
|
||||
|
||||
return extensions.get(extension.id);
|
||||
return extensions.get(extensionId);
|
||||
},
|
||||
|
||||
getExtensionPageContext(extension, window) {
|
||||
getExtensionPageContext(extensionId, window) {
|
||||
let winId = getInnerWindowID(window);
|
||||
|
||||
let context = this.extensionPageWindows.get(winId);
|
||||
if (!context) {
|
||||
let context = new ExtensionContext(extension, window, {isExtensionPage: true});
|
||||
let context = new ExtensionContext(extensionId, window, {isExtensionPage: true});
|
||||
this.extensionPageWindows.set(winId, context);
|
||||
}
|
||||
|
||||
@ -683,7 +683,7 @@ DocumentManager = {
|
||||
for (let window of this.enumerateWindows(global.docShell)) {
|
||||
for (let script of extension.scripts) {
|
||||
if (script.matches(window)) {
|
||||
let context = this.getContentScriptContext(extension, window);
|
||||
let context = this.getContentScriptContext(extensionId, window);
|
||||
context.addScript(script);
|
||||
}
|
||||
}
|
||||
@ -721,10 +721,10 @@ DocumentManager = {
|
||||
let state = this.getWindowState(window);
|
||||
|
||||
if (state == "document_start") {
|
||||
for (let extension of ExtensionManager.extensions.values()) {
|
||||
for (let [extensionId, extension] of ExtensionManager.extensions) {
|
||||
for (let script of extension.scripts) {
|
||||
if (script.matches(window)) {
|
||||
let context = this.getContentScriptContext(extension, window);
|
||||
let context = this.getContentScriptContext(extensionId, window);
|
||||
context.addScript(script);
|
||||
}
|
||||
}
|
||||
|
@ -162,14 +162,13 @@ class SpreadArgs extends Array {
|
||||
let gContextId = 0;
|
||||
|
||||
class BaseContext {
|
||||
constructor(extension) {
|
||||
constructor(extensionId) {
|
||||
this.onClose = new Set();
|
||||
this.checkedLastError = false;
|
||||
this._lastError = null;
|
||||
this.contextId = `${++gContextId}-${Services.appinfo.uniqueProcessID}`;
|
||||
this.unloaded = false;
|
||||
this.extension = extension;
|
||||
this.extensionId = extension.id;
|
||||
this.extensionId = extensionId;
|
||||
this.jsonSandbox = null;
|
||||
this.active = true;
|
||||
|
||||
|
@ -93,8 +93,7 @@ extensions.on("shutdown", (type, extension) => {
|
||||
});
|
||||
/* eslint-enable mozilla/balanced-listeners */
|
||||
|
||||
extensions.registerSchemaAPI("alarms", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("alarms", (extension, context) => {
|
||||
return {
|
||||
alarms: {
|
||||
create: function(name, alarmInfo) {
|
||||
|
@ -143,8 +143,7 @@ extensions.on("shutdown", (type, extension) => {
|
||||
});
|
||||
/* eslint-enable mozilla/balanced-listeners */
|
||||
|
||||
extensions.registerSchemaAPI("extension", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("extension", (extension, context) => {
|
||||
return {
|
||||
extension: {
|
||||
getBackgroundPage: function() {
|
||||
|
@ -238,8 +238,7 @@ function* query(detailsIn, props, extension) {
|
||||
}
|
||||
}
|
||||
|
||||
extensions.registerSchemaAPI("cookies", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("cookies", (extension, context) => {
|
||||
let self = {
|
||||
cookies: {
|
||||
get: function(details) {
|
||||
|
@ -386,8 +386,7 @@ function queryHelper(query) {
|
||||
});
|
||||
}
|
||||
|
||||
extensions.registerSchemaAPI("downloads", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("downloads", (extension, context) => {
|
||||
return {
|
||||
downloads: {
|
||||
download(options) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
extensions.registerSchemaAPI("extension", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("extension", (extension, context) => {
|
||||
return {
|
||||
extension: {
|
||||
getURL: function(url) {
|
||||
|
@ -7,8 +7,7 @@ var {
|
||||
detectLanguage,
|
||||
} = ExtensionUtils;
|
||||
|
||||
extensions.registerSchemaAPI("i18n", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("i18n", (extension, context) => {
|
||||
return {
|
||||
i18n: {
|
||||
getMessage: function(messageName, substitutions) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
extensions.registerSchemaAPI("idle", context => {
|
||||
extensions.registerSchemaAPI("idle", (extension, context) => {
|
||||
return {
|
||||
idle: {
|
||||
queryState: function(detectionIntervalInSeconds) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
/* vim: set sts=2 sw=2 et tw=80: */
|
||||
"use strict";
|
||||
|
||||
extensions.registerSchemaAPI("management", context => {
|
||||
extensions.registerSchemaAPI("management", (extension, context) => {
|
||||
return {
|
||||
management: {},
|
||||
};
|
||||
|
@ -92,8 +92,7 @@ extensions.on("shutdown", (type, extension) => {
|
||||
|
||||
var nextId = 0;
|
||||
|
||||
extensions.registerSchemaAPI("notifications", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("notifications", (extension, context) => {
|
||||
return {
|
||||
notifications: {
|
||||
create: function(notificationId, options) {
|
||||
|
@ -20,8 +20,7 @@ var {
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "NativeApp",
|
||||
"resource://gre/modules/NativeMessaging.jsm");
|
||||
|
||||
extensions.registerSchemaAPI("runtime", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("runtime", (extension, context) => {
|
||||
return {
|
||||
runtime: {
|
||||
onStartup: new EventManager(context, "runtime.onStartup", fire => {
|
||||
|
@ -10,8 +10,7 @@ var {
|
||||
EventManager,
|
||||
} = ExtensionUtils;
|
||||
|
||||
extensions.registerSchemaAPI("storage", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("storage", (extension, context) => {
|
||||
return {
|
||||
storage: {
|
||||
local: {
|
||||
|
@ -25,8 +25,7 @@ extensions.on("test-message", (type, extension, ...args) => {
|
||||
});
|
||||
/* eslint-enable mozilla/balanced-listeners */
|
||||
|
||||
extensions.registerSchemaAPI("test", context => {
|
||||
let {extension} = context;
|
||||
extensions.registerSchemaAPI("test", (extension, context) => {
|
||||
return {
|
||||
test: {
|
||||
sendMessage: function(...args) {
|
||||
|
@ -158,7 +158,7 @@ function convertGetFrameResult(tabId, data) {
|
||||
};
|
||||
}
|
||||
|
||||
extensions.registerSchemaAPI("webNavigation", context => {
|
||||
extensions.registerSchemaAPI("webNavigation", (extension, context) => {
|
||||
return {
|
||||
webNavigation: {
|
||||
onBeforeNavigate: new WebNavigationEventManager(context, "onBeforeNavigate").api(),
|
||||
|
@ -99,7 +99,7 @@ function WebRequestEventManager(context, eventName) {
|
||||
|
||||
WebRequestEventManager.prototype = Object.create(SingletonEventManager.prototype);
|
||||
|
||||
extensions.registerSchemaAPI("webRequest", context => {
|
||||
extensions.registerSchemaAPI("webRequest", (extension, context) => {
|
||||
return {
|
||||
webRequest: {
|
||||
onBeforeRequest: new WebRequestEventManager(context, "onBeforeRequest").api(),
|
||||
|
@ -49,7 +49,7 @@ add_task(function* test_contentscript_context() {
|
||||
// Get the content script context and check that it points to the correct window.
|
||||
|
||||
let {DocumentManager} = SpecialPowers.Cu.import("resource://gre/modules/ExtensionContent.jsm", {});
|
||||
let context = DocumentManager.getContentScriptContext(extension, win);
|
||||
let context = DocumentManager.getContentScriptContext(extension.id, win);
|
||||
ok(context != null, "Got content script context");
|
||||
|
||||
is(SpecialPowers.unwrap(context.contentWindow), win, "Context's contentWindow property is correct");
|
||||
|
@ -13,13 +13,16 @@ var {
|
||||
|
||||
class StubContext extends BaseContext {
|
||||
constructor() {
|
||||
let fakeExtension = {id: "test@web.extension"};
|
||||
super(fakeExtension);
|
||||
super();
|
||||
this.sandbox = Cu.Sandbox(global);
|
||||
}
|
||||
|
||||
get cloneScope() {
|
||||
return this.sandbox;
|
||||
return this. sandbox;
|
||||
}
|
||||
|
||||
get extension() {
|
||||
return {id: "test@web.extension"};
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,13 +130,13 @@ add_task(function* test_post_unload_listeners() {
|
||||
|
||||
class Context extends BaseContext {
|
||||
constructor(principal) {
|
||||
let fakeExtension = {id: "test@web.extension"};
|
||||
super(fakeExtension);
|
||||
super();
|
||||
Object.defineProperty(this, "principal", {
|
||||
value: principal,
|
||||
configurable: true,
|
||||
});
|
||||
this.sandbox = Cu.Sandbox(principal, {wantXrays: false});
|
||||
this.extension = {id: "test@web.extension"};
|
||||
}
|
||||
|
||||
get cloneScope() {
|
||||
|
Loading…
Reference in New Issue
Block a user