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/supervised_user_error_page/supervised_user_gin_wrapper.h" | |
6 | |
7 #include "base/strings/utf_string_conversions.h" | |
8 #include "components/web_restrictions/browser/web_restrictions_client.h" | |
9 #include "content/public/renderer/render_frame.h" | |
10 #include "gin/handle.h" | |
11 #include "gin/object_template_builder.h" | |
12 #include "third_party/WebKit/public/web/WebKit.h" | |
13 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
14 | |
15 namespace supervised_user_error_page { | |
16 | |
17 gin::WrapperInfo SupervisedUserGinWrapper::kWrapperInfo = { | |
18 gin::kEmbedderNativeGin}; | |
19 | |
20 // static | |
21 void SupervisedUserGinWrapper::Install( | |
22 content::RenderFrame* render_frame, | |
23 const std::string& url, | |
24 const web_restrictions::mojom::WebRestrictionsPtr& | |
25 web_restrictions_service) { | |
26 v8::Isolate* isolate = blink::mainThreadIsolate(); | |
27 v8::HandleScope handle_scope(isolate); | |
28 v8::Local<v8::Context> context = | |
29 render_frame->GetWebFrame()->mainWorldScriptContext(); | |
30 if (context.IsEmpty()) | |
31 return; | |
32 v8::Context::Scope context_scope(context); | |
33 gin::Handle<SupervisedUserGinWrapper> controller = gin::CreateHandle( | |
34 isolate, new SupervisedUserGinWrapper(render_frame, url, | |
35 web_restrictions_service)); | |
36 if (controller.IsEmpty()) | |
37 return; | |
38 v8::Local<v8::Object> global = context->Global(); | |
39 global->Set(gin::StringToV8(isolate, "webRestrictions"), controller.ToV8()); | |
40 } | |
41 | |
42 SupervisedUserGinWrapper::SupervisedUserGinWrapper( | |
43 content::RenderFrame* render_frame, | |
44 const std::string& url, | |
45 const web_restrictions::mojom::WebRestrictionsPtr& web_restrictions_service) | |
46 : content::RenderFrameObserver(render_frame), | |
47 url_(url), | |
48 web_restrictions_service_(web_restrictions_service), | |
49 weak_ptr_factory_(this) {} | |
50 | |
51 SupervisedUserGinWrapper::~SupervisedUserGinWrapper() {} | |
52 | |
53 bool SupervisedUserGinWrapper::RequestPermission() { | |
54 if (!render_frame()) | |
55 return false; | |
56 web_restrictions_service_->RequestPermission( | |
57 url_, base::Bind(&SupervisedUserGinWrapper::OnAccessRequestAdded, | |
58 weak_ptr_factory_.GetWeakPtr())); | |
59 render_frame()->GetWebFrame()->reload(); | |
60 return true; | |
61 } | |
62 | |
63 void SupervisedUserGinWrapper::OnAccessRequestAdded(bool success) { | |
64 VLOG(1) << "Sent access request for " << url_ | |
65 << (success ? " successfully" : " unsuccessfully"); | |
66 std::string jsFunc = | |
67 success ? "setRequestStatus(true);" : "setRequestStatus(false);"; | |
68 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
| |
69 } | |
70 | |
71 void SupervisedUserGinWrapper::OnDestruct() { | |
72 // Do nothing. Overrides version that deletes RenderFrameObserver. | |
73 } | |
74 | |
75 gin::ObjectTemplateBuilder SupervisedUserGinWrapper::GetObjectTemplateBuilder( | |
76 v8::Isolate* isolate) { | |
77 return gin::Wrappable<SupervisedUserGinWrapper>::GetObjectTemplateBuilder( | |
78 isolate) | |
79 .SetMethod("requestPermission", | |
80 &SupervisedUserGinWrapper::RequestPermission); | |
81 } | |
82 | |
83 } // namespace web_restrictions | |
OLD | NEW |