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

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 trivial 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 (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 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 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.
44 for (unsigned i = 0; i < arraysize(keys); ++i) {
45 const char* key = keys[i];
46 const base::Value* value;
47 if (pref_values->Get(key, &value)) {
48 base::Value* copied_value = value->DeepCopy();
49 // 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.
50 dict.Set(key, copied_value);
51 }
52 }
53
54 SendMessage("prefsUpdated", dict);
55 }
56
57 void TranslateInternalsHandler::SendMessage(const std::string& message,
58 const base::Value& value) {
59 const char func[] = "cr.translateInternals.messageHandler";
60 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.
61 web_ui()->CallJavascriptFunction(func, *message_data, value);
62 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698