| 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/extensions/extension_action.h" | 9 #include "chrome/browser/extensions/extension_action.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 namespace system_indicator = api::system_indicator; | 23 namespace system_indicator = api::system_indicator; |
| 24 | 24 |
| 25 // Observes clicks on a given status icon and forwards the event to the | 25 // Observes clicks on a given status icon and forwards the event to the |
| 26 // appropriate extension. Handles icon updates, and responsible for creating | 26 // appropriate extension. Handles icon updates, and responsible for creating |
| 27 // and removing the icon from the notification area during construction and | 27 // and removing the icon from the notification area during construction and |
| 28 // destruction. | 28 // destruction. |
| 29 class ExtensionIndicatorIcon : public StatusIconObserver, | 29 class ExtensionIndicatorIcon : public StatusIconObserver, |
| 30 public ExtensionActionIconFactory::Observer { | 30 public ExtensionActionIconFactory::Observer { |
| 31 public: | 31 public: |
| 32 static ExtensionIndicatorIcon* Create(const Extension* extension, | 32 static ExtensionIndicatorIcon* Create(const Extension* extension, |
| 33 const ExtensionAction* action, | 33 ExtensionAction* action, |
| 34 Profile* profile, | 34 Profile* profile, |
| 35 StatusTray* status_tray); | 35 StatusTray* status_tray); |
| 36 ~ExtensionIndicatorIcon() override; | 36 ~ExtensionIndicatorIcon() override; |
| 37 | 37 |
| 38 // StatusIconObserver implementation. | 38 // StatusIconObserver implementation. |
| 39 void OnStatusIconClicked() override; | 39 void OnStatusIconClicked() override; |
| 40 | 40 |
| 41 // ExtensionActionIconFactory::Observer implementation. | 41 // ExtensionActionIconFactory::Observer implementation. |
| 42 void OnIconUpdated() override; | 42 void OnIconUpdated() override; |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 ExtensionIndicatorIcon(const Extension* extension, | 45 ExtensionIndicatorIcon(const Extension* extension, |
| 46 const ExtensionAction* action, | 46 ExtensionAction* action, |
| 47 Profile* profile, | 47 Profile* profile, |
| 48 StatusTray* status_tray); | 48 StatusTray* status_tray); |
| 49 | 49 |
| 50 const extensions::Extension* extension_; | 50 const extensions::Extension* extension_; |
| 51 StatusTray* status_tray_; | 51 StatusTray* status_tray_; |
| 52 StatusIcon* icon_; | 52 StatusIcon* icon_; |
| 53 Profile* profile_; | 53 Profile* profile_; |
| 54 ExtensionActionIconFactory icon_factory_; | 54 ExtensionActionIconFactory icon_factory_; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 ExtensionIndicatorIcon* ExtensionIndicatorIcon::Create( | 57 ExtensionIndicatorIcon* ExtensionIndicatorIcon::Create( |
| 58 const Extension* extension, | 58 const Extension* extension, |
| 59 const ExtensionAction* action, | 59 ExtensionAction* action, |
| 60 Profile* profile, | 60 Profile* profile, |
| 61 StatusTray* status_tray) { | 61 StatusTray* status_tray) { |
| 62 scoped_ptr<ExtensionIndicatorIcon> extension_icon( | 62 scoped_ptr<ExtensionIndicatorIcon> extension_icon( |
| 63 new ExtensionIndicatorIcon(extension, action, profile, status_tray)); | 63 new ExtensionIndicatorIcon(extension, action, profile, status_tray)); |
| 64 | 64 |
| 65 // Check if a status icon was successfully created. | 65 // Check if a status icon was successfully created. |
| 66 if (extension_icon->icon_) | 66 if (extension_icon->icon_) |
| 67 return extension_icon.release(); | 67 return extension_icon.release(); |
| 68 | 68 |
| 69 // We could not create a status icon. | 69 // We could not create a status icon. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 89 event_router->DispatchEventToExtension( | 89 event_router->DispatchEventToExtension( |
| 90 extension_->id(), event.Pass()); | 90 extension_->id(), event.Pass()); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void ExtensionIndicatorIcon::OnIconUpdated() { | 93 void ExtensionIndicatorIcon::OnIconUpdated() { |
| 94 icon_->SetImage( | 94 icon_->SetImage( |
| 95 icon_factory_.GetIcon(ExtensionAction::kDefaultTabId).AsImageSkia()); | 95 icon_factory_.GetIcon(ExtensionAction::kDefaultTabId).AsImageSkia()); |
| 96 } | 96 } |
| 97 | 97 |
| 98 ExtensionIndicatorIcon::ExtensionIndicatorIcon(const Extension* extension, | 98 ExtensionIndicatorIcon::ExtensionIndicatorIcon(const Extension* extension, |
| 99 const ExtensionAction* action, | 99 ExtensionAction* action, |
| 100 Profile* profile, | 100 Profile* profile, |
| 101 StatusTray* status_tray) | 101 StatusTray* status_tray) |
| 102 : extension_(extension), | 102 : extension_(extension), |
| 103 status_tray_(status_tray), | 103 status_tray_(status_tray), |
| 104 icon_(NULL), | 104 icon_(NULL), |
| 105 profile_(profile), | 105 profile_(profile), |
| 106 icon_factory_(profile, extension, action, this) { | 106 icon_factory_(profile, extension, action, this) { |
| 107 // Get the icon image and tool tip for the status icon. The extension name is | 107 // Get the icon image and tool tip for the status icon. The extension name is |
| 108 // used as the tool tip. | 108 // used as the tool tip. |
| 109 gfx::ImageSkia icon_image = | 109 gfx::ImageSkia icon_image = |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 169 |
| 170 if (it == system_indicators_.end()) | 170 if (it == system_indicators_.end()) |
| 171 return false; | 171 return false; |
| 172 | 172 |
| 173 it->second->OnStatusIconClicked(); | 173 it->second->OnStatusIconClicked(); |
| 174 return true; | 174 return true; |
| 175 } | 175 } |
| 176 | 176 |
| 177 void SystemIndicatorManager::CreateOrUpdateIndicator( | 177 void SystemIndicatorManager::CreateOrUpdateIndicator( |
| 178 const Extension* extension, | 178 const Extension* extension, |
| 179 const ExtensionAction* extension_action) { | 179 ExtensionAction* extension_action) { |
| 180 DCHECK(thread_checker_.CalledOnValidThread()); | 180 DCHECK(thread_checker_.CalledOnValidThread()); |
| 181 SystemIndicatorMap::iterator it = system_indicators_.find(extension->id()); | 181 SystemIndicatorMap::iterator it = system_indicators_.find(extension->id()); |
| 182 if (it != system_indicators_.end()) { | 182 if (it != system_indicators_.end()) { |
| 183 it->second->OnIconUpdated(); | 183 it->second->OnIconUpdated(); |
| 184 return; | 184 return; |
| 185 } | 185 } |
| 186 | 186 |
| 187 ExtensionIndicatorIcon* extension_icon = ExtensionIndicatorIcon::Create( | 187 ExtensionIndicatorIcon* extension_icon = ExtensionIndicatorIcon::Create( |
| 188 extension, extension_action, profile_, status_tray_); | 188 extension, extension_action, profile_, status_tray_); |
| 189 if (extension_icon) | 189 if (extension_icon) |
| 190 system_indicators_[extension->id()] = make_linked_ptr(extension_icon); | 190 system_indicators_[extension->id()] = make_linked_ptr(extension_icon); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void SystemIndicatorManager::RemoveIndicator(const std::string& extension_id) { | 193 void SystemIndicatorManager::RemoveIndicator(const std::string& extension_id) { |
| 194 DCHECK(thread_checker_.CalledOnValidThread()); | 194 DCHECK(thread_checker_.CalledOnValidThread()); |
| 195 system_indicators_.erase(extension_id); | 195 system_indicators_.erase(extension_id); |
| 196 } | 196 } |
| 197 | 197 |
| 198 } // namespace extensions | 198 } // namespace extensions |
| OLD | NEW |