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_navigation_throttle.h" | 5 #include "chrome/browser/chromeos/arc/arc_navigation_throttle.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/metrics/histogram_macros.h" |
10 #include "components/arc/arc_bridge_service.h" | 11 #include "components/arc/arc_bridge_service.h" |
11 #include "components/arc/arc_service_manager.h" | 12 #include "components/arc/arc_service_manager.h" |
12 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" | 13 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/browser/navigation_handle.h" | 15 #include "content/public/browser/navigation_handle.h" |
15 | 16 |
16 namespace arc { | 17 namespace arc { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 continue; | 104 continue; |
104 if (ArcIntentHelperBridge::IsIntentHelperPackage( | 105 if (ArcIntentHelperBridge::IsIntentHelperPackage( |
105 handlers[i]->package_name)) { | 106 handlers[i]->package_name)) { |
106 // If Chrome browser was selected as the preferred app, we should't | 107 // If Chrome browser was selected as the preferred app, we should't |
107 // create a throttle. | 108 // create a throttle. |
108 DVLOG(1) | 109 DVLOG(1) |
109 << "Chrome browser is selected as the preferred app for this URL: " | 110 << "Chrome browser is selected as the preferred app for this URL: " |
110 << navigation_handle()->GetURL().spec(); | 111 << navigation_handle()->GetURL().spec(); |
111 } | 112 } |
112 OnDisambigDialogClosed(std::move(handlers), i, | 113 OnDisambigDialogClosed(std::move(handlers), i, |
113 CloseReason::REASON_PREFERRED_ACTIVITY_FOUND); | 114 CloseReason::PREFERRED_ACTIVITY_FOUND); |
114 return; | 115 return; |
115 } | 116 } |
116 | 117 |
117 scoped_refptr<ActivityIconLoader> icon_loader = GetIconLoader(); | 118 scoped_refptr<ActivityIconLoader> icon_loader = GetIconLoader(); |
118 if (!icon_loader) { | 119 if (!icon_loader) { |
119 LOG(ERROR) << "Cannot get an instance of ActivityIconLoader"; | 120 LOG(ERROR) << "Cannot get an instance of ActivityIconLoader"; |
120 navigation_handle()->Resume(); | 121 navigation_handle()->Resume(); |
121 return; | 122 return; |
122 } | 123 } |
123 std::vector<ActivityIconLoader::ActivityName> activities; | 124 std::vector<ActivityIconLoader::ActivityName> activities; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 157 } |
157 | 158 |
158 void ArcNavigationThrottle::OnDisambigDialogClosed( | 159 void ArcNavigationThrottle::OnDisambigDialogClosed( |
159 mojo::Array<mojom::UrlHandlerInfoPtr> handlers, | 160 mojo::Array<mojom::UrlHandlerInfoPtr> handlers, |
160 size_t selected_app_index, | 161 size_t selected_app_index, |
161 CloseReason close_reason) { | 162 CloseReason close_reason) { |
162 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 163 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
163 const GURL& url = navigation_handle()->GetURL(); | 164 const GURL& url = navigation_handle()->GetURL(); |
164 content::NavigationHandle* handle = navigation_handle(); | 165 content::NavigationHandle* handle = navigation_handle(); |
165 | 166 |
166 // TODO(djacobo): Record UMA | 167 mojom::IntentHelperInstance* bridge = GetIntentHelper(); |
167 // If the user fails to select an option from the list, or the UI returned an | 168 if (!bridge || selected_app_index >= handlers.size()) { |
168 // error or if |selected_app_index| is not a valid index, then resume the | 169 close_reason = CloseReason::ERROR; |
169 // navigation in Chrome. Otherwise store the preferred app (if any) and start | |
170 // the selected app, either Chrome Browser or ARC app. | |
171 if (close_reason == CloseReason::REASON_DIALOG_DEACTIVATED || | |
172 close_reason == CloseReason::REASON_ERROR || | |
173 selected_app_index >= handlers.size()) { | |
174 DVLOG(1) << "User didn't select a valid option, resuming navigation."; | |
175 handle->Resume(); | |
176 return; | |
177 } | 170 } |
178 mojom::IntentHelperInstance* bridge = GetIntentHelper(); | 171 |
179 if (!bridge) { | 172 switch (close_reason) { |
180 handle->Resume(); | 173 case CloseReason::ERROR: |
181 return; | 174 case CloseReason::DIALOG_DEACTIVATED: { |
| 175 // If the user fails to select an option from the list, or the UI returned |
| 176 // an error or if |selected_app_index| is not a valid index, then resume |
| 177 // the navigation in Chrome. |
| 178 DVLOG(1) << "User didn't select a valid option, resuming navigation."; |
| 179 handle->Resume(); |
| 180 break; |
| 181 } |
| 182 case CloseReason::ALWAYS_PRESSED: { |
| 183 bridge->AddPreferredPackage(handlers[selected_app_index]->package_name); |
| 184 // fall through. |
| 185 } |
| 186 case CloseReason::JUST_ONCE_PRESSED: |
| 187 case CloseReason::PREFERRED_ACTIVITY_FOUND: { |
| 188 if (ArcIntentHelperBridge::IsIntentHelperPackage( |
| 189 handlers[selected_app_index]->package_name)) { |
| 190 handle->Resume(); |
| 191 } else { |
| 192 bridge->HandleUrl(url.spec(), |
| 193 handlers[selected_app_index]->package_name); |
| 194 handle->CancelDeferredNavigation( |
| 195 content::NavigationThrottle::CANCEL_AND_IGNORE); |
| 196 } |
| 197 break; |
| 198 } |
| 199 case CloseReason::SIZE: { |
| 200 NOTREACHED(); |
| 201 return; |
| 202 } |
182 } | 203 } |
183 if (close_reason == CloseReason::REASON_ALWAYS_PRESSED) { | 204 |
184 bridge->AddPreferredPackage(handlers[selected_app_index]->package_name); | 205 UMA_HISTOGRAM_ENUMERATION("Arc.IntentHandlerAction", |
185 } | 206 static_cast<int>(close_reason), |
186 if (ArcIntentHelperBridge::IsIntentHelperPackage( | 207 static_cast<int>(CloseReason::SIZE)); |
187 handlers[selected_app_index]->package_name)) { | |
188 handle->Resume(); | |
189 return; | |
190 } | |
191 bridge->HandleUrl(url.spec(), handlers[selected_app_index]->package_name); | |
192 handle->CancelDeferredNavigation( | |
193 content::NavigationThrottle::CANCEL_AND_IGNORE); | |
194 } | 208 } |
195 | 209 |
196 } // namespace arc | 210 } // namespace arc |
OLD | NEW |