1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/universal_web_contents_observers.h"
7 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
9 #include "extensions/buildflags/buildflags.h"
11 #if BUILDFLAG(ENABLE_EXTENSIONS)
12 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
15 void AttachUniversalWebContentsObservers(content::WebContents* web_contents) {
16 // This function is for attaching *universal* WebContentsObservers - ones that
17 // should be attached to *every* WebContents. Such universal observers and/or
18 // helpers are relatively rare and therefore only a limited set of observers
19 // should be handled below.
21 // In particular, helpers handled by TabHelpers::AttachTabHelpers typically
22 // only apply to tabs, but not to other flavors of WebContents. As pointed
23 // out by //docs/tab_helpers.md there are WebContents that are not tabs
24 // and not every WebContents has (or needs) every tab helper.
26 #if BUILDFLAG(ENABLE_EXTENSIONS)
27 if (extensions::ChromeContentBrowserClientExtensionsPart::
28 AreExtensionsDisabledForProfile(web_contents->GetBrowserContext())) {
32 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(