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

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

Issue 7067040: Enable incognito_session_only preferences (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with ToT Created 9 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 | Annotate | Revision Log
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 22 matching lines...) Expand all
33 const char kControlledByOtherExtensions[] = "ControlledByOtherExtensions"; 33 const char kControlledByOtherExtensions[] = "ControlledByOtherExtensions";
34 const char kControllableByThisExtension[] = "ControllableByThisExtension"; 34 const char kControllableByThisExtension[] = "ControllableByThisExtension";
35 const char kControlledByThisExtension[] = "ControlledByThisExtension"; 35 const char kControlledByThisExtension[] = "ControlledByThisExtension";
36 36
37 const char kIncognito[] = "incognito"; 37 const char kIncognito[] = "incognito";
38 const char kIncognitoSpecific[] = "incognitoSpecific"; 38 const char kIncognitoSpecific[] = "incognitoSpecific";
39 const char kScope[] = "scope"; 39 const char kScope[] = "scope";
40 const char kLevelOfControl[] = "levelOfControl"; 40 const char kLevelOfControl[] = "levelOfControl";
41 const char kRegular[] = "regular"; 41 const char kRegular[] = "regular";
42 const char kIncognitoPersistent[] = "incognito_persistent"; 42 const char kIncognitoPersistent[] = "incognito_persistent";
43 const char kIncognitoSessionOnly[] = "incognito_session_only";
43 const char kValue[] = "value"; 44 const char kValue[] = "value";
44 45
45 const char kOnPrefChangeFormat[] = 46 const char kOnPrefChangeFormat[] =
46 "preferences.%s.onChange"; 47 "preferences.%s.onChange";
47 48
48 const char kIncognitoErrorMessage[] = 49 const char kIncognitoErrorMessage[] =
49 "You do not have permission to access incognito preferences."; 50 "You do not have permission to access incognito preferences.";
50 51
52 const char kIncognitoSessionOnlyErrorMessage[] =
53 "You cannot set a preference with scope 'incognito_session_only' when no "
54 "incognito window is open.";
55
51 const char kPermissionErrorMessage[] = 56 const char kPermissionErrorMessage[] =
52 "You do not have permission to access the preference '%s'. " 57 "You do not have permission to access the preference '%s'. "
53 "Be sure to declare in your manifest what permissions you need."; 58 "Be sure to declare in your manifest what permissions you need.";
54 59
55 PrefMappingEntry kPrefMapping[] = { 60 PrefMappingEntry kPrefMapping[] = {
56 { "blockThirdPartyCookies", 61 { "blockThirdPartyCookies",
57 prefs::kBlockThirdPartyCookies, 62 prefs::kBlockThirdPartyCookies,
58 Extension::kContentSettingsPermission 63 Extension::kContentSettingsPermission
59 }, 64 },
60 { "enableReferrers", 65 { "enableReferrers",
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 return kControllableByThisExtension; 116 return kControllableByThisExtension;
112 117
113 return kControlledByOtherExtensions; 118 return kControlledByOtherExtensions;
114 } 119 }
115 120
116 bool StringToScope(const std::string& s, extension_prefs_scope::Scope* scope) { 121 bool StringToScope(const std::string& s, extension_prefs_scope::Scope* scope) {
117 if (s == kRegular) 122 if (s == kRegular)
118 *scope = extension_prefs_scope::kRegular; 123 *scope = extension_prefs_scope::kRegular;
119 else if (s == kIncognitoPersistent) 124 else if (s == kIncognitoPersistent)
120 *scope = extension_prefs_scope::kIncognitoPersistent; 125 *scope = extension_prefs_scope::kIncognitoPersistent;
126 else if (s == kIncognitoSessionOnly)
127 *scope = extension_prefs_scope::kIncognitoSessionOnly;
121 else 128 else
122 return false; 129 return false;
123 return true; 130 return true;
124 } 131 }
125 132
126 class PrefMapping { 133 class PrefMapping {
127 public: 134 public:
128 static PrefMapping* GetInstance() { 135 static PrefMapping* GetInstance() {
129 return Singleton<PrefMapping>::get(); 136 return Singleton<PrefMapping>::get();
130 } 137 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 Value* value = NULL; 367 Value* value = NULL;
361 EXTENSION_FUNCTION_VALIDATE(details->Get(kValue, &value)); 368 EXTENSION_FUNCTION_VALIDATE(details->Get(kValue, &value));
362 369
363 std::string scope_str = kRegular; 370 std::string scope_str = kRegular;
364 if (details->HasKey(kScope)) 371 if (details->HasKey(kScope))
365 EXTENSION_FUNCTION_VALIDATE(details->GetString(kScope, &scope_str)); 372 EXTENSION_FUNCTION_VALIDATE(details->GetString(kScope, &scope_str));
366 373
367 extension_prefs_scope::Scope scope; 374 extension_prefs_scope::Scope scope;
368 EXTENSION_FUNCTION_VALIDATE(StringToScope(scope_str, &scope)); 375 EXTENSION_FUNCTION_VALIDATE(StringToScope(scope_str, &scope));
369 376
370 // TODO(battre): add kIncognitoSessionOnly 377 bool incognito = (scope == extension_prefs_scope::kIncognitoPersistent ||
371 bool incognito = (scope == extension_prefs_scope::kIncognitoPersistent); 378 scope == extension_prefs_scope::kIncognitoSessionOnly);
372 if (incognito) { 379 if (incognito) {
373 // Regular profiles can't access incognito unless include_incognito is true. 380 // Regular profiles can't access incognito unless include_incognito is true.
374 if (!profile()->IsOffTheRecord() && !include_incognito()) { 381 if (!profile()->IsOffTheRecord() && !include_incognito()) {
375 error_ = kIncognitoErrorMessage; 382 error_ = kIncognitoErrorMessage;
376 return false; 383 return false;
377 } 384 }
378 } else { 385 } else {
379 // Incognito profiles can't access regular mode ever, they only exist in 386 // Incognito profiles can't access regular mode ever, they only exist in
380 // split mode. 387 // split mode.
381 if (profile()->IsOffTheRecord()) { 388 if (profile()->IsOffTheRecord()) {
382 error_ = "Can't modify regular settings from an incognito context."; 389 error_ = "Can't modify regular settings from an incognito context.";
383 return false; 390 return false;
384 } 391 }
385 } 392 }
386 393
394 if (scope == extension_prefs_scope::kIncognitoSessionOnly &&
395 !profile_->HasOffTheRecordProfile()) {
396 error_ = kIncognitoSessionOnlyErrorMessage;
397 return false;
398 }
399
387 std::string browser_pref; 400 std::string browser_pref;
388 std::string permission; 401 std::string permission;
389 EXTENSION_FUNCTION_VALIDATE( 402 EXTENSION_FUNCTION_VALIDATE(
390 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref( 403 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref(
391 pref_key, &browser_pref, &permission)); 404 pref_key, &browser_pref, &permission));
392 if (!GetExtension()->HasApiPermission(permission)) { 405 if (!GetExtension()->HasApiPermission(permission)) {
393 error_ = base::StringPrintf(kPermissionErrorMessage, pref_key.c_str()); 406 error_ = base::StringPrintf(kPermissionErrorMessage, pref_key.c_str());
394 return false; 407 return false;
395 } 408 }
396 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); 409 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs();
(...skipping 27 matching lines...) Expand all
424 DictionaryValue* details = NULL; 437 DictionaryValue* details = NULL;
425 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); 438 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details));
426 439
427 std::string scope_str = kRegular; 440 std::string scope_str = kRegular;
428 if (details->HasKey(kScope)) 441 if (details->HasKey(kScope))
429 EXTENSION_FUNCTION_VALIDATE(details->GetString(kScope, &scope_str)); 442 EXTENSION_FUNCTION_VALIDATE(details->GetString(kScope, &scope_str));
430 443
431 extension_prefs_scope::Scope scope; 444 extension_prefs_scope::Scope scope;
432 EXTENSION_FUNCTION_VALIDATE(StringToScope(scope_str, &scope)); 445 EXTENSION_FUNCTION_VALIDATE(StringToScope(scope_str, &scope));
433 446
434 // TODO(battre): add kIncognitoSessionOnly 447 bool incognito = (scope == extension_prefs_scope::kIncognitoPersistent ||
435 bool incognito = (scope == extension_prefs_scope::kIncognitoPersistent); 448 scope == extension_prefs_scope::kIncognitoSessionOnly);
436 if (incognito) { 449 if (incognito) {
437 // We don't check incognito permissions here, as an extension should be 450 // We don't check incognito permissions here, as an extension should be
438 // always allowed to clear its own settings. 451 // always allowed to clear its own settings.
439 } else { 452 } else {
440 // Incognito profiles can't access regular mode ever, they only exist in 453 // Incognito profiles can't access regular mode ever, they only exist in
441 // split mode. 454 // split mode.
442 if (profile()->IsOffTheRecord()) { 455 if (profile()->IsOffTheRecord()) {
443 error_ = "Can't modify regular settings from an incognito context."; 456 error_ = "Can't modify regular settings from an incognito context.";
444 return false; 457 return false;
445 } 458 }
446 } 459 }
447 460
448 std::string browser_pref; 461 std::string browser_pref;
449 std::string permission; 462 std::string permission;
450 EXTENSION_FUNCTION_VALIDATE( 463 EXTENSION_FUNCTION_VALIDATE(
451 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref( 464 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref(
452 pref_key, &browser_pref, &permission)); 465 pref_key, &browser_pref, &permission));
453 if (!GetExtension()->HasApiPermission(permission)) { 466 if (!GetExtension()->HasApiPermission(permission)) {
454 error_ = base::StringPrintf(kPermissionErrorMessage, pref_key.c_str()); 467 error_ = base::StringPrintf(kPermissionErrorMessage, pref_key.c_str());
455 return false; 468 return false;
456 } 469 }
457 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); 470 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs();
458 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); 471 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, scope);
459 return true; 472 return true;
460 } 473 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_pref_value_map_unittest.cc ('k') | chrome/browser/extensions/extension_prefs_scope.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698