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

Unified Diff: chrome/browser/chromeos/arc/arc_navigation_throttle.cc

Issue 2277533002: Open |current_url| in Chrome when |previous_url| is empty (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add unittest 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 side-by-side diff with in-line comments
Download patch
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 317c2d68aad03829c43a5596302cce9d87d97037..883151731da41dbaee8be230f62e0f019f8b9791 100644
--- a/chrome/browser/chromeos/arc/arc_navigation_throttle.cc
+++ b/chrome/browser/chromeos/arc/arc_navigation_throttle.cc
@@ -21,6 +21,7 @@
#include "content/public/browser/web_contents.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "ui/base/page_transition_types.h"
+#include "url/gurl.h"
namespace arc {
@@ -84,7 +85,9 @@ ArcNavigationThrottle::HandleRequest() {
if (ShouldIgnoreNavigation(navigation_handle()->GetPageTransition()))
return content::NavigationThrottle::PROCEED;
- if (!ShouldOverrideUrlLoading(navigation_handle()))
+ const GURL previous_url = navigation_handle()->GetReferrer().url;
+ const GURL current_url = navigation_handle()->GetURL();
+ if (!ShouldOverrideUrlLoading(previous_url, current_url))
return content::NavigationThrottle::PROCEED;
arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get();
@@ -249,10 +252,27 @@ void ArcNavigationThrottle::OnIntentPickerClosed(
static_cast<int>(CloseReason::SIZE));
}
-bool ArcNavigationThrottle::ShouldOverrideUrlLoading(
- content::NavigationHandle* navigation_handle) {
- GURL previous_url = navigation_handle->GetReferrer().url;
- GURL current_url = navigation_handle->GetURL();
+// static
+bool ArcNavigationThrottle::ShouldOverrideUrlLoadingForTesting(
+ const GURL& previous_url,
+ const GURL& current_url) {
+ return ShouldOverrideUrlLoading(previous_url, current_url);
+}
+
+// static
+bool ArcNavigationThrottle::ShouldOverrideUrlLoading(const GURL& previous_url,
+ const GURL& current_url) {
+ // When the navigation is initiated via e.g. JavaScript code, the referrer
+ // can be empty. In this case, we should open it in the desktop browser.
+ if (!previous_url.is_valid() || previous_url.is_empty())
+ return false;
+
+ // Also check |current_url| just in case.
+ if (!current_url.is_valid() || current_url.is_empty()) {
+ DVLOG(1) << "Unexpected URL: " << current_url << ", opening it in Chrome.";
+ return false;
+ }
+
return !net::registry_controlled_domains::SameDomainOrHost(
current_url, previous_url,
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);

Powered by Google App Engine
This is Rietveld 408576698