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

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

Issue 2357053002: Always use arc::InstanceHolder<T>::GetInstanceForMethod (Closed)
Patch Set: review Created 4 years, 3 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;
37 constexpr uint32_t kMinVersionForAddPreferredPackage = 7;
36 38
37 // Shows the Chrome OS' original external protocol dialog as a fallback. 39 // Shows the Chrome OS' original external protocol dialog as a fallback.
38 void ShowFallbackExternalProtocolDialog(int render_process_host_id, 40 void ShowFallbackExternalProtocolDialog(int render_process_host_id,
39 int routing_id, 41 int routing_id,
40 const GURL& url) { 42 const GURL& url) {
41 WebContents* web_contents = 43 WebContents* web_contents =
42 tab_util::GetWebContentsByID(render_process_host_id, routing_id); 44 tab_util::GetWebContentsByID(render_process_host_id, routing_id);
43 new ExternalProtocolDialog(web_contents, url); 45 new ExternalProtocolDialog(web_contents, url);
44 } 46 }
45 47
46 mojom::IntentHelperInstance* GetIntentHelper() {
47 return ArcIntentHelperBridge::GetIntentHelperInstance(kMinInstanceVersion);
48 }
49
50 scoped_refptr<ActivityIconLoader> GetIconLoader() { 48 scoped_refptr<ActivityIconLoader> GetIconLoader() {
51 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
52 ArcServiceManager* arc_service_manager = ArcServiceManager::Get(); 50 ArcServiceManager* arc_service_manager = ArcServiceManager::Get();
53 return arc_service_manager ? arc_service_manager->icon_loader() : nullptr; 51 return arc_service_manager ? arc_service_manager->icon_loader() : nullptr;
54 } 52 }
55 53
56 // Called when the dialog is closed. 54 // Called when the dialog is closed.
57 void OnIntentPickerClosed(int render_process_host_id, 55 void OnIntentPickerClosed(int render_process_host_id,
58 int routing_id, 56 int routing_id,
59 const GURL& url, 57 const GURL& url,
60 mojo::Array<mojom::UrlHandlerInfoPtr> handlers, 58 mojo::Array<mojom::UrlHandlerInfoPtr> handlers,
61 size_t selected_app_index, 59 size_t selected_app_index,
62 ArcNavigationThrottle::CloseReason close_reason) { 60 ArcNavigationThrottle::CloseReason close_reason) {
63 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 61 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
64 62
65 mojom::IntentHelperInstance* intent_helper = GetIntentHelper(); 63 // Make sure that the instance at least supports HandleUrl.
66 if (!intent_helper || selected_app_index >= handlers.size()) 64 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance(
65 "HandleUrl", kMinVersionForHandleUrl);
66 if (!instance || selected_app_index >= handlers.size())
67 close_reason = ArcNavigationThrottle::CloseReason::ERROR; 67 close_reason = ArcNavigationThrottle::CloseReason::ERROR;
68 68
69 switch (close_reason) { 69 switch (close_reason) {
70 case ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED: { 70 case ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED: {
71 intent_helper->AddPreferredPackage( 71 // Call AddPreferredPackage if it is supported.
72 handlers[selected_app_index]->package_name); 72 if (ArcIntentHelperBridge::GetIntentHelperInstance(
73 "AddPreferredPackage", kMinVersionForAddPreferredPackage)) {
74 instance->AddPreferredPackage(
75 handlers[selected_app_index]->package_name);
76 }
73 // fall through. 77 // fall through.
74 } 78 }
75 case ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED: 79 case ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED:
76 case ArcNavigationThrottle::CloseReason::PREFERRED_ACTIVITY_FOUND: { 80 case ArcNavigationThrottle::CloseReason::PREFERRED_ACTIVITY_FOUND: {
77 // Launch the selected app. 81 // Launch the selected app.
78 intent_helper->HandleUrl(url.spec(), 82 instance->HandleUrl(url.spec(),
79 handlers[selected_app_index]->package_name); 83 handlers[selected_app_index]->package_name);
80 break; 84 break;
81 } 85 }
82 case ArcNavigationThrottle::CloseReason::ERROR: 86 case ArcNavigationThrottle::CloseReason::ERROR:
83 case ArcNavigationThrottle::CloseReason::INVALID: { 87 case ArcNavigationThrottle::CloseReason::INVALID: {
84 LOG(ERROR) << "IntentPickerBubbleView returned unexpected close_reason: " 88 LOG(ERROR) << "IntentPickerBubbleView returned unexpected close_reason: "
85 << static_cast<int>(close_reason); 89 << static_cast<int>(close_reason);
86 // fall through. 90 // fall through.
87 } 91 }
88 case ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED: { 92 case ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED: {
89 // The user didn't select any ARC activity. Show the Chrome OS dialog. 93 // The user didn't select any ARC activity. Show the Chrome OS dialog.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 routing_id, url, base::Passed(&handlers))); 126 routing_id, url, base::Passed(&handlers)));
123 } 127 }
124 128
125 // Called when ARC returned a handler list for the |url|. 129 // Called when ARC returned a handler list for the |url|.
126 void OnUrlHandlerList(int render_process_host_id, 130 void OnUrlHandlerList(int render_process_host_id,
127 int routing_id, 131 int routing_id,
128 const GURL& url, 132 const GURL& url,
129 mojo::Array<mojom::UrlHandlerInfoPtr> handlers) { 133 mojo::Array<mojom::UrlHandlerInfoPtr> handlers) {
130 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 134 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
131 135
132 mojom::IntentHelperInstance* intent_helper = GetIntentHelper(); 136 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance(
137 "HandleUrl", kMinVersionForHandleUrl);
133 scoped_refptr<ActivityIconLoader> icon_loader = GetIconLoader(); 138 scoped_refptr<ActivityIconLoader> icon_loader = GetIconLoader();
134 139
135 if (!intent_helper || !icon_loader || !handlers.size()) { 140 if (!instance || !icon_loader || !handlers.size()) {
136 // No handler is available on ARC side. Show the Chrome OS dialog. 141 // No handler is available on ARC side. Show the Chrome OS dialog.
137 ShowFallbackExternalProtocolDialog(render_process_host_id, routing_id, url); 142 ShowFallbackExternalProtocolDialog(render_process_host_id, routing_id, url);
138 return; 143 return;
139 } 144 }
140 145
141 if (handlers.size() == 1) { 146 if (handlers.size() == 1) {
142 // Special case. When ARC has only one activity for the |url|, silently 147 // Special case. When ARC has only one activity for the |url|, silently
143 // launch the app to be consistent with Android's behavior. No UI needed 148 // launch the app to be consistent with Android's behavior. No UI needed
144 // in this case. 149 // in this case.
145 intent_helper->HandleUrl(url.spec(), handlers[0]->package_name); 150 instance->HandleUrl(url.spec(), handlers[0]->package_name);
146 return; 151 return;
147 } 152 }
148 153
149 // Otherwise, retrieve icons of the activities. 154 // Otherwise, retrieve icons of the activities.
150 std::vector<ActivityIconLoader::ActivityName> activities; 155 std::vector<ActivityIconLoader::ActivityName> activities;
151 for (const auto& handler : handlers) { 156 for (const auto& handler : handlers) {
152 activities.emplace_back(handler->package_name, handler->activity_name); 157 activities.emplace_back(handler->package_name, handler->activity_name);
153 } 158 }
154 icon_loader->GetActivityIcons( 159 icon_loader->GetActivityIcons(
155 activities, base::Bind(OnAppIconsReceived, render_process_host_id, 160 activities, base::Bind(OnAppIconsReceived, render_process_host_id,
156 routing_id, url, base::Passed(&handlers))); 161 routing_id, url, base::Passed(&handlers)));
157 } 162 }
158 163
159 } // namespace 164 } // namespace
160 165
161 bool RunArcExternalProtocolDialog(const GURL& url, 166 bool RunArcExternalProtocolDialog(const GURL& url,
162 int render_process_host_id, 167 int render_process_host_id,
163 int routing_id, 168 int routing_id,
164 ui::PageTransition page_transition, 169 ui::PageTransition page_transition,
165 bool has_user_gesture) { 170 bool has_user_gesture) {
166 if (ShouldIgnoreNavigation(page_transition)) 171 if (ShouldIgnoreNavigation(page_transition))
167 return false; 172 return false;
168 173
169 mojom::IntentHelperInstance* intent_helper = GetIntentHelper(); 174 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance(
170 if (!intent_helper) 175 "RequestUrlHandlerList", kMinVersionForRequestUrlHandlerList);
176 if (!instance)
171 return false; // ARC is either not supported or not yet ready. 177 return false; // ARC is either not supported or not yet ready.
172 178
173 WebContents* web_contents = 179 WebContents* web_contents =
174 tab_util::GetWebContentsByID(render_process_host_id, routing_id); 180 tab_util::GetWebContentsByID(render_process_host_id, routing_id);
175 if (!web_contents || !web_contents->GetBrowserContext() || 181 if (!web_contents || !web_contents->GetBrowserContext() ||
176 web_contents->GetBrowserContext()->IsOffTheRecord()) { 182 web_contents->GetBrowserContext()->IsOffTheRecord()) {
177 return false; 183 return false;
178 } 184 }
179 185
180 // Show ARC version of the dialog, which is IntentPickerBubbleView. To show 186 // Show ARC version of the dialog, which is IntentPickerBubbleView. To show
181 // the bubble view, we need to ask ARC for a handler list first. 187 // the bubble view, we need to ask ARC for a handler list first.
182 intent_helper->RequestUrlHandlerList( 188 instance->RequestUrlHandlerList(
183 url.spec(), 189 url.spec(),
184 base::Bind(OnUrlHandlerList, render_process_host_id, routing_id, url)); 190 base::Bind(OnUrlHandlerList, render_process_host_id, routing_id, url));
185 return true; 191 return true;
186 } 192 }
187 193
188 } // namespace arc 194 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698