Chromium Code Reviews| Index: chrome/browser/chromeos/arc/arc_navigation_throttle.cc |
| diff --git a/chrome/browser/chromeos/arc/arc_navigation_throttle.cc b/chrome/browser/chromeos/arc/arc_navigation_throttle.cc |
| index 0275bb7befbd74bc18a055f23cdf9096e811025e..66f6bee6bb86d10f69aaa95675b4822d08278ec2 100644 |
| --- a/chrome/browser/chromeos/arc/arc_navigation_throttle.cc |
| +++ b/chrome/browser/chromeos/arc/arc_navigation_throttle.cc |
| @@ -13,6 +13,7 @@ |
| #include "components/arc/arc_bridge_service.h" |
| #include "components/arc/arc_service_manager.h" |
| #include "components/arc/intent_helper/arc_intent_helper_bridge.h" |
| +#include "components/arc/intent_helper/local_activity_resolver.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/navigation_handle.h" |
| #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| @@ -57,16 +58,49 @@ ArcNavigationThrottle::ArcNavigationThrottle( |
| const ShowDisambigDialogCallback& show_disambig_dialog_cb) |
| : content::NavigationThrottle(navigation_handle), |
| show_disambig_dialog_callback_(show_disambig_dialog_cb), |
| - weak_ptr_factory_(this) {} |
| + weak_ptr_factory_(this), |
| + previous_user_action_(CloseReason::SIZE) {} |
|
djacobo_
2016/07/28 20:08:01
move before weak_ptr_factory pls.
|
| ArcNavigationThrottle::~ArcNavigationThrottle() = default; |
| content::NavigationThrottle::ThrottleCheckResult |
| ArcNavigationThrottle::WillStartRequest() { |
| + return HandleRequest(); |
| +} |
| + |
| +content::NavigationThrottle::ThrottleCheckResult |
| +ArcNavigationThrottle::WillRedirectRequest() { |
| + switch (previous_user_action_) { |
| + case CloseReason::ERROR: |
| + case CloseReason::DIALOG_DEACTIVATED: |
| + // User dismissed the dialog, or some error occurred before. Don't |
| + // repeatedly pop up the dialog. |
| + return content::NavigationThrottle::PROCEED; |
| + |
| + case CloseReason::ALWAYS_PRESSED: |
| + case CloseReason::JUST_ONCE_PRESSED: |
| + case CloseReason::PREFERRED_ACTIVITY_FOUND: |
| + // Should never get here - if the user selected one of these previously, |
| + // chrome should not see a redirect. |
| + NOTREACHED(); |
| + |
| + case CloseReason::SIZE: |
| + // No disambig has previously been popped up for this - continue. |
| + break; |
| + } |
| + return HandleRequest(); |
| +} |
| + |
| +content::NavigationThrottle::ThrottleCheckResult |
| +ArcNavigationThrottle::HandleRequest() { |
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + const GURL& url = navigation_handle()->GetURL(); |
| + // Mask out any redirect qualifiers - this method handles navigation from |
| + // redirect and non-redirect navigations equivalently. |
| const ui::PageTransition transition = |
| - navigation_handle()->GetPageTransition(); |
| + ui::PageTransitionFromInt(navigation_handle()->GetPageTransition() & |
| + ~ui::PAGE_TRANSITION_IS_REDIRECT_MASK); |
| if (!ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_LINK)) { |
| // If this navigation event wasn't spawned by the user clicking on a link. |
| @@ -75,16 +109,24 @@ ArcNavigationThrottle::WillStartRequest() { |
| if (ui::PageTransitionGetQualifier(transition) != 0) { |
| // Qualifiers indicate that this navigation was the result of a click on a |
| - // forward/back button, or a redirect, or typing in the URL bar, etc. Don't |
| - // pass any of those types of navigations to the intent helper (see |
| - // crbug.com/630072). |
| + // forward/back button, or typing in the URL bar, etc. Don't pass any of |
| + // those types of navigations to the intent helper (see crbug.com/630072). |
| + // Note that redirects, which we do pass on, are masked out above. |
| return content::NavigationThrottle::PROCEED; |
| } |
| if (!ShouldOverrideUrlLoading(navigation_handle())) |
| return content::NavigationThrottle::PROCEED; |
| - const GURL& url = navigation_handle()->GetURL(); |
| + arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); |
| + DCHECK(arc_service_manager); |
| + scoped_refptr<arc::LocalActivityResolver> local_resolver = |
| + arc_service_manager->activity_resolver(); |
| + if (local_resolver->ShouldChromeHandleUrl(url)) { |
| + // If this navigation event doesn't hit an android app. |
| + return content::NavigationThrottle::PROCEED; |
| + } |
| + |
| mojom::IntentHelperInstance* bridge_instance = GetIntentHelper(); |
| if (!bridge_instance) |
| return content::NavigationThrottle::PROCEED; |
| @@ -94,12 +136,6 @@ ArcNavigationThrottle::WillStartRequest() { |
| return content::NavigationThrottle::DEFER; |
| } |
| -content::NavigationThrottle::ThrottleCheckResult |
| -ArcNavigationThrottle::WillRedirectRequest() { |
| - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| - return content::NavigationThrottle::PROCEED; |
| -} |
| - |
| // We received the array of app candidates to handle this URL (even the Chrome |
| // app is included). |
| void ArcNavigationThrottle::OnAppCandidatesReceived( |
| @@ -194,6 +230,8 @@ void ArcNavigationThrottle::OnDisambigDialogClosed( |
| const GURL& url = navigation_handle()->GetURL(); |
| content::NavigationHandle* handle = navigation_handle(); |
| + previous_user_action_ = close_reason; |
| + |
| mojom::IntentHelperInstance* bridge = GetIntentHelper(); |
| if (!bridge || selected_app_index >= handlers.size()) { |
| close_reason = CloseReason::ERROR; |