| 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/intent_helper/arc_external_protocol_dialog
.h" | 5 #include "chrome/browser/chromeos/arc/intent_helper/arc_external_protocol_dialog
.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 // Otherwise, retrieve icons of the activities. | 332 // Otherwise, retrieve icons of the activities. |
| 333 std::vector<ActivityIconLoader::ActivityName> activities; | 333 std::vector<ActivityIconLoader::ActivityName> activities; |
| 334 for (const auto& handler : handlers) { | 334 for (const auto& handler : handlers) { |
| 335 activities.emplace_back(handler->package_name, handler->activity_name); | 335 activities.emplace_back(handler->package_name, handler->activity_name); |
| 336 } | 336 } |
| 337 icon_loader->GetActivityIcons( | 337 icon_loader->GetActivityIcons( |
| 338 activities, base::Bind(OnAppIconsReceived, render_process_host_id, | 338 activities, base::Bind(OnAppIconsReceived, render_process_host_id, |
| 339 routing_id, url, base::Passed(&handlers))); | 339 routing_id, url, base::Passed(&handlers))); |
| 340 } | 340 } |
| 341 | 341 |
| 342 // Returns true if ARC should ignore the navigation with the |page_transition|. |
| 343 bool ShouldIgnoreNavigation(ui::PageTransition page_transition) { |
| 344 // Handle client-side redirections. Forwarding such navigations to ARC is |
| 345 // better than just showing the "can't open" dialog. |
| 346 // TODO(djacobo): Check if doing this in arc::ShouldIgnoreNavigation is safe, |
| 347 // and move it to the function if it is. (b/32442730#comment3) |
| 348 page_transition = ui::PageTransitionFromInt( |
| 349 page_transition & ~ui::PAGE_TRANSITION_CLIENT_REDIRECT); |
| 350 |
| 351 // Try to forward <form> submissions to ARC when possible. |
| 352 constexpr bool kAllowFormSubmit = true; |
| 353 return arc::ShouldIgnoreNavigation(page_transition, kAllowFormSubmit); |
| 354 } |
| 355 |
| 342 } // namespace | 356 } // namespace |
| 343 | 357 |
| 344 bool RunArcExternalProtocolDialog(const GURL& url, | 358 bool RunArcExternalProtocolDialog(const GURL& url, |
| 345 int render_process_host_id, | 359 int render_process_host_id, |
| 346 int routing_id, | 360 int routing_id, |
| 347 ui::PageTransition page_transition, | 361 ui::PageTransition page_transition, |
| 348 bool has_user_gesture) { | 362 bool has_user_gesture) { |
| 349 // This function is for external protocols that Chrome cannot handle. | 363 // This function is for external protocols that Chrome cannot handle. |
| 350 DCHECK(!url.SchemeIsHTTPOrHTTPS()) << url; | 364 DCHECK(!url.SchemeIsHTTPOrHTTPS()) << url; |
| 351 | 365 |
| 352 // Handle client-side redirections. Forwarding such navigations to ARC is | 366 if (ShouldIgnoreNavigation(page_transition)) |
| 353 // better than just showing the "can't open" dialog. | |
| 354 // TODO(djacobo): Check if doing this in arc::ShouldIgnoreNavigation is safe, | |
| 355 // and move it to the function if it is. (b/32442730#comment3) | |
| 356 page_transition = ui::PageTransitionFromInt( | |
| 357 page_transition & ~ui::PAGE_TRANSITION_CLIENT_REDIRECT); | |
| 358 | |
| 359 // Try to forward <form> submissions to ARC when possible. | |
| 360 constexpr bool kAllowFormSubmit = true; | |
| 361 if (ShouldIgnoreNavigation(page_transition, kAllowFormSubmit)) | |
| 362 return false; | 367 return false; |
| 363 | 368 |
| 364 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance( | 369 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance( |
| 365 "RequestUrlHandlerList", kMinVersionForRequestUrlHandlerList); | 370 "RequestUrlHandlerList", kMinVersionForRequestUrlHandlerList); |
| 366 if (!instance) | 371 if (!instance) |
| 367 return false; // ARC is either not supported or not yet ready. | 372 return false; // ARC is either not supported or not yet ready. |
| 368 | 373 |
| 369 WebContents* web_contents = | 374 WebContents* web_contents = |
| 370 tab_util::GetWebContentsByID(render_process_host_id, routing_id); | 375 tab_util::GetWebContentsByID(render_process_host_id, routing_id); |
| 371 if (!web_contents || !web_contents->GetBrowserContext() || | 376 if (!web_contents || !web_contents->GetBrowserContext() || |
| 372 web_contents->GetBrowserContext()->IsOffTheRecord()) { | 377 web_contents->GetBrowserContext()->IsOffTheRecord()) { |
| 373 return false; | 378 return false; |
| 374 } | 379 } |
| 375 | 380 |
| 376 // Show ARC version of the dialog, which is IntentPickerBubbleView. To show | 381 // Show ARC version of the dialog, which is IntentPickerBubbleView. To show |
| 377 // the bubble view, we need to ask ARC for a handler list first. | 382 // the bubble view, we need to ask ARC for a handler list first. |
| 378 instance->RequestUrlHandlerList( | 383 instance->RequestUrlHandlerList( |
| 379 url.spec(), | 384 url.spec(), |
| 380 base::Bind(OnUrlHandlerList, render_process_host_id, routing_id, url)); | 385 base::Bind(OnUrlHandlerList, render_process_host_id, routing_id, url)); |
| 381 return true; | 386 return true; |
| 382 } | 387 } |
| 383 | 388 |
| 389 bool ShouldIgnoreNavigationForTesting(ui::PageTransition page_transition) { |
| 390 return ShouldIgnoreNavigation(page_transition); |
| 391 } |
| 392 |
| 384 GetActionResult GetActionForTesting( | 393 GetActionResult GetActionForTesting( |
| 385 const GURL& original_url, | 394 const GURL& original_url, |
| 386 const mojo::Array<mojom::IntentHandlerInfoPtr>& handlers, | 395 const mojo::Array<mojom::IntentHandlerInfoPtr>& handlers, |
| 387 size_t selected_app_index, | 396 size_t selected_app_index, |
| 388 std::pair<GURL, std::string>* out_url_and_package) { | 397 std::pair<GURL, std::string>* out_url_and_package) { |
| 389 return GetAction(original_url, handlers, selected_app_index, | 398 return GetAction(original_url, handlers, selected_app_index, |
| 390 out_url_and_package); | 399 out_url_and_package); |
| 391 } | 400 } |
| 392 | 401 |
| 393 } // namespace arc | 402 } // namespace arc |
| OLD | NEW |