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

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

Issue 2931023002: [TooManyTabs] Add TabNavigationThrottle (Closed)
Patch Set: 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/tab_navigation_throttle.cc
diff --git a/chrome/browser/resource_coordinator/tab_navigation_throttle.cc b/chrome/browser/resource_coordinator/tab_navigation_throttle.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ed0dd949b8e1bc706a42d8f616c77f243538e06d
--- /dev/null
+++ b/chrome/browser/resource_coordinator/tab_navigation_throttle.cc
@@ -0,0 +1,56 @@
+// 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/tab_navigation_throttle.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 "content/public/browser/navigation_handle.h"
+#include "content/public/browser/web_contents.h"
+
+namespace resource_coordinator {
+
+// static
+std::unique_ptr<TabNavigationThrottle>
+TabNavigationThrottle::MaybeCreateThrottleFor(
+ content::NavigationHandle* navigation_handle) {
+ // Only consider throttling common URLs, i.e., HTTP/HTTPS and common
+ // chrome:// UI URLs, for main frames.
Charlie Reis 2017/06/10 00:53:36 I'm curious, what's the motivation for this? We'v
Zhen Wang 2017/06/13 23:33:21 My actual intention is to exclude all non-tab navi
Zhen Wang 2017/06/19 23:00:12 Ping.
Charlie Reis 2017/07/06 23:50:30 I'm not sure I understand what you mean. chrome-e
+ 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.
+ if (search::IsNTPURL(
+ navigation_handle->GetURL(),
+ Profile::FromBrowserContext(
+ navigation_handle->GetWebContents()->GetBrowserContext()))) {
+ return nullptr;
+ }
+
+ return base::MakeUnique<TabNavigationThrottle>(navigation_handle);
Charlie Reis 2017/06/10 00:53:36 It seems like we're creating this throttle in a lo
Zhen Wang 2017/06/13 23:33:21 Thanks for the pointers! Added restriction on firs
Charlie Reis 2017/07/06 23:50:30 SiteInstanceImpl::active_frame_count() says how ma
Zhen Wang 2017/07/07 18:06:39 active_frame_count is not exposed as a public cont
Charlie Reis 2017/07/07 22:07:55 Ah, I'd forgotten we're not in content here. Neve
+}
+
+const char* TabNavigationThrottle::GetNameForLogging() {
+ return "TabNavigationThrottle";
+}
+
+TabNavigationThrottle::TabNavigationThrottle(
+ content::NavigationHandle* navigation_handle)
+ : content::NavigationThrottle(navigation_handle) {}
+
+TabNavigationThrottle::~TabNavigationThrottle() {}
+
+content::NavigationThrottle::ThrottleCheckResult
+TabNavigationThrottle::WillStartRequest() {
+ return g_browser_process->GetTabManager()->MaybeThrottleNavigation(
+ navigation_handle());
+}
+
+} // namespace resource_coordinator

Powered by Google App Engine
This is Rietveld 408576698