Chromium Code Reviews| Index: chrome/browser/chromeos/arc/arc_navigation_throttle.cc |
| diff --git a/chrome/browser/chromeos/arc/arc_navigation_throttle.cc b/chrome/browser/chromeos/arc/arc_navigation_throttle.cc |
| index 317c2d68aad03829c43a5596302cce9d87d97037..883151731da41dbaee8be230f62e0f019f8b9791 100644 |
| --- a/chrome/browser/chromeos/arc/arc_navigation_throttle.cc |
| +++ b/chrome/browser/chromeos/arc/arc_navigation_throttle.cc |
| @@ -21,6 +21,7 @@ |
| #include "content/public/browser/web_contents.h" |
| #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| #include "ui/base/page_transition_types.h" |
| +#include "url/gurl.h" |
| namespace arc { |
| @@ -84,7 +85,9 @@ ArcNavigationThrottle::HandleRequest() { |
| if (ShouldIgnoreNavigation(navigation_handle()->GetPageTransition())) |
| return content::NavigationThrottle::PROCEED; |
| - if (!ShouldOverrideUrlLoading(navigation_handle())) |
| + const GURL previous_url = navigation_handle()->GetReferrer().url; |
| + const GURL current_url = navigation_handle()->GetURL(); |
| + if (!ShouldOverrideUrlLoading(previous_url, current_url)) |
| return content::NavigationThrottle::PROCEED; |
| arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); |
| @@ -249,10 +252,27 @@ void ArcNavigationThrottle::OnIntentPickerClosed( |
| static_cast<int>(CloseReason::SIZE)); |
| } |
| -bool ArcNavigationThrottle::ShouldOverrideUrlLoading( |
| - content::NavigationHandle* navigation_handle) { |
| - GURL previous_url = navigation_handle->GetReferrer().url; |
| - GURL current_url = navigation_handle->GetURL(); |
| +// static |
| +bool ArcNavigationThrottle::ShouldOverrideUrlLoadingForTesting( |
| + const GURL& previous_url, |
| + const GURL& current_url) { |
| + return ShouldOverrideUrlLoading(previous_url, current_url); |
| +} |
| + |
| +// static |
| +bool ArcNavigationThrottle::ShouldOverrideUrlLoading(const GURL& previous_url, |
| + const GURL& current_url) { |
| + // When the navigation is initiated via e.g. JavaScript code, the referrer |
|
Yusuke Sato
2016/09/20 22:47:56
Slightly modified the comment too.
|
| + // can be empty. In this case, we should open it in the desktop browser. |
| + if (!previous_url.is_valid() || previous_url.is_empty()) |
| + return false; |
| + |
| + // Also check |current_url| just in case. |
| + if (!current_url.is_valid() || current_url.is_empty()) { |
| + DVLOG(1) << "Unexpected URL: " << current_url << ", opening it in Chrome."; |
| + return false; |
| + } |
| + |
| return !net::registry_controlled_domains::SameDomainOrHost( |
| current_url, previous_url, |
| net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |