diff options
author | dtseng@chromium.org <dtseng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-02 17:19:46 +0000 |
---|---|---|
committer | dtseng@chromium.org <dtseng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-02 17:19:46 +0000 |
commit | 22aa4b67754f518c46bec79c9bedc22a82396e95 (patch) | |
tree | dc417e53bd0f2e44b240101fa42d5010c9027699 /chrome/browser | |
parent | 0ff16aec015bea373b87832d76ed25a50750a33d (diff) | |
download | chromium_src-22aa4b67754f518c46bec79c9bedc22a82396e95.zip chromium_src-22aa4b67754f518c46bec79c9bedc22a82396e95.tar.gz chromium_src-22aa4b67754f518c46bec79c9bedc22a82396e95.tar.bz2 |
Relanding 3149027.
TBR=dmazzoni,chaitanyag
BUG=none.
TEST=none.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58373 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
4 files changed, 142 insertions, 4 deletions
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index dc03bbb..4ded6a6 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -46,9 +46,7 @@ #include "chrome/browser/extensions/extension_sidebar_api.h" #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/extensions/extension_test_api.h" -#if defined(OS_CHROMEOS) #include "chrome/browser/extensions/extension_tts_api.h" -#endif #include "chrome/browser/extensions/extension_webstore_private_api.h" #include "chrome/browser/extensions/extensions_quota_service.h" #include "chrome/browser/extensions/extensions_service.h" @@ -235,12 +233,10 @@ void FactoryRegistry::ResetFunctions() { RegisterFunction<GetFocusedControlFunction>(); RegisterFunction<SetAccessibilityEnabledFunction>(); -#if defined(OS_CHROMEOS) // Text-to-speech. RegisterFunction<ExtensionTtsSpeakFunction>(); RegisterFunction<ExtensionTtsStopSpeakingFunction>(); RegisterFunction<ExtensionTtsIsSpeakingFunction>(); -#endif // Clipboard. RegisterFunction<ExecuteCopyClipboardFunction>(); diff --git a/chrome/browser/extensions/extension_tts_api_gtk.cc b/chrome/browser/extensions/extension_tts_api_gtk.cc new file mode 100644 index 0000000..6804f92 --- /dev/null +++ b/chrome/browser/extensions/extension_tts_api_gtk.cc @@ -0,0 +1,17 @@ +// Copyright (c) 2010 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 "extension_tts_api.h"
+
+bool ExtensionTtsSpeakFunction::RunImpl() {
+ return false;
+}
+
+bool ExtensionTtsStopSpeakingFunction::RunImpl() {
+ return false;
+}
+
+bool ExtensionTtsIsSpeakingFunction::RunImpl() {
+ return false;
+}
diff --git a/chrome/browser/extensions/extension_tts_api_mac.mm b/chrome/browser/extensions/extension_tts_api_mac.mm new file mode 100644 index 0000000..98e49e3 --- /dev/null +++ b/chrome/browser/extensions/extension_tts_api_mac.mm @@ -0,0 +1,39 @@ +// Copyright (c) 2010 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 "extension_tts_api.h"
+
+#include <string>
+
+#include "base/values.h"
+#include "chrome/browser/extensions/extension_function.h"
+
+#import <cocoa/cocoa.h>
+
+static NSSpeechSynthesizer* speech_synthesizer_;
+
+void InitializeSpeechSynthesizer() {
+ if (!speech_synthesizer_)
+ speech_synthesizer_ = [[NSSpeechSynthesizer alloc] init];
+}
+
+bool ExtensionTtsSpeakFunction::RunImpl() {
+ InitializeSpeechSynthesizer();
+ std::string utterance;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &utterance));
+ return
+ [speech_synthesizer_ startSpeakingString:
+ [NSString stringWithUTF8String: utterance.c_str()]];
+}
+
+bool ExtensionTtsStopSpeakingFunction::RunImpl() {
+ InitializeSpeechSynthesizer();
+ [speech_synthesizer_ stopSpeaking];
+ return true;
+}
+
+bool ExtensionTtsIsSpeakingFunction::RunImpl() {
+ InitializeSpeechSynthesizer();
+ return [speech_synthesizer_ isSpeaking];
+}
diff --git a/chrome/browser/extensions/extension_tts_api_win.cc b/chrome/browser/extensions/extension_tts_api_win.cc new file mode 100644 index 0000000..260d047 --- /dev/null +++ b/chrome/browser/extensions/extension_tts_api_win.cc @@ -0,0 +1,86 @@ +// Copyright (c) 2010 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 "extension_tts_api.h"
+
+#include <atlbase.h>
+#include <atlcom.h>
+#include <sapi.h>
+
+#include "base/scoped_comptr_win.h"
+#include "base/singleton.h"
+#include "base/values.h"
+
+class SpeechSynthesizerWrapper {
+ public:
+ SpeechSynthesizerWrapper() : speech_synthesizer_(NULL),
+ paused_(false),
+ permanent_failure_(false) {
+ InitializeSpeechSynthesizer();
+ }
+
+ bool InitializeSpeechSynthesizer() {
+ if (!SUCCEEDED(CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_SERVER,
+ IID_ISpVoice, reinterpret_cast<void**>(&speech_synthesizer_)))) {
+ permanent_failure_ = true;
+ return false;
+ }
+
+ if (paused_)
+ speech_synthesizer_->Resume();
+ return true;
+ }
+
+ ScopedComPtr<ISpVoice> speech_synthesizer() {
+ return speech_synthesizer_;
+ }
+
+ bool paused() {
+ return paused_;
+ }
+
+ void paused(bool state) {
+ paused_ = state;
+ }
+
+ private:
+ ScopedComPtr<ISpVoice> speech_synthesizer_;
+ bool paused_;
+ // Indicates an error retrieving the SAPI COM interface.
+ bool permanent_failure_;
+};
+
+typedef Singleton<SpeechSynthesizerWrapper> SpeechSynthesizerSingleton;
+
+bool ExtensionTtsSpeakFunction::RunImpl() {
+ ScopedComPtr<ISpVoice> speech_synthesizer =
+ SpeechSynthesizerSingleton::get()->speech_synthesizer();
+ if (speech_synthesizer) {
+ std::wstring utterance;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &utterance));
+ if (SpeechSynthesizerSingleton::get()->paused())
+ speech_synthesizer->Resume();
+ speech_synthesizer->Speak(
+ utterance.c_str(), SPF_ASYNC | SPF_PURGEBEFORESPEAK, NULL);
+ return true;
+ }
+
+ return false;
+}
+
+bool ExtensionTtsStopSpeakingFunction::RunImpl() {
+ // We need to keep track of the paused state since SAPI doesn't have a stop
+ // method.
+ ScopedComPtr<ISpVoice> speech_synthesizer =
+ SpeechSynthesizerSingleton::get()->speech_synthesizer();
+ if (speech_synthesizer && !SpeechSynthesizerSingleton::get()->paused()) {
+ speech_synthesizer->Pause();
+ SpeechSynthesizerSingleton::get()->paused(true);
+ }
+ return true;
+}
+
+bool ExtensionTtsIsSpeakingFunction::RunImpl() {
+ return false;
+}
|