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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 WebContents* web_contents = | 57 WebContents* web_contents = |
58 tab_util::GetWebContentsByID(render_process_host_id, routing_id); | 58 tab_util::GetWebContentsByID(render_process_host_id, routing_id); |
59 if (web_contents && web_contents->GetController().IsInitialNavigation()) | 59 if (web_contents && web_contents->GetController().IsInitialNavigation()) |
60 web_contents->Close(); | 60 web_contents->Close(); |
61 } | 61 } |
62 | 62 |
63 // Called when the dialog is closed. | 63 // Called when the dialog is closed. |
64 void OnIntentPickerClosed(int render_process_host_id, | 64 void OnIntentPickerClosed(int render_process_host_id, |
65 int routing_id, | 65 int routing_id, |
66 const GURL& url, | 66 const GURL& url, |
67 mojo::Array<mojom::UrlHandlerInfoPtr> handlers, | 67 mojo::Array<mojom::IntentHandlerInfoPtr> handlers, |
68 size_t selected_app_index, | 68 size_t selected_app_index, |
69 ArcNavigationThrottle::CloseReason close_reason) { | 69 ArcNavigationThrottle::CloseReason close_reason) { |
70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
71 | 71 |
72 mojom::IntentHelperInstance* intent_helper = GetIntentHelper(); | 72 mojom::IntentHelperInstance* intent_helper = GetIntentHelper(); |
73 if (!intent_helper || selected_app_index >= handlers.size()) | 73 if (!intent_helper || selected_app_index >= handlers.size()) |
74 close_reason = ArcNavigationThrottle::CloseReason::ERROR; | 74 close_reason = ArcNavigationThrottle::CloseReason::ERROR; |
75 | 75 |
76 switch (close_reason) { | 76 switch (close_reason) { |
77 case ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED: { | 77 case ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED: { |
(...skipping 25 matching lines...) Expand all Loading... |
103 break; | 103 break; |
104 } | 104 } |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 // Called when ARC returned activity icons for the |handlers|. | 108 // Called when ARC returned activity icons for the |handlers|. |
109 void OnAppIconsReceived( | 109 void OnAppIconsReceived( |
110 int render_process_host_id, | 110 int render_process_host_id, |
111 int routing_id, | 111 int routing_id, |
112 const GURL& url, | 112 const GURL& url, |
113 mojo::Array<mojom::UrlHandlerInfoPtr> handlers, | 113 mojo::Array<mojom::IntentHandlerInfoPtr> handlers, |
114 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons) { | 114 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons) { |
115 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 115 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
116 | 116 |
117 using NameAndIcon = std::pair<std::string, gfx::Image>; | 117 using NameAndIcon = std::pair<std::string, gfx::Image>; |
118 std::vector<NameAndIcon> app_info; | 118 std::vector<NameAndIcon> app_info; |
119 | 119 |
120 for (const auto& handler : handlers) { | 120 for (const auto& handler : handlers) { |
121 const ActivityIconLoader::ActivityName activity(handler->package_name, | 121 const ActivityIconLoader::ActivityName activity(handler->package_name, |
122 handler->activity_name); | 122 handler->activity_name); |
123 const auto it = icons->find(activity); | 123 const auto it = icons->find(activity); |
124 app_info.emplace_back( | 124 app_info.emplace_back( |
125 handler->name, it != icons->end() ? it->second.icon20 : gfx::Image()); | 125 handler->name, it != icons->end() ? it->second.icon20 : gfx::Image()); |
126 } | 126 } |
127 | 127 |
128 auto show_bubble_cb = base::Bind(ShowIntentPickerBubble()); | 128 auto show_bubble_cb = base::Bind(ShowIntentPickerBubble()); |
129 WebContents* web_contents = | 129 WebContents* web_contents = |
130 tab_util::GetWebContentsByID(render_process_host_id, routing_id); | 130 tab_util::GetWebContentsByID(render_process_host_id, routing_id); |
131 show_bubble_cb.Run(web_contents, app_info, | 131 show_bubble_cb.Run(web_contents, app_info, |
132 base::Bind(OnIntentPickerClosed, render_process_host_id, | 132 base::Bind(OnIntentPickerClosed, render_process_host_id, |
133 routing_id, url, base::Passed(&handlers))); | 133 routing_id, url, base::Passed(&handlers))); |
134 } | 134 } |
135 | 135 |
136 // Called when ARC returned a handler list for the |url|. | 136 // Called when ARC returned a handler list for the |url|. |
137 void OnUrlHandlerList(int render_process_host_id, | 137 void OnUrlHandlerList(int render_process_host_id, |
138 int routing_id, | 138 int routing_id, |
139 const GURL& url, | 139 const GURL& url, |
140 mojo::Array<mojom::UrlHandlerInfoPtr> handlers) { | 140 mojo::Array<mojom::IntentHandlerInfoPtr> handlers) { |
141 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 141 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
142 | 142 |
143 mojom::IntentHelperInstance* intent_helper = GetIntentHelper(); | 143 mojom::IntentHelperInstance* intent_helper = GetIntentHelper(); |
144 scoped_refptr<ActivityIconLoader> icon_loader = GetIconLoader(); | 144 scoped_refptr<ActivityIconLoader> icon_loader = GetIconLoader(); |
145 | 145 |
146 if (!intent_helper || !icon_loader || !handlers.size()) { | 146 if (!intent_helper || !icon_loader || !handlers.size()) { |
147 // No handler is available on ARC side. Show the Chrome OS dialog. | 147 // No handler is available on ARC side. Show the Chrome OS dialog. |
148 ShowFallbackExternalProtocolDialog(render_process_host_id, routing_id, url); | 148 ShowFallbackExternalProtocolDialog(render_process_host_id, routing_id, url); |
149 return; | 149 return; |
150 } | 150 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 182 |
183 // Show ARC version of the dialog, which is IntentPickerBubbleView. To show | 183 // Show ARC version of the dialog, which is IntentPickerBubbleView. To show |
184 // the bubble view, we need to ask ARC for a handler list first. | 184 // the bubble view, we need to ask ARC for a handler list first. |
185 intent_helper->RequestUrlHandlerList( | 185 intent_helper->RequestUrlHandlerList( |
186 url.spec(), | 186 url.spec(), |
187 base::Bind(OnUrlHandlerList, render_process_host_id, routing_id, url)); | 187 base::Bind(OnUrlHandlerList, render_process_host_id, routing_id, url)); |
188 return true; | 188 return true; |
189 } | 189 } |
190 | 190 |
191 } // namespace arc | 191 } // namespace arc |
OLD | NEW |