OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_message_handler.h" | 5 #include "chrome/browser/extensions/extension_message_handler.h" |
6 | 6 |
7 #include "chrome/browser/extensions/app_notify_channel_setup.h" | |
7 #include "chrome/browser/extensions/extension_message_service.h" | 8 #include "chrome/browser/extensions/extension_message_service.h" |
9 #include "chrome/browser/extensions/extension_service.h" | |
8 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/common/extensions/extension_messages.h" | 11 #include "chrome/common/extensions/extension_messages.h" |
10 #include "content/browser/child_process_security_policy.h" | 12 #include "content/browser/child_process_security_policy.h" |
11 #include "content/browser/renderer_host/render_process_host.h" | 13 #include "content/browser/renderer_host/render_process_host.h" |
12 #include "content/browser/renderer_host/render_view_host.h" | 14 #include "content/browser/renderer_host/render_view_host.h" |
13 #include "content/browser/renderer_host/render_view_host_delegate.h" | 15 #include "content/browser/renderer_host/render_view_host_delegate.h" |
14 | 16 |
15 ExtensionMessageHandler::ExtensionMessageHandler( | 17 ExtensionMessageHandler::ExtensionMessageHandler( |
16 RenderViewHost* render_view_host) | 18 RenderViewHost* render_view_host) |
17 : RenderViewHostObserver(render_view_host) { | 19 : RenderViewHostObserver(render_view_host) { |
18 } | 20 } |
19 | 21 |
20 ExtensionMessageHandler::~ExtensionMessageHandler() { | 22 ExtensionMessageHandler::~ExtensionMessageHandler() { |
21 } | 23 } |
22 | 24 |
23 bool ExtensionMessageHandler::OnMessageReceived( | 25 bool ExtensionMessageHandler::OnMessageReceived( |
24 const IPC::Message& message) { | 26 const IPC::Message& message) { |
25 bool handled = true; | 27 bool handled = true; |
26 IPC_BEGIN_MESSAGE_MAP(ExtensionMessageHandler, message) | 28 IPC_BEGIN_MESSAGE_MAP(ExtensionMessageHandler, message) |
27 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage) | 29 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage) |
30 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppNotifyChannel, | |
31 OnGetAppNotifyChannel) | |
28 IPC_MESSAGE_UNHANDLED(handled = false) | 32 IPC_MESSAGE_UNHANDLED(handled = false) |
29 IPC_END_MESSAGE_MAP() | 33 IPC_END_MESSAGE_MAP() |
30 return handled; | 34 return handled; |
31 } | 35 } |
32 | 36 |
33 void ExtensionMessageHandler::RenderViewHostInitialized() { | 37 void ExtensionMessageHandler::RenderViewHostInitialized() { |
34 Send(new ExtensionMsg_NotifyRenderViewType( | 38 Send(new ExtensionMsg_NotifyRenderViewType( |
35 routing_id(), render_view_host()->delegate()->GetRenderViewType())); | 39 routing_id(), render_view_host()->delegate()->GetRenderViewType())); |
36 } | 40 } |
37 | 41 |
38 void ExtensionMessageHandler::OnPostMessage(int port_id, | 42 void ExtensionMessageHandler::OnPostMessage(int port_id, |
39 const std::string& message) { | 43 const std::string& message) { |
40 Profile* profile = Profile::FromBrowserContext( | 44 Profile* profile = Profile::FromBrowserContext( |
41 render_view_host()->process()->browser_context()); | 45 render_view_host()->process()->browser_context()); |
42 if (profile->GetExtensionMessageService()) { | 46 if (profile->GetExtensionMessageService()) { |
43 profile->GetExtensionMessageService()->PostMessageFromRenderer( | 47 profile->GetExtensionMessageService()->PostMessageFromRenderer( |
44 port_id, message); | 48 port_id, message); |
45 } | 49 } |
46 } | 50 } |
51 | |
52 void ExtensionMessageHandler::OnGetAppNotifyChannel( | |
53 int request_id, | |
54 const GURL& requestor_url, | |
55 const std::string& client_id) { | |
56 | |
57 // Check for permission first. | |
58 Profile* profile = Profile::FromBrowserContext( | |
59 render_view_host()->process()->browser_context()); | |
60 ExtensionService* extension_service = profile->GetExtensionService(); | |
61 if (!extension_service || !extension_service->is_ready()) | |
Aaron Boodman
2011/10/04 23:40:36
I don't think that it is possible for either of th
asargent_no_longer_on_chrome
2011/10/06 03:35:32
Ok, removed this.
| |
62 return; | |
63 const Extension* extension = | |
64 extension_service->GetInstalledApp(requestor_url); | |
Aaron Boodman
2011/10/04 23:40:36
Can you also check that the app is running in the
asargent_no_longer_on_chrome
2011/10/06 03:35:32
As discussed in IRC, I've added the process check
| |
65 if (!extension || | |
66 !extension->HasAPIPermission(ExtensionAPIPermission::kExperimental)) { | |
67 AppNotifyChannelSetupComplete(request_id, "", "permission_error"); | |
68 return; | |
69 } | |
70 | |
71 scoped_refptr<AppNotifyChannelSetup> channel_setup( | |
72 new AppNotifyChannelSetup(request_id, | |
73 client_id, | |
74 requestor_url, | |
75 this->AsWeakPtr())); | |
76 channel_setup->Start(); | |
77 // We'll get called back in AppNotifyChannelSetupComplete. | |
78 } | |
79 | |
80 void ExtensionMessageHandler::AppNotifyChannelSetupComplete( | |
81 int request_id, const std::string& client_id, const std::string& error) { | |
82 Send(new ExtensionMsg_GetAppNotifyChannelResponse( | |
83 routing_id(), request_id, client_id, error)); | |
84 } | |
OLD | NEW |