summaryrefslogtreecommitdiffstats
path: root/chromium/content/browser/plugin_content_origin_allowlist.cc
blob: 97a4f6e9c0954f8730840a0fec486e8f1fc1d5e5 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// 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.

#include "content/browser/plugin_content_origin_allowlist.h"

#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/common/frame_messages.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"

namespace content {

PluginContentOriginAllowlist::DocumentPluginContentOriginAllowlist::
    ~DocumentPluginContentOriginAllowlist() {}

PluginContentOriginAllowlist::DocumentPluginContentOriginAllowlist::
    DocumentPluginContentOriginAllowlist(RenderFrameHost* render_frame_host) {}

void PluginContentOriginAllowlist::DocumentPluginContentOriginAllowlist::
    InsertOrigin(const url::Origin& content_origin) {
  origins_.insert(content_origin);
}

RENDER_DOCUMENT_HOST_USER_DATA_KEY_IMPL(
    PluginContentOriginAllowlist::DocumentPluginContentOriginAllowlist)

PluginContentOriginAllowlist::PluginContentOriginAllowlist(
    WebContents* web_contents)
    : WebContentsObserver(web_contents) {}

PluginContentOriginAllowlist::~PluginContentOriginAllowlist() {}

void PluginContentOriginAllowlist::RenderFrameCreated(
    RenderFrameHost* render_frame_host) {
  // When RenderFrame is created inside the main frame,
  DocumentPluginContentOriginAllowlist* allowlist =
      DocumentPluginContentOriginAllowlist::GetForCurrentDocument(
          render_frame_host->GetMainFrame());
  if (!allowlist || allowlist->origins().empty())
    return;
  render_frame_host->Send(new FrameMsg_UpdatePluginContentOriginAllowlist(
      render_frame_host->GetRoutingID(), allowlist->origins()));
}

bool PluginContentOriginAllowlist::OnMessageReceived(
    const IPC::Message& message,
    RenderFrameHost* render_frame_host) {
  bool handled = true;
  IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(PluginContentOriginAllowlist, message,
                                   render_frame_host)
    IPC_MESSAGE_HANDLER(FrameHostMsg_PluginContentOriginAllowed,
                        OnPluginContentOriginAllowed)
    IPC_MESSAGE_UNHANDLED(handled = false)
  IPC_END_MESSAGE_MAP()

  return handled;
}

void PluginContentOriginAllowlist::OnPluginContentOriginAllowed(
    RenderFrameHost* render_frame_host,
    const url::Origin& content_origin) {
  DocumentPluginContentOriginAllowlist* allowlist =
      DocumentPluginContentOriginAllowlist::GetOrCreateForCurrentDocument(
          render_frame_host->GetMainFrame());
  allowlist->InsertOrigin(content_origin);

  // TODO(yuzus, crbug.com/1061899): This message should be sent to all the
  // frames in the same frame tree as |render_frame_host|. When mojofying this
  // IPC, this should use PageBroadcast interface and look up the correct set of
  // RenderViewHosts from |render_frame_host| instead of getting them from
  // |web_contents()|.
  web_contents()->SendToAllFrames(
      new FrameMsg_UpdatePluginContentOriginAllowlist(MSG_ROUTING_NONE,
                                                      allowlist->origins()));
}

bool PluginContentOriginAllowlist::IsOriginAllowlistedForFrameForTesting(
    RenderFrameHost* render_frame_host,
    const url::Origin& content_origin) {
  DocumentPluginContentOriginAllowlist* allowlist =
      DocumentPluginContentOriginAllowlist::GetForCurrentDocument(
          render_frame_host->GetMainFrame());
  PluginContentOriginAllowlist::DocumentPluginContentOriginAllowlist::
      GetForCurrentDocument(render_frame_host->GetMainFrame());
  if (!allowlist)
    return false;
  return allowlist->origins().find(content_origin) !=
         allowlist->origins().end();
}

}  // namespace content