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

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

Issue 14699002: Move BrowserAction references from ExtensionPrefs to ExtensionActionAPI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 7 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/api/extension_action/extension_action_api.h" 5 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 29 matching lines...) Expand all
40 40
41 const char kBrowserActionStorageKey[] = "browser_action"; 41 const char kBrowserActionStorageKey[] = "browser_action";
42 const char kPopupUrlStorageKey[] = "poupup_url"; 42 const char kPopupUrlStorageKey[] = "poupup_url";
43 const char kTitleStorageKey[] = "title"; 43 const char kTitleStorageKey[] = "title";
44 const char kIconStorageKey[] = "icon"; 44 const char kIconStorageKey[] = "icon";
45 const char kBadgeTextStorageKey[] = "badge_text"; 45 const char kBadgeTextStorageKey[] = "badge_text";
46 const char kBadgeBackgroundColorStorageKey[] = "badge_background_color"; 46 const char kBadgeBackgroundColorStorageKey[] = "badge_background_color";
47 const char kBadgeTextColorStorageKey[] = "badge_text_color"; 47 const char kBadgeTextColorStorageKey[] = "badge_text_color";
48 const char kAppearanceStorageKey[] = "appearance"; 48 const char kAppearanceStorageKey[] = "appearance";
49 49
50 // Whether the browser action is visible in the toolbar.
51 const char kBrowserActionVisible[] = "browser_action_visible";
52
50 // Errors. 53 // Errors.
51 const char kNoExtensionActionError[] = 54 const char kNoExtensionActionError[] =
52 "This extension has no action specified."; 55 "This extension has no action specified.";
53 const char kNoTabError[] = "No tab with id: *."; 56 const char kNoTabError[] = "No tab with id: *.";
54 const char kNoPageActionError[] = 57 const char kNoPageActionError[] =
55 "This extension has no page action specified."; 58 "This extension has no page action specified.";
56 const char kUrlNotActiveError[] = "This url is no longer active: *."; 59 const char kUrlNotActiveError[] = "This url is no longer active: *.";
57 60
58 struct IconRepresentationInfo { 61 struct IconRepresentationInfo {
59 // Size as a string that will be used to retrieve representation value from 62 // Size as a string that will be used to retrieve representation value from
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 230
228 ExtensionActionAPI::~ExtensionActionAPI() { 231 ExtensionActionAPI::~ExtensionActionAPI() {
229 } 232 }
230 233
231 // static 234 // static
232 ProfileKeyedAPIFactory<ExtensionActionAPI>* 235 ProfileKeyedAPIFactory<ExtensionActionAPI>*
233 ExtensionActionAPI::GetFactoryInstance() { 236 ExtensionActionAPI::GetFactoryInstance() {
234 return &g_factory.Get(); 237 return &g_factory.Get();
235 } 238 }
236 239
240 // static
241 bool ExtensionActionAPI::GetBrowserActionVisibility(
242 const ExtensionPrefs* prefs,
243 const std::string& extension_id) {
244 bool visible = false;
245 if (!prefs || !prefs->ReadPrefAsBoolean(extension_id,
246 kBrowserActionVisible,
247 &visible)) {
248 return true;
249 }
250 return visible;
251 }
252
253 // static
254 void ExtensionActionAPI::SetBrowserActionVisibility(
255 ExtensionPrefs* prefs,
256 const std::string& extension_id,
257 bool visible) {
258 if (GetBrowserActionVisibility(prefs, extension_id) == visible)
259 return;
260
261 prefs->UpdateExtensionPref(extension_id,
262 kBrowserActionVisible,
263 Value::CreateBooleanValue(visible));
264 content::NotificationService::current()->Notify(
265 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
266 content::Source<ExtensionPrefs>(prefs),
267 content::Details<const std::string>(&extension_id));
268 }
269
237 // 270 //
238 // ExtensionActionStorageManager 271 // ExtensionActionStorageManager
239 // 272 //
240 273
241 ExtensionActionStorageManager::ExtensionActionStorageManager(Profile* profile) 274 ExtensionActionStorageManager::ExtensionActionStorageManager(Profile* profile)
242 : profile_(profile) { 275 : profile_(profile) {
243 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 276 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
244 content::Source<Profile>(profile_)); 277 content::Source<Profile>(profile_));
245 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, 278 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED,
246 content::NotificationService::AllBrowserContextsAndSources()); 279 content::NotificationService::AllBrowserContextsAndSources());
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 return true; 766 return true;
734 } 767 }
735 768
736 bool EnablePageActionsFunction::RunImpl() { 769 bool EnablePageActionsFunction::RunImpl() {
737 return SetPageActionEnabled(true); 770 return SetPageActionEnabled(true);
738 } 771 }
739 772
740 bool DisablePageActionsFunction::RunImpl() { 773 bool DisablePageActionsFunction::RunImpl() {
741 return SetPageActionEnabled(false); 774 return SetPageActionEnabled(false);
742 } 775 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698