mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1451463: Make Quitter a WebExtension experiment. r=aswan
Differential Revision: https://phabricator.services.mozilla.com/D12478 --HG-- extra : rebase_source : 1a89085a191d3bdda5b49f178644e5766a9fb5c2 extra : amend_source : 0685f35163593b596d50c45567b5d64b68935f04
This commit is contained in:
parent
bbeb9c3ddb
commit
0df1d1fa1e
@ -617,7 +617,8 @@ MozDocumentMatcher::Matches(const DocInfo& aDoc) const
|
||||
// matchAboutBlank is true and it has the null principal. In all other
|
||||
// cases, we test the URL of the principal that it inherits.
|
||||
if (mMatchAboutBlank && aDoc.IsTopLevel() &&
|
||||
aDoc.URL().Spec().EqualsLiteral("about:blank") &&
|
||||
(aDoc.URL().Spec().EqualsLiteral("about:blank") ||
|
||||
aDoc.URL().Scheme() == nsGkAtoms::data) &&
|
||||
aDoc.Principal() && aDoc.Principal()->GetIsNullPrincipal()) {
|
||||
return true;
|
||||
}
|
||||
|
7
tools/quitter/.eslintrc.js
Normal file
7
tools/quitter/.eslintrc.js
Normal file
@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
globals: {
|
||||
cloneInto: true,
|
||||
}
|
||||
};
|
9
tools/quitter/background.js
Normal file
9
tools/quitter/background.js
Normal file
@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
/* eslint-env webextensions */
|
||||
|
||||
browser.runtime.onMessage.addListener(msg => {
|
||||
if (msg === "quit") {
|
||||
browser.quitter.quit();
|
||||
}
|
||||
});
|
42
tools/quitter/bootstrap.js
vendored
42
tools/quitter/bootstrap.js
vendored
@ -1,42 +0,0 @@
|
||||
/* 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/. */
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const CHILD_SCRIPT = "chrome://quitter/content/contentscript.js";
|
||||
|
||||
const quitterObserver = {
|
||||
init() {
|
||||
Services.mm.addMessageListener("Quitter.Quit", this);
|
||||
Services.mm.loadFrameScript(CHILD_SCRIPT, true);
|
||||
},
|
||||
|
||||
uninit() {
|
||||
Services.mm.removeMessageListener("Quitter.Quit", this);
|
||||
Services.mm.removeDelayedFrameScript(CHILD_SCRIPT, true);
|
||||
},
|
||||
|
||||
/**
|
||||
* messageManager callback function
|
||||
* This will get requests from our API in the window and process them in chrome for it
|
||||
**/
|
||||
receiveMessage(aMessage) {
|
||||
switch (aMessage.name) {
|
||||
case "Quitter.Quit":
|
||||
Services.startup.quit(Ci.nsIAppStartup.eForceQuit);
|
||||
break;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function startup(data, reason) {
|
||||
quitterObserver.init();
|
||||
}
|
||||
|
||||
function shutdown(data, reason) {
|
||||
quitterObserver.uninit();
|
||||
}
|
||||
|
||||
function install(data, reason) {}
|
||||
function uninstall(data, reason) {}
|
@ -1 +0,0 @@
|
||||
content quitter chrome/quitter/content/
|
@ -2,34 +2,12 @@
|
||||
* 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/. */
|
||||
|
||||
/* eslint-env mozilla/frame-script */
|
||||
"use strict";
|
||||
|
||||
function Quitter() {
|
||||
}
|
||||
/* eslint-env webextensions */
|
||||
|
||||
Quitter.prototype = {
|
||||
toString() { return "[Quitter]"; },
|
||||
quit() { sendSyncMessage("Quitter.Quit", {}); },
|
||||
const Quitter = {
|
||||
quit() { browser.runtime.sendMessage("quit"); },
|
||||
};
|
||||
|
||||
// This is a frame script, so it may be running in a content process.
|
||||
// In any event, it is targeted at a specific "tab", so we listen for
|
||||
// the DOMWindowCreated event to be notified about content windows
|
||||
// being created in this context.
|
||||
|
||||
function QuitterManager() {
|
||||
addEventListener("DOMWindowCreated", this, false);
|
||||
}
|
||||
|
||||
QuitterManager.prototype = {
|
||||
handleEvent: function handleEvent(aEvent) {
|
||||
var quitter = new Quitter(window);
|
||||
var window = aEvent.target.defaultView;
|
||||
window.wrappedJSObject.Quitter = Cu.cloneInto({
|
||||
toString: quitter.toString.bind(quitter),
|
||||
quit: quitter.quit.bind(quitter),
|
||||
}, window, {cloneFunctions: true});
|
||||
},
|
||||
};
|
||||
|
||||
var quittermanager = new QuitterManager();
|
||||
window.wrappedJSObject.Quitter = cloneInto(Quitter, window, {cloneFunctions: true});
|
||||
|
@ -1,36 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
|
||||
|
||||
<Description about="urn:mozilla:install-manifest">
|
||||
<em:id>quitter@mozilla.org</em:id>
|
||||
<em:version>2018.03.19</em:version>
|
||||
<em:type>2</em:type>
|
||||
<em:bootstrap>true</em:bootstrap>
|
||||
|
||||
<!-- Target Application this extension can install into,
|
||||
with minimum and maximum supported versions. -->
|
||||
<em:targetApplication>
|
||||
<Description>
|
||||
<!-- Firefox -->
|
||||
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
|
||||
<em:minVersion>45</em:minVersion>
|
||||
<em:maxVersion>*</em:maxVersion>
|
||||
</Description>
|
||||
</em:targetApplication>
|
||||
<em:targetApplication>
|
||||
<Description>
|
||||
<!-- Fennec -->
|
||||
<em:id>{aa3c5121-dab2-40e2-81ca-7ea25febc110}</em:id>
|
||||
<em:minVersion>45</em:minVersion>
|
||||
<em:maxVersion>*</em:maxVersion>
|
||||
</Description>
|
||||
</em:targetApplication>
|
||||
|
||||
<!-- Front End MetaData -->
|
||||
<em:name>Quitter</em:name>
|
||||
<em:description>Adds a quit method that content pages can use to quit the application.</em:description>
|
||||
<em:creator>Mozilla</em:creator>
|
||||
</Description>
|
||||
</RDF>
|
@ -1,3 +0,0 @@
|
||||
quitter.jar:
|
||||
% content quitter %content/
|
||||
content/contentscript.js (contentscript.js)
|
34
tools/quitter/manifest.json
Normal file
34
tools/quitter/manifest.json
Normal file
@ -0,0 +1,34 @@
|
||||
{
|
||||
"manifest_version": 2,
|
||||
|
||||
"applications": {
|
||||
"gecko": {"id": "quitter@mozilla.org"}
|
||||
},
|
||||
|
||||
"name": "Quitter",
|
||||
"description": "Quit",
|
||||
"version": "2018.04.03",
|
||||
"author": "Mozilla",
|
||||
|
||||
"background": {
|
||||
"scripts": ["background.js"]
|
||||
},
|
||||
|
||||
"content_scripts": [{
|
||||
"js": ["contentscript.js"],
|
||||
"run_at": "document_start",
|
||||
"match_about_blank": true,
|
||||
"matches": ["<all_urls>"]
|
||||
}],
|
||||
|
||||
"experiment_apis": {
|
||||
"quitter": {
|
||||
"schema": "schema.json",
|
||||
"parent": {
|
||||
"scopes": ["addon_parent"],
|
||||
"script": "parent.js",
|
||||
"paths": [["quitter", "quit"]]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,12 +6,12 @@
|
||||
|
||||
XPI_NAME = 'quitter'
|
||||
|
||||
JAR_MANIFESTS += ['jar.mn']
|
||||
|
||||
USE_EXTENSION_MANIFEST = True
|
||||
|
||||
FINAL_TARGET_FILES += [
|
||||
'bootstrap.js',
|
||||
'chrome.manifest',
|
||||
'install.rdf',
|
||||
'background.js',
|
||||
'contentscript.js',
|
||||
'manifest.json',
|
||||
'parent.js',
|
||||
'schema.json',
|
||||
]
|
||||
|
17
tools/quitter/parent.js
Normal file
17
tools/quitter/parent.js
Normal file
@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
|
||||
/* globals ExtensionAPI */
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
this.quitter = class extends ExtensionAPI {
|
||||
getAPI(context) {
|
||||
return {
|
||||
quitter: {
|
||||
quit() {
|
||||
Services.startup.quit(Ci.nsIAppStartup.eForceQuit);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
Binary file not shown.
13
tools/quitter/schema.json
Normal file
13
tools/quitter/schema.json
Normal file
@ -0,0 +1,13 @@
|
||||
[
|
||||
{
|
||||
"namespace": "quitter",
|
||||
"functions": [
|
||||
{
|
||||
"name": "quit",
|
||||
"type": "function",
|
||||
"async": true,
|
||||
"parameters": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue
Block a user