| 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 136 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::REASON_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::REASON_ALWAYS_PRESSED: { |
| 181 return; | 174 bridge->AddPreferredPackage(handlers[selected_app_index]->package_name); |
| 175 // fall through. |
| 176 } |
| 177 case CloseReason::REASON_JUST_ONCE_PRESSED: |
| 178 case CloseReason::REASON_PREFERRED_ACTIVITY_FOUND: { |
| 179 if (ArcIntentHelperBridge::IsIntentHelperPackage( |
| 180 handlers[selected_app_index]->package_name)) { |
| 181 handle->Resume(); |
| 182 } else { |
| 183 bridge->HandleUrl(url.spec(), |
| 184 handlers[selected_app_index]->package_name); |
| 185 handle->CancelDeferredNavigation( |
| 186 content::NavigationThrottle::CANCEL_AND_IGNORE); |
| 187 } |
| 188 break; |
| 189 } |
| 190 case CloseReason::REASON_DIALOG_DEACTIVATED: |
| 191 case CloseReason::REASON_ERROR: { |
| 192 // If the user fails to select an option from the list, or the UI returned |
| 193 // an error or if |selected_app_index| is not a valid index, then resume |
| 194 // the navigation in Chrome. |
| 195 DVLOG(1) << "User didn't select a valid option, resuming navigation."; |
| 196 handle->Resume(); |
| 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 |