Chromium Code Reviews| 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 cf151693b32f03671b7a2912b54c15b084059bd0..6949963034f391e02c7de29665921d180d0c774e 100644 |
| --- a/chrome/browser/apps/app_url_redirector.cc |
| +++ b/chrome/browser/apps/app_url_redirector.cc |
| @@ -11,13 +11,15 @@ |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/profiles/profile_io_data.h" |
|
davidben
2015/09/01 21:55:17
No longer needed?
clamy
2015/09/03 15:30:50
Done.
|
| #include "chrome/common/extensions/api/url_handlers/url_handlers_parser.h" |
| -#include "components/navigation_interception/intercept_navigation_resource_throttle.h" |
| +#include "components/navigation_interception/intercept_navigation_throttle.h" |
| #include "components/navigation_interception/navigation_params.h" |
| #include "content/public/browser/browser_thread.h" |
|
davidben
2015/09/01 21:55:17
No longer needed?
clamy
2015/09/03 15:30:50
Done.
|
| +#include "content/public/browser/navigation_handle.h" |
| #include "content/public/browser/render_view_host.h" |
|
davidben
2015/09/01 21:55:17
No longer needed?
clamy
2015/09/03 15:30:51
Done.
|
| #include "content/public/browser/resource_request_info.h" |
|
davidben
2015/09/01 21:55:17
No longer needed?
clamy
2015/09/03 15:30:50
Done.
|
| #include "content/public/browser/resource_throttle.h" |
|
davidben
2015/09/01 21:55:17
No longer needed?
clamy
2015/09/03 15:30:51
Done.
|
| #include "content/public/browser/web_contents.h" |
| +#include "extensions/browser/extension_registry.h" |
| #include "extensions/browser/info_map.h" |
|
davidben
2015/09/01 21:55:17
No longer needed?
clamy
2015/09/03 15:30:50
Done.
|
| #include "extensions/common/extension.h" |
| #include "extensions/common/extension_set.h" |
| @@ -37,7 +39,6 @@ bool LaunchAppWithUrl( |
| const std::string& handler_id, |
| content::WebContents* source, |
| const navigation_interception::NavigationParams& params) { |
| - DCHECK_CURRENTLY_ON(BrowserThread::UI); |
|
carlosk
2015/08/28 16:40:24
Can this method now be called from other threads b
clamy
2015/09/03 15:30:50
No the class now resides strictly on the UI thread
|
| // Redirect top-level navigations only. This excludes iframes and webviews |
| // in particular. |
| @@ -54,8 +55,7 @@ bool LaunchAppWithUrl( |
| return true; |
| } |
| - // These are guaranteed by CreateThrottleFor below. |
| - DCHECK(!params.is_post()); |
| + // This is guaranteed by CreateThrottleFor below. |
| DCHECK(UrlHandlers::CanExtensionHandleUrl(app.get(), params.url())); |
| Profile* profile = |
| @@ -73,57 +73,56 @@ bool LaunchAppWithUrl( |
| } // namespace |
| // static |
| -content::ResourceThrottle* |
| -AppUrlRedirector::MaybeCreateThrottleFor(net::URLRequest* request, |
| - ProfileIOData* profile_io_data) { |
| - DVLOG(1) << "Considering URL for redirection: " |
| - << request->method() << " " << request->url().spec(); |
| +scoped_ptr<content::NavigationThrottle> |
| +AppUrlRedirector::MaybeCreateThrottleFor(content::NavigationHandle* handle, |
| + content::WebContents* web_contents) { |
| + DVLOG(1) << "Considering URL for redirection: " << handle->GetURL().spec(); |
| + scoped_ptr<content::NavigationThrottle> throttle; |
| + |
| + content::BrowserContext* browser_context = web_contents->GetBrowserContext(); |
| + if (!browser_context) |
| + return throttle.Pass(); |
|
carlosk
2015/08/28 16:40:24
nit: IIRC you can return nullptr for scoped_ptr re
clamy
2015/09/03 15:30:51
Done.
|
| // Support only GET for now. |
| - if (request->method() != "GET") { |
| + if (handle->IsPost()) { |
| DVLOG(1) << "Skip redirection: method is not GET"; |
| - return NULL; |
| + return throttle.Pass(); |
| } |
| - if (!request->url().SchemeIsHTTPOrHTTPS()) { |
| + if (!handle->GetURL().SchemeIsHTTPOrHTTPS()) { |
| DVLOG(1) << "Skip redirection: scheme is not HTTP or HTTPS"; |
| - 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; |
| + return throttle.Pass(); |
| } |
| // 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. |
| - if (profile_io_data->IsOffTheRecord()) { |
| + Profile* profile = Profile::FromBrowserContext(browser_context); |
| + if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE) { |
| DVLOG(1) << "Skip redirection: unsupported in incognito"; |
| - return NULL; |
| + return throttle.Pass(); |
| } |
| - const extensions::ExtensionSet& extensions = |
| - profile_io_data->GetExtensionInfoMap()->extensions(); |
| - for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); |
| - iter != extensions.end(); |
| - ++iter) { |
| + const extensions::ExtensionSet& enabled_extensions = |
| + extensions::ExtensionRegistry::Get(web_contents->GetBrowserContext()) |
| + ->enabled_extensions(); |
| + for (extensions::ExtensionSet::const_iterator iter = |
| + enabled_extensions.begin(); |
| + iter != enabled_extensions.end(); ++iter) { |
| const UrlHandlerInfo* handler = |
| - UrlHandlers::FindMatchingUrlHandler(iter->get(), request->url()); |
| + UrlHandlers::FindMatchingUrlHandler(iter->get(), handle->GetURL()); |
| if (handler) { |
| DVLOG(1) << "Found matching app handler for redirection: " |
| << (*iter)->name() << "(" << (*iter)->id() << "):" |
| << handler->id; |
| - return new navigation_interception::InterceptNavigationResourceThrottle( |
| - request, |
| - base::Bind(&LaunchAppWithUrl, |
| - scoped_refptr<const Extension>(*iter), |
| - handler->id)); |
| + throttle.reset(new navigation_interception::InterceptNavigationThrottle( |
| + handle, web_contents, |
| + base::Bind(&LaunchAppWithUrl, scoped_refptr<const Extension>(*iter), |
| + handler->id))); |
| + return throttle.Pass(); |
| } |
| } |
| DVLOG(1) << "Skipping redirection: no matching app handler found"; |
| - return NULL; |
| + return throttle.Pass(); |
| } |