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> | 7 #include <vector> |
8 | 8 |
9 #include "android_webview/common/aw_resource.h" | 9 #include "android_webview/common/aw_resource.h" |
10 #include "android_webview/common/aw_switches.h" | 10 #include "android_webview/common/aw_switches.h" |
11 #include "android_webview/common/render_view_messages.h" | 11 #include "android_webview/common/render_view_messages.h" |
12 #include "android_webview/common/url_constants.h" | 12 #include "android_webview/common/url_constants.h" |
13 #include "android_webview/grit/aw_resources.h" | 13 #include "android_webview/grit/aw_resources.h" |
14 #include "android_webview/grit/aw_strings.h" | 14 #include "android_webview/grit/aw_strings.h" |
15 #include "android_webview/renderer/aw_content_settings_client.h" | 15 #include "android_webview/renderer/aw_content_settings_client.h" |
16 #include "android_webview/renderer/aw_key_systems.h" | 16 #include "android_webview/renderer/aw_key_systems.h" |
17 #include "android_webview/renderer/aw_message_port_client.h" | 17 #include "android_webview/renderer/aw_message_port_client.h" |
18 #include "android_webview/renderer/aw_print_web_view_helper_delegate.h" | 18 #include "android_webview/renderer/aw_print_web_view_helper_delegate.h" |
19 #include "android_webview/renderer/aw_render_frame_ext.h" | 19 #include "android_webview/renderer/aw_render_frame_ext.h" |
20 #include "android_webview/renderer/aw_render_view_ext.h" | 20 #include "android_webview/renderer/aw_render_view_ext.h" |
21 #include "android_webview/renderer/print_render_frame_observer.h" | 21 #include "android_webview/renderer/print_render_frame_observer.h" |
22 #include "base/command_line.h" | 22 #include "base/command_line.h" |
23 #include "base/i18n/rtl.h" | 23 #include "base/i18n/rtl.h" |
24 #include "base/message_loop/message_loop.h" | 24 #include "base/message_loop/message_loop.h" |
25 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
27 #include "components/autofill/content/renderer/autofill_agent.h" | 27 #include "components/autofill/content/renderer/autofill_agent.h" |
28 #include "components/autofill/content/renderer/password_autofill_agent.h" | 28 #include "components/autofill/content/renderer/password_autofill_agent.h" |
29 #include "components/printing/renderer/print_web_view_helper.h" | 29 #include "components/printing/renderer/print_web_view_helper.h" |
| 30 #include "components/supervised_user_error_page/gin_wrapper.h" |
| 31 #include "components/supervised_user_error_page/supervised_user_error_page_andro
id.h" |
30 #include "components/visitedlink/renderer/visitedlink_slave.h" | 32 #include "components/visitedlink/renderer/visitedlink_slave.h" |
| 33 #include "components/web_restrictions/interfaces/web_restrictions.mojom.h" |
31 #include "content/public/common/url_constants.h" | 34 #include "content/public/common/url_constants.h" |
32 #include "content/public/renderer/document_state.h" | 35 #include "content/public/renderer/document_state.h" |
33 #include "content/public/renderer/navigation_state.h" | 36 #include "content/public/renderer/navigation_state.h" |
34 #include "content/public/renderer/render_frame.h" | 37 #include "content/public/renderer/render_frame.h" |
35 #include "content/public/renderer/render_thread.h" | 38 #include "content/public/renderer/render_thread.h" |
36 #include "content/public/renderer/render_view.h" | 39 #include "content/public/renderer/render_view.h" |
37 #include "net/base/escape.h" | 40 #include "net/base/escape.h" |
38 #include "net/base/net_errors.h" | 41 #include "net/base/net_errors.h" |
| 42 #include "services/shell/public/cpp/interface_provider.h" |
39 #include "third_party/WebKit/public/platform/WebString.h" | 43 #include "third_party/WebKit/public/platform/WebString.h" |
40 #include "third_party/WebKit/public/platform/WebURL.h" | 44 #include "third_party/WebKit/public/platform/WebURL.h" |
41 #include "third_party/WebKit/public/platform/WebURLError.h" | 45 #include "third_party/WebKit/public/platform/WebURLError.h" |
42 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 46 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
43 #include "third_party/WebKit/public/web/WebFrame.h" | 47 #include "third_party/WebKit/public/web/WebFrame.h" |
44 #include "third_party/WebKit/public/web/WebNavigationType.h" | 48 #include "third_party/WebKit/public/web/WebNavigationType.h" |
45 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 49 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
46 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
47 #include "ui/base/resource/resource_bundle.h" | 51 #include "ui/base/resource/resource_bundle.h" |
48 #include "url/gurl.h" | 52 #include "url/gurl.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 render_view, std::unique_ptr<printing::PrintWebViewHelper::Delegate>( | 164 render_view, std::unique_ptr<printing::PrintWebViewHelper::Delegate>( |
161 new AwPrintWebViewHelperDelegate())); | 165 new AwPrintWebViewHelperDelegate())); |
162 } | 166 } |
163 | 167 |
164 bool AwContentRendererClient::HasErrorPage(int http_status_code, | 168 bool AwContentRendererClient::HasErrorPage(int http_status_code, |
165 std::string* error_domain) { | 169 std::string* error_domain) { |
166 return http_status_code >= 400; | 170 return http_status_code >= 400; |
167 } | 171 } |
168 | 172 |
169 void AwContentRendererClient::GetNavigationErrorStrings( | 173 void AwContentRendererClient::GetNavigationErrorStrings( |
170 content::RenderFrame* /* render_frame */, | 174 content::RenderFrame* render_frame, |
171 const blink::WebURLRequest& failed_request, | 175 const blink::WebURLRequest& failed_request, |
172 const blink::WebURLError& error, | 176 const blink::WebURLError& error, |
173 std::string* error_html, | 177 std::string* error_html, |
174 base::string16* error_description) { | 178 base::string16* error_description) { |
175 if (error_html) { | 179 if (error_html) { |
176 std::string url = | 180 GURL gurl(failed_request.url()); |
177 net::EscapeForHTML(GURL(failed_request.url()).possibly_invalid_spec()); | 181 std::string url = net::EscapeForHTML(gurl.possibly_invalid_spec()); |
178 std::string err = | 182 std::string err = |
179 base::UTF16ToUTF8(base::StringPiece16(error.localizedDescription)); | 183 base::UTF16ToUTF8(base::StringPiece16(error.localizedDescription)); |
180 | 184 |
181 std::vector<std::string> replacements; | 185 std::vector<std::string> replacements; |
182 replacements.push_back( | 186 replacements.push_back( |
183 l10n_util::GetStringUTF8(IDS_AW_WEBPAGE_NOT_AVAILABLE)); | 187 l10n_util::GetStringUTF8(IDS_AW_WEBPAGE_NOT_AVAILABLE)); |
184 if (err.empty()) { | 188 if (err.empty()) { |
185 replacements.push_back(l10n_util::GetStringFUTF8( | 189 replacements.push_back(l10n_util::GetStringFUTF8( |
186 IDS_AW_WEBPAGE_TEMPORARILY_DOWN, base::UTF8ToUTF16(url))); | 190 IDS_AW_WEBPAGE_TEMPORARILY_DOWN, base::UTF8ToUTF16(url))); |
187 replacements.push_back(l10n_util::GetStringUTF8( | 191 replacements.push_back(l10n_util::GetStringUTF8( |
188 IDS_AW_WEBPAGE_TEMPORARILY_DOWN_SUGGESTIONS)); | 192 IDS_AW_WEBPAGE_TEMPORARILY_DOWN_SUGGESTIONS)); |
189 } else { | 193 } else { |
190 replacements.push_back(l10n_util::GetStringFUTF8( | 194 replacements.push_back(l10n_util::GetStringFUTF8( |
191 IDS_AW_WEBPAGE_CAN_NOT_BE_LOADED, base::UTF8ToUTF16(url))); | 195 IDS_AW_WEBPAGE_CAN_NOT_BE_LOADED, base::UTF8ToUTF16(url))); |
192 replacements.push_back(err); | 196 replacements.push_back(err); |
193 } | 197 } |
194 if (base::i18n::IsRTL()) | 198 if (base::i18n::IsRTL()) |
195 replacements.push_back("direction: rtl;"); | 199 replacements.push_back("direction: rtl;"); |
196 else | 200 else |
197 replacements.push_back(""); | 201 replacements.push_back(""); |
198 *error_html = base::ReplaceStringPlaceholders( | 202 *error_html = base::ReplaceStringPlaceholders( |
199 ResourceBundle::GetSharedInstance().GetRawDataResource( | 203 ResourceBundle::GetSharedInstance().GetRawDataResource( |
200 IDR_AW_LOAD_ERROR_HTML), | 204 IDR_AW_LOAD_ERROR_HTML), |
201 replacements, nullptr); | 205 replacements, nullptr); |
| 206 if (error.reason == net::ERR_BLOCKED_BY_ADMINISTRATOR) { |
| 207 // This needs more information |
| 208 render_frame->GetRemoteInterfaces()->GetInterface( |
| 209 &web_restrictions_service_); |
| 210 web_restrictions::mojom::ClientResultPtr result; |
| 211 if (web_restrictions_service_->GetResult(mojo::String(url), &result)) { |
| 212 std::string detailed_error_html = |
| 213 supervised_user_error_page::BuildHtmlFromWebRestrictionsResult( |
| 214 result, RenderThread::Get()->GetLocale()); |
| 215 if (!detailed_error_html.empty()) { |
| 216 *error_html = detailed_error_html; |
| 217 supervised_user_error_page::GinWrapper::InstallWhenFrameReady( |
| 218 render_frame, url, web_restrictions_service_); |
| 219 } |
| 220 } |
| 221 } |
202 } | 222 } |
203 if (error_description) { | 223 if (error_description) { |
204 if (error.localizedDescription.isEmpty()) | 224 if (error.localizedDescription.isEmpty()) |
205 *error_description = base::ASCIIToUTF16(net::ErrorToString(error.reason)); | 225 *error_description = base::ASCIIToUTF16(net::ErrorToString(error.reason)); |
206 else | 226 else |
207 *error_description = error.localizedDescription; | 227 *error_description = error.localizedDescription; |
208 } | 228 } |
209 } | 229 } |
210 | 230 |
211 unsigned long long AwContentRendererClient::VisitedLinkHash( | 231 unsigned long long AwContentRendererClient::VisitedLinkHash( |
(...skipping 28 matching lines...) Expand all Loading... |
240 for (auto* extension : kMediaPlayerExtensions) { | 260 for (auto* extension : kMediaPlayerExtensions) { |
241 if (base::EndsWith(url.path(), extension, | 261 if (base::EndsWith(url.path(), extension, |
242 base::CompareCase::INSENSITIVE_ASCII)) { | 262 base::CompareCase::INSENSITIVE_ASCII)) { |
243 return true; | 263 return true; |
244 } | 264 } |
245 } | 265 } |
246 return false; | 266 return false; |
247 } | 267 } |
248 | 268 |
249 } // namespace android_webview | 269 } // namespace android_webview |
OLD | NEW |