зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1472491: Part 5d - Add ContentSearchChild actor. r=adw f=felipe
MozReview-Commit-ID: 5u7VpedF3xH --HG-- rename : browser/base/content/tab-content.js => browser/actors/ContentSearchChild.jsm extra : rebase_source : abfaa941f6769428a7dd47cc7c3f953f6d8c3e87
This commit is contained in:
Родитель
572e4a0ada
Коммит
0c0831f6d0
|
@ -0,0 +1,37 @@
|
|||
/* vim: set ts=2 sw=2 sts=2 et tw=80: */
|
||||
/* 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";
|
||||
|
||||
var EXPORTED_SYMBOLS = ["ContentSearchChild"];
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
|
||||
|
||||
class ContentSearchChild extends ActorChild {
|
||||
handleEvent(event) {
|
||||
this._sendMsg(event.detail.type, event.detail.data);
|
||||
}
|
||||
|
||||
receiveMessage(msg) {
|
||||
this._fireEvent(msg.data.type, msg.data.data);
|
||||
}
|
||||
|
||||
_sendMsg(type, data = null) {
|
||||
this.mm.sendAsyncMessage("ContentSearch", {
|
||||
type,
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
_fireEvent(type, data = null) {
|
||||
let event = Cu.cloneInto({
|
||||
detail: {
|
||||
type,
|
||||
data,
|
||||
},
|
||||
}, this.content);
|
||||
this.content.dispatchEvent(new this.content.CustomEvent("ContentSearchService",
|
||||
event));
|
||||
}
|
||||
}
|
|
@ -10,5 +10,6 @@ with Files("PageStyleChild.jsm"):
|
|||
FINAL_TARGET_FILES.actors += [
|
||||
'AboutReaderChild.jsm',
|
||||
'BrowserTabChild.jsm',
|
||||
'ContentSearchChild.jsm',
|
||||
'PageStyleChild.jsm',
|
||||
]
|
||||
|
|
|
@ -54,64 +54,6 @@ addEventListener("pageshow", function({ originalTarget }) {
|
|||
}
|
||||
}, false, true);
|
||||
|
||||
|
||||
var ContentSearchMediator = {
|
||||
|
||||
whitelist: new Set([
|
||||
"about:home",
|
||||
"about:newtab",
|
||||
"about:welcome",
|
||||
]),
|
||||
|
||||
init(chromeGlobal) {
|
||||
chromeGlobal.addEventListener("ContentSearchClient", this, true, true);
|
||||
addMessageListener("ContentSearch", this);
|
||||
this.init = null;
|
||||
},
|
||||
|
||||
handleEvent(event) {
|
||||
if (this._contentWhitelisted) {
|
||||
this._sendMsg(event.detail.type, event.detail.data);
|
||||
}
|
||||
},
|
||||
|
||||
receiveMessage(msg) {
|
||||
if (msg.data.type == "AddToWhitelist") {
|
||||
for (let uri of msg.data.data) {
|
||||
this.whitelist.add(uri);
|
||||
}
|
||||
this._sendMsg("AddToWhitelistAck");
|
||||
return;
|
||||
}
|
||||
if (this._contentWhitelisted) {
|
||||
this._fireEvent(msg.data.type, msg.data.data);
|
||||
}
|
||||
},
|
||||
|
||||
get _contentWhitelisted() {
|
||||
return this.whitelist.has(content.document.documentURI);
|
||||
},
|
||||
|
||||
_sendMsg(type, data = null) {
|
||||
sendAsyncMessage("ContentSearch", {
|
||||
type,
|
||||
data,
|
||||
});
|
||||
},
|
||||
|
||||
_fireEvent(type, data = null) {
|
||||
let event = Cu.cloneInto({
|
||||
detail: {
|
||||
type,
|
||||
data,
|
||||
},
|
||||
}, content);
|
||||
content.dispatchEvent(new content.CustomEvent("ContentSearchService",
|
||||
event));
|
||||
},
|
||||
};
|
||||
ContentSearchMediator.init(this);
|
||||
|
||||
// Keep a reference to the translation content handler to avoid it it being GC'ed.
|
||||
var trHandler = null;
|
||||
if (Services.prefs.getBoolPref("browser.translation.detectLanguage")) {
|
||||
|
|
|
@ -712,15 +712,10 @@ async function promiseTab() {
|
|||
tab.linkedBrowser.addEventListener("load", function onLoad(event) {
|
||||
tab.linkedBrowser.removeEventListener("load", onLoad, true);
|
||||
gMsgMan = tab.linkedBrowser.messageManager;
|
||||
gMsgMan.sendAsyncMessage("ContentSearch", {
|
||||
type: "AddToWhitelist",
|
||||
data: [pageURL],
|
||||
});
|
||||
promiseMsg("ContentSearch", "AddToWhitelistAck", gMsgMan).then(() => {
|
||||
let jsURL = getRootDirectory(gTestPath) + TEST_CONTENT_SCRIPT_BASENAME;
|
||||
gMsgMan.loadFrameScript(jsURL, false);
|
||||
deferred.resolve(msg("init"));
|
||||
});
|
||||
|
||||
let jsURL = getRootDirectory(gTestPath) + TEST_CONTENT_SCRIPT_BASENAME;
|
||||
gMsgMan.loadFrameScript(jsURL, false);
|
||||
deferred.resolve(msg("init"));
|
||||
}, true, true);
|
||||
openTrustedLinkIn(pageURL, "current");
|
||||
return deferred.promise;
|
||||
|
|
|
@ -53,6 +53,21 @@ let ACTORS = {
|
|||
},
|
||||
},
|
||||
|
||||
ContentSearch: {
|
||||
child: {
|
||||
module: "resource:///actors/ContentSearchChild.jsm",
|
||||
group: "browsers",
|
||||
matches: ["about:home", "about:newtab", "about:welcome",
|
||||
"chrome://mochitests/content/*"],
|
||||
events: {
|
||||
"ContentSearchClient": {capture: true, wantUntrusted: true},
|
||||
},
|
||||
messages: [
|
||||
"ContentSearch",
|
||||
]
|
||||
},
|
||||
},
|
||||
|
||||
PageStyle: {
|
||||
child: {
|
||||
module: "resource:///actors/PageStyleChild.jsm",
|
||||
|
|
|
@ -15,6 +15,10 @@ Services.scriptloader.loadSubScript(
|
|||
let originalEngine = Services.search.currentEngine;
|
||||
|
||||
add_task(async function setup() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.newtab.preload", false]],
|
||||
});
|
||||
|
||||
await promiseNewEngine("testEngine.xml", {
|
||||
setAsCurrent: true,
|
||||
testPath: "chrome://mochitests/content/browser/browser/components/search/test/",
|
||||
|
@ -346,18 +350,11 @@ function waitForNewEngine(basename, numImages) {
|
|||
}
|
||||
|
||||
async function addTab() {
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:newtab");
|
||||
registerCleanupFunction(() => gBrowser.removeTab(tab));
|
||||
|
||||
let url = getRootDirectory(gTestPath) + TEST_CONTENT_SCRIPT_BASENAME;
|
||||
gMsgMan = tab.linkedBrowser.messageManager;
|
||||
gMsgMan.sendAsyncMessage(CONTENT_SEARCH_MSG, {
|
||||
type: "AddToWhitelist",
|
||||
data: ["about:blank"],
|
||||
});
|
||||
|
||||
await waitForMsg(CONTENT_SEARCH_MSG, "AddToWhitelistAck");
|
||||
|
||||
gMsgMan.loadFrameScript(url, false);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче