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

Unified 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: Respond to comments, and fix a possible race in displaying error page Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: android_webview/renderer/aw_content_renderer_client.cc
diff --git a/android_webview/renderer/aw_content_renderer_client.cc b/android_webview/renderer/aw_content_renderer_client.cc
index eaceec574351aec7806f95090d1ff6094716a544..5e56eae8eed41521e8e45439f79dc2e035f7be46 100644
--- a/android_webview/renderer/aw_content_renderer_client.cc
+++ b/android_webview/renderer/aw_content_renderer_client.cc
@@ -27,11 +27,16 @@
#include "components/autofill/content/renderer/autofill_agent.h"
#include "components/autofill/content/renderer/password_autofill_agent.h"
#include "components/printing/renderer/print_web_view_helper.h"
+#include "components/supervised_user_error_page/gin_wrapper.h"
+#include "components/supervised_user_error_page/supervised_user_error_page_android.h"
#include "components/visitedlink/renderer/visitedlink_slave.h"
+#include "components/web_restrictions/interfaces/web_restrictions.mojom.h"
+#include "content/public/common/service_registry.h"
#include "content/public/common/url_constants.h"
#include "content/public/renderer/document_state.h"
#include "content/public/renderer/navigation_state.h"
#include "content/public/renderer/render_frame.h"
+#include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_thread.h"
#include "content/public/renderer/render_view.h"
#include "net/base/escape.h"
@@ -41,6 +46,7 @@
#include "third_party/WebKit/public/platform/WebURLError.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
#include "third_party/WebKit/public/web/WebFrame.h"
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebNavigationType.h"
#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
#include "ui/base/l10n/l10n_util.h"
@@ -50,9 +56,31 @@
using content::RenderThread;
+namespace {
Bernhard Bauer 2016/05/19 10:00:15 Nit: Empty lines inside the namespace.
aberent 2016/05/19 15:44:02 Done.
+class ErrorPageObserver : public content::RenderFrameObserver {
+ public:
+ ErrorPageObserver(content::RenderFrame* render_frame,
+ const std::string& url,
+ const web_restrictions::mojom::WebRestrictionsPtr&
+ web_restrictions_service)
+ : content::RenderFrameObserver(render_frame),
+ url_(url),
+ web_restrictions_service_(web_restrictions_service) {}
+
+ void DidClearWindowObject() override {
+ supervised_user_error_page::GinWrapper::InstallWhenFrameReady(
+ render_frame(), url_, web_restrictions_service_);
+ }
+
+ private:
+ std::string url_;
+ const web_restrictions::mojom::WebRestrictionsPtr& web_restrictions_service_;
+};
+}
+
namespace android_webview {
-AwContentRendererClient::AwContentRendererClient() {}
+AwContentRendererClient::AwContentRendererClient() : weak_ptr_factory_(this) {}
AwContentRendererClient::~AwContentRendererClient() {}
@@ -167,14 +195,14 @@ bool AwContentRendererClient::HasErrorPage(int http_status_code,
}
void AwContentRendererClient::GetNavigationErrorStrings(
- content::RenderFrame* /* render_frame */,
+ content::RenderFrame* render_frame,
const blink::WebURLRequest& failed_request,
const blink::WebURLError& error,
std::string* error_html,
base::string16* error_description) {
if (error_html) {
- std::string url =
- net::EscapeForHTML(GURL(failed_request.url()).possibly_invalid_spec());
+ GURL gurl(failed_request.url());
+ std::string url = net::EscapeForHTML(gurl.possibly_invalid_spec());
std::string err =
base::UTF16ToUTF8(base::StringPiece16(error.localizedDescription));
@@ -199,6 +227,21 @@ void AwContentRendererClient::GetNavigationErrorStrings(
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_AW_LOAD_ERROR_HTML),
replacements, nullptr);
+ if (error.reason == net::ERR_BLOCKED_BY_ADMINISTRATOR) {
+ // This needs more information
+ render_frame->GetServiceRegistry()->ConnectToRemoteService(
+ mojo::GetProxy(&web_restrictions_service_));
+ web_restrictions::mojom::ClientResultPtr result;
+ if (web_restrictions_service_->GetResult(mojo::String(url), &result)) {
+ *error_html =
+ supervised_user_error_page::BuildHtmlFromWebRestrictionsResult(
+ result, RenderThread::Get()->GetLocale());
+ 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.
+ supervised_user_error_page::GinWrapper::InstallWhenFrameReady(
+ render_frame, url, web_restrictions_service_);
+ }
+ }
+ }
}
if (error_description) {
if (error.localizedDescription.isEmpty())

Powered by Google App Engine
This is Rietveld 408576698