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

Unified Diff: chrome/browser/resource_coordinator/background_tab_navigation_throttle.cc

Issue 2931023002: [TooManyTabs] Add TabNavigationThrottle (Closed)
Patch Set: review fix Created 3 years, 6 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/resource_coordinator/background_tab_navigation_throttle.cc
diff --git a/chrome/browser/resource_coordinator/background_tab_navigation_throttle.cc b/chrome/browser/resource_coordinator/background_tab_navigation_throttle.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6a1c3c9871b4119cb01a88255cfa9f5650bad046
--- /dev/null
+++ b/chrome/browser/resource_coordinator/background_tab_navigation_throttle.cc
@@ -0,0 +1,77 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
+
+#include "base/feature_list.h"
+#include "base/memory/ptr_util.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/resource_coordinator/tab_manager.h"
+#include "chrome/browser/search/search.h"
+#include "chrome/common/chrome_features.h"
+#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/web_contents.h"
+
+namespace resource_coordinator {
+
+// static
+std::unique_ptr<BackgroundTabNavigationThrottle>
+BackgroundTabNavigationThrottle::MaybeCreateThrottleFor(
+ content::NavigationHandle* navigation_handle) {
+ if (!base::FeatureList::IsEnabled(features::kStaggeredBackgroundTabOpen))
+ return nullptr;
+
+ // Never delay foreground tabs.
+ if (navigation_handle->GetWebContents()->IsVisible())
+ return nullptr;
+
+ // Never delay the tab when there is opener, so the created window can talk
+ // to the creator immediately.
+ if (navigation_handle->GetWebContents()->HasOpener())
+ return nullptr;
+
+ // Only delay the first navigation in a newly created tab.
+ if (!navigation_handle->GetWebContents()
+ ->GetController()
+ .IsInitialNavigation()) {
+ return nullptr;
+ }
+
+ // Only consider throttling common URLs, i.e., HTTP/HTTPS and common
+ // chrome:// UI URLs, for main frames.
chrisha 2017/06/15 21:02:24 I would suggest something even stronger: chrome:/
Zhen Wang 2017/06/19 23:00:12 That sounds good to me. For this CL, it tries to f
+ if (!navigation_handle->IsInMainFrame() ||
+ (!navigation_handle->GetURL().SchemeIsHTTPOrHTTPS() &&
+ !TabManager::IsInternalPage(navigation_handle->GetURL()))) {
+ return nullptr;
+ }
+
+ // Do not delay the NTP, which in some cases has an HTTPS URL.
chrisha 2017/06/15 21:02:24 Why? If an NTP is opened as a background tab it sh
Zhen Wang 2017/06/19 23:00:12 I was copying this part from another navigation th
chrisha 2017/06/20 18:26:54 Take a peek at what session restore does, it might
Zhen Wang 2017/07/06 18:26:12 I added a TODO for this in tab_manager.cc.
+ if (search::IsNTPURL(
+ navigation_handle->GetURL(),
+ Profile::FromBrowserContext(
+ navigation_handle->GetWebContents()->GetBrowserContext()))) {
+ return nullptr;
+ }
+
chrisha 2017/06/15 21:02:24 Where are we detecting if the new tab is in the ba
Zhen Wang 2017/06/19 23:00:12 This is done above after the feature flag check (l
chrisha 2017/06/20 18:26:54 Clearly I'm blind :)
+ return base::MakeUnique<BackgroundTabNavigationThrottle>(navigation_handle);
+}
+
+const char* BackgroundTabNavigationThrottle::GetNameForLogging() {
+ return "BackgroundTabNavigationThrottle";
+}
+
+BackgroundTabNavigationThrottle::BackgroundTabNavigationThrottle(
+ content::NavigationHandle* navigation_handle)
+ : content::NavigationThrottle(navigation_handle) {}
+
+BackgroundTabNavigationThrottle::~BackgroundTabNavigationThrottle() {}
+
+content::NavigationThrottle::ThrottleCheckResult
+BackgroundTabNavigationThrottle::WillStartRequest() {
+ return g_browser_process->GetTabManager()->MaybeThrottleNavigation(
+ navigation_handle());
+}
+
+} // namespace resource_coordinator

Powered by Google App Engine
This is Rietveld 408576698