OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/translate_internals/translate_internals_ui.h" | 5 #include "chrome/browser/ui/webui/translate_internals/translate_internals_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/webui/translate_internals/translate_internals_handle
r.h" | 15 #include "chrome/browser/ui/webui/translate_internals/translate_internals_handle
r.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 18 #include "components/translate/content/common/cld_data_source.h" |
18 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
19 #include "content/public/browser/web_ui.h" | 20 #include "content/public/browser/web_ui.h" |
20 #include "content/public/browser/web_ui_data_source.h" | 21 #include "content/public/browser/web_ui_data_source.h" |
21 #include "grit/browser_resources.h" | 22 #include "grit/browser_resources.h" |
22 #include "grit/translate_internals_resources.h" | 23 #include "grit/translate_internals_resources.h" |
23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
25 | 26 |
26 // Macro stringification. | |
27 // https://gcc.gnu.org/onlinedocs/cpp/Stringification.html | |
28 #define XSTR(S) STR(S) | |
29 #define STR(S) #S | |
30 | |
31 namespace { | 27 namespace { |
32 | 28 |
33 // Sets the languages to |dict|. Each key is a language code and each value is | 29 // Sets the languages to |dict|. Each key is a language code and each value is |
34 // a language name in the locale. | 30 // a language name in the locale. |
35 void GetLanguages(base::DictionaryValue* dict) { | 31 void GetLanguages(base::DictionaryValue* dict) { |
36 DCHECK(dict); | 32 DCHECK(dict); |
37 | 33 |
38 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 34 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
39 std::vector<std::string> language_codes; | 35 std::vector<std::string> language_codes; |
40 l10n_util::GetAcceptLanguagesForLocale(app_locale, &language_codes); | 36 l10n_util::GetAcceptLanguagesForLocale(app_locale, &language_codes); |
(...skipping 28 matching lines...) Expand all Loading... |
69 | 65 |
70 std::string cld_version = ""; | 66 std::string cld_version = ""; |
71 std::string cld_data_source = ""; | 67 std::string cld_data_source = ""; |
72 // The version strings are hardcoded here to avoid linking with the CLD | 68 // The version strings are hardcoded here to avoid linking with the CLD |
73 // library, see http://crbug.com/297777. | 69 // library, see http://crbug.com/297777. |
74 #if CLD_VERSION==1 | 70 #if CLD_VERSION==1 |
75 cld_version = "1.6"; | 71 cld_version = "1.6"; |
76 cld_data_source = "static"; // CLD1.x does not support dynamic data loading | 72 cld_data_source = "static"; // CLD1.x does not support dynamic data loading |
77 #elif CLD_VERSION==2 | 73 #elif CLD_VERSION==2 |
78 cld_version = "2"; | 74 cld_version = "2"; |
79 cld_data_source = std::string(XSTR(CLD2_DATA_SOURCE)); | 75 cld_data_source = translate::CldDataSource::GetName(); |
80 #else | 76 #else |
81 NOTREACHED(); | 77 NOTREACHED(); |
82 #endif | 78 #endif |
83 source->AddString("cld-version", cld_version); | 79 source->AddString("cld-version", cld_version); |
84 source->AddString("cld-data-source", cld_data_source); | 80 source->AddString("cld-data-source", cld_data_source); |
85 | 81 |
86 return source; | 82 return source; |
87 } | 83 } |
88 | 84 |
89 } // namespace | 85 } // namespace |
90 | 86 |
91 TranslateInternalsUI::TranslateInternalsUI(content::WebUI* web_ui) | 87 TranslateInternalsUI::TranslateInternalsUI(content::WebUI* web_ui) |
92 : WebUIController(web_ui) { | 88 : WebUIController(web_ui) { |
93 web_ui->AddMessageHandler(new TranslateInternalsHandler); | 89 web_ui->AddMessageHandler(new TranslateInternalsHandler); |
94 | 90 |
95 Profile* profile = Profile::FromWebUI(web_ui); | 91 Profile* profile = Profile::FromWebUI(web_ui); |
96 content::WebUIDataSource::Add(profile, CreateTranslateInternalsHTMLSource()); | 92 content::WebUIDataSource::Add(profile, CreateTranslateInternalsHTMLSource()); |
97 } | 93 } |
OLD | NEW |