| 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 "components/arc/arc_bridge_service.h" | 13 #include "components/arc/arc_bridge_service.h" |
| 14 #include "components/arc/arc_service_manager.h" | 14 #include "components/arc/arc_service_manager.h" |
| 15 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" | 15 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" |
| 16 #include "components/arc/intent_helper/local_activity_resolver.h" | 16 #include "components/arc/intent_helper/local_activity_resolver.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/navigation_handle.h" | 18 #include "content/public/browser/navigation_handle.h" |
| 19 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 19 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 20 #include "ui/base/page_transition_types.h" | 20 #include "ui/base/page_transition_types.h" |
| 21 #include "url/gurl.h" |
| 21 | 22 |
| 22 namespace arc { | 23 namespace arc { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 constexpr int kMinInstanceVersion = 7; | 27 constexpr int kMinInstanceVersion = 7; |
| 27 | 28 |
| 28 scoped_refptr<ActivityIconLoader> GetIconLoader() { | 29 scoped_refptr<ActivityIconLoader> GetIconLoader() { |
| 29 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 30 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 30 ArcServiceManager* arc_service_manager = ArcServiceManager::Get(); | 31 ArcServiceManager* arc_service_manager = ArcServiceManager::Get(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 44 VLOG(1) << "ARC intent helper instance is not ready."; | 45 VLOG(1) << "ARC intent helper instance is not ready."; |
| 45 return nullptr; | 46 return nullptr; |
| 46 } | 47 } |
| 47 if (bridge_service->intent_helper()->version() < kMinInstanceVersion) { | 48 if (bridge_service->intent_helper()->version() < kMinInstanceVersion) { |
| 48 VLOG(1) << "ARC intent helper instance is too old."; | 49 VLOG(1) << "ARC intent helper instance is too old."; |
| 49 return nullptr; | 50 return nullptr; |
| 50 } | 51 } |
| 51 return intent_helper_instance; | 52 return intent_helper_instance; |
| 52 } | 53 } |
| 53 | 54 |
| 55 // Compares the host name of the referrer and target URL to decide whether |
| 56 // the navigation needs to be overriden. |
| 57 bool ShouldOverrideUrlLoading(const GURL& previous_url, |
| 58 const GURL& current_url) { |
| 59 // When the navigation is initiated in a web page where sending a referrer |
| 60 // is disabled, |previous_url| can be empty. In this case, we should open |
| 61 // it in the desktop browser. |
| 62 if (!previous_url.is_valid() || previous_url.is_empty()) |
| 63 return false; |
| 64 |
| 65 // Also check |current_url| just in case. |
| 66 if (!current_url.is_valid() || current_url.is_empty()) { |
| 67 DVLOG(1) << "Unexpected URL: " << current_url << ", opening it in Chrome."; |
| 68 return false; |
| 69 } |
| 70 |
| 71 return !net::registry_controlled_domains::SameDomainOrHost( |
| 72 current_url, previous_url, |
| 73 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 74 } |
| 75 |
| 54 } // namespace | 76 } // namespace |
| 55 | 77 |
| 56 ArcNavigationThrottle::ArcNavigationThrottle( | 78 ArcNavigationThrottle::ArcNavigationThrottle( |
| 57 content::NavigationHandle* navigation_handle, | 79 content::NavigationHandle* navigation_handle, |
| 58 const ShowIntentPickerCallback& show_intent_picker_cb) | 80 const ShowIntentPickerCallback& show_intent_picker_cb) |
| 59 : content::NavigationThrottle(navigation_handle), | 81 : content::NavigationThrottle(navigation_handle), |
| 60 show_intent_picker_callback_(show_intent_picker_cb), | 82 show_intent_picker_callback_(show_intent_picker_cb), |
| 61 previous_user_action_(CloseReason::INVALID), | 83 previous_user_action_(CloseReason::INVALID), |
| 62 weak_ptr_factory_(this) {} | 84 weak_ptr_factory_(this) {} |
| 63 | 85 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 133 } |
| 112 | 134 |
| 113 if (ui::PageTransitionGetQualifier(transition) != 0) { | 135 if (ui::PageTransitionGetQualifier(transition) != 0) { |
| 114 // Qualifiers indicate that this navigation was the result of a click on a | 136 // Qualifiers indicate that this navigation was the result of a click on a |
| 115 // forward/back button, or typing in the URL bar, etc. Don't pass any of | 137 // forward/back button, or typing in the URL bar, etc. Don't pass any of |
| 116 // those types of navigations to the intent helper (see crbug.com/630072). | 138 // those types of navigations to the intent helper (see crbug.com/630072). |
| 117 // Note that redirects, which we do pass on, are masked out above. | 139 // Note that redirects, which we do pass on, are masked out above. |
| 118 return content::NavigationThrottle::PROCEED; | 140 return content::NavigationThrottle::PROCEED; |
| 119 } | 141 } |
| 120 | 142 |
| 121 if (!ShouldOverrideUrlLoading(navigation_handle())) | 143 const GURL previous_url = navigation_handle()->GetReferrer().url; |
| 144 const GURL current_url = navigation_handle()->GetURL(); |
| 145 if (!ShouldOverrideUrlLoading(previous_url, current_url)) |
| 122 return content::NavigationThrottle::PROCEED; | 146 return content::NavigationThrottle::PROCEED; |
| 123 | 147 |
| 124 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); | 148 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); |
| 125 DCHECK(arc_service_manager); | 149 DCHECK(arc_service_manager); |
| 126 scoped_refptr<arc::LocalActivityResolver> local_resolver = | 150 scoped_refptr<arc::LocalActivityResolver> local_resolver = |
| 127 arc_service_manager->activity_resolver(); | 151 arc_service_manager->activity_resolver(); |
| 128 if (local_resolver->ShouldChromeHandleUrl(url)) { | 152 if (local_resolver->ShouldChromeHandleUrl(url)) { |
| 129 // Allow navigation to proceed if there isn't an android app that handles | 153 // Allow navigation to proceed if there isn't an android app that handles |
| 130 // the given URL. | 154 // the given URL. |
| 131 return content::NavigationThrottle::PROCEED; | 155 return content::NavigationThrottle::PROCEED; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 NOTREACHED(); | 296 NOTREACHED(); |
| 273 return; | 297 return; |
| 274 } | 298 } |
| 275 } | 299 } |
| 276 | 300 |
| 277 UMA_HISTOGRAM_ENUMERATION("Arc.IntentHandlerAction", | 301 UMA_HISTOGRAM_ENUMERATION("Arc.IntentHandlerAction", |
| 278 static_cast<int>(close_reason), | 302 static_cast<int>(close_reason), |
| 279 static_cast<int>(CloseReason::SIZE)); | 303 static_cast<int>(CloseReason::SIZE)); |
| 280 } | 304 } |
| 281 | 305 |
| 282 bool ArcNavigationThrottle::ShouldOverrideUrlLoading( | 306 // static |
| 283 content::NavigationHandle* navigation_handle) { | 307 bool ArcNavigationThrottle::ShouldOverrideUrlLoadingForTesting( |
| 284 GURL previous_url = navigation_handle->GetReferrer().url; | 308 const GURL& previous_url, |
| 285 GURL current_url = navigation_handle->GetURL(); | 309 const GURL& current_url) { |
| 286 return !net::registry_controlled_domains::SameDomainOrHost( | 310 return ShouldOverrideUrlLoading(previous_url, current_url); |
| 287 current_url, previous_url, | |
| 288 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | |
| 289 } | 311 } |
| 290 | 312 |
| 291 } // namespace arc | 313 } // namespace arc |
| OLD | NEW |