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

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

Issue 2931023002: [TooManyTabs] Add TabNavigationThrottle (Closed)
Patch Set: add comments Created 3 years, 5 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..88a87ca5161088e9b9f13ef541f7f88ff14571b3
--- /dev/null
+++ b/chrome/browser/resource_coordinator/background_tab_navigation_throttle.cc
@@ -0,0 +1,65 @@
+// 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;
+
+ // Only consider main frames because this is to delay tabs.
+ if (!navigation_handle->IsInMainFrame())
+ 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;
+ }
+
+ 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