OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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/remoting/remoting_resources_source.h" | |
6 | |
7 #include <algorithm> | |
8 #include <string> | |
9 | |
10 #include "base/message_loop.h" | |
11 #include "base/utf_string_conversions.h" | |
12 #include "base/values.h" | |
13 #include "chrome/browser/google/google_util.h" | |
14 #include "chrome/common/jstemplate_builder.h" | |
15 #include "googleurl/src/gurl.h" | |
16 #include "grit/app_resources.h" | |
17 #include "grit/browser_resources.h" | |
18 #include "grit/chromium_strings.h" | |
19 #include "grit/generated_resources.h" | |
20 #include "grit/locale_settings.h" | |
21 #include "ui/base/l10n/l10n_util.h" | |
22 #include "ui/base/resource/resource_bundle.h" | |
23 | |
24 // Define the values of standard URLs. | |
25 const char RemotingResourcesSource::kInvalidPasswordHelpUrl[] = | |
26 "https://www.google.com/support/accounts/bin/answer.py?ctx=ch&answer=27444"; | |
27 const char RemotingResourcesSource::kCanNotAccessAccountUrl[] = | |
28 "https://www.google.com/support/accounts/bin/answer.py?answer=48598"; | |
29 const char RemotingResourcesSource::kCreateNewAccountUrl[] = | |
30 "https://www.google.com/accounts/NewAccount?service=chromiumsync"; | |
31 | |
32 RemotingResourcesSource::RemotingResourcesSource() | |
33 : DataSource(chrome::kChromeUIRemotingResourcesHost, | |
34 MessageLoop::current()) { | |
35 } | |
36 | |
37 void RemotingResourcesSource::StartDataRequest(const std::string& path_raw, | |
38 bool is_incognito, | |
39 int request_id) { | |
40 const char kRemotingGaiaLoginPath[] = "gaialogin"; | |
41 const char kRemotingSetupFlowPath[] = "setup"; | |
42 const char kRemotingSetupDonePath[] = "setupdone"; | |
43 const char kRemotingSettingUpPath[] = "settingup"; | |
44 const char kRemotingSetupErrorPath[] = "setuperror"; | |
45 | |
46 std::string response; | |
47 if (path_raw == kRemotingGaiaLoginPath) { | |
48 DictionaryValue localized_strings; | |
49 | |
50 // Start by setting the per-locale URLs we show on the setup wizard. | |
51 localized_strings.SetString("invalidpasswordhelpurl", | |
52 GetLocalizedUrl(kInvalidPasswordHelpUrl)); | |
53 localized_strings.SetString("cannotaccessaccounturl", | |
54 GetLocalizedUrl(kCanNotAccessAccountUrl)); | |
55 localized_strings.SetString("createnewaccounturl", | |
56 GetLocalizedUrl(kCreateNewAccountUrl)); | |
57 | |
58 localized_strings.SetString("settingupsync", | |
59 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_SETTING_UP_SYNC)); | |
60 localized_strings.SetString("introduction", ""); | |
61 localized_strings.SetString("signinprefix", | |
62 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_SIGNIN_PREFIX)); | |
63 localized_strings.SetString("signinsuffix", | |
64 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_SIGNIN_SUFFIX)); | |
65 localized_strings.SetString("cannotbeblank", | |
66 l10n_util::GetStringUTF16(IDS_SYNC_CANNOT_BE_BLANK)); | |
67 localized_strings.SetString("emaillabel", | |
68 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_EMAIL)); | |
69 localized_strings.SetString("passwordlabel", | |
70 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_PASSWORD)); | |
71 localized_strings.SetString("invalidcredentials", | |
72 l10n_util::GetStringUTF16(IDS_SYNC_INVALID_USER_CREDENTIALS)); | |
73 localized_strings.SetString("signin", | |
74 l10n_util::GetStringUTF16(IDS_SYNC_SIGNIN)); | |
75 localized_strings.SetString("couldnotconnect", | |
76 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_COULD_NOT_CONNECT)); | |
77 localized_strings.SetString("cannotaccessaccount", | |
78 l10n_util::GetStringUTF16(IDS_SYNC_CANNOT_ACCESS_ACCOUNT)); | |
79 localized_strings.SetString("createaccount", | |
80 l10n_util::GetStringUTF16(IDS_SYNC_CREATE_ACCOUNT)); | |
81 localized_strings.SetString("cancel", | |
82 l10n_util::GetStringUTF16(IDS_CANCEL)); | |
83 localized_strings.SetString("settingup", | |
84 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_SETTING_UP)); | |
85 localized_strings.SetString("success", | |
86 l10n_util::GetStringUTF16(IDS_SYNC_SUCCESS)); | |
87 localized_strings.SetString("errorsigningin", | |
88 l10n_util::GetStringUTF16(IDS_SYNC_ERROR_SIGNING_IN)); | |
89 localized_strings.SetString("captchainstructions", | |
90 l10n_util::GetStringUTF16(IDS_SYNC_GAIA_CAPTCHA_INSTRUCTIONS)); | |
91 localized_strings.SetString("invalidaccesscode", | |
92 l10n_util::GetStringUTF16(IDS_SYNC_INVALID_ACCESS_CODE_LABEL)); | |
93 localized_strings.SetString("enteraccesscode", | |
94 l10n_util::GetStringUTF16(IDS_SYNC_ENTER_ACCESS_CODE_LABEL)); | |
95 localized_strings.SetString("getaccesscodehelp", | |
96 l10n_util::GetStringUTF16(IDS_SYNC_ACCESS_CODE_HELP_LABEL)); | |
97 localized_strings.SetString("getaccesscodeurl", | |
98 l10n_util::GetStringUTF16(IDS_SYNC_GET_ACCESS_CODE_URL)); | |
99 | |
100 static const base::StringPiece html(ResourceBundle::GetSharedInstance() | |
101 .GetRawDataResource(IDR_GAIA_LOGIN_HTML)); | |
102 SetFontAndTextDirection(&localized_strings); | |
103 response = jstemplate_builder::GetI18nTemplateHtml( | |
104 html, &localized_strings); | |
105 } else if (path_raw == kRemotingSettingUpPath) { | |
106 DictionaryValue localized_strings; | |
107 localized_strings.SetString("settingup", | |
108 l10n_util::GetStringUTF16(IDS_REMOTING_SETTING_UP_MESSAGE)); | |
109 localized_strings.SetString("cancel", | |
110 l10n_util::GetStringUTF16(IDS_CANCEL)); | |
111 static const base::StringPiece html(ResourceBundle::GetSharedInstance() | |
112 .GetRawDataResource(IDR_REMOTING_SETTING_UP_HTML)); | |
113 SetFontAndTextDirection(&localized_strings); | |
114 response = jstemplate_builder::GetI18nTemplateHtml( | |
115 html, &localized_strings); | |
116 } else if (path_raw == kRemotingSetupDonePath) { | |
117 DictionaryValue localized_strings; | |
118 localized_strings.SetString("success", | |
119 l10n_util::GetStringUTF16(IDS_REMOTING_SUCCESS_TITLE)); | |
120 localized_strings.SetString("okay", | |
121 l10n_util::GetStringUTF16(IDS_OK)); | |
122 static const base::StringPiece html(ResourceBundle::GetSharedInstance() | |
123 .GetRawDataResource(IDR_REMOTING_SETUP_DONE_HTML)); | |
124 SetFontAndTextDirection(&localized_strings); | |
125 response = jstemplate_builder::GetI18nTemplateHtml( | |
126 html, &localized_strings); | |
127 } else if (path_raw == kRemotingSetupErrorPath) { | |
128 DictionaryValue localized_strings; | |
129 localized_strings.SetString("close", | |
130 l10n_util::GetStringUTF16(IDS_CLOSE)); | |
131 localized_strings.SetString("retry", | |
132 l10n_util::GetStringUTF16(IDS_REMOTING_RETRY_BUTTON_TEXT)); | |
133 static const base::StringPiece html(ResourceBundle::GetSharedInstance() | |
134 .GetRawDataResource(IDR_REMOTING_SETUP_ERROR_HTML)); | |
135 SetFontAndTextDirection(&localized_strings); | |
136 response = jstemplate_builder::GetI18nTemplateHtml( | |
137 html, &localized_strings); | |
138 } else if (path_raw == kRemotingSetupFlowPath) { | |
139 static const base::StringPiece html(ResourceBundle::GetSharedInstance() | |
140 .GetRawDataResource(IDR_REMOTING_SETUP_FLOW_HTML)); | |
141 response = html.as_string(); | |
142 } | |
143 // Send the response. | |
144 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | |
145 html_bytes->data.resize(response.size()); | |
146 std::copy(response.begin(), response.end(), html_bytes->data.begin()); | |
147 SendResponse(request_id, html_bytes); | |
148 } | |
149 | |
150 std::string RemotingResourcesSource::GetMimeType( | |
151 const std::string& path) const { | |
152 return "text/html"; | |
153 } | |
154 | |
155 std::string RemotingResourcesSource::GetLocalizedUrl( | |
156 const std::string& url) const { | |
157 GURL original_url(url); | |
158 DCHECK(original_url.is_valid()); | |
159 GURL localized_url = google_util::AppendGoogleLocaleParam(original_url); | |
160 return localized_url.spec(); | |
161 } | |
OLD | NEW |