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

Side by Side Diff: components/web_restrictions/renderer/web_restrictions_gin_wrapper.cc

Issue 1890203002: Implement Web Restrictions in WebView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix final nits Created 4 years, 4 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
(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_restrictions/renderer/web_restrictions_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_restrictions {
14
15 gin::WrapperInfo WebRestrictionsGinWrapper::kWrapperInfo = {
16 gin::kEmbedderNativeGin};
17
18 // static
19 void WebRestrictionsGinWrapper::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<WebRestrictionsGinWrapper> controller =
28 gin::CreateHandle(isolate, new WebRestrictionsGinWrapper(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 WebRestrictionsGinWrapper::WebRestrictionsGinWrapper(
36 content::RenderFrame* render_frame)
37 : content::RenderFrameObserver(render_frame) {}
38
39 WebRestrictionsGinWrapper::~WebRestrictionsGinWrapper() {}
40
41 bool WebRestrictionsGinWrapper::RequestPermission() {
42 if (!render_frame())
43 return false;
44 render_frame()->GetWebFrame()->reload();
45 return true;
46 }
47
48 void WebRestrictionsGinWrapper::OnDestruct() {
49 // Do nothing. Overrides version that deletes RenderFrameObserver.
50 }
51
52 gin::ObjectTemplateBuilder WebRestrictionsGinWrapper::GetObjectTemplateBuilder(
53 v8::Isolate* isolate) {
54 return gin::Wrappable<WebRestrictionsGinWrapper>::GetObjectTemplateBuilder(
55 isolate)
56 .SetMethod("requestPermission",
57 &WebRestrictionsGinWrapper::RequestPermission);
58 }
59
60 } // namespace web_restrictions
OLDNEW
« no previous file with comments | « components/web_restrictions/renderer/web_restrictions_gin_wrapper.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698