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

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

Issue 7031063: Extension API: Rename contentSettings.misc to .global and rename preferences under it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 9 years, 6 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 | « no previous file | chrome/common/extensions/api/extension_api.json » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_preference_api.h" 5 #include "chrome/browser/extensions/extension_preference_api.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 const char kIncognitoSessionOnlyErrorMessage[] = 52 const char kIncognitoSessionOnlyErrorMessage[] =
53 "You cannot set a preference with scope 'incognito_session_only' when no " 53 "You cannot set a preference with scope 'incognito_session_only' when no "
54 "incognito window is open."; 54 "incognito window is open.";
55 55
56 const char kPermissionErrorMessage[] = 56 const char kPermissionErrorMessage[] =
57 "You do not have permission to access the preference '%s'. " 57 "You do not have permission to access the preference '%s'. "
58 "Be sure to declare in your manifest what permissions you need."; 58 "Be sure to declare in your manifest what permissions you need.";
59 59
60 PrefMappingEntry kPrefMapping[] = { 60 PrefMappingEntry kPrefMapping[] = {
61 { "blockThirdPartyCookies", 61 { "thirdPartyCookiesAllowed",
62 prefs::kBlockThirdPartyCookies, 62 prefs::kBlockThirdPartyCookies,
63 Extension::kContentSettingsPermission 63 Extension::kContentSettingsPermission
64 }, 64 },
65 { "enableReferrers", 65 { "referrersEnabled",
66 prefs::kEnableReferrers, 66 prefs::kEnableReferrers,
67 Extension::kContentSettingsPermission 67 Extension::kContentSettingsPermission
68 }, 68 },
69 { "enableHyperlinkAuditing", 69 { "hyperlinkAuditingEnabled",
70 prefs::kEnableHyperlinkAuditing, 70 prefs::kEnableHyperlinkAuditing,
71 Extension::kContentSettingsPermission 71 Extension::kContentSettingsPermission
72 }, 72 },
73 { "proxy", 73 { "proxy",
74 prefs::kProxy, 74 prefs::kProxy,
75 Extension::kProxyPermission 75 Extension::kProxyPermission
76 }, 76 },
77 }; 77 };
78 78
79 class IdentityPrefTransformer : public PrefTransformerInterface { 79 class IdentityPrefTransformer : public PrefTransformerInterface {
80 public: 80 public:
81 IdentityPrefTransformer() { }
82 virtual ~IdentityPrefTransformer() { }
83
84 virtual Value* ExtensionToBrowserPref(const Value* extension_pref, 81 virtual Value* ExtensionToBrowserPref(const Value* extension_pref,
85 std::string* error, 82 std::string* error,
86 bool* bad_message) { 83 bool* bad_message) {
87 return extension_pref->DeepCopy(); 84 return extension_pref->DeepCopy();
88 } 85 }
89 86
90 virtual Value* BrowserToExtensionPref(const Value* browser_pref) { 87 virtual Value* BrowserToExtensionPref(const Value* browser_pref) {
91 return browser_pref->DeepCopy(); 88 return browser_pref->DeepCopy();
92 } 89 }
93 }; 90 };
94 91
92 class InvertBooleanTransformer : public PrefTransformerInterface {
93 public:
94 virtual Value* ExtensionToBrowserPref(const Value* extension_pref,
95 std::string* error,
96 bool* bad_message) {
97 return InvertBooleanValue(extension_pref);
98 }
99
100 virtual Value* BrowserToExtensionPref(const Value* browser_pref) {
101 return InvertBooleanValue(browser_pref);
102 }
103
104 private:
105 static Value* InvertBooleanValue(const Value* value) {
106 bool bool_value = false;
107 bool result = value->GetAsBoolean(&bool_value);
108 DCHECK(result);
109 return Value::CreateBooleanValue(!bool_value);
110 }
111 };
112
95 // Returns a string constant (defined in the API) indicating the level of 113 // Returns a string constant (defined in the API) indicating the level of
96 // control this extension has over the specified preference. 114 // control this extension has over the specified preference.
97 const char* GetLevelOfControl( 115 const char* GetLevelOfControl(
98 Profile* profile, 116 Profile* profile,
99 const std::string& extension_id, 117 const std::string& extension_id,
100 const std::string& browser_pref, 118 const std::string& browser_pref,
101 bool incognito) { 119 bool incognito) {
102 PrefService* prefs = incognito ? profile->GetOffTheRecordPrefs() 120 PrefService* prefs = incognito ? profile->GetOffTheRecordPrefs()
103 : profile->GetPrefs(); 121 : profile->GetPrefs();
104 const PrefService::Preference* pref = 122 const PrefService::Preference* pref =
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 kPrefMapping[i].permission); 201 kPrefMapping[i].permission);
184 std::string event_name = 202 std::string event_name =
185 base::StringPrintf(kOnPrefChangeFormat, 203 base::StringPrintf(kOnPrefChangeFormat,
186 kPrefMapping[i].extension_pref); 204 kPrefMapping[i].extension_pref);
187 event_mapping_[kPrefMapping[i].browser_pref] = 205 event_mapping_[kPrefMapping[i].browser_pref] =
188 std::make_pair(event_name, kPrefMapping[i].permission); 206 std::make_pair(event_name, kPrefMapping[i].permission);
189 } 207 }
190 DCHECK_EQ(arraysize(kPrefMapping), mapping_.size()); 208 DCHECK_EQ(arraysize(kPrefMapping), mapping_.size());
191 DCHECK_EQ(arraysize(kPrefMapping), event_mapping_.size()); 209 DCHECK_EQ(arraysize(kPrefMapping), event_mapping_.size());
192 RegisterPrefTransformer(prefs::kProxy, new ProxyPrefTransformer()); 210 RegisterPrefTransformer(prefs::kProxy, new ProxyPrefTransformer());
211 RegisterPrefTransformer(prefs::kBlockThirdPartyCookies,
212 new InvertBooleanTransformer());
193 } 213 }
194 214
195 ~PrefMapping() { 215 ~PrefMapping() {
196 STLDeleteContainerPairSecondPointers(transformers_.begin(), 216 STLDeleteContainerPairSecondPointers(transformers_.begin(),
197 transformers_.end()); 217 transformers_.end());
198 } 218 }
199 219
200 void RegisterPrefTransformer(const std::string& browser_pref, 220 void RegisterPrefTransformer(const std::string& browser_pref,
201 PrefTransformerInterface* transformer) { 221 PrefTransformerInterface* transformer) {
202 DCHECK_EQ(0u, transformers_.count(browser_pref)) << 222 DCHECK_EQ(0u, transformers_.count(browser_pref)) <<
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref( 490 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref(
471 pref_key, &browser_pref, &permission)); 491 pref_key, &browser_pref, &permission));
472 if (!GetExtension()->HasApiPermission(permission)) { 492 if (!GetExtension()->HasApiPermission(permission)) {
473 error_ = base::StringPrintf(kPermissionErrorMessage, pref_key.c_str()); 493 error_ = base::StringPrintf(kPermissionErrorMessage, pref_key.c_str());
474 return false; 494 return false;
475 } 495 }
476 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); 496 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs();
477 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); 497 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, scope);
478 return true; 498 return true;
479 } 499 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/api/extension_api.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698