Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: android_webview/renderer/aw_content_renderer_client.cc

Issue 1890203002: Implement Web Restrictions in WebView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase (again!) Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 {
60
61 class ErrorPageObserver : public content::RenderFrameObserver {
62 public:
63 ErrorPageObserver(content::RenderFrame* render_frame,
64 const std::string& url,
65 const web_restrictions::mojom::WebRestrictionsPtr&
66 web_restrictions_service)
67 : content::RenderFrameObserver(render_frame),
68 url_(url),
69 web_restrictions_service_(web_restrictions_service) {}
70
71 void DidClearWindowObject() override {
72 supervised_user_error_page::GinWrapper::InstallWhenFrameReady(
73 render_frame(), url_, web_restrictions_service_);
74 }
75
76 private:
77 std::string url_;
78 const web_restrictions::mojom::WebRestrictionsPtr& web_restrictions_service_;
79 };
80
81 } // namespace
82
53 namespace android_webview { 83 namespace android_webview {
54 84
55 AwContentRendererClient::AwContentRendererClient() {} 85 AwContentRendererClient::AwContentRendererClient() : weak_ptr_factory_(this) {}
56 86
57 AwContentRendererClient::~AwContentRendererClient() {} 87 AwContentRendererClient::~AwContentRendererClient() {}
58 88
59 void AwContentRendererClient::RenderThreadStarted() { 89 void AwContentRendererClient::RenderThreadStarted() {
60 RenderThread* thread = RenderThread::Get(); 90 RenderThread* thread = RenderThread::Get();
61 aw_render_thread_observer_.reset(new AwRenderThreadObserver); 91 aw_render_thread_observer_.reset(new AwRenderThreadObserver);
62 thread->AddObserver(aw_render_thread_observer_.get()); 92 thread->AddObserver(aw_render_thread_observer_.get());
63 93
64 visited_link_slave_.reset(new visitedlink::VisitedLinkSlave); 94 visited_link_slave_.reset(new visitedlink::VisitedLinkSlave);
65 thread->AddObserver(visited_link_slave_.get()); 95 thread->AddObserver(visited_link_slave_.get());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 render_view, std::unique_ptr<printing::PrintWebViewHelper::Delegate>( 190 render_view, std::unique_ptr<printing::PrintWebViewHelper::Delegate>(
161 new AwPrintWebViewHelperDelegate())); 191 new AwPrintWebViewHelperDelegate()));
162 } 192 }
163 193
164 bool AwContentRendererClient::HasErrorPage(int http_status_code, 194 bool AwContentRendererClient::HasErrorPage(int http_status_code,
165 std::string* error_domain) { 195 std::string* error_domain) {
166 return http_status_code >= 400; 196 return http_status_code >= 400;
167 } 197 }
168 198
169 void AwContentRendererClient::GetNavigationErrorStrings( 199 void AwContentRendererClient::GetNavigationErrorStrings(
170 content::RenderFrame* /* render_frame */, 200 content::RenderFrame* render_frame,
171 const blink::WebURLRequest& failed_request, 201 const blink::WebURLRequest& failed_request,
172 const blink::WebURLError& error, 202 const blink::WebURLError& error,
173 std::string* error_html, 203 std::string* error_html,
174 base::string16* error_description) { 204 base::string16* error_description) {
175 if (error_html) { 205 if (error_html) {
176 std::string url = 206 GURL gurl(failed_request.url());
177 net::EscapeForHTML(GURL(failed_request.url()).possibly_invalid_spec()); 207 std::string url = net::EscapeForHTML(gurl.possibly_invalid_spec());
178 std::string err = 208 std::string err =
179 base::UTF16ToUTF8(base::StringPiece16(error.localizedDescription)); 209 base::UTF16ToUTF8(base::StringPiece16(error.localizedDescription));
180 210
181 std::vector<std::string> replacements; 211 std::vector<std::string> replacements;
182 replacements.push_back( 212 replacements.push_back(
183 l10n_util::GetStringUTF8(IDS_AW_WEBPAGE_NOT_AVAILABLE)); 213 l10n_util::GetStringUTF8(IDS_AW_WEBPAGE_NOT_AVAILABLE));
184 if (err.empty()) { 214 if (err.empty()) {
185 replacements.push_back(l10n_util::GetStringFUTF8( 215 replacements.push_back(l10n_util::GetStringFUTF8(
186 IDS_AW_WEBPAGE_TEMPORARILY_DOWN, base::UTF8ToUTF16(url))); 216 IDS_AW_WEBPAGE_TEMPORARILY_DOWN, base::UTF8ToUTF16(url)));
187 replacements.push_back(l10n_util::GetStringUTF8( 217 replacements.push_back(l10n_util::GetStringUTF8(
188 IDS_AW_WEBPAGE_TEMPORARILY_DOWN_SUGGESTIONS)); 218 IDS_AW_WEBPAGE_TEMPORARILY_DOWN_SUGGESTIONS));
189 } else { 219 } else {
190 replacements.push_back(l10n_util::GetStringFUTF8( 220 replacements.push_back(l10n_util::GetStringFUTF8(
191 IDS_AW_WEBPAGE_CAN_NOT_BE_LOADED, base::UTF8ToUTF16(url))); 221 IDS_AW_WEBPAGE_CAN_NOT_BE_LOADED, base::UTF8ToUTF16(url)));
192 replacements.push_back(err); 222 replacements.push_back(err);
193 } 223 }
194 if (base::i18n::IsRTL()) 224 if (base::i18n::IsRTL())
195 replacements.push_back("direction: rtl;"); 225 replacements.push_back("direction: rtl;");
196 else 226 else
197 replacements.push_back(""); 227 replacements.push_back("");
198 *error_html = base::ReplaceStringPlaceholders( 228 *error_html = base::ReplaceStringPlaceholders(
199 ResourceBundle::GetSharedInstance().GetRawDataResource( 229 ResourceBundle::GetSharedInstance().GetRawDataResource(
200 IDR_AW_LOAD_ERROR_HTML), 230 IDR_AW_LOAD_ERROR_HTML),
201 replacements, nullptr); 231 replacements, nullptr);
232 if (error.reason == net::ERR_BLOCKED_BY_ADMINISTRATOR) {
233 // This needs more information
234 render_frame->GetServiceRegistry()->ConnectToRemoteService(
235 mojo::GetProxy(&web_restrictions_service_));
236 web_restrictions::mojom::ClientResultPtr result;
237 if (web_restrictions_service_->GetResult(mojo::String(url), &result)) {
238 *error_html =
239 supervised_user_error_page::BuildHtmlFromWebRestrictionsResult(
240 result, RenderThread::Get()->GetLocale());
241 supervised_user_error_page::GinWrapper::InstallWhenFrameReady(
242 render_frame, url, web_restrictions_service_);
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698