Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(861)

Side by Side Diff: chrome/browser/extensions/extension_message_handler.cc

Issue 6794035: Move dispatching and sending of the last extension specific messages out of TabContents and Rende... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #include "chrome/browser/extensions/extension_message_handler.h"
6
7 #include "chrome/browser/extensions/extension_function_dispatcher.h"
8 #include "chrome/browser/extensions/extension_message_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/extensions/extension_messages.h"
11 #include "content/browser/child_process_security_policy.h"
12 #include "content/browser/renderer_host/render_process_host.h"
13 #include "content/browser/renderer_host/render_view_host.h"
14 #include "content/browser/renderer_host/render_view_host_delegate.h"
15 #include "content/browser/tab_contents/tab_contents.h"
16 #include "content/common/notification_service.h"
17
18 ExtensionMessageHandler::ExtensionMessageHandler(
19 int child_id, IPC::Message::Sender* sender, Profile* profile)
20 : child_id_(child_id),
21 sender_(sender),
22 extension_function_dispatcher_(NULL),
23 profile_(profile) {
24 }
25
26 ExtensionMessageHandler::~ExtensionMessageHandler() {
27 }
28
29 bool ExtensionMessageHandler::OnMessageReceived(
30 const IPC::Message& message) {
31 bool handled = true;
32 IPC_BEGIN_MESSAGE_MAP(ExtensionMessageHandler, message)
33 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage)
34 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
35 IPC_MESSAGE_UNHANDLED(handled = false)
36 IPC_END_MESSAGE_MAP()
37 return handled;
38 }
39
40 bool ExtensionMessageHandler::CanDispatchRequest(
41 int child_id,
42 int routing_id,
43 const ExtensionHostMsg_DomMessage_Params& params) {
44 if (!ChildProcessSecurityPolicy::GetInstance()->
45 HasExtensionBindings(child_id)) {
46 // This can happen if someone uses window.open() to open an extension URL
47 // from a non-extension context.
48 sender_->Send(new ExtensionMsg_Response(
49 routing_id, params.request_id, false, std::string(),
Matt Perry 2011/04/05 19:18:33 nit: indent + 2
jam 2011/04/05 19:25:38 Done.
50 "Access to extension API denied."));
51 return false;
52 }
53
54 return true;
55 }
56
57 void ExtensionMessageHandler::OnPostMessage(int port_id,
58 const std::string& message) {
59 if (profile_->GetExtensionMessageService()) {
60 profile_->GetExtensionMessageService()->PostMessageFromRenderer(
61 port_id, message);
62 }
63 }
64
65 void ExtensionMessageHandler::OnRequest(
66 const IPC::Message& message,
67 const ExtensionHostMsg_DomMessage_Params& params) {
68 DCHECK(child_id_);
69 if (!extension_function_dispatcher_ ||
70 !CanDispatchRequest(child_id_, message.routing_id(), params)) {
71 return;
72 }
73
74 extension_function_dispatcher_->HandleRequest(params);
75 }
76
77 ExtensionMessageObserver::ExtensionMessageObserver(TabContents* tab_contents)
78 : TabContentsObserver(tab_contents),
79 ALLOW_THIS_IN_INITIALIZER_LIST(
80 handler_(0, this, tab_contents->profile())) {
81 // We don't pass in a child_id to handler_ since for TabContents that can
82 // change later.
83 }
84
85 ExtensionMessageObserver::~ExtensionMessageObserver() {
86 }
87
88 bool ExtensionMessageObserver::OnMessageReceived(const IPC::Message& message) {
89 bool handled = true;
90 IPC_BEGIN_MESSAGE_MAP(ExtensionMessageObserver, message)
91 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
92 IPC_MESSAGE_UNHANDLED(handled = false)
93 IPC_END_MESSAGE_MAP()
94
95 if (!handled)
96 handled = handler_.OnMessageReceived(message);
97 return handled;
98 }
99
100 void ExtensionMessageObserver::OnRequest(
101 const IPC::Message& message,
102 const ExtensionHostMsg_DomMessage_Params& params) {
103 if (!handler_.CanDispatchRequest(
104 tab_contents()->render_view_host()->process()->id(),
105 message.routing_id(),
106 params)) {
107 return;
108 }
109
110 tab_contents()->render_view_host()->delegate()->ProcessWebUIMessage(params);
111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698