Chromium Code Reviews| Index: chrome/browser/ui/webui/translate_internals/translate_internals_handler.cc |
| diff --git a/chrome/browser/ui/webui/translate_internals/translate_internals_handler.cc b/chrome/browser/ui/webui/translate_internals/translate_internals_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..05766b99c71a831435d450d59f178891ed82dcec |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/translate_internals/translate_internals_handler.cc |
| @@ -0,0 +1,62 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/webui/translate_internals/translate_internals_handler.h" |
| + |
| +#include <map> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| +#include "base/prefs/pref_service.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/translate/translate_prefs.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/browser/web_ui.h" |
| + |
| +void TranslateInternalsHandler::RegisterMessages() { |
| + web_ui()->RegisterMessageCallback("requestInfo", base::Bind( |
| + &TranslateInternalsHandler::OnRequestInfo, base::Unretained(this))); |
| +} |
| + |
| +void TranslateInternalsHandler::OnRequestInfo(const base::ListValue* /*args*/) { |
| + content::WebContents* web_contents = web_ui()->GetWebContents(); |
| + Profile* profile = |
| + Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| + PrefService* prefs = profile->GetOriginalProfile()->GetPrefs(); |
| + |
| + base::DictionaryValue dict; |
| + |
| + static const char* keys[] = { |
| + prefs::kEnableTranslate, |
| + TranslatePrefs::kPrefTranslateLanguageBlacklist, |
| + TranslatePrefs::kPrefTranslateSiteBlacklist, |
| + TranslatePrefs::kPrefTranslateWhitelists, |
| + TranslatePrefs::kPrefTranslateDeniedCount, |
| + TranslatePrefs::kPrefTranslateAcceptedCount, |
| + }; |
| + |
| + scoped_ptr<base::DictionaryValue> pref_values(prefs->GetPreferenceValues()); |
|
Evan Stade
2013/04/12 16:02:25
why copy into a dict? What's wrong with GetPrefere
hajimehoshi
2013/04/15 04:01:49
Done.
|
| + for (unsigned i = 0; i < arraysize(keys); ++i) { |
| + const char* key = keys[i]; |
| + const base::Value* value; |
| + if (pref_values->Get(key, &value)) { |
| + base::Value* copied_value = value->DeepCopy(); |
| + // The ownership of |copied_value| will be passed to |dict|. |
|
Evan Stade
2013/04/12 16:02:25
instead of relying on a comment, you can write cod
hajimehoshi
2013/04/15 04:01:49
Done.
|
| + dict.Set(key, copied_value); |
| + } |
| + } |
| + |
| + SendMessage("prefsUpdated", dict); |
| +} |
| + |
| +void TranslateInternalsHandler::SendMessage(const std::string& message, |
| + const base::Value& value) { |
| + const char func[] = "cr.translateInternals.messageHandler"; |
| + scoped_ptr<base::Value> message_data(base::Value::CreateStringValue(message)); |
|
Evan Stade
2013/04/12 16:02:25
CreateStringValue is deprecated.
hajimehoshi
2013/04/15 04:01:49
Done.
|
| + web_ui()->CallJavascriptFunction(func, *message_data, value); |
| +} |