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

Side by Side Diff: chrome/common/extensions/extension_action.h

Issue 10914244: Remove support for page_action.icons, and the legacy code surrounding it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: constants removed Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | chrome/common/extensions/extension_action.cc » ('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 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // extension id 126 // extension id
127 const std::string& extension_id() const { return extension_id_; } 127 const std::string& extension_id() const { return extension_id_; }
128 128
129 // What kind of action is this? 129 // What kind of action is this?
130 Type action_type() const { return action_type_; } 130 Type action_type() const { return action_type_; }
131 131
132 // action id -- only used with legacy page actions API 132 // action id -- only used with legacy page actions API
133 std::string id() const { return id_; } 133 std::string id() const { return id_; }
134 void set_id(const std::string& id) { id_ = id; } 134 void set_id(const std::string& id) { id_ = id; }
135 135
136 // static icon paths from manifest -- only used with legacy page actions API.
137 std::vector<std::string>* icon_paths() { return &icon_paths_; }
138 const std::vector<std::string>* icon_paths() const { return &icon_paths_; }
139
140 bool has_changed() const { return has_changed_; } 136 bool has_changed() const { return has_changed_; }
141 void set_has_changed(bool value) { has_changed_ = value; } 137 void set_has_changed(bool value) { has_changed_ = value; }
142 138
143 // Set the url which the popup will load when the user clicks this action's 139 // Set the url which the popup will load when the user clicks this action's
144 // icon. Setting an empty URL will disable the popup for a given tab. 140 // icon. Setting an empty URL will disable the popup for a given tab.
145 void SetPopupUrl(int tab_id, const GURL& url); 141 void SetPopupUrl(int tab_id, const GURL& url);
146 142
147 // Use HasPopup() to see if a popup should be displayed. 143 // Use HasPopup() to see if a popup should be displayed.
148 bool HasPopup(int tab_id) const; 144 bool HasPopup(int tab_id) const;
149 145
150 // Get the URL to display in a popup. 146 // Get the URL to display in a popup.
151 GURL GetPopupUrl(int tab_id) const; 147 GURL GetPopupUrl(int tab_id) const;
152 148
153 // Set this action's title on a specific tab. 149 // Set this action's title on a specific tab.
154 void SetTitle(int tab_id, const std::string& title) { 150 void SetTitle(int tab_id, const std::string& title) {
155 SetValue(&title_, tab_id, title); 151 SetValue(&title_, tab_id, title);
156 } 152 }
157 153
158 // If tab |tab_id| has a set title, return it. Otherwise, return 154 // If tab |tab_id| has a set title, return it. Otherwise, return
159 // the default title. 155 // the default title.
160 std::string GetTitle(int tab_id) const { return GetValue(&title_, tab_id); } 156 std::string GetTitle(int tab_id) const { return GetValue(&title_, tab_id); }
161 157
162 // Icons are a bit different because the default value can be set to either a 158 // Icons are a bit different because the default value can be set to either a
163 // bitmap or a path. However, conceptually, there is only one default icon. 159 // bitmap or a path. However, conceptually, there is only one default icon.
164 // Setting the default icon using a path clears the bitmap and vice-versa. 160 // Setting the default icon using a path clears the bitmap and vice-versa.
165 161
166 // Since ExtensionAction, living in common/, can't interact with the browser 162 // Since ExtensionAction, living in common/, can't interact with the browser
167 // to load images, the UI code needs to load the images for each path. For 163 // to load images, the UI code needs to load the icon. Load the image there
168 // each path in default_icon_path() and icon_paths(), load the image there 164 // using an ImageLoadingTracker and call CacheIcon(image) with the result.
169 // using an ImageLoadingTracker and call CacheIcon(path, image) with the
170 // result.
171 // 165 //
172 // If an image is cached redundantly, the first load will be used. 166 // If an image is cached redundantly, the first load will be used.
173 void CacheIcon(const std::string& path, const gfx::Image& icon); 167 void CacheIcon(const gfx::Image& icon);
174 168
175 // Set this action's icon bitmap on a specific tab. 169 // Set this action's icon bitmap on a specific tab.
176 void SetIcon(int tab_id, const gfx::Image& image); 170 void SetIcon(int tab_id, const gfx::Image& image);
177 171
178 // Get the icon for a tab, or the default if no icon was set for this tab, 172 // Get the icon for a tab, or the default if no icon was set for this tab,
179 // retrieving icons that have been specified by path from the previous 173 // retrieving icons that have been specified by path from the previous
180 // arguments to CacheIcon(). If the default icon isn't found in the cache, 174 // arguments to CacheIcon(). If the default icon isn't found in the cache,
181 // returns the puzzle piece icon. 175 // returns the puzzle piece icon.
182 gfx::Image GetIcon(int tab_id) const; 176 gfx::Image GetIcon(int tab_id) const;
183 177
184 // Gets the icon that has been set using |SetIcon| for the tab. 178 // Gets the icon that has been set using |SetIcon| for the tab.
185 gfx::ImageSkia GetExplicitlySetIcon(int tab_id) const; 179 gfx::ImageSkia GetExplicitlySetIcon(int tab_id) const;
186 180
187 // Set this action's icon index for a specific tab. For use with
188 // icon_paths(), only used in page actions.
189 void SetIconIndex(int tab_id, int index);
190
191 // Get this action's icon index for a tab, or the default if no icon index
192 // was set.
193 int GetIconIndex(int tab_id) const {
194 return GetValue(&icon_index_, tab_id);
195 }
196
197 // Non-tab-specific icon path. This is used to support the default_icon key of 181 // Non-tab-specific icon path. This is used to support the default_icon key of
198 // page and browser actions. 182 // page and browser actions.
199 void set_default_icon_path(const std::string& path) { 183 void set_default_icon_path(const std::string& path) {
200 default_icon_path_ = path; 184 default_icon_path_ = path;
201 } 185 }
202 const std::string& default_icon_path() const { 186 const std::string& default_icon_path() const {
203 return default_icon_path_; 187 return default_icon_path_;
204 } 188 }
205 189
206 // Set this action's badge text on a specific tab. 190 // Set this action's badge text on a specific tab.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 // extension manifest). 287 // extension manifest).
304 const std::string extension_id_; 288 const std::string extension_id_;
305 289
306 const Type action_type_; 290 const Type action_type_;
307 291
308 // Each of these data items can have both a global state (stored with the key 292 // Each of these data items can have both a global state (stored with the key
309 // kDefaultTabId), or tab-specific state (stored with the tab_id as the key). 293 // kDefaultTabId), or tab-specific state (stored with the tab_id as the key).
310 std::map<int, GURL> popup_url_; 294 std::map<int, GURL> popup_url_;
311 std::map<int, std::string> title_; 295 std::map<int, std::string> title_;
312 std::map<int, gfx::ImageSkia> icon_; 296 std::map<int, gfx::ImageSkia> icon_;
313 std::map<int, int> icon_index_; // index into icon_paths_
314 std::map<int, std::string> badge_text_; 297 std::map<int, std::string> badge_text_;
315 std::map<int, SkColor> badge_background_color_; 298 std::map<int, SkColor> badge_background_color_;
316 std::map<int, SkColor> badge_text_color_; 299 std::map<int, SkColor> badge_text_color_;
317 std::map<int, Appearance> appearance_; 300 std::map<int, Appearance> appearance_;
318 301
319 // IconAnimations are destroyed by a delayed task on the UI message loop so 302 // IconAnimations are destroyed by a delayed task on the UI message loop so
320 // that even if the Extension and ExtensionAction are destroyed on a non-UI 303 // that even if the Extension and ExtensionAction are destroyed on a non-UI
321 // thread, the animation will still only be touched from the UI thread. This 304 // thread, the animation will still only be touched from the UI thread. This
322 // causes the WeakPtr in this map to become NULL. GetIconAnimation() removes 305 // causes the WeakPtr in this map to become NULL. GetIconAnimation() removes
323 // NULLs to prevent the map from growing without bound. 306 // NULLs to prevent the map from growing without bound.
324 mutable std::map<int, base::WeakPtr<IconAnimation> > icon_animation_; 307 mutable std::map<int, base::WeakPtr<IconAnimation> > icon_animation_;
325 308
326 std::string default_icon_path_; 309 std::string default_icon_path_;
327 310
328 // The id for the ExtensionAction, for example: "RssPageAction". This is 311 // The id for the ExtensionAction, for example: "RssPageAction". This is
329 // needed for compat with an older version of the page actions API. 312 // needed for compat with an older version of the page actions API.
330 std::string id_; 313 std::string id_;
331 314
332 // A list of paths to icons this action might show. This is needed to support
333 // the legacy setIcon({iconIndex:...} method of the page actions API.
334 std::vector<std::string> icon_paths_;
335
336 // Saves the arguments from CacheIcon() calls. 315 // Saves the arguments from CacheIcon() calls.
337 std::map<std::string, gfx::ImageSkia> path_to_icon_cache_; 316 scoped_ptr<gfx::ImageSkia> cached_icon_;
338 317
339 // True if the ExtensionAction's settings have changed from what was 318 // True if the ExtensionAction's settings have changed from what was
340 // specified in the manifest. 319 // specified in the manifest.
341 bool has_changed_; 320 bool has_changed_;
342 321
343 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); 322 DISALLOW_COPY_AND_ASSIGN(ExtensionAction);
344 }; 323 };
345 324
346 template<> 325 template<>
347 struct ExtensionAction::ValueTraits<int> { 326 struct ExtensionAction::ValueTraits<int> {
348 static int CreateEmpty() { 327 static int CreateEmpty() {
349 return -1; 328 return -1;
350 } 329 }
351 }; 330 };
352 331
353 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ 332 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | chrome/common/extensions/extension_action.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698