| Index: chrome/browser/apps/app_url_redirector.cc
|
| diff --git a/chrome/browser/apps/app_url_redirector.cc b/chrome/browser/apps/app_url_redirector.cc
|
| index 63962933dc61a3eca1ccac913285d6089856cc91..cf151693b32f03671b7a2912b54c15b084059bd0 100644
|
| --- a/chrome/browser/apps/app_url_redirector.cc
|
| +++ b/chrome/browser/apps/app_url_redirector.cc
|
| @@ -9,18 +9,22 @@
|
| #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"
|
| -#include "components/navigation_interception/intercept_navigation_throttle.h"
|
| +#include "components/navigation_interception/intercept_navigation_resource_throttle.h"
|
| #include "components/navigation_interception/navigation_params.h"
|
| #include "content/public/browser/browser_thread.h"
|
| -#include "content/public/browser/navigation_handle.h"
|
| +#include "content/public/browser/render_view_host.h"
|
| +#include "content/public/browser/resource_request_info.h"
|
| +#include "content/public/browser/resource_throttle.h"
|
| #include "content/public/browser/web_contents.h"
|
| -#include "extensions/browser/extension_registry.h"
|
| +#include "extensions/browser/info_map.h"
|
| #include "extensions/common/extension.h"
|
| #include "extensions/common/extension_set.h"
|
| #include "net/url_request/url_request.h"
|
|
|
| using content::BrowserThread;
|
| +using content::ResourceRequestInfo;
|
| using content::WebContents;
|
| using extensions::Extension;
|
| using extensions::UrlHandlers;
|
| @@ -51,8 +55,8 @@
|
| }
|
|
|
| // These are guaranteed by CreateThrottleFor below.
|
| + DCHECK(!params.is_post());
|
| DCHECK(UrlHandlers::CanExtensionHandleUrl(app.get(), params.url()));
|
| - DCHECK(!params.is_post());
|
|
|
| Profile* profile =
|
| Profile::FromBrowserContext(source->GetBrowserContext());
|
| @@ -69,54 +73,57 @@
|
| } // namespace
|
|
|
| // static
|
| -scoped_ptr<content::NavigationThrottle>
|
| -AppUrlRedirector::MaybeCreateThrottleFor(content::NavigationHandle* handle) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - DVLOG(1) << "Considering URL for redirection: " << handle->GetURL().spec();
|
| -
|
| - content::BrowserContext* browser_context =
|
| - handle->GetWebContents()->GetBrowserContext();
|
| - DCHECK(browser_context);
|
| +content::ResourceThrottle*
|
| +AppUrlRedirector::MaybeCreateThrottleFor(net::URLRequest* request,
|
| + ProfileIOData* profile_io_data) {
|
| + DVLOG(1) << "Considering URL for redirection: "
|
| + << request->method() << " " << request->url().spec();
|
|
|
| // Support only GET for now.
|
| - if (handle->IsPost()) {
|
| + if (request->method() != "GET") {
|
| DVLOG(1) << "Skip redirection: method is not GET";
|
| - return nullptr;
|
| + return NULL;
|
| }
|
|
|
| - if (!handle->GetURL().SchemeIsHTTPOrHTTPS()) {
|
| + if (!request->url().SchemeIsHTTPOrHTTPS()) {
|
| DVLOG(1) << "Skip redirection: scheme is not HTTP or HTTPS";
|
| - return nullptr;
|
| + return NULL;
|
| + }
|
| +
|
| + // The user has indicated that a URL should be force downloaded. Turn off
|
| + // URL redirection in this case.
|
| + if (ResourceRequestInfo::ForRequest(request)->IsDownload()) {
|
| + DVLOG(1) << "Skip redirection: request is a forced download";
|
| + return NULL;
|
| }
|
|
|
| // Never redirect URLs to apps in incognito. Technically, apps are not
|
| // supported in incognito, but that may change in future.
|
| // See crbug.com/240879, which tracks incognito support for v2 apps.
|
| - Profile* profile = Profile::FromBrowserContext(browser_context);
|
| - if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE) {
|
| + if (profile_io_data->IsOffTheRecord()) {
|
| DVLOG(1) << "Skip redirection: unsupported in incognito";
|
| - return nullptr;
|
| + return NULL;
|
| }
|
|
|
| - const extensions::ExtensionSet& enabled_extensions =
|
| - extensions::ExtensionRegistry::Get(browser_context)->enabled_extensions();
|
| - for (extensions::ExtensionSet::const_iterator iter =
|
| - enabled_extensions.begin();
|
| - iter != enabled_extensions.end(); ++iter) {
|
| + const extensions::ExtensionSet& extensions =
|
| + profile_io_data->GetExtensionInfoMap()->extensions();
|
| + for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
|
| + iter != extensions.end();
|
| + ++iter) {
|
| const UrlHandlerInfo* handler =
|
| - UrlHandlers::FindMatchingUrlHandler(iter->get(), handle->GetURL());
|
| + UrlHandlers::FindMatchingUrlHandler(iter->get(), request->url());
|
| if (handler) {
|
| DVLOG(1) << "Found matching app handler for redirection: "
|
| << (*iter)->name() << "(" << (*iter)->id() << "):"
|
| << handler->id;
|
| - return scoped_ptr<content::NavigationThrottle>(
|
| - new navigation_interception::InterceptNavigationThrottle(
|
| - handle,
|
| - base::Bind(&LaunchAppWithUrl,
|
| - scoped_refptr<const Extension>(*iter), handler->id)));
|
| + return new navigation_interception::InterceptNavigationResourceThrottle(
|
| + request,
|
| + base::Bind(&LaunchAppWithUrl,
|
| + scoped_refptr<const Extension>(*iter),
|
| + handler->id));
|
| }
|
| }
|
|
|
| DVLOG(1) << "Skipping redirection: no matching app handler found";
|
| - return nullptr;
|
| + return NULL;
|
| }
|
|
|