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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 tab_util::GetWebContentsByID(render_process_host_id, routing_id); | 63 tab_util::GetWebContentsByID(render_process_host_id, routing_id); |
64 if (web_contents && web_contents->GetController().IsInitialNavigation()) | 64 if (web_contents && web_contents->GetController().IsInitialNavigation()) |
65 web_contents->Close(); | 65 web_contents->Close(); |
66 } | 66 } |
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 size_t selected_app_index, | 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 // Make sure that the instance at least supports HandleUrl. | 78 // Make sure that the instance at least supports HandleUrl. |
78 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance( | 79 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance( |
79 "HandleUrl", kMinVersionForHandleUrl); | 80 "HandleUrl", kMinVersionForHandleUrl); |
80 if (!instance || selected_app_index >= handlers.size()) | 81 if (!instance) { |
81 close_reason = ArcNavigationThrottle::CloseReason::ERROR; | 82 close_reason = ArcNavigationThrottle::CloseReason::ERROR; |
| 83 } else if (close_reason == |
| 84 ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED || |
| 85 close_reason == |
| 86 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()) |
| 97 close_reason = ArcNavigationThrottle::CloseReason::ERROR; |
| 98 } |
82 | 99 |
83 switch (close_reason) { | 100 switch (close_reason) { |
84 case ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED: { | 101 case ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED: { |
85 if (ArcIntentHelperBridge::GetIntentHelperInstance( | 102 if (ArcIntentHelperBridge::GetIntentHelperInstance( |
86 "AddPreferredPackage", kMinVersionForAddPreferredPackage)) { | 103 "AddPreferredPackage", kMinVersionForAddPreferredPackage)) { |
87 instance->AddPreferredPackage( | 104 instance->AddPreferredPackage( |
88 handlers[selected_app_index]->package_name); | 105 handlers[selected_app_index]->package_name); |
89 } | 106 } |
90 // fall through. | 107 // fall through. |
91 } | 108 } |
(...skipping 28 matching lines...) Expand all Loading... |
120 | 137 |
121 // Called when ARC returned activity icons for the |handlers|. | 138 // Called when ARC returned activity icons for the |handlers|. |
122 void OnAppIconsReceived( | 139 void OnAppIconsReceived( |
123 int render_process_host_id, | 140 int render_process_host_id, |
124 int routing_id, | 141 int routing_id, |
125 const GURL& url, | 142 const GURL& url, |
126 mojo::Array<mojom::IntentHandlerInfoPtr> handlers, | 143 mojo::Array<mojom::IntentHandlerInfoPtr> handlers, |
127 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons) { | 144 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons) { |
128 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 145 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
129 | 146 |
130 using NameAndIcon = std::pair<std::string, gfx::Image>; | 147 using AppInfo = arc::ArcNavigationThrottle::AppInfo; |
131 std::vector<NameAndIcon> app_info; | 148 std::vector<AppInfo> app_info; |
132 | 149 |
133 for (const auto& handler : handlers) { | 150 for (const auto& handler : handlers) { |
134 const ActivityIconLoader::ActivityName activity(handler->package_name, | 151 const ActivityIconLoader::ActivityName activity(handler->package_name, |
135 handler->activity_name); | 152 handler->activity_name); |
136 const auto it = icons->find(activity); | 153 const auto it = icons->find(activity); |
137 app_info.emplace_back( | 154 app_info.emplace_back( |
138 handler->name, it != icons->end() ? it->second.icon20 : gfx::Image()); | 155 AppInfo(it != icons->end() ? it->second.icon20 : gfx::Image(), |
| 156 handler->package_name, handler->name)); |
139 } | 157 } |
140 | 158 |
141 auto show_bubble_cb = base::Bind(ShowIntentPickerBubble()); | 159 auto show_bubble_cb = base::Bind(ShowIntentPickerBubble()); |
142 WebContents* web_contents = | 160 WebContents* web_contents = |
143 tab_util::GetWebContentsByID(render_process_host_id, routing_id); | 161 tab_util::GetWebContentsByID(render_process_host_id, routing_id); |
144 show_bubble_cb.Run(web_contents, app_info, | 162 show_bubble_cb.Run(web_contents, app_info, |
145 base::Bind(OnIntentPickerClosed, render_process_host_id, | 163 base::Bind(OnIntentPickerClosed, render_process_host_id, |
146 routing_id, url, base::Passed(&handlers))); | 164 routing_id, url, base::Passed(&handlers))); |
147 } | 165 } |
148 | 166 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 229 |
212 // Show ARC version of the dialog, which is IntentPickerBubbleView. To show | 230 // Show ARC version of the dialog, which is IntentPickerBubbleView. To show |
213 // the bubble view, we need to ask ARC for a handler list first. | 231 // the bubble view, we need to ask ARC for a handler list first. |
214 instance->RequestUrlHandlerList( | 232 instance->RequestUrlHandlerList( |
215 url.spec(), | 233 url.spec(), |
216 base::Bind(OnUrlHandlerList, render_process_host_id, routing_id, url)); | 234 base::Bind(OnUrlHandlerList, render_process_host_id, routing_id, url)); |
217 return true; | 235 return true; |
218 } | 236 } |
219 | 237 |
220 } // namespace arc | 238 } // namespace arc |
OLD | NEW |