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

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: Address Xiyuan's comment 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..4db4b12a3b23a32ff0badce1e5f90f7602386134 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 {
@@ -34,6 +35,27 @@ scoped_refptr<ActivityIconLoader> GetIconLoader() {
return arc_service_manager ? arc_service_manager->icon_loader() : nullptr;
}
+// Compares the host name of the referrer and target URL to decide whether
+// the navigation needs to be overriden.
+bool ShouldOverrideUrlLoading(const GURL& previous_url,
+ const GURL& current_url) {
+ // When the navigation is initiated in a web page where sending a referrer
+ // is disabled, |previous_url| 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);
+}
+
} // namespace
ArcNavigationThrottle::ArcNavigationThrottle(
@@ -84,7 +106,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,13 +273,11 @@ 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();
- return !net::registry_controlled_domains::SameDomainOrHost(
- current_url, previous_url,
- net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
+// static
+bool ArcNavigationThrottle::ShouldOverrideUrlLoadingForTesting(
+ const GURL& previous_url,
+ const GURL& current_url) {
+ return ShouldOverrideUrlLoading(previous_url, current_url);
}
} // namespace arc
« no previous file with comments | « chrome/browser/chromeos/arc/arc_navigation_throttle.h ('k') | chrome/browser/chromeos/arc/arc_navigation_throttle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698