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
),
23 extension_dispatcher_(extension_dispatcher
) {}
25 ExtensionFrameHelper::~ExtensionFrameHelper() {
28 void ExtensionFrameHelper::DidCreateScriptContext(
29 v8::Local
<v8::Context
> context
,
32 extension_dispatcher_
->DidCreateScriptContext(
33 render_frame()->GetWebFrame(), context
, extension_group
, world_id
);
36 void ExtensionFrameHelper::WillReleaseScriptContext(
37 v8::Local
<v8::Context
> context
,
39 extension_dispatcher_
->WillReleaseScriptContext(
40 render_frame()->GetWebFrame(), context
, world_id
);
43 bool ExtensionFrameHelper::OnMessageReceived(const IPC::Message
& message
) {
45 IPC_BEGIN_MESSAGE_MAP(ExtensionFrameHelper
, message
)
46 IPC_MESSAGE_HANDLER(ExtensionMsg_AddMessageToConsole
,
47 OnAddMessageToConsole
)
48 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect
,
49 OnExtensionDispatchOnConnect
)
50 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage
, OnExtensionDeliverMessage
)
51 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect
,
52 OnExtensionDispatchOnDisconnect
)
53 IPC_MESSAGE_HANDLER(ExtensionMsg_SetTabId
, OnExtensionSetTabId
)
54 IPC_MESSAGE_HANDLER(ExtensionMsg_SetTabExtensionOwner
,
55 OnSetTabExtensionOwner
)
56 IPC_MESSAGE_UNHANDLED(handled
= false)
61 void ExtensionFrameHelper::OnAddMessageToConsole(
62 content::ConsoleMessageLevel level
,
63 const std::string
& message
) {
64 console::AddMessage(render_frame()->GetRenderView(), level
, message
);
67 void ExtensionFrameHelper::OnExtensionDispatchOnConnect(
69 const std::string
& channel_name
,
70 const ExtensionMsg_TabConnectionInfo
& source
,
71 const ExtensionMsg_ExternalConnectionInfo
& info
,
72 const std::string
& tls_channel_id
) {
73 MessagingBindings::DispatchOnConnect(
74 extension_dispatcher_
->script_context_set(),
83 void ExtensionFrameHelper::OnExtensionDeliverMessage(int target_id
,
84 const Message
& message
) {
85 MessagingBindings::DeliverMessage(
86 extension_dispatcher_
->script_context_set(), target_id
, message
,
90 void ExtensionFrameHelper::OnExtensionDispatchOnDisconnect(
92 const std::string
& error_message
) {
93 MessagingBindings::DispatchOnDisconnect(
94 extension_dispatcher_
->script_context_set(), port_id
, error_message
,
98 void ExtensionFrameHelper::OnExtensionSetTabId(int tab_id
) {
99 CHECK_EQ(tab_id_
, -1);
104 void ExtensionFrameHelper::OnSetTabExtensionOwner(
105 const std::string
& extension_id
) {
106 tab_extension_owner_id_
= extension_id
;
109 } // namespace extensions