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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 163 |
164 void NetErrorHelper::TrackClick(int tracking_id) { | 164 void NetErrorHelper::TrackClick(int tracking_id) { |
165 core_->TrackClick(tracking_id); | 165 core_->TrackClick(tracking_id); |
166 } | 166 } |
167 | 167 |
168 void NetErrorHelper::GenerateLocalizedErrorPage( | 168 void NetErrorHelper::GenerateLocalizedErrorPage( |
169 const blink::WebURLError& error, | 169 const blink::WebURLError& error, |
170 bool is_failed_post, | 170 bool is_failed_post, |
171 scoped_ptr<ErrorPageParams> params, | 171 scoped_ptr<ErrorPageParams> params, |
172 bool* reload_button_shown, | 172 bool* reload_button_shown, |
173 bool* load_stale_button_shown, | 173 bool* show_saved_copy_button_shown, |
174 std::string* error_html) const { | 174 std::string* error_html) const { |
175 error_html->clear(); | 175 error_html->clear(); |
176 | 176 |
177 int resource_id = IDR_NET_ERROR_HTML; | 177 int resource_id = IDR_NET_ERROR_HTML; |
178 const base::StringPiece template_html( | 178 const base::StringPiece template_html( |
179 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); | 179 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
180 if (template_html.empty()) { | 180 if (template_html.empty()) { |
181 NOTREACHED() << "unable to load template."; | 181 NOTREACHED() << "unable to load template."; |
182 } else { | 182 } else { |
183 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
184 bool load_stale_cache_enabled = | |
185 command_line->HasSwitch(switches::kEnableOfflineLoadStaleCache); | |
186 | |
187 base::DictionaryValue error_strings; | 183 base::DictionaryValue error_strings; |
188 LocalizedError::GetStrings(error.reason, error.domain.utf8(), | 184 LocalizedError::GetStrings(error.reason, error.domain.utf8(), |
189 error.unreachableURL, is_failed_post, | 185 error.unreachableURL, is_failed_post, |
190 (load_stale_cache_enabled && | 186 error.staleCopyInCache, |
191 error.staleCopyInCache && !is_failed_post), | |
192 RenderThread::Get()->GetLocale(), | 187 RenderThread::Get()->GetLocale(), |
193 render_frame()->GetRenderView()-> | 188 render_frame()->GetRenderView()-> |
194 GetAcceptLanguages(), | 189 GetAcceptLanguages(), |
195 params.Pass(), &error_strings); | 190 params.Pass(), &error_strings); |
196 *reload_button_shown = error_strings.Get("reloadButton", NULL); | 191 *reload_button_shown = error_strings.Get("reloadButton", NULL); |
197 *load_stale_button_shown = error_strings.Get("staleLoadButton", NULL); | 192 *show_saved_copy_button_shown = |
| 193 error_strings.Get("showSavedCopyButton", NULL); |
198 | 194 |
199 // "t" is the id of the template's root node. | 195 // "t" is the id of the template's root node. |
200 *error_html = webui::GetTemplatesHtml(template_html, &error_strings, "t"); | 196 *error_html = webui::GetTemplatesHtml(template_html, &error_strings, "t"); |
201 } | 197 } |
202 } | 198 } |
203 | 199 |
204 void NetErrorHelper::LoadErrorPageInMainFrame(const std::string& html, | 200 void NetErrorHelper::LoadErrorPageInMainFrame(const std::string& html, |
205 const GURL& failed_url) { | 201 const GURL& failed_url) { |
206 blink::WebView* web_view = render_frame()->GetRenderView()->GetWebView(); | 202 blink::WebView* web_view = render_frame()->GetRenderView()->GetWebView(); |
207 if (!web_view) | 203 if (!web_view) |
208 return; | 204 return; |
209 blink::WebFrame* frame = web_view->mainFrame(); | 205 blink::WebFrame* frame = web_view->mainFrame(); |
210 frame->loadHTMLString(html, GURL(kUnreachableWebDataURL), failed_url, true); | 206 frame->loadHTMLString(html, GURL(kUnreachableWebDataURL), failed_url, true); |
211 } | 207 } |
212 | 208 |
213 void NetErrorHelper::EnablePageHelperFunctions() { | 209 void NetErrorHelper::EnablePageHelperFunctions() { |
214 NetErrorPageController::Install(render_frame()); | 210 NetErrorPageController::Install(render_frame()); |
215 } | 211 } |
216 | 212 |
217 void NetErrorHelper::UpdateErrorPage(const blink::WebURLError& error, | 213 void NetErrorHelper::UpdateErrorPage(const blink::WebURLError& error, |
218 bool is_failed_post) { | 214 bool is_failed_post) { |
219 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
220 bool load_stale_cache_enabled = | |
221 command_line->HasSwitch(switches::kEnableOfflineLoadStaleCache); | |
222 | |
223 base::DictionaryValue error_strings; | 215 base::DictionaryValue error_strings; |
224 LocalizedError::GetStrings(error.reason, | 216 LocalizedError::GetStrings(error.reason, |
225 error.domain.utf8(), | 217 error.domain.utf8(), |
226 error.unreachableURL, | 218 error.unreachableURL, |
227 is_failed_post, | 219 is_failed_post, |
228 (load_stale_cache_enabled && | 220 error.staleCopyInCache, |
229 error.staleCopyInCache && !is_failed_post), | |
230 RenderThread::Get()->GetLocale(), | 221 RenderThread::Get()->GetLocale(), |
231 render_frame()->GetRenderView()-> | 222 render_frame()->GetRenderView()-> |
232 GetAcceptLanguages(), | 223 GetAcceptLanguages(), |
233 scoped_ptr<ErrorPageParams>(), | 224 scoped_ptr<ErrorPageParams>(), |
234 &error_strings); | 225 &error_strings); |
235 | 226 |
236 std::string json; | 227 std::string json; |
237 JSONWriter::Write(&error_strings, &json); | 228 JSONWriter::Write(&error_strings, &json); |
238 | 229 |
239 std::string js = "if (window.updateForDnsProbe) " | 230 std::string js = "if (window.updateForDnsProbe) " |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 success ? data : "", | 337 success ? data : "", |
347 render_frame()->GetRenderView()->GetAcceptLanguages(), | 338 render_frame()->GetRenderView()->GetAcceptLanguages(), |
348 base::i18n::IsRTL()); | 339 base::i18n::IsRTL()); |
349 } | 340 } |
350 | 341 |
351 void NetErrorHelper::OnTrackingRequestComplete( | 342 void NetErrorHelper::OnTrackingRequestComplete( |
352 const blink::WebURLResponse& response, | 343 const blink::WebURLResponse& response, |
353 const std::string& data) { | 344 const std::string& data) { |
354 tracking_fetcher_.reset(); | 345 tracking_fetcher_.reset(); |
355 } | 346 } |
OLD | NEW |