Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: chrome/browser/chromeos/arc/arc_external_protocol_dialog.cc

Issue 2433733002: Revert "Reusing Ok/Cancel buttons for intent picker" (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 std::string selected_app_package, 73 size_t selected_app_index,
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();
78 // Make sure that the instance at least supports HandleUrl. 77 // Make sure that the instance at least supports HandleUrl.
79 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance( 78 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance(
80 "HandleUrl", kMinVersionForHandleUrl); 79 "HandleUrl", kMinVersionForHandleUrl);
81 if (!instance) { 80 if (!instance || selected_app_index >= handlers.size())
82 close_reason = ArcNavigationThrottle::CloseReason::ERROR; 81 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 }
99 82
100 switch (close_reason) { 83 switch (close_reason) {
101 case ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED: { 84 case ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED: {
102 if (ArcIntentHelperBridge::GetIntentHelperInstance( 85 if (ArcIntentHelperBridge::GetIntentHelperInstance(
103 "AddPreferredPackage", kMinVersionForAddPreferredPackage)) { 86 "AddPreferredPackage", kMinVersionForAddPreferredPackage)) {
104 instance->AddPreferredPackage( 87 instance->AddPreferredPackage(
105 handlers[selected_app_index]->package_name); 88 handlers[selected_app_index]->package_name);
106 } 89 }
107 // fall through. 90 // fall through.
108 } 91 }
(...skipping 28 matching lines...) Expand all
137 120
138 // Called when ARC returned activity icons for the |handlers|. 121 // Called when ARC returned activity icons for the |handlers|.
139 void OnAppIconsReceived( 122 void OnAppIconsReceived(
140 int render_process_host_id, 123 int render_process_host_id,
141 int routing_id, 124 int routing_id,
142 const GURL& url, 125 const GURL& url,
143 mojo::Array<mojom::IntentHandlerInfoPtr> handlers, 126 mojo::Array<mojom::IntentHandlerInfoPtr> handlers,
144 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons) { 127 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons) {
145 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 128 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
146 129
147 using AppInfo = arc::ArcNavigationThrottle::AppInfo; 130 using NameAndIcon = std::pair<std::string, gfx::Image>;
148 std::vector<AppInfo> app_info; 131 std::vector<NameAndIcon> app_info;
149 132
150 for (const auto& handler : handlers) { 133 for (const auto& handler : handlers) {
151 const ActivityIconLoader::ActivityName activity(handler->package_name, 134 const ActivityIconLoader::ActivityName activity(handler->package_name,
152 handler->activity_name); 135 handler->activity_name);
153 const auto it = icons->find(activity); 136 const auto it = icons->find(activity);
154 app_info.emplace_back( 137 app_info.emplace_back(
155 AppInfo(it != icons->end() ? it->second.icon20 : gfx::Image(), 138 handler->name, it != icons->end() ? it->second.icon20 : gfx::Image());
156 handler->package_name, handler->name));
157 } 139 }
158 140
159 auto show_bubble_cb = base::Bind(ShowIntentPickerBubble()); 141 auto show_bubble_cb = base::Bind(ShowIntentPickerBubble());
160 WebContents* web_contents = 142 WebContents* web_contents =
161 tab_util::GetWebContentsByID(render_process_host_id, routing_id); 143 tab_util::GetWebContentsByID(render_process_host_id, routing_id);
162 show_bubble_cb.Run(web_contents, app_info, 144 show_bubble_cb.Run(web_contents, app_info,
163 base::Bind(OnIntentPickerClosed, render_process_host_id, 145 base::Bind(OnIntentPickerClosed, render_process_host_id,
164 routing_id, url, base::Passed(&handlers))); 146 routing_id, url, base::Passed(&handlers)));
165 } 147 }
166 148
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 211
230 // Show ARC version of the dialog, which is IntentPickerBubbleView. To show 212 // 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. 213 // the bubble view, we need to ask ARC for a handler list first.
232 instance->RequestUrlHandlerList( 214 instance->RequestUrlHandlerList(
233 url.spec(), 215 url.spec(),
234 base::Bind(OnUrlHandlerList, render_process_host_id, routing_id, url)); 216 base::Bind(OnUrlHandlerList, render_process_host_id, routing_id, url));
235 return true; 217 return true;
236 } 218 }
237 219
238 } // namespace arc 220 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/browser/chromeos/arc/arc_navigation_throttle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698