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

Unified Diff: third_party/WebKit/Source/modules/keyboard_lock/NavigatorKeyboardLock.h

Issue 2805763004: [System-Keyboard-Lock] Forward navigator functions to RenderFrameHost (Closed)
Patch Set: Resolve review comments 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/keyboard_lock/NavigatorKeyboardLock.h
diff --git a/third_party/WebKit/Source/modules/keyboard_lock/NavigatorKeyboardLock.h b/third_party/WebKit/Source/modules/keyboard_lock/NavigatorKeyboardLock.h
new file mode 100644
index 0000000000000000000000000000000000000000..d290f88a06b1725b1a55805a684b4a3e301c407a
--- /dev/null
+++ b/third_party/WebKit/Source/modules/keyboard_lock/NavigatorKeyboardLock.h
@@ -0,0 +1,77 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NavigatorKeyboardLock_h
+#define NavigatorKeyboardLock_h
+
+#include "bindings/core/v8/ScriptPromise.h"
+#include "core/frame/Navigator.h"
+#include "platform/Supplementable.h"
+#include "platform/heap/Handle.h"
+#include "platform/heap/Member.h"
+#include "platform/wtf/Forward.h"
+#include "public/platform/modules/keyboard_lock/keyboard_lock.mojom-blink.h"
+
+namespace blink {
+
+class ScriptPromiseResolver;
+
+// The supplement of Navigator to process navigator.requestKeyLock() and
+// navigator.cancelKeyLock() web APIs. This class forwards both requests
+// directly to the browser process through mojo.
+class NavigatorKeyboardLock final
+ : public GarbageCollectedFinalized<NavigatorKeyboardLock>,
+ public Supplement<Navigator> {
+ USING_GARBAGE_COLLECTED_MIXIN(NavigatorKeyboardLock);
+
+ public:
+ // Requests to receive a set of key codes
+ // (https://www.w3.org/TR/uievents/#interface-keyboardevent) in string format.
foolip 2017/04/18 05:10:57 /TR/ links are usually stale snapshots, link to ht
Hzj_jie 2017/04/19 00:45:55 Done.
+ // The Promise will be rejected if the user or browser do not allow the web
+ // page to use this API. Otherwise, web page should expect to receive the key
+ // presses once the Promise has been resolved. This API does best effort to
+ // deliver the key codes: due to the platform restrictions, some keys or key
+ // combinations may not be able to receive or intercept by the user agent.
+ // - Making two requests concurrently without waiting for one Promise to
+ // finish is disallowed, the second Promise will be rejected immediately.
+ // - Making a second request after the Promise of the first one has finished
+ // is allowed; the second request will overwrite the key codes reserved.
foolip 2017/04/18 05:10:57 https://garykac.github.io/system-keyboard-lock/#re
Hzj_jie 2017/04/19 00:45:55 Yes, I have updated the idl file to include all th
+ // - Passing in an empty keyCodes array will reserve all keys.
+ static ScriptPromise requestKeyLock(ScriptState*,
+ Navigator&,
+ const Vector<String>&);
+
+ // Equals to execute navigator.requestKeyLock([]);
+ static ScriptPromise requestKeyLock(ScriptState*, Navigator&);
foolip 2017/04/18 05:10:57 You should be able to remove this if the IDL has [
Hzj_jie 2017/04/19 00:45:55 Done.
+
+ // Removes all reserved keys. This function is also asynchronized, the web
+ // page may still receive reserved keys after this function has finished. Once
+ // the web page is closed, the user agent implictly executes this API.
+ static void cancelKeyLock(Navigator&);
+
+ DECLARE_TRACE();
+
+ private:
+ explicit NavigatorKeyboardLock(Navigator&);
+ static const char* SupplementName();
+
+ static NavigatorKeyboardLock& From(Navigator&);
+
+ ScriptPromise requestKeyLock(ScriptState*, const Vector<String>&);
+ void cancelKeyLock();
+
+ // Ensures the |service_| is correctly initialized. In case of the |service_|
+ // cannot be initialized, this function returns false, and returns error
+ // message through the |error_message| if it's not a nullptr.
+ bool EnsureServiceConnected(String* error_message);
+
+ void LockRequestFinished(bool, const String&);
+
+ mojom::blink::KeyboardLockServicePtr service_;
+ Member<ScriptPromiseResolver> request_keylock_resolver_;
+};
+
+} // namespace blink
+
+#endif // NavigatorKeyboardLock_h

Powered by Google App Engine
This is Rietveld 408576698