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

Unified Diff: components/web_restriction/web_restriction_gin_wrapper.cc

Issue 1423713015: [WIP] WebRestrictions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: continue review in split cl Created 4 years, 11 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: components/web_restriction/web_restriction_gin_wrapper.cc
diff --git a/components/web_restriction/web_restriction_gin_wrapper.cc b/components/web_restriction/web_restriction_gin_wrapper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e62a955fe5ece3d632dde092568cc00b3fcc2778
--- /dev/null
+++ b/components/web_restriction/web_restriction_gin_wrapper.cc
@@ -0,0 +1,54 @@
+// 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/web_restriction/web_restriction_gin_wrapper.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 web_restriction {
+
+gin::WrapperInfo WebRestrictionGinWrapper::kWrapperInfo = {
+ gin::kEmbedderNativeGin};
+
+// static
+void WebRestrictionGinWrapper::Install(content::RenderFrame* render_frame) {
+ 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<WebRestrictionGinWrapper> controller =
+ gin::CreateHandle(isolate, new WebRestrictionGinWrapper(render_frame));
+ if (controller.IsEmpty())
+ return;
+ v8::Local<v8::Object> global = context->Global();
+ global->Set(gin::StringToV8(isolate, "webRestriction"), controller.ToV8());
+}
+
+WebRestrictionGinWrapper::WebRestrictionGinWrapper(
+ content::RenderFrame* render_frame)
+ : render_frame_(render_frame) {}
+
+WebRestrictionGinWrapper::~WebRestrictionGinWrapper() {}
+
+bool WebRestrictionGinWrapper::RequestPermission() {
+ render_frame_->GetWebFrame()->reload();
+ return true;
+}
+
+gin::ObjectTemplateBuilder WebRestrictionGinWrapper::GetObjectTemplateBuilder(
+ v8::Isolate* isolate) {
+ return gin::Wrappable<WebRestrictionGinWrapper>::GetObjectTemplateBuilder(
+ isolate)
+ .SetMethod("requestPermission",
+ &WebRestrictionGinWrapper::RequestPermission);
+}
+
+} // namespace web_restriction

Powered by Google App Engine
This is Rietveld 408576698