summaryrefslogtreecommitdiffstats
path: root/chromium/content/browser/plugin_content_origin_allowlist.h
blob: 6bf00a9e7be793856a063a67b05fdda0c09d9bdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2014 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.

#ifndef CONTENT_BROWSER_PLUGIN_CONTENT_ORIGIN_ALLOWLIST_H_
#define CONTENT_BROWSER_PLUGIN_CONTENT_ORIGIN_ALLOWLIST_H_

#include <set>

#include "base/macros.h"
#include "content/common/content_export.h"
#include "content/public/browser/render_document_host_user_data.h"
#include "content/public/browser/web_contents_observer.h"
#include "url/origin.h"

namespace content {

class WebContents;

class CONTENT_EXPORT PluginContentOriginAllowlist : public WebContentsObserver {
  // This class manages the lists of document-tied temporarily allowlisted
  // plugin content origins that are exempt from power saving.
  //
  // RenderFrames report content origins that should be allowlisted via IPC.
  // This class aggregates those origins and broadcasts the total list to all
  // RenderFrames inside the same RenderView. This class also sends these
  // origins to any newly created RenderFrames.
 public:
  explicit PluginContentOriginAllowlist(WebContents* web_contents);
  ~PluginContentOriginAllowlist() override;

 private:
  FRIEND_TEST_ALL_PREFIXES(PluginContentOriginAllowlistTest,
                           ClearAllowlistOnNavigate);
  FRIEND_TEST_ALL_PREFIXES(PluginContentOriginAllowlistTest,
                           SubframeInheritsAllowlist);

  class DocumentPluginContentOriginAllowlist
      : public RenderDocumentHostUserData<
            DocumentPluginContentOriginAllowlist> {
    // This class manages the list of temporarily allowlisted plugin content
    // origins that are exempt from power saving. The list is managed
    // per-document and cleared upon document destruction, as this is part of
    // the RenderDocumentHostUserData.
   public:
    ~DocumentPluginContentOriginAllowlist() override;
    void InsertOrigin(const url::Origin& content_origin);
    std::set<url::Origin> origins() { return origins_; }

   private:
    explicit DocumentPluginContentOriginAllowlist(
        RenderFrameHost* render_frame_host);
    friend class RenderDocumentHostUserData<
        DocumentPluginContentOriginAllowlist>;

    std::set<url::Origin> origins_;

    RENDER_DOCUMENT_HOST_USER_DATA_KEY_DECL();
  };

  static bool IsOriginAllowlistedForFrameForTesting(
      RenderFrameHost* render_frame_host,
      const url::Origin& content_origin);

  // WebContentsObserver implementation.
  void RenderFrameCreated(RenderFrameHost* render_frame_host) override;
  bool OnMessageReceived(const IPC::Message& message,
                         RenderFrameHost* render_frame_host) override;

  void OnPluginContentOriginAllowed(RenderFrameHost* render_frame_host,
                                    const url::Origin& content_origin);

  DISALLOW_COPY_AND_ASSIGN(PluginContentOriginAllowlist);
};

}  // namespace content

#endif  // CONTENT_BROWSER_PLUGIN_CONTENT_ORIGIN_ALLOWLIST_H_