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

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: Latest master 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
« no previous file with comments | « chrome/browser/extensions/extension_action.h ('k') | chrome/browser/extensions/state_store.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 color_utils::HSL shift = {-1, 0, 0.5}; 43 color_utils::HSL shift = {-1, 0, 0.5};
44 return gfx::ImageSkiaRep( 44 return gfx::ImageSkiaRep(
45 SkBitmapOperations::CreateHSLShiftedBitmap(icon_rep.sk_bitmap(), shift), 45 SkBitmapOperations::CreateHSLShiftedBitmap(icon_rep.sk_bitmap(), shift),
46 icon_rep.scale()); 46 icon_rep.scale());
47 } 47 }
48 48
49 private: 49 private:
50 const gfx::ImageSkia icon_; 50 const gfx::ImageSkia icon_;
51 }; 51 };
52 52
53 template <class T>
54 bool HasValue(const std::map<int, T>& map, int tab_id) {
55 return map.find(tab_id) != map.end();
56 }
57
53 } // namespace 58 } // namespace
54 59
55 const int ExtensionAction::kDefaultTabId = -1; 60 const int ExtensionAction::kDefaultTabId = -1;
56 61
57 ExtensionAction::ExtensionAction( 62 ExtensionAction::ExtensionAction(const std::string& extension_id,
58 const std::string& extension_id, 63 extensions::ActionInfo::Type action_type,
59 extensions::ActionInfo::Type action_type, 64 const extensions::ActionInfo& manifest_data)
60 const extensions::ActionInfo& manifest_data) 65 : extension_id_(extension_id), action_type_(action_type) {
61 : extension_id_(extension_id),
62 action_type_(action_type),
63 has_changed_(false) {
64 // Page/script actions are hidden/disabled by default, and browser actions are 66 // Page/script actions are hidden/disabled by default, and browser actions are
65 // visible/enabled by default. 67 // visible/enabled by default.
66 SetIsVisible(kDefaultTabId, 68 SetIsVisible(kDefaultTabId,
67 action_type == extensions::ActionInfo::TYPE_BROWSER); 69 action_type == extensions::ActionInfo::TYPE_BROWSER);
68 SetTitle(kDefaultTabId, manifest_data.default_title); 70 SetTitle(kDefaultTabId, manifest_data.default_title);
69 SetPopupUrl(kDefaultTabId, manifest_data.default_popup_url); 71 SetPopupUrl(kDefaultTabId, manifest_data.default_popup_url);
70 if (!manifest_data.default_icon.empty()) { 72 if (!manifest_data.default_icon.empty()) {
71 set_default_icon(make_scoped_ptr(new ExtensionIconSet( 73 set_default_icon(make_scoped_ptr(new ExtensionIconSet(
72 manifest_data.default_icon))); 74 manifest_data.default_icon)));
73 } 75 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 new IconWithBadgeImageSource(icon, 200 new IconWithBadgeImageSource(icon,
199 icon.size(), 201 icon.size(),
200 spacing, 202 spacing,
201 GetBadgeText(tab_id), 203 GetBadgeText(tab_id),
202 GetBadgeTextColor(tab_id), 204 GetBadgeTextColor(tab_id),
203 GetBadgeBackgroundColor(tab_id), 205 GetBadgeBackgroundColor(tab_id),
204 action_type()), 206 action_type()),
205 icon.size()); 207 icon.size());
206 } 208 }
207 209
210 bool ExtensionAction::HasPopupUrl(int tab_id) const {
211 return HasValue(popup_url_, tab_id);
212 }
213
214 bool ExtensionAction::HasTitle(int tab_id) const {
215 return HasValue(title_, tab_id);
216 }
217
218 bool ExtensionAction::HasBadgeText(int tab_id) const {
219 return HasValue(badge_text_, tab_id);
220 }
221
222 bool ExtensionAction::HasBadgeBackgroundColor(int tab_id) const {
223 return HasValue(badge_background_color_, tab_id);
224 }
225
226 bool ExtensionAction::HasBadgeTextColor(int tab_id) const {
227 return HasValue(badge_text_color_, tab_id);
228 }
229
230 bool ExtensionAction::HasIsVisible(int tab_id) const {
231 return HasValue(is_visible_, tab_id);
232 }
233
234 bool ExtensionAction::HasIcon(int tab_id) const {
235 return HasValue(icon_, tab_id);
236 }
237
208 // Determines which icon would be returned by |GetIcon|, and returns its width. 238 // Determines which icon would be returned by |GetIcon|, and returns its width.
209 int ExtensionAction::GetIconWidth(int tab_id) const { 239 int ExtensionAction::GetIconWidth(int tab_id) const {
210 // If icon has been set, return its width. 240 // If icon has been set, return its width.
211 gfx::ImageSkia icon = GetValue(&icon_, tab_id); 241 gfx::ImageSkia icon = GetValue(&icon_, tab_id);
212 if (!icon.isNull()) 242 if (!icon.isNull())
213 return icon.width(); 243 return icon.width();
214 // If there is a default icon, the icon width will be set depending on our 244 // If there is a default icon, the icon width will be set depending on our
215 // action type. 245 // action type.
216 if (default_icon_) 246 if (default_icon_)
217 return GetIconSizeForType(action_type()); 247 return GetIconSizeForType(action_type());
218 248
219 // If no icon has been set and there is no default icon, we need favicon 249 // If no icon has been set and there is no default icon, we need favicon
220 // width. 250 // width.
221 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( 251 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
222 IDR_EXTENSIONS_FAVICON).ToImageSkia()->width(); 252 IDR_EXTENSIONS_FAVICON).ToImageSkia()->width();
223 } 253 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_action.h ('k') | chrome/browser/extensions/state_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698