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_forwarder.h" | 5 #include "chrome/browser/extensions/extension_event_router_forwarder.h" |
6 | 6 |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/extensions/extension_event_router.h" | 8 #include "chrome/browser/extensions/extension_event_router.h" |
9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
11 | 11 |
12 ExtensionEventRouterForwarder::ExtensionEventRouterForwarder() { | 12 ExtensionEventRouterForwarder::ExtensionEventRouterForwarder() { |
13 } | 13 } |
14 | 14 |
15 ExtensionEventRouterForwarder::~ExtensionEventRouterForwarder() { | 15 ExtensionEventRouterForwarder::~ExtensionEventRouterForwarder() { |
16 } | 16 } |
17 | 17 |
18 void ExtensionEventRouterForwarder::BroadcastEventToRenderers( | 18 void ExtensionEventRouterForwarder::BroadcastEventToRenderers( |
19 const std::string& event_name, | 19 const std::string& event_name, |
20 const std::string& event_args, | 20 const std::string& event_args, |
21 const GURL& event_url) { | 21 const GURL& event_url) { |
22 HandleEvent("", event_name, event_args, 0, true, event_url); | 22 HandleEvent("", event_name, event_args, 0, true, event_url); |
23 } | 23 } |
24 | 24 |
25 void ExtensionEventRouterForwarder::DispatchEventToRenderers( | 25 void ExtensionEventRouterForwarder::DispatchEventToRenderers( |
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 ProfileId profile_id, | 28 void* profile, |
29 bool use_profile_to_restrict_events, | 29 bool use_profile_to_restrict_events, |
30 const GURL& event_url) { | 30 const GURL& event_url) { |
31 if (profile_id == Profile::kInvalidProfileId) | 31 if (!profile) |
32 return; | 32 return; |
33 HandleEvent("", event_name, event_args, profile_id, | 33 HandleEvent("", event_name, event_args, profile, |
34 use_profile_to_restrict_events, event_url); | 34 use_profile_to_restrict_events, event_url); |
35 } | 35 } |
36 | 36 |
37 void ExtensionEventRouterForwarder::BroadcastEventToExtension( | 37 void ExtensionEventRouterForwarder::BroadcastEventToExtension( |
38 const std::string& extension_id, | 38 const std::string& extension_id, |
39 const std::string& event_name, | 39 const std::string& event_name, |
40 const std::string& event_args, | 40 const std::string& event_args, |
41 const GURL& event_url) { | 41 const GURL& event_url) { |
42 HandleEvent(extension_id, event_name, event_args, 0, true, event_url); | 42 HandleEvent(extension_id, event_name, event_args, 0, true, event_url); |
43 } | 43 } |
44 | 44 |
45 void ExtensionEventRouterForwarder::DispatchEventToExtension( | 45 void ExtensionEventRouterForwarder::DispatchEventToExtension( |
46 const std::string& extension_id, | 46 const std::string& extension_id, |
47 const std::string& event_name, | 47 const std::string& event_name, |
48 const std::string& event_args, | 48 const std::string& event_args, |
49 ProfileId profile_id, | 49 void* profile, |
50 bool use_profile_to_restrict_events, | 50 bool use_profile_to_restrict_events, |
51 const GURL& event_url) { | 51 const GURL& event_url) { |
52 if (profile_id == Profile::kInvalidProfileId) | 52 if (!profile) |
53 return; | 53 return; |
54 HandleEvent(extension_id, event_name, event_args, profile_id, | 54 HandleEvent(extension_id, event_name, event_args, profile, |
55 use_profile_to_restrict_events, event_url); | 55 use_profile_to_restrict_events, event_url); |
56 } | 56 } |
57 | 57 |
58 void ExtensionEventRouterForwarder::HandleEvent( | 58 void ExtensionEventRouterForwarder::HandleEvent( |
59 const std::string& extension_id, | 59 const std::string& extension_id, |
60 const std::string& event_name, | 60 const std::string& event_name, |
61 const std::string& event_args, | 61 const std::string& event_args, |
62 ProfileId profile_id, | 62 void* profile_ptr, |
63 bool use_profile_to_restrict_events, | 63 bool use_profile_to_restrict_events, |
64 const GURL& event_url) { | 64 const GURL& event_url) { |
65 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 65 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
66 BrowserThread::PostTask( | 66 BrowserThread::PostTask( |
67 BrowserThread::UI, FROM_HERE, | 67 BrowserThread::UI, FROM_HERE, |
68 NewRunnableMethod( | 68 NewRunnableMethod( |
69 this, | 69 this, |
70 &ExtensionEventRouterForwarder::HandleEvent, | 70 &ExtensionEventRouterForwarder::HandleEvent, |
71 extension_id, event_name, event_args, profile_id, | 71 extension_id, event_name, event_args, profile_ptr, |
72 use_profile_to_restrict_events, event_url)); | 72 use_profile_to_restrict_events, event_url)); |
73 return; | 73 return; |
74 } | 74 } |
75 | 75 |
76 if (!g_browser_process || !g_browser_process->profile_manager()) | 76 if (!g_browser_process || !g_browser_process->profile_manager()) |
77 return; | 77 return; |
78 | 78 |
79 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 79 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
80 Profile* profile = NULL; | 80 Profile* profile = NULL; |
81 if (profile_id != Profile::kInvalidProfileId) { | 81 if (profile_ptr) { |
82 profile = profile_manager->GetProfileWithId(profile_id); | 82 profile = reinterpret_cast<Profile*>(profile_ptr); |
83 if (!profile) | 83 if (!profile_manager->IsValidProfile(profile)) |
84 return; | 84 return; |
85 } | 85 } |
86 if (profile) { | 86 if (profile) { |
87 CallExtensionEventRouter( | 87 CallExtensionEventRouter( |
88 profile, extension_id, event_name, event_args, | 88 profile, extension_id, event_name, event_args, |
89 use_profile_to_restrict_events ? profile : NULL, event_url); | 89 use_profile_to_restrict_events ? profile : NULL, event_url); |
90 } else { | 90 } else { |
91 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); | 91 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); |
92 for (size_t i = 0; i < profiles.size(); ++i) { | 92 for (size_t i = 0; i < profiles.size(); ++i) { |
93 CallExtensionEventRouter( | 93 CallExtensionEventRouter( |
(...skipping 20 matching lines...) Expand all Loading... |
114 profile->GetExtensionEventRouter()-> | 114 profile->GetExtensionEventRouter()-> |
115 DispatchEventToRenderers( | 115 DispatchEventToRenderers( |
116 event_name, event_args, restrict_to_profile, event_url); | 116 event_name, event_args, restrict_to_profile, event_url); |
117 } else { | 117 } else { |
118 profile->GetExtensionEventRouter()-> | 118 profile->GetExtensionEventRouter()-> |
119 DispatchEventToExtension( | 119 DispatchEventToExtension( |
120 extension_id, | 120 extension_id, |
121 event_name, event_args, restrict_to_profile, event_url); | 121 event_name, event_args, restrict_to_profile, event_url); |
122 } | 122 } |
123 } | 123 } |
OLD | NEW |