OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "android_webview/renderer/aw_content_renderer_client.h" | 5 #include "android_webview/renderer/aw_content_renderer_client.h" |
6 | 6 |
| 7 #include <vector> |
| 8 |
7 #include "android_webview/common/aw_resource.h" | 9 #include "android_webview/common/aw_resource.h" |
8 #include "android_webview/common/render_view_messages.h" | 10 #include "android_webview/common/render_view_messages.h" |
9 #include "android_webview/common/url_constants.h" | 11 #include "android_webview/common/url_constants.h" |
| 12 #include "android_webview/grit/aw_renderer_resources.h" |
10 #include "android_webview/renderer/aw_content_settings_client.h" | 13 #include "android_webview/renderer/aw_content_settings_client.h" |
11 #include "android_webview/renderer/aw_key_systems.h" | 14 #include "android_webview/renderer/aw_key_systems.h" |
12 #include "android_webview/renderer/aw_message_port_client.h" | 15 #include "android_webview/renderer/aw_message_port_client.h" |
13 #include "android_webview/renderer/aw_print_web_view_helper_delegate.h" | 16 #include "android_webview/renderer/aw_print_web_view_helper_delegate.h" |
14 #include "android_webview/renderer/aw_render_frame_ext.h" | 17 #include "android_webview/renderer/aw_render_frame_ext.h" |
15 #include "android_webview/renderer/aw_render_view_ext.h" | 18 #include "android_webview/renderer/aw_render_view_ext.h" |
16 #include "android_webview/renderer/print_render_frame_observer.h" | 19 #include "android_webview/renderer/print_render_frame_observer.h" |
| 20 #include "base/i18n/rtl.h" |
17 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
| 22 #include "base/strings/string_util.h" |
18 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
19 #include "components/autofill/content/renderer/autofill_agent.h" | 24 #include "components/autofill/content/renderer/autofill_agent.h" |
20 #include "components/autofill/content/renderer/password_autofill_agent.h" | 25 #include "components/autofill/content/renderer/password_autofill_agent.h" |
21 #include "components/printing/renderer/print_web_view_helper.h" | 26 #include "components/printing/renderer/print_web_view_helper.h" |
22 #include "components/visitedlink/renderer/visitedlink_slave.h" | 27 #include "components/visitedlink/renderer/visitedlink_slave.h" |
23 #include "content/public/common/url_constants.h" | 28 #include "content/public/common/url_constants.h" |
24 #include "content/public/renderer/render_frame.h" | 29 #include "content/public/renderer/render_frame.h" |
25 #include "content/public/renderer/render_thread.h" | 30 #include "content/public/renderer/render_thread.h" |
26 #include "content/public/renderer/render_view.h" | 31 #include "content/public/renderer/render_view.h" |
27 #include "net/base/escape.h" | 32 #include "net/base/escape.h" |
28 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
29 #include "third_party/WebKit/public/platform/WebString.h" | 34 #include "third_party/WebKit/public/platform/WebString.h" |
30 #include "third_party/WebKit/public/platform/WebURL.h" | 35 #include "third_party/WebKit/public/platform/WebURL.h" |
31 #include "third_party/WebKit/public/platform/WebURLError.h" | 36 #include "third_party/WebKit/public/platform/WebURLError.h" |
32 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 37 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
33 #include "third_party/WebKit/public/web/WebFrame.h" | 38 #include "third_party/WebKit/public/web/WebFrame.h" |
34 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 39 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 40 #include "ui/base/l10n/l10n_util.h" |
| 41 #include "ui/base/resource/resource_bundle.h" |
35 #include "url/gurl.h" | 42 #include "url/gurl.h" |
36 | 43 |
37 using content::RenderThread; | 44 using content::RenderThread; |
38 | 45 |
39 namespace android_webview { | 46 namespace android_webview { |
40 | 47 |
41 AwContentRendererClient::AwContentRendererClient() { | 48 AwContentRendererClient::AwContentRendererClient() { |
42 } | 49 } |
43 | 50 |
44 AwContentRendererClient::~AwContentRendererClient() { | 51 AwContentRendererClient::~AwContentRendererClient() { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 110 } |
104 | 111 |
105 void AwContentRendererClient::GetNavigationErrorStrings( | 112 void AwContentRendererClient::GetNavigationErrorStrings( |
106 content::RenderView* /* render_view */, | 113 content::RenderView* /* render_view */, |
107 blink::WebFrame* /* frame */, | 114 blink::WebFrame* /* frame */, |
108 const blink::WebURLRequest& failed_request, | 115 const blink::WebURLRequest& failed_request, |
109 const blink::WebURLError& error, | 116 const blink::WebURLError& error, |
110 std::string* error_html, | 117 std::string* error_html, |
111 base::string16* error_description) { | 118 base::string16* error_description) { |
112 if (error_html) { | 119 if (error_html) { |
113 GURL error_url(failed_request.url()); | 120 std::string url = |
| 121 net::EscapeForHTML(GURL(failed_request.url()).possibly_invalid_spec()); |
114 std::string err = | 122 std::string err = |
115 base::UTF16ToUTF8(base::StringPiece16(error.localizedDescription)); | 123 base::UTF16ToUTF8(base::StringPiece16(error.localizedDescription)); |
116 std::string contents; | 124 |
| 125 std::vector<std::string> replacements; |
| 126 replacements.push_back( |
| 127 l10n_util::GetStringUTF8(IDS_AW_WEBPAGE_NOT_AVAILABLE)); |
117 if (err.empty()) { | 128 if (err.empty()) { |
118 contents = AwResource::GetNoDomainPageContent(); | 129 replacements.push_back(l10n_util::GetStringFUTF8( |
| 130 IDS_AW_WEBPAGE_TEMPORARILY_DOWN, base::UTF8ToUTF16(url))); |
| 131 replacements.push_back( |
| 132 l10n_util::GetStringUTF8(IDS_AW_WEBPAGE_DOWN_SUGGESTIONS)); |
119 } else { | 133 } else { |
120 contents = AwResource::GetLoadErrorPageContent(); | 134 replacements.push_back(l10n_util::GetStringFUTF8( |
121 base::ReplaceSubstringsAfterOffset(&contents, 0, "%e", err); | 135 IDS_AW_WEBPAGE_CAN_NOT_BE_LOADED, base::UTF8ToUTF16(url))); |
| 136 replacements.push_back(err); |
122 } | 137 } |
123 | 138 if (base::i18n::IsRTL()) |
124 base::ReplaceSubstringsAfterOffset(&contents, 0, "%s", | 139 replacements.push_back("direction: rtl;"); |
125 net::EscapeForHTML(error_url.possibly_invalid_spec())); | 140 else |
126 *error_html = contents; | 141 replacements.push_back(""); |
| 142 *error_html = base::ReplaceStringPlaceholders( |
| 143 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 144 IDR_AW_LOAD_ERROR_HTML), |
| 145 replacements, nullptr); |
127 } | 146 } |
128 if (error_description) { | 147 if (error_description) { |
129 if (error.localizedDescription.isEmpty()) | 148 if (error.localizedDescription.isEmpty()) |
130 *error_description = base::ASCIIToUTF16(net::ErrorToString(error.reason)); | 149 *error_description = base::ASCIIToUTF16(net::ErrorToString(error.reason)); |
131 else | 150 else |
132 *error_description = error.localizedDescription; | 151 *error_description = error.localizedDescription; |
133 } | 152 } |
134 } | 153 } |
135 | 154 |
136 unsigned long long AwContentRendererClient::VisitedLinkHash( | 155 unsigned long long AwContentRendererClient::VisitedLinkHash( |
(...skipping 13 matching lines...) Expand all Loading... |
150 | 169 |
151 bool AwContentRendererClient::ShouldOverridePageVisibilityState( | 170 bool AwContentRendererClient::ShouldOverridePageVisibilityState( |
152 const content::RenderFrame* render_frame, | 171 const content::RenderFrame* render_frame, |
153 blink::WebPageVisibilityState* override_state) { | 172 blink::WebPageVisibilityState* override_state) { |
154 // webview is always visible due to rendering requirements. | 173 // webview is always visible due to rendering requirements. |
155 *override_state = blink::WebPageVisibilityStateVisible; | 174 *override_state = blink::WebPageVisibilityStateVisible; |
156 return true; | 175 return true; |
157 } | 176 } |
158 | 177 |
159 } // namespace android_webview | 178 } // namespace android_webview |
OLD | NEW |