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

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

Issue 10177003: Font Settings Extension API: Add functions to clear prefs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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) 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_font_settings_api.h" 5 #include "chrome/browser/extensions/extension_font_settings_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 269
270 extension_preference_helpers::DispatchEventToExtensions( 270 extension_preference_helpers::DispatchEventToExtensions(
271 profile_, 271 profile_,
272 event_name, 272 event_name,
273 &args, 273 &args,
274 ExtensionAPIPermission::kExperimental, 274 ExtensionAPIPermission::kExperimental,
275 incognito, 275 incognito,
276 pref_name); 276 pref_name);
277 } 277 }
278 278
279 bool ClearFontFunction::RunImpl() {
280 DictionaryValue* details = NULL;
281 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
282
283 std::string pref_path;
284 EXTENSION_FUNCTION_VALIDATE(GetFontNamePrefPath(details, &pref_path));
285
286 // Ensure |pref_path| really is for a registered per-script font pref.
287 EXTENSION_FUNCTION_VALIDATE(
288 profile_->GetPrefs()->FindPreference(pref_path.c_str()));
289
290 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs();
291 prefs->RemoveExtensionControlledPref(extension_id(),
292 pref_path.c_str(),
293 kExtensionPrefsScopeRegular);
294 return true;
295 }
296
279 bool GetFontFunction::RunImpl() { 297 bool GetFontFunction::RunImpl() {
280 DictionaryValue* details = NULL; 298 DictionaryValue* details = NULL;
281 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); 299 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
282 300
283 std::string pref_path; 301 std::string pref_path;
284 EXTENSION_FUNCTION_VALIDATE(GetFontNamePrefPath(details, &pref_path)); 302 EXTENSION_FUNCTION_VALIDATE(GetFontNamePrefPath(details, &pref_path));
285 303
286 PrefService* prefs = profile_->GetPrefs(); 304 PrefService* prefs = profile_->GetPrefs();
287 const PrefService::Preference* pref = 305 const PrefService::Preference* pref =
288 prefs->FindPreference(pref_path.c_str()); 306 prefs->FindPreference(pref_path.c_str());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 DictionaryValue* font_name = new DictionaryValue(); 372 DictionaryValue* font_name = new DictionaryValue();
355 font_name->Set(kFontNameKey, Value::CreateStringValue(name)); 373 font_name->Set(kFontNameKey, Value::CreateStringValue(name));
356 font_name->Set(kLocalizedNameKey, Value::CreateStringValue(localized_name)); 374 font_name->Set(kLocalizedNameKey, Value::CreateStringValue(localized_name));
357 result->Append(font_name); 375 result->Append(font_name);
358 } 376 }
359 377
360 result_.reset(result.release()); 378 result_.reset(result.release());
361 return true; 379 return true;
362 } 380 }
363 381
382 bool ClearFontPrefExtensionFunction::RunImpl() {
383 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs();
384 prefs->RemoveExtensionControlledPref(extension_id(),
385 GetPrefName(),
386 kExtensionPrefsScopeRegular);
387 return true;
388 }
389
364 bool GetFontPrefExtensionFunction::RunImpl() { 390 bool GetFontPrefExtensionFunction::RunImpl() {
365 PrefService* prefs = profile_->GetPrefs(); 391 PrefService* prefs = profile_->GetPrefs();
366 const PrefService::Preference* pref = prefs->FindPreference(GetPrefName()); 392 const PrefService::Preference* pref = prefs->FindPreference(GetPrefName());
367 EXTENSION_FUNCTION_VALIDATE(pref); 393 EXTENSION_FUNCTION_VALIDATE(pref);
368 394
369 DictionaryValue* result = new DictionaryValue(); 395 DictionaryValue* result = new DictionaryValue();
370 result->Set(GetKey(), pref->GetValue()->DeepCopy()); 396 result->Set(GetKey(), pref->GetValue()->DeepCopy());
371 result_.reset(result); 397 result_.reset(result);
372 return true; 398 return true;
373 } 399 }
374 400
375 bool SetFontPrefExtensionFunction::RunImpl() { 401 bool SetFontPrefExtensionFunction::RunImpl() {
376 DictionaryValue* details = NULL; 402 DictionaryValue* details = NULL;
377 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); 403 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
378 404
379 Value* value; 405 Value* value;
380 EXTENSION_FUNCTION_VALIDATE(details->Get(GetKey(), &value)); 406 EXTENSION_FUNCTION_VALIDATE(details->Get(GetKey(), &value));
381 407
382 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); 408 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs();
383 prefs->SetExtensionControlledPref(extension_id(), 409 prefs->SetExtensionControlledPref(extension_id(),
384 GetPrefName(), 410 GetPrefName(),
385 kExtensionPrefsScopeRegular, 411 kExtensionPrefsScopeRegular,
386 value->DeepCopy()); 412 value->DeepCopy());
387 return true; 413 return true;
388 } 414 }
389 415
416 const char* ClearDefaultFontSizeFunction::GetPrefName() {
417 return prefs::kWebKitGlobalDefaultFontSize;
418 }
419
390 const char* GetDefaultFontSizeFunction::GetPrefName() { 420 const char* GetDefaultFontSizeFunction::GetPrefName() {
391 return prefs::kWebKitGlobalDefaultFontSize; 421 return prefs::kWebKitGlobalDefaultFontSize;
392 } 422 }
393 423
394 const char* GetDefaultFontSizeFunction::GetKey() { 424 const char* GetDefaultFontSizeFunction::GetKey() {
395 return kPixelSizeKey; 425 return kPixelSizeKey;
396 } 426 }
397 427
398 const char* SetDefaultFontSizeFunction::GetPrefName() { 428 const char* SetDefaultFontSizeFunction::GetPrefName() {
399 return prefs::kWebKitGlobalDefaultFontSize; 429 return prefs::kWebKitGlobalDefaultFontSize;
400 } 430 }
401 431
402 const char* SetDefaultFontSizeFunction::GetKey() { 432 const char* SetDefaultFontSizeFunction::GetKey() {
403 return kPixelSizeKey; 433 return kPixelSizeKey;
404 } 434 }
405 435
436 const char* ClearDefaultFixedFontSizeFunction::GetPrefName() {
437 return prefs::kWebKitGlobalDefaultFixedFontSize;
438 }
439
406 const char* GetDefaultFixedFontSizeFunction::GetPrefName() { 440 const char* GetDefaultFixedFontSizeFunction::GetPrefName() {
407 return prefs::kWebKitGlobalDefaultFixedFontSize; 441 return prefs::kWebKitGlobalDefaultFixedFontSize;
408 } 442 }
409 443
410 const char* GetDefaultFixedFontSizeFunction::GetKey() { 444 const char* GetDefaultFixedFontSizeFunction::GetKey() {
411 return kPixelSizeKey; 445 return kPixelSizeKey;
412 } 446 }
413 447
414 const char* SetDefaultFixedFontSizeFunction::GetPrefName() { 448 const char* SetDefaultFixedFontSizeFunction::GetPrefName() {
415 return prefs::kWebKitGlobalDefaultFixedFontSize; 449 return prefs::kWebKitGlobalDefaultFixedFontSize;
416 } 450 }
417 451
418 const char* SetDefaultFixedFontSizeFunction::GetKey() { 452 const char* SetDefaultFixedFontSizeFunction::GetKey() {
419 return kPixelSizeKey; 453 return kPixelSizeKey;
420 } 454 }
421 455
456 const char* ClearMinimumFontSizeFunction::GetPrefName() {
457 return prefs::kWebKitGlobalMinimumFontSize;
458 }
459
422 const char* GetMinimumFontSizeFunction::GetPrefName() { 460 const char* GetMinimumFontSizeFunction::GetPrefName() {
423 return prefs::kWebKitGlobalMinimumFontSize; 461 return prefs::kWebKitGlobalMinimumFontSize;
424 } 462 }
425 463
426 const char* GetMinimumFontSizeFunction::GetKey() { 464 const char* GetMinimumFontSizeFunction::GetKey() {
427 return kPixelSizeKey; 465 return kPixelSizeKey;
428 } 466 }
429 467
430 const char* SetMinimumFontSizeFunction::GetPrefName() { 468 const char* SetMinimumFontSizeFunction::GetPrefName() {
431 return prefs::kWebKitGlobalMinimumFontSize; 469 return prefs::kWebKitGlobalMinimumFontSize;
432 } 470 }
433 471
434 const char* SetMinimumFontSizeFunction::GetKey() { 472 const char* SetMinimumFontSizeFunction::GetKey() {
435 return kPixelSizeKey; 473 return kPixelSizeKey;
436 } 474 }
437 475
476 const char* ClearDefaultCharacterSetFunction::GetPrefName() {
477 return prefs::kGlobalDefaultCharset;
478 }
479
438 const char* GetDefaultCharacterSetFunction::GetPrefName() { 480 const char* GetDefaultCharacterSetFunction::GetPrefName() {
439 return prefs::kGlobalDefaultCharset; 481 return prefs::kGlobalDefaultCharset;
440 } 482 }
441 483
442 const char* GetDefaultCharacterSetFunction::GetKey() { 484 const char* GetDefaultCharacterSetFunction::GetKey() {
443 return kCharsetKey; 485 return kCharsetKey;
444 } 486 }
445 487
446 const char* SetDefaultCharacterSetFunction::GetPrefName() { 488 const char* SetDefaultCharacterSetFunction::GetPrefName() {
447 return prefs::kGlobalDefaultCharset; 489 return prefs::kGlobalDefaultCharset;
448 } 490 }
449 491
450 const char* SetDefaultCharacterSetFunction::GetKey() { 492 const char* SetDefaultCharacterSetFunction::GetKey() {
451 return kCharsetKey; 493 return kCharsetKey;
452 } 494 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_font_settings_api.h ('k') | chrome/browser/extensions/extension_font_settings_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698