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

Side by Side Diff: chrome/renderer/localized_error.cc

Issue 31014: Port DictionaryValue to use string16 instead of wstring. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/pref_service.cc ('k') | chrome/renderer/render_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/renderer/localized_error.h" 5 #include "chrome/renderer/localized_error.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/common/l10n_util.h" 10 #include "chrome/common/l10n_util.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 IDS_ERRORPAGES_DETAILS_TOO_MANY_REDIRECTS, 79 IDS_ERRORPAGES_DETAILS_TOO_MANY_REDIRECTS,
80 SUGGEST_RELOAD | SUGGEST_LEARNMORE, 80 SUGGEST_RELOAD | SUGGEST_LEARNMORE,
81 }, 81 },
82 }; 82 };
83 83
84 } // namespace 84 } // namespace
85 85
86 void GetLocalizedErrorValues(const WebError& error, 86 void GetLocalizedErrorValues(const WebError& error,
87 DictionaryValue* error_strings) { 87 DictionaryValue* error_strings) {
88 // Grab strings that are applicable to all error pages 88 // Grab strings that are applicable to all error pages
89 error_strings->SetString(L"detailsLink", 89 error_strings->SetString(
90 l10n_util::GetString(IDS_ERRORPAGES_DETAILS_LINK)); 90 ASCIIToUTF16("detailsLink"),
91 error_strings->SetString(L"detailsHeading", 91 WideToUTF16Hack(l10n_util::GetString(IDS_ERRORPAGES_DETAILS_LINK)));
92 l10n_util::GetString(IDS_ERRORPAGES_DETAILS_HEADING)); 92 error_strings->SetString(
93 ASCIIToUTF16("detailsHeading"),
94 WideToUTF16Hack(l10n_util::GetString(IDS_ERRORPAGES_DETAILS_HEADING)));
93 95
94 // Grab the strings and settings that depend on the error type. Init 96 // Grab the strings and settings that depend on the error type. Init
95 // options with default values. 97 // options with default values.
96 WebErrorNetErrorMap options = { 98 WebErrorNetErrorMap options = {
97 0, 99 0,
98 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, 100 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
99 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, 101 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
100 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE, 102 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
101 IDS_ERRORPAGES_DETAILS_UNKNOWN, 103 IDS_ERRORPAGES_DETAILS_UNKNOWN,
102 SUGGEST_NONE, 104 SUGGEST_NONE,
103 }; 105 };
104 int error_code = error.GetErrorCode(); 106 int error_code = error.GetErrorCode();
105 for (size_t i = 0; i < arraysize(net_error_options); ++i) { 107 for (size_t i = 0; i < arraysize(net_error_options); ++i) {
106 if (net_error_options[i].error_code == error_code) { 108 if (net_error_options[i].error_code == error_code) {
107 memcpy(&options, &net_error_options[i], sizeof(WebErrorNetErrorMap)); 109 memcpy(&options, &net_error_options[i], sizeof(WebErrorNetErrorMap));
108 break; 110 break;
109 } 111 }
110 } 112 }
111 113
112 std::wstring suggestions_heading; 114 std::wstring suggestions_heading;
113 if (options.suggestions != SUGGEST_NONE) { 115 if (options.suggestions != SUGGEST_NONE) {
114 suggestions_heading = 116 suggestions_heading =
115 l10n_util::GetString(IDS_ERRORPAGES_SUGGESTION_HEADING); 117 l10n_util::GetString(IDS_ERRORPAGES_SUGGESTION_HEADING);
116 } 118 }
117 error_strings->SetString(L"suggestionsHeading", suggestions_heading); 119 error_strings->SetString(ASCIIToUTF16("suggestionsHeading"),
120 WideToUTF16Hack(suggestions_heading));
118 121
119 std::wstring failed_url(ASCIIToWide(error.GetFailedURL().spec())); 122 std::wstring failed_url(ASCIIToWide(error.GetFailedURL().spec()));
120 // URLs are always LTR. 123 // URLs are always LTR.
121 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) 124 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
122 l10n_util::WrapStringWithLTRFormatting(&failed_url); 125 l10n_util::WrapStringWithLTRFormatting(&failed_url);
123 error_strings->SetString(L"title", 126 error_strings->SetString(
124 l10n_util::GetStringF(options.title_resource_id, 127 ASCIIToUTF16("title"),
125 failed_url)); 128 WideToUTF16Hack(l10n_util::GetStringF(options.title_resource_id,
126 error_strings->SetString(L"heading", 129 failed_url)));
127 l10n_util::GetString(options.heading_resource_id)); 130 error_strings->SetString(
131 ASCIIToUTF16("heading"),
132 WideToUTF16Hack(l10n_util::GetString(options.heading_resource_id)));
128 133
129 DictionaryValue* summary = new DictionaryValue; 134 DictionaryValue* summary = new DictionaryValue;
130 summary->SetString(L"msg", 135 summary->SetString(
131 l10n_util::GetString(options.summary_resource_id)); 136 ASCIIToUTF16("msg"),
137 WideToUTF16Hack(l10n_util::GetString(options.summary_resource_id)));
132 // TODO(tc): we want the unicode url here since it's being displayed 138 // TODO(tc): we want the unicode url here since it's being displayed
133 summary->SetString(L"failedUrl", failed_url); 139 summary->SetString(ASCIIToUTF16("failedUrl"), WideToUTF16Hack(failed_url));
134 error_strings->Set(L"summary", summary); 140 error_strings->Set(ASCIIToUTF16("summary"), summary);
135 141
136 // Error codes are expected to be negative 142 // Error codes are expected to be negative
137 DCHECK(error_code < 0); 143 DCHECK(error_code < 0);
138 std::wstring details = l10n_util::GetString(options.details_resource_id); 144 std::wstring details = l10n_util::GetString(options.details_resource_id);
139 error_strings->SetString(L"details", 145 error_strings->SetString(
140 l10n_util::GetStringF(IDS_ERRORPAGES_DETAILS_TEMPLATE, 146 ASCIIToUTF16("details"),
141 IntToWString(-error_code), 147 WideToUTF16Hack(l10n_util::GetStringF(
142 ASCIIToWide(net::ErrorToString(error_code)), 148 IDS_ERRORPAGES_DETAILS_TEMPLATE,
143 details)); 149 IntToWString(-error_code),
150 ASCIIToWide(net::ErrorToString(error_code)),
151 details)));
144 152
145 if (options.suggestions & SUGGEST_RELOAD) { 153 if (options.suggestions & SUGGEST_RELOAD) {
146 DictionaryValue* suggest_reload = new DictionaryValue; 154 DictionaryValue* suggest_reload = new DictionaryValue;
147 suggest_reload->SetString(L"msg", 155 suggest_reload->SetString(
148 l10n_util::GetString(IDS_ERRORPAGES_SUGGESTION_RELOAD)); 156 ASCIIToUTF16("msg"),
149 suggest_reload->SetString(L"reloadUrl", failed_url); 157 WideToUTF16Hack(l10n_util::GetString(
150 error_strings->Set(L"suggestionsReload", suggest_reload); 158 IDS_ERRORPAGES_SUGGESTION_RELOAD)));
159 suggest_reload->SetString(ASCIIToUTF16("reloadUrl"),
160 WideToUTF16Hack(failed_url));
161 error_strings->Set(ASCIIToUTF16("suggestionsReload"), suggest_reload);
151 } 162 }
152 163
153 if (options.suggestions & SUGGEST_HOSTNAME) { 164 if (options.suggestions & SUGGEST_HOSTNAME) {
154 // Only show the "Go to hostname" suggestion if the failed_url has a path. 165 // Only show the "Go to hostname" suggestion if the failed_url has a path.
155 const GURL& failed_url = error.GetFailedURL(); 166 const GURL& failed_url = error.GetFailedURL();
156 if (std::string() == failed_url.path()) { 167 if (std::string() == failed_url.path()) {
157 DictionaryValue* suggest_home_page = new DictionaryValue; 168 DictionaryValue* suggest_home_page = new DictionaryValue;
158 suggest_home_page->SetString(L"suggestionsHomepageMsg", 169 suggest_home_page->SetString(
159 l10n_util::GetString(IDS_ERRORPAGES_SUGGESTION_HOMEPAGE)); 170 ASCIIToUTF16("suggestionsHomepageMsg"),
171 WideToUTF16Hack(l10n_util::GetString(
172 IDS_ERRORPAGES_SUGGESTION_HOMEPAGE)));
160 std::wstring homepage(ASCIIToWide(failed_url.GetWithEmptyPath().spec())); 173 std::wstring homepage(ASCIIToWide(failed_url.GetWithEmptyPath().spec()));
161 // URLs are always LTR. 174 // URLs are always LTR.
162 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) 175 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
163 l10n_util::WrapStringWithLTRFormatting(&homepage); 176 l10n_util::WrapStringWithLTRFormatting(&homepage);
164 suggest_home_page->SetString(L"homePage", homepage); 177 suggest_home_page->SetString(ASCIIToUTF16("homePage"),
178 WideToUTF16Hack(homepage));
165 // TODO(tc): we actually want the unicode hostname 179 // TODO(tc): we actually want the unicode hostname
166 suggest_home_page->SetString(L"hostName", 180 suggest_home_page->SetString(ASCIIToUTF16("hostName"),
167 ASCIIToWide(failed_url.host())); 181 UTF8ToUTF16(failed_url.host()));
168 error_strings->Set(L"suggestionsHomepage", suggest_home_page); 182 error_strings->Set(ASCIIToUTF16("suggestionsHomepage"),
183 suggest_home_page);
169 } 184 }
170 } 185 }
171 186
172 if (options.suggestions & SUGGEST_LEARNMORE) { 187 if (options.suggestions & SUGGEST_LEARNMORE) {
173 GURL learn_more_url; 188 GURL learn_more_url;
174 switch (options.error_code) { 189 switch (options.error_code) {
175 case net::ERR_TOO_MANY_REDIRECTS: 190 case net::ERR_TOO_MANY_REDIRECTS:
176 learn_more_url = GURL(kRedirectLoopLearnMoreUrl); 191 learn_more_url = GURL(kRedirectLoopLearnMoreUrl);
177 break; 192 break;
178 default: 193 default:
179 break; 194 break;
180 } 195 }
181 196
182 if (learn_more_url.is_valid()) { 197 if (learn_more_url.is_valid()) {
183 // Add the language parameter to the URL. 198 // Add the language parameter to the URL.
184 std::string query = learn_more_url.query() + "&hl=" + 199 std::string query = learn_more_url.query() + "&hl=" +
185 WideToASCII(webkit_glue::GetWebKitLocale()); 200 WideToASCII(webkit_glue::GetWebKitLocale());
186 GURL::Replacements repl; 201 GURL::Replacements repl;
187 repl.SetQueryStr(query); 202 repl.SetQueryStr(query);
188 learn_more_url = learn_more_url.ReplaceComponents(repl); 203 learn_more_url = learn_more_url.ReplaceComponents(repl);
189 204
190 DictionaryValue* suggest_learn_more = new DictionaryValue; 205 DictionaryValue* suggest_learn_more = new DictionaryValue;
191 suggest_learn_more->SetString(L"msg", 206 suggest_learn_more->SetString(
192 l10n_util::GetString(IDS_ERRORPAGES_SUGGESTION_LEARNMORE)); 207 ASCIIToUTF16("msg"),
193 suggest_learn_more->SetString(L"learnMoreUrl", 208 WideToUTF16Hack(l10n_util::GetString(
194 ASCIIToWide(learn_more_url.spec())); 209 IDS_ERRORPAGES_SUGGESTION_LEARNMORE)));
195 error_strings->Set(L"suggestionsLearnMore", suggest_learn_more); 210 suggest_learn_more->SetString(ASCIIToUTF16("learnMoreUrl"),
211 UTF8ToUTF16(learn_more_url.spec()));
212 error_strings->Set(ASCIIToUTF16("suggestionsLearnMore"),
213 suggest_learn_more);
196 } 214 }
197 } 215 }
198 } 216 }
199 217
200 void GetFormRepostErrorValues(const GURL& display_url, 218 void GetFormRepostErrorValues(const GURL& display_url,
201 DictionaryValue* error_strings) { 219 DictionaryValue* error_strings) {
202 std::wstring failed_url(ASCIIToWide(display_url.spec())); 220 std::wstring failed_url(ASCIIToWide(display_url.spec()));
203 // URLs are always LTR. 221 // URLs are always LTR.
204 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) 222 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
205 l10n_util::WrapStringWithLTRFormatting(&failed_url); 223 l10n_util::WrapStringWithLTRFormatting(&failed_url);
206 error_strings->SetString( 224 error_strings->SetString(
207 L"title", l10n_util::GetStringF(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, 225 ASCIIToUTF16("title"),
208 failed_url.c_str())); 226 WideToUTF16Hack(l10n_util::GetStringF(
209 error_strings->SetString(L"heading", 227 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
210 l10n_util::GetString(IDS_HTTP_POST_WARNING_TITLE)); 228 failed_url.c_str())));
211 error_strings->SetString(L"suggestionsHeading", L""); 229 error_strings->SetString(
230 ASCIIToUTF16("heading"),
231 WideToUTF16Hack(l10n_util::GetString(IDS_HTTP_POST_WARNING_TITLE)));
232 error_strings->SetString(ASCIIToUTF16("suggestionsHeading"),
233 ASCIIToUTF16(""));
212 DictionaryValue* summary = new DictionaryValue; 234 DictionaryValue* summary = new DictionaryValue;
213 summary->SetString(L"msg", 235 summary->SetString(
214 l10n_util::GetString(IDS_ERRORPAGES_HTTP_POST_WARNING)); 236 ASCIIToUTF16("msg"),
215 error_strings->Set(L"summary", summary); 237 WideToUTF16Hack(l10n_util::GetString(IDS_ERRORPAGES_HTTP_POST_WARNING)));
238 error_strings->Set(ASCIIToUTF16("summary"), summary);
216 } 239 }
OLDNEW
« no previous file with comments | « chrome/common/pref_service.cc ('k') | chrome/renderer/render_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698