Bug 1048618: Send nsIURIFixupInfo to the parent process. r=gijs

This commit is contained in:
Dave Townsend 2014-09-02 18:34:01 -04:00
parent c5d9fce5af
commit 306f7c8729
4 changed files with 78 additions and 48 deletions

View File

@ -672,33 +672,17 @@ var gPopupBlockerObserver = {
}
};
function gKeywordURIFixup(fixupInfo, topic, data) {
fixupInfo.QueryInterface(Ci.nsIURIFixupInfo);
function gKeywordURIFixup({ target: browser, data: fixupInfo }) {
let deserializeURI = (spec) => spec ? makeURI(spec) : null;
// We get called irrespective of whether we did a keyword search, or
// whether the original input would be vaguely interpretable as a URL,
// so figure that out first.
let alternativeURI = fixupInfo.fixedURI;
let alternativeURI = deserializeURI(fixupInfo.fixedURI);
if (!fixupInfo.fixupUsedKeyword || !alternativeURI) {
return;
}
// We should have a document loader...
let docshellRef = fixupInfo.consumer;
try {
docshellRef.QueryInterface(Ci.nsIDocumentLoader);
} catch (ex) {
return;
}
if (!docshellRef.document)
return;
// ... from which we can deduce the browser
let browser = gBrowser.getBrowserForDocument(docshellRef.document);
if (!browser)
return;
// At this point we're still only just about to load this URI.
// When the async DNS lookup comes back, we may be in any of these states:
// 1) still on the previous URI, waiting for the preferredURI (keyword
@ -708,6 +692,7 @@ function gKeywordURIFixup(fixupInfo, topic, data) {
// We keep track of the currentURI to detect case (1) in the DNS lookup
// callback.
let previousURI = browser.currentURI;
let preferredURI = deserializeURI(fixupInfo.preferredURI);
// now swap for a weak ref so we don't hang on to browser needlessly
// even if the DNS query takes forever
@ -738,7 +723,7 @@ function gKeywordURIFixup(fixupInfo, topic, data) {
let currentURI = browser.currentURI;
// If we're in case (3) (see above), don't show an info bar.
if (!currentURI.equals(previousURI) &&
!currentURI.equals(fixupInfo.preferredURI)) {
!currentURI.equals(preferredURI)) {
return;
}
@ -1087,7 +1072,7 @@ var gBrowserInit = {
Services.obs.addObserver(gXPInstallObserver, "addon-install-blocked", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-failed", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-complete", false);
Services.obs.addObserver(gKeywordURIFixup, "keyword-uri-fixup", false);
window.messageManager.addMessageListener("Browser:URIFixup", gKeywordURIFixup);
BrowserOffline.init();
OfflineApps.init();
@ -1393,7 +1378,7 @@ var gBrowserInit = {
Services.obs.removeObserver(gXPInstallObserver, "addon-install-blocked");
Services.obs.removeObserver(gXPInstallObserver, "addon-install-failed");
Services.obs.removeObserver(gXPInstallObserver, "addon-install-complete");
Services.obs.removeObserver(gKeywordURIFixup, "keyword-uri-fixup");
window.messageManager.removeMessageListener("Browser:URIFixup", gKeywordURIFixup);
try {
gPrefService.removeObserver(gHomeButton.prefDomain, gHomeButton);

View File

@ -634,6 +634,33 @@ let DOMFullscreenHandler = {
};
DOMFullscreenHandler.init();
function gKeywordURIFixup(fixupInfo) {
fixupInfo.QueryInterface(Ci.nsIURIFixupInfo);
// Ignore info from other docshells
let parent = fixupInfo.consumer.QueryInterface(Ci.nsIDocShellTreeItem).sameTypeRootTreeItem;
if (parent != docShell)
return;
let data = {};
for (let f of Object.keys(fixupInfo)) {
if (f == "consumer" || typeof fixupInfo[f] == "function")
continue;
if (fixupInfo[f] && fixupInfo[f] instanceof Ci.nsIURI) {
data[f] = fixupInfo[f].spec;
} else {
data[f] = fixupInfo[f];
}
}
sendAsyncMessage("Browser:URIFixup", data);
}
Services.obs.addObserver(gKeywordURIFixup, "keyword-uri-fixup", false);
addEventListener("unload", () => {
Services.obs.removeObserver(gKeywordURIFixup, "keyword-uri-fixup");
}, false);
addMessageListener("Browser:AppTab", function(message) {
docShell.isAppTab = message.data.isAppTab;
});

View File

@ -15,8 +15,10 @@ function promiseNotificationForTab(aBrowser, value, expected, tab=aBrowser.selec
let deferred = Promise.defer();
let notificationBox = aBrowser.getNotificationBox(tab.linkedBrowser);
if (expected) {
info("Waiting for " + value + " notification");
let checkForNotification = function() {
if (notificationBox.getNotificationWithValue(value)) {
info("Saw the notification");
notificationObserver.disconnect();
notificationObserver = null;
deferred.resolve();
@ -48,12 +50,13 @@ function* runURLBarSearchTest(valueToOpen, expectSearch, expectNotification, aWi
expectedURI = Services.search.defaultEngine.getSubmission(valueToOpen, null, "keyword").uri.spec;
}
aWindow.gURLBar.focus();
let docLoadPromise = waitForDocLoadAndStopIt(expectedURI, aWindow.gBrowser);
let docLoadPromise = waitForDocLoadAndStopIt(expectedURI, aWindow.gBrowser.selectedBrowser);
EventUtils.synthesizeKey("VK_RETURN", {}, aWindow);
yield docLoadPromise;
yield promiseNotificationForTab(aWindow.gBrowser, "keyword-uri-fixup", expectNotification);
yield Promise.all([
docLoadPromise,
promiseNotificationForTab(aWindow.gBrowser, "keyword-uri-fixup", expectNotification)
]);
}
add_task(function* test_navigate_full_domain() {
@ -88,7 +91,7 @@ function get_test_function_for_localhost_with_hostname(hostName, isPrivate) {
let notificationBox = browser.getNotificationBox(tab.linkedBrowser);
let notification = notificationBox.getNotificationWithValue("keyword-uri-fixup");
let docLoadPromise = waitForDocLoadAndStopIt("http://" + hostName + "/", browser);
let docLoadPromise = waitForDocLoadAndStopIt("http://" + hostName + "/", tab.linkedBrowser);
notification.querySelector(".notification-button-default").click();
// check pref value

View File

@ -394,27 +394,42 @@ function promiseClearHistory() {
* The URL of the document that is expected to load.
* @return promise
*/
function waitForDocLoadAndStopIt(aExpectedURL, aBrowser=gBrowser) {
let deferred = Promise.defer();
let progressListener = {
onStateChange: function (webProgress, req, flags, status) {
info("waitForDocLoadAndStopIt: onStateChange: " + req.name);
let docStart = Ci.nsIWebProgressListener.STATE_IS_DOCUMENT |
Ci.nsIWebProgressListener.STATE_START;
if ((flags & docStart) && webProgress.isTopLevel) {
info("waitForDocLoadAndStopIt: Document start: " +
req.QueryInterface(Ci.nsIChannel).URI.spec);
is(req.originalURI.spec, aExpectedURL,
"waitForDocLoadAndStopIt: The expected URL was loaded");
req.cancel(Components.results.NS_ERROR_FAILURE);
aBrowser.removeProgressListener(progressListener);
deferred.resolve();
}
},
};
aBrowser.addProgressListener(progressListener);
info("waitForDocLoadAndStopIt: Waiting for URL: " + aExpectedURL);
return deferred.promise;
function waitForDocLoadAndStopIt(aExpectedURL, aBrowser=gBrowser.selectedBrowser) {
function content_script() {
let { interfaces: Ci, utils: Cu } = Components;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
let wp = docShell.QueryInterface(Ci.nsIWebProgress);
let progressListener = {
onStateChange: function (webProgress, req, flags, status) {
dump("waitForDocLoadAndStopIt: onStateChange " + flags.toString(16) + ": " + req.name + "\n");
let docStart = Ci.nsIWebProgressListener.STATE_IS_DOCUMENT |
Ci.nsIWebProgressListener.STATE_START;
if (((flags & docStart) == docStart) && webProgress.isTopLevel) {
dump("waitForDocLoadAndStopIt: Document start: " +
req.QueryInterface(Ci.nsIChannel).URI.spec + "\n");
req.cancel(Components.results.NS_ERROR_FAILURE);
wp.removeProgressListener(progressListener);
sendAsyncMessage("Test:WaitForDocLoadAndStopIt", { uri: req.originalURI.spec });
}
},
QueryInterface: XPCOMUtils.generateQI(["nsISupportsWeakReference"])
};
wp.addProgressListener(progressListener, wp.NOTIFY_ALL);
}
return new Promise((resolve, reject) => {
function complete({ data }) {
is(data.uri, aExpectedURL, "waitForDocLoadAndStopIt: The expected URL was loaded");
mm.removeMessageListener("Test:WaitForDocLoadAndStopIt", complete);
resolve();
}
let mm = aBrowser.messageManager;
mm.loadFrameScript("data:,(" + content_script.toString() + ")();", true);
mm.addMessageListener("Test:WaitForDocLoadAndStopIt", complete);
info("waitForDocLoadAndStopIt: Waiting for URL: " + aExpectedURL);
});
}
/**