OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/api/system_indicator/system_indicator_manage r.h" | 5 #include "chrome/browser/extensions/api/system_indicator/system_indicator_manage r.h" |
6 | 6 |
7 #include "base/memory/linked_ptr.h" | 7 #include "base/memory/linked_ptr.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/extensions/extension_action.h" | 10 #include "chrome/browser/extensions/extension_action.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/status_icons/status_icon.h" | 13 #include "chrome/browser/status_icons/status_icon.h" |
14 #include "chrome/browser/status_icons/status_icon_observer.h" | 14 #include "chrome/browser/status_icons/status_icon_observer.h" |
15 #include "chrome/browser/status_icons/status_tray.h" | 15 #include "chrome/browser/status_icons/status_tray.h" |
16 #include "chrome/common/extensions/api/system_indicator.h" | 16 #include "chrome/common/extensions/api/system_indicator.h" |
17 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
18 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
19 #include "extensions/browser/event_router.h" | 19 #include "extensions/browser/event_router.h" |
20 #include "extensions/browser/extension_registry.h" | |
20 #include "extensions/browser/extension_system.h" | 21 #include "extensions/browser/extension_system.h" |
21 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
22 #include "ui/gfx/image/image.h" | 23 #include "ui/gfx/image/image.h" |
23 | 24 |
24 namespace extensions { | 25 namespace extensions { |
25 | 26 |
26 namespace system_indicator = api::system_indicator; | 27 namespace system_indicator = api::system_indicator; |
27 | 28 |
28 // Observes clicks on a given status icon and forwards the event to the | 29 // Observes clicks on a given status icon and forwards the event to the |
29 // appropriate extension. Handles icon updates, and responsible for creating | 30 // appropriate extension. Handles icon updates, and responsible for creating |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 if (icon_) { | 78 if (icon_) { |
78 icon_->RemoveObserver(this); | 79 icon_->RemoveObserver(this); |
79 status_tray_->RemoveStatusIcon(icon_); | 80 status_tray_->RemoveStatusIcon(icon_); |
80 } | 81 } |
81 } | 82 } |
82 | 83 |
83 void ExtensionIndicatorIcon::OnStatusIconClicked() { | 84 void ExtensionIndicatorIcon::OnStatusIconClicked() { |
84 scoped_ptr<base::ListValue> params( | 85 scoped_ptr<base::ListValue> params( |
85 api::system_indicator::OnClicked::Create()); | 86 api::system_indicator::OnClicked::Create()); |
86 | 87 |
87 EventRouter* event_router = EventRouter::Get(profile_); | |
88 scoped_ptr<Event> event(new Event( | 88 scoped_ptr<Event> event(new Event( |
89 system_indicator::OnClicked::kEventName, | 89 system_indicator::OnClicked::kEventName, |
90 params.Pass(), | 90 params.Pass(), |
91 profile_)); | 91 profile_)); |
92 event_router->DispatchEventToExtension( | 92 EventRouter::Get(profile_) |
93 extension_->id(), event.Pass()); | 93 ->DispatchEventToExtension(extension_->id(), event.Pass()); |
dewittj
2014/04/28 21:25:49
Don't really need to change this eh?
limasdf
2014/04/28 22:51:40
Yes it doesnt really need to be change. But |event
dewittj
2014/04/28 23:34:52
I know it sounds pedantic, but I'd rather the patc
limasdf
2014/04/29 00:09:29
Yeah. Exactly. Thanks you for letting me know good
| |
94 } | 94 } |
95 | 95 |
96 void ExtensionIndicatorIcon::OnIconUpdated() { | 96 void ExtensionIndicatorIcon::OnIconUpdated() { |
97 icon_->SetImage( | 97 icon_->SetImage( |
98 icon_factory_.GetIcon(ExtensionAction::kDefaultTabId).AsImageSkia()); | 98 icon_factory_.GetIcon(ExtensionAction::kDefaultTabId).AsImageSkia()); |
99 } | 99 } |
100 | 100 |
101 ExtensionIndicatorIcon::ExtensionIndicatorIcon(const Extension* extension, | 101 ExtensionIndicatorIcon::ExtensionIndicatorIcon(const Extension* extension, |
102 const ExtensionAction* action, | 102 const ExtensionAction* action, |
103 Profile* profile, | 103 Profile* profile, |
(...skipping 10 matching lines...) Expand all Loading... | |
114 base::string16 tool_tip = base::UTF8ToUTF16(extension_->name()); | 114 base::string16 tool_tip = base::UTF8ToUTF16(extension_->name()); |
115 | 115 |
116 icon_ = status_tray_->CreateStatusIcon( | 116 icon_ = status_tray_->CreateStatusIcon( |
117 StatusTray::OTHER_ICON, icon_image, tool_tip); | 117 StatusTray::OTHER_ICON, icon_image, tool_tip); |
118 if (icon_) | 118 if (icon_) |
119 icon_->AddObserver(this); | 119 icon_->AddObserver(this); |
120 } | 120 } |
121 | 121 |
122 SystemIndicatorManager::SystemIndicatorManager(Profile* profile, | 122 SystemIndicatorManager::SystemIndicatorManager(Profile* profile, |
123 StatusTray* status_tray) | 123 StatusTray* status_tray) |
124 : profile_(profile), status_tray_(status_tray) { | 124 : profile_(profile), |
125 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 125 status_tray_(status_tray), |
126 content::Source<Profile>(profile_->GetOriginalProfile())); | 126 extension_registry_observer_(this) { |
127 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); | |
128 | |
127 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, | 129 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, |
128 content::Source<Profile>(profile_->GetOriginalProfile())); | 130 content::Source<Profile>(profile_->GetOriginalProfile())); |
129 } | 131 } |
130 | 132 |
131 SystemIndicatorManager::~SystemIndicatorManager() { | 133 SystemIndicatorManager::~SystemIndicatorManager() { |
132 DCHECK(thread_checker_.CalledOnValidThread()); | 134 DCHECK(thread_checker_.CalledOnValidThread()); |
133 } | 135 } |
134 | 136 |
135 void SystemIndicatorManager::Shutdown() { | 137 void SystemIndicatorManager::Shutdown() { |
136 DCHECK(thread_checker_.CalledOnValidThread()); | 138 DCHECK(thread_checker_.CalledOnValidThread()); |
137 } | 139 } |
138 | 140 |
141 void SystemIndicatorManager::OnExtensionUnloaded( | |
142 content::BrowserContext* browser_context, | |
143 const Extension* extension, | |
144 UnloadedExtensionInfo::Reason reason) { | |
145 RemoveIndicator(extension->id()); | |
146 } | |
147 | |
139 void SystemIndicatorManager::Observe( | 148 void SystemIndicatorManager::Observe( |
140 int type, | 149 int type, |
141 const content::NotificationSource& source, | 150 const content::NotificationSource& source, |
142 const content::NotificationDetails& details) { | 151 const content::NotificationDetails& details) { |
143 DCHECK(thread_checker_.CalledOnValidThread()); | 152 DCHECK(thread_checker_.CalledOnValidThread()); |
153 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED); | |
144 | 154 |
145 switch (type) { | 155 OnSystemIndicatorChanged(content::Details<ExtensionAction>(details).ptr()); |
146 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: | |
147 RemoveIndicator( | |
148 content::Details<UnloadedExtensionInfo>(details)->extension->id()); | |
149 break; | |
150 case chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED: | |
151 OnSystemIndicatorChanged( | |
152 content::Details<ExtensionAction>(details).ptr()); | |
153 break; | |
154 default: | |
155 NOTREACHED(); | |
156 break; | |
157 } | |
158 } | 156 } |
159 | 157 |
160 void SystemIndicatorManager::OnSystemIndicatorChanged( | 158 void SystemIndicatorManager::OnSystemIndicatorChanged( |
161 const ExtensionAction* extension_action) { | 159 const ExtensionAction* extension_action) { |
162 DCHECK(thread_checker_.CalledOnValidThread()); | 160 DCHECK(thread_checker_.CalledOnValidThread()); |
163 std::string extension_id = extension_action->extension_id(); | 161 std::string extension_id = extension_action->extension_id(); |
164 ExtensionService* service = | 162 ExtensionService* service = |
165 ExtensionSystem::Get(profile_)->extension_service(); | 163 ExtensionSystem::Get(profile_)->extension_service(); |
166 | 164 |
167 if (extension_action->GetIsVisible(ExtensionAction::kDefaultTabId)) { | 165 if (extension_action->GetIsVisible(ExtensionAction::kDefaultTabId)) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 if (extension_icon) | 199 if (extension_icon) |
202 system_indicators_[extension->id()] = make_linked_ptr(extension_icon); | 200 system_indicators_[extension->id()] = make_linked_ptr(extension_icon); |
203 } | 201 } |
204 | 202 |
205 void SystemIndicatorManager::RemoveIndicator(const std::string& extension_id) { | 203 void SystemIndicatorManager::RemoveIndicator(const std::string& extension_id) { |
206 DCHECK(thread_checker_.CalledOnValidThread()); | 204 DCHECK(thread_checker_.CalledOnValidThread()); |
207 system_indicators_.erase(extension_id); | 205 system_indicators_.erase(extension_id); |
208 } | 206 } |
209 | 207 |
210 } // namespace extensions | 208 } // namespace extensions |
OLD | NEW |