OLD | NEW |
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/ui/webui/options2/core_options_handler.h" | 5 #include "chrome/browser/ui/webui/options2/core_options_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 void CoreOptionsHandler::StopObservingPref(const std::string& path) { | 291 void CoreOptionsHandler::StopObservingPref(const std::string& path) { |
292 registrar_.Remove(path.c_str(), this); | 292 registrar_.Remove(path.c_str(), this); |
293 } | 293 } |
294 | 294 |
295 void CoreOptionsHandler::HandleFetchPrefs(const ListValue* args) { | 295 void CoreOptionsHandler::HandleFetchPrefs(const ListValue* args) { |
296 // First param is name of callback function, so, there needs to be at least | 296 // First param is name of callback function, so, there needs to be at least |
297 // one more element for the actual preference identifier. | 297 // one more element for the actual preference identifier. |
298 DCHECK_GE(static_cast<int>(args->GetSize()), 2); | 298 DCHECK_GE(static_cast<int>(args->GetSize()), 2); |
299 | 299 |
300 // Get callback JS function name. | 300 // Get callback JS function name. |
301 base::Value* callback; | 301 const base::Value* callback; |
302 if (!args->Get(0, &callback) || !callback->IsType(base::Value::TYPE_STRING)) | 302 if (!args->Get(0, &callback) || !callback->IsType(base::Value::TYPE_STRING)) |
303 return; | 303 return; |
304 | 304 |
305 string16 callback_function; | 305 string16 callback_function; |
306 if (!callback->GetAsString(&callback_function)) | 306 if (!callback->GetAsString(&callback_function)) |
307 return; | 307 return; |
308 | 308 |
309 // Get the list of name for prefs to build the response dictionary. | 309 // Get the list of name for prefs to build the response dictionary. |
310 DictionaryValue result_value; | 310 DictionaryValue result_value; |
311 base::Value* list_member; | 311 const base::Value* list_member; |
312 | 312 |
313 for (size_t i = 1; i < args->GetSize(); i++) { | 313 for (size_t i = 1; i < args->GetSize(); i++) { |
314 if (!args->Get(i, &list_member)) | 314 if (!args->Get(i, &list_member)) |
315 break; | 315 break; |
316 | 316 |
317 if (!list_member->IsType(base::Value::TYPE_STRING)) | 317 if (!list_member->IsType(base::Value::TYPE_STRING)) |
318 continue; | 318 continue; |
319 | 319 |
320 std::string pref_name; | 320 std::string pref_name; |
321 if (!list_member->GetAsString(&pref_name)) | 321 if (!list_member->GetAsString(&pref_name)) |
(...skipping 10 matching lines...) Expand all Loading... |
332 // identifiers that we are observing. | 332 // identifiers that we are observing. |
333 DCHECK_GE(static_cast<int>(args->GetSize()), 2); | 333 DCHECK_GE(static_cast<int>(args->GetSize()), 2); |
334 | 334 |
335 // Get preference change callback function name. | 335 // Get preference change callback function name. |
336 string16 callback_func_name; | 336 string16 callback_func_name; |
337 if (!args->GetString(0, &callback_func_name)) | 337 if (!args->GetString(0, &callback_func_name)) |
338 return; | 338 return; |
339 | 339 |
340 // Get all other parameters - pref identifiers. | 340 // Get all other parameters - pref identifiers. |
341 for (size_t i = 1; i < args->GetSize(); i++) { | 341 for (size_t i = 1; i < args->GetSize(); i++) { |
342 base::Value* list_member; | 342 const base::Value* list_member; |
343 if (!args->Get(i, &list_member)) | 343 if (!args->Get(i, &list_member)) |
344 break; | 344 break; |
345 | 345 |
346 // Just ignore bad pref identifiers for now. | 346 // Just ignore bad pref identifiers for now. |
347 std::string pref_name; | 347 std::string pref_name; |
348 if (!list_member->IsType(base::Value::TYPE_STRING) || | 348 if (!list_member->IsType(base::Value::TYPE_STRING) || |
349 !list_member->GetAsString(&pref_name)) | 349 !list_member->GetAsString(&pref_name)) |
350 continue; | 350 continue; |
351 | 351 |
352 if (pref_callback_map_.find(pref_name) == pref_callback_map_.end()) | 352 if (pref_callback_map_.find(pref_name) == pref_callback_map_.end()) |
(...skipping 29 matching lines...) Expand all Loading... |
382 HandleSetPref(args, TYPE_LIST); | 382 HandleSetPref(args, TYPE_LIST); |
383 } | 383 } |
384 | 384 |
385 void CoreOptionsHandler::HandleSetPref(const ListValue* args, PrefType type) { | 385 void CoreOptionsHandler::HandleSetPref(const ListValue* args, PrefType type) { |
386 DCHECK_GT(static_cast<int>(args->GetSize()), 1); | 386 DCHECK_GT(static_cast<int>(args->GetSize()), 1); |
387 | 387 |
388 std::string pref_name; | 388 std::string pref_name; |
389 if (!args->GetString(0, &pref_name)) | 389 if (!args->GetString(0, &pref_name)) |
390 return; | 390 return; |
391 | 391 |
392 base::Value* value; | 392 const base::Value* value; |
393 if (!args->Get(1, &value)) | 393 if (!args->Get(1, &value)) |
394 return; | 394 return; |
395 | 395 |
396 scoped_ptr<base::Value> temp_value; | 396 scoped_ptr<base::Value> temp_value; |
397 | 397 |
398 switch (type) { | 398 switch (type) { |
399 case TYPE_BOOLEAN: | 399 case TYPE_BOOLEAN: |
400 CHECK_EQ(base::Value::TYPE_BOOLEAN, value->GetType()); | 400 CHECK_EQ(base::Value::TYPE_BOOLEAN, value->GetType()); |
401 break; | 401 break; |
402 case TYPE_INTEGER: { | 402 case TYPE_INTEGER: { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 474 |
475 void CoreOptionsHandler::UpdatePepperFlashSettingsEnabled() { | 475 void CoreOptionsHandler::UpdatePepperFlashSettingsEnabled() { |
476 scoped_ptr<base::Value> enabled( | 476 scoped_ptr<base::Value> enabled( |
477 base::Value::CreateBooleanValue( | 477 base::Value::CreateBooleanValue( |
478 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled())); | 478 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled())); |
479 web_ui()->CallJavascriptFunction( | 479 web_ui()->CallJavascriptFunction( |
480 "OptionsPage.setPepperFlashSettingsEnabled", *enabled); | 480 "OptionsPage.setPepperFlashSettingsEnabled", *enabled); |
481 } | 481 } |
482 | 482 |
483 } // namespace options2 | 483 } // namespace options2 |
OLD | NEW |