OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/translate_internals/translate_internals_handle
r.h" |
| 6 |
| 7 #include <map> |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" |
| 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/values.h" |
| 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/translate/translate_prefs.h" |
| 17 #include "chrome/common/pref_names.h" |
| 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/browser/web_ui.h" |
| 20 |
| 21 void TranslateInternalsHandler::RegisterMessages() { |
| 22 web_ui()->RegisterMessageCallback("requestInfo", base::Bind( |
| 23 &TranslateInternalsHandler::OnRequestInfo, base::Unretained(this))); |
| 24 } |
| 25 |
| 26 void TranslateInternalsHandler::OnRequestInfo(const base::ListValue* /*args*/) { |
| 27 content::WebContents* web_contents = web_ui()->GetWebContents(); |
| 28 Profile* profile = |
| 29 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 30 PrefService* prefs = profile->GetOriginalProfile()->GetPrefs(); |
| 31 |
| 32 base::DictionaryValue dict; |
| 33 |
| 34 static const char* keys[] = { |
| 35 prefs::kEnableTranslate, |
| 36 TranslatePrefs::kPrefTranslateLanguageBlacklist, |
| 37 TranslatePrefs::kPrefTranslateSiteBlacklist, |
| 38 TranslatePrefs::kPrefTranslateWhitelists, |
| 39 TranslatePrefs::kPrefTranslateDeniedCount, |
| 40 TranslatePrefs::kPrefTranslateAcceptedCount, |
| 41 }; |
| 42 |
| 43 for (size_t i = 0; i < arraysize(keys); ++i) { |
| 44 const char* key = keys[i]; |
| 45 const PrefService::Preference* pref = prefs->FindPreference(key); |
| 46 if (pref) |
| 47 dict.Set(key, pref->GetValue()->DeepCopy()); |
| 48 } |
| 49 |
| 50 SendMessageToJs("prefsUpdated", dict); |
| 51 } |
| 52 |
| 53 void TranslateInternalsHandler::SendMessageToJs(const std::string& message, |
| 54 const base::Value& value) { |
| 55 const char func[] = "cr.translateInternals.messageHandler"; |
| 56 base::StringValue message_data(message); |
| 57 web_ui()->CallJavascriptFunction(func, message_data, value); |
| 58 } |
OLD | NEW |