| 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/intent_helper/arc_navigation_throttle.h" | 5 #include "chrome/browser/chromeos/arc/intent_helper/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 "components/arc/intent_helper/page_transition_util.h" | 17 #include "components/arc/intent_helper/page_transition_util.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/site_instance.h" | 21 #include "content/public/browser/site_instance.h" |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 23 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 24 #include "ui/base/page_transition_types.h" | 24 #include "ui/base/page_transition_types.h" |
| 25 | 25 |
| 26 namespace arc { | 26 namespace arc { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 scoped_refptr<ActivityIconLoader> GetIconLoader() { | |
| 31 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 32 ArcServiceManager* arc_service_manager = ArcServiceManager::Get(); | |
| 33 return arc_service_manager ? arc_service_manager->icon_loader() : nullptr; | |
| 34 } | |
| 35 | |
| 36 // Compares the host name of the referrer and target URL to decide whether | 30 // Compares the host name of the referrer and target URL to decide whether |
| 37 // the navigation needs to be overriden. | 31 // the navigation needs to be overriden. |
| 38 bool ShouldOverrideUrlLoading(const GURL& previous_url, | 32 bool ShouldOverrideUrlLoading(const GURL& previous_url, |
| 39 const GURL& current_url) { | 33 const GURL& current_url) { |
| 40 // When the navigation is initiated in a web page where sending a referrer | 34 // When the navigation is initiated in a web page where sending a referrer |
| 41 // is disabled, |previous_url| can be empty. In this case, we should open | 35 // is disabled, |previous_url| can be empty. In this case, we should open |
| 42 // it in the desktop browser. | 36 // it in the desktop browser. |
| 43 if (!previous_url.is_valid() || previous_url.is_empty()) | 37 if (!previous_url.is_valid() || previous_url.is_empty()) |
| 44 return false; | 38 return false; |
| 45 | 39 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 const std::string package_name = handlers[index]->package_name; | 234 const std::string package_name = handlers[index]->package_name; |
| 241 OnIntentPickerClosed(std::move(handlers), package_name, | 235 OnIntentPickerClosed(std::move(handlers), package_name, |
| 242 CloseReason::PREFERRED_ACTIVITY_FOUND); | 236 CloseReason::PREFERRED_ACTIVITY_FOUND); |
| 243 return; | 237 return; |
| 244 } | 238 } |
| 245 | 239 |
| 246 std::pair<size_t, size_t> indices; | 240 std::pair<size_t, size_t> indices; |
| 247 if (IsSwapElementsNeeded(handlers, &indices)) | 241 if (IsSwapElementsNeeded(handlers, &indices)) |
| 248 std::swap(handlers[indices.first], handlers[indices.second]); | 242 std::swap(handlers[indices.first], handlers[indices.second]); |
| 249 | 243 |
| 250 scoped_refptr<ActivityIconLoader> icon_loader = GetIconLoader(); | 244 auto* intent_helper_bridge = |
| 251 if (!icon_loader) { | 245 ArcServiceManager::GetGlobalService<ArcIntentHelperBridge>(); |
| 252 LOG(ERROR) << "Cannot get an instance of ActivityIconLoader"; | 246 if (!intent_helper_bridge) { |
| 247 LOG(ERROR) << "Cannot get an instance of ArcIntentHelperBridge"; |
| 253 navigation_handle()->Resume(); | 248 navigation_handle()->Resume(); |
| 254 return; | 249 return; |
| 255 } | 250 } |
| 256 std::vector<ActivityIconLoader::ActivityName> activities; | 251 std::vector<ArcIntentHelperBridge::ActivityName> activities; |
| 257 for (const auto& handler : handlers) | 252 for (const auto& handler : handlers) |
| 258 activities.emplace_back(handler->package_name, handler->activity_name); | 253 activities.emplace_back(handler->package_name, handler->activity_name); |
| 259 icon_loader->GetActivityIcons( | 254 intent_helper_bridge->GetActivityIcons( |
| 260 activities, | 255 activities, |
| 261 base::Bind(&ArcNavigationThrottle::OnAppIconsReceived, | 256 base::Bind(&ArcNavigationThrottle::OnAppIconsReceived, |
| 262 weak_ptr_factory_.GetWeakPtr(), base::Passed(&handlers))); | 257 weak_ptr_factory_.GetWeakPtr(), base::Passed(&handlers))); |
| 263 } | 258 } |
| 264 | 259 |
| 265 void ArcNavigationThrottle::OnAppIconsReceived( | 260 void ArcNavigationThrottle::OnAppIconsReceived( |
| 266 std::vector<mojom::IntentHandlerInfoPtr> handlers, | 261 std::vector<mojom::IntentHandlerInfoPtr> handlers, |
| 267 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons) { | 262 std::unique_ptr<ArcIntentHelperBridge::ActivityToIconsMap> icons) { |
| 268 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 263 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 269 std::vector<AppInfo> app_info; | 264 std::vector<AppInfo> app_info; |
| 270 | 265 |
| 271 for (const auto& handler : handlers) { | 266 for (const auto& handler : handlers) { |
| 272 gfx::Image icon; | 267 gfx::Image icon; |
| 273 const ActivityIconLoader::ActivityName activity(handler->package_name, | 268 const ArcIntentHelperBridge::ActivityName activity(handler->package_name, |
| 274 handler->activity_name); | 269 handler->activity_name); |
| 275 const auto it = icons->find(activity); | 270 const auto it = icons->find(activity); |
| 276 | 271 |
| 277 app_info.emplace_back( | 272 app_info.emplace_back( |
| 278 AppInfo(it != icons->end() ? it->second.icon20 : gfx::Image(), | 273 AppInfo(it != icons->end() ? it->second.icon20 : gfx::Image(), |
| 279 handler->package_name, handler->name)); | 274 handler->package_name, handler->name)); |
| 280 } | 275 } |
| 281 | 276 |
| 282 show_intent_picker_callback_.Run( | 277 show_intent_picker_callback_.Run( |
| 283 navigation_handle()->GetWebContents(), app_info, | 278 navigation_handle()->GetWebContents(), app_info, |
| 284 base::Bind(&ArcNavigationThrottle::OnIntentPickerClosed, | 279 base::Bind(&ArcNavigationThrottle::OnIntentPickerClosed, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 } | 423 } |
| 429 if (chrome_app_index < ArcNavigationThrottle::kMaxAppResults) | 424 if (chrome_app_index < ArcNavigationThrottle::kMaxAppResults) |
| 430 return false; | 425 return false; |
| 431 | 426 |
| 432 *out_indices = std::make_pair(ArcNavigationThrottle::kMaxAppResults - 1, | 427 *out_indices = std::make_pair(ArcNavigationThrottle::kMaxAppResults - 1, |
| 433 chrome_app_index); | 428 chrome_app_index); |
| 434 return true; | 429 return true; |
| 435 } | 430 } |
| 436 | 431 |
| 437 } // namespace arc | 432 } // namespace arc |
| OLD | NEW |