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.h" | |
10 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
11 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
12 | 11 |
13 ExtensionEventRouterForwarder::ExtensionEventRouterForwarder() { | 12 ExtensionEventRouterForwarder::ExtensionEventRouterForwarder() { |
14 } | 13 } |
15 | 14 |
16 ExtensionEventRouterForwarder::~ExtensionEventRouterForwarder() { | 15 ExtensionEventRouterForwarder::~ExtensionEventRouterForwarder() { |
17 } | 16 } |
18 | 17 |
19 void ExtensionEventRouterForwarder::BroadcastEventToRenderers( | 18 void ExtensionEventRouterForwarder::BroadcastEventToRenderers( |
20 const std::string& event_name, const std::string& event_args, | 19 const std::string& event_name, const std::string& event_args, |
21 const GURL& event_url) { | 20 const GURL& event_url) { |
22 HandleEvent("", event_name, event_args, NULL, true, event_url); | 21 HandleEvent("", event_name, event_args, 0, true, event_url); |
23 } | 22 } |
24 | 23 |
25 void ExtensionEventRouterForwarder::DispatchEventToRenderers( | 24 void ExtensionEventRouterForwarder::DispatchEventToRenderers( |
26 const std::string& event_name, const std::string& event_args, | 25 const std::string& event_name, const std::string& event_args, |
27 Profile* profile, bool use_profile_to_restrict_events, | 26 ProfileId profile_id, bool use_profile_to_restrict_events, |
28 const GURL& event_url) { | 27 const GURL& event_url) { |
29 DCHECK(profile); | 28 if (profile_id == Profile::InvalidProfileId) |
30 HandleEvent("", event_name, event_args, profile, | 29 return; |
30 HandleEvent("", event_name, event_args, profile_id, | |
31 use_profile_to_restrict_events, event_url); | 31 use_profile_to_restrict_events, event_url); |
32 } | 32 } |
33 | 33 |
34 void ExtensionEventRouterForwarder::BroadcastEventToExtension( | 34 void ExtensionEventRouterForwarder::BroadcastEventToExtension( |
35 const std::string& extension_id, | 35 const std::string& extension_id, |
36 const std::string& event_name, const std::string& event_args, | 36 const std::string& event_name, const std::string& event_args, |
37 const GURL& event_url) { | 37 const GURL& event_url) { |
38 HandleEvent(extension_id, event_name, event_args, NULL, true, event_url); | 38 HandleEvent(extension_id, event_name, event_args, 0, true, event_url); |
39 } | 39 } |
40 | 40 |
41 void ExtensionEventRouterForwarder::DispatchEventToExtension( | 41 void ExtensionEventRouterForwarder::DispatchEventToExtension( |
42 const std::string& extension_id, | 42 const std::string& extension_id, |
43 const std::string& event_name, const std::string& event_args, | 43 const std::string& event_name, const std::string& event_args, |
44 Profile* profile, bool use_profile_to_restrict_events, | 44 ProfileId profile_id, bool use_profile_to_restrict_events, |
45 const GURL& event_url) { | 45 const GURL& event_url) { |
46 DCHECK(profile); | 46 if (profile_id == Profile::InvalidProfileId) |
47 HandleEvent(extension_id, event_name, event_args, profile, | 47 return; |
48 HandleEvent(extension_id, event_name, event_args, profile_id, | |
48 use_profile_to_restrict_events, event_url); | 49 use_profile_to_restrict_events, event_url); |
49 } | 50 } |
50 | 51 |
51 void ExtensionEventRouterForwarder::HandleEvent( | 52 void ExtensionEventRouterForwarder::HandleEvent( |
52 const std::string& extension_id, | 53 const std::string& extension_id, |
53 const std::string& event_name, const std::string& event_args, | 54 const std::string& event_name, const std::string& event_args, |
54 Profile* profile, bool use_profile_to_restrict_events, | 55 ProfileId profile_id, bool use_profile_to_restrict_events, |
55 const GURL& event_url) { | 56 const GURL& event_url) { |
56 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 57 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
57 BrowserThread::PostTask( | 58 BrowserThread::PostTask( |
58 BrowserThread::UI, FROM_HERE, | 59 BrowserThread::UI, FROM_HERE, |
59 NewRunnableMethod( | 60 NewRunnableMethod( |
60 this, | 61 this, |
61 &ExtensionEventRouterForwarder::HandleEvent, | 62 &ExtensionEventRouterForwarder::HandleEvent, |
62 extension_id, event_name, event_args, profile, | 63 extension_id, event_name, event_args, profile_id, |
63 use_profile_to_restrict_events, event_url)); | 64 use_profile_to_restrict_events, event_url)); |
64 return; | 65 return; |
65 } | 66 } |
66 | 67 |
67 if (!g_browser_process || !g_browser_process->profile_manager()) | 68 if (!g_browser_process || !g_browser_process->profile_manager()) |
68 return; | 69 return; |
69 | 70 |
70 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 71 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
72 Profile* profile = profile_manager->GetProfileWithId(profile_id); | |
73 if (profile_id != Profile::InvalidProfileId && !profile) | |
willchan no longer on Chromium
2011/02/28 21:48:41
Shouldn't we only call GetProfileWithId() if profi
| |
74 return; | |
71 if (profile) { | 75 if (profile) { |
72 if (!profile_manager->IsValidProfile(profile)) | |
73 return; | |
74 CallExtensionEventRouter( | 76 CallExtensionEventRouter( |
75 profile, extension_id, event_name, event_args, | 77 profile, extension_id, event_name, event_args, |
76 use_profile_to_restrict_events ? profile : NULL, event_url); | 78 use_profile_to_restrict_events ? profile : NULL, event_url); |
77 } else { | 79 } else { |
78 ProfileManager::iterator i; | 80 ProfileManager::iterator i; |
79 for (i = profile_manager->begin(); i != profile_manager->end(); ++i) { | 81 for (i = profile_manager->begin(); i != profile_manager->end(); ++i) { |
80 CallExtensionEventRouter( | 82 CallExtensionEventRouter( |
81 *i, extension_id, event_name, event_args, | 83 *i, extension_id, event_name, event_args, |
82 use_profile_to_restrict_events ? (*i) : NULL, event_url); | 84 use_profile_to_restrict_events ? (*i) : NULL, event_url); |
83 } | 85 } |
84 } | 86 } |
85 } | 87 } |
86 | 88 |
87 void ExtensionEventRouterForwarder::CallExtensionEventRouter( | 89 void ExtensionEventRouterForwarder::CallExtensionEventRouter( |
88 Profile* profile, const std::string& extension_id, | 90 Profile* profile, const std::string& extension_id, |
89 const std::string& event_name, const std::string& event_args, | 91 const std::string& event_name, const std::string& event_args, |
90 Profile* restrict_to_profile, const GURL& event_url) { | 92 Profile* restrict_to_profile, const GURL& event_url) { |
91 if (extension_id.empty()) { | 93 if (extension_id.empty()) { |
92 profile->GetExtensionEventRouter()-> | 94 profile->GetExtensionEventRouter()-> |
93 DispatchEventToRenderers( | 95 DispatchEventToRenderers( |
94 event_name, event_args, restrict_to_profile, event_url); | 96 event_name, event_args, restrict_to_profile, event_url); |
95 } else { | 97 } else { |
96 profile->GetExtensionEventRouter()-> | 98 profile->GetExtensionEventRouter()-> |
97 DispatchEventToExtension( | 99 DispatchEventToExtension( |
98 extension_id, | 100 extension_id, |
99 event_name, event_args, restrict_to_profile, event_url); | 101 event_name, event_args, restrict_to_profile, event_url); |
100 } | 102 } |
101 } | 103 } |
102 | 104 |
OLD | NEW |