Commit 887f3f3d authored by davidben@chromium.org's avatar davidben@chromium.org

Abort prerenders on app-intercepted navigations.

Instead of skipping the interception, abort the prerender so that the prerender
doesn't cause the actual navigation to bypass the interception.

BUG=370519

Review URL: https://codereview.chromium.org/265293011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270789 0039d316-1c4b-4281-b951-d872f2087c98
parent ab99d3ba
......@@ -7,6 +7,7 @@
#include "apps/launcher.h"
#include "base/bind.h"
#include "base/logging.h"
#include "chrome/browser/prerender/prerender_contents.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/common/extensions/api/url_handlers/url_handlers_parser.h"
......@@ -46,6 +47,14 @@ bool LaunchAppWithUrl(
return false;
}
// If prerendering, don't launch the app but abort the navigation.
prerender::PrerenderContents* prerender_contents =
prerender::PrerenderContents::FromWebContents(source);
if (prerender_contents) {
prerender_contents->Destroy(prerender::FINAL_STATUS_NAVIGATION_INTERCEPTED);
return true;
}
// These are guaranteed by CreateThrottleFor below.
DCHECK(!params.is_post());
DCHECK(UrlHandlers::CanExtensionHandleUrl(app, params.url()));
......
......@@ -117,6 +117,8 @@ void PlatformAppUrlRedirectorBrowserTest::SetUpCommandLine(
CommandLine* command_line) {
PlatformAppBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(::switches::kDisablePopupBlocking);
command_line->AppendSwitchASCII(::switches::kPrerenderMode,
::switches::kPrerenderModeSwitchValueEnabled);
}
// TODO(sergeygs): Factor out common functionality from TestXyz,
......@@ -507,4 +509,16 @@ IN_PROC_BROWSER_TEST_F(PlatformAppUrlRedirectorBrowserTest,
"url_handlers/handlers/steal_xhr_target");
}
// Test that a click on a prerendered link still launches.
IN_PROC_BROWSER_TEST_F(PlatformAppUrlRedirectorBrowserTest,
PrerenderedClickInTabIntercepted) {
#if defined (OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA) return; // Bug 301638
#endif
TestNavigationInTab(
"url_handlers/launching_pages/prerender_link.html",
"url_handlers/handlers/simple",
"Handler launched");
}
} // namespace extensions
......@@ -62,6 +62,7 @@ const char* kFinalStatusNames[] = {
"Cookie Store Not Loaded",
"Cookie Conflict",
"Non-Empty Browsing Instance",
"Navigation Intercepted",
"Max",
};
COMPILE_ASSERT(arraysize(kFinalStatusNames) == FINAL_STATUS_MAX + 1,
......
......@@ -63,6 +63,7 @@ enum FinalStatus {
FINAL_STATUS_COOKIE_STORE_NOT_LOADED = 48,
FINAL_STATUS_COOKIE_CONFLICT = 49,
FINAL_STATUS_NON_EMPTY_BROWSING_INSTANCE = 50,
FINAL_STATUS_NAVIGATION_INTERCEPTED = 51,
FINAL_STATUS_MAX,
};
......
......@@ -312,11 +312,15 @@ void ChromeResourceDispatcherHostDelegate::RequestBeginning(
ProfileIOData* io_data = ProfileIOData::FromResourceContext(
resource_context);
if (!is_prerendering && resource_type == ResourceType::MAIN_FRAME) {
#if defined(OS_ANDROID)
// TODO(davidben): This is insufficient to integrate with prerender properly.
// https://crbug.com/370595
if (resource_type == ResourceType::MAIN_FRAME && !is_prerendering) {
throttles->push_back(
InterceptNavigationDelegate::CreateThrottleFor(request));
}
#else
if (resource_type == ResourceType::MAIN_FRAME) {
// Redirect some navigations to apps that have registered matching URL
// handlers ('url_handlers' in the manifest).
content::ResourceThrottle* url_to_app_throttle =
......@@ -324,14 +328,16 @@ void ChromeResourceDispatcherHostDelegate::RequestBeginning(
if (url_to_app_throttle)
throttles->push_back(url_to_app_throttle);
// Experimental: Launch ephemeral apps from search results.
content::ResourceThrottle* ephemeral_app_throttle =
EphemeralAppThrottle::MaybeCreateThrottleForLaunch(
request, io_data);
if (ephemeral_app_throttle)
throttles->push_back(ephemeral_app_throttle);
#endif
if (!is_prerendering) {
// Experimental: Launch ephemeral apps from search results.
content::ResourceThrottle* ephemeral_app_throttle =
EphemeralAppThrottle::MaybeCreateThrottleForLaunch(
request, io_data);
if (ephemeral_app_throttle)
throttles->push_back(ephemeral_app_throttle);
}
}
#endif
#if defined(OS_CHROMEOS)
// Check if we need to add offline throttle. This should be done only
......
......@@ -6,9 +6,10 @@
var target_dir = '/extensions/platform_apps/url_handlers/common/';
var link = document.getElementById('link');
var mismatching_link = document.getElementById('mismatching_link');
var prerender_link = document.getElementById('prerender_link');
var form = document.getElementById('form');
if (link || mismatching_link || form) {
if (link || mismatching_link || prerender_link || form) {
var clickEvent = document.createEvent('MouseEvents');
clickEvent.initMouseEvent('click', true, true, window,
0, 0, 0, 0, 0, false, false,
......@@ -30,6 +31,19 @@
mismatching_link.dispatchEvent(clickEvent);
}
if (prerender_link) {
console.log("Prerendering a link");
prerender_link.href = target_dir + "target.html";
var prerender = document.createElement("link");
prerender.rel = "prerender";
prerender.href = prerender_link.href;
prerender.addEventListener("webkitprerenderstop", function() {
console.log("Prerender aborted. Clicking link");
prerender_link.dispatchEvent(clickEvent);
});
document.body.appendChild(prerender);
}
if (form) {
console.log("Submitting a form");
form.action = target_dir + 'target.html';
......
<!--
* 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.
-->
<html>
<body>
I'm a page that prerenders and then click a regular link.
<div><a id="prerender_link">Prerendered link</a></div>
<script src="navigate.js"></script>
</body>
</html>
......@@ -40036,6 +40036,7 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<int value="48" label="COOKIE_STORE_NOT_LOADED"/>
<int value="49" label="COOKIE_CONFLICT"/>
<int value="50" label="NON_EMPTY_BROWSING_INSTANCE"/>
<int value="51" label="NAVIGATION_INTERCEPTED"/>
</enum>
<enum name="PrerenderHoverEvent" type="int">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment