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 "extensions/renderer/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::DidCreateScriptContext(
28 v8::Handle
<v8::Context
> context
,
31 extension_dispatcher_
->DidCreateScriptContext(
32 render_frame()->GetWebFrame(), context
, extension_group
, world_id
);
35 void ExtensionFrameHelper::WillReleaseScriptContext(
36 v8::Handle
<v8::Context
> context
,
38 extension_dispatcher_
->WillReleaseScriptContext(
39 render_frame()->GetWebFrame(), context
, world_id
);
42 bool ExtensionFrameHelper::OnMessageReceived(const IPC::Message
& message
) {
44 IPC_BEGIN_MESSAGE_MAP(ExtensionFrameHelper
, message
)
45 IPC_MESSAGE_HANDLER(ExtensionMsg_AddMessageToConsole
,
46 OnAddMessageToConsole
)
47 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect
,
48 OnExtensionDispatchOnConnect
)
49 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage
, OnExtensionDeliverMessage
)
50 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect
,
51 OnExtensionDispatchOnDisconnect
)
52 IPC_MESSAGE_UNHANDLED(handled
= false)
57 void ExtensionFrameHelper::OnAddMessageToConsole(
58 content::ConsoleMessageLevel level
,
59 const std::string
& message
) {
60 console::AddMessage(render_frame()->GetRenderView(), level
, message
);
63 void ExtensionFrameHelper::OnExtensionDispatchOnConnect(
65 const std::string
& channel_name
,
66 const ExtensionMsg_TabConnectionInfo
& source
,
67 const ExtensionMsg_ExternalConnectionInfo
& info
,
68 const std::string
& tls_channel_id
) {
69 MessagingBindings::DispatchOnConnect(
70 extension_dispatcher_
->script_context_set(),
79 void ExtensionFrameHelper::OnExtensionDeliverMessage(int target_id
,
80 const Message
& message
) {
81 MessagingBindings::DeliverMessage(
82 extension_dispatcher_
->script_context_set(), target_id
, message
,
86 void ExtensionFrameHelper::OnExtensionDispatchOnDisconnect(
88 const std::string
& error_message
) {
89 MessagingBindings::DispatchOnDisconnect(
90 extension_dispatcher_
->script_context_set(), port_id
, error_message
,
94 } // namespace extensions