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

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

Issue 10952021: Moving preference API into api/preferences (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/extensions/extension_preference_helpers.h" 15 #include "chrome/browser/extensions/api/preference/preference_helpers.h"
16 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/extensions/api/font_settings.h" 20 #include "chrome/common/extensions/api/font_settings.h"
21 #include "chrome/common/extensions/extension_error_utils.h" 21 #include "chrome/common/extensions/extension_error_utils.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "content/public/browser/font_list_async.h" 23 #include "content/public/browser/font_list_async.h"
24 #include "content/public/browser/notification_details.h" 24 #include "content/public/browser/notification_details.h"
25 #include "content/public/browser/notification_source.h" 25 #include "content/public/browser/notification_source.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 200 }
201 font_name = MaybeGetLocalizedFontName(font_name); 201 font_name = MaybeGetLocalizedFontName(font_name);
202 202
203 ListValue args; 203 ListValue args;
204 DictionaryValue* dict = new DictionaryValue(); 204 DictionaryValue* dict = new DictionaryValue();
205 args.Append(dict); 205 args.Append(dict);
206 dict->SetString(kFontIdKey, font_name); 206 dict->SetString(kFontIdKey, font_name);
207 dict->SetString(kGenericFamilyKey, generic_family); 207 dict->SetString(kGenericFamilyKey, generic_family);
208 dict->SetString(kScriptKey, script); 208 dict->SetString(kScriptKey, script);
209 209
210 extension_preference_helpers::DispatchEventToExtensions( 210 extensions::preference_helpers::DispatchEventToExtensions(
211 profile_, 211 profile_,
212 kOnFontChanged, 212 kOnFontChanged,
213 &args, 213 &args,
214 APIPermission::kFontSettings, 214 APIPermission::kFontSettings,
215 incognito, 215 incognito,
216 pref_name); 216 pref_name);
217 } 217 }
218 218
219 void FontSettingsEventRouter::OnFontPrefChanged( 219 void FontSettingsEventRouter::OnFontPrefChanged(
220 PrefService* pref_service, 220 PrefService* pref_service,
221 const std::string& pref_name, 221 const std::string& pref_name,
222 const std::string& event_name, 222 const std::string& event_name,
223 const std::string& key, 223 const std::string& key,
224 bool incognito) { 224 bool incognito) {
225 const PrefService::Preference* pref = pref_service->FindPreference( 225 const PrefService::Preference* pref = pref_service->FindPreference(
226 pref_name.c_str()); 226 pref_name.c_str());
227 CHECK(pref); 227 CHECK(pref);
228 228
229 ListValue args; 229 ListValue args;
230 DictionaryValue* dict = new DictionaryValue(); 230 DictionaryValue* dict = new DictionaryValue();
231 args.Append(dict); 231 args.Append(dict);
232 dict->Set(key, pref->GetValue()->DeepCopy()); 232 dict->Set(key, pref->GetValue()->DeepCopy());
233 233
234 extension_preference_helpers::DispatchEventToExtensions( 234 extensions::preference_helpers::DispatchEventToExtensions(
235 profile_, 235 profile_,
236 event_name, 236 event_name,
237 &args, 237 &args,
238 APIPermission::kFontSettings, 238 APIPermission::kFontSettings,
239 incognito, 239 incognito,
240 pref_name); 240 pref_name);
241 } 241 }
242 242
243 bool ClearFontFunction::RunImpl() { 243 bool ClearFontFunction::RunImpl() {
244 if (profile_->IsOffTheRecord()) { 244 if (profile_->IsOffTheRecord()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 277
278 std::string font_name; 278 std::string font_name;
279 EXTENSION_FUNCTION_VALIDATE( 279 EXTENSION_FUNCTION_VALIDATE(
280 pref && pref->GetValue()->GetAsString(&font_name)); 280 pref && pref->GetValue()->GetAsString(&font_name));
281 font_name = MaybeGetLocalizedFontName(font_name); 281 font_name = MaybeGetLocalizedFontName(font_name);
282 282
283 // We don't support incognito-specific font prefs, so don't consider them when 283 // We don't support incognito-specific font prefs, so don't consider them when
284 // getting level of control. 284 // getting level of control.
285 const bool kIncognito = false; 285 const bool kIncognito = false;
286 std::string level_of_control = 286 std::string level_of_control =
287 extension_preference_helpers::GetLevelOfControl(profile_, 287 extensions::preference_helpers::GetLevelOfControl(profile_,
288 extension_id(), 288 extension_id(),
289 pref_path, 289 pref_path,
290 kIncognito); 290 kIncognito);
291 291
292 DictionaryValue* result = new DictionaryValue(); 292 DictionaryValue* result = new DictionaryValue();
293 result->SetString(kFontIdKey, font_name); 293 result->SetString(kFontIdKey, font_name);
294 result->SetString(kLevelOfControlKey, level_of_control); 294 result->SetString(kLevelOfControlKey, level_of_control);
295 SetResult(result); 295 SetResult(result);
296 return true; 296 return true;
297 } 297 }
298 298
299 bool SetFontFunction::RunImpl() { 299 bool SetFontFunction::RunImpl() {
300 if (profile_->IsOffTheRecord()) { 300 if (profile_->IsOffTheRecord()) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 bool GetFontPrefExtensionFunction::RunImpl() { 379 bool GetFontPrefExtensionFunction::RunImpl() {
380 PrefService* prefs = profile_->GetPrefs(); 380 PrefService* prefs = profile_->GetPrefs();
381 const PrefService::Preference* pref = prefs->FindPreference(GetPrefName()); 381 const PrefService::Preference* pref = prefs->FindPreference(GetPrefName());
382 EXTENSION_FUNCTION_VALIDATE(pref); 382 EXTENSION_FUNCTION_VALIDATE(pref);
383 383
384 // We don't support incognito-specific font prefs, so don't consider them when 384 // We don't support incognito-specific font prefs, so don't consider them when
385 // getting level of control. 385 // getting level of control.
386 const bool kIncognito = false; 386 const bool kIncognito = false;
387 387
388 std::string level_of_control = 388 std::string level_of_control =
389 extension_preference_helpers::GetLevelOfControl(profile_, 389 extensions::preference_helpers::GetLevelOfControl(profile_,
390 extension_id(), 390 extension_id(),
391 GetPrefName(), 391 GetPrefName(),
392 kIncognito); 392 kIncognito);
393 393
394 DictionaryValue* result = new DictionaryValue(); 394 DictionaryValue* result = new DictionaryValue();
395 result->Set(GetKey(), pref->GetValue()->DeepCopy()); 395 result->Set(GetKey(), pref->GetValue()->DeepCopy());
396 result->SetString(kLevelOfControlKey, level_of_control); 396 result->SetString(kLevelOfControlKey, level_of_control);
397 SetResult(result); 397 SetResult(result);
398 return true; 398 return true;
399 } 399 }
400 400
401 bool SetFontPrefExtensionFunction::RunImpl() { 401 bool SetFontPrefExtensionFunction::RunImpl() {
402 if (profile_->IsOffTheRecord()) { 402 if (profile_->IsOffTheRecord()) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 472
473 const char* SetMinimumFontSizeFunction::GetPrefName() { 473 const char* SetMinimumFontSizeFunction::GetPrefName() {
474 return prefs::kWebKitMinimumFontSize; 474 return prefs::kWebKitMinimumFontSize;
475 } 475 }
476 476
477 const char* SetMinimumFontSizeFunction::GetKey() { 477 const char* SetMinimumFontSizeFunction::GetKey() {
478 return kPixelSizeKey; 478 return kPixelSizeKey;
479 } 479 }
480 480
481 } // namespace extensions 481 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698