OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 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 TranslateInternalsHandler::TranslateInternalsHandler() { | |
22 } | |
23 | |
24 TranslateInternalsHandler::~TranslateInternalsHandler() { | |
25 } | |
26 | |
27 void TranslateInternalsHandler::RegisterMessages() { | |
28 web_ui()->RegisterMessageCallback("requestInfo", base::Bind( | |
29 &TranslateInternalsHandler::OnRequestInfo, base::Unretained(this))); | |
30 } | |
31 | |
32 void TranslateInternalsHandler::OnRequestInfo(const base::ListValue*) { | |
33 content::WebContents* web_contents = web_ui()->GetWebContents(); | |
34 Profile* profile = | |
35 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
36 PrefService* prefs = profile->GetOriginalProfile()->GetPrefs(); | |
37 | |
38 base::DictionaryValue dict; | |
39 | |
40 static const char* keys[] = { | |
41 prefs::kEnableTranslate, | |
42 TranslatePrefs::kPrefTranslateLanguageBlacklist, | |
43 TranslatePrefs::kPrefTranslateSiteBlacklist, | |
44 TranslatePrefs::kPrefTranslateWhitelists, | |
45 TranslatePrefs::kPrefTranslateDeniedCount, | |
46 TranslatePrefs::kPrefTranslateAcceptedCount, | |
47 NULL, | |
Takashi Toyoshima
2013/04/12 08:43:35
I think we often use arraysize to run for loop on
| |
48 }; | |
49 | |
50 scoped_ptr<base::DictionaryValue> pref_values(prefs->GetPreferenceValues()); | |
51 for (int i = 0; keys[i]; ++i) { | |
52 const char* key = keys[i]; | |
53 const base::Value* value; | |
54 if (pref_values->Get(key, &value)) { | |
55 base::Value* copied_value = value->DeepCopy(); | |
56 // The ownership of |copied_value| will be passed to |dict|. | |
57 dict.Set(key, copied_value); | |
58 } | |
59 } | |
60 | |
61 SendMessage("prefsUpdated", dict); | |
62 } | |
63 | |
64 void TranslateInternalsHandler::SendMessage(const std::string& message, | |
65 const base::Value& value) { | |
66 const char func[] = "cr.translateInternals.messageHandler"; | |
67 scoped_ptr<base::Value> message_data(base::Value::CreateStringValue(message)); | |
68 web_ui()->CallJavascriptFunction(func, *message_data, value); | |
69 } | |
OLD | NEW |