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

Side by Side Diff: chrome/browser/extensions/api/braille_private/braille_private_api.cc

Issue 13355002: Implement chrome.brailleDisplayPrivate API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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 (c) 2013 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 "chrome/browser/extensions/api/braille_private/braille_private_api.h"
6
7 #include "base/lazy_instance.h"
8 #include "chrome/browser/extensions/api/braille_private/braille_controller.h"
9 #include "chrome/browser/extensions/event_names.h"
10 #include "chrome/browser/extensions/event_router.h"
11 #include "chrome/browser/extensions/extension_system.h"
12
13 namespace WriteText = extensions::api::braille_private::WriteText;
14 using extensions::api::braille_private::BrailleController;
15
16 namespace extensions {
17 BraillePrivateAPI::BraillePrivateAPI(Profile* profile) : profile_(profile) {
18 fprintf(stderr, "Creating BraillePrivateAPI");
19 BrailleController::GetInstance()->AddObserver(this);
20 }
21
22 BraillePrivateAPI::~BraillePrivateAPI() {
23 BrailleController::GetInstance()->RemoveObserver(this);
24 }
25
26 void BraillePrivateAPI::Shutdown() {
27 fprintf(stderr, "Destroying braille private api");
28 }
29
30 static base::LazyInstance<ProfileKeyedAPIFactory<BraillePrivateAPI> >
31 g_factory = LAZY_INSTANCE_INITIALIZER;
32
33 // static
34 ProfileKeyedAPIFactory<BraillePrivateAPI>*
35 BraillePrivateAPI::GetFactoryInstance() {
36 return &g_factory.Get();
37 }
38
39 void BraillePrivateAPI::OnKeyEvent(
40 scoped_ptr<base::DictionaryValue> eventValue) {
41 scoped_ptr<ListValue> args(new ListValue());
42 args->Append(eventValue.release());
43 scoped_ptr<Event> event(new Event(
44 event_names::kBraillePrivateOnKeyEvent, args.Pass()));
45 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass());
46 }
47
48 namespace api {
49 bool BraillePrivateGetDisplayStateFunction::Prepare() {
50 return true;
51 }
52
53 void BraillePrivateGetDisplayStateFunction::Work() {
54 SetResult(BrailleController::GetInstance()->GetDisplayState().release());
55 }
56
57 bool BraillePrivateGetDisplayStateFunction::Respond() {
58 return true;
59 }
60
61 bool BraillePrivateWriteTextFunction::Prepare() {
62 params_ = WriteText::Params::Create(*args_);
63 EXTENSION_FUNCTION_VALIDATE(params_);
64 return true;
65 }
66
67 void BraillePrivateWriteTextFunction::Work() {
68 fprintf(stderr, "Braille text %s\n", params_->text.c_str());
69 BrailleController::GetInstance()->WriteText(params_->text, params_->cursor);
70 }
71
72 bool BraillePrivateWriteTextFunction::Respond() {
73 return true;
74 }
75
76 bool BraillePrivateWriteDotsFunction::Prepare() {
77 return false;
78 }
79
80 void BraillePrivateWriteDotsFunction::Work() {
81 }
82
83 bool BraillePrivateWriteDotsFunction::Respond() {
84 return false;
85 }
86 } // namespace api
87 } // extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698