mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1208257 - [webext] tabs.json (r=kmag)
This commit is contained in:
parent
52236ac1b1
commit
172bc851f3
@ -109,7 +109,7 @@ global.currentWindow = function(context) {
|
||||
|
||||
// TODO: activeTab permission
|
||||
|
||||
extensions.registerAPI((extension, context) => {
|
||||
extensions.registerSchemaAPI("tabs", null, (extension, context) => {
|
||||
let self = {
|
||||
tabs: {
|
||||
onActivated: new WindowEventManager(context, "tabs.onActivated", "TabSelect", (fire, event) => {
|
||||
@ -296,7 +296,7 @@ extensions.registerAPI((extension, context) => {
|
||||
}
|
||||
}
|
||||
|
||||
let window = "windowId" in createProperties ?
|
||||
let window = createProperties.windowId !== null ?
|
||||
WindowManager.getWindow(createProperties.windowId) :
|
||||
WindowManager.topWindow;
|
||||
if (!window.gBrowser) {
|
||||
@ -328,34 +328,27 @@ extensions.registerAPI((extension, context) => {
|
||||
}
|
||||
},
|
||||
|
||||
update: function(...args) {
|
||||
let tabId, updateProperties, callback;
|
||||
if (args.length == 1) {
|
||||
updateProperties = args[0];
|
||||
} else {
|
||||
[tabId, updateProperties, callback] = args;
|
||||
}
|
||||
|
||||
let tab = tabId ? TabManager.getTab(tabId) : TabManager.activeTab;
|
||||
update: function(tabId, updateProperties, callback) {
|
||||
let tab = tabId !== null ? TabManager.getTab(tabId) : TabManager.activeTab;
|
||||
let tabbrowser = tab.ownerDocument.defaultView.gBrowser;
|
||||
if ("url" in updateProperties) {
|
||||
if (updateProperties.url !== null) {
|
||||
tab.linkedBrowser.loadURI(updateProperties.url);
|
||||
}
|
||||
if ("active" in updateProperties) {
|
||||
if (updateProperties.active !== null) {
|
||||
if (updateProperties.active) {
|
||||
tabbrowser.selectedTab = tab;
|
||||
} else {
|
||||
// Not sure what to do here? Which tab should we select?
|
||||
}
|
||||
}
|
||||
if ("pinned" in updateProperties) {
|
||||
if (updateProperties.pinned !== null) {
|
||||
if (updateProperties.pinned) {
|
||||
tabbrowser.pinTab(tab);
|
||||
} else {
|
||||
tabbrowser.unpinTab(tab);
|
||||
}
|
||||
}
|
||||
// FIXME: highlighted/selected, openerTabId
|
||||
// FIXME: highlighted/selected, muted, openerTabId
|
||||
|
||||
if (callback) {
|
||||
runSafe(context, callback, TabManager.convert(extension, tab));
|
||||
@ -363,7 +356,7 @@ extensions.registerAPI((extension, context) => {
|
||||
},
|
||||
|
||||
reload: function(tabId, reloadProperties, callback) {
|
||||
let tab = tabId ? TabManager.getTab(tabId) : TabManager.activeTab;
|
||||
let tab = tabId !== null ? TabManager.getTab(tabId) : TabManager.activeTab;
|
||||
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
|
||||
if (reloadProperties && reloadProperties.bypassCache) {
|
||||
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
|
||||
@ -388,51 +381,39 @@ extensions.registerAPI((extension, context) => {
|
||||
runSafe(context, callback, tab);
|
||||
},
|
||||
|
||||
getAllInWindow: function(...args) {
|
||||
let window, callback;
|
||||
if (args.length == 1) {
|
||||
callback = args[0];
|
||||
} else {
|
||||
window = WindowManager.getWindow(args[0]);
|
||||
callback = args[1];
|
||||
getAllInWindow: function(windowId, callback) {
|
||||
if (windowId === null) {
|
||||
windowId = WindowManager.topWindow.windowId;
|
||||
}
|
||||
|
||||
if (!window) {
|
||||
window = WindowManager.topWindow;
|
||||
}
|
||||
|
||||
return self.tabs.query({windowId: WindowManager.getId(window)}, callback);
|
||||
return self.tabs.query({windowId}, callback);
|
||||
},
|
||||
|
||||
query: function(queryInfo, callback) {
|
||||
if (!queryInfo) {
|
||||
queryInfo = {};
|
||||
}
|
||||
|
||||
let pattern = null;
|
||||
if (queryInfo.url) {
|
||||
if (queryInfo.url !== null) {
|
||||
pattern = new MatchPattern(queryInfo.url);
|
||||
}
|
||||
|
||||
function matches(window, tab) {
|
||||
let props = ["active", "pinned", "highlighted", "status", "title", "index"];
|
||||
for (let prop of props) {
|
||||
if (prop in queryInfo && queryInfo[prop] != tab[prop]) {
|
||||
if (queryInfo[prop] !== null && queryInfo[prop] != tab[prop]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
let lastFocused = window == WindowManager.topWindow;
|
||||
if ("lastFocusedWindow" in queryInfo && queryInfo.lastFocusedWindow != lastFocused) {
|
||||
if (queryInfo.lastFocusedWindow !== null && queryInfo.lastFocusedWindow != lastFocused) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let windowType = WindowManager.windowType(window);
|
||||
if ("windowType" in queryInfo && queryInfo.windowType != windowType) {
|
||||
if (queryInfo.windowType !== null && queryInfo.windowType != windowType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("windowId" in queryInfo) {
|
||||
if (queryInfo.windowId !== null) {
|
||||
if (queryInfo.windowId == WindowManager.WINDOW_ID_CURRENT) {
|
||||
if (currentWindow(context) != window) {
|
||||
return false;
|
||||
@ -442,7 +423,7 @@ extensions.registerAPI((extension, context) => {
|
||||
}
|
||||
}
|
||||
|
||||
if ("currentWindow" in queryInfo) {
|
||||
if (queryInfo.currentWindow !== null) {
|
||||
let eq = window == currentWindow(context);
|
||||
if (queryInfo.currentWindow != eq) {
|
||||
return false;
|
||||
@ -469,7 +450,7 @@ extensions.registerAPI((extension, context) => {
|
||||
},
|
||||
|
||||
_execute: function(tabId, details, kind, callback) {
|
||||
let tab = tabId ? TabManager.getTab(tabId) : TabManager.activeTab;
|
||||
let tab = tabId !== null ? TabManager.getTab(tabId) : TabManager.activeTab;
|
||||
let mm = tab.linkedBrowser.messageManager;
|
||||
|
||||
let options = {
|
||||
@ -494,10 +475,10 @@ extensions.registerAPI((extension, context) => {
|
||||
options.matchesHost = extension.whiteListedHosts.serialize();
|
||||
}
|
||||
|
||||
if (details.code) {
|
||||
if (details.code !== null) {
|
||||
options[kind + "Code"] = details.code;
|
||||
}
|
||||
if (details.file) {
|
||||
if (details.file !== null) {
|
||||
let url = context.uri.resolve(details.file);
|
||||
if (extension.isExtensionURL(url)) {
|
||||
// We should really set |lastError| here, and go straight to
|
||||
@ -511,7 +492,7 @@ extensions.registerAPI((extension, context) => {
|
||||
if (details.matchAboutBlank) {
|
||||
options.match_about_blank = details.matchAboutBlank;
|
||||
}
|
||||
if (details.runAt) {
|
||||
if (details.runAt !== null) {
|
||||
options.run_at = details.runAt;
|
||||
}
|
||||
mm.sendAsyncMessage("Extension:Execute",
|
||||
@ -520,29 +501,24 @@ extensions.registerAPI((extension, context) => {
|
||||
// TODO: Call the callback with the result (which is what???).
|
||||
},
|
||||
|
||||
executeScript: function(...args) {
|
||||
if (args.length == 1) {
|
||||
self.tabs._execute(undefined, args[0], "js", undefined);
|
||||
} else {
|
||||
self.tabs._execute(args[0], args[1], "js", args[2]);
|
||||
}
|
||||
executeScript: function(tabId, details, callback) {
|
||||
self.tabs._execute(tabId, details, 'js', callback);
|
||||
},
|
||||
|
||||
insertCss: function(...args) {
|
||||
if (args.length == 1) {
|
||||
self.tabs._execute(undefined, args[0], "css", undefined);
|
||||
} else {
|
||||
self.tabs._execute(args[0], args[1], "css", args[2]);
|
||||
}
|
||||
insertCss: function(tabId, details, callback) {
|
||||
self.tabs._execute(tabId, details, 'css', callback);
|
||||
},
|
||||
|
||||
connect: function(tabId, connectInfo) {
|
||||
let tab = TabManager.getTab(tabId);
|
||||
let mm = tab.linkedBrowser.messageManager;
|
||||
|
||||
let name = connectInfo.name || "";
|
||||
let name = "";
|
||||
if (connectInfo && connectInfo.name !== null) {
|
||||
name = connectInfo.name;
|
||||
}
|
||||
let recipient = {extensionId: extension.id};
|
||||
if ("frameId" in connectInfo) {
|
||||
if (connectInfo && connectInfo.frameId !== null) {
|
||||
recipient.frameId = connectInfo.frameId;
|
||||
}
|
||||
return context.messenger.connect(mm, name, recipient);
|
||||
@ -557,7 +533,7 @@ extensions.registerAPI((extension, context) => {
|
||||
let mm = tab.linkedBrowser.messageManager;
|
||||
|
||||
let recipient = {extensionId: extension.id};
|
||||
if (options && "frameId" in options) {
|
||||
if (options && options.frameId !== null) {
|
||||
recipient.frameId = options.frameId;
|
||||
}
|
||||
return context.messenger.sendMessage(mm, message, recipient, responseCallback);
|
||||
|
@ -3,4 +3,5 @@
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
browser.jar:
|
||||
content/browser/schemas/tabs.json
|
||||
content/browser/schemas/windows.json
|
||||
|
1190
browser/components/extensions/schemas/tabs.json
Normal file
1190
browser/components/extensions/schemas/tabs.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -107,7 +107,7 @@ function* do_test_update(background) {
|
||||
add_task(function* test_pinned() {
|
||||
yield do_test_update(function background() {
|
||||
// Create a new tab for testing update.
|
||||
browser.tabs.create(null, function(tab) {
|
||||
browser.tabs.create({}, function(tab) {
|
||||
browser.tabs.onUpdated.addListener(function onUpdated(tabId, changeInfo) {
|
||||
// Check callback
|
||||
browser.test.assertEq(tabId, tab.id, "Check tab id");
|
||||
@ -151,7 +151,7 @@ add_task(function* test_unpinned() {
|
||||
add_task(function* test_url() {
|
||||
yield do_test_update(function background() {
|
||||
// Create a new tab for testing update.
|
||||
browser.tabs.create(null, function(tab) {
|
||||
browser.tabs.create({}, function(tab) {
|
||||
browser.tabs.onUpdated.addListener(function onUpdated(tabId, changeInfo) {
|
||||
// Check callback
|
||||
browser.test.assertEq(tabId, tab.id, "Check tab id");
|
||||
|
@ -623,6 +623,7 @@ BrowserGlue.prototype = {
|
||||
ExtensionManagement.registerScript("chrome://browser/content/ext-windows.js");
|
||||
ExtensionManagement.registerScript("chrome://browser/content/ext-bookmarks.js");
|
||||
|
||||
ExtensionManagement.registerSchema("chrome://browser/content/schemas/tabs.json");
|
||||
ExtensionManagement.registerSchema("chrome://browser/content/schemas/windows.json");
|
||||
|
||||
this._flashHangCount = 0;
|
||||
|
@ -65,6 +65,7 @@ ExtensionManagement.registerScript("chrome://extensions/content/ext-storage.js")
|
||||
ExtensionManagement.registerScript("chrome://extensions/content/ext-test.js");
|
||||
|
||||
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/cookies.json");
|
||||
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/extension_types.json");
|
||||
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/web_navigation.json");
|
||||
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/web_request.json");
|
||||
|
||||
|
@ -135,8 +135,9 @@ class ChoiceType extends Type {
|
||||
};
|
||||
|
||||
// This is a reference to another type--essentially a typedef.
|
||||
// FIXME
|
||||
class RefType extends Type {
|
||||
// For a reference to a type named T declared in namespace NS,
|
||||
// namespaceName will be NS and reference will be T.
|
||||
constructor(namespaceName, reference) {
|
||||
super();
|
||||
this.namespaceName = namespaceName;
|
||||
@ -573,7 +574,7 @@ this.Schemas = {
|
||||
let allowedSet = new Set([...allowedProperties, ...extra, "description"]);
|
||||
for (let prop of Object.keys(type)) {
|
||||
if (!allowedSet.has(prop)) {
|
||||
throw new Error(`Internal error: Namespace ${namespaceName} has invalid type property ${prop} in type ${type.name}`);
|
||||
throw new Error(`Internal error: Namespace ${namespaceName} has invalid type property "${prop}" in type "${type.name}"`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -585,7 +586,12 @@ this.Schemas = {
|
||||
return new ChoiceType(choices);
|
||||
} else if ("$ref" in type) {
|
||||
checkTypeProperties("$ref");
|
||||
return new RefType(namespaceName, type["$ref"]);
|
||||
let ref = type["$ref"];
|
||||
let ns = namespaceName;
|
||||
if (ref.includes('.')) {
|
||||
[ns, ref] = ref.split('.');
|
||||
}
|
||||
return new RefType(ns, ref);
|
||||
}
|
||||
|
||||
if (!("type" in type)) {
|
||||
@ -597,7 +603,21 @@ this.Schemas = {
|
||||
// Otherwise it's a normal type...
|
||||
if (type.type == "string") {
|
||||
checkTypeProperties("enum", "minLength", "maxLength");
|
||||
return new StringType(type["enum"] || null,
|
||||
|
||||
let enumeration = type["enum"] || null;
|
||||
if (enumeration) {
|
||||
// The "enum" property is either a list of strings that are
|
||||
// valid values or else a list of {name, description} objects,
|
||||
// where the .name values are the valid values.
|
||||
enumeration = enumeration.map(e => {
|
||||
if (typeof(e) == "object") {
|
||||
return e.name;
|
||||
} else {
|
||||
return e;
|
||||
}
|
||||
});
|
||||
}
|
||||
return new StringType(enumeration,
|
||||
type.minLength || 0,
|
||||
type.maxLength || Infinity);
|
||||
} else if (type.type == "object") {
|
||||
@ -607,8 +627,10 @@ this.Schemas = {
|
||||
}
|
||||
let properties = {};
|
||||
for (let propName of Object.keys(type.properties)) {
|
||||
let propType = this.parseType(namespaceName, type.properties[propName],
|
||||
["optional", "unsupported", "deprecated"]);
|
||||
properties[propName] = {
|
||||
type: this.parseType(namespaceName, type.properties[propName], ["optional", "unsupported"]),
|
||||
type: propType,
|
||||
optional: type.properties[propName].optional || false,
|
||||
unsupported: type.properties[propName].unsupported || false,
|
||||
};
|
||||
@ -648,7 +670,8 @@ this.Schemas = {
|
||||
checkTypeProperties("parameters");
|
||||
return new FunctionType(parameters);
|
||||
} else if (type.type == "any") {
|
||||
checkTypeProperties();
|
||||
// Need to see what minimum and maximum are supposed to do here.
|
||||
checkTypeProperties("minimum", "maximum");
|
||||
return new AnyType();
|
||||
} else {
|
||||
throw new Error(`Unexpected type ${type.type}`);
|
||||
@ -669,8 +692,12 @@ this.Schemas = {
|
||||
},
|
||||
|
||||
loadFunction(namespaceName, fun) {
|
||||
// We ignore this property for now.
|
||||
let returns = fun.returns;
|
||||
|
||||
let f = new FunctionEntry(namespaceName, fun.name,
|
||||
this.parseType(namespaceName, fun, ["name", "unsupported"]),
|
||||
this.parseType(namespaceName, fun,
|
||||
["name", "unsupported", "deprecated", "returns"]),
|
||||
fun.unsupported || false);
|
||||
this.register(namespaceName, fun.name, f);
|
||||
},
|
||||
@ -690,7 +717,8 @@ this.Schemas = {
|
||||
let filters = event.filters;
|
||||
|
||||
let type = this.parseType(namespaceName, event,
|
||||
["name", "unsupported", "extraParameters", "returns", "filters"]);
|
||||
["name", "unsupported", "deprecated",
|
||||
"extraParameters", "returns", "filters"]);
|
||||
|
||||
let e = new Event(namespaceName, event.name, type, extras,
|
||||
event.unsupported || false);
|
||||
|
59
toolkit/components/extensions/schemas/extension_types.json
Normal file
59
toolkit/components/extensions/schemas/extension_types.json
Normal file
@ -0,0 +1,59 @@
|
||||
// Copyright 2014 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
[
|
||||
{
|
||||
"namespace": "extensionTypes",
|
||||
"description": "The <code>browser.extensionTypes</code> API contains type declarations for WebExtensions.",
|
||||
"types": [
|
||||
{
|
||||
"id": "ImageFormat",
|
||||
"type": "string",
|
||||
"enum": ["jpeg", "png"],
|
||||
"description": "The format of an image."
|
||||
},
|
||||
{
|
||||
"id": "ImageDetails",
|
||||
"type": "object",
|
||||
"description": "Details about the format and quality of an image.",
|
||||
"properties": {
|
||||
"format": {
|
||||
"$ref": "ImageFormat",
|
||||
"optional": true,
|
||||
"description": "The format of the resulting image. Default is <code>\"jpeg\"</code>."
|
||||
},
|
||||
"quality": {
|
||||
"type": "integer",
|
||||
"optional": true,
|
||||
"minimum": 0,
|
||||
"maximum": 100,
|
||||
"description": "When format is <code>\"jpeg\"</code>, controls the quality of the resulting image. This value is ignored for PNG images. As quality is decreased, the resulting image will have more visual artifacts, and the number of bytes needed to store it will decrease."
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "RunAt",
|
||||
"type": "string",
|
||||
"enum": ["document_start", "document_end", "document_idle"],
|
||||
"description": "The soonest that the JavaScript or CSS will be injected into the tab."
|
||||
},
|
||||
{
|
||||
"id": "InjectDetails",
|
||||
"type": "object",
|
||||
"description": "Details of the script or CSS to inject. Either the code or the file property must be set, but both may not be set at the same time.",
|
||||
"properties": {
|
||||
"code": {"type": "string", "optional": true, "description": "JavaScript or CSS code to inject.<br><br><b>Warning:</b><br>Be careful using the <code>code</code> parameter. Incorrect use of it may open your extension to <a href=\"https://en.wikipedia.org/wiki/Cross-site_scripting\">cross site scripting</a> attacks."},
|
||||
"file": {"type": "string", "optional": true, "description": "JavaScript or CSS file to inject."},
|
||||
"allFrames": {"type": "boolean", "optional": true, "description": "If allFrames is <code>true</code>, implies that the JavaScript or CSS should be injected into all frames of current page. By default, it's <code>false</code> and is only injected into the top frame."},
|
||||
"matchAboutBlank": {"type": "boolean", "optional": true, "description": "If matchAboutBlank is true, then the code is also injected in about:blank and about:srcdoc frames if your extension has access to its parent document. Code cannot be inserted in top-level about:-frames. By default it is <code>false</code>."},
|
||||
"runAt": {
|
||||
"$ref": "RunAt",
|
||||
"optional": true,
|
||||
"description": "The soonest that the JavaScript or CSS will be injected into the tab. Defaults to \"document_idle\"."
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
@ -5,5 +5,6 @@
|
||||
toolkit.jar:
|
||||
% content extensions %content/extensions/
|
||||
content/extensions/schemas/cookies.json
|
||||
content/extensions/schemas/extension_types.json
|
||||
content/extensions/schemas/web_navigation.json
|
||||
content/extensions/schemas/web_request.json
|
||||
|
Loading…
Reference in New Issue
Block a user