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

Side by Side Diff: chrome/browser/extensions/api/font_settings/font_settings_api.cc

Issue 16915006: Convert most of extensions and some other random stuff to using the base namespace for Values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
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 // Font Settings Extension API implementation. 5 // Font Settings Extension API implementation.
6 6
7 #include "chrome/browser/extensions/api/font_settings/font_settings_api.h" 7 #include "chrome/browser/extensions/api/font_settings/font_settings_api.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 pref_name.c_str()); 167 pref_name.c_str());
168 CHECK(pref); 168 CHECK(pref);
169 169
170 std::string font_name; 170 std::string font_name;
171 if (!pref->GetValue()->GetAsString(&font_name)) { 171 if (!pref->GetValue()->GetAsString(&font_name)) {
172 NOTREACHED(); 172 NOTREACHED();
173 return; 173 return;
174 } 174 }
175 font_name = MaybeGetLocalizedFontName(font_name); 175 font_name = MaybeGetLocalizedFontName(font_name);
176 176
177 ListValue args; 177 base::ListValue args;
178 DictionaryValue* dict = new DictionaryValue(); 178 base::DictionaryValue* dict = new base::DictionaryValue();
179 args.Append(dict); 179 args.Append(dict);
180 dict->SetString(kFontIdKey, font_name); 180 dict->SetString(kFontIdKey, font_name);
181 dict->SetString(kGenericFamilyKey, generic_family); 181 dict->SetString(kGenericFamilyKey, generic_family);
182 dict->SetString(kScriptKey, script); 182 dict->SetString(kScriptKey, script);
183 183
184 extensions::preference_helpers::DispatchEventToExtensions( 184 extensions::preference_helpers::DispatchEventToExtensions(
185 profile_, 185 profile_,
186 kOnFontChanged, 186 kOnFontChanged,
187 &args, 187 &args,
188 APIPermission::kFontSettings, 188 APIPermission::kFontSettings,
189 false, 189 false,
190 pref_name); 190 pref_name);
191 } 191 }
192 192
193 void FontSettingsEventRouter::OnFontPrefChanged( 193 void FontSettingsEventRouter::OnFontPrefChanged(
194 const std::string& event_name, 194 const std::string& event_name,
195 const std::string& key, 195 const std::string& key,
196 const std::string& pref_name) { 196 const std::string& pref_name) {
197 const PrefService::Preference* pref = registrar_.prefs()->FindPreference( 197 const PrefService::Preference* pref = registrar_.prefs()->FindPreference(
198 pref_name.c_str()); 198 pref_name.c_str());
199 CHECK(pref); 199 CHECK(pref);
200 200
201 ListValue args; 201 base::ListValue args;
202 DictionaryValue* dict = new DictionaryValue(); 202 base::DictionaryValue* dict = new base::DictionaryValue();
203 args.Append(dict); 203 args.Append(dict);
204 dict->Set(key, pref->GetValue()->DeepCopy()); 204 dict->Set(key, pref->GetValue()->DeepCopy());
205 205
206 extensions::preference_helpers::DispatchEventToExtensions( 206 extensions::preference_helpers::DispatchEventToExtensions(
207 profile_, 207 profile_,
208 event_name, 208 event_name,
209 &args, 209 &args,
210 APIPermission::kFontSettings, 210 APIPermission::kFontSettings,
211 false, 211 false,
212 pref_name); 212 pref_name);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 268
269 // We don't support incognito-specific font prefs, so don't consider them when 269 // We don't support incognito-specific font prefs, so don't consider them when
270 // getting level of control. 270 // getting level of control.
271 const bool kIncognito = false; 271 const bool kIncognito = false;
272 std::string level_of_control = 272 std::string level_of_control =
273 extensions::preference_helpers::GetLevelOfControl(profile_, 273 extensions::preference_helpers::GetLevelOfControl(profile_,
274 extension_id(), 274 extension_id(),
275 pref_path, 275 pref_path,
276 kIncognito); 276 kIncognito);
277 277
278 DictionaryValue* result = new DictionaryValue(); 278 base::DictionaryValue* result = new base::DictionaryValue();
279 result->SetString(kFontIdKey, font_name); 279 result->SetString(kFontIdKey, font_name);
280 result->SetString(kLevelOfControlKey, level_of_control); 280 result->SetString(kLevelOfControlKey, level_of_control);
281 SetResult(result); 281 SetResult(result);
282 return true; 282 return true;
283 } 283 }
284 284
285 bool FontSettingsSetFontFunction::RunImpl() { 285 bool FontSettingsSetFontFunction::RunImpl() {
286 if (profile_->IsOffTheRecord()) { 286 if (profile_->IsOffTheRecord()) {
287 error_ = kSetFromIncognitoError; 287 error_ = kSetFromIncognitoError;
288 return false; 288 return false;
(...skipping 18 matching lines...) Expand all
307 return true; 307 return true;
308 } 308 }
309 309
310 bool FontSettingsGetFontListFunction::RunImpl() { 310 bool FontSettingsGetFontListFunction::RunImpl() {
311 content::GetFontListAsync( 311 content::GetFontListAsync(
312 Bind(&FontSettingsGetFontListFunction::FontListHasLoaded, this)); 312 Bind(&FontSettingsGetFontListFunction::FontListHasLoaded, this));
313 return true; 313 return true;
314 } 314 }
315 315
316 void FontSettingsGetFontListFunction::FontListHasLoaded( 316 void FontSettingsGetFontListFunction::FontListHasLoaded(
317 scoped_ptr<ListValue> list) { 317 scoped_ptr<base::ListValue> list) {
318 bool success = CopyFontsToResult(list.get()); 318 bool success = CopyFontsToResult(list.get());
319 SendResponse(success); 319 SendResponse(success);
320 } 320 }
321 321
322 bool FontSettingsGetFontListFunction::CopyFontsToResult(ListValue* fonts) { 322 bool FontSettingsGetFontListFunction::CopyFontsToResult(
323 scoped_ptr<ListValue> result(new ListValue()); 323 base::ListValue* fonts) {
324 for (ListValue::iterator it = fonts->begin(); it != fonts->end(); ++it) { 324 scoped_ptr<base::ListValue> result(new base::ListValue());
325 ListValue* font_list_value; 325 for (base::ListValue::iterator it = fonts->begin();
326 it != fonts->end(); ++it) {
327 base::ListValue* font_list_value;
326 if (!(*it)->GetAsList(&font_list_value)) { 328 if (!(*it)->GetAsList(&font_list_value)) {
327 NOTREACHED(); 329 NOTREACHED();
328 return false; 330 return false;
329 } 331 }
330 332
331 std::string name; 333 std::string name;
332 if (!font_list_value->GetString(0, &name)) { 334 if (!font_list_value->GetString(0, &name)) {
333 NOTREACHED(); 335 NOTREACHED();
334 return false; 336 return false;
335 } 337 }
336 338
337 std::string localized_name; 339 std::string localized_name;
338 if (!font_list_value->GetString(1, &localized_name)) { 340 if (!font_list_value->GetString(1, &localized_name)) {
339 NOTREACHED(); 341 NOTREACHED();
340 return false; 342 return false;
341 } 343 }
342 344
343 DictionaryValue* font_name = new DictionaryValue(); 345 base::DictionaryValue* font_name = new base::DictionaryValue();
344 font_name->Set(kFontIdKey, Value::CreateStringValue(name)); 346 font_name->Set(kFontIdKey, Value::CreateStringValue(name));
345 font_name->Set(kDisplayNameKey, Value::CreateStringValue(localized_name)); 347 font_name->Set(kDisplayNameKey, Value::CreateStringValue(localized_name));
346 result->Append(font_name); 348 result->Append(font_name);
347 } 349 }
348 350
349 SetResult(result.release()); 351 SetResult(result.release());
350 return true; 352 return true;
351 } 353 }
352 354
353 bool ClearFontPrefExtensionFunction::RunImpl() { 355 bool ClearFontPrefExtensionFunction::RunImpl() {
(...skipping 15 matching lines...) Expand all
369 // We don't support incognito-specific font prefs, so don't consider them when 371 // We don't support incognito-specific font prefs, so don't consider them when
370 // getting level of control. 372 // getting level of control.
371 const bool kIncognito = false; 373 const bool kIncognito = false;
372 374
373 std::string level_of_control = 375 std::string level_of_control =
374 extensions::preference_helpers::GetLevelOfControl(profile_, 376 extensions::preference_helpers::GetLevelOfControl(profile_,
375 extension_id(), 377 extension_id(),
376 GetPrefName(), 378 GetPrefName(),
377 kIncognito); 379 kIncognito);
378 380
379 DictionaryValue* result = new DictionaryValue(); 381 base::DictionaryValue* result = new base::DictionaryValue();
380 result->Set(GetKey(), pref->GetValue()->DeepCopy()); 382 result->Set(GetKey(), pref->GetValue()->DeepCopy());
381 result->SetString(kLevelOfControlKey, level_of_control); 383 result->SetString(kLevelOfControlKey, level_of_control);
382 SetResult(result); 384 SetResult(result);
383 return true; 385 return true;
384 } 386 }
385 387
386 bool SetFontPrefExtensionFunction::RunImpl() { 388 bool SetFontPrefExtensionFunction::RunImpl() {
387 if (profile_->IsOffTheRecord()) { 389 if (profile_->IsOffTheRecord()) {
388 error_ = kSetFromIncognitoError; 390 error_ = kSetFromIncognitoError;
389 return false; 391 return false;
390 } 392 }
391 393
392 DictionaryValue* details = NULL; 394 base::DictionaryValue* details = NULL;
393 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); 395 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
394 396
395 Value* value; 397 Value* value;
396 EXTENSION_FUNCTION_VALIDATE(details->Get(GetKey(), &value)); 398 EXTENSION_FUNCTION_VALIDATE(details->Get(GetKey(), &value));
397 399
398 PreferenceAPI::Get(profile_)->SetExtensionControlledPref( 400 PreferenceAPI::Get(profile_)->SetExtensionControlledPref(
399 extension_id(), 401 extension_id(),
400 GetPrefName(), 402 GetPrefName(),
401 kExtensionPrefsScopeRegular, 403 kExtensionPrefsScopeRegular,
402 value->DeepCopy()); 404 value->DeepCopy());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 459
458 const char* FontSettingsSetMinimumFontSizeFunction::GetPrefName() { 460 const char* FontSettingsSetMinimumFontSizeFunction::GetPrefName() {
459 return prefs::kWebKitMinimumFontSize; 461 return prefs::kWebKitMinimumFontSize;
460 } 462 }
461 463
462 const char* FontSettingsSetMinimumFontSizeFunction::GetKey() { 464 const char* FontSettingsSetMinimumFontSizeFunction::GetKey() {
463 return kPixelSizeKey; 465 return kPixelSizeKey;
464 } 466 }
465 467
466 } // namespace extensions 468 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698