OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/net/net_error_helper.h" | 5 #include "chrome/renderer/net/net_error_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 89 } |
90 | 90 |
91 NetErrorHelper::~NetErrorHelper() { | 91 NetErrorHelper::~NetErrorHelper() { |
92 RenderThread::Get()->RemoveObserver(this); | 92 RenderThread::Get()->RemoveObserver(this); |
93 } | 93 } |
94 | 94 |
95 void NetErrorHelper::ReloadButtonPressed() { | 95 void NetErrorHelper::ReloadButtonPressed() { |
96 core_->ExecuteButtonPress(NetErrorHelperCore::RELOAD_BUTTON); | 96 core_->ExecuteButtonPress(NetErrorHelperCore::RELOAD_BUTTON); |
97 } | 97 } |
98 | 98 |
99 void NetErrorHelper::LoadStaleButtonPressed() { | 99 void NetErrorHelper::ShowSavedCopyButtonPressed() { |
100 core_->ExecuteButtonPress(NetErrorHelperCore::LOAD_STALE_BUTTON); | 100 core_->ExecuteButtonPress(NetErrorHelperCore::SHOW_SAVED_COPY_BUTTON); |
101 } | 101 } |
102 | 102 |
103 void NetErrorHelper::MoreButtonPressed() { | 103 void NetErrorHelper::MoreButtonPressed() { |
104 core_->ExecuteButtonPress(NetErrorHelperCore::MORE_BUTTON); | 104 core_->ExecuteButtonPress(NetErrorHelperCore::MORE_BUTTON); |
105 } | 105 } |
106 | 106 |
107 void NetErrorHelper::DidStartProvisionalLoad() { | 107 void NetErrorHelper::DidStartProvisionalLoad() { |
108 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 108 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
109 core_->OnStartLoad(GetFrameType(frame), GetLoadingPageType(frame)); | 109 core_->OnStartLoad(GetFrameType(frame), GetLoadingPageType(frame)); |
110 } | 110 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 164 |
165 void NetErrorHelper::TrackClick(int tracking_id) { | 165 void NetErrorHelper::TrackClick(int tracking_id) { |
166 core_->TrackClick(tracking_id); | 166 core_->TrackClick(tracking_id); |
167 } | 167 } |
168 | 168 |
169 void NetErrorHelper::GenerateLocalizedErrorPage( | 169 void NetErrorHelper::GenerateLocalizedErrorPage( |
170 const blink::WebURLError& error, | 170 const blink::WebURLError& error, |
171 bool is_failed_post, | 171 bool is_failed_post, |
172 scoped_ptr<ErrorPageParams> params, | 172 scoped_ptr<ErrorPageParams> params, |
173 bool* reload_button_shown, | 173 bool* reload_button_shown, |
174 bool* load_stale_button_shown, | 174 bool* show_saved_copy_button_shown, |
175 std::string* error_html) const { | 175 std::string* error_html) const { |
176 error_html->clear(); | 176 error_html->clear(); |
177 | 177 |
178 int resource_id = IDR_NET_ERROR_HTML; | 178 int resource_id = IDR_NET_ERROR_HTML; |
179 const base::StringPiece template_html( | 179 const base::StringPiece template_html( |
180 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); | 180 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
181 if (template_html.empty()) { | 181 if (template_html.empty()) { |
182 NOTREACHED() << "unable to load template."; | 182 NOTREACHED() << "unable to load template."; |
183 } else { | 183 } else { |
184 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
185 bool load_stale_cache_enabled = | |
186 command_line->HasSwitch(switches::kEnableOfflineLoadStaleCache); | |
187 | |
188 base::DictionaryValue error_strings; | 184 base::DictionaryValue error_strings; |
189 LocalizedError::GetStrings(error.reason, error.domain.utf8(), | 185 LocalizedError::GetStrings(error.reason, error.domain.utf8(), |
190 error.unreachableURL, is_failed_post, | 186 error.unreachableURL, is_failed_post, |
191 (load_stale_cache_enabled && | 187 error.staleCopyInCache, |
192 error.staleCopyInCache && !is_failed_post), | |
193 RenderThread::Get()->GetLocale(), | 188 RenderThread::Get()->GetLocale(), |
194 render_frame()->GetRenderView()-> | 189 render_frame()->GetRenderView()-> |
195 GetAcceptLanguages(), | 190 GetAcceptLanguages(), |
196 params.Pass(), &error_strings); | 191 params.Pass(), &error_strings); |
197 *reload_button_shown = error_strings.Get("reloadButton", NULL); | 192 *reload_button_shown = error_strings.Get("reloadButton", NULL); |
198 *load_stale_button_shown = error_strings.Get("staleLoadButton", NULL); | 193 *show_saved_copy_button_shown = |
| 194 error_strings.Get("showSavedCopyButton", NULL); |
199 | 195 |
200 // "t" is the id of the template's root node. | 196 // "t" is the id of the template's root node. |
201 *error_html = webui::GetTemplatesHtml(template_html, &error_strings, "t"); | 197 *error_html = webui::GetTemplatesHtml(template_html, &error_strings, "t"); |
202 } | 198 } |
203 } | 199 } |
204 | 200 |
205 void NetErrorHelper::LoadErrorPageInMainFrame(const std::string& html, | 201 void NetErrorHelper::LoadErrorPageInMainFrame(const std::string& html, |
206 const GURL& failed_url) { | 202 const GURL& failed_url) { |
207 blink::WebView* web_view = render_frame()->GetRenderView()->GetWebView(); | 203 blink::WebView* web_view = render_frame()->GetRenderView()->GetWebView(); |
208 if (!web_view) | 204 if (!web_view) |
209 return; | 205 return; |
210 blink::WebFrame* frame = web_view->mainFrame(); | 206 blink::WebFrame* frame = web_view->mainFrame(); |
211 frame->loadHTMLString(html, GURL(kUnreachableWebDataURL), failed_url, true); | 207 frame->loadHTMLString(html, GURL(kUnreachableWebDataURL), failed_url, true); |
212 } | 208 } |
213 | 209 |
214 void NetErrorHelper::EnablePageHelperFunctions() { | 210 void NetErrorHelper::EnablePageHelperFunctions() { |
215 NetErrorPageController::Install(render_frame()); | 211 NetErrorPageController::Install(render_frame()); |
216 } | 212 } |
217 | 213 |
218 void NetErrorHelper::UpdateErrorPage(const blink::WebURLError& error, | 214 void NetErrorHelper::UpdateErrorPage(const blink::WebURLError& error, |
219 bool is_failed_post) { | 215 bool is_failed_post) { |
220 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
221 bool load_stale_cache_enabled = | |
222 command_line->HasSwitch(switches::kEnableOfflineLoadStaleCache); | |
223 | |
224 base::DictionaryValue error_strings; | 216 base::DictionaryValue error_strings; |
225 LocalizedError::GetStrings(error.reason, | 217 LocalizedError::GetStrings(error.reason, |
226 error.domain.utf8(), | 218 error.domain.utf8(), |
227 error.unreachableURL, | 219 error.unreachableURL, |
228 is_failed_post, | 220 is_failed_post, |
229 (load_stale_cache_enabled && | 221 error.staleCopyInCache, |
230 error.staleCopyInCache && !is_failed_post), | |
231 RenderThread::Get()->GetLocale(), | 222 RenderThread::Get()->GetLocale(), |
232 render_frame()->GetRenderView()-> | 223 render_frame()->GetRenderView()-> |
233 GetAcceptLanguages(), | 224 GetAcceptLanguages(), |
234 scoped_ptr<ErrorPageParams>(), | 225 scoped_ptr<ErrorPageParams>(), |
235 &error_strings); | 226 &error_strings); |
236 | 227 |
237 std::string json; | 228 std::string json; |
238 JSONWriter::Write(&error_strings, &json); | 229 JSONWriter::Write(&error_strings, &json); |
239 | 230 |
240 std::string js = "if (window.updateForDnsProbe) " | 231 std::string js = "if (window.updateForDnsProbe) " |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 success ? data : "", | 338 success ? data : "", |
348 render_frame()->GetRenderView()->GetAcceptLanguages(), | 339 render_frame()->GetRenderView()->GetAcceptLanguages(), |
349 base::i18n::IsRTL()); | 340 base::i18n::IsRTL()); |
350 } | 341 } |
351 | 342 |
352 void NetErrorHelper::OnTrackingRequestComplete( | 343 void NetErrorHelper::OnTrackingRequestComplete( |
353 const blink::WebURLResponse& response, | 344 const blink::WebURLResponse& response, |
354 const std::string& data) { | 345 const std::string& data) { |
355 tracking_fetcher_.reset(); | 346 tracking_fetcher_.reset(); |
356 } | 347 } |
OLD | NEW |