[BackgroundSync] Clean up some tests
[chromium-blink-merge.git] / extensions / renderer / extension_frame_helper.cc
blobbcfcf42760d206bf92a1e6d1490e7a1a09cf902f
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 tab_id_(-1),
23 extension_dispatcher_(extension_dispatcher) {}
25 ExtensionFrameHelper::~ExtensionFrameHelper() {
28 void ExtensionFrameHelper::DidCreateScriptContext(
29 v8::Local<v8::Context> context,
30 int extension_group,
31 int world_id) {
32 extension_dispatcher_->DidCreateScriptContext(
33 render_frame()->GetWebFrame(), context, extension_group, world_id);
36 void ExtensionFrameHelper::WillReleaseScriptContext(
37 v8::Local<v8::Context> context,
38 int world_id) {
39 extension_dispatcher_->WillReleaseScriptContext(
40 render_frame()->GetWebFrame(), context, world_id);
43 bool ExtensionFrameHelper::OnMessageReceived(const IPC::Message& message) {
44 bool handled = true;
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)
57 IPC_END_MESSAGE_MAP()
58 return handled;
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(
68 int target_port_id,
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(),
75 target_port_id,
76 channel_name,
77 source,
78 info,
79 tls_channel_id,
80 render_frame());
83 void ExtensionFrameHelper::OnExtensionDeliverMessage(int target_id,
84 const Message& message) {
85 MessagingBindings::DeliverMessage(
86 extension_dispatcher_->script_context_set(), target_id, message,
87 render_frame());
90 void ExtensionFrameHelper::OnExtensionDispatchOnDisconnect(
91 int port_id,
92 const std::string& error_message) {
93 MessagingBindings::DispatchOnDisconnect(
94 extension_dispatcher_->script_context_set(), port_id, error_message,
95 render_frame());
98 void ExtensionFrameHelper::OnExtensionSetTabId(int tab_id) {
99 CHECK_EQ(tab_id_, -1);
100 CHECK_GE(tab_id, 0);
101 tab_id_ = tab_id;
104 void ExtensionFrameHelper::OnSetTabExtensionOwner(
105 const std::string& extension_id) {
106 tab_extension_owner_id_ = extension_id;
109 } // namespace extensions