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

Side by Side Diff: chrome/browser/ui/webui/translate_internals/translate_internals_handler.cc

Issue 13842010: Added chrome://translate-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the mistakes Created 7 years, 8 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
OLDNEW
(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 (unsigned i = 0; i < arraysize(keys); ++i) {
Evan Stade 2013/04/15 19:25:13 size_t
hajimehoshi 2013/04/16 02:01:42 Done.
44 const char* key = keys[i];
45 const PrefService::Preference* pref = prefs->FindPreference(key);
46 if (pref) {
47 const base::Value* value = pref->GetValue();
48 dict.Set(key, value->DeepCopy());
Evan Stade 2013/04/15 19:25:13 nit: combine these two lines
hajimehoshi 2013/04/16 02:01:42 Done.
49 }
50 }
51
52 SendMessage("prefsUpdated", dict);
53 }
54
55 void TranslateInternalsHandler::SendMessage(const std::string& message,
56 const base::Value& value) {
57 const char func[] = "cr.translateInternals.messageHandler";
58 scoped_ptr<base::Value> message_data(new base::StringValue(message));
Evan Stade 2013/04/15 19:25:13 no need for heap allocation
hajimehoshi 2013/04/16 02:01:42 Done.
59 web_ui()->CallJavascriptFunction(func, *message_data, value);
60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698