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

Side by Side Diff: content/browser/keyboard_lock/keyboard_lock_service_impl.cc

Issue 2879033002: Keyboard Lock Host implementation
Patch Set: Missing change to rename CodeToUsbKeycode to CodeStringToUsbKeycode Created 3 years, 6 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
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 #include "content/browser/keyboard_lock/keyboard_lock_service_impl.h" 5 #include "content/browser/keyboard_lock/keyboard_lock_service_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h"
11 #include "base/location.h"
12 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "components/keyboard_lock/keyboard_lock_host.h"
15 #include "content/public/browser/web_contents.h"
11 #include "content/public/browser/render_frame_host.h" 16 #include "content/public/browser/render_frame_host.h"
12 17
13 namespace content { 18 namespace content {
14 19
15 KeyboardLockServiceImpl::KeyboardLockServiceImpl() = default; 20 KeyboardLockServiceImpl::KeyboardLockServiceImpl(
21 RenderFrameHost* render_frame_host)
22 : web_contents_(WebContents::FromRenderFrameHost(render_frame_host)) {
23 DCHECK(web_contents_);
24 }
16 25
17 KeyboardLockServiceImpl::~KeyboardLockServiceImpl() = default; 26 KeyboardLockServiceImpl::~KeyboardLockServiceImpl() = default;
18 27
19 // static 28 // static
20 void KeyboardLockServiceImpl::CreateMojoService( 29 void KeyboardLockServiceImpl::CreateMojoService(
30 RenderFrameHost* render_frame_host,
21 const service_manager::BindSourceInfo& source_info, 31 const service_manager::BindSourceInfo& source_info,
22 blink::mojom::KeyboardLockServiceRequest request) { 32 blink::mojom::KeyboardLockServiceRequest request) {
23 mojo::MakeStrongBinding( 33 mojo::MakeStrongBinding(
24 base::MakeUnique<KeyboardLockServiceImpl>(), 34 base::MakeUnique<KeyboardLockServiceImpl>(render_frame_host),
25 std::move(request)); 35 std::move(request));
26 } 36 }
27 37
28 void KeyboardLockServiceImpl::RequestKeyboardLock( 38 void KeyboardLockServiceImpl::RequestKeyboardLock(
29 const std::vector<std::string>& key_codes, 39 const std::vector<std::string>& key_codes,
30 const RequestKeyboardLockCallback& callback) { 40 const RequestKeyboardLockCallback& callback) {
31 // TODO(zijiehe): Implementation required. 41 keyboard_lock::KeyboardLockHost* host =
32 callback.Run(blink::mojom::KeyboardLockRequestResult::SUCCESS); 42 keyboard_lock::KeyboardLockHost::Find(web_contents_);
43 if (!host) {
44 // This should not happen in production.
45 callback.Run(blink::mojom::KeyboardLockRequestResult::SUCCESS);
46 return;
47 }
48
49 host->SetReservedKeyCodes(web_contents_, key_codes,
50 base::Bind([](RequestKeyboardLockCallback callback, bool result) {
51 callback.Run(
52 blink::mojom::KeyboardLockRequestResult::SUCCESS);
53 },
54 callback));
33 } 55 }
34 56
35 void KeyboardLockServiceImpl::CancelKeyboardLock() { 57 void KeyboardLockServiceImpl::CancelKeyboardLock() {
36 // TODO(zijiehe): Implementation required. 58 keyboard_lock::KeyboardLockHost* host =
59 keyboard_lock::KeyboardLockHost::Find(web_contents_);
60 if (!host) {
61 // This should not happen in production.
62 return;
63 }
64 host->ClearReservedKeys(web_contents_, base::Callback<void(bool)>());
37 } 65 }
38 66
39 } // namespace content 67 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/keyboard_lock/keyboard_lock_service_impl.h ('k') | content/public/browser/web_contents_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698