Index: components/supervised_user_error_page/supervised_user_gin_wrapper.cc |
diff --git a/components/supervised_user_error_page/supervised_user_gin_wrapper.cc b/components/supervised_user_error_page/supervised_user_gin_wrapper.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3d64cf7d66cf11f5674f03fc0a453ceb74235a0b |
--- /dev/null |
+++ b/components/supervised_user_error_page/supervised_user_gin_wrapper.cc |
@@ -0,0 +1,83 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/supervised_user_error_page/supervised_user_gin_wrapper.h" |
+ |
+#include "base/strings/utf_string_conversions.h" |
+#include "components/web_restrictions/browser/web_restrictions_client.h" |
+#include "content/public/renderer/render_frame.h" |
+#include "gin/handle.h" |
+#include "gin/object_template_builder.h" |
+#include "third_party/WebKit/public/web/WebKit.h" |
+#include "third_party/WebKit/public/web/WebLocalFrame.h" |
+ |
+namespace supervised_user_error_page { |
+ |
+gin::WrapperInfo SupervisedUserGinWrapper::kWrapperInfo = { |
+ gin::kEmbedderNativeGin}; |
+ |
+// static |
+void SupervisedUserGinWrapper::Install( |
+ content::RenderFrame* render_frame, |
+ const std::string& url, |
+ const web_restrictions::mojom::WebRestrictionsPtr& |
+ web_restrictions_service) { |
+ v8::Isolate* isolate = blink::mainThreadIsolate(); |
+ v8::HandleScope handle_scope(isolate); |
+ v8::Local<v8::Context> context = |
+ render_frame->GetWebFrame()->mainWorldScriptContext(); |
+ if (context.IsEmpty()) |
+ return; |
+ v8::Context::Scope context_scope(context); |
+ gin::Handle<SupervisedUserGinWrapper> controller = gin::CreateHandle( |
+ isolate, new SupervisedUserGinWrapper(render_frame, url, |
+ web_restrictions_service)); |
+ if (controller.IsEmpty()) |
+ return; |
+ v8::Local<v8::Object> global = context->Global(); |
+ global->Set(gin::StringToV8(isolate, "webRestrictions"), controller.ToV8()); |
+} |
+ |
+SupervisedUserGinWrapper::SupervisedUserGinWrapper( |
+ 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), |
+ weak_ptr_factory_(this) {} |
+ |
+SupervisedUserGinWrapper::~SupervisedUserGinWrapper() {} |
+ |
+bool SupervisedUserGinWrapper::RequestPermission() { |
+ if (!render_frame()) |
+ return false; |
+ web_restrictions_service_->RequestPermission( |
+ url_, base::Bind(&SupervisedUserGinWrapper::OnAccessRequestAdded, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ render_frame()->GetWebFrame()->reload(); |
+ return true; |
+} |
+ |
+void SupervisedUserGinWrapper::OnAccessRequestAdded(bool success) { |
+ VLOG(1) << "Sent access request for " << url_ |
+ << (success ? " successfully" : " unsuccessfully"); |
+ std::string jsFunc = |
+ success ? "setRequestStatus(true);" : "setRequestStatus(false);"; |
+ render_frame()->ExecuteJavaScript(base::ASCIIToUTF16(jsFunc)); |
jochen (gone - plz use gerrit)
2016/04/17 17:07:05
please have the requestPermission method take a ca
aberent
2016/05/18 20:06:50
Done. Please, however, review carefully. I have co
|
+} |
+ |
+void SupervisedUserGinWrapper::OnDestruct() { |
+ // Do nothing. Overrides version that deletes RenderFrameObserver. |
+} |
+ |
+gin::ObjectTemplateBuilder SupervisedUserGinWrapper::GetObjectTemplateBuilder( |
+ v8::Isolate* isolate) { |
+ return gin::Wrappable<SupervisedUserGinWrapper>::GetObjectTemplateBuilder( |
+ isolate) |
+ .SetMethod("requestPermission", |
+ &SupervisedUserGinWrapper::RequestPermission); |
+} |
+ |
+} // namespace web_restrictions |