Chromium Code Reviews| 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" | |
| 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" |
| 39 #include "content/public/renderer/render_frame_observer.h" | |
| 35 #include "content/public/renderer/render_thread.h" | 40 #include "content/public/renderer/render_thread.h" |
| 36 #include "content/public/renderer/render_view.h" | 41 #include "content/public/renderer/render_view.h" |
| 37 #include "net/base/escape.h" | 42 #include "net/base/escape.h" |
| 38 #include "net/base/net_errors.h" | 43 #include "net/base/net_errors.h" |
| 39 #include "third_party/WebKit/public/platform/WebString.h" | 44 #include "third_party/WebKit/public/platform/WebString.h" |
| 40 #include "third_party/WebKit/public/platform/WebURL.h" | 45 #include "third_party/WebKit/public/platform/WebURL.h" |
| 41 #include "third_party/WebKit/public/platform/WebURLError.h" | 46 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 42 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 47 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 43 #include "third_party/WebKit/public/web/WebFrame.h" | 48 #include "third_party/WebKit/public/web/WebFrame.h" |
| 49 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
| 44 #include "third_party/WebKit/public/web/WebNavigationType.h" | 50 #include "third_party/WebKit/public/web/WebNavigationType.h" |
| 45 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 51 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 46 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
| 47 #include "ui/base/resource/resource_bundle.h" | 53 #include "ui/base/resource/resource_bundle.h" |
| 48 #include "url/gurl.h" | 54 #include "url/gurl.h" |
| 49 #include "url/url_constants.h" | 55 #include "url/url_constants.h" |
| 50 | 56 |
| 51 using content::RenderThread; | 57 using content::RenderThread; |
| 52 | 58 |
| 59 namespace { | |
|
Bernhard Bauer
2016/05/19 10:00:15
Nit: Empty lines inside the namespace.
aberent
2016/05/19 15:44:02
Done.
| |
| 60 class ErrorPageObserver : public content::RenderFrameObserver { | |
| 61 public: | |
| 62 ErrorPageObserver(content::RenderFrame* render_frame, | |
| 63 const std::string& url, | |
| 64 const web_restrictions::mojom::WebRestrictionsPtr& | |
| 65 web_restrictions_service) | |
| 66 : content::RenderFrameObserver(render_frame), | |
| 67 url_(url), | |
| 68 web_restrictions_service_(web_restrictions_service) {} | |
| 69 | |
| 70 void DidClearWindowObject() override { | |
| 71 supervised_user_error_page::GinWrapper::InstallWhenFrameReady( | |
| 72 render_frame(), url_, web_restrictions_service_); | |
| 73 } | |
| 74 | |
| 75 private: | |
| 76 std::string url_; | |
| 77 const web_restrictions::mojom::WebRestrictionsPtr& web_restrictions_service_; | |
| 78 }; | |
| 79 } | |
| 80 | |
| 53 namespace android_webview { | 81 namespace android_webview { |
| 54 | 82 |
| 55 AwContentRendererClient::AwContentRendererClient() {} | 83 AwContentRendererClient::AwContentRendererClient() : weak_ptr_factory_(this) {} |
| 56 | 84 |
| 57 AwContentRendererClient::~AwContentRendererClient() {} | 85 AwContentRendererClient::~AwContentRendererClient() {} |
| 58 | 86 |
| 59 void AwContentRendererClient::RenderThreadStarted() { | 87 void AwContentRendererClient::RenderThreadStarted() { |
| 60 RenderThread* thread = RenderThread::Get(); | 88 RenderThread* thread = RenderThread::Get(); |
| 61 aw_render_thread_observer_.reset(new AwRenderThreadObserver); | 89 aw_render_thread_observer_.reset(new AwRenderThreadObserver); |
| 62 thread->AddObserver(aw_render_thread_observer_.get()); | 90 thread->AddObserver(aw_render_thread_observer_.get()); |
| 63 | 91 |
| 64 visited_link_slave_.reset(new visitedlink::VisitedLinkSlave); | 92 visited_link_slave_.reset(new visitedlink::VisitedLinkSlave); |
| 65 thread->AddObserver(visited_link_slave_.get()); | 93 thread->AddObserver(visited_link_slave_.get()); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 render_view, std::unique_ptr<printing::PrintWebViewHelper::Delegate>( | 188 render_view, std::unique_ptr<printing::PrintWebViewHelper::Delegate>( |
| 161 new AwPrintWebViewHelperDelegate())); | 189 new AwPrintWebViewHelperDelegate())); |
| 162 } | 190 } |
| 163 | 191 |
| 164 bool AwContentRendererClient::HasErrorPage(int http_status_code, | 192 bool AwContentRendererClient::HasErrorPage(int http_status_code, |
| 165 std::string* error_domain) { | 193 std::string* error_domain) { |
| 166 return http_status_code >= 400; | 194 return http_status_code >= 400; |
| 167 } | 195 } |
| 168 | 196 |
| 169 void AwContentRendererClient::GetNavigationErrorStrings( | 197 void AwContentRendererClient::GetNavigationErrorStrings( |
| 170 content::RenderFrame* /* render_frame */, | 198 content::RenderFrame* render_frame, |
| 171 const blink::WebURLRequest& failed_request, | 199 const blink::WebURLRequest& failed_request, |
| 172 const blink::WebURLError& error, | 200 const blink::WebURLError& error, |
| 173 std::string* error_html, | 201 std::string* error_html, |
| 174 base::string16* error_description) { | 202 base::string16* error_description) { |
| 175 if (error_html) { | 203 if (error_html) { |
| 176 std::string url = | 204 GURL gurl(failed_request.url()); |
| 177 net::EscapeForHTML(GURL(failed_request.url()).possibly_invalid_spec()); | 205 std::string url = net::EscapeForHTML(gurl.possibly_invalid_spec()); |
| 178 std::string err = | 206 std::string err = |
| 179 base::UTF16ToUTF8(base::StringPiece16(error.localizedDescription)); | 207 base::UTF16ToUTF8(base::StringPiece16(error.localizedDescription)); |
| 180 | 208 |
| 181 std::vector<std::string> replacements; | 209 std::vector<std::string> replacements; |
| 182 replacements.push_back( | 210 replacements.push_back( |
| 183 l10n_util::GetStringUTF8(IDS_AW_WEBPAGE_NOT_AVAILABLE)); | 211 l10n_util::GetStringUTF8(IDS_AW_WEBPAGE_NOT_AVAILABLE)); |
| 184 if (err.empty()) { | 212 if (err.empty()) { |
| 185 replacements.push_back(l10n_util::GetStringFUTF8( | 213 replacements.push_back(l10n_util::GetStringFUTF8( |
| 186 IDS_AW_WEBPAGE_TEMPORARILY_DOWN, base::UTF8ToUTF16(url))); | 214 IDS_AW_WEBPAGE_TEMPORARILY_DOWN, base::UTF8ToUTF16(url))); |
| 187 replacements.push_back(l10n_util::GetStringUTF8( | 215 replacements.push_back(l10n_util::GetStringUTF8( |
| 188 IDS_AW_WEBPAGE_TEMPORARILY_DOWN_SUGGESTIONS)); | 216 IDS_AW_WEBPAGE_TEMPORARILY_DOWN_SUGGESTIONS)); |
| 189 } else { | 217 } else { |
| 190 replacements.push_back(l10n_util::GetStringFUTF8( | 218 replacements.push_back(l10n_util::GetStringFUTF8( |
| 191 IDS_AW_WEBPAGE_CAN_NOT_BE_LOADED, base::UTF8ToUTF16(url))); | 219 IDS_AW_WEBPAGE_CAN_NOT_BE_LOADED, base::UTF8ToUTF16(url))); |
| 192 replacements.push_back(err); | 220 replacements.push_back(err); |
| 193 } | 221 } |
| 194 if (base::i18n::IsRTL()) | 222 if (base::i18n::IsRTL()) |
| 195 replacements.push_back("direction: rtl;"); | 223 replacements.push_back("direction: rtl;"); |
| 196 else | 224 else |
| 197 replacements.push_back(""); | 225 replacements.push_back(""); |
| 198 *error_html = base::ReplaceStringPlaceholders( | 226 *error_html = base::ReplaceStringPlaceholders( |
| 199 ResourceBundle::GetSharedInstance().GetRawDataResource( | 227 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 200 IDR_AW_LOAD_ERROR_HTML), | 228 IDR_AW_LOAD_ERROR_HTML), |
| 201 replacements, nullptr); | 229 replacements, nullptr); |
| 230 if (error.reason == net::ERR_BLOCKED_BY_ADMINISTRATOR) { | |
| 231 // This needs more information | |
| 232 render_frame->GetServiceRegistry()->ConnectToRemoteService( | |
| 233 mojo::GetProxy(&web_restrictions_service_)); | |
| 234 web_restrictions::mojom::ClientResultPtr result; | |
| 235 if (web_restrictions_service_->GetResult(mojo::String(url), &result)) { | |
| 236 *error_html = | |
| 237 supervised_user_error_page::BuildHtmlFromWebRestrictionsResult( | |
| 238 result, RenderThread::Get()->GetLocale()); | |
| 239 if (result->intParams["Allow access requests"]) { | |
|
Bernhard Bauer
2016/05/19 10:00:15
Extract the string (and the others) to constants?
aberent
2016/05/19 15:44:02
Actually I have just taken this if statement out.
| |
| 240 supervised_user_error_page::GinWrapper::InstallWhenFrameReady( | |
| 241 render_frame, url, web_restrictions_service_); | |
| 242 } | |
| 243 } | |
| 244 } | |
| 202 } | 245 } |
| 203 if (error_description) { | 246 if (error_description) { |
| 204 if (error.localizedDescription.isEmpty()) | 247 if (error.localizedDescription.isEmpty()) |
| 205 *error_description = base::ASCIIToUTF16(net::ErrorToString(error.reason)); | 248 *error_description = base::ASCIIToUTF16(net::ErrorToString(error.reason)); |
| 206 else | 249 else |
| 207 *error_description = error.localizedDescription; | 250 *error_description = error.localizedDescription; |
| 208 } | 251 } |
| 209 } | 252 } |
| 210 | 253 |
| 211 unsigned long long AwContentRendererClient::VisitedLinkHash( | 254 unsigned long long AwContentRendererClient::VisitedLinkHash( |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 240 for (const auto& extension : kMediaPlayerExtensions) { | 283 for (const auto& extension : kMediaPlayerExtensions) { |
| 241 if (base::EndsWith(url.path(), extension, | 284 if (base::EndsWith(url.path(), extension, |
| 242 base::CompareCase::INSENSITIVE_ASCII)) { | 285 base::CompareCase::INSENSITIVE_ASCII)) { |
| 243 return true; | 286 return true; |
| 244 } | 287 } |
| 245 } | 288 } |
| 246 return false; | 289 return false; |
| 247 } | 290 } |
| 248 | 291 |
| 249 } // namespace android_webview | 292 } // namespace android_webview |
| OLD | NEW |