Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/arc/arc_navigation_throttle.h" | 5 #include "chrome/browser/chromeos/arc/arc_navigation_throttle.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "chrome/browser/chromeos/arc/page_transition_util.h" | 13 #include "chrome/browser/chromeos/arc/page_transition_util.h" |
| 14 #include "components/arc/arc_bridge_service.h" | 14 #include "components/arc/arc_bridge_service.h" |
| 15 #include "components/arc/arc_service_manager.h" | 15 #include "components/arc/arc_service_manager.h" |
| 16 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" | 16 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" |
| 17 #include "components/arc/intent_helper/local_activity_resolver.h" | 17 #include "components/arc/intent_helper/local_activity_resolver.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
| 20 #include "content/public/browser/navigation_handle.h" | 20 #include "content/public/browser/navigation_handle.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 22 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 23 #include "ui/base/page_transition_types.h" | 23 #include "ui/base/page_transition_types.h" |
| 24 #include "url/gurl.h" | |
| 24 | 25 |
| 25 namespace arc { | 26 namespace arc { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 constexpr int kMinInstanceVersion = 7; | 30 constexpr int kMinInstanceVersion = 7; |
| 30 | 31 |
| 31 scoped_refptr<ActivityIconLoader> GetIconLoader() { | 32 scoped_refptr<ActivityIconLoader> GetIconLoader() { |
| 32 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 33 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 33 ArcServiceManager* arc_service_manager = ArcServiceManager::Get(); | 34 ArcServiceManager* arc_service_manager = ArcServiceManager::Get(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 return HandleRequest(); | 78 return HandleRequest(); |
| 78 } | 79 } |
| 79 | 80 |
| 80 content::NavigationThrottle::ThrottleCheckResult | 81 content::NavigationThrottle::ThrottleCheckResult |
| 81 ArcNavigationThrottle::HandleRequest() { | 82 ArcNavigationThrottle::HandleRequest() { |
| 82 const GURL& url = navigation_handle()->GetURL(); | 83 const GURL& url = navigation_handle()->GetURL(); |
| 83 | 84 |
| 84 if (ShouldIgnoreNavigation(navigation_handle()->GetPageTransition())) | 85 if (ShouldIgnoreNavigation(navigation_handle()->GetPageTransition())) |
| 85 return content::NavigationThrottle::PROCEED; | 86 return content::NavigationThrottle::PROCEED; |
| 86 | 87 |
| 87 if (!ShouldOverrideUrlLoading(navigation_handle())) | 88 const GURL previous_url = navigation_handle()->GetReferrer().url; |
| 89 const GURL current_url = navigation_handle()->GetURL(); | |
| 90 if (!ShouldOverrideUrlLoading(previous_url, current_url)) | |
| 88 return content::NavigationThrottle::PROCEED; | 91 return content::NavigationThrottle::PROCEED; |
| 89 | 92 |
| 90 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); | 93 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); |
| 91 DCHECK(arc_service_manager); | 94 DCHECK(arc_service_manager); |
| 92 scoped_refptr<arc::LocalActivityResolver> local_resolver = | 95 scoped_refptr<arc::LocalActivityResolver> local_resolver = |
| 93 arc_service_manager->activity_resolver(); | 96 arc_service_manager->activity_resolver(); |
| 94 if (local_resolver->ShouldChromeHandleUrl(url)) { | 97 if (local_resolver->ShouldChromeHandleUrl(url)) { |
| 95 // Allow navigation to proceed if there isn't an android app that handles | 98 // Allow navigation to proceed if there isn't an android app that handles |
| 96 // the given URL. | 99 // the given URL. |
| 97 return content::NavigationThrottle::PROCEED; | 100 return content::NavigationThrottle::PROCEED; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 NOTREACHED(); | 245 NOTREACHED(); |
| 243 return; | 246 return; |
| 244 } | 247 } |
| 245 } | 248 } |
| 246 | 249 |
| 247 UMA_HISTOGRAM_ENUMERATION("Arc.IntentHandlerAction", | 250 UMA_HISTOGRAM_ENUMERATION("Arc.IntentHandlerAction", |
| 248 static_cast<int>(close_reason), | 251 static_cast<int>(close_reason), |
| 249 static_cast<int>(CloseReason::SIZE)); | 252 static_cast<int>(CloseReason::SIZE)); |
| 250 } | 253 } |
| 251 | 254 |
| 252 bool ArcNavigationThrottle::ShouldOverrideUrlLoading( | 255 // static |
| 253 content::NavigationHandle* navigation_handle) { | 256 bool ArcNavigationThrottle::ShouldOverrideUrlLoadingForTesting( |
| 254 GURL previous_url = navigation_handle->GetReferrer().url; | 257 const GURL& previous_url, |
| 255 GURL current_url = navigation_handle->GetURL(); | 258 const GURL& current_url) { |
| 259 return ShouldOverrideUrlLoading(previous_url, current_url); | |
| 260 } | |
| 261 | |
| 262 // static | |
| 263 bool ArcNavigationThrottle::ShouldOverrideUrlLoading(const GURL& previous_url, | |
| 264 const GURL& current_url) { | |
| 265 // 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.
| |
| 266 // can be empty. In this case, we should open it in the desktop browser. | |
| 267 if (!previous_url.is_valid() || previous_url.is_empty()) | |
| 268 return false; | |
| 269 | |
| 270 // Also check |current_url| just in case. | |
| 271 if (!current_url.is_valid() || current_url.is_empty()) { | |
| 272 DVLOG(1) << "Unexpected URL: " << current_url << ", opening it in Chrome."; | |
| 273 return false; | |
| 274 } | |
| 275 | |
| 256 return !net::registry_controlled_domains::SameDomainOrHost( | 276 return !net::registry_controlled_domains::SameDomainOrHost( |
| 257 current_url, previous_url, | 277 current_url, previous_url, |
| 258 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 278 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 259 } | 279 } |
| 260 | 280 |
| 261 } // namespace arc | 281 } // namespace arc |
| OLD | NEW |