| 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_external_protocol_dialog
.h" | 5 #include "chrome/browser/chromeos/arc/intent_helper/arc_external_protocol_dialog
.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 // Shows the Chrome OS' original external protocol dialog as a fallback. | 42 // Shows the Chrome OS' original external protocol dialog as a fallback. |
| 43 void ShowFallbackExternalProtocolDialog(int render_process_host_id, | 43 void ShowFallbackExternalProtocolDialog(int render_process_host_id, |
| 44 int routing_id, | 44 int routing_id, |
| 45 const GURL& url) { | 45 const GURL& url) { |
| 46 WebContents* web_contents = | 46 WebContents* web_contents = |
| 47 tab_util::GetWebContentsByID(render_process_host_id, routing_id); | 47 tab_util::GetWebContentsByID(render_process_host_id, routing_id); |
| 48 new ExternalProtocolDialog(web_contents, url); | 48 new ExternalProtocolDialog(web_contents, url); |
| 49 } | 49 } |
| 50 | 50 |
| 51 scoped_refptr<ActivityIconLoader> GetIconLoader() { | |
| 52 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 53 ArcServiceManager* arc_service_manager = ArcServiceManager::Get(); | |
| 54 return arc_service_manager ? arc_service_manager->icon_loader() : nullptr; | |
| 55 } | |
| 56 | |
| 57 void CloseTabIfNeeded(int render_process_host_id, int routing_id) { | 51 void CloseTabIfNeeded(int render_process_host_id, int routing_id) { |
| 58 WebContents* web_contents = | 52 WebContents* web_contents = |
| 59 tab_util::GetWebContentsByID(render_process_host_id, routing_id); | 53 tab_util::GetWebContentsByID(render_process_host_id, routing_id); |
| 60 if (web_contents && web_contents->GetController().IsInitialNavigation()) | 54 if (web_contents && web_contents->GetController().IsInitialNavigation()) |
| 61 web_contents->Close(); | 55 web_contents->Close(); |
| 62 } | 56 } |
| 63 | 57 |
| 64 // Shows |url| in the current tab. | 58 // Shows |url| in the current tab. |
| 65 void OpenUrlInChrome(int render_process_host_id, | 59 void OpenUrlInChrome(int render_process_host_id, |
| 66 int routing_id, | 60 int routing_id, |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 359 |
| 366 auto* arc_service_manager = ArcServiceManager::Get(); | 360 auto* arc_service_manager = ArcServiceManager::Get(); |
| 367 if (!arc_service_manager) { | 361 if (!arc_service_manager) { |
| 368 // ARC is not running anymore. Show the Chrome OS dialog. | 362 // ARC is not running anymore. Show the Chrome OS dialog. |
| 369 ShowFallbackExternalProtocolDialog(render_process_host_id, routing_id, url); | 363 ShowFallbackExternalProtocolDialog(render_process_host_id, routing_id, url); |
| 370 return; | 364 return; |
| 371 } | 365 } |
| 372 | 366 |
| 373 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( | 367 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( |
| 374 arc_service_manager->arc_bridge_service()->intent_helper(), HandleUrl); | 368 arc_service_manager->arc_bridge_service()->intent_helper(), HandleUrl); |
| 375 scoped_refptr<ActivityIconLoader> icon_loader = GetIconLoader(); | 369 auto* intent_helper_bridge = |
| 376 | 370 ArcServiceManager::GetGlobalService<ArcIntentHelperBridge>(); |
| 377 if (!instance || !icon_loader) { | 371 if (!instance || !intent_helper_bridge) { |
| 378 // ARC is not running anymore. Show the Chrome OS dialog. | 372 // ARC is not running anymore. Show the Chrome OS dialog. |
| 379 ShowFallbackExternalProtocolDialog(render_process_host_id, routing_id, url); | 373 ShowFallbackExternalProtocolDialog(render_process_host_id, routing_id, url); |
| 380 return; | 374 return; |
| 381 } | 375 } |
| 382 | 376 |
| 383 // Check if the |url| should be handled right away without showing the UI. | 377 // Check if the |url| should be handled right away without showing the UI. |
| 384 GetActionResult result; | 378 GetActionResult result; |
| 385 if (HandleUrl(render_process_host_id, routing_id, url, always_ask_user, | 379 if (HandleUrl(render_process_host_id, routing_id, url, always_ask_user, |
| 386 handlers, handlers.size(), &result)) { | 380 handlers, handlers.size(), &result)) { |
| 387 if (result == GetActionResult::HANDLE_URL_IN_ARC) { | 381 if (result == GetActionResult::HANDLE_URL_IN_ARC) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 398 // |url| is intent: with fallback or geo:, for example, it may be. | 392 // |url| is intent: with fallback or geo:, for example, it may be. |
| 399 std::pair<size_t, size_t> indices; | 393 std::pair<size_t, size_t> indices; |
| 400 if (ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) | 394 if (ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) |
| 401 std::swap(handlers[indices.first], handlers[indices.second]); | 395 std::swap(handlers[indices.first], handlers[indices.second]); |
| 402 | 396 |
| 403 // Then request the icons. | 397 // Then request the icons. |
| 404 std::vector<ActivityIconLoader::ActivityName> activities; | 398 std::vector<ActivityIconLoader::ActivityName> activities; |
| 405 for (const auto& handler : handlers) { | 399 for (const auto& handler : handlers) { |
| 406 activities.emplace_back(handler->package_name, handler->activity_name); | 400 activities.emplace_back(handler->package_name, handler->activity_name); |
| 407 } | 401 } |
| 408 icon_loader->GetActivityIcons( | 402 intent_helper_bridge->icon_loader()->GetActivityIcons( |
| 409 activities, base::Bind(OnAppIconsReceived, render_process_host_id, | 403 activities, base::Bind(OnAppIconsReceived, render_process_host_id, |
| 410 routing_id, url, base::Passed(&handlers))); | 404 routing_id, url, base::Passed(&handlers))); |
| 411 } | 405 } |
| 412 | 406 |
| 413 // Returns true if the |url| is safe to be forwarded to ARC without showing the | 407 // Returns true if the |url| is safe to be forwarded to ARC without showing the |
| 414 // disambig dialog when there is a preferred app on ARC for the |url|. Note that | 408 // disambig dialog when there is a preferred app on ARC for the |url|. Note that |
| 415 // this function almost always returns true (i.e. "safe") except for very rare | 409 // this function almost always returns true (i.e. "safe") except for very rare |
| 416 // situations mentioned below. | 410 // situations mentioned below. |
| 417 // TODO(yusukes|djacobo): Find a better way to detect a request loop and remove | 411 // TODO(yusukes|djacobo): Find a better way to detect a request loop and remove |
| 418 // these heuristics. | 412 // these heuristics. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 bool IsSafeToRedirectToArcWithoutUserConfirmationForTesting( | 508 bool IsSafeToRedirectToArcWithoutUserConfirmationForTesting( |
| 515 const GURL& url, | 509 const GURL& url, |
| 516 ui::PageTransition page_transition, | 510 ui::PageTransition page_transition, |
| 517 const GURL& last_url, | 511 const GURL& last_url, |
| 518 ui::PageTransition last_page_transition) { | 512 ui::PageTransition last_page_transition) { |
| 519 return IsSafeToRedirectToArcWithoutUserConfirmation( | 513 return IsSafeToRedirectToArcWithoutUserConfirmation( |
| 520 url, page_transition, last_url, last_page_transition); | 514 url, page_transition, last_url, last_page_transition); |
| 521 } | 515 } |
| 522 | 516 |
| 523 } // namespace arc | 517 } // namespace arc |
| OLD | NEW |