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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 bool NetErrorHelper::OnMessageReceived(const IPC::Message& message) { | 139 bool NetErrorHelper::OnMessageReceived(const IPC::Message& message) { |
140 bool handled = true; | 140 bool handled = true; |
141 | 141 |
142 IPC_BEGIN_MESSAGE_MAP(NetErrorHelper, message) | 142 IPC_BEGIN_MESSAGE_MAP(NetErrorHelper, message) |
143 IPC_MESSAGE_HANDLER(ChromeViewMsg_NetErrorInfo, OnNetErrorInfo) | 143 IPC_MESSAGE_HANDLER(ChromeViewMsg_NetErrorInfo, OnNetErrorInfo) |
144 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetCanShowNetworkDiagnosticsDialog, | 144 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetCanShowNetworkDiagnosticsDialog, |
145 OnSetCanShowNetworkDiagnosticsDialog); | 145 OnSetCanShowNetworkDiagnosticsDialog); |
146 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetNavigationCorrectionInfo, | 146 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetNavigationCorrectionInfo, |
147 OnSetNavigationCorrectionInfo); | 147 OnSetNavigationCorrectionInfo); |
| 148 #if defined(OS_ANDROID) |
| 149 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetHasOfflinePages, OnSetHasOfflinePages) |
| 150 #endif |
148 IPC_MESSAGE_UNHANDLED(handled = false) | 151 IPC_MESSAGE_UNHANDLED(handled = false) |
149 IPC_END_MESSAGE_MAP() | 152 IPC_END_MESSAGE_MAP() |
150 | 153 |
151 return handled; | 154 return handled; |
152 } | 155 } |
153 | 156 |
154 void NetErrorHelper::NetworkStateChanged(bool enabled) { | 157 void NetErrorHelper::NetworkStateChanged(bool enabled) { |
155 core_->NetworkStateChanged(enabled); | 158 core_->NetworkStateChanged(enabled); |
156 } | 159 } |
157 | 160 |
158 void NetErrorHelper::GetErrorHTML(const blink::WebURLError& error, | 161 void NetErrorHelper::GetErrorHTML(const blink::WebURLError& error, |
159 bool is_failed_post, | 162 bool is_failed_post, |
160 bool is_ignoring_cache, | 163 bool is_ignoring_cache, |
161 std::string* error_html) { | 164 std::string* error_html) { |
162 core_->GetErrorHTML(GetFrameType(render_frame()), error, is_failed_post, | 165 core_->GetErrorHTML(GetFrameType(render_frame()), error, is_failed_post, |
163 is_ignoring_cache, error_html); | 166 is_ignoring_cache, error_html); |
164 } | 167 } |
165 | 168 |
166 bool NetErrorHelper::ShouldSuppressErrorPage(const GURL& url) { | 169 bool NetErrorHelper::ShouldSuppressErrorPage(const GURL& url) { |
167 return core_->ShouldSuppressErrorPage(GetFrameType(render_frame()), url); | 170 return core_->ShouldSuppressErrorPage(GetFrameType(render_frame()), url); |
168 } | 171 } |
169 | 172 |
170 void NetErrorHelper::GenerateLocalizedErrorPage( | 173 void NetErrorHelper::GenerateLocalizedErrorPage( |
171 const blink::WebURLError& error, | 174 const blink::WebURLError& error, |
172 bool is_failed_post, | 175 bool is_failed_post, |
173 bool can_show_network_diagnostics_dialog, | 176 bool can_show_network_diagnostics_dialog, |
| 177 bool has_offline_pages, |
174 scoped_ptr<ErrorPageParams> params, | 178 scoped_ptr<ErrorPageParams> params, |
175 bool* reload_button_shown, | 179 bool* reload_button_shown, |
176 bool* show_saved_copy_button_shown, | 180 bool* show_saved_copy_button_shown, |
177 bool* show_cached_copy_button_shown, | 181 bool* show_cached_copy_button_shown, |
| 182 bool* show_saved_pages_button_shown, |
178 std::string* error_html) const { | 183 std::string* error_html) const { |
179 error_html->clear(); | 184 error_html->clear(); |
180 | 185 |
181 int resource_id = IDR_NET_ERROR_HTML; | 186 int resource_id = IDR_NET_ERROR_HTML; |
182 const base::StringPiece template_html( | 187 const base::StringPiece template_html( |
183 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); | 188 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
184 if (template_html.empty()) { | 189 if (template_html.empty()) { |
185 NOTREACHED() << "unable to load template."; | 190 NOTREACHED() << "unable to load template."; |
186 } else { | 191 } else { |
187 base::DictionaryValue error_strings; | 192 base::DictionaryValue error_strings; |
188 LocalizedError::GetStrings(error.reason, error.domain.utf8(), | 193 LocalizedError::GetStrings(error.reason, error.domain.utf8(), |
189 error.unreachableURL, is_failed_post, | 194 error.unreachableURL, is_failed_post, |
190 error.staleCopyInCache, | 195 error.staleCopyInCache, |
191 can_show_network_diagnostics_dialog, | 196 can_show_network_diagnostics_dialog, |
| 197 has_offline_pages, |
192 RenderThread::Get()->GetLocale(), | 198 RenderThread::Get()->GetLocale(), |
193 render_frame()->GetRenderView()-> | 199 render_frame()->GetRenderView()-> |
194 GetAcceptLanguages(), | 200 GetAcceptLanguages(), |
195 params.Pass(), &error_strings); | 201 params.Pass(), &error_strings); |
196 *reload_button_shown = error_strings.Get("reloadButton", nullptr); | 202 *reload_button_shown = error_strings.Get("reloadButton", nullptr); |
197 *show_saved_copy_button_shown = | 203 *show_saved_copy_button_shown = |
198 error_strings.Get("showSavedCopyButton", nullptr); | 204 error_strings.Get("showSavedCopyButton", nullptr); |
199 *show_cached_copy_button_shown = | 205 *show_cached_copy_button_shown = |
200 error_strings.Get("cacheButton", nullptr); | 206 error_strings.Get("cacheButton", nullptr); |
| 207 *show_saved_pages_button_shown = |
| 208 error_strings.Get("showSavedPagesButton", nullptr); |
201 // "t" is the id of the template's root node. | 209 // "t" is the id of the template's root node. |
202 *error_html = webui::GetTemplatesHtml(template_html, &error_strings, "t"); | 210 *error_html = webui::GetTemplatesHtml(template_html, &error_strings, "t"); |
203 } | 211 } |
204 } | 212 } |
205 | 213 |
206 void NetErrorHelper::LoadErrorPage(const std::string& html, | 214 void NetErrorHelper::LoadErrorPage(const std::string& html, |
207 const GURL& failed_url) { | 215 const GURL& failed_url) { |
208 render_frame()->GetWebFrame()->loadHTMLString( | 216 render_frame()->GetWebFrame()->loadHTMLString( |
209 html, GURL(kUnreachableWebDataURL), failed_url, true); | 217 html, GURL(kUnreachableWebDataURL), failed_url, true); |
210 } | 218 } |
211 | 219 |
212 void NetErrorHelper::EnablePageHelperFunctions() { | 220 void NetErrorHelper::EnablePageHelperFunctions() { |
213 NetErrorPageController::Install( | 221 NetErrorPageController::Install( |
214 render_frame(), weak_controller_delegate_factory_.GetWeakPtr()); | 222 render_frame(), weak_controller_delegate_factory_.GetWeakPtr()); |
215 } | 223 } |
216 | 224 |
217 void NetErrorHelper::UpdateErrorPage(const blink::WebURLError& error, | 225 void NetErrorHelper::UpdateErrorPage(const blink::WebURLError& error, |
218 bool is_failed_post, | 226 bool is_failed_post, |
219 bool can_show_network_diagnostics_dialog) { | 227 bool can_show_network_diagnostics_dialog, |
| 228 bool has_offline_pages) { |
220 base::DictionaryValue error_strings; | 229 base::DictionaryValue error_strings; |
221 LocalizedError::GetStrings(error.reason, | 230 LocalizedError::GetStrings(error.reason, |
222 error.domain.utf8(), | 231 error.domain.utf8(), |
223 error.unreachableURL, | 232 error.unreachableURL, |
224 is_failed_post, | 233 is_failed_post, |
225 error.staleCopyInCache, | 234 error.staleCopyInCache, |
226 can_show_network_diagnostics_dialog, | 235 can_show_network_diagnostics_dialog, |
| 236 has_offline_pages, |
227 RenderThread::Get()->GetLocale(), | 237 RenderThread::Get()->GetLocale(), |
228 render_frame()->GetRenderView()-> | 238 render_frame()->GetRenderView()-> |
229 GetAcceptLanguages(), | 239 GetAcceptLanguages(), |
230 scoped_ptr<ErrorPageParams>(), | 240 scoped_ptr<ErrorPageParams>(), |
231 &error_strings); | 241 &error_strings); |
232 | 242 |
233 std::string json; | 243 std::string json; |
234 JSONWriter::Write(error_strings, &json); | 244 JSONWriter::Write(error_strings, &json); |
235 | 245 |
236 std::string js = "if (window.updateForDnsProbe) " | 246 std::string js = "if (window.updateForDnsProbe) " |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 request.setCachePolicy(blink::WebURLRequest::ReturnCacheDataDontLoad); | 313 request.setCachePolicy(blink::WebURLRequest::ReturnCacheDataDontLoad); |
304 | 314 |
305 web_frame->loadRequest(request); | 315 web_frame->loadRequest(request); |
306 } | 316 } |
307 | 317 |
308 void NetErrorHelper::DiagnoseError(const GURL& page_url) { | 318 void NetErrorHelper::DiagnoseError(const GURL& page_url) { |
309 render_frame()->Send(new ChromeViewHostMsg_RunNetworkDiagnostics( | 319 render_frame()->Send(new ChromeViewHostMsg_RunNetworkDiagnostics( |
310 render_frame()->GetRoutingID(), page_url)); | 320 render_frame()->GetRoutingID(), page_url)); |
311 } | 321 } |
312 | 322 |
| 323 void NetErrorHelper::ShowOfflinePages() { |
| 324 #if defined(OS_ANDROID) |
| 325 render_frame()->Send(new ChromeViewHostMsg_ShowOfflinePages( |
| 326 render_frame()->GetRoutingID())); |
| 327 #endif |
| 328 } |
| 329 |
313 void NetErrorHelper::OnNetErrorInfo(int status_num) { | 330 void NetErrorHelper::OnNetErrorInfo(int status_num) { |
314 DCHECK(status_num >= 0 && status_num < error_page::DNS_PROBE_MAX); | 331 DCHECK(status_num >= 0 && status_num < error_page::DNS_PROBE_MAX); |
315 | 332 |
316 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num); | 333 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num); |
317 | 334 |
318 core_->OnNetErrorInfo(static_cast<DnsProbeStatus>(status_num)); | 335 core_->OnNetErrorInfo(static_cast<DnsProbeStatus>(status_num)); |
319 } | 336 } |
320 | 337 |
321 void NetErrorHelper::OnSetCanShowNetworkDiagnosticsDialog( | 338 void NetErrorHelper::OnSetCanShowNetworkDiagnosticsDialog( |
322 bool can_use_local_diagnostics_service) { | 339 bool can_use_local_diagnostics_service) { |
(...skipping 23 matching lines...) Expand all Loading... |
346 success ? data : "", | 363 success ? data : "", |
347 render_frame()->GetRenderView()->GetAcceptLanguages(), | 364 render_frame()->GetRenderView()->GetAcceptLanguages(), |
348 base::i18n::IsRTL()); | 365 base::i18n::IsRTL()); |
349 } | 366 } |
350 | 367 |
351 void NetErrorHelper::OnTrackingRequestComplete( | 368 void NetErrorHelper::OnTrackingRequestComplete( |
352 const blink::WebURLResponse& response, | 369 const blink::WebURLResponse& response, |
353 const std::string& data) { | 370 const std::string& data) { |
354 tracking_fetcher_.reset(); | 371 tracking_fetcher_.reset(); |
355 } | 372 } |
| 373 |
| 374 #if defined(OS_ANDROID) |
| 375 void NetErrorHelper::OnSetHasOfflinePages(bool has_offline_pages) { |
| 376 core_->OnSetHasOfflinePages(has_offline_pages); |
| 377 } |
| 378 #endif |
OLD | NEW |