Bug 1253307 - Use a better function to load web handler apps in e10s. r=billm r=mconley, a=ritu

This commit is contained in:
Blake Kaplan 2016-03-11 14:31:55 -08:00
parent 76c3cd8735
commit 336393bb8f
7 changed files with 94 additions and 45 deletions

View File

@ -11,5 +11,5 @@ interface nsIURI;
[scriptable, builtinclass, uuid(94f4a92b-752e-4fd9-8345-11b069ca19f3)]
interface nsIRemoteWindowContext : nsISupports
{
void openURI(in nsIURI aURI, in uint32_t aFlags);
void openURI(in nsIURI aURI);
};

View File

@ -1606,12 +1606,9 @@ RemoteWindowContext::GetInterface(const nsIID& aIID, void** aSink)
}
NS_IMETHODIMP
RemoteWindowContext::OpenURI(nsIURI* aURI, uint32_t aFlags)
RemoteWindowContext::OpenURI(nsIURI* aURI)
{
URIParams uri;
SerializeURI(aURI, uri);
Unused << mTabParent->SendOpenURI(uri, aFlags);
mTabParent->LoadURL(aURI);
return NS_OK;
}

View File

@ -525,8 +525,6 @@ child:
async LoadURL(nsCString uri, BrowserConfiguration config, ShowInfo info);
async OpenURI(URIParams uri, uint32_t flags);
async CacheFileDescriptor(nsString path, FileDescriptor fd);
async UpdateDimensions(CSSRect rect, CSSSize size,

View File

@ -593,6 +593,7 @@ TabChild::TabChild(nsIContentChild* aManager,
, mIPCOpen(true)
, mParentIsActive(false)
, mDidSetRealShowInfo(false)
, mDidLoadURLInit(false)
, mAPZChild(nullptr)
{
// In the general case having the TabParent tell us if APZ is enabled or not
@ -1278,6 +1279,8 @@ TabChild::RecvLoadURL(const nsCString& aURI,
const BrowserConfiguration& aConfiguration,
const ShowInfo& aInfo)
{
if (!mDidLoadURLInit) {
mDidLoadURLInit = true;
if (!InitTabChildGlobal()) {
return false;
}
@ -1289,44 +1292,21 @@ TabChild::RecvLoadURL(const nsCString& aURI,
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
MOZ_ASSERT(swm);
swm->LoadRegistrations(aConfiguration.serviceWorkerRegistrations());
}
nsresult rv = WebNavigation()->LoadURI(NS_ConvertUTF8toUTF16(aURI).get(),
nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
nsIWebNavigation::LOAD_FLAGS_DISALLOW_INHERIT_OWNER,
nullptr, nullptr, nullptr);
if (NS_FAILED(rv)) {
NS_WARNING("WebNavigation()->LoadURI failed. Eating exception, what else can I do?");
}
nsresult rv =
WebNavigation()->LoadURI(NS_ConvertUTF8toUTF16(aURI).get(),
nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
nsIWebNavigation::LOAD_FLAGS_DISALLOW_INHERIT_OWNER,
nullptr, nullptr, nullptr);
if (NS_FAILED(rv)) {
NS_WARNING("WebNavigation()->LoadURI failed. Eating exception, what else can I do?");
}
#ifdef MOZ_CRASHREPORTER
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("URL"), aURI);
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("URL"), aURI);
#endif
return true;
}
bool
TabChild::RecvOpenURI(const URIParams& aURI, const uint32_t& aFlags)
{
nsCOMPtr<nsIURI> uri = DeserializeURI(aURI);
nsCOMPtr<nsIChannel> channel;
nsresult rv =
NS_NewChannel(getter_AddRefs(channel),
uri,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_DOCUMENT);
if (NS_WARN_IF(NS_FAILED(rv))) {
return true;
}
nsCOMPtr<nsIURILoader> loader = do_GetService("@mozilla.org/uriloader;1");
if (NS_WARN_IF(!loader)) {
return true;
}
nsCOMPtr<nsIInterfaceRequestor> context(do_QueryInterface(WebNavigation()));
loader->OpenURI(channel, aFlags, context);
return true;
}

View File

@ -313,9 +313,6 @@ public:
const BrowserConfiguration& aConfiguration,
const ShowInfo& aInfo) override;
virtual bool RecvOpenURI(const URIParams& aURI,
const uint32_t& aFlags) override;
virtual bool RecvCacheFileDescriptor(const nsString& aPath,
const FileDescriptor& aFileDescriptor)
override;
@ -746,6 +743,7 @@ private:
bool mAsyncPanZoomEnabled;
CSSSize mUnscaledInnerSize;
bool mDidSetRealShowInfo;
bool mDidLoadURLInit;
AutoTArray<bool, NUMBER_OF_AUDIO_CHANNELS> mAudioChannelsActive;

View File

@ -86,7 +86,7 @@ nsWebHandlerApp.prototype = {
// If aWindowContext refers to a remote docshell, send the load
// request to the correct process.
aWindowContext.getInterface(Ci.nsIRemoteWindowContext)
.openURI(uriToSend, Ci.nsIURILoader.IS_CONTENT_PREFERRED);
.openURI(uriToSend);
return;
} catch (e) {
if (e.result != Cr.NS_NOINTERFACE) {

View File

@ -0,0 +1,76 @@
let testURL = "http://example.com/browser/" +
"uriloader/exthandler/tests/mochitest/protocolHandler.html";
add_task(function*() {
// Load a page registering a protocol handler.
let browser = gBrowser.selectedBrowser;
browser.loadURI(testURL);
yield BrowserTestUtils.browserLoaded(browser, testURL);
// Register the protocol handler by clicking the notificationbar button.
let notificationValue = "Protocol Registration: testprotocol";
let getNotification = () =>
gBrowser.getNotificationBox().getNotificationWithValue(notificationValue);
yield BrowserTestUtils.waitForCondition(getNotification);
let notification = getNotification();
let button =
notification.getElementsByClassName("notification-button-default")[0];
ok(button, "got registration button");
button.click();
// Set the new handler as default.
const protoSvc = Cc["@mozilla.org/uriloader/external-protocol-service;1"].
getService(Ci.nsIExternalProtocolService);
let protoInfo = protoSvc.getProtocolHandlerInfo("testprotocol");
is(protoInfo.preferredAction, protoInfo.useHelperApp,
"using a helper application is the preferred action");
ok(!protoInfo.preferredApplicationHandler, "no preferred handler is set");
let handlers = protoInfo.possibleApplicationHandlers;
is(1, handlers.length, "only one handler registered for testprotocol");
let handler = handlers.queryElementAt(0, Ci.nsIHandlerApp);
ok(handler instanceof Ci.nsIWebHandlerApp, "the handler is a web handler");
is(handler.uriTemplate, "https://example.com/foobar?uri=%s",
"correct url template")
protoInfo.preferredApplicationHandler = handler;
protoInfo.alwaysAskBeforeHandling = false;
const handlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"].
getService(Ci.nsIHandlerService);
handlerSvc.store(protoInfo);
// Middle-click a testprotocol link and check the new tab is correct
let link = browser.contentDocument.getElementById("link");
const expectedURL = "https://example.com/foobar?uri=testprotocol%3Atest";
let promiseTabOpened =
BrowserTestUtils.waitForNewTab(gBrowser, expectedURL);
yield BrowserTestUtils.synthesizeMouseAtCenter(link, {button: 1}, browser);
let tab = yield promiseTabOpened;
gBrowser.selectedTab = tab;
is(gURLBar.value, expectedURL,
"the expected URL is displayed in the location bar");
yield BrowserTestUtils.removeTab(tab);
// Shift-click the testprotocol link and check the new window.
let newWindowPromise = BrowserTestUtils.waitForNewWindow();
yield BrowserTestUtils.synthesizeMouseAtCenter(link, {shiftKey: true},
browser);
let win = yield newWindowPromise;
yield BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser);
yield BrowserTestUtils.waitForCondition(() => win.gBrowser.currentURI.spec == expectedURL);
is(win.gURLBar.value, expectedURL,
"the expected URL is displayed in the location bar");
yield BrowserTestUtils.closeWindow(win);
// Click the testprotocol link and check the url in the current tab.
let loadPromise = BrowserTestUtils.browserLoaded(browser);
yield BrowserTestUtils.synthesizeMouseAtCenter(link, {}, browser);
yield loadPromise;
yield BrowserTestUtils.waitForCondition(() => gURLBar.value != testURL);
is(gURLBar.value, expectedURL,
"the expected URL is displayed in the location bar");
// Cleanup.
protoInfo.preferredApplicationHandler = null;
handlers.removeElementAt(0);
handlerSvc.store(protoInfo);
});