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/supervised_user_error_page.h" | |
31 #include "components/supervised_user_error_page/supervised_user_gin_wrapper.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" | |
34 #include "content/public/common/service_registry.h" | |
31 #include "content/public/common/url_constants.h" | 35 #include "content/public/common/url_constants.h" |
32 #include "content/public/renderer/document_state.h" | 36 #include "content/public/renderer/document_state.h" |
33 #include "content/public/renderer/navigation_state.h" | 37 #include "content/public/renderer/navigation_state.h" |
34 #include "content/public/renderer/render_frame.h" | 38 #include "content/public/renderer/render_frame.h" |
35 #include "content/public/renderer/render_thread.h" | 39 #include "content/public/renderer/render_thread.h" |
36 #include "content/public/renderer/render_view.h" | 40 #include "content/public/renderer/render_view.h" |
37 #include "net/base/escape.h" | 41 #include "net/base/escape.h" |
38 #include "net/base/net_errors.h" | 42 #include "net/base/net_errors.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" |
48 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
44 #include "third_party/WebKit/public/web/WebNavigationType.h" | 49 #include "third_party/WebKit/public/web/WebNavigationType.h" |
45 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 50 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
46 #include "ui/base/l10n/l10n_util.h" | 51 #include "ui/base/l10n/l10n_util.h" |
47 #include "ui/base/resource/resource_bundle.h" | 52 #include "ui/base/resource/resource_bundle.h" |
48 #include "url/gurl.h" | 53 #include "url/gurl.h" |
49 #include "url/url_constants.h" | 54 #include "url/url_constants.h" |
50 | 55 |
51 using content::RenderThread; | 56 using content::RenderThread; |
52 | 57 |
53 namespace android_webview { | 58 namespace android_webview { |
54 | 59 |
55 AwContentRendererClient::AwContentRendererClient() | 60 AwContentRendererClient::AwContentRendererClient() |
56 : disable_page_visibility_( | 61 : disable_page_visibility_( |
57 base::CommandLine::ForCurrentProcess() | 62 base::CommandLine::ForCurrentProcess()->HasSwitch( |
58 ->HasSwitch(switches::kDisablePageVisibility)) {} | 63 switches::kDisablePageVisibility)), |
64 weak_ptr_factory_(this) {} | |
59 | 65 |
60 AwContentRendererClient::~AwContentRendererClient() { | 66 AwContentRendererClient::~AwContentRendererClient() { |
61 } | 67 } |
62 | 68 |
63 void AwContentRendererClient::RenderThreadStarted() { | 69 void AwContentRendererClient::RenderThreadStarted() { |
64 RenderThread* thread = RenderThread::Get(); | 70 RenderThread* thread = RenderThread::Get(); |
65 aw_render_process_observer_.reset(new AwRenderProcessObserver); | 71 aw_render_process_observer_.reset(new AwRenderProcessObserver); |
66 thread->AddObserver(aw_render_process_observer_.get()); | 72 thread->AddObserver(aw_render_process_observer_.get()); |
67 | 73 |
68 visited_link_slave_.reset(new visitedlink::VisitedLinkSlave); | 74 visited_link_slave_.reset(new visitedlink::VisitedLinkSlave); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 render_view, std::unique_ptr<printing::PrintWebViewHelper::Delegate>( | 170 render_view, std::unique_ptr<printing::PrintWebViewHelper::Delegate>( |
165 new AwPrintWebViewHelperDelegate())); | 171 new AwPrintWebViewHelperDelegate())); |
166 } | 172 } |
167 | 173 |
168 bool AwContentRendererClient::HasErrorPage(int http_status_code, | 174 bool AwContentRendererClient::HasErrorPage(int http_status_code, |
169 std::string* error_domain) { | 175 std::string* error_domain) { |
170 return http_status_code >= 400; | 176 return http_status_code >= 400; |
171 } | 177 } |
172 | 178 |
173 void AwContentRendererClient::GetNavigationErrorStrings( | 179 void AwContentRendererClient::GetNavigationErrorStrings( |
174 content::RenderFrame* /* render_frame */, | 180 content::RenderFrame* render_frame, |
175 const blink::WebURLRequest& failed_request, | 181 const blink::WebURLRequest& failed_request, |
176 const blink::WebURLError& error, | 182 const blink::WebURLError& error, |
177 std::string* error_html, | 183 std::string* error_html, |
178 base::string16* error_description) { | 184 base::string16* error_description) { |
179 if (error_html) { | 185 if (error_html) { |
180 std::string url = | 186 GURL gurl(failed_request.url()); |
181 net::EscapeForHTML(GURL(failed_request.url()).possibly_invalid_spec()); | 187 std::string url = net::EscapeForHTML(gurl.possibly_invalid_spec()); |
182 std::string err = | 188 std::string err = |
183 base::UTF16ToUTF8(base::StringPiece16(error.localizedDescription)); | 189 base::UTF16ToUTF8(base::StringPiece16(error.localizedDescription)); |
184 | 190 |
185 std::vector<std::string> replacements; | 191 std::vector<std::string> replacements; |
186 replacements.push_back( | 192 replacements.push_back( |
187 l10n_util::GetStringUTF8(IDS_AW_WEBPAGE_NOT_AVAILABLE)); | 193 l10n_util::GetStringUTF8(IDS_AW_WEBPAGE_NOT_AVAILABLE)); |
188 if (err.empty()) { | 194 if (err.empty()) { |
189 replacements.push_back(l10n_util::GetStringFUTF8( | 195 replacements.push_back(l10n_util::GetStringFUTF8( |
190 IDS_AW_WEBPAGE_TEMPORARILY_DOWN, base::UTF8ToUTF16(url))); | 196 IDS_AW_WEBPAGE_TEMPORARILY_DOWN, base::UTF8ToUTF16(url))); |
191 replacements.push_back(l10n_util::GetStringUTF8( | 197 replacements.push_back(l10n_util::GetStringUTF8( |
192 IDS_AW_WEBPAGE_TEMPORARILY_DOWN_SUGGESTIONS)); | 198 IDS_AW_WEBPAGE_TEMPORARILY_DOWN_SUGGESTIONS)); |
193 } else { | 199 } else { |
194 replacements.push_back(l10n_util::GetStringFUTF8( | 200 replacements.push_back(l10n_util::GetStringFUTF8( |
195 IDS_AW_WEBPAGE_CAN_NOT_BE_LOADED, base::UTF8ToUTF16(url))); | 201 IDS_AW_WEBPAGE_CAN_NOT_BE_LOADED, base::UTF8ToUTF16(url))); |
196 replacements.push_back(err); | 202 replacements.push_back(err); |
197 } | 203 } |
198 if (base::i18n::IsRTL()) | 204 if (base::i18n::IsRTL()) |
199 replacements.push_back("direction: rtl;"); | 205 replacements.push_back("direction: rtl;"); |
200 else | 206 else |
201 replacements.push_back(""); | 207 replacements.push_back(""); |
202 *error_html = base::ReplaceStringPlaceholders( | 208 *error_html = base::ReplaceStringPlaceholders( |
203 ResourceBundle::GetSharedInstance().GetRawDataResource( | 209 ResourceBundle::GetSharedInstance().GetRawDataResource( |
204 IDR_AW_LOAD_ERROR_HTML), | 210 IDR_AW_LOAD_ERROR_HTML), |
205 replacements, nullptr); | 211 replacements, nullptr); |
212 if (error.reason == net::ERR_BLOCKED_BY_ADMINISTRATOR) { | |
213 // This needs more information | |
214 render_frame->GetServiceRegistry()->ConnectToRemoteService( | |
215 mojo::GetProxy(&web_restrictions_service_)); | |
216 web_restrictions_service_->GetResult( | |
217 mojo::String(url), | |
218 base::Bind(&AwContentRendererClient::OnWebRestrictionsDataReceived, | |
219 weak_ptr_factory_.GetWeakPtr(), url, render_frame, error)); | |
220 } | |
206 } | 221 } |
207 if (error_description) { | 222 if (error_description) { |
208 if (error.localizedDescription.isEmpty()) | 223 if (error.localizedDescription.isEmpty()) |
209 *error_description = base::ASCIIToUTF16(net::ErrorToString(error.reason)); | 224 *error_description = base::ASCIIToUTF16(net::ErrorToString(error.reason)); |
210 else | 225 else |
211 *error_description = error.localizedDescription; | 226 *error_description = error.localizedDescription; |
212 } | 227 } |
213 } | 228 } |
214 | 229 |
215 unsigned long long AwContentRendererClient::VisitedLinkHash( | 230 unsigned long long AwContentRendererClient::VisitedLinkHash( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 const content::RenderFrame* render_frame, | 269 const content::RenderFrame* render_frame, |
255 blink::WebPageVisibilityState* override_state) { | 270 blink::WebPageVisibilityState* override_state) { |
256 if (disable_page_visibility_) { | 271 if (disable_page_visibility_) { |
257 *override_state = blink::WebPageVisibilityStateVisible; | 272 *override_state = blink::WebPageVisibilityStateVisible; |
258 return true; | 273 return true; |
259 } | 274 } |
260 | 275 |
261 return false; | 276 return false; |
262 } | 277 } |
263 | 278 |
279 void AwContentRendererClient::OnWebRestrictionsDataReceived( | |
280 const std::string& url, | |
281 content::RenderFrame* render_frame, | |
282 const blink::WebURLError& error, | |
283 web_restrictions::mojom::ClientResultPtr result) { | |
284 if (!result) | |
285 return; | |
286 std::string html_error = | |
287 supervised_user_error_page::BuildHtmlFromWebRestrictionsResult( | |
288 result, RenderThread::Get()->GetLocale()); | |
289 if (result->intParams["Allow access requests"]) { | |
290 supervised_user_error_page::SupervisedUserGinWrapper::Install( | |
291 render_frame, url, web_restrictions_service_); | |
292 } | |
293 // Replace is always true, since this replaces the original error page | |
294 render_frame->GetWebFrame()->loadHTMLString( | |
jochen (gone - plz use gerrit)
2016/04/17 17:07:05
why does this not override the previously installe
aberent
2016/05/18 20:06:49
I am not sure that it didn't. I have now created a
| |
295 html_error, GURL(content::kUnreachableWebDataURL), error.unreachableURL, | |
296 true); | |
297 } | |
298 | |
264 } // namespace android_webview | 299 } // namespace android_webview |
OLD | NEW |