1 // Copyright 2020 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 #ifndef CHROME_RENDERER_CHROME_CONTENT_SETTINGS_AGENT_DELEGATE_H_
6 #define CHROME_RENDERER_CHROME_CONTENT_SETTINGS_AGENT_DELEGATE_H_
8 #include "base/gtest_prod_util.h"
9 #include "base/memory/raw_ptr.h"
10 #include "components/content_settings/renderer/content_settings_agent_impl.h"
11 #include "extensions/buildflags/buildflags.h"
13 #if BUILDFLAG(ENABLE_EXTENSIONS)
14 namespace extensions {
17 } // namespace extensions
20 class ChromeContentSettingsAgentDelegate
21 : public content_settings::ContentSettingsAgentImpl::Delegate,
22 public content::RenderFrameObserver,
23 public content::RenderFrameObserverTracker<
24 ChromeContentSettingsAgentDelegate> {
26 explicit ChromeContentSettingsAgentDelegate(
27 content::RenderFrame* render_frame);
28 ~ChromeContentSettingsAgentDelegate() override;
30 #if BUILDFLAG(ENABLE_EXTENSIONS)
31 // Sets the extension dispatcher. Call this right after constructing this
32 // class. This should only be called once.
33 void SetExtensionDispatcher(extensions::Dispatcher* extension_dispatcher);
36 bool IsPluginTemporarilyAllowed(const std::string& identifier);
37 void AllowPluginTemporarily(const std::string& identifier);
39 // content_settings::ContentSettingsAgentImpl::Delegate:
40 bool IsSchemeAllowlisted(const std::string& scheme) override;
41 absl::optional<bool> AllowReadFromClipboard() override;
42 absl::optional<bool> AllowWriteToClipboard() override;
43 absl::optional<bool> AllowMutationEvents() override;
46 FRIEND_TEST_ALL_PREFIXES(ChromeContentSettingsAgentDelegateBrowserTest,
47 PluginsTemporarilyAllowed);
49 // RenderFrameObserver:
50 void DidCommitProvisionalLoad(ui::PageTransition transition) override;
51 void OnDestruct() override;
53 // Whether the observed RenderFrame is for a platform app.
56 // Whether the observed RenderFrame is an allow-listed System Web App.
57 bool IsAllowListedSystemWebApp();
59 #if BUILDFLAG(ENABLE_EXTENSIONS)
60 // If |origin| corresponds to an installed extension, returns that extension.
61 // Otherwise returns null.
62 const extensions::Extension* GetExtension(
63 const blink::WebSecurityOrigin& origin) const;
65 // Owned by ChromeContentRendererClient and outlive us.
66 raw_ptr<extensions::Dispatcher, ExperimentalRenderer> extension_dispatcher_ =
70 base::flat_set<std::string> temporarily_allowed_plugins_;
72 raw_ptr<content::RenderFrame, ExperimentalRenderer> render_frame_ = nullptr;
75 #endif // CHROME_RENDERER_CHROME_CONTENT_SETTINGS_AGENT_DELEGATE_H_