Chromium Code Reviews| 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..0dd405d89181f453957a0f5014aa2f260ac98e59 |
| --- /dev/null |
| +++ b/chrome/browser/resource_coordinator/background_tab_navigation_throttle.cc |
| @@ -0,0 +1,72 @@ |
| +// 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; |
| + } |
| + |
| + // Only consider delaying common URLs, i.e., HTTP/HTTPS and common |
| + // chrome:// UI URLs. |
| + if (!navigation_handle->GetURL().SchemeIsHTTPOrHTTPS() && |
| + !TabManager::IsInternalPage(navigation_handle->GetURL())) { |
|
Charlie Reis
2017/07/06 23:50:30
As noted earlier, I don't understand why we need t
Zhen Wang
2017/07/07 18:06:39
Maybe we do not need any URL check here. I was jus
Charlie Reis
2017/07/07 22:07:56
Acknowledged.
|
| + 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 |