Chromium Code Reviews| 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" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 // create a throttle. | 88 // create a throttle. |
| 89 DVLOG(1) | 89 DVLOG(1) |
| 90 << "Chrome browser is selected as the preferred app for this URL: " | 90 << "Chrome browser is selected as the preferred app for this URL: " |
| 91 << url_for_logging; | 91 << url_for_logging; |
| 92 } | 92 } |
| 93 return i; | 93 return i; |
| 94 } | 94 } |
| 95 return handlers.size(); // not found | 95 return handlers.size(); // not found |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Swaps Chrome app with any app in row |kMaxAppResults-1| iff its index is | |
| 99 // bigger, thus ensuring the user can always see Chrome without scrolling. | |
| 100 // When swap is needed, fills |out_indices| and returns true. If |handlers| | |
| 101 // do not have Chrome, returns false. | |
| 102 bool IsSwapElementsNeeded( | |
| 103 const mojo::Array<mojom::IntentHandlerInfoPtr>& handlers, | |
| 104 std::pair<size_t, size_t>* out_indices) { | |
| 105 size_t chrome_app_index = 0; | |
| 106 for (size_t i = 0; i < handlers.size(); ++i) { | |
| 107 if (ArcIntentHelperBridge::IsIntentHelperPackage( | |
| 108 handlers[i]->package_name)) { | |
| 109 chrome_app_index = i; | |
| 110 break; | |
| 111 } | |
| 112 } | |
| 113 if (chrome_app_index < ArcNavigationThrottle::kMaxAppResults) | |
| 114 return false; | |
| 115 | |
| 116 *out_indices = std::make_pair(ArcNavigationThrottle::kMaxAppResults - 1, | |
| 117 chrome_app_index); | |
| 118 return true; | |
| 119 } | |
| 120 | |
| 121 } // namespace | 98 } // namespace |
| 122 | 99 |
| 123 ArcNavigationThrottle::ArcNavigationThrottle( | 100 ArcNavigationThrottle::ArcNavigationThrottle( |
| 124 content::NavigationHandle* navigation_handle, | 101 content::NavigationHandle* navigation_handle, |
| 125 const ShowIntentPickerCallback& show_intent_picker_cb) | 102 const ShowIntentPickerCallback& show_intent_picker_cb) |
| 126 : content::NavigationThrottle(navigation_handle), | 103 : content::NavigationThrottle(navigation_handle), |
| 127 show_intent_picker_callback_(show_intent_picker_cb), | 104 show_intent_picker_callback_(show_intent_picker_cb), |
| 128 previous_user_action_(CloseReason::INVALID), | 105 previous_user_action_(CloseReason::INVALID), |
| 129 weak_ptr_factory_(this) {} | 106 weak_ptr_factory_(this) {} |
| 130 | 107 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 return IsAppAvailable(handlers); | 376 return IsAppAvailable(handlers); |
| 400 } | 377 } |
| 401 | 378 |
| 402 // static | 379 // static |
| 403 size_t ArcNavigationThrottle::FindPreferredAppForTesting( | 380 size_t ArcNavigationThrottle::FindPreferredAppForTesting( |
| 404 const mojo::Array<mojom::IntentHandlerInfoPtr>& handlers) { | 381 const mojo::Array<mojom::IntentHandlerInfoPtr>& handlers) { |
| 405 return FindPreferredApp(handlers, GURL()); | 382 return FindPreferredApp(handlers, GURL()); |
| 406 } | 383 } |
| 407 | 384 |
| 408 // static | 385 // static |
| 409 bool ArcNavigationThrottle::IsSwapElementsNeededForTesting( | 386 bool ArcNavigationThrottle::IsSwapElementsNeeded( |
| 410 const mojo::Array<mojom::IntentHandlerInfoPtr>& handlers, | 387 const mojo::Array<mojom::IntentHandlerInfoPtr>& handlers, |
| 411 std::pair<size_t, size_t>* out_indices) { | 388 std::pair<size_t, size_t>* out_indices) { |
| 412 return IsSwapElementsNeeded(handlers, out_indices); | 389 size_t chrome_app_index = 0; |
|
Yusuke Sato
2016/11/05 01:19:26
moved the function as-is. no change.
| |
| 390 for (size_t i = 0; i < handlers.size(); ++i) { | |
| 391 if (ArcIntentHelperBridge::IsIntentHelperPackage( | |
| 392 handlers[i]->package_name)) { | |
| 393 chrome_app_index = i; | |
| 394 break; | |
| 395 } | |
| 396 } | |
| 397 if (chrome_app_index < ArcNavigationThrottle::kMaxAppResults) | |
| 398 return false; | |
| 399 | |
| 400 *out_indices = std::make_pair(ArcNavigationThrottle::kMaxAppResults - 1, | |
| 401 chrome_app_index); | |
| 402 return true; | |
| 413 } | 403 } |
| 414 | 404 |
| 415 } // namespace arc | 405 } // namespace arc |
| OLD | NEW |