Skip to content

Commit

Permalink
[System-Keyboard-Lock] Forward navigator functions to RenderFrameHost
Browse files Browse the repository at this point in the history
This change forwards navigator.requestKeyLock() and navigator.cancelKeyLock()
functions to the RenderFrameHostImpl.

System-Keyboard-Lock is a feature to detect the key presses which usually cannot
be received by the browser, and send them to the web page. It contains various
components to achieve the goal. This change is one of them, which receives
JavaScript (or Web Platform API in the design doc) function calls and forwards
them into RenderFrameHost. For detail, please refer to the design doc at,
https://docs.google.com/document/d/1T9gJHYdA1VGZ6QHQeOu0hOacWWWJ7yNEt1VDbLju4bs/edit#heading=h.cgwemqs2j4ta

W3C Working Draft: https://garykac.github.io/system-keyboard-lock/
Intent to implement: https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/9pauQUAvrcw/lfbG7eunCAAJ

BUG=680809
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_site_isolation

Review-Url: https://codereview.chromium.org/2805763004
Cr-Commit-Position: refs/heads/master@{#468158}
  • Loading branch information
zijiehe authored and Commit bot committed Apr 28, 2017
1 parent 56fc9d6 commit 6016778
Show file tree
Hide file tree
Showing 25 changed files with 444 additions and 0 deletions.
2 changes: 2 additions & 0 deletions content/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,8 @@ source_set("browser") {
"indexed_db/list_set.h",
"installedapp/installed_app_provider_impl_default.cc",
"installedapp/installed_app_provider_impl_default.h",
"keyboard_lock/keyboard_lock_service_impl.cc",
"keyboard_lock/keyboard_lock_service_impl.h",
"leveldb_wrapper_impl.cc",
"leveldb_wrapper_impl.h",
"loader/async_resource_handler.cc",
Expand Down
1 change: 1 addition & 0 deletions content/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ include_rules = [
"+third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h",
"+third_party/WebKit/public/platform/modules/installedapp/installed_app_provider.mojom.h",
"+third_party/WebKit/public/platform/modules/installedapp/related_application.mojom.h",
"+third_party/WebKit/public/platform/modules/keyboard_lock/keyboard_lock.mojom.h",
"+third_party/WebKit/public/platform/modules/mediasession/media_session.mojom.h",
"+third_party/WebKit/public/platform/modules/notifications/WebNotificationConstants.h",
"+third_party/WebKit/public/platform/modules/notifications/notification.mojom.h",
Expand Down
4 changes: 4 additions & 0 deletions content/browser/frame_host/render_frame_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "content/browser/frame_host/render_frame_proxy_host.h"
#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
#include "content/browser/installedapp/installed_app_provider_impl_default.h"
#include "content/browser/keyboard_lock/keyboard_lock_service_impl.h"
#include "content/browser/loader/resource_dispatcher_host_impl.h"
#include "content/browser/media/media_interface_proxy.h"
#include "content/browser/media/session/media_session_service_impl.h"
Expand Down Expand Up @@ -2714,6 +2715,9 @@ void RenderFrameHostImpl::RegisterMojoInterfaces() {
&RemoterFactoryImpl::Bind, GetProcess()->GetID(), GetRoutingID()));
#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)

GetInterfaceRegistry()->AddInterface(base::Bind(
&KeyboardLockServiceImpl::CreateMojoService));

GetContentClient()->browser()->ExposeInterfacesToFrame(GetInterfaceRegistry(),
this);
}
Expand Down
38 changes: 38 additions & 0 deletions content/browser/keyboard_lock/keyboard_lock_service_impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.

#include "content/browser/keyboard_lock/keyboard_lock_service_impl.h"

#include <memory>
#include <utility>

#include "base/memory/ptr_util.h"
#include "content/public/browser/render_frame_host.h"

namespace content {

KeyboardLockServiceImpl::KeyboardLockServiceImpl() = default;

KeyboardLockServiceImpl::~KeyboardLockServiceImpl() = default;

// static
void KeyboardLockServiceImpl::CreateMojoService(
blink::mojom::KeyboardLockServiceRequest request) {
mojo::MakeStrongBinding(
base::MakeUnique<KeyboardLockServiceImpl>(),
std::move(request));
}

void KeyboardLockServiceImpl::RequestKeyLock(
const std::vector<std::string>& key_codes,
const RequestKeyLockCallback& callback) {
// TODO(zijiehe): Implementation required.
callback.Run(true, std::string());
}

void KeyboardLockServiceImpl::CancelKeyLock() {
// TODO(zijiehe): Implementation required.
}

} // namespace content
29 changes: 29 additions & 0 deletions content/browser/keyboard_lock/keyboard_lock_service_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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.

#include <string>
#include <vector>

#include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "third_party/WebKit/public/platform/modules/keyboard_lock/keyboard_lock.mojom.h"

namespace content {

class CONTENT_EXPORT KeyboardLockServiceImpl
: public NON_EXPORTED_BASE(blink::mojom::KeyboardLockService) {
public:
KeyboardLockServiceImpl();
~KeyboardLockServiceImpl() override;

static void CreateMojoService(
blink::mojom::KeyboardLockServiceRequest request);

// blink::mojom::KeyboardLockService implementations.
void RequestKeyLock(const std::vector<std::string>& key_codes,
const RequestKeyLockCallback& callback) override;
void CancelKeyLock() override;
};

} // namespace
1 change: 1 addition & 0 deletions content/public/app/mojo/content_browser_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
// impossible this week. Remove once sky/ken fix this.
"autofill::mojom::AutofillDriver",
"autofill::mojom::PasswordManagerDriver",
"blink::mojom::KeyboardLockService",
"blink::mojom::MediaSessionService",
"blink::mojom::PermissionService",
"blink::mojom::PresentationService",
Expand Down
5 changes: 5 additions & 0 deletions third_party/WebKit/LayoutTests/W3CImportExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -734,3 +734,8 @@ external/wpt/uievents/order-of-events/mouse-events/click-order-manual.html [ Ski
external/wpt/uievents/order-of-events/mouse-events/mouseevents-mousemove-manual.htm [ Skip ]
external/wpt/uievents/order-of-events/mouse-events/mousemove-across-manual.html [ Skip ]
external/wpt/uievents/order-of-events/mouse-events/mousemove-between-manual.html [ Skip ]
external/wpt/keyboard-lock/idlharness.https.html [ Skip ]
external/wpt/keyboard-lock/navigator-cancelKeyLock.https.html [ Skip ]
external/wpt/keyboard-lock/navigator-requestKeyLock.https.html [ Skip ]
external/wpt/keyboard-lock/navigator-requestKeyLock-two-parallel-requests.https.html [ Skip ]
external/wpt/keyboard-lock/navigator-requestKeyLock-two-sequential-requests.https.html [ Skip ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This is a testharness.js-based test.
FAIL Navigator interface: operation requestKeyLock(sequence) assert_throws: calling operation with this = null didn't throw TypeError function "function () {
fn.apply(obj, args);
}" did not throw
PASS Navigator interface: operation cancelKeyLock()
PASS Navigator must be primary interface of navigator
PASS Stringification of navigator
PASS Navigator interface: navigator must inherit property "requestKeyLock" with the proper type (0)
PASS Navigator interface: calling requestKeyLock(sequence) on navigator with too few arguments must throw TypeError
PASS Navigator interface: navigator must inherit property "cancelKeyLock" with the proper type (1)
Harness: the test ran to completion.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!doctype html>
<html>
<head>
<title>Keyboard Lock IDL tests</title>
<link rel="help" href="https://github.com/w3c/keyboard-lock"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/WebIDLParser.js"></script>
<script src="/resources/idlharness.js"></script>
</head>
<body>
<pre id="untested_idl" style="display: none">
interface Navigator {
};
</pre>
<!--
The reason of the failure of requestKeyLock test looks like a code defect in
idlharness.js. media-capabilities/idlharness.html is also impacted by this
issue. See https://codereview.chromium.org/2805763004/#ps620001, which
includes a potential fix.
TODO(zijiehe): Submit the fix.
-->
<pre id="idl" style="display: none">
partial interface Navigator {
[SecureContext] Promise<void> requestKeyLock(optional sequence<DOMString> keyCodes = []);
[SecureContext] void cancelKeyLock();
};
</pre>
<script>
var idl_array = new IdlArray();
idl_array.add_untested_idls(
document.getElementById("untested_idl").textContent);
idl_array.add_idls(document.getElementById("idl").textContent);
idl_array.add_objects({
Navigator: ["navigator"]
});
idl_array.test();
</script>
<div id="log"></div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';

test(() => {
assert_equals(navigator.cancelKeyLock(),
undefined);
}, 'Keyboard Lock cancelKeyLock');

</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';

promise_test((t) => {
const p1 = navigator.requestKeyLock(['a', 'b']);
const p2 = navigator.requestKeyLock(['c', 'd']);
return promise_rejects(t, null, p2,
'requestKeyLock() should only be ' +
'executed if another request has finished.');
}, 'Keyboard Lock requestKeyLock twice in parallel');

</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';

promise_test(() => {
return navigator.requestKeyLock(['a', 'b'])
.then(() => {
return navigator.requestKeyLock(['c', 'd']);
});
}, 'Keyboard Lock requestKeyLock twice sequentially');

</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';

promise_test(() => {
const p = navigator.requestKeyLock(['a', 'b']);
assert_true(p instanceof Promise);
return p;
}, 'Keyboard Lock requestKeyLock');

</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4361,6 +4361,7 @@ interface Navigator
getter vendorSub
getter webkitPersistentStorage
getter webkitTemporaryStorage
method cancelKeyLock
method constructor
method getBattery
method getGamepads
Expand All @@ -4370,6 +4371,7 @@ interface Navigator
method isProtocolHandlerRegistered
method javaEnabled
method registerProtocolHandler
method requestKeyLock
method requestMIDIAccess
method requestMediaKeySystemAccess
method sendBeacon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4368,6 +4368,7 @@ interface Navigator
getter vendorSub
getter webkitPersistentStorage
getter webkitTemporaryStorage
method cancelKeyLock
method constructor
method getBattery
method getGamepads
Expand All @@ -4377,6 +4378,7 @@ interface Navigator
method isProtocolHandlerRegistered
method javaEnabled
method registerProtocolHandler
method requestKeyLock
method requestMIDIAccess
method requestMediaKeySystemAccess
method sendBeacon
Expand Down
1 change: 1 addition & 0 deletions third_party/WebKit/Source/modules/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ target(modules_target_type, "modules") {
"//third_party/WebKit/Source/modules/indexeddb",
"//third_party/WebKit/Source/modules/installation",
"//third_party/WebKit/Source/modules/installedapp",
"//third_party/WebKit/Source/modules/keyboard_lock",
"//third_party/WebKit/Source/modules/media_capabilities",
"//third_party/WebKit/Source/modules/media_controls",
"//third_party/WebKit/Source/modules/mediacapturefromelement",
Expand Down
12 changes: 12 additions & 0 deletions third_party/WebKit/Source/modules/keyboard_lock/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 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.

import("//third_party/WebKit/Source/modules/modules.gni")

blink_modules_sources("keyboard_lock") {
sources = [
"NavigatorKeyboardLock.cpp",
"NavigatorKeyboardLock.h",
]
}
Loading

0 comments on commit 6016778

Please sign in to comment.