| 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(); |
| 34 return arc_service_manager ? arc_service_manager->icon_loader() : nullptr; | 35 return arc_service_manager ? arc_service_manager->icon_loader() : nullptr; |
| 35 } | 36 } |
| 36 | 37 |
| 38 // Compares the host name of the referrer and target URL to decide whether |
| 39 // the navigation needs to be overriden. |
| 40 bool ShouldOverrideUrlLoading(const GURL& previous_url, |
| 41 const GURL& current_url) { |
| 42 // When the navigation is initiated in a web page where sending a referrer |
| 43 // is disabled, |previous_url| can be empty. In this case, we should open |
| 44 // it in the desktop browser. |
| 45 if (!previous_url.is_valid() || previous_url.is_empty()) |
| 46 return false; |
| 47 |
| 48 // Also check |current_url| just in case. |
| 49 if (!current_url.is_valid() || current_url.is_empty()) { |
| 50 DVLOG(1) << "Unexpected URL: " << current_url << ", opening it in Chrome."; |
| 51 return false; |
| 52 } |
| 53 |
| 54 return !net::registry_controlled_domains::SameDomainOrHost( |
| 55 current_url, previous_url, |
| 56 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 57 } |
| 58 |
| 37 } // namespace | 59 } // namespace |
| 38 | 60 |
| 39 ArcNavigationThrottle::ArcNavigationThrottle( | 61 ArcNavigationThrottle::ArcNavigationThrottle( |
| 40 content::NavigationHandle* navigation_handle, | 62 content::NavigationHandle* navigation_handle, |
| 41 const ShowIntentPickerCallback& show_intent_picker_cb) | 63 const ShowIntentPickerCallback& show_intent_picker_cb) |
| 42 : content::NavigationThrottle(navigation_handle), | 64 : content::NavigationThrottle(navigation_handle), |
| 43 show_intent_picker_callback_(show_intent_picker_cb), | 65 show_intent_picker_callback_(show_intent_picker_cb), |
| 44 previous_user_action_(CloseReason::INVALID), | 66 previous_user_action_(CloseReason::INVALID), |
| 45 weak_ptr_factory_(this) {} | 67 weak_ptr_factory_(this) {} |
| 46 | 68 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 77 return HandleRequest(); | 99 return HandleRequest(); |
| 78 } | 100 } |
| 79 | 101 |
| 80 content::NavigationThrottle::ThrottleCheckResult | 102 content::NavigationThrottle::ThrottleCheckResult |
| 81 ArcNavigationThrottle::HandleRequest() { | 103 ArcNavigationThrottle::HandleRequest() { |
| 82 const GURL& url = navigation_handle()->GetURL(); | 104 const GURL& url = navigation_handle()->GetURL(); |
| 83 | 105 |
| 84 if (ShouldIgnoreNavigation(navigation_handle()->GetPageTransition())) | 106 if (ShouldIgnoreNavigation(navigation_handle()->GetPageTransition())) |
| 85 return content::NavigationThrottle::PROCEED; | 107 return content::NavigationThrottle::PROCEED; |
| 86 | 108 |
| 87 if (!ShouldOverrideUrlLoading(navigation_handle())) | 109 const GURL previous_url = navigation_handle()->GetReferrer().url; |
| 110 const GURL current_url = navigation_handle()->GetURL(); |
| 111 if (!ShouldOverrideUrlLoading(previous_url, current_url)) |
| 88 return content::NavigationThrottle::PROCEED; | 112 return content::NavigationThrottle::PROCEED; |
| 89 | 113 |
| 90 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); | 114 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); |
| 91 DCHECK(arc_service_manager); | 115 DCHECK(arc_service_manager); |
| 92 scoped_refptr<arc::LocalActivityResolver> local_resolver = | 116 scoped_refptr<arc::LocalActivityResolver> local_resolver = |
| 93 arc_service_manager->activity_resolver(); | 117 arc_service_manager->activity_resolver(); |
| 94 if (local_resolver->ShouldChromeHandleUrl(url)) { | 118 if (local_resolver->ShouldChromeHandleUrl(url)) { |
| 95 // Allow navigation to proceed if there isn't an android app that handles | 119 // Allow navigation to proceed if there isn't an android app that handles |
| 96 // the given URL. | 120 // the given URL. |
| 97 return content::NavigationThrottle::PROCEED; | 121 return content::NavigationThrottle::PROCEED; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 NOTREACHED(); | 266 NOTREACHED(); |
| 243 return; | 267 return; |
| 244 } | 268 } |
| 245 } | 269 } |
| 246 | 270 |
| 247 UMA_HISTOGRAM_ENUMERATION("Arc.IntentHandlerAction", | 271 UMA_HISTOGRAM_ENUMERATION("Arc.IntentHandlerAction", |
| 248 static_cast<int>(close_reason), | 272 static_cast<int>(close_reason), |
| 249 static_cast<int>(CloseReason::SIZE)); | 273 static_cast<int>(CloseReason::SIZE)); |
| 250 } | 274 } |
| 251 | 275 |
| 252 bool ArcNavigationThrottle::ShouldOverrideUrlLoading( | 276 // static |
| 253 content::NavigationHandle* navigation_handle) { | 277 bool ArcNavigationThrottle::ShouldOverrideUrlLoadingForTesting( |
| 254 GURL previous_url = navigation_handle->GetReferrer().url; | 278 const GURL& previous_url, |
| 255 GURL current_url = navigation_handle->GetURL(); | 279 const GURL& current_url) { |
| 256 return !net::registry_controlled_domains::SameDomainOrHost( | 280 return ShouldOverrideUrlLoading(previous_url, current_url); |
| 257 current_url, previous_url, | |
| 258 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | |
| 259 } | 281 } |
| 260 | 282 |
| 261 } // namespace arc | 283 } // namespace arc |
| OLD | NEW |