summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_message_handler.cc
blob: 4447dac3f9ff5181aa4b79781acc2d012f635434 (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
// Copyright (c) 2011 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 "chrome/browser/extensions/extension_message_handler.h"

#include "chrome/browser/extensions/extension_message_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/extension_messages.h"
#include "content/browser/child_process_security_policy.h"
#include "content/browser/renderer_host/render_process_host.h"
#include "content/browser/renderer_host/render_view_host.h"

ExtensionMessageHandler::ExtensionMessageHandler(
    RenderViewHost* render_view_host)
    : RenderViewHostObserver(render_view_host) {
}

ExtensionMessageHandler::~ExtensionMessageHandler() {
}

bool ExtensionMessageHandler::OnMessageReceived(
    const IPC::Message& message) {
  bool handled = true;
  IPC_BEGIN_MESSAGE_MAP(ExtensionMessageHandler, message)
    IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage)
    IPC_MESSAGE_UNHANDLED(handled = false)
  IPC_END_MESSAGE_MAP()
  return handled;
}

void ExtensionMessageHandler::OnPostMessage(int port_id,
                                            const std::string& message) {
  Profile* profile = render_view_host()->process()->profile();
  if (profile->GetExtensionMessageService()) {
    profile->GetExtensionMessageService()->PostMessageFromRenderer(
        port_id, message);
  }
}