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

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

Issue 10704023: Moved ExtensionPrefs and related into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest-er master merged in Created 8 years, 5 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/extension_preference_api.h" 5 #include "chrome/browser/extensions/extension_preference_api.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 args.Append(dict); 280 args.Append(dict);
281 const PrefService::Preference* pref = 281 const PrefService::Preference* pref =
282 pref_service->FindPreference(browser_pref.c_str()); 282 pref_service->FindPreference(browser_pref.c_str());
283 CHECK(pref); 283 CHECK(pref);
284 ExtensionService* extension_service = profile_->GetExtensionService(); 284 ExtensionService* extension_service = profile_->GetExtensionService();
285 PrefTransformerInterface* transformer = 285 PrefTransformerInterface* transformer =
286 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref); 286 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref);
287 dict->Set(keys::kValue, 287 dict->Set(keys::kValue,
288 transformer->BrowserToExtensionPref(pref->GetValue())); 288 transformer->BrowserToExtensionPref(pref->GetValue()));
289 if (incognito) { 289 if (incognito) {
290 ExtensionPrefs* ep = extension_service->extension_prefs(); 290 extensions::ExtensionPrefs* ep = extension_service->extension_prefs();
291 dict->SetBoolean(keys::kIncognitoSpecific, 291 dict->SetBoolean(keys::kIncognitoSpecific,
292 ep->HasIncognitoPrefValue(browser_pref)); 292 ep->HasIncognitoPrefValue(browser_pref));
293 } 293 }
294 294
295 helpers::DispatchEventToExtensions(profile_, 295 helpers::DispatchEventToExtensions(profile_,
296 event_name, 296 event_name,
297 &args, 297 &args,
298 permission, 298 permission,
299 incognito, 299 incognito,
300 browser_pref); 300 browser_pref);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 result->SetString(keys::kLevelOfControl, level_of_control); 355 result->SetString(keys::kLevelOfControl, level_of_control);
356 356
357 // Retrieve pref value. 357 // Retrieve pref value.
358 PrefTransformerInterface* transformer = 358 PrefTransformerInterface* transformer =
359 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref); 359 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref);
360 result->Set(keys::kValue, 360 result->Set(keys::kValue,
361 transformer->BrowserToExtensionPref(pref->GetValue())); 361 transformer->BrowserToExtensionPref(pref->GetValue()));
362 362
363 // Retrieve incognito status. 363 // Retrieve incognito status.
364 if (incognito) { 364 if (incognito) {
365 ExtensionPrefs* ep = profile_->GetExtensionService()->extension_prefs(); 365 extensions::ExtensionPrefs* ep =
366 profile_->GetExtensionService()->extension_prefs();
366 result->SetBoolean(keys::kIncognitoSpecific, 367 result->SetBoolean(keys::kIncognitoSpecific,
367 ep->HasIncognitoPrefValue(browser_pref)); 368 ep->HasIncognitoPrefValue(browser_pref));
368 } 369 }
369 370
370 result_.reset(result.release()); 371 result_.reset(result.release());
371 return true; 372 return true;
372 } 373 }
373 374
374 SetPreferenceFunction::~SetPreferenceFunction() { } 375 SetPreferenceFunction::~SetPreferenceFunction() { }
375 376
376 bool SetPreferenceFunction::RunImpl() { 377 bool SetPreferenceFunction::RunImpl() {
377 std::string pref_key; 378 std::string pref_key;
378 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); 379 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key));
379 DictionaryValue* details = NULL; 380 DictionaryValue* details = NULL;
380 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); 381 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details));
381 382
382 Value* value = NULL; 383 Value* value = NULL;
383 EXTENSION_FUNCTION_VALIDATE(details->Get(keys::kValue, &value)); 384 EXTENSION_FUNCTION_VALIDATE(details->Get(keys::kValue, &value));
384 385
385 ExtensionPrefsScope scope = kExtensionPrefsScopeRegular; 386 extensions::ExtensionPrefsScope scope =
387 extensions::kExtensionPrefsScopeRegular;
386 if (details->HasKey(keys::kScopeKey)) { 388 if (details->HasKey(keys::kScopeKey)) {
387 std::string scope_str; 389 std::string scope_str;
388 EXTENSION_FUNCTION_VALIDATE( 390 EXTENSION_FUNCTION_VALIDATE(
389 details->GetString(keys::kScopeKey, &scope_str)); 391 details->GetString(keys::kScopeKey, &scope_str));
390 392
391 EXTENSION_FUNCTION_VALIDATE(helpers::StringToScope(scope_str, &scope)); 393 EXTENSION_FUNCTION_VALIDATE(helpers::StringToScope(scope_str, &scope));
392 } 394 }
393 395
394 // Check incognito scope. 396 // Check incognito scope.
395 bool incognito = (scope == kExtensionPrefsScopeIncognitoPersistent || 397 bool incognito =
396 scope == kExtensionPrefsScopeIncognitoSessionOnly); 398 (scope == extensions::kExtensionPrefsScopeIncognitoPersistent ||
399 scope == extensions::kExtensionPrefsScopeIncognitoSessionOnly);
397 if (incognito) { 400 if (incognito) {
398 // Regular profiles can't access incognito unless include_incognito is true. 401 // Regular profiles can't access incognito unless include_incognito is true.
399 if (!profile()->IsOffTheRecord() && !include_incognito()) { 402 if (!profile()->IsOffTheRecord() && !include_incognito()) {
400 error_ = keys::kIncognitoErrorMessage; 403 error_ = keys::kIncognitoErrorMessage;
401 return false; 404 return false;
402 } 405 }
403 } else { 406 } else {
404 // Incognito profiles can't access regular mode ever, they only exist in 407 // Incognito profiles can't access regular mode ever, they only exist in
405 // split mode. 408 // split mode.
406 if (profile()->IsOffTheRecord()) { 409 if (profile()->IsOffTheRecord()) {
407 error_ = "Can't modify regular settings from an incognito context."; 410 error_ = "Can't modify regular settings from an incognito context.";
408 return false; 411 return false;
409 } 412 }
410 } 413 }
411 414
412 if (scope == kExtensionPrefsScopeIncognitoSessionOnly && 415 if (scope == extensions::kExtensionPrefsScopeIncognitoSessionOnly &&
413 !profile_->HasOffTheRecordProfile()) { 416 !profile_->HasOffTheRecordProfile()) {
414 error_ = keys::kIncognitoSessionOnlyErrorMessage; 417 error_ = keys::kIncognitoSessionOnlyErrorMessage;
415 return false; 418 return false;
416 } 419 }
417 420
418 // Obtain pref. 421 // Obtain pref.
419 std::string browser_pref; 422 std::string browser_pref;
420 if (!ValidateBrowserPref(pref_key, &browser_pref)) 423 if (!ValidateBrowserPref(pref_key, &browser_pref))
421 return false; 424 return false;
422 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); 425 extensions::ExtensionPrefs* prefs =
426 profile_->GetExtensionService()->extension_prefs();
423 const PrefService::Preference* pref = 427 const PrefService::Preference* pref =
424 prefs->pref_service()->FindPreference(browser_pref.c_str()); 428 prefs->pref_service()->FindPreference(browser_pref.c_str());
425 CHECK(pref); 429 CHECK(pref);
426 430
427 // Validate new value. 431 // Validate new value.
428 EXTENSION_FUNCTION_VALIDATE(value->GetType() == pref->GetType()); 432 EXTENSION_FUNCTION_VALIDATE(value->GetType() == pref->GetType());
429 PrefTransformerInterface* transformer = 433 PrefTransformerInterface* transformer =
430 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref); 434 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref);
431 std::string error; 435 std::string error;
432 bool bad_message = false; 436 bool bad_message = false;
(...skipping 13 matching lines...) Expand all
446 } 450 }
447 451
448 ClearPreferenceFunction::~ClearPreferenceFunction() { } 452 ClearPreferenceFunction::~ClearPreferenceFunction() { }
449 453
450 bool ClearPreferenceFunction::RunImpl() { 454 bool ClearPreferenceFunction::RunImpl() {
451 std::string pref_key; 455 std::string pref_key;
452 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); 456 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key));
453 DictionaryValue* details = NULL; 457 DictionaryValue* details = NULL;
454 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); 458 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details));
455 459
456 ExtensionPrefsScope scope = kExtensionPrefsScopeRegular; 460 extensions::ExtensionPrefsScope scope =
461 extensions::kExtensionPrefsScopeRegular;
457 if (details->HasKey(keys::kScopeKey)) { 462 if (details->HasKey(keys::kScopeKey)) {
458 std::string scope_str; 463 std::string scope_str;
459 EXTENSION_FUNCTION_VALIDATE( 464 EXTENSION_FUNCTION_VALIDATE(
460 details->GetString(keys::kScopeKey, &scope_str)); 465 details->GetString(keys::kScopeKey, &scope_str));
461 466
462 EXTENSION_FUNCTION_VALIDATE(helpers::StringToScope(scope_str, &scope)); 467 EXTENSION_FUNCTION_VALIDATE(helpers::StringToScope(scope_str, &scope));
463 } 468 }
464 469
465 // Check incognito scope. 470 // Check incognito scope.
466 bool incognito = (scope == kExtensionPrefsScopeIncognitoPersistent || 471 bool incognito =
467 scope == kExtensionPrefsScopeIncognitoSessionOnly); 472 (scope == extensions::kExtensionPrefsScopeIncognitoPersistent ||
473 scope == extensions::kExtensionPrefsScopeIncognitoSessionOnly);
468 if (incognito) { 474 if (incognito) {
469 // We don't check incognito permissions here, as an extension should be 475 // We don't check incognito permissions here, as an extension should be
470 // always allowed to clear its own settings. 476 // always allowed to clear its own settings.
471 } else { 477 } else {
472 // Incognito profiles can't access regular mode ever, they only exist in 478 // Incognito profiles can't access regular mode ever, they only exist in
473 // split mode. 479 // split mode.
474 if (profile()->IsOffTheRecord()) { 480 if (profile()->IsOffTheRecord()) {
475 error_ = "Can't modify regular settings from an incognito context."; 481 error_ = "Can't modify regular settings from an incognito context.";
476 return false; 482 return false;
477 } 483 }
478 } 484 }
479 485
480 std::string browser_pref; 486 std::string browser_pref;
481 if (!ValidateBrowserPref(pref_key, &browser_pref)) 487 if (!ValidateBrowserPref(pref_key, &browser_pref))
482 return false; 488 return false;
483 489
484 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); 490 extensions::ExtensionPrefs* prefs =
491 profile_->GetExtensionService()->extension_prefs();
485 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); 492 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, scope);
486 return true; 493 return true;
487 } 494 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698