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

Side by Side Diff: third_party/WebKit/Source/modules/keyboard_lock/NavigatorKeyboardLock.cpp

Issue 2805763004: [System-Keyboard-Lock] Forward navigator functions to RenderFrameHost (Closed)
Patch Set: Add external/wpt tests Created 3 years, 8 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 2017 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 "modules/keyboard_lock/NavigatorKeyboardLock.h"
6
7 #include "bindings/core/v8/ScriptPromise.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "bindings/core/v8/V8Binding.h"
10 #include "core/frame/LocalFrame.h"
11 #include "platform/heap/Persistent.h"
12 #include "platform/wtf/Assertions.h"
13 #include "platform/wtf/Functional.h"
14 #include "public/platform/InterfaceProvider.h"
15
16 namespace blink {
17
18 NavigatorKeyboardLock::NavigatorKeyboardLock(Navigator& navigator)
19 : Supplement<Navigator>(navigator) {}
20
21 NavigatorKeyboardLock& NavigatorKeyboardLock::From(Navigator& navigator) {
22 NavigatorKeyboardLock* supplement = static_cast<NavigatorKeyboardLock*>(
23 Supplement<Navigator>::From(navigator, SupplementName()));
24 if (!supplement) {
25 supplement = new NavigatorKeyboardLock(navigator);
26 ProvideTo(navigator, SupplementName(), supplement);
27 }
28 return *supplement;
29 }
30
31 // static
32 ScriptPromise NavigatorKeyboardLock::requestKeyLock(
33 ScriptState* state,
34 Navigator& navigator,
35 const Vector<String>& keycodes) {
36 return NavigatorKeyboardLock::From(navigator).requestKeyLock(state, keycodes);
37 }
38
39 ScriptPromise NavigatorKeyboardLock::requestKeyLock(
40 ScriptState* state,
41 const Vector<String>& keycodes) {
42 DCHECK(state);
43 if (request_keylock_resolver_) {
44 return ScriptPromise::Reject(
45 state, V8String(state->GetIsolate(),
46 "Last requestKeyLock() has not finished yet."));
47 }
48
49 if (!service_) {
50 GetSupplementable()->GetFrame()->GetInterfaceProvider()->GetInterface(
51 mojo::MakeRequest(&service_));
52 }
53
54 if (!service_.get()) {
55 return ScriptPromise::Reject(
56 state, V8String(state->GetIsolate(), "Browser is not connecting."));
57 }
58
59 request_keylock_resolver_ = ScriptPromiseResolver::Create(state);
60 service_->RequestKeyLock(
61 keycodes,
62 ConvertToBaseCallback(WTF::Bind(
63 &NavigatorKeyboardLock::LockRequestFinished, WrapPersistent(this))));
64 return request_keylock_resolver_->Promise();
65 }
66
67 void NavigatorKeyboardLock::cancelKeyLock() {
68 if (!service_) {
69 GetSupplementable()->GetFrame()->GetInterfaceProvider()->GetInterface(
70 mojo::MakeRequest(&service_));
71 }
72
73 if (!service_.get()) {
whywhat 2017/04/12 16:02:13 nit: one line blocks don't require {}
Hzj_jie 2017/04/13 00:38:54 Done.
74 return;
75 }
76
77 service_->CancelKeyLock(ConvertToBaseCallback(WTF::Bind(
78 &NavigatorKeyboardLock::CancelRequestFinished, WrapPersistent(this))));
79 }
80
81 // static
82 void NavigatorKeyboardLock::cancelKeyLock(Navigator& navigator) {
83 NavigatorKeyboardLock::From(navigator).cancelKeyLock();
84 }
85
86 void NavigatorKeyboardLock::LockRequestFinished(bool allowed,
87 const String& reason) {
88 DCHECK(request_keylock_resolver_);
89 if (allowed) {
whywhat 2017/04/12 16:02:13 nit: ditto
Hzj_jie 2017/04/13 00:38:54 Done.
90 request_keylock_resolver_->Resolve();
91 } else {
92 request_keylock_resolver_->Reject(reason);
93 }
94 request_keylock_resolver_ = nullptr;
95 }
96
97 void NavigatorKeyboardLock::CancelRequestFinished() {
98 // TODO(zijiehe): The response of CancelKeyLock may need to be forwarded to
whywhat 2017/04/12 16:02:13 nit: you could not submit the unused code path unt
Hzj_jie 2017/04/13 00:38:54 Done.
99 // the web page.
100 }
101
102 // static
103 const char* NavigatorKeyboardLock::SupplementName() {
104 return "NavigatorKeyboardLock";
105 }
106
107 DEFINE_TRACE(NavigatorKeyboardLock) {
108 visitor->Trace(request_keylock_resolver_);
109 Supplement<Navigator>::Trace(visitor);
110 }
111
112 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698