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_event_router.h" | 5 #include "chrome/browser/extensions/extension_event_router.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/extensions/extension_devtools_manager.h" | 8 #include "chrome/browser/extensions/extension_devtools_manager.h" |
9 #include "chrome/browser/extensions/extension_processes_api.h" | 9 #include "chrome/browser/extensions/extension_processes_api.h" |
10 #include "chrome/browser/extensions/extension_processes_api_constants.h" | 10 #include "chrome/browser/extensions/extension_processes_api_constants.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/extension_tabs_module.h" | 12 #include "chrome/browser/extensions/extension_tabs_module.h" |
13 #include "chrome/browser/extensions/extension_webrequest_api.h" | 13 #include "chrome/browser/extensions/extension_webrequest_api.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
16 #include "chrome/common/extensions/extension_messages.h" | 16 #include "chrome/common/extensions/extension_messages.h" |
17 #include "content/browser/child_process_security_policy.h" | 17 #include "content/browser/child_process_security_policy.h" |
18 #include "content/browser/renderer_host/render_process_host.h" | 18 #include "content/browser/renderer_host/render_process_host.h" |
19 #include "content/common/notification_service.h" | 19 #include "content/common/notification_service.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const char kDispatchEvent[] = "Event.dispatchJSON"; | 23 const char kDispatchEvent[] = "Event.dispatchJSON"; |
24 | 24 |
25 static void DispatchEvent(RenderProcessHost* renderer, | |
26 const std::string& extension_id, | |
27 const std::string& event_name, | |
28 const std::string& event_args, | |
29 const GURL& event_url) { | |
30 ListValue args; | |
31 args.Set(0, Value::CreateStringValue(event_name)); | |
32 args.Set(1, Value::CreateStringValue(event_args)); | |
33 renderer->Send(new ExtensionMsg_MessageInvoke(MSG_ROUTING_CONTROL, | |
34 extension_id, kDispatchEvent, args, event_url)); | |
35 } | |
36 | |
37 static void NotifyEventListenerRemovedOnIOThread( | 25 static void NotifyEventListenerRemovedOnIOThread( |
38 ProfileId profile_id, | 26 ProfileId profile_id, |
39 const std::string& extension_id, | 27 const std::string& extension_id, |
40 const std::string& sub_event_name) { | 28 const std::string& sub_event_name) { |
41 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 29 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
42 profile_id, extension_id, sub_event_name); | 30 profile_id, extension_id, sub_event_name); |
43 } | 31 } |
44 | 32 |
45 } // namespace | 33 } // namespace |
46 | 34 |
47 struct ExtensionEventRouter::EventListener { | 35 struct ExtensionEventRouter::EventListener { |
48 RenderProcessHost* process; | 36 RenderProcessHost* process; |
49 std::string extension_id; | 37 std::string extension_id; |
50 | 38 |
51 explicit EventListener(RenderProcessHost* process, | 39 explicit EventListener(RenderProcessHost* process, |
52 const std::string& extension_id) | 40 const std::string& extension_id) |
53 : process(process), extension_id(extension_id) {} | 41 : process(process), extension_id(extension_id) {} |
54 | 42 |
55 bool operator<(const EventListener& that) const { | 43 bool operator<(const EventListener& that) const { |
56 if (process < that.process) | 44 if (process < that.process) |
57 return true; | 45 return true; |
58 if (process == that.process && extension_id < that.extension_id) | 46 if (process == that.process && extension_id < that.extension_id) |
59 return true; | 47 return true; |
60 return false; | 48 return false; |
61 } | 49 } |
62 }; | 50 }; |
63 | 51 |
64 // static | 52 // static |
65 bool ExtensionEventRouter::CanCrossIncognito(Profile* profile, | 53 void ExtensionEventRouter::DispatchEvent(IPC::Message::Sender* ipc_sender, |
66 const std::string& extension_id) { | 54 const std::string& extension_id, |
67 const Extension* extension = | 55 const std::string& event_name, |
68 profile->GetExtensionService()->GetExtensionById(extension_id, false); | 56 const std::string& event_args, |
69 return CanCrossIncognito(profile, extension); | 57 const GURL& event_url) { |
70 } | 58 ListValue args; |
71 | 59 args.Set(0, Value::CreateStringValue(event_name)); |
72 // static | 60 args.Set(1, Value::CreateStringValue(event_args)); |
73 bool ExtensionEventRouter::CanCrossIncognito(Profile* profile, | 61 ipc_sender->Send(new ExtensionMsg_MessageInvoke(MSG_ROUTING_CONTROL, |
74 const Extension* extension) { | 62 extension_id, kDispatchEvent, args, event_url)); |
75 // We allow the extension to see events and data from another profile iff it | |
76 // uses "spanning" behavior and it has incognito access. "split" mode | |
77 // extensions only see events for a matching profile. | |
78 return | |
79 (profile->GetExtensionService()->IsIncognitoEnabled(extension->id()) && | |
80 !extension->incognito_split_mode()); | |
81 } | 63 } |
82 | 64 |
83 ExtensionEventRouter::ExtensionEventRouter(Profile* profile) | 65 ExtensionEventRouter::ExtensionEventRouter(Profile* profile) |
84 : profile_(profile), | 66 : profile_(profile), |
85 extension_devtools_manager_(profile->GetExtensionDevToolsManager()) { | 67 extension_devtools_manager_(profile->GetExtensionDevToolsManager()) { |
86 registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, | 68 registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, |
87 NotificationService::AllSources()); | 69 NotificationService::AllSources()); |
88 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, | 70 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, |
89 NotificationService::AllSources()); | 71 NotificationService::AllSources()); |
90 } | 72 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 217 } |
236 } | 218 } |
237 } | 219 } |
238 break; | 220 break; |
239 } | 221 } |
240 default: | 222 default: |
241 NOTREACHED(); | 223 NOTREACHED(); |
242 return; | 224 return; |
243 } | 225 } |
244 } | 226 } |
OLD | NEW |