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

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

Issue 6480033: Implement experimental.contentSettings.misc.blockThirdPartyCookies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix stuff Created 9 years, 10 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/extension_preference_api.h"
6
7 #include "base/values.h"
8 #include "chrome/browser/extensions/extension_prefs.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/pref_names.h"
12
13 namespace {
14
15 struct PrefMappingEntry {
16 const char* extension_pref;
17 const char* browser_pref;
18 };
19
20 PrefMappingEntry pref_mapping[] = {
21 {"blockThirdPartyCookies", prefs::kBlockThirdPartyCookies},
22 };
23
24 const char* BrowserPrefForExtensionPref(const std::string& extension_pref) {
25 for (size_t i = 0; i < arraysize(pref_mapping); ++i) {
26 if (extension_pref == pref_mapping[i].extension_pref)
27 return pref_mapping[i].browser_pref;
28 }
29 return NULL;
30 }
31
32 } // namespace
33
34 GetPreferenceFunction::~GetPreferenceFunction() { }
35
36 bool GetPreferenceFunction::RunImpl() {
37 std::string pref_key;
38 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key));
39 DictionaryValue* details;
40 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details));
41 Value* incognito_value;
42 bool incognito = false;
43 if (details->Get("incognito", &incognito_value))
44 EXTENSION_FUNCTION_VALIDATE(incognito_value->GetAsBoolean(&incognito));
battre 2011/02/11 13:49:02 maybe if (details->HasKey("incognito")) EXTENSIO
45
46 PrefService* prefs = incognito ? profile_->GetOffTheRecordPrefs()
47 : profile_->GetPrefs();
48 const char* browser_pref = BrowserPrefForExtensionPref(pref_key);
49 if (!browser_pref) {
50 NOTREACHED();
51 return false;
52 }
53 const PrefService::Preference* pref = prefs->FindPreference(browser_pref);
54 if (!pref) {
55 NOTREACHED();
56 return false;
57 }
58 result_.reset(pref->GetValue()->DeepCopy());
59 return true;
60 }
61
62 SetPreferenceFunction::~SetPreferenceFunction() { }
63
64 bool SetPreferenceFunction::RunImpl() {
65 std::string pref_key;
66 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key));
67 DictionaryValue* details;
68 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details));
69
70 Value* value;
71 EXTENSION_FUNCTION_VALIDATE(details->Get("value", &value));
battre 2011/02/11 13:49:02 make value a full parameter of the function? That
Bernhard Bauer 2011/02/11 15:27:15 Hm. I tried to keep as close to the original spec
72
73 Value* incognito_value;
74 bool incognito = false;
75 if (details->Get("incognito", &incognito_value))
76 EXTENSION_FUNCTION_VALIDATE(incognito_value->GetAsBoolean(&incognito));
battre 2011/02/11 13:49:02 see above
77
78 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs();
79 const char* browser_pref = BrowserPrefForExtensionPref(pref_key);
80 if (!browser_pref)
battre 2011/02/11 13:49:02 insert NOTREACHED(); as above?
Bernhard Bauer 2011/02/11 15:27:15 I've rewritten the checking code quite a bit. It s
81 return false;
82 prefs->SetExtensionControlledPref(extension_id(),
83 browser_pref,
84 incognito,
85 value->DeepCopy());
86 return true;
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698