OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/child_process_security_policy.h" | 8 #include "chrome/browser/child_process_security_policy.h" |
9 #include "chrome/browser/extensions/extension_devtools_manager.h" | 9 #include "chrome/browser/extensions/extension_devtools_manager.h" |
10 #include "chrome/browser/extensions/extension_processes_api.h" | 10 #include "chrome/browser/extensions/extension_processes_api.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 const std::string& event_name, | 26 const std::string& event_name, |
27 const std::string& event_args, | 27 const std::string& event_args, |
28 const GURL& event_url) { | 28 const GURL& event_url) { |
29 ListValue args; | 29 ListValue args; |
30 args.Set(0, Value::CreateStringValue(event_name)); | 30 args.Set(0, Value::CreateStringValue(event_name)); |
31 args.Set(1, Value::CreateStringValue(event_args)); | 31 args.Set(1, Value::CreateStringValue(event_args)); |
32 renderer->Send(new ViewMsg_ExtensionMessageInvoke(MSG_ROUTING_CONTROL, | 32 renderer->Send(new ViewMsg_ExtensionMessageInvoke(MSG_ROUTING_CONTROL, |
33 extension_id, kDispatchEvent, args, event_url)); | 33 extension_id, kDispatchEvent, args, event_url)); |
34 } | 34 } |
35 | 35 |
36 static bool CanCrossIncognito(Profile* profile, | |
37 const std::string& extension_id) { | |
38 // We allow the extension to see events and data from another profile iff it | |
39 // uses "spanning" behavior and it has incognito access. "split" mode | |
40 // extensions only see events for a matching profile. | |
41 const Extension* extension = | |
42 profile->GetExtensionsService()->GetExtensionById(extension_id, false); | |
43 return (profile->GetExtensionsService()->IsIncognitoEnabled(extension) && | |
44 !extension->incognito_split_mode()); | |
45 } | |
46 | |
47 } // namespace | 36 } // namespace |
48 | 37 |
49 struct ExtensionEventRouter::EventListener { | 38 struct ExtensionEventRouter::EventListener { |
50 RenderProcessHost* process; | 39 RenderProcessHost* process; |
51 std::string extension_id; | 40 std::string extension_id; |
52 | 41 |
53 explicit EventListener(RenderProcessHost* process, | 42 explicit EventListener(RenderProcessHost* process, |
54 const std::string& extension_id) | 43 const std::string& extension_id) |
55 : process(process), extension_id(extension_id) {} | 44 : process(process), extension_id(extension_id) {} |
56 | 45 |
57 bool operator<(const EventListener& that) const { | 46 bool operator<(const EventListener& that) const { |
58 if (process < that.process) | 47 if (process < that.process) |
59 return true; | 48 return true; |
60 if (process == that.process && extension_id < that.extension_id) | 49 if (process == that.process && extension_id < that.extension_id) |
61 return true; | 50 return true; |
62 return false; | 51 return false; |
63 } | 52 } |
64 }; | 53 }; |
65 | 54 |
| 55 // static |
| 56 bool ExtensionEventRouter::CanCrossIncognito(Profile* profile, |
| 57 const std::string& extension_id) { |
| 58 const Extension* extension = |
| 59 profile->GetExtensionsService()->GetExtensionById(extension_id, false); |
| 60 return CanCrossIncognito(profile, extension); |
| 61 } |
| 62 |
| 63 // static |
| 64 bool ExtensionEventRouter::CanCrossIncognito(Profile* profile, |
| 65 const Extension* extension) { |
| 66 // We allow the extension to see events and data from another profile iff it |
| 67 // uses "spanning" behavior and it has incognito access. "split" mode |
| 68 // extensions only see events for a matching profile. |
| 69 return (profile->GetExtensionsService()->IsIncognitoEnabled(extension) && |
| 70 !extension->incognito_split_mode()); |
| 71 } |
| 72 |
66 ExtensionEventRouter::ExtensionEventRouter(Profile* profile) | 73 ExtensionEventRouter::ExtensionEventRouter(Profile* profile) |
67 : profile_(profile), | 74 : profile_(profile), |
68 extension_devtools_manager_(profile->GetExtensionDevToolsManager()) { | 75 extension_devtools_manager_(profile->GetExtensionDevToolsManager()) { |
69 registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, | 76 registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, |
70 NotificationService::AllSources()); | 77 NotificationService::AllSources()); |
71 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, | 78 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, |
72 NotificationService::AllSources()); | 79 NotificationService::AllSources()); |
73 } | 80 } |
74 | 81 |
75 ExtensionEventRouter::~ExtensionEventRouter() { | 82 ExtensionEventRouter::~ExtensionEventRouter() { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 } | 214 } |
208 } | 215 } |
209 } | 216 } |
210 break; | 217 break; |
211 } | 218 } |
212 default: | 219 default: |
213 NOTREACHED(); | 220 NOTREACHED(); |
214 return; | 221 return; |
215 } | 222 } |
216 } | 223 } |
OLD | NEW |