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

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

Issue 2357053002: Always use arc::InstanceHolder<T>::GetInstanceForMethod (Closed)
Patch Set: rebase, no code change 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 14 matching lines...) Expand all
25 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
26 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
27 #include "url/gurl.h" 27 #include "url/gurl.h"
28 28
29 using content::WebContents; 29 using content::WebContents;
30 30
31 namespace arc { 31 namespace arc {
32 32
33 namespace { 33 namespace {
34 34
35 constexpr uint32_t kMinInstanceVersion = 3; // RequestActivityIcons' MinVersion 35 constexpr uint32_t kMinVersionForHandleUrl = 2;
36 constexpr uint32_t kMinVersionForRequestUrlHandlerList = 2;
36 37
37 // Shows the Chrome OS' original external protocol dialog as a fallback. 38 // Shows the Chrome OS' original external protocol dialog as a fallback.
38 void ShowFallbackExternalProtocolDialog(int render_process_host_id, 39 void ShowFallbackExternalProtocolDialog(int render_process_host_id,
39 int routing_id, 40 int routing_id,
40 const GURL& url) { 41 const GURL& url) {
41 WebContents* web_contents = 42 WebContents* web_contents =
42 tab_util::GetWebContentsByID(render_process_host_id, routing_id); 43 tab_util::GetWebContentsByID(render_process_host_id, routing_id);
43 new ExternalProtocolDialog(web_contents, url); 44 new ExternalProtocolDialog(web_contents, url);
44 } 45 }
45 46
46 mojom::IntentHelperInstance* GetIntentHelper() {
47 return ArcIntentHelperBridge::GetIntentHelperInstance(kMinInstanceVersion);
48 }
49
50 scoped_refptr<ActivityIconLoader> GetIconLoader() { 47 scoped_refptr<ActivityIconLoader> GetIconLoader() {
51 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
52 ArcServiceManager* arc_service_manager = ArcServiceManager::Get(); 49 ArcServiceManager* arc_service_manager = ArcServiceManager::Get();
53 return arc_service_manager ? arc_service_manager->icon_loader() : nullptr; 50 return arc_service_manager ? arc_service_manager->icon_loader() : nullptr;
54 } 51 }
55 52
56 void CloseTabIfNeeded(int render_process_host_id, int routing_id) { 53 void CloseTabIfNeeded(int render_process_host_id, int routing_id) {
57 WebContents* web_contents = 54 WebContents* web_contents =
58 tab_util::GetWebContentsByID(render_process_host_id, routing_id); 55 tab_util::GetWebContentsByID(render_process_host_id, routing_id);
59 if (web_contents && web_contents->GetController().IsInitialNavigation()) 56 if (web_contents && web_contents->GetController().IsInitialNavigation())
60 web_contents->Close(); 57 web_contents->Close();
61 } 58 }
62 59
63 // Called when the dialog is closed. 60 // Called when the dialog is closed.
64 void OnIntentPickerClosed(int render_process_host_id, 61 void OnIntentPickerClosed(int render_process_host_id,
65 int routing_id, 62 int routing_id,
66 const GURL& url, 63 const GURL& url,
67 mojo::Array<mojom::IntentHandlerInfoPtr> handlers, 64 mojo::Array<mojom::IntentHandlerInfoPtr> handlers,
68 size_t selected_app_index, 65 size_t selected_app_index,
69 ArcNavigationThrottle::CloseReason close_reason) { 66 ArcNavigationThrottle::CloseReason close_reason) {
70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
71 68
72 mojom::IntentHelperInstance* intent_helper = GetIntentHelper(); 69 // Make sure that the instance at least supports HandleUrl.
73 if (!intent_helper || selected_app_index >= handlers.size()) 70 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance(
71 "HandleUrl", kMinVersionForHandleUrl);
72 if (!instance || selected_app_index >= handlers.size())
74 close_reason = ArcNavigationThrottle::CloseReason::ERROR; 73 close_reason = ArcNavigationThrottle::CloseReason::ERROR;
75 74
76 switch (close_reason) { 75 switch (close_reason) {
77 case ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED: { 76 case ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED: {
78 // TODO(yusukes): Add NOTREACHED(); break; here once b/31665510 is fixed. 77 // TODO(yusukes): Add NOTREACHED(); break; here once b/31665510 is fixed.
79 // fall through, for now. 78 // fall through, for now.
80 } 79 }
81 case ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED: { 80 case ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED: {
82 // Launch the selected app. 81 // Launch the selected app.
83 intent_helper->HandleUrl(url.spec(), 82 instance->HandleUrl(url.spec(),
84 handlers[selected_app_index]->package_name); 83 handlers[selected_app_index]->package_name);
85 CloseTabIfNeeded(render_process_host_id, routing_id); 84 CloseTabIfNeeded(render_process_host_id, routing_id);
86 break; 85 break;
87 } 86 }
88 case ArcNavigationThrottle::CloseReason::PREFERRED_ACTIVITY_FOUND: { 87 case ArcNavigationThrottle::CloseReason::PREFERRED_ACTIVITY_FOUND: {
89 // Our OnUrlHandlerList callback does not search for a preferred activity. 88 // Our OnUrlHandlerList callback does not search for a preferred activity.
90 NOTREACHED(); 89 NOTREACHED();
91 break; 90 break;
92 } 91 }
93 case ArcNavigationThrottle::CloseReason::ERROR: 92 case ArcNavigationThrottle::CloseReason::ERROR:
94 case ArcNavigationThrottle::CloseReason::INVALID: { 93 case ArcNavigationThrottle::CloseReason::INVALID: {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 routing_id, url, base::Passed(&handlers))); 132 routing_id, url, base::Passed(&handlers)));
134 } 133 }
135 134
136 // Called when ARC returned a handler list for the |url|. 135 // Called when ARC returned a handler list for the |url|.
137 void OnUrlHandlerList(int render_process_host_id, 136 void OnUrlHandlerList(int render_process_host_id,
138 int routing_id, 137 int routing_id,
139 const GURL& url, 138 const GURL& url,
140 mojo::Array<mojom::IntentHandlerInfoPtr> handlers) { 139 mojo::Array<mojom::IntentHandlerInfoPtr> handlers) {
141 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 140 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
142 141
143 mojom::IntentHelperInstance* intent_helper = GetIntentHelper(); 142 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance(
143 "HandleUrl", kMinVersionForHandleUrl);
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 (!instance || !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 }
151 151
152 // Otherwise, retrieve icons of the activities. 152 // Otherwise, retrieve icons of the activities.
153 std::vector<ActivityIconLoader::ActivityName> activities; 153 std::vector<ActivityIconLoader::ActivityName> activities;
154 for (const auto& handler : handlers) { 154 for (const auto& handler : handlers) {
155 activities.emplace_back(handler->package_name, handler->activity_name); 155 activities.emplace_back(handler->package_name, handler->activity_name);
156 } 156 }
157 icon_loader->GetActivityIcons( 157 icon_loader->GetActivityIcons(
158 activities, base::Bind(OnAppIconsReceived, render_process_host_id, 158 activities, base::Bind(OnAppIconsReceived, render_process_host_id,
159 routing_id, url, base::Passed(&handlers))); 159 routing_id, url, base::Passed(&handlers)));
160 } 160 }
161 161
162 } // namespace 162 } // namespace
163 163
164 bool RunArcExternalProtocolDialog(const GURL& url, 164 bool RunArcExternalProtocolDialog(const GURL& url,
165 int render_process_host_id, 165 int render_process_host_id,
166 int routing_id, 166 int routing_id,
167 ui::PageTransition page_transition, 167 ui::PageTransition page_transition,
168 bool has_user_gesture) { 168 bool has_user_gesture) {
169 if (ShouldIgnoreNavigation(page_transition)) 169 if (ShouldIgnoreNavigation(page_transition))
170 return false; 170 return false;
171 171
172 mojom::IntentHelperInstance* intent_helper = GetIntentHelper(); 172 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance(
173 if (!intent_helper) 173 "RequestUrlHandlerList", kMinVersionForRequestUrlHandlerList);
174 if (!instance)
174 return false; // ARC is either not supported or not yet ready. 175 return false; // ARC is either not supported or not yet ready.
175 176
176 WebContents* web_contents = 177 WebContents* web_contents =
177 tab_util::GetWebContentsByID(render_process_host_id, routing_id); 178 tab_util::GetWebContentsByID(render_process_host_id, routing_id);
178 if (!web_contents || !web_contents->GetBrowserContext() || 179 if (!web_contents || !web_contents->GetBrowserContext() ||
179 web_contents->GetBrowserContext()->IsOffTheRecord()) { 180 web_contents->GetBrowserContext()->IsOffTheRecord()) {
180 return false; 181 return false;
181 } 182 }
182 183
183 // Show ARC version of the dialog, which is IntentPickerBubbleView. To show 184 // 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. 185 // the bubble view, we need to ask ARC for a handler list first.
185 intent_helper->RequestUrlHandlerList( 186 instance->RequestUrlHandlerList(
186 url.spec(), 187 url.spec(),
187 base::Bind(OnUrlHandlerList, render_process_host_id, routing_id, url)); 188 base::Bind(OnUrlHandlerList, render_process_host_id, routing_id, url));
188 return true; 189 return true;
189 } 190 }
190 191
191 } // namespace arc 192 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698