OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/web_restriction/web_restriction_gin_wrapper.h" |
| 6 |
| 7 #include "content/public/renderer/render_frame.h" |
| 8 #include "gin/handle.h" |
| 9 #include "gin/object_template_builder.h" |
| 10 #include "third_party/WebKit/public/web/WebKit.h" |
| 11 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 12 |
| 13 namespace web_restriction { |
| 14 |
| 15 gin::WrapperInfo WebRestrictionGinWrapper::kWrapperInfo = { |
| 16 gin::kEmbedderNativeGin}; |
| 17 |
| 18 // static |
| 19 void WebRestrictionGinWrapper::Install(content::RenderFrame* render_frame) { |
| 20 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 21 v8::HandleScope handle_scope(isolate); |
| 22 v8::Local<v8::Context> context = |
| 23 render_frame->GetWebFrame()->mainWorldScriptContext(); |
| 24 if (context.IsEmpty()) |
| 25 return; |
| 26 v8::Context::Scope context_scope(context); |
| 27 gin::Handle<WebRestrictionGinWrapper> controller = |
| 28 gin::CreateHandle(isolate, new WebRestrictionGinWrapper(render_frame)); |
| 29 if (controller.IsEmpty()) |
| 30 return; |
| 31 v8::Local<v8::Object> global = context->Global(); |
| 32 global->Set(gin::StringToV8(isolate, "webRestriction"), controller.ToV8()); |
| 33 } |
| 34 |
| 35 WebRestrictionGinWrapper::WebRestrictionGinWrapper( |
| 36 content::RenderFrame* render_frame) |
| 37 : render_frame_(render_frame) {} |
| 38 |
| 39 WebRestrictionGinWrapper::~WebRestrictionGinWrapper() {} |
| 40 |
| 41 bool WebRestrictionGinWrapper::RequestPermission() { |
| 42 render_frame_->GetWebFrame()->reload(); |
| 43 return true; |
| 44 } |
| 45 |
| 46 gin::ObjectTemplateBuilder WebRestrictionGinWrapper::GetObjectTemplateBuilder( |
| 47 v8::Isolate* isolate) { |
| 48 return gin::Wrappable<WebRestrictionGinWrapper>::GetObjectTemplateBuilder( |
| 49 isolate) |
| 50 .SetMethod("requestPermission", |
| 51 &WebRestrictionGinWrapper::RequestPermission); |
| 52 } |
| 53 |
| 54 } // namespace web_restriction |
OLD | NEW |