OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NavigatorKeyboardLock_h | 5 #ifndef NavigatorKeyboardLock_h |
6 #define NavigatorKeyboardLock_h | 6 #define NavigatorKeyboardLock_h |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "core/frame/Navigator.h" | 9 #include "core/frame/Navigator.h" |
10 #include "platform/Supplementable.h" | 10 #include "platform/Supplementable.h" |
11 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
12 #include "platform/heap/Member.h" | 12 #include "platform/heap/Member.h" |
13 #include "platform/wtf/Forward.h" | 13 #include "platform/wtf/Forward.h" |
14 #include "public/platform/modules/keyboard_lock/keyboard_lock.mojom-blink.h" | 14 #include "public/platform/modules/keyboard_lock/keyboard_lock.mojom-blink.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 class ScriptPromiseResolver; | 18 class ScriptPromiseResolver; |
19 | 19 |
20 // The supplement of Navigator to process navigator.requestKeyLock() and | 20 // The supplement of Navigator to process navigator.requestKeyboardLock() and |
21 // navigator.cancelKeyLock() web APIs. This class forwards both requests | 21 // navigator.cancelKeyboardLock() web APIs. This class forwards both requests |
22 // directly to the browser process through mojo. | 22 // directly to the browser process through mojo. |
23 class NavigatorKeyboardLock final | 23 class NavigatorKeyboardLock final |
24 : public GarbageCollectedFinalized<NavigatorKeyboardLock>, | 24 : public GarbageCollectedFinalized<NavigatorKeyboardLock>, |
25 public Supplement<Navigator> { | 25 public Supplement<Navigator> { |
26 USING_GARBAGE_COLLECTED_MIXIN(NavigatorKeyboardLock); | 26 USING_GARBAGE_COLLECTED_MIXIN(NavigatorKeyboardLock); |
27 | 27 |
28 public: | 28 public: |
29 // Requests to receive a set of key codes | 29 // Requests to receive a set of key codes |
30 // (https://w3c.github.io/uievents/#dom-keyboardevent-code) in string format. | 30 // (https://w3c.github.io/uievents/#dom-keyboardevent-code) in string format. |
31 // The Promise will be rejected if the user or browser do not allow the web | 31 // The Promise will be rejected if the user or browser do not allow the web |
32 // page to use this API. Otherwise, web page should expect to receive the key | 32 // page to use this API. Otherwise, web page should expect to receive the key |
33 // presses once the Promise has been resolved. This API does best effort to | 33 // presses once the Promise has been resolved. This API does best effort to |
34 // deliver the key codes: due to the platform restrictions, some keys or key | 34 // deliver the key codes: due to the platform restrictions, some keys or key |
35 // combinations may not be able to receive or intercept by the user agent. | 35 // combinations may not be able to receive or intercept by the user agent. |
36 // - Making two requests concurrently without waiting for one Promise to | 36 // - Making two requests concurrently without waiting for one Promise to |
37 // finish is disallowed, the second Promise will be rejected immediately. | 37 // finish is disallowed, the second Promise will be rejected immediately. |
38 // - Making a second request after the Promise of the first one has finished | 38 // - Making a second request after the Promise of the first one has finished |
39 // is allowed; the second request will overwrite the key codes reserved. | 39 // is allowed; the second request will overwrite the key codes reserved. |
40 // - Passing in an empty keyCodes array will reserve all keys. | 40 // - Passing in an empty keyCodes array will reserve all keys. |
41 static ScriptPromise requestKeyLock(ScriptState*, | 41 static ScriptPromise requestKeyboardLock(ScriptState*, |
42 Navigator&, | 42 Navigator&, |
43 const Vector<String>&); | 43 const Vector<String>&); |
44 | 44 |
45 // Removes all reserved keys. This function is also asynchronized, the web | 45 // Removes all reserved keys. This function is also asynchronized, the web |
46 // page may still receive reserved keys after this function has finished. Once | 46 // page may still receive reserved keys after this function has finished. Once |
47 // the web page is closed, the user agent implicitly executes this API. | 47 // the web page is closed, the user agent implicitly executes this API. |
48 static void cancelKeyLock(Navigator&); | 48 static void cancelKeyboardLock(Navigator&); |
49 | 49 |
50 DECLARE_TRACE(); | 50 DECLARE_TRACE(); |
51 | 51 |
52 private: | 52 private: |
53 explicit NavigatorKeyboardLock(Navigator&); | 53 explicit NavigatorKeyboardLock(Navigator&); |
54 static const char* SupplementName(); | 54 static const char* SupplementName(); |
55 | 55 |
56 static NavigatorKeyboardLock& From(Navigator&); | 56 static NavigatorKeyboardLock& From(Navigator&); |
57 | 57 |
58 ScriptPromise requestKeyLock(ScriptState*, const Vector<String>&); | 58 ScriptPromise requestKeyboardLock(ScriptState*, const Vector<String>&); |
59 void cancelKeyLock(); | 59 void cancelKeyboardLock(); |
60 | 60 |
61 // Ensures the |service_| is correctly initialized. In case of the |service_| | 61 // Ensures the |service_| is correctly initialized. In case of the |service_| |
62 // cannot be initialized, this function returns false. | 62 // cannot be initialized, this function returns false. |
63 bool EnsureServiceConnected(); | 63 bool EnsureServiceConnected(); |
64 | 64 |
65 void LockRequestFinished(bool, const String&); | 65 void LockRequestFinished(mojom::KeyboardLockRequestResult); |
66 | 66 |
67 mojom::blink::KeyboardLockServicePtr service_; | 67 mojom::blink::KeyboardLockServicePtr service_; |
68 Member<ScriptPromiseResolver> request_keylock_resolver_; | 68 Member<ScriptPromiseResolver> request_keylock_resolver_; |
69 }; | 69 }; |
70 | 70 |
71 } // namespace blink | 71 } // namespace blink |
72 | 72 |
73 #endif // NavigatorKeyboardLock_h | 73 #endif // NavigatorKeyboardLock_h |
OLD | NEW |