summaryrefslogtreecommitdiffstats
path: root/content/browser/plugin_content_origin_whitelist.cc
blob: d10e703f1170a58f0c566dd261246e5b64f208c3 (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
// 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_whitelist.h"

#include "content/common/frame_messages.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"

namespace content {

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

PluginContentOriginWhitelist::~PluginContentOriginWhitelist() {
}

void PluginContentOriginWhitelist::RenderFrameCreated(
    RenderFrameHost* render_frame_host) {
  if (!whitelist_.empty()) {
    Send(new FrameMsg_UpdatePluginContentOriginWhitelist(
        render_frame_host->GetRoutingID(), whitelist_));
  }
}

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

  return handled;
}

void PluginContentOriginWhitelist::DidNavigateMainFrame(
    const LoadCommittedDetails& details,
    const FrameNavigateParams& params) {
  if (details.is_navigation_to_different_page()) {
    // We expect RenderFrames to clear their replicated whitelist independently.
    whitelist_.clear();
  }
}

void PluginContentOriginWhitelist::OnPluginContentOriginAllowed(
    const GURL& content_origin) {
  whitelist_.insert(content_origin);

  web_contents()->SendToAllFrames(
      new FrameMsg_UpdatePluginContentOriginWhitelist(
          MSG_ROUTING_NONE, whitelist_));
}

}  // namespace content