Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / chrome / renderer / extensions / extension_frame_helper.cc
blobef0e95372fd44d9fee34f18c8e649b7a813b9e54
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/renderer/extensions/extension_frame_helper.h"
7 #include "content/public/renderer/render_frame.h"
8 #include "extensions/common/api/messaging/message.h"
9 #include "extensions/common/extension_messages.h"
10 #include "extensions/renderer/console.h"
11 #include "extensions/renderer/dispatcher.h"
12 #include "extensions/renderer/messaging_bindings.h"
13 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
14 #include "third_party/WebKit/public/web/WebLocalFrame.h"
16 namespace extensions {
18 ExtensionFrameHelper::ExtensionFrameHelper(content::RenderFrame* render_frame,
19 Dispatcher* extension_dispatcher)
20 : content::RenderFrameObserver(render_frame),
21 content::RenderFrameObserverTracker<ExtensionFrameHelper>(render_frame),
22 extension_dispatcher_(extension_dispatcher) {}
24 ExtensionFrameHelper::~ExtensionFrameHelper() {
27 void ExtensionFrameHelper::WillReleaseScriptContext(
28 v8::Handle<v8::Context> context,
29 int world_id) {
30 extension_dispatcher_->WillReleaseScriptContext(
31 render_frame()->GetWebFrame(), context, world_id);
34 bool ExtensionFrameHelper::OnMessageReceived(const IPC::Message& message) {
35 bool handled = true;
36 IPC_BEGIN_MESSAGE_MAP(ExtensionFrameHelper, message)
37 IPC_MESSAGE_HANDLER(ExtensionMsg_AddMessageToConsole,
38 OnAddMessageToConsole)
39 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect,
40 OnExtensionDispatchOnConnect)
41 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnExtensionDeliverMessage)
42 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect,
43 OnExtensionDispatchOnDisconnect)
44 IPC_MESSAGE_UNHANDLED(handled = false)
45 IPC_END_MESSAGE_MAP()
46 return handled;
49 void ExtensionFrameHelper::OnAddMessageToConsole(
50 content::ConsoleMessageLevel level,
51 const std::string& message) {
52 console::AddMessage(render_frame()->GetRenderView(), level, message);
55 void ExtensionFrameHelper::OnExtensionDispatchOnConnect(
56 int target_port_id,
57 const std::string& channel_name,
58 const ExtensionMsg_TabConnectionInfo& source,
59 const ExtensionMsg_ExternalConnectionInfo& info,
60 const std::string& tls_channel_id) {
61 MessagingBindings::DispatchOnConnect(
62 extension_dispatcher_->script_context_set(),
63 target_port_id,
64 channel_name,
65 source,
66 info,
67 tls_channel_id,
68 render_frame());
71 void ExtensionFrameHelper::OnExtensionDeliverMessage(int target_id,
72 const Message& message) {
73 MessagingBindings::DeliverMessage(
74 extension_dispatcher_->script_context_set(), target_id, message,
75 render_frame());
78 void ExtensionFrameHelper::OnExtensionDispatchOnDisconnect(
79 int port_id,
80 const std::string& error_message) {
81 MessagingBindings::DispatchOnDisconnect(
82 extension_dispatcher_->script_context_set(), port_id, error_message,
83 render_frame());
86 } // namespace extensions