| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 constexpr int kMinInstanceVersion = 7; | 26 constexpr int kMinInstanceVersion = 7; |
| 27 | 27 |
| 28 scoped_refptr<ActivityIconLoader> GetIconLoader() { | 28 scoped_refptr<ActivityIconLoader> GetIconLoader() { |
| 29 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 29 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 30 ArcServiceManager* arc_service_manager = ArcServiceManager::Get(); | 30 ArcServiceManager* arc_service_manager = ArcServiceManager::Get(); |
| 31 return arc_service_manager ? arc_service_manager->icon_loader() : nullptr; | 31 return arc_service_manager ? arc_service_manager->icon_loader() : nullptr; |
| 32 } | 32 } |
| 33 | 33 |
| 34 mojom::IntentHelperInstance* GetIntentHelper() { | |
| 35 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 36 ArcBridgeService* bridge_service = ArcBridgeService::Get(); | |
| 37 if (!bridge_service) { | |
| 38 VLOG(1) << "ARC bridge is not ready."; | |
| 39 return nullptr; | |
| 40 } | |
| 41 mojom::IntentHelperInstance* intent_helper_instance = | |
| 42 bridge_service->intent_helper()->instance(); | |
| 43 if (!intent_helper_instance) { | |
| 44 VLOG(1) << "ARC intent helper instance is not ready."; | |
| 45 return nullptr; | |
| 46 } | |
| 47 if (bridge_service->intent_helper()->version() < kMinInstanceVersion) { | |
| 48 VLOG(1) << "ARC intent helper instance is too old."; | |
| 49 return nullptr; | |
| 50 } | |
| 51 return intent_helper_instance; | |
| 52 } | |
| 53 | |
| 54 } // namespace | 34 } // namespace |
| 55 | 35 |
| 56 ArcNavigationThrottle::ArcNavigationThrottle( | 36 ArcNavigationThrottle::ArcNavigationThrottle( |
| 57 content::NavigationHandle* navigation_handle, | 37 content::NavigationHandle* navigation_handle, |
| 58 const ShowIntentPickerCallback& show_intent_picker_cb) | 38 const ShowIntentPickerCallback& show_intent_picker_cb) |
| 59 : content::NavigationThrottle(navigation_handle), | 39 : content::NavigationThrottle(navigation_handle), |
| 60 show_intent_picker_callback_(show_intent_picker_cb), | 40 show_intent_picker_callback_(show_intent_picker_cb), |
| 61 previous_user_action_(CloseReason::INVALID), | 41 previous_user_action_(CloseReason::INVALID), |
| 62 weak_ptr_factory_(this) {} | 42 weak_ptr_factory_(this) {} |
| 63 | 43 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); | 104 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); |
| 125 DCHECK(arc_service_manager); | 105 DCHECK(arc_service_manager); |
| 126 scoped_refptr<arc::LocalActivityResolver> local_resolver = | 106 scoped_refptr<arc::LocalActivityResolver> local_resolver = |
| 127 arc_service_manager->activity_resolver(); | 107 arc_service_manager->activity_resolver(); |
| 128 if (local_resolver->ShouldChromeHandleUrl(url)) { | 108 if (local_resolver->ShouldChromeHandleUrl(url)) { |
| 129 // Allow navigation to proceed if there isn't an android app that handles | 109 // Allow navigation to proceed if there isn't an android app that handles |
| 130 // the given URL. | 110 // the given URL. |
| 131 return content::NavigationThrottle::PROCEED; | 111 return content::NavigationThrottle::PROCEED; |
| 132 } | 112 } |
| 133 | 113 |
| 134 mojom::IntentHelperInstance* bridge_instance = GetIntentHelper(); | 114 mojom::IntentHelperInstance* bridge_instance = |
| 115 arc::ArcIntentHelperBridge::GetIntentHelperInstance(kMinInstanceVersion); |
| 135 if (!bridge_instance) | 116 if (!bridge_instance) |
| 136 return content::NavigationThrottle::PROCEED; | 117 return content::NavigationThrottle::PROCEED; |
| 137 bridge_instance->RequestUrlHandlerList( | 118 bridge_instance->RequestUrlHandlerList( |
| 138 url.spec(), base::Bind(&ArcNavigationThrottle::OnAppCandidatesReceived, | 119 url.spec(), base::Bind(&ArcNavigationThrottle::OnAppCandidatesReceived, |
| 139 weak_ptr_factory_.GetWeakPtr())); | 120 weak_ptr_factory_.GetWeakPtr())); |
| 140 return content::NavigationThrottle::DEFER; | 121 return content::NavigationThrottle::DEFER; |
| 141 } | 122 } |
| 142 | 123 |
| 143 // We received the array of app candidates to handle this URL (even the Chrome | 124 // We received the array of app candidates to handle this URL (even the Chrome |
| 144 // app is included). | 125 // app is included). |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 void ArcNavigationThrottle::OnIntentPickerClosed( | 210 void ArcNavigationThrottle::OnIntentPickerClosed( |
| 230 mojo::Array<mojom::UrlHandlerInfoPtr> handlers, | 211 mojo::Array<mojom::UrlHandlerInfoPtr> handlers, |
| 231 size_t selected_app_index, | 212 size_t selected_app_index, |
| 232 CloseReason close_reason) { | 213 CloseReason close_reason) { |
| 233 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 214 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 234 const GURL& url = navigation_handle()->GetURL(); | 215 const GURL& url = navigation_handle()->GetURL(); |
| 235 content::NavigationHandle* handle = navigation_handle(); | 216 content::NavigationHandle* handle = navigation_handle(); |
| 236 | 217 |
| 237 previous_user_action_ = close_reason; | 218 previous_user_action_ = close_reason; |
| 238 | 219 |
| 239 mojom::IntentHelperInstance* bridge = GetIntentHelper(); | 220 mojom::IntentHelperInstance* bridge = |
| 221 arc::ArcIntentHelperBridge::GetIntentHelperInstance(kMinInstanceVersion); |
| 240 if (!bridge || selected_app_index >= handlers.size()) { | 222 if (!bridge || selected_app_index >= handlers.size()) { |
| 241 close_reason = CloseReason::ERROR; | 223 close_reason = CloseReason::ERROR; |
| 242 } | 224 } |
| 243 | 225 |
| 244 switch (close_reason) { | 226 switch (close_reason) { |
| 245 case CloseReason::ERROR: | 227 case CloseReason::ERROR: |
| 246 case CloseReason::DIALOG_DEACTIVATED: { | 228 case CloseReason::DIALOG_DEACTIVATED: { |
| 247 // If the user fails to select an option from the list, or the UI returned | 229 // If the user fails to select an option from the list, or the UI returned |
| 248 // an error or if |selected_app_index| is not a valid index, then resume | 230 // an error or if |selected_app_index| is not a valid index, then resume |
| 249 // the navigation in Chrome. | 231 // the navigation in Chrome. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 bool ArcNavigationThrottle::ShouldOverrideUrlLoading( | 264 bool ArcNavigationThrottle::ShouldOverrideUrlLoading( |
| 283 content::NavigationHandle* navigation_handle) { | 265 content::NavigationHandle* navigation_handle) { |
| 284 GURL previous_url = navigation_handle->GetReferrer().url; | 266 GURL previous_url = navigation_handle->GetReferrer().url; |
| 285 GURL current_url = navigation_handle->GetURL(); | 267 GURL current_url = navigation_handle->GetURL(); |
| 286 return !net::registry_controlled_domains::SameDomainOrHost( | 268 return !net::registry_controlled_domains::SameDomainOrHost( |
| 287 current_url, previous_url, | 269 current_url, previous_url, |
| 288 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 270 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 289 } | 271 } |
| 290 | 272 |
| 291 } // namespace arc | 273 } // namespace arc |
| OLD | NEW |