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

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: Latest Master for CQ 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 26 matching lines...) Expand all
37 37
38 const char kBrowserActionStorageKey[] = "browser_action"; 38 const char kBrowserActionStorageKey[] = "browser_action";
39 const char kPopupUrlStorageKey[] = "poupup_url"; 39 const char kPopupUrlStorageKey[] = "poupup_url";
40 const char kTitleStorageKey[] = "title"; 40 const char kTitleStorageKey[] = "title";
41 const char kIconStorageKey[] = "icon"; 41 const char kIconStorageKey[] = "icon";
42 const char kBadgeTextStorageKey[] = "badge_text"; 42 const char kBadgeTextStorageKey[] = "badge_text";
43 const char kBadgeBackgroundColorStorageKey[] = "badge_background_color"; 43 const char kBadgeBackgroundColorStorageKey[] = "badge_background_color";
44 const char kBadgeTextColorStorageKey[] = "badge_text_color"; 44 const char kBadgeTextColorStorageKey[] = "badge_text_color";
45 const char kAppearanceStorageKey[] = "appearance"; 45 const char kAppearanceStorageKey[] = "appearance";
46 46
47 // Whether the browser action is visible in the toolbar.
48 const char kBrowserActionVisible[] = "browser_action_visible";
49
47 // Errors. 50 // Errors.
48 const char kNoExtensionActionError[] = 51 const char kNoExtensionActionError[] =
49 "This extension has no action specified."; 52 "This extension has no action specified.";
50 const char kNoTabError[] = "No tab with id: *."; 53 const char kNoTabError[] = "No tab with id: *.";
51 const char kNoPageActionError[] = 54 const char kNoPageActionError[] =
52 "This extension has no page action specified."; 55 "This extension has no page action specified.";
53 const char kUrlNotActiveError[] = "This url is no longer active: *."; 56 const char kUrlNotActiveError[] = "This url is no longer active: *.";
54 57
55 struct IconRepresentationInfo { 58 struct IconRepresentationInfo {
56 // Size as a string that will be used to retrieve representation value from 59 // Size as a string that will be used to retrieve representation value from
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 223
221 ExtensionActionAPI::~ExtensionActionAPI() { 224 ExtensionActionAPI::~ExtensionActionAPI() {
222 } 225 }
223 226
224 // static 227 // static
225 ProfileKeyedAPIFactory<ExtensionActionAPI>* 228 ProfileKeyedAPIFactory<ExtensionActionAPI>*
226 ExtensionActionAPI::GetFactoryInstance() { 229 ExtensionActionAPI::GetFactoryInstance() {
227 return &g_factory.Get(); 230 return &g_factory.Get();
228 } 231 }
229 232
233 // static
234 bool ExtensionActionAPI::GetBrowserActionVisibility(
235 const ExtensionPrefs* prefs,
236 const std::string& extension_id) {
237 bool visible = false;
238 if (!prefs || !prefs->ReadPrefAsBoolean(extension_id,
239 kBrowserActionVisible,
240 &visible)) {
241 return true;
242 }
243 return visible;
244 }
245
246 // static
247 void ExtensionActionAPI::SetBrowserActionVisibility(
248 ExtensionPrefs* prefs,
249 const std::string& extension_id,
250 bool visible) {
251 if (GetBrowserActionVisibility(prefs, extension_id) == visible)
252 return;
253
254 prefs->UpdateExtensionPref(extension_id,
255 kBrowserActionVisible,
256 Value::CreateBooleanValue(visible));
257 content::NotificationService::current()->Notify(
258 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
259 content::Source<ExtensionPrefs>(prefs),
260 content::Details<const std::string>(&extension_id));
261 }
262
230 // 263 //
231 // ExtensionActionStorageManager 264 // ExtensionActionStorageManager
232 // 265 //
233 266
234 ExtensionActionStorageManager::ExtensionActionStorageManager(Profile* profile) 267 ExtensionActionStorageManager::ExtensionActionStorageManager(Profile* profile)
235 : profile_(profile) { 268 : profile_(profile) {
236 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 269 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
237 content::Source<Profile>(profile_)); 270 content::Source<Profile>(profile_));
238 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, 271 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED,
239 content::NotificationService::AllBrowserContextsAndSources()); 272 content::NotificationService::AllBrowserContextsAndSources());
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 return true; 759 return true;
727 } 760 }
728 761
729 bool EnablePageActionsFunction::RunImpl() { 762 bool EnablePageActionsFunction::RunImpl() {
730 return SetPageActionEnabled(true); 763 return SetPageActionEnabled(true);
731 } 764 }
732 765
733 bool DisablePageActionsFunction::RunImpl() { 766 bool DisablePageActionsFunction::RunImpl() {
734 return SetPageActionEnabled(false); 767 return SetPageActionEnabled(false);
735 } 768 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698