| Index: chrome/browser/extensions/api/braille_private/braille_private_api.cc
|
| diff --git a/chrome/browser/extensions/api/braille_private/braille_private_api.cc b/chrome/browser/extensions/api/braille_private/braille_private_api.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..95a3f259881503efa11c133bd4e3402a4d600aa5
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/braille_private/braille_private_api.cc
|
| @@ -0,0 +1,87 @@
|
| +// Copyright (c) 2013 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 "chrome/browser/extensions/api/braille_private/braille_private_api.h"
|
| +
|
| +#include "base/lazy_instance.h"
|
| +#include "chrome/browser/extensions/api/braille_private/braille_controller.h"
|
| +#include "chrome/browser/extensions/event_names.h"
|
| +#include "chrome/browser/extensions/event_router.h"
|
| +#include "chrome/browser/extensions/extension_system.h"
|
| +
|
| +namespace WriteText = extensions::api::braille_private::WriteText;
|
| +using extensions::api::braille_private::BrailleController;
|
| +
|
| +namespace extensions {
|
| +BraillePrivateAPI::BraillePrivateAPI(Profile* profile) : profile_(profile) {
|
| + fprintf(stderr, "Creating BraillePrivateAPI");
|
| + BrailleController::GetInstance()->AddObserver(this);
|
| +}
|
| +
|
| +BraillePrivateAPI::~BraillePrivateAPI() {
|
| + BrailleController::GetInstance()->RemoveObserver(this);
|
| +}
|
| +
|
| +void BraillePrivateAPI::Shutdown() {
|
| + fprintf(stderr, "Destroying braille private api");
|
| +}
|
| +
|
| +static base::LazyInstance<ProfileKeyedAPIFactory<BraillePrivateAPI> >
|
| +g_factory = LAZY_INSTANCE_INITIALIZER;
|
| +
|
| +// static
|
| +ProfileKeyedAPIFactory<BraillePrivateAPI>*
|
| +BraillePrivateAPI::GetFactoryInstance() {
|
| + return &g_factory.Get();
|
| +}
|
| +
|
| +void BraillePrivateAPI::OnKeyEvent(
|
| + scoped_ptr<base::DictionaryValue> eventValue) {
|
| + scoped_ptr<ListValue> args(new ListValue());
|
| + args->Append(eventValue.release());
|
| + scoped_ptr<Event> event(new Event(
|
| + event_names::kBraillePrivateOnKeyEvent, args.Pass()));
|
| + ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass());
|
| +}
|
| +
|
| +namespace api {
|
| +bool BraillePrivateGetDisplayStateFunction::Prepare() {
|
| + return true;
|
| +}
|
| +
|
| +void BraillePrivateGetDisplayStateFunction::Work() {
|
| + SetResult(BrailleController::GetInstance()->GetDisplayState().release());
|
| +}
|
| +
|
| +bool BraillePrivateGetDisplayStateFunction::Respond() {
|
| + return true;
|
| +}
|
| +
|
| +bool BraillePrivateWriteTextFunction::Prepare() {
|
| + params_ = WriteText::Params::Create(*args_);
|
| + EXTENSION_FUNCTION_VALIDATE(params_);
|
| + return true;
|
| +}
|
| +
|
| +void BraillePrivateWriteTextFunction::Work() {
|
| + fprintf(stderr, "Braille text %s\n", params_->text.c_str());
|
| + BrailleController::GetInstance()->WriteText(params_->text, params_->cursor);
|
| +}
|
| +
|
| +bool BraillePrivateWriteTextFunction::Respond() {
|
| + return true;
|
| +}
|
| +
|
| +bool BraillePrivateWriteDotsFunction::Prepare() {
|
| + return false;
|
| +}
|
| +
|
| +void BraillePrivateWriteDotsFunction::Work() {
|
| +}
|
| +
|
| +bool BraillePrivateWriteDotsFunction::Respond() {
|
| + return false;
|
| +}
|
| +} // namespace api
|
| +} // extensions
|
|
|