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_external_protocol_dialog.h" | 5 #include "chrome/browser/chromeos/arc/arc_external_protocol_dialog.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 // Called when the dialog is closed. | 68 // Called when the dialog is closed. |
69 void OnIntentPickerClosed(int render_process_host_id, | 69 void OnIntentPickerClosed(int render_process_host_id, |
70 int routing_id, | 70 int routing_id, |
71 const GURL& url, | 71 const GURL& url, |
72 mojo::Array<mojom::IntentHandlerInfoPtr> handlers, | 72 mojo::Array<mojom::IntentHandlerInfoPtr> handlers, |
73 std::string selected_app_package, | 73 std::string selected_app_package, |
74 ArcNavigationThrottle::CloseReason close_reason) { | 74 ArcNavigationThrottle::CloseReason close_reason) { |
75 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 75 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
76 | 76 |
77 size_t selected_app_index = handlers.size(); | 77 // If the user selected an app to continue the navigation, confirm that the |
| 78 // |package_name| matches a valid option and return the index. |
| 79 const size_t selected_app_index = |
| 80 ArcNavigationThrottle::GetAppIndex(handlers, selected_app_package); |
78 // Make sure that the instance at least supports HandleUrl. | 81 // Make sure that the instance at least supports HandleUrl. |
79 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance( | 82 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance( |
80 "HandleUrl", kMinVersionForHandleUrl); | 83 "HandleUrl", kMinVersionForHandleUrl); |
81 if (!instance) { | 84 if (!instance) { |
82 close_reason = ArcNavigationThrottle::CloseReason::ERROR; | 85 close_reason = ArcNavigationThrottle::CloseReason::ERROR; |
83 } else if (close_reason == | 86 } else if (close_reason == |
84 ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED || | 87 ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED || |
85 close_reason == | 88 close_reason == |
86 ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED) { | 89 ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED) { |
87 // If the user selected an app to continue the navigation, confirm that the | |
88 // |package_name| matches a valid option and return the index. | |
89 for (size_t i = 0; i < handlers.size(); ++i) { | |
90 if (handlers[i]->package_name == selected_app_package) { | |
91 selected_app_index = i; | |
92 break; | |
93 } | |
94 } | |
95 | |
96 if (selected_app_index == handlers.size()) | 90 if (selected_app_index == handlers.size()) |
97 close_reason = ArcNavigationThrottle::CloseReason::ERROR; | 91 close_reason = ArcNavigationThrottle::CloseReason::ERROR; |
98 } | 92 } |
99 | 93 |
100 switch (close_reason) { | 94 switch (close_reason) { |
101 case ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED: { | 95 case ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED: { |
102 if (ArcIntentHelperBridge::GetIntentHelperInstance( | 96 if (ArcIntentHelperBridge::GetIntentHelperInstance( |
103 "AddPreferredPackage", kMinVersionForAddPreferredPackage)) { | 97 "AddPreferredPackage", kMinVersionForAddPreferredPackage)) { |
104 instance->AddPreferredPackage( | 98 instance->AddPreferredPackage( |
105 handlers[selected_app_index]->package_name); | 99 handlers[selected_app_index]->package_name); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 223 |
230 // Show ARC version of the dialog, which is IntentPickerBubbleView. To show | 224 // Show ARC version of the dialog, which is IntentPickerBubbleView. To show |
231 // the bubble view, we need to ask ARC for a handler list first. | 225 // the bubble view, we need to ask ARC for a handler list first. |
232 instance->RequestUrlHandlerList( | 226 instance->RequestUrlHandlerList( |
233 url.spec(), | 227 url.spec(), |
234 base::Bind(OnUrlHandlerList, render_process_host_id, routing_id, url)); | 228 base::Bind(OnUrlHandlerList, render_process_host_id, routing_id, url)); |
235 return true; | 229 return true; |
236 } | 230 } |
237 | 231 |
238 } // namespace arc | 232 } // namespace arc |
OLD | NEW |