Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: chrome/browser/extensions/extension_action.cc

Issue 186013003: Persist browseraction properties across restarts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove reliance on ID Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/extension_action.h" 5 #include "chrome/browser/extensions/extension_action.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 color_utils::HSL shift = {-1, 0, 0.5}; 44 color_utils::HSL shift = {-1, 0, 0.5};
45 return gfx::ImageSkiaRep( 45 return gfx::ImageSkiaRep(
46 SkBitmapOperations::CreateHSLShiftedBitmap(icon_rep.sk_bitmap(), shift), 46 SkBitmapOperations::CreateHSLShiftedBitmap(icon_rep.sk_bitmap(), shift),
47 icon_rep.scale()); 47 icon_rep.scale());
48 } 48 }
49 49
50 private: 50 private:
51 const gfx::ImageSkia icon_; 51 const gfx::ImageSkia icon_;
52 }; 52 };
53 53
54 template <class T>
55 bool HasDefaultValue(const std::map<int, T>& map) {
56 return map.find(ExtensionAction::kDefaultTabId) != map.end();
57 }
58
54 } // namespace 59 } // namespace
55 60
56 const int ExtensionAction::kDefaultTabId = -1; 61 const int ExtensionAction::kDefaultTabId = -1;
57 62
58 ExtensionAction::ExtensionAction( 63 ExtensionAction::ExtensionAction(const std::string& extension_id,
59 const std::string& extension_id, 64 extensions::ActionInfo::Type action_type,
60 extensions::ActionInfo::Type action_type, 65 const extensions::ActionInfo& manifest_data)
61 const extensions::ActionInfo& manifest_data) 66 : extension_id_(extension_id), action_type_(action_type) {
62 : extension_id_(extension_id),
63 action_type_(action_type),
64 has_changed_(false) {
65 // Page/script actions are hidden/disabled by default, and browser actions are 67 // Page/script actions are hidden/disabled by default, and browser actions are
66 // visible/enabled by default. 68 // visible/enabled by default.
67 SetIsVisible(kDefaultTabId, 69 SetIsVisible(kDefaultTabId,
68 action_type == extensions::ActionInfo::TYPE_BROWSER); 70 action_type == extensions::ActionInfo::TYPE_BROWSER);
69 SetTitle(kDefaultTabId, manifest_data.default_title); 71 SetTitle(kDefaultTabId, manifest_data.default_title);
70 SetPopupUrl(kDefaultTabId, manifest_data.default_popup_url); 72 SetPopupUrl(kDefaultTabId, manifest_data.default_popup_url);
71 if (!manifest_data.default_icon.empty()) { 73 if (!manifest_data.default_icon.empty()) {
72 set_default_icon(make_scoped_ptr(new ExtensionIconSet( 74 set_default_icon(make_scoped_ptr(new ExtensionIconSet(
73 manifest_data.default_icon))); 75 manifest_data.default_icon)));
74 } 76 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 new IconWithBadgeImageSource(icon, 201 new IconWithBadgeImageSource(icon,
200 icon.size(), 202 icon.size(),
201 spacing, 203 spacing,
202 GetBadgeText(tab_id), 204 GetBadgeText(tab_id),
203 GetBadgeTextColor(tab_id), 205 GetBadgeTextColor(tab_id),
204 GetBadgeBackgroundColor(tab_id), 206 GetBadgeBackgroundColor(tab_id),
205 action_type()), 207 action_type()),
206 icon.size()); 208 icon.size());
207 } 209 }
208 210
211 bool ExtensionAction::HasDefaultPopupUrl() const {
212 return HasDefaultValue(popup_url_);
213 }
214
215 bool ExtensionAction::HasDefaultTitle() const {
216 return HasDefaultValue(title_);
217 }
218
219 bool ExtensionAction::HasDefaultBadgeText() const {
220 return HasDefaultValue(badge_text_);
221 }
222
223 bool ExtensionAction::HasDefaultBadgeBackgroundColor() const {
224 return HasDefaultValue(badge_background_color_);
225 }
226
227 bool ExtensionAction::HasDefaultBadgeTextColor() const {
228 return HasDefaultValue(badge_text_color_);
229 }
230
231 bool ExtensionAction::HasDefaultIsVisible() const {
232 return HasDefaultValue(is_visible_);
233 }
234
235 bool ExtensionAction::HasDefaultIcon() const { return HasDefaultValue(icon_); }
236
209 // Determines which icon would be returned by |GetIcon|, and returns its width. 237 // Determines which icon would be returned by |GetIcon|, and returns its width.
210 int ExtensionAction::GetIconWidth(int tab_id) const { 238 int ExtensionAction::GetIconWidth(int tab_id) const {
211 // If icon has been set, return its width. 239 // If icon has been set, return its width.
212 gfx::ImageSkia icon = GetValue(&icon_, tab_id); 240 gfx::ImageSkia icon = GetValue(&icon_, tab_id);
213 if (!icon.isNull()) 241 if (!icon.isNull())
214 return icon.width(); 242 return icon.width();
215 // If there is a default icon, the icon width will be set depending on our 243 // If there is a default icon, the icon width will be set depending on our
216 // action type. 244 // action type.
217 if (default_icon_) 245 if (default_icon_)
218 return GetIconSizeForType(action_type()); 246 return GetIconSizeForType(action_type());
219 247
220 // If no icon has been set and there is no default icon, we need favicon 248 // If no icon has been set and there is no default icon, we need favicon
221 // width. 249 // width.
222 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( 250 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
223 IDR_EXTENSIONS_FAVICON).ToImageSkia()->width(); 251 IDR_EXTENSIONS_FAVICON).ToImageSkia()->width();
224 } 252 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698