Compare commits

..

59 Commits

Author SHA1 Message Date
Cheng Zhao
4b5dd2ed4b Bump v0.18.1. 2014-10-17 17:00:26 +08:00
Cheng Zhao
85afa851dd win: Fix toggling the menubar, closes #681 2014-10-17 16:43:57 +08:00
Cheng Zhao
57acdc1bf6 Use menu bar features in default_app 2014-10-17 16:43:37 +08:00
Cheng Zhao
ae76657e17 Still requires unity for global app menubar
Fixes #709 and atom/atom#3854.
2014-10-17 16:06:45 +08:00
Cheng Zhao
4ca6ac34ac Do not create native Event object when not needed 2014-10-17 14:36:43 +08:00
Cheng Zhao
e4a71b86df Caching object templates for Event, fixes #705 2014-10-17 13:53:18 +08:00
Cheng Zhao
4dd7848084 Run idle GC in browser every 1m 2014-10-17 12:41:40 +08:00
Cheng Zhao
a95679c212 Enable mnemonics in menu, fixes atom/atom#3844 2014-10-16 21:22:22 +08:00
Cheng Zhao
b41d356143 --harmony_collections is not needed anymore 2014-10-16 20:59:01 +08:00
Cheng Zhao
feb6a93881 Merge pull request #708 from matttbe/globalmenu
linux: GlobalMenu: UBUNTU_MENUPROXY with >1 char
2014-10-16 18:53:24 +08:00
Matthieu Baerts
940b40439f linux: GlobalMenu: UBUNTU_MENUPROXY with >1 char
When testing if $UBUNTU_MENUPROXY is set, we should also check if it
contains more than one character. Avoid cases when $UBUNTU_MENUPROXY is
set to 0 or 1.
2014-10-15 14:17:18 +02:00
Cheng Zhao
ed07bd202f Bump v0.18.0. 2014-10-14 20:24:56 +08:00
Cheng Zhao
8c29ffd084 Make __filename normalized
This can make sure __filename and __dirname on Windows use "\" as path
delimeter.
2014-10-14 19:45:57 +08:00
Cheng Zhao
dba2fa31b6 Fix __dirname for page in asar package
Fixes #694.
2014-10-14 19:27:47 +08:00
Cheng Zhao
2de80571d8 Add spec for #694 2014-10-14 19:27:38 +08:00
Cheng Zhao
51acba594b Merge pull request #698 from matttbe/master
linux: Rename window's class to Atom
2014-10-14 18:58:37 +08:00
Cheng Zhao
a194d45dfa Merge pull request #700 from atom/chrome38
Upgrade to Chrome 38
2014-10-14 18:42:21 +08:00
Cheng Zhao
9356296a84 Merge pull request #703 from waywardmonkeys/cleanup-asar-docs
[docs] Clean up some grammar around ASAR.
2014-10-14 18:40:47 +08:00
Bruce Mitchener
2fa0b1117c [docs] Clean up some grammar around ASAR. 2014-10-14 08:16:22 +07:00
Cheng Zhao
49814e1919 Just pass spec when mkdir failed 2014-10-13 23:48:56 +08:00
Cheng Zhao
74da83a0bb Upgrade libchromiumcontent to fix node.lib 2014-10-13 23:26:13 +08:00
Cheng Zhao
643d1dcdd1 win: Fix building 2014-10-13 22:47:13 +08:00
Cheng Zhao
b717add81b Print error when mkdir failed 2014-10-13 19:08:23 +08:00
Cheng Zhao
c36c4e36c5 Upgrade libchromiumcontent to fix linking error 2014-10-13 18:11:19 +08:00
Cheng Zhao
0b48c3ea90 Merge pull request #699 from matttbe/globalmenu
linux: GlobalMenu: only if UBUNTU_MENUPROXY is set
2014-10-13 16:31:04 +08:00
Cheng Zhao
68e28159bb Upgrade to apm@0.102.0 2014-10-13 15:00:05 +08:00
Cheng Zhao
69a89303d0 Fix building on Linux 2014-10-13 11:03:56 +08:00
Cheng Zhao
9e87037d34 Upgrade to libchromiumcontent 44c71d8 2014-10-13 10:09:58 +08:00
Matthieu Baerts
7cd4d35778 linux: GlobalMenu: only if UBUNTU_MENUPROXY is set
When checking if we should react differently when GlobalMenu bar is
used, we should check if UBUNTU_MENUPROXY env var is (correctly) set
instead of checking if we're using Unity on a Unity session.

It's better to do that because we can use Compiz on a Unity session
without Unity. Or we can also use Unity in a different session.
2014-10-12 21:16:32 +02:00
Matthieu Baerts
8296178e33 linux: Rename window's class to Atom
The window's class should be Atom instead of Atom Shell because the
launcher and the binary to launch Atom are called 'atom' and not 'atom
shell'. This is why currently all Atom's windows will not be linked to
their launcher in a dock (e.g. with Cairo-Dock).

Note that it's not advised to add white-spaces in a window's class
('Atom Shell').
2014-10-12 18:47:49 +02:00
Cheng Zhao
32dff999a5 Fix API changes of Chrome 38 2014-10-11 19:11:34 +08:00
Cheng Zhao
13e5cf32d5 Upgrade brightray for Chrome 38 2014-10-11 19:11:07 +08:00
Cheng Zhao
11d9e522d5 Update node for V8 changes 2014-10-11 19:10:57 +08:00
Cheng Zhao
4aac0d6d1c Upgrade to Chrome 38.0.2125.102 2014-10-11 19:10:32 +08:00
Cheng Zhao
ddf4f14dba Merge pull request #685 from atom/speech
Add support for speech synthesizer and recognizer
2014-10-08 19:05:00 +08:00
Cheng Zhao
b560176aeb Set google API key 2014-10-08 18:27:39 +08:00
Cheng Zhao
802f964cd3 Enable AVFoundation 2014-10-08 18:17:27 +08:00
Cheng Zhao
0c349c047d Fix cpplint warning 2014-10-08 17:47:47 +08:00
Cheng Zhao
d4e3c39fa5 Add AtomSpeechRecognitionManagerDelegate 2014-10-08 11:55:14 +08:00
Cheng Zhao
3a177d55f8 Add linux tts implementation from Chrome 2014-10-08 02:14:12 +00:00
Cheng Zhao
b2741a8316 Upgrade libchromiuncontent to 3245ef8 2014-10-08 02:05:19 +00:00
Cheng Zhao
909f1bcf3c Upgrade brightray 2014-10-08 01:34:24 +00:00
Cheng Zhao
009412d738 Upgrade libchromiumcontent to f0c3a45 2014-10-08 01:27:07 +00:00
Cheng Zhao
33c622ec86 Install tts dispatcher 2014-10-07 21:27:15 +08:00
Cheng Zhao
05b602d0ce Import Chrome's tts code 2014-10-07 21:18:44 +08:00
Cheng Zhao
8519ea3299 Bump v0.17.2. 2014-10-06 19:13:26 +08:00
Cheng Zhao
aad46b0894 Upgrade to Chrome af66653 2014-10-06 19:02:54 +08:00
Cheng Zhao
5dfbaebd4c Upgrade brightray 2014-10-06 11:23:53 +08:00
Cheng Zhao
b2b70bb37c Upgrade libchromiumcontent to 440833b, fixes #462 2014-10-06 10:54:14 +08:00
Cheng Zhao
35d37c3463 Merge pull request #680 from Subash/patch-1
Optimize fs.stat
2014-10-03 18:09:57 +08:00
Kevin Sawicki
eea82efbf8 Merge pull request #682 from joshmarinacci/patch-1
speling error.
2014-10-02 14:51:41 -07:00
Josh Marinacci
7659edd139 speling error. 2014-10-02 14:51:05 -07:00
Subash Pathak
9f8a5a7af3 Optimize fs.stat 2014-10-02 23:35:37 +05:45
Cheng Zhao
cc4897f8c1 Add process.versions['chrome'], fixes #675 2014-10-02 23:48:17 +08:00
Cheng Zhao
ee5335ca6e Merge pull request #674 from Subash/fs-stat
Fs stat fixes #672
2014-10-02 11:46:06 +08:00
Subash Pathak
dde8e47add Time Shim 2014-10-01 22:24:51 +05:45
Subash Pathak
0040f07097 Added Stat Time 2014-10-01 22:01:57 +05:45
Cheng Zhao
64b2c9b36c Bump v0.17.1. 2014-10-01 20:41:35 +08:00
Cheng Zhao
d754b2bda7 Break on first found app 2014-10-01 20:40:52 +08:00
70 changed files with 3284 additions and 118 deletions

View File

@@ -101,6 +101,8 @@
'atom/browser/atom_javascript_dialog_manager.h',
'atom/browser/atom_resource_dispatcher_host_delegate.cc',
'atom/browser/atom_resource_dispatcher_host_delegate.h',
'atom/browser/atom_speech_recognition_manager_delegate.cc',
'atom/browser/atom_speech_recognition_manager_delegate.h',
'atom/browser/browser.cc',
'atom/browser/browser.h',
'atom/browser/browser_linux.cc',
@@ -214,6 +216,7 @@
'atom/common/crash_reporter/win/crash_service_main.h',
'atom/common/draggable_region.cc',
'atom/common/draggable_region.h',
'atom/common/google_api_key.h',
'atom/common/linux/application_info.cc',
'atom/common/native_mate_converters/accelerator_converter.cc',
'atom/common/native_mate_converters/accelerator_converter.h',
@@ -279,6 +282,16 @@
'chromium_src/chrome/browser/printing/printing_message_filter.h',
'chromium_src/chrome/browser/printing/printing_ui_web_contents_observer.cc',
'chromium_src/chrome/browser/printing/printing_ui_web_contents_observer.h',
'chromium_src/chrome/browser/speech/tts_controller.h',
'chromium_src/chrome/browser/speech/tts_controller_impl.cc',
'chromium_src/chrome/browser/speech/tts_controller_impl.h',
'chromium_src/chrome/browser/speech/tts_linux.cc',
'chromium_src/chrome/browser/speech/tts_mac.mm',
'chromium_src/chrome/browser/speech/tts_message_filter.cc',
'chromium_src/chrome/browser/speech/tts_message_filter.h',
'chromium_src/chrome/browser/speech/tts_platform.cc',
'chromium_src/chrome/browser/speech/tts_platform.h',
'chromium_src/chrome/browser/speech/tts_win.cc',
'chromium_src/chrome/browser/ui/libgtk2ui/app_indicator_icon_menu.cc',
'chromium_src/chrome/browser/ui/libgtk2ui/app_indicator_icon_menu.h',
'chromium_src/chrome/browser/ui/libgtk2ui/gtk2_status_icon.cc',
@@ -289,11 +302,17 @@
'chromium_src/chrome/browser/ui/views/status_icons/status_tray_state_changer_win.h',
'chromium_src/chrome/common/print_messages.cc',
'chromium_src/chrome/common/print_messages.h',
'chromium_src/chrome/common/tts_messages.h',
'chromium_src/chrome/common/tts_utterance_request.cc',
'chromium_src/chrome/common/tts_utterance_request.h',
'chromium_src/chrome/renderer/printing/print_web_view_helper.cc',
'chromium_src/chrome/renderer/printing/print_web_view_helper_linux.cc',
'chromium_src/chrome/renderer/printing/print_web_view_helper_mac.mm',
'chromium_src/chrome/renderer/printing/print_web_view_helper_win.cc',
'chromium_src/chrome/renderer/printing/print_web_view_helper.h',
'chromium_src/chrome/renderer/tts_dispatcher.cc',
'chromium_src/chrome/renderer/tts_dispatcher.h',
'chromium_src/library_loaders/libspeechd_loader.cc',
'<@(native_mate_files)',
],
'framework_sources': [
@@ -549,7 +568,7 @@
'vendor/breakpad/src',
],
'cflags': [
'-Wno-deprecated-declarations',
'-Wno-deprecated-register',
'-Wno-empty-body',
],
'dependencies': [

View File

@@ -8,9 +8,11 @@
#include "atom/app/atom_content_client.h"
#include "atom/browser/atom_browser_client.h"
#include "atom/common/google_api_key.h"
#include "atom/renderer/atom_renderer_client.h"
#include "base/command_line.h"
#include "base/debug/stack_trace.h"
#include "base/environment.h"
#include "base/logging.h"
#include "content/public/common/content_switches.h"
#include "ui/base/resource/resource_bundle.h"
@@ -52,6 +54,11 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
void AtomMainDelegate::PreSandboxStartup() {
brightray::MainDelegate::PreSandboxStartup();
// Set google API key.
scoped_ptr<base::Environment> env(base::Environment::Create());
if (!env->HasVar("GOOGLE_API_KEY"))
env->SetVar("GOOGLE_API_KEY", GOOGLEAPIS_API_KEY);
CommandLine* command_line = CommandLine::ForCurrentProcess();
std::string process_type = command_line->GetSwitchValueASCII(
switches::kProcessType);
@@ -73,6 +80,11 @@ void AtomMainDelegate::PreSandboxStartup() {
// Disable renderer sandbox for most of node's functions.
command_line->AppendSwitch(switches::kNoSandbox);
#if defined(OS_MACOSX)
// Enable AVFoundation.
command_line->AppendSwitch("enable-avfoundation");
#endif
// Add a flag to mark the end of switches added by atom-shell.
command_line->AppendSwitch("atom-shell-switches-end");
}

View File

@@ -19,6 +19,7 @@
#include "native_mate/callback.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "net/base/load_flags.h"
#include "net/proxy/proxy_service.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
@@ -46,10 +47,10 @@ class ResolveProxyHelper {
// Start the request.
int result = proxy_service->ResolveProxy(
url, &proxy_info_,
url, net::LOAD_NORMAL, &proxy_info_,
base::Bind(&ResolveProxyHelper::OnResolveProxyCompleted,
base::Unretained(this)),
&pac_req_, net::BoundNetLog());
&pac_req_, nullptr, net::BoundNetLog());
// Completed synchronously.
if (result != net::ERR_IO_PENDING)

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include <set>
#include <string>
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "base/bind.h"
@@ -31,17 +32,30 @@ struct Converter<std::set<T> > {
};
template<>
struct Converter<TracingController::Options> {
struct Converter<base::debug::CategoryFilter> {
static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val,
TracingController::Options* out) {
if (!val->IsNumber())
base::debug::CategoryFilter* out) {
std::string filter;
if (!ConvertFromV8(isolate, val, &filter))
return false;
*out = static_cast<TracingController::Options>(val->IntegerValue());
*out = base::debug::CategoryFilter(filter);
return true;
}
};
template<>
struct Converter<base::debug::TraceOptions> {
static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val,
base::debug::TraceOptions* out) {
std::string options;
if (!ConvertFromV8(isolate, val, &options))
return false;
return out->SetFromString(options);
}
};
} // namespace mate
namespace {

View File

@@ -17,14 +17,15 @@ MenuViews::MenuViews() {
void MenuViews::Popup(Window* window) {
gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
views::MenuRunner menu_runner(model());
views::MenuRunner menu_runner(
model(),
views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS);
ignore_result(menu_runner.RunMenuAt(
static_cast<NativeWindowViews*>(window->window())->widget(),
NULL,
gfx::Rect(cursor, gfx::Size()),
views::MENU_ANCHOR_TOPLEFT,
ui::MENU_SOURCE_MOUSE,
views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU));
ui::MENU_SOURCE_MOUSE));
}
// static

View File

@@ -35,10 +35,10 @@ void WebContents::RenderProcessGone(base::TerminationStatus status) {
Emit("crashed");
}
void WebContents::DidFinishLoad(int64 frame_id,
const GURL& validated_url,
bool is_main_frame,
content::RenderViewHost* render_view_host) {
void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) {
bool is_main_frame = !render_frame_host->GetParent();
base::ListValue args;
args.AppendBoolean(is_main_frame);
Emit("did-frame-finish-load", args);

View File

@@ -52,11 +52,8 @@ class WebContents : public mate::EventEmitter,
// content::WebContentsObserver implementations:
virtual void RenderViewDeleted(content::RenderViewHost*) OVERRIDE;
virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
virtual void DidFinishLoad(
int64 frame_id,
const GURL& validated_url,
bool is_main_frame,
content::RenderViewHost* render_view_host) OVERRIDE;
virtual void DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) OVERRIDE;
virtual void DidStartLoading(
content::RenderViewHost* render_view_host) OVERRIDE;
virtual void DidStopLoading(

View File

@@ -11,6 +11,12 @@
namespace mate {
namespace {
v8::Persistent<v8::ObjectTemplate> template_;
} // namespace
Event::Event()
: sender_(NULL),
message_(NULL),
@@ -21,9 +27,14 @@ Event::~Event() {
}
ObjectTemplateBuilder Event::GetObjectTemplateBuilder(v8::Isolate* isolate) {
return ObjectTemplateBuilder(isolate)
.SetMethod("preventDefault", &Event::PreventDefault)
.SetMethod("sendReply", &Event::SendReply);
if (template_.IsEmpty())
template_.Reset(isolate, ObjectTemplateBuilder(isolate)
.SetMethod("preventDefault", &Event::PreventDefault)
.SetMethod("sendReply", &Event::SendReply)
.Build());
return ObjectTemplateBuilder(
isolate, v8::Local<v8::ObjectTemplate>::New(isolate, template_));
}
void Event::SetSenderAndMessage(content::WebContents* sender,

View File

@@ -10,11 +10,37 @@
#include "atom/common/native_mate_converters/v8_value_converter.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "native_mate/arguments.h"
#include "native_mate/object_template_builder.h"
#include "atom/common/node_includes.h"
namespace mate {
namespace {
v8::Persistent<v8::ObjectTemplate> event_template;
void PreventDefault(mate::Arguments* args) {
args->GetThis()->SetHiddenValue(
StringToV8(args->isolate(), "prevent_default"),
v8::True(args->isolate()));
}
// Create a pure JavaScript Event object.
v8::Local<v8::Object> CreateEventObject(v8::Isolate* isolate) {
if (event_template.IsEmpty()) {
event_template.Reset(isolate, ObjectTemplateBuilder(isolate)
.SetMethod("preventDefault", &PreventDefault)
.Build());
}
return v8::Local<v8::ObjectTemplate>::New(
isolate, event_template)->NewInstance();
}
} // namespace
EventEmitter::EventEmitter() {
}
@@ -38,15 +64,22 @@ bool EventEmitter::Emit(const base::StringPiece& name,
v8::Handle<v8::Context> context = isolate->GetCurrentContext();
scoped_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter);
mate::Handle<mate::Event> event = mate::Event::Create(isolate);
if (sender && message)
event->SetSenderAndMessage(sender, message);
v8::Handle<v8::Object> event;
bool use_native_event = sender && message;
if (use_native_event) {
mate::Handle<mate::Event> native_event = mate::Event::Create(isolate);
native_event->SetSenderAndMessage(sender, message);
event = v8::Handle<v8::Object>::Cast(native_event.ToV8());
} else {
event = CreateEventObject(isolate);
}
// v8_args = [name, event, args...];
std::vector<v8::Handle<v8::Value>> v8_args;
v8_args.reserve(args.GetSize() + 2);
v8_args.push_back(mate::StringToV8(isolate, name));
v8_args.push_back(event.ToV8());
v8_args.push_back(event);
for (size_t i = 0; i < args.GetSize(); i++) {
const base::Value* value(NULL);
if (args.Get(i, &value))
@@ -57,7 +90,17 @@ bool EventEmitter::Emit(const base::StringPiece& name,
node::MakeCallback(isolate, GetWrapper(isolate), "emit", v8_args.size(),
&v8_args[0]);
return event->prevent_default();
if (use_native_event) {
Handle<Event> native_event;
if (ConvertFromV8(isolate, event, &native_event))
return native_event->prevent_default();
}
v8::Handle<v8::Value> prevent_default =
event->GetHiddenValue(StringToSymbol(isolate, "prevent_default"));
if (prevent_default.IsEmpty())
return false;
return prevent_default->BooleanValue();
}
} // namespace mate

View File

@@ -7,10 +7,7 @@
#include <utility>
#include "atom/browser/atom_browser_context.h"
#ifndef GOOGLEAPIS_API_KEY
#define GOOGLEAPIS_API_KEY "AIzaSyAQfxPJiounkhOjODEO5ZieffeBv6yft2Q"
#endif
#include "atom/common/google_api_key.h"
namespace atom {

View File

@@ -8,16 +8,18 @@
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/atom_browser_main_parts.h"
#include "atom/browser/atom_resource_dispatcher_host_delegate.h"
#include "atom/browser/atom_speech_recognition_manager_delegate.h"
#include "atom/browser/native_window.h"
#include "atom/browser/window_list.h"
#include "chrome/browser/printing/printing_message_filter.h"
#include "chrome/browser/speech/tts_message_filter.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/resource_dispatcher_host.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/web_preferences.h"
#include "ui/base/l10n/l10n_util.h"
#include "webkit/common/webpreferences.h"
namespace atom {
@@ -51,7 +53,9 @@ AtomBrowserClient::~AtomBrowserClient() {
void AtomBrowserClient::RenderProcessWillLaunch(
content::RenderProcessHost* host) {
int id = host->GetID();
host->AddFilter(new PrintingMessageFilter(host->GetID()));
host->AddFilter(new TtsMessageFilter(id, host->GetBrowserContext()));
}
void AtomBrowserClient::ResourceDispatcherHostCreated() {
@@ -60,6 +64,11 @@ void AtomBrowserClient::ResourceDispatcherHostCreated() {
resource_dispatcher_delegate_.get());
}
content::SpeechRecognitionManagerDelegate*
AtomBrowserClient::GetSpeechRecognitionManagerDelegate() {
return new AtomSpeechRecognitionManagerDelegate;
}
content::AccessTokenStore* AtomBrowserClient::CreateAccessTokenStore() {
return new AtomAccessTokenStore;
}
@@ -67,7 +76,7 @@ content::AccessTokenStore* AtomBrowserClient::CreateAccessTokenStore() {
void AtomBrowserClient::OverrideWebkitPrefs(
content::RenderViewHost* render_view_host,
const GURL& url,
WebPreferences* prefs) {
content::WebPreferences* prefs) {
prefs->javascript_enabled = true;
prefs->web_security_enabled = true;
prefs->javascript_can_open_windows_automatically = true;

View File

@@ -23,10 +23,12 @@ class AtomBrowserClient : public brightray::BrowserClient {
virtual void RenderProcessWillLaunch(
content::RenderProcessHost* host) OVERRIDE;
virtual void ResourceDispatcherHostCreated() OVERRIDE;
virtual content::SpeechRecognitionManagerDelegate*
GetSpeechRecognitionManagerDelegate() override;
virtual content::AccessTokenStore* CreateAccessTokenStore() OVERRIDE;
virtual void OverrideWebkitPrefs(content::RenderViewHost* render_view_host,
const GURL& url,
WebPreferences* prefs) OVERRIDE;
content::WebPreferences* prefs) OVERRIDE;
virtual bool ShouldSwapBrowsingInstancesForNavigation(
content::SiteInstance* site_instance,
const GURL& current_url,

View File

@@ -28,7 +28,8 @@ AtomBrowserMainParts* AtomBrowserMainParts::self_ = NULL;
AtomBrowserMainParts::AtomBrowserMainParts()
: browser_(new Browser),
node_bindings_(NodeBindings::Create(true)),
atom_bindings_(new AtomBindings) {
atom_bindings_(new AtomBindings),
gc_timer_(true, true) {
DCHECK(!self_) << "Cannot have two AtomBrowserMainParts";
self_ = this;
}
@@ -75,6 +76,13 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() {
node_bindings_->PrepareMessageLoop();
node_bindings_->RunMessageLoop();
// Start idle gc.
gc_timer_.Start(
FROM_HERE, base::TimeDelta::FromMinutes(1),
base::Bind(base::IgnoreResult(&v8::Isolate::IdleNotification),
base::Unretained(js_env_->isolate()),
1000));
brightray::BrowserMainParts::PreMainMessageLoopRun();
#if defined(USE_X11)

View File

@@ -5,6 +5,7 @@
#ifndef ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
#define ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
#include "base/timer/timer.h"
#include "brightray/browser/browser_main_parts.h"
namespace atom {
@@ -43,6 +44,8 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
scoped_ptr<AtomBindings> atom_bindings_;
scoped_ptr<NodeDebugger> node_debugger_;
base::Timer gc_timer_;
static AtomBrowserMainParts* self_;
DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);

View File

@@ -0,0 +1,74 @@
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/atom_speech_recognition_manager_delegate.h"
#include <string>
#include "base/callback.h"
namespace atom {
AtomSpeechRecognitionManagerDelegate::AtomSpeechRecognitionManagerDelegate() {
}
AtomSpeechRecognitionManagerDelegate::~AtomSpeechRecognitionManagerDelegate() {
}
void AtomSpeechRecognitionManagerDelegate::OnRecognitionStart(int session_id) {
}
void AtomSpeechRecognitionManagerDelegate::OnAudioStart(int session_id) {
}
void AtomSpeechRecognitionManagerDelegate::OnEnvironmentEstimationComplete(
int session_id) {
}
void AtomSpeechRecognitionManagerDelegate::OnSoundStart(int session_id) {
}
void AtomSpeechRecognitionManagerDelegate::OnSoundEnd(int session_id) {
}
void AtomSpeechRecognitionManagerDelegate::OnAudioEnd(int session_id) {
}
void AtomSpeechRecognitionManagerDelegate::OnRecognitionEnd(int session_id) {
}
void AtomSpeechRecognitionManagerDelegate::OnRecognitionResults(
int session_id, const content::SpeechRecognitionResults& result) {
}
void AtomSpeechRecognitionManagerDelegate::OnRecognitionError(
int session_id, const content::SpeechRecognitionError& error) {
}
void AtomSpeechRecognitionManagerDelegate::OnAudioLevelsChange(
int session_id, float volume, float noise_volume) {
}
void AtomSpeechRecognitionManagerDelegate::GetDiagnosticInformation(
bool* can_report_metrics, std::string* hardware_info) {
*can_report_metrics = false;
}
void AtomSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed(
int session_id,
base::Callback<void(bool ask_user, bool is_allowed)> callback) {
callback.Run(true, true);
}
content::SpeechRecognitionEventListener*
AtomSpeechRecognitionManagerDelegate::GetEventListener() {
return this;
}
bool AtomSpeechRecognitionManagerDelegate::FilterProfanities(
int render_process_id) {
return false;
}
} // namespace atom

View File

@@ -0,0 +1,52 @@
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_ATOM_SPEECH_RECOGNITION_MANAGER_DELEGATE_H_
#define ATOM_BROWSER_ATOM_SPEECH_RECOGNITION_MANAGER_DELEGATE_H_
#include <string>
#include "content/public/browser/speech_recognition_event_listener.h"
#include "content/public/browser/speech_recognition_manager_delegate.h"
namespace atom {
class AtomSpeechRecognitionManagerDelegate
: public content::SpeechRecognitionManagerDelegate,
public content::SpeechRecognitionEventListener {
public:
AtomSpeechRecognitionManagerDelegate();
virtual ~AtomSpeechRecognitionManagerDelegate();
// content::SpeechRecognitionEventListener:
virtual void OnRecognitionStart(int session_id) override;
virtual void OnAudioStart(int session_id) override;
virtual void OnEnvironmentEstimationComplete(int session_id) override;
virtual void OnSoundStart(int session_id) override;
virtual void OnSoundEnd(int session_id) override;
virtual void OnAudioEnd(int session_id) override;
virtual void OnRecognitionEnd(int session_id) override;
virtual void OnRecognitionResults(
int session_id, const content::SpeechRecognitionResults& result) override;
virtual void OnRecognitionError(
int session_id, const content::SpeechRecognitionError& error) override;
virtual void OnAudioLevelsChange(int session_id, float volume,
float noise_volume) override;
// content::SpeechRecognitionManagerDelegate:
virtual void GetDiagnosticInformation(bool* can_report_metrics,
std::string* hardware_info) override;
virtual void CheckRecognitionIsAllowed(
int session_id,
base::Callback<void(bool ask_user, bool is_allowed)> callback) override;
virtual content::SpeechRecognitionEventListener* GetEventListener() override;
virtual bool FilterProfanities(int render_process_id) override;
private:
DISALLOW_COPY_AND_ASSIGN(AtomSpeechRecognitionManagerDelegate);
};
} // namespace atom
#endif // ATOM_BROWSER_ATOM_SPEECH_RECOGNITION_MANAGER_DELEGATE_H_

View File

@@ -12,12 +12,11 @@ app.on('window-all-closed', function() {
});
app.on('ready', function() {
app.commandLine.appendSwitch('js-flags', '--harmony_collections');
mainWindow = new BrowserWindow({
width: 800,
height: 600,
resizable: false,
'auto-hide-menu-bar': true,
'use-content-size': true,
});
mainWindow.loadUrl('file://' + __dirname + '/index.html');
@@ -152,33 +151,33 @@ app.on('ready', function() {
} else {
var template = [
{
label: 'File',
label: '&File',
submenu: [
{
label: 'Open',
label: '&Open',
accelerator: 'Ctrl+O',
},
{
label: 'Close',
label: '&Close',
accelerator: 'Ctrl+W',
click: function() { mainWindow.close(); }
},
]
},
{
label: 'View',
label: '&View',
submenu: [
{
label: 'Reload',
label: '&Reload',
accelerator: 'Ctrl+R',
click: function() { mainWindow.restart(); }
},
{
label: 'Enter Fullscreen',
label: '&Enter Fullscreen',
click: function() { mainWindow.setFullScreen(true); }
},
{
label: 'Toggle DevTools',
label: '&Toggle DevTools',
accelerator: 'Alt+Ctrl+I',
click: function() { mainWindow.toggleDevTools(); }
},

View File

@@ -2,12 +2,6 @@
<head>
<title>Atom Shell</title>
<style>
html {
height: 100%;
width: 100%;
overflow: hidden;
}
body {
color: #555;
font-family: 'Open Sans',Helvetica,Arial,sans-serif;

View File

@@ -67,6 +67,7 @@ setImmediate ->
try
packagePath = path.join process.resourcesPath, packagePath
packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json')))
break
catch e
continue

View File

@@ -44,13 +44,13 @@
#include "content/public/common/content_switches.h"
#include "content/public/common/renderer_preferences.h"
#include "content/public/common/user_agent.h"
#include "content/public/common/web_preferences.h"
#include "ipc/ipc_message_macros.h"
#include "native_mate/dictionary.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
#include "webkit/common/webpreferences.h"
using content::NavigationEntry;
@@ -248,9 +248,8 @@ bool NativeWindow::IsDevToolsOpened() {
void NativeWindow::InspectElement(int x, int y) {
OpenDevTools();
content::RenderViewHost* rvh = GetWebContents()->GetRenderViewHost();
scoped_refptr<content::DevToolsAgentHost> agent(
content::DevToolsAgentHost::GetOrCreateFor(rvh));
content::DevToolsAgentHost::GetOrCreateFor(GetWebContents()));
agent->InspectElement(x, y);
}
@@ -287,7 +286,7 @@ void NativeWindow::CapturePage(const gfx::Rect& rect,
base::Bind(&NativeWindow::OnCapturePageDone,
weak_factory_.GetWeakPtr(),
callback),
SkBitmap::kARGB_8888_Config);
kAlpha_8_SkColorType);
}
void NativeWindow::DestroyWebContents() {
@@ -368,7 +367,8 @@ void NativeWindow::AppendExtraCommandLineSwitches(
}
}
void NativeWindow::OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs) {
void NativeWindow::OverrideWebkitPrefs(const GURL& url,
content::WebPreferences* prefs) {
if (web_preferences_.IsEmpty())
return;

View File

@@ -23,8 +23,6 @@
#include "native_mate/persistent_dictionary.h"
#include "ui/gfx/image/image_skia.h"
struct WebPreferences;
namespace base {
class CommandLine;
}
@@ -32,6 +30,7 @@ class CommandLine;
namespace content {
class BrowserContext;
class WebContents;
struct WebPreferences;
}
namespace gfx {
@@ -178,7 +177,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
// Called when renderer process is going to be started.
void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
int child_process_id);
void OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs);
void OverrideWebkitPrefs(const GURL& url, content::WebPreferences* prefs);
// Public API used by platform-dependent delegates and observers to send UI
// related notifications.

View File

@@ -68,8 +68,12 @@ bool ShouldUseGlobalMenuBar() {
// Some DE would pretend to be Unity but don't have global application menu,
// so we can not trust unity::IsRunning().
scoped_ptr<base::Environment> env(base::Environment::Create());
return unity::IsRunning() && (base::nix::GetDesktopEnvironment(env.get()) ==
base::nix::DESKTOP_ENVIRONMENT_UNITY);
bool is_unity = unity::IsRunning() &&
base::nix::GetDesktopEnvironment(env.get()) ==
base::nix::DESKTOP_ENVIRONMENT_UNITY;
std::string menu_proxy;
return is_unity && env->GetVar("UBUNTU_MENUPROXY", &menu_proxy) &&
menu_proxy.length() > 1;
}
#endif
@@ -155,8 +159,8 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
"%s/%s/%d", "Atom Shell", Browser::Get()->GetName().c_str(),
++kWindowsCreated);
// Set WM_CLASS.
params.wm_class_name = "atom-shell";
params.wm_class_class = "Atom Shell";
params.wm_class_name = "atom";
params.wm_class_class = "Atom";
#endif
window_->Init(params);
@@ -688,7 +692,10 @@ void NativeWindowViews::HandleKeyboardEvent(
// When a single Alt is pressed:
menu_bar_alt_pressed_ = true;
} else if (event.type == blink::WebInputEvent::KeyUp && IsAltKey(event) &&
event.modifiers == 0 && menu_bar_alt_pressed_) {
#if defined(USE_X11)
event.modifiers == 0 &&
#endif
menu_bar_alt_pressed_) {
// When a single Alt is released right after a Alt is pressed:
menu_bar_alt_pressed_ = false;
SetMenuBarVisibility(!menu_bar_visible_);

View File

@@ -99,7 +99,7 @@ void URLRequestAsarJob::DidOpen(int result) {
return;
}
int rv = stream_->Seek(net::FROM_BEGIN,
int rv = stream_->Seek(base::File::FROM_BEGIN,
file_info_.offset,
base::Bind(&URLRequestAsarJob::DidSeek,
weak_ptr_factory_.GetWeakPtr()));

View File

@@ -17,7 +17,7 @@
<key>CFBundleIconFile</key>
<string>atom.icns</string>
<key>CFBundleVersion</key>
<string>0.17.0</string>
<string>0.18.1</string>
<key>LSMinimumSystemVersion</key>
<string>10.8.0</string>
<key>NSMainNibFile</key>

View File

@@ -50,8 +50,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,17,0,0
PRODUCTVERSION 0,17,0,0
FILEVERSION 0,18,1,0
PRODUCTVERSION 0,18,1,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@@ -68,12 +68,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "GitHub, Inc."
VALUE "FileDescription", "Atom-Shell"
VALUE "FileVersion", "0.17.0"
VALUE "FileVersion", "0.18.1"
VALUE "InternalName", "atom.exe"
VALUE "LegalCopyright", "Copyright (C) 2013 GitHub, Inc. All rights reserved."
VALUE "OriginalFilename", "atom.exe"
VALUE "ProductName", "Atom-Shell"
VALUE "ProductVersion", "0.17.0"
VALUE "ProductVersion", "0.18.1"
VALUE "SquirrelAwareVersion", "1"
END
END

View File

@@ -91,7 +91,7 @@ bool StringToAccelerator(const std::string& description,
LOG(ERROR) << "The accelerator string can only contain ASCII characters";
return false;
}
std::string shortcut(StringToLowerASCII(description));
std::string shortcut(base::StringToLowerASCII(description));
std::vector<std::string> tokens;
base::SplitString(shortcut, '+', &tokens);

View File

@@ -145,7 +145,7 @@ MessageDialog::MessageDialog(NativeWindow* parent_window,
views::LabelButton* button = new views::LabelButton(
this, base::UTF8ToUTF16(buttons[i]));
button->set_tag(i);
button->set_min_size(gfx::Size(60, 30));
button->SetMinSize(gfx::Size(60, 30));
button->SetStyle(views::Button::STYLE_BUTTON);
button->SetGroup(kButtonGroup);

View File

@@ -35,14 +35,15 @@ void MenuDelegate::RunMenu(ui::MenuModel* model, views::MenuButton* button) {
id_ = button->tag();
views::MenuItemView* item = BuildMenu(model);
views::MenuRunner menu_runner(item);
views::MenuRunner menu_runner(
item,
views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS);
ignore_result(menu_runner.RunMenuAt(
button->GetWidget()->GetTopLevelWidget(),
button,
bounds,
views::MENU_ANCHOR_TOPRIGHT,
ui::MENU_SOURCE_MOUSE,
views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU));
ui::MENU_SOURCE_MOUSE));
}
views::MenuItemView* MenuDelegate::BuildMenu(ui::MenuModel* model) {

View File

@@ -60,14 +60,15 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos,
if (!SetForegroundWindow(window_))
return;
views::MenuRunner menu_runner(menu_model_);
views::MenuRunner menu_runner(
menu_model_,
views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS);
ignore_result(menu_runner.RunMenuAt(
NULL,
NULL,
gfx::Rect(cursor_pos, gfx::Size()),
views::MENU_ANCHOR_TOPLEFT,
ui::MENU_SOURCE_MOUSE,
views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU));
ui::MENU_SOURCE_MOUSE));
}
void NotifyIcon::ResetIcon() {

View File

@@ -9,6 +9,7 @@
#include "base/values.h"
#include "content/public/common/common_param_traits.h"
#include "ipc/ipc_message_macros.h"
#include "ui/gfx/ipc/gfx_param_traits.h"
// The message starter should be declared in ipc/ipc_message_start.h. Since
// we don't want to patch Chromium, we just pretend to be Content Shell.

View File

@@ -8,6 +8,7 @@
#include <string>
#include "atom/common/atom_version.h"
#include "atom/common/chrome_version.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "base/logging.h"
#include "native_mate/callback.h"
@@ -78,9 +79,12 @@ void AtomBindings::BindTo(v8::Isolate* isolate,
base::Bind(&AtomBindings::ActivateUVLoop, base::Unretained(this)));
v8::Handle<v8::Object> versions;
if (dict.Get("versions", &versions))
if (dict.Get("versions", &versions)) {
versions->Set(mate::StringToV8(isolate, "atom-shell"),
mate::StringToV8(isolate, ATOM_VERSION_STRING));
versions->Set(mate::StringToV8(isolate, "chrome"),
mate::StringToV8(isolate, CHROME_VERSION_STRING));
}
}
void AtomBindings::ActivateUVLoop(v8::Isolate* isolate) {

View File

@@ -6,8 +6,8 @@
#define ATOM_VERSION_H
#define ATOM_MAJOR_VERSION 0
#define ATOM_MINOR_VERSION 17
#define ATOM_PATCH_VERSION 0
#define ATOM_MINOR_VERSION 18
#define ATOM_PATCH_VERSION 1
#define ATOM_VERSION_IS_RELEASE 1

View File

@@ -8,7 +8,7 @@
#ifndef ATOM_COMMON_CHROME_VERSION_H_
#define ATOM_COMMON_CHROME_VERSION_H_
#define CHROME_VERSION_STRING "37.0.2062.102"
#define CHROME_VERSION_STRING "38.0.2125.101"
#define CHROME_VERSION "v" CHROME_VERSION_STRING
#endif // ATOM_COMMON_CHROME_VERSION_H_

View File

@@ -6,3 +6,4 @@
#include "atom/common/api/api_messages.h"
#include "chrome/common/print_messages.h"
#include "chrome/common/tts_messages.h"

View File

@@ -0,0 +1,12 @@
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_COMMON_GOOGLE_API_KEY_H_
#define ATOM_COMMON_GOOGLE_API_KEY_H_
#ifndef GOOGLEAPIS_API_KEY
#define GOOGLEAPIS_API_KEY "AIzaSyAQfxPJiounkhOjODEO5ZieffeBv6yft2Q"
#endif
#endif // ATOM_COMMON_GOOGLE_API_KEY_H_

View File

@@ -29,6 +29,7 @@ splitPath = (p) ->
nextInode = 0
uid = if process.getuid? then process.getuid() else 0
gid = if process.getgid? then process.getgid() else 0
fakeTime = new Date()
asarStatsToFsStats = (stats) ->
{
dev: 1,
@@ -38,7 +39,11 @@ asarStatsToFsStats = (stats) ->
uid: uid,
gid: gid,
rdev: 0,
size: stats.size
atime: stats.atime || fakeTime,
birthtime: stats.birthtime || fakeTime,
mtime: stats.mtime || fakeTime,
ctime: stats.ctime || fakeTime,
size: stats.size,
isFile: -> stats.isFile
isDirectory: -> stats.isDirectory
isSymbolicLink: -> stats.isLink

View File

@@ -12,6 +12,7 @@
#include "atom/renderer/api/atom_renderer_bindings.h"
#include "atom/renderer/atom_render_view_observer.h"
#include "chrome/renderer/printing/print_web_view_helper.h"
#include "chrome/renderer/tts_dispatcher.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_thread.h"
@@ -128,6 +129,11 @@ void AtomRendererClient::RenderViewCreated(content::RenderView* render_view) {
new AtomRenderViewObserver(render_view, this);
}
blink::WebSpeechSynthesizer* AtomRendererClient::OverrideSpeechSynthesizer(
blink::WebSpeechSynthesizerClient* client) {
return new TtsDispatcher(client);
}
void AtomRendererClient::DidCreateScriptContext(blink::WebFrame* frame,
v8::Handle<v8::Context> context,
int extension_group,

View File

@@ -50,6 +50,8 @@ class AtomRendererClient : public content::ContentRendererClient,
virtual void RenderThreadStarted() OVERRIDE;
virtual void RenderFrameCreated(content::RenderFrame* render_frame) OVERRIDE;
virtual void RenderViewCreated(content::RenderView*) OVERRIDE;
virtual blink::WebSpeechSynthesizer* OverrideSpeechSynthesizer(
blink::WebSpeechSynthesizerClient* client);
virtual void DidCreateScriptContext(blink::WebFrame* frame,
v8::Handle<v8::Context> context,
int extension_group,

View File

@@ -31,11 +31,11 @@ window.addEventListener 'unload', ->
# Set the __filename to the path of html file if it's file: or asar: protocol.
if window.location.protocol in ['file:', 'asar:']
pathname =
if process.platform is 'win32'
if process.platform is 'win32' and window.location.pathname[0] is '/'
window.location.pathname.substr 1
else
window.location.pathname
global.__filename = decodeURIComponent pathname
global.__filename = path.normalize decodeURIComponent(pathname)
global.__dirname = path.dirname global.__filename
# Set module's filename so relative require can work as expected.

View File

@@ -0,0 +1,343 @@
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_SPEECH_TTS_CONTROLLER_H_
#define CHROME_BROWSER_SPEECH_TTS_CONTROLLER_H_
#include <queue>
#include <set>
#include <string>
#include <vector>
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/memory/weak_ptr.h"
#include "url/gurl.h"
class Utterance;
class TtsPlatformImpl;
namespace base {
class Value;
}
namespace content {
class BrowserContext;
}
// Events sent back from the TTS engine indicating the progress.
enum TtsEventType {
TTS_EVENT_START,
TTS_EVENT_END,
TTS_EVENT_WORD,
TTS_EVENT_SENTENCE,
TTS_EVENT_MARKER,
TTS_EVENT_INTERRUPTED,
TTS_EVENT_CANCELLED,
TTS_EVENT_ERROR,
TTS_EVENT_PAUSE,
TTS_EVENT_RESUME
};
enum TtsGenderType {
TTS_GENDER_NONE,
TTS_GENDER_MALE,
TTS_GENDER_FEMALE
};
// Returns true if this event type is one that indicates an utterance
// is finished and can be destroyed.
bool IsFinalTtsEventType(TtsEventType event_type);
// The continuous parameters that apply to a given utterance.
struct UtteranceContinuousParameters {
UtteranceContinuousParameters();
double rate;
double pitch;
double volume;
};
// Information about one voice.
struct VoiceData {
VoiceData();
~VoiceData();
std::string name;
std::string lang;
TtsGenderType gender;
std::string extension_id;
std::set<TtsEventType> events;
// If true, the synthesis engine is a remote network resource.
// It may be higher latency and may incur bandwidth costs.
bool remote;
// If true, this is implemented by this platform's subclass of
// TtsPlatformImpl. If false, this is implemented by an extension.
bool native;
std::string native_voice_identifier;
};
// Interface that delegates TTS requests to user-installed extensions.
class TtsEngineDelegate {
public:
virtual ~TtsEngineDelegate() {}
// Return a list of all available voices registered.
virtual void GetVoices(content::BrowserContext* browser_context,
std::vector<VoiceData>* out_voices) = 0;
// Speak the given utterance by sending an event to the given TTS engine.
virtual void Speak(Utterance* utterance, const VoiceData& voice) = 0;
// Stop speaking the given utterance by sending an event to the target
// associated with this utterance.
virtual void Stop(Utterance* utterance) = 0;
// Pause in the middle of speaking this utterance.
virtual void Pause(Utterance* utterance) = 0;
// Resume speaking this utterance.
virtual void Resume(Utterance* utterance) = 0;
// Load the built-in component extension for ChromeOS.
virtual bool LoadBuiltInTtsExtension(
content::BrowserContext* browser_context) = 0;
};
// Class that wants to receive events on utterances.
class UtteranceEventDelegate {
public:
virtual ~UtteranceEventDelegate() {}
virtual void OnTtsEvent(Utterance* utterance,
TtsEventType event_type,
int char_index,
const std::string& error_message) = 0;
};
// Class that wants to be notified when the set of
// voices has changed.
class VoicesChangedDelegate {
public:
virtual ~VoicesChangedDelegate() {}
virtual void OnVoicesChanged() = 0;
};
// One speech utterance.
class Utterance {
public:
// Construct an utterance given a profile and a completion task to call
// when the utterance is done speaking. Before speaking this utterance,
// its other parameters like text, rate, pitch, etc. should all be set.
explicit Utterance(content::BrowserContext* browser_context);
~Utterance();
// Sends an event to the delegate. If the event type is TTS_EVENT_END
// or TTS_EVENT_ERROR, deletes the utterance. If |char_index| is -1,
// uses the last good value.
void OnTtsEvent(TtsEventType event_type,
int char_index,
const std::string& error_message);
// Finish an utterance without sending an event to the delegate.
void Finish();
// Getters and setters for the text to speak and other speech options.
void set_text(const std::string& text) { text_ = text; }
const std::string& text() const { return text_; }
void set_options(const base::Value* options);
const base::Value* options() const { return options_.get(); }
void set_src_extension_id(const std::string& src_extension_id) {
src_extension_id_ = src_extension_id;
}
const std::string& src_extension_id() { return src_extension_id_; }
void set_src_id(int src_id) { src_id_ = src_id; }
int src_id() { return src_id_; }
void set_src_url(const GURL& src_url) { src_url_ = src_url; }
const GURL& src_url() { return src_url_; }
void set_voice_name(const std::string& voice_name) {
voice_name_ = voice_name;
}
const std::string& voice_name() const { return voice_name_; }
void set_lang(const std::string& lang) {
lang_ = lang;
}
const std::string& lang() const { return lang_; }
void set_gender(TtsGenderType gender) {
gender_ = gender;
}
TtsGenderType gender() const { return gender_; }
void set_continuous_parameters(const UtteranceContinuousParameters& params) {
continuous_parameters_ = params;
}
const UtteranceContinuousParameters& continuous_parameters() {
return continuous_parameters_;
}
void set_can_enqueue(bool can_enqueue) { can_enqueue_ = can_enqueue; }
bool can_enqueue() const { return can_enqueue_; }
void set_required_event_types(const std::set<TtsEventType>& types) {
required_event_types_ = types;
}
const std::set<TtsEventType>& required_event_types() const {
return required_event_types_;
}
void set_desired_event_types(const std::set<TtsEventType>& types) {
desired_event_types_ = types;
}
const std::set<TtsEventType>& desired_event_types() const {
return desired_event_types_;
}
const std::string& extension_id() const { return extension_id_; }
void set_extension_id(const std::string& extension_id) {
extension_id_ = extension_id;
}
UtteranceEventDelegate* event_delegate() const {
return event_delegate_.get();
}
void set_event_delegate(
base::WeakPtr<UtteranceEventDelegate> event_delegate) {
event_delegate_ = event_delegate;
}
// Getters and setters for internal state.
content::BrowserContext* browser_context() const { return browser_context_; }
int id() const { return id_; }
bool finished() const { return finished_; }
private:
// The BrowserContext that initiated this utterance.
content::BrowserContext* browser_context_;
// The extension ID of the extension providing TTS for this utterance, or
// empty if native TTS is being used.
std::string extension_id_;
// The unique ID of this utterance, used to associate callback functions
// with utterances.
int id_;
// The id of the next utterance, so we can associate requests with
// responses.
static int next_utterance_id_;
// The text to speak.
std::string text_;
// The full options arg passed to tts.speak, which may include fields
// other than the ones we explicitly parse, below.
scoped_ptr<base::Value> options_;
// The extension ID of the extension that called speak() and should
// receive events.
std::string src_extension_id_;
// The source extension's ID of this utterance, so that it can associate
// events with the appropriate callback.
int src_id_;
// The URL of the page where the source extension called speak.
GURL src_url_;
// The delegate to be called when an utterance event is fired.
base::WeakPtr<UtteranceEventDelegate> event_delegate_;
// The parsed options.
std::string voice_name_;
std::string lang_;
TtsGenderType gender_;
UtteranceContinuousParameters continuous_parameters_;
bool can_enqueue_;
std::set<TtsEventType> required_event_types_;
std::set<TtsEventType> desired_event_types_;
// The index of the current char being spoken.
int char_index_;
// True if this utterance received an event indicating it's done.
bool finished_;
};
// Singleton class that manages text-to-speech for the TTS and TTS engine
// extension APIs, maintaining a queue of pending utterances and keeping
// track of all state.
class TtsController {
public:
// Get the single instance of this class.
static TtsController* GetInstance();
// Returns true if we're currently speaking an utterance.
virtual bool IsSpeaking() = 0;
// Speak the given utterance. If the utterance's can_enqueue flag is true
// and another utterance is in progress, adds it to the end of the queue.
// Otherwise, interrupts any current utterance and speaks this one
// immediately.
virtual void SpeakOrEnqueue(Utterance* utterance) = 0;
// Stop all utterances and flush the queue. Implies leaving pause mode
// as well.
virtual void Stop() = 0;
// Pause the speech queue. Some engines may support pausing in the middle
// of an utterance.
virtual void Pause() = 0;
// Resume speaking.
virtual void Resume() = 0;
// Handle events received from the speech engine. Events are forwarded to
// the callback function, and in addition, completion and error events
// trigger finishing the current utterance and starting the next one, if
// any.
virtual void OnTtsEvent(int utterance_id,
TtsEventType event_type,
int char_index,
const std::string& error_message) = 0;
// Return a list of all available voices, including the native voice,
// if supported, and all voices registered by extensions.
virtual void GetVoices(content::BrowserContext* browser_context,
std::vector<VoiceData>* out_voices) = 0;
// Called by the extension system or platform implementation when the
// list of voices may have changed and should be re-queried.
virtual void VoicesChanged() = 0;
// Add a delegate that wants to be notified when the set of voices changes.
virtual void AddVoicesChangedDelegate(VoicesChangedDelegate* delegate) = 0;
// Remove delegate that wants to be notified when the set of voices changes.
virtual void RemoveVoicesChangedDelegate(VoicesChangedDelegate* delegate) = 0;
// Set the delegate that processes TTS requests with user-installed
// extensions.
virtual void SetTtsEngineDelegate(TtsEngineDelegate* delegate) = 0;
// Get the delegate that processes TTS requests with user-installed
// extensions.
virtual TtsEngineDelegate* GetTtsEngineDelegate() = 0;
// For unit testing.
virtual void SetPlatformImpl(TtsPlatformImpl* platform_impl) = 0;
virtual int QueueSize() = 0;
protected:
virtual ~TtsController() {}
};
#endif // CHROME_BROWSER_SPEECH_TTS_CONTROLLER_H_

View File

@@ -0,0 +1,464 @@
// Copyright 2014 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/speech/tts_controller_impl.h"
#include <string>
#include <vector>
#include "base/float_util.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/speech/tts_platform.h"
namespace {
// A value to be used to indicate that there is no char index available.
const int kInvalidCharIndex = -1;
// Given a language/region code of the form 'fr-FR', returns just the basic
// language portion, e.g. 'fr'.
std::string TrimLanguageCode(std::string lang) {
if (lang.size() >= 5 && lang[2] == '-')
return lang.substr(0, 2);
else
return lang;
}
} // namespace
bool IsFinalTtsEventType(TtsEventType event_type) {
return (event_type == TTS_EVENT_END ||
event_type == TTS_EVENT_INTERRUPTED ||
event_type == TTS_EVENT_CANCELLED ||
event_type == TTS_EVENT_ERROR);
}
//
// UtteranceContinuousParameters
//
UtteranceContinuousParameters::UtteranceContinuousParameters()
: rate(-1),
pitch(-1),
volume(-1) {}
//
// VoiceData
//
VoiceData::VoiceData()
: gender(TTS_GENDER_NONE),
remote(false),
native(false) {}
VoiceData::~VoiceData() {}
//
// Utterance
//
// static
int Utterance::next_utterance_id_ = 0;
Utterance::Utterance(content::BrowserContext* browser_context)
: browser_context_(browser_context),
id_(next_utterance_id_++),
src_id_(-1),
gender_(TTS_GENDER_NONE),
can_enqueue_(false),
char_index_(0),
finished_(false) {
options_.reset(new base::DictionaryValue());
}
Utterance::~Utterance() {
DCHECK(finished_);
}
void Utterance::OnTtsEvent(TtsEventType event_type,
int char_index,
const std::string& error_message) {
if (char_index >= 0)
char_index_ = char_index;
if (IsFinalTtsEventType(event_type))
finished_ = true;
if (event_delegate_)
event_delegate_->OnTtsEvent(this, event_type, char_index, error_message);
if (finished_)
event_delegate_.reset();
}
void Utterance::Finish() {
finished_ = true;
}
void Utterance::set_options(const base::Value* options) {
options_.reset(options->DeepCopy());
}
TtsController* TtsController::GetInstance() {
return TtsControllerImpl::GetInstance();
}
//
// TtsControllerImpl
//
// static
TtsControllerImpl* TtsControllerImpl::GetInstance() {
return Singleton<TtsControllerImpl>::get();
}
TtsControllerImpl::TtsControllerImpl()
: current_utterance_(NULL),
paused_(false),
platform_impl_(NULL),
tts_engine_delegate_(NULL) {
}
TtsControllerImpl::~TtsControllerImpl() {
if (current_utterance_) {
current_utterance_->Finish();
delete current_utterance_;
}
// Clear any queued utterances too.
ClearUtteranceQueue(false); // Don't sent events.
}
void TtsControllerImpl::SpeakOrEnqueue(Utterance* utterance) {
// If we're paused and we get an utterance that can't be queued,
// flush the queue but stay in the paused state.
if (paused_ && !utterance->can_enqueue()) {
Stop();
paused_ = true;
delete utterance;
return;
}
if (paused_ || (IsSpeaking() && utterance->can_enqueue())) {
utterance_queue_.push(utterance);
} else {
Stop();
SpeakNow(utterance);
}
}
void TtsControllerImpl::SpeakNow(Utterance* utterance) {
// Ensure we have all built-in voices loaded. This is a no-op if already
// loaded.
bool loaded_built_in =
GetPlatformImpl()->LoadBuiltInTtsExtension(utterance->browser_context());
// Get all available voices and try to find a matching voice.
std::vector<VoiceData> voices;
GetVoices(utterance->browser_context(), &voices);
int index = GetMatchingVoice(utterance, voices);
VoiceData voice;
if (index != -1) {
// Select the matching voice.
voice = voices[index];
} else {
// However, if no match was found on a platform without native tts voices,
// attempt to get a voice based only on the current locale without respect
// to any supplied voice names.
std::vector<VoiceData> native_voices;
if (GetPlatformImpl()->PlatformImplAvailable())
GetPlatformImpl()->GetVoices(&native_voices);
if (native_voices.empty() && !voices.empty()) {
// TODO(dtseng): Notify extension caller of an error.
utterance->set_voice_name("");
// TODO(gaochun): Replace the global variable g_browser_process with
// GetContentClient()->browser() to eliminate the dependency of browser
// once TTS implementation was moved to content.
utterance->set_lang(g_browser_process->GetApplicationLocale());
index = GetMatchingVoice(utterance, voices);
// If even that fails, just take the first available voice.
if (index == -1)
index = 0;
voice = voices[index];
} else {
// Otherwise, simply give native voices a chance to handle this utterance.
voice.native = true;
}
}
GetPlatformImpl()->WillSpeakUtteranceWithVoice(utterance, voice);
if (!voice.native) {
#if !defined(OS_ANDROID)
DCHECK(!voice.extension_id.empty());
current_utterance_ = utterance;
utterance->set_extension_id(voice.extension_id);
if (tts_engine_delegate_)
tts_engine_delegate_->Speak(utterance, voice);
bool sends_end_event =
voice.events.find(TTS_EVENT_END) != voice.events.end();
if (!sends_end_event) {
utterance->Finish();
delete utterance;
current_utterance_ = NULL;
SpeakNextUtterance();
}
#endif
} else {
// It's possible for certain platforms to send start events immediately
// during |speak|.
current_utterance_ = utterance;
GetPlatformImpl()->clear_error();
bool success = GetPlatformImpl()->Speak(
utterance->id(),
utterance->text(),
utterance->lang(),
voice,
utterance->continuous_parameters());
if (!success)
current_utterance_ = NULL;
// If the native voice wasn't able to process this speech, see if
// the browser has built-in TTS that isn't loaded yet.
if (!success && loaded_built_in) {
utterance_queue_.push(utterance);
return;
}
if (!success) {
utterance->OnTtsEvent(TTS_EVENT_ERROR, kInvalidCharIndex,
GetPlatformImpl()->error());
delete utterance;
return;
}
}
}
void TtsControllerImpl::Stop() {
paused_ = false;
if (current_utterance_ && !current_utterance_->extension_id().empty()) {
#if !defined(OS_ANDROID)
if (tts_engine_delegate_)
tts_engine_delegate_->Stop(current_utterance_);
#endif
} else {
GetPlatformImpl()->clear_error();
GetPlatformImpl()->StopSpeaking();
}
if (current_utterance_)
current_utterance_->OnTtsEvent(TTS_EVENT_INTERRUPTED, kInvalidCharIndex,
std::string());
FinishCurrentUtterance();
ClearUtteranceQueue(true); // Send events.
}
void TtsControllerImpl::Pause() {
paused_ = true;
if (current_utterance_ && !current_utterance_->extension_id().empty()) {
#if !defined(OS_ANDROID)
if (tts_engine_delegate_)
tts_engine_delegate_->Pause(current_utterance_);
#endif
} else if (current_utterance_) {
GetPlatformImpl()->clear_error();
GetPlatformImpl()->Pause();
}
}
void TtsControllerImpl::Resume() {
paused_ = false;
if (current_utterance_ && !current_utterance_->extension_id().empty()) {
#if !defined(OS_ANDROID)
if (tts_engine_delegate_)
tts_engine_delegate_->Resume(current_utterance_);
#endif
} else if (current_utterance_) {
GetPlatformImpl()->clear_error();
GetPlatformImpl()->Resume();
} else {
SpeakNextUtterance();
}
}
void TtsControllerImpl::OnTtsEvent(int utterance_id,
TtsEventType event_type,
int char_index,
const std::string& error_message) {
// We may sometimes receive completion callbacks "late", after we've
// already finished the utterance (for example because another utterance
// interrupted or we got a call to Stop). This is normal and we can
// safely just ignore these events.
if (!current_utterance_ || utterance_id != current_utterance_->id()) {
return;
}
current_utterance_->OnTtsEvent(event_type, char_index, error_message);
if (current_utterance_->finished()) {
FinishCurrentUtterance();
SpeakNextUtterance();
}
}
void TtsControllerImpl::GetVoices(content::BrowserContext* browser_context,
std::vector<VoiceData>* out_voices) {
#if !defined(OS_ANDROID)
if (browser_context && tts_engine_delegate_)
tts_engine_delegate_->GetVoices(browser_context, out_voices);
#endif
TtsPlatformImpl* platform_impl = GetPlatformImpl();
if (platform_impl) {
// Ensure we have all built-in voices loaded. This is a no-op if already
// loaded.
platform_impl->LoadBuiltInTtsExtension(browser_context);
if (platform_impl->PlatformImplAvailable())
platform_impl->GetVoices(out_voices);
}
}
bool TtsControllerImpl::IsSpeaking() {
return current_utterance_ != NULL || GetPlatformImpl()->IsSpeaking();
}
void TtsControllerImpl::FinishCurrentUtterance() {
if (current_utterance_) {
if (!current_utterance_->finished())
current_utterance_->OnTtsEvent(TTS_EVENT_INTERRUPTED, kInvalidCharIndex,
std::string());
delete current_utterance_;
current_utterance_ = NULL;
}
}
void TtsControllerImpl::SpeakNextUtterance() {
if (paused_)
return;
// Start speaking the next utterance in the queue. Keep trying in case
// one fails but there are still more in the queue to try.
while (!utterance_queue_.empty() && !current_utterance_) {
Utterance* utterance = utterance_queue_.front();
utterance_queue_.pop();
SpeakNow(utterance);
}
}
void TtsControllerImpl::ClearUtteranceQueue(bool send_events) {
while (!utterance_queue_.empty()) {
Utterance* utterance = utterance_queue_.front();
utterance_queue_.pop();
if (send_events)
utterance->OnTtsEvent(TTS_EVENT_CANCELLED, kInvalidCharIndex,
std::string());
else
utterance->Finish();
delete utterance;
}
}
void TtsControllerImpl::SetPlatformImpl(
TtsPlatformImpl* platform_impl) {
platform_impl_ = platform_impl;
}
int TtsControllerImpl::QueueSize() {
return static_cast<int>(utterance_queue_.size());
}
TtsPlatformImpl* TtsControllerImpl::GetPlatformImpl() {
if (!platform_impl_)
platform_impl_ = TtsPlatformImpl::GetInstance();
return platform_impl_;
}
int TtsControllerImpl::GetMatchingVoice(
const Utterance* utterance, std::vector<VoiceData>& voices) {
// Make two passes: the first time, do strict language matching
// ('fr-FR' does not match 'fr-CA'). The second time, do prefix
// language matching ('fr-FR' matches 'fr' and 'fr-CA')
for (int pass = 0; pass < 2; ++pass) {
for (size_t i = 0; i < voices.size(); ++i) {
const VoiceData& voice = voices[i];
if (!utterance->extension_id().empty() &&
utterance->extension_id() != voice.extension_id) {
continue;
}
if (!voice.name.empty() &&
!utterance->voice_name().empty() &&
voice.name != utterance->voice_name()) {
continue;
}
if (!voice.lang.empty() && !utterance->lang().empty()) {
std::string voice_lang = voice.lang;
std::string utterance_lang = utterance->lang();
if (pass == 1) {
voice_lang = TrimLanguageCode(voice_lang);
utterance_lang = TrimLanguageCode(utterance_lang);
}
if (voice_lang != utterance_lang) {
continue;
}
}
if (voice.gender != TTS_GENDER_NONE &&
utterance->gender() != TTS_GENDER_NONE &&
voice.gender != utterance->gender()) {
continue;
}
if (utterance->required_event_types().size() > 0) {
bool has_all_required_event_types = true;
for (std::set<TtsEventType>::const_iterator iter =
utterance->required_event_types().begin();
iter != utterance->required_event_types().end();
++iter) {
if (voice.events.find(*iter) == voice.events.end()) {
has_all_required_event_types = false;
break;
}
}
if (!has_all_required_event_types)
continue;
}
return static_cast<int>(i);
}
}
return -1;
}
void TtsControllerImpl::VoicesChanged() {
for (std::set<VoicesChangedDelegate*>::iterator iter =
voices_changed_delegates_.begin();
iter != voices_changed_delegates_.end(); ++iter) {
(*iter)->OnVoicesChanged();
}
}
void TtsControllerImpl::AddVoicesChangedDelegate(
VoicesChangedDelegate* delegate) {
voices_changed_delegates_.insert(delegate);
}
void TtsControllerImpl::RemoveVoicesChangedDelegate(
VoicesChangedDelegate* delegate) {
voices_changed_delegates_.erase(delegate);
}
void TtsControllerImpl::SetTtsEngineDelegate(
TtsEngineDelegate* delegate) {
tts_engine_delegate_ = delegate;
}
TtsEngineDelegate* TtsControllerImpl::GetTtsEngineDelegate() {
return tts_engine_delegate_;
}

View File

@@ -0,0 +1,104 @@
// Copyright 2014 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.
#ifndef CHROME_BROWSER_SPEECH_TTS_CONTROLLER_IMPL_H_
#define CHROME_BROWSER_SPEECH_TTS_CONTROLLER_IMPL_H_
#include <queue>
#include <set>
#include <string>
#include <vector>
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/speech/tts_controller.h"
#include "url/gurl.h"
namespace content {
class BrowserContext;
}
// Singleton class that manages text-to-speech for the TTS and TTS engine
// extension APIs, maintaining a queue of pending utterances and keeping
// track of all state.
class TtsControllerImpl : public TtsController {
public:
// Get the single instance of this class.
static TtsControllerImpl* GetInstance();
// TtsController methods
virtual bool IsSpeaking() OVERRIDE;
virtual void SpeakOrEnqueue(Utterance* utterance) OVERRIDE;
virtual void Stop() OVERRIDE;
virtual void Pause() OVERRIDE;
virtual void Resume() OVERRIDE;
virtual void OnTtsEvent(int utterance_id,
TtsEventType event_type,
int char_index,
const std::string& error_message) OVERRIDE;
virtual void GetVoices(content::BrowserContext* browser_context,
std::vector<VoiceData>* out_voices) OVERRIDE;
virtual void VoicesChanged() OVERRIDE;
virtual void AddVoicesChangedDelegate(
VoicesChangedDelegate* delegate) OVERRIDE;
virtual void RemoveVoicesChangedDelegate(
VoicesChangedDelegate* delegate) OVERRIDE;
virtual void SetTtsEngineDelegate(TtsEngineDelegate* delegate) OVERRIDE;
virtual TtsEngineDelegate* GetTtsEngineDelegate() OVERRIDE;
virtual void SetPlatformImpl(TtsPlatformImpl* platform_impl) OVERRIDE;
virtual int QueueSize() OVERRIDE;
protected:
TtsControllerImpl();
virtual ~TtsControllerImpl();
private:
// Get the platform TTS implementation (or injected mock).
TtsPlatformImpl* GetPlatformImpl();
// Start speaking the given utterance. Will either take ownership of
// |utterance| or delete it if there's an error. Returns true on success.
void SpeakNow(Utterance* utterance);
// Clear the utterance queue. If send_events is true, will send
// TTS_EVENT_CANCELLED events on each one.
void ClearUtteranceQueue(bool send_events);
// Finalize and delete the current utterance.
void FinishCurrentUtterance();
// Start speaking the next utterance in the queue.
void SpeakNextUtterance();
// Given an utterance and a vector of voices, return the
// index of the voice that best matches the utterance.
int GetMatchingVoice(const Utterance* utterance,
std::vector<VoiceData>& voices);
friend struct DefaultSingletonTraits<TtsControllerImpl>;
// The current utterance being spoken.
Utterance* current_utterance_;
// Whether the queue is paused or not.
bool paused_;
// A queue of utterances to speak after the current one finishes.
std::queue<Utterance*> utterance_queue_;
// A set of delegates that want to be notified when the voices change.
std::set<VoicesChangedDelegate*> voices_changed_delegates_;
// A pointer to the platform implementation of text-to-speech, for
// dependency injection.
TtsPlatformImpl* platform_impl_;
// The delegate that processes TTS requests with user-installed extensions.
TtsEngineDelegate* tts_engine_delegate_;
DISALLOW_COPY_AND_ASSIGN(TtsControllerImpl);
};
#endif // CHROME_BROWSER_SPEECH_TTS_CONTROLLER_IMPL_H_

View File

@@ -0,0 +1,347 @@
// Copyright (c) 2012 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 <math.h>
#include <map>
#include "base/command_line.h"
#include "base/debug/leak_annotations.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/synchronization/lock.h"
#include "chrome/browser/speech/tts_platform.h"
#include "content/public/browser/browser_thread.h"
#include "library_loaders/libspeechd.h"
using content::BrowserThread;
namespace {
const char kNotSupportedError[] =
"Native speech synthesis not supported on this platform.";
struct SPDChromeVoice {
std::string name;
std::string module;
};
} // namespace
class TtsPlatformImplLinux : public TtsPlatformImpl {
public:
virtual bool PlatformImplAvailable() OVERRIDE;
virtual bool Speak(
int utterance_id,
const std::string& utterance,
const std::string& lang,
const VoiceData& voice,
const UtteranceContinuousParameters& params) OVERRIDE;
virtual bool StopSpeaking() OVERRIDE;
virtual void Pause() OVERRIDE;
virtual void Resume() OVERRIDE;
virtual bool IsSpeaking() OVERRIDE;
virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE;
void OnSpeechEvent(SPDNotificationType type);
// Get the single instance of this class.
static TtsPlatformImplLinux* GetInstance();
private:
TtsPlatformImplLinux();
virtual ~TtsPlatformImplLinux();
// Initiate the connection with the speech dispatcher.
void Initialize();
// Resets the connection with speech dispatcher.
void Reset();
static void NotificationCallback(size_t msg_id,
size_t client_id,
SPDNotificationType type);
static void IndexMarkCallback(size_t msg_id,
size_t client_id,
SPDNotificationType state,
char* index_mark);
static SPDNotificationType current_notification_;
base::Lock initialization_lock_;
LibSpeechdLoader libspeechd_loader_;
SPDConnection* conn_;
// These apply to the current utterance only.
std::string utterance_;
int utterance_id_;
// Map a string composed of a voicename and module to the voicename. Used to
// uniquely identify a voice across all available modules.
scoped_ptr<std::map<std::string, SPDChromeVoice> > all_native_voices_;
friend struct DefaultSingletonTraits<TtsPlatformImplLinux>;
DISALLOW_COPY_AND_ASSIGN(TtsPlatformImplLinux);
};
// static
SPDNotificationType TtsPlatformImplLinux::current_notification_ =
SPD_EVENT_END;
TtsPlatformImplLinux::TtsPlatformImplLinux()
: utterance_id_(0) {
BrowserThread::PostTask(BrowserThread::FILE,
FROM_HERE,
base::Bind(&TtsPlatformImplLinux::Initialize,
base::Unretained(this)));
}
void TtsPlatformImplLinux::Initialize() {
base::AutoLock lock(initialization_lock_);
if (!libspeechd_loader_.Load("libspeechd.so.2"))
return;
{
// spd_open has memory leaks which are hard to suppress.
// http://crbug.com/317360
ANNOTATE_SCOPED_MEMORY_LEAK;
conn_ = libspeechd_loader_.spd_open(
"chrome", "extension_api", NULL, SPD_MODE_SINGLE);
}
if (!conn_)
return;
// Register callbacks for all events.
conn_->callback_begin =
conn_->callback_end =
conn_->callback_cancel =
conn_->callback_pause =
conn_->callback_resume =
&NotificationCallback;
conn_->callback_im = &IndexMarkCallback;
libspeechd_loader_.spd_set_notification_on(conn_, SPD_BEGIN);
libspeechd_loader_.spd_set_notification_on(conn_, SPD_END);
libspeechd_loader_.spd_set_notification_on(conn_, SPD_CANCEL);
libspeechd_loader_.spd_set_notification_on(conn_, SPD_PAUSE);
libspeechd_loader_.spd_set_notification_on(conn_, SPD_RESUME);
}
TtsPlatformImplLinux::~TtsPlatformImplLinux() {
base::AutoLock lock(initialization_lock_);
if (conn_) {
libspeechd_loader_.spd_close(conn_);
conn_ = NULL;
}
}
void TtsPlatformImplLinux::Reset() {
base::AutoLock lock(initialization_lock_);
if (conn_)
libspeechd_loader_.spd_close(conn_);
conn_ = libspeechd_loader_.spd_open(
"chrome", "extension_api", NULL, SPD_MODE_SINGLE);
}
bool TtsPlatformImplLinux::PlatformImplAvailable() {
if (!initialization_lock_.Try())
return false;
bool result = libspeechd_loader_.loaded() && (conn_ != NULL);
initialization_lock_.Release();
return result;
}
bool TtsPlatformImplLinux::Speak(
int utterance_id,
const std::string& utterance,
const std::string& lang,
const VoiceData& voice,
const UtteranceContinuousParameters& params) {
if (!PlatformImplAvailable()) {
error_ = kNotSupportedError;
return false;
}
// Speech dispatcher's speech params are around 3x at either limit.
float rate = params.rate > 3 ? 3 : params.rate;
rate = params.rate < 0.334 ? 0.334 : rate;
float pitch = params.pitch > 3 ? 3 : params.pitch;
pitch = params.pitch < 0.334 ? 0.334 : pitch;
std::map<std::string, SPDChromeVoice>::iterator it =
all_native_voices_->find(voice.name);
if (it != all_native_voices_->end()) {
libspeechd_loader_.spd_set_output_module(conn_, it->second.module.c_str());
libspeechd_loader_.spd_set_synthesis_voice(conn_, it->second.name.c_str());
}
// Map our multiplicative range to Speech Dispatcher's linear range.
// .334 = -100.
// 3 = 100.
libspeechd_loader_.spd_set_voice_rate(conn_, 100 * log10(rate) / log10(3));
libspeechd_loader_.spd_set_voice_pitch(conn_, 100 * log10(pitch) / log10(3));
utterance_ = utterance;
utterance_id_ = utterance_id;
if (libspeechd_loader_.spd_say(conn_, SPD_TEXT, utterance.c_str()) == -1) {
Reset();
return false;
}
return true;
}
bool TtsPlatformImplLinux::StopSpeaking() {
if (!PlatformImplAvailable())
return false;
if (libspeechd_loader_.spd_stop(conn_) == -1) {
Reset();
return false;
}
return true;
}
void TtsPlatformImplLinux::Pause() {
if (!PlatformImplAvailable())
return;
libspeechd_loader_.spd_pause(conn_);
}
void TtsPlatformImplLinux::Resume() {
if (!PlatformImplAvailable())
return;
libspeechd_loader_.spd_resume(conn_);
}
bool TtsPlatformImplLinux::IsSpeaking() {
return current_notification_ == SPD_EVENT_BEGIN;
}
void TtsPlatformImplLinux::GetVoices(
std::vector<VoiceData>* out_voices) {
if (!all_native_voices_.get()) {
all_native_voices_.reset(new std::map<std::string, SPDChromeVoice>());
char** modules = libspeechd_loader_.spd_list_modules(conn_);
if (!modules)
return;
for (int i = 0; modules[i]; i++) {
char* module = modules[i];
libspeechd_loader_.spd_set_output_module(conn_, module);
SPDVoice** native_voices =
libspeechd_loader_.spd_list_synthesis_voices(conn_);
if (!native_voices) {
free(module);
continue;
}
for (int j = 0; native_voices[j]; j++) {
SPDVoice* native_voice = native_voices[j];
SPDChromeVoice native_data;
native_data.name = native_voice->name;
native_data.module = module;
std::string key;
key.append(native_data.name);
key.append(" ");
key.append(native_data.module);
all_native_voices_->insert(
std::pair<std::string, SPDChromeVoice>(key, native_data));
free(native_voices[j]);
}
free(modules[i]);
}
}
for (std::map<std::string, SPDChromeVoice>::iterator it =
all_native_voices_->begin();
it != all_native_voices_->end();
it++) {
out_voices->push_back(VoiceData());
VoiceData& voice = out_voices->back();
voice.native = true;
voice.name = it->first;
voice.events.insert(TTS_EVENT_START);
voice.events.insert(TTS_EVENT_END);
voice.events.insert(TTS_EVENT_CANCELLED);
voice.events.insert(TTS_EVENT_MARKER);
voice.events.insert(TTS_EVENT_PAUSE);
voice.events.insert(TTS_EVENT_RESUME);
}
}
void TtsPlatformImplLinux::OnSpeechEvent(SPDNotificationType type) {
TtsController* controller = TtsController::GetInstance();
switch (type) {
case SPD_EVENT_BEGIN:
controller->OnTtsEvent(utterance_id_, TTS_EVENT_START, 0, std::string());
break;
case SPD_EVENT_RESUME:
controller->OnTtsEvent(utterance_id_, TTS_EVENT_RESUME, 0, std::string());
break;
case SPD_EVENT_END:
controller->OnTtsEvent(
utterance_id_, TTS_EVENT_END, utterance_.size(), std::string());
break;
case SPD_EVENT_PAUSE:
controller->OnTtsEvent(
utterance_id_, TTS_EVENT_PAUSE, utterance_.size(), std::string());
break;
case SPD_EVENT_CANCEL:
controller->OnTtsEvent(
utterance_id_, TTS_EVENT_CANCELLED, 0, std::string());
break;
case SPD_EVENT_INDEX_MARK:
controller->OnTtsEvent(utterance_id_, TTS_EVENT_MARKER, 0, std::string());
break;
}
}
// static
void TtsPlatformImplLinux::NotificationCallback(
size_t msg_id, size_t client_id, SPDNotificationType type) {
// We run Speech Dispatcher in threaded mode, so these callbacks should always
// be in a separate thread.
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
current_notification_ = type;
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(&TtsPlatformImplLinux::OnSpeechEvent,
base::Unretained(TtsPlatformImplLinux::GetInstance()),
type));
}
}
// static
void TtsPlatformImplLinux::IndexMarkCallback(size_t msg_id,
size_t client_id,
SPDNotificationType state,
char* index_mark) {
// TODO(dtseng): index_mark appears to specify an index type supplied by a
// client. Need to explore how this is used before hooking it up with existing
// word, sentence events.
// We run Speech Dispatcher in threaded mode, so these callbacks should always
// be in a separate thread.
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
current_notification_ = state;
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&TtsPlatformImplLinux::OnSpeechEvent,
base::Unretained(TtsPlatformImplLinux::GetInstance()),
state));
}
}
// static
TtsPlatformImplLinux* TtsPlatformImplLinux::GetInstance() {
return Singleton<TtsPlatformImplLinux,
LeakySingletonTraits<TtsPlatformImplLinux> >::get();
}
// static
TtsPlatformImpl* TtsPlatformImpl::GetInstance() {
return TtsPlatformImplLinux::GetInstance();
}

View File

@@ -0,0 +1,352 @@
// Copyright (c) 2012 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 "base/mac/scoped_nsobject.h"
#include "base/memory/singleton.h"
#include "base/strings/sys_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/speech/tts_controller.h"
#include "chrome/browser/speech/tts_platform.h"
#import <Cocoa/Cocoa.h>
class TtsPlatformImplMac;
@interface ChromeTtsDelegate : NSObject <NSSpeechSynthesizerDelegate> {
@private
TtsPlatformImplMac* ttsImplMac_; // weak.
}
- (id)initWithPlatformImplMac:(TtsPlatformImplMac*)ttsImplMac;
@end
// Subclass of NSSpeechSynthesizer that takes an utterance
// string on initialization, retains it and only allows it
// to be spoken once.
//
// We construct a new NSSpeechSynthesizer for each utterance, for
// two reasons:
// 1. To associate delegate callbacks with a particular utterance,
// without assuming anything undocumented about the protocol.
// 2. To work around http://openradar.appspot.com/radar?id=2854403,
// where Nuance voices don't retain the utterance string and
// crash when trying to call willSpeakWord.
@interface SingleUseSpeechSynthesizer : NSSpeechSynthesizer {
@private
base::scoped_nsobject<NSString> utterance_;
bool didSpeak_;
}
- (id)initWithUtterance:(NSString*)utterance;
- (bool)startSpeakingRetainedUtterance;
- (bool)startSpeakingString:(NSString*)utterance;
@end
class TtsPlatformImplMac : public TtsPlatformImpl {
public:
virtual bool PlatformImplAvailable() OVERRIDE {
return true;
}
virtual bool Speak(
int utterance_id,
const std::string& utterance,
const std::string& lang,
const VoiceData& voice,
const UtteranceContinuousParameters& params) OVERRIDE;
virtual bool StopSpeaking() OVERRIDE;
virtual void Pause() OVERRIDE;
virtual void Resume() OVERRIDE;
virtual bool IsSpeaking() OVERRIDE;
virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE;
// Called by ChromeTtsDelegate when we get a callback from the
// native speech engine.
void OnSpeechEvent(NSSpeechSynthesizer* sender,
TtsEventType event_type,
int char_index,
const std::string& error_message);
// Get the single instance of this class.
static TtsPlatformImplMac* GetInstance();
private:
TtsPlatformImplMac();
virtual ~TtsPlatformImplMac();
base::scoped_nsobject<SingleUseSpeechSynthesizer> speech_synthesizer_;
base::scoped_nsobject<ChromeTtsDelegate> delegate_;
int utterance_id_;
std::string utterance_;
int last_char_index_;
bool paused_;
friend struct DefaultSingletonTraits<TtsPlatformImplMac>;
DISALLOW_COPY_AND_ASSIGN(TtsPlatformImplMac);
};
// static
TtsPlatformImpl* TtsPlatformImpl::GetInstance() {
return TtsPlatformImplMac::GetInstance();
}
bool TtsPlatformImplMac::Speak(
int utterance_id,
const std::string& utterance,
const std::string& lang,
const VoiceData& voice,
const UtteranceContinuousParameters& params) {
// TODO: convert SSML to SAPI xml. http://crbug.com/88072
utterance_ = utterance;
paused_ = false;
NSString* utterance_nsstring =
[NSString stringWithUTF8String:utterance_.c_str()];
// Deliberately construct a new speech synthesizer every time Speak is
// called, otherwise there's no way to know whether calls to the delegate
// apply to the current utterance or a previous utterance. In
// experimentation, the overhead of constructing and destructing a
// NSSpeechSynthesizer is minimal.
speech_synthesizer_.reset(
[[SingleUseSpeechSynthesizer alloc]
initWithUtterance:utterance_nsstring]);
[speech_synthesizer_ setDelegate:delegate_];
if (!voice.native_voice_identifier.empty()) {
NSString* native_voice_identifier =
[NSString stringWithUTF8String:voice.native_voice_identifier.c_str()];
[speech_synthesizer_ setVoice:native_voice_identifier];
}
utterance_id_ = utterance_id;
// TODO: support languages other than the default: crbug.com/88059
if (params.rate >= 0.0) {
// The TTS api defines rate via words per minute. Let 200 be the default.
[speech_synthesizer_
setObject:[NSNumber numberWithInt:params.rate * 200]
forProperty:NSSpeechRateProperty error:nil];
}
if (params.pitch >= 0.0) {
// The input is a float from 0.0 to 2.0, with 1.0 being the default.
// Get the default pitch for this voice and modulate it by 50% - 150%.
NSError* errorCode;
NSNumber* defaultPitchObj =
[speech_synthesizer_ objectForProperty:NSSpeechPitchBaseProperty
error:&errorCode];
int defaultPitch = defaultPitchObj ? [defaultPitchObj intValue] : 48;
int newPitch = static_cast<int>(defaultPitch * (0.5 * params.pitch + 0.5));
[speech_synthesizer_
setObject:[NSNumber numberWithInt:newPitch]
forProperty:NSSpeechPitchBaseProperty error:nil];
}
if (params.volume >= 0.0) {
[speech_synthesizer_
setObject: [NSNumber numberWithFloat:params.volume]
forProperty:NSSpeechVolumeProperty error:nil];
}
bool success = [speech_synthesizer_ startSpeakingRetainedUtterance];
if (success) {
TtsController* controller = TtsController::GetInstance();
controller->OnTtsEvent(utterance_id_, TTS_EVENT_START, 0, "");
}
return success;
}
bool TtsPlatformImplMac::StopSpeaking() {
if (speech_synthesizer_.get()) {
[speech_synthesizer_ stopSpeaking];
speech_synthesizer_.reset(nil);
}
paused_ = false;
return true;
}
void TtsPlatformImplMac::Pause() {
if (speech_synthesizer_.get() && utterance_id_ && !paused_) {
[speech_synthesizer_ pauseSpeakingAtBoundary:NSSpeechImmediateBoundary];
paused_ = true;
TtsController::GetInstance()->OnTtsEvent(
utterance_id_, TTS_EVENT_PAUSE, last_char_index_, "");
}
}
void TtsPlatformImplMac::Resume() {
if (speech_synthesizer_.get() && utterance_id_ && paused_) {
[speech_synthesizer_ continueSpeaking];
paused_ = false;
TtsController::GetInstance()->OnTtsEvent(
utterance_id_, TTS_EVENT_RESUME, last_char_index_, "");
}
}
bool TtsPlatformImplMac::IsSpeaking() {
if (speech_synthesizer_)
return [speech_synthesizer_ isSpeaking];
return false;
}
void TtsPlatformImplMac::GetVoices(std::vector<VoiceData>* outVoices) {
NSArray* voices = [NSSpeechSynthesizer availableVoices];
// Create a new temporary array of the available voices with
// the default voice first.
NSMutableArray* orderedVoices =
[NSMutableArray arrayWithCapacity:[voices count]];
NSString* defaultVoice = [NSSpeechSynthesizer defaultVoice];
if (defaultVoice) {
[orderedVoices addObject:defaultVoice];
}
for (NSString* voiceIdentifier in voices) {
if (![voiceIdentifier isEqualToString:defaultVoice])
[orderedVoices addObject:voiceIdentifier];
}
for (NSString* voiceIdentifier in orderedVoices) {
outVoices->push_back(VoiceData());
VoiceData& data = outVoices->back();
NSDictionary* attributes =
[NSSpeechSynthesizer attributesForVoice:voiceIdentifier];
NSString* name = [attributes objectForKey:NSVoiceName];
NSString* gender = [attributes objectForKey:NSVoiceGender];
NSString* localeIdentifier =
[attributes objectForKey:NSVoiceLocaleIdentifier];
data.native = true;
data.native_voice_identifier = base::SysNSStringToUTF8(voiceIdentifier);
data.name = base::SysNSStringToUTF8(name);
NSDictionary* localeComponents =
[NSLocale componentsFromLocaleIdentifier:localeIdentifier];
NSString* language = [localeComponents objectForKey:NSLocaleLanguageCode];
NSString* country = [localeComponents objectForKey:NSLocaleCountryCode];
if (language && country) {
data.lang =
[[NSString stringWithFormat:@"%@-%@", language, country] UTF8String];
} else {
data.lang = base::SysNSStringToUTF8(language);
}
if ([gender isEqualToString:NSVoiceGenderMale])
data.gender = TTS_GENDER_MALE;
else if ([gender isEqualToString:NSVoiceGenderFemale])
data.gender = TTS_GENDER_FEMALE;
else
data.gender = TTS_GENDER_NONE;
data.events.insert(TTS_EVENT_START);
data.events.insert(TTS_EVENT_END);
data.events.insert(TTS_EVENT_WORD);
data.events.insert(TTS_EVENT_ERROR);
data.events.insert(TTS_EVENT_CANCELLED);
data.events.insert(TTS_EVENT_INTERRUPTED);
data.events.insert(TTS_EVENT_PAUSE);
data.events.insert(TTS_EVENT_RESUME);
}
}
void TtsPlatformImplMac::OnSpeechEvent(
NSSpeechSynthesizer* sender,
TtsEventType event_type,
int char_index,
const std::string& error_message) {
// Don't send events from an utterance that's already completed.
// This depends on the fact that we construct a new NSSpeechSynthesizer
// each time we call Speak.
if (sender != speech_synthesizer_.get())
return;
if (event_type == TTS_EVENT_END)
char_index = utterance_.size();
TtsController* controller = TtsController::GetInstance();
controller->OnTtsEvent(
utterance_id_, event_type, char_index, error_message);
last_char_index_ = char_index;
}
TtsPlatformImplMac::TtsPlatformImplMac() {
utterance_id_ = -1;
paused_ = false;
delegate_.reset([[ChromeTtsDelegate alloc] initWithPlatformImplMac:this]);
}
TtsPlatformImplMac::~TtsPlatformImplMac() {
}
// static
TtsPlatformImplMac* TtsPlatformImplMac::GetInstance() {
return Singleton<TtsPlatformImplMac>::get();
}
@implementation ChromeTtsDelegate
- (id)initWithPlatformImplMac:(TtsPlatformImplMac*)ttsImplMac {
if ((self = [super init])) {
ttsImplMac_ = ttsImplMac;
}
return self;
}
- (void)speechSynthesizer:(NSSpeechSynthesizer*)sender
didFinishSpeaking:(BOOL)finished_speaking {
ttsImplMac_->OnSpeechEvent(sender, TTS_EVENT_END, 0, "");
}
- (void)speechSynthesizer:(NSSpeechSynthesizer*)sender
willSpeakWord:(NSRange)character_range
ofString:(NSString*)string {
ttsImplMac_->OnSpeechEvent(sender, TTS_EVENT_WORD,
character_range.location, "");
}
- (void)speechSynthesizer:(NSSpeechSynthesizer*)sender
didEncounterErrorAtIndex:(NSUInteger)character_index
ofString:(NSString*)string
message:(NSString*)message {
std::string message_utf8 = base::SysNSStringToUTF8(message);
ttsImplMac_->OnSpeechEvent(sender, TTS_EVENT_ERROR, character_index,
message_utf8);
}
@end
@implementation SingleUseSpeechSynthesizer
- (id)initWithUtterance:(NSString*)utterance {
self = [super init];
if (self) {
utterance_.reset([utterance retain]);
didSpeak_ = false;
}
return self;
}
- (bool)startSpeakingRetainedUtterance {
CHECK(!didSpeak_);
CHECK(utterance_);
didSpeak_ = true;
return [super startSpeakingString:utterance_];
}
- (bool)startSpeakingString:(NSString*)utterance {
CHECK(false);
return false;
}
@end

View File

@@ -0,0 +1,176 @@
// 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/speech/tts_message_filter.h"
#include "base/bind.h"
#include "base/logging.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/render_process_host.h"
using content::BrowserThread;
TtsMessageFilter::TtsMessageFilter(int render_process_id,
content::BrowserContext* browser_context)
: BrowserMessageFilter(TtsMsgStart),
render_process_id_(render_process_id),
browser_context_(browser_context),
weak_ptr_factory_(this) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
TtsController::GetInstance()->AddVoicesChangedDelegate(this);
// Balanced in OnChannelClosingInUIThread() to keep the ref-count be non-zero
// until all WeakPtr's are invalidated.
AddRef();
}
void TtsMessageFilter::OverrideThreadForMessage(
const IPC::Message& message, BrowserThread::ID* thread) {
switch (message.type()) {
case TtsHostMsg_InitializeVoiceList::ID:
case TtsHostMsg_Speak::ID:
case TtsHostMsg_Pause::ID:
case TtsHostMsg_Resume::ID:
case TtsHostMsg_Cancel::ID:
*thread = BrowserThread::UI;
break;
}
}
bool TtsMessageFilter::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(TtsMessageFilter, message)
IPC_MESSAGE_HANDLER(TtsHostMsg_InitializeVoiceList, OnInitializeVoiceList)
IPC_MESSAGE_HANDLER(TtsHostMsg_Speak, OnSpeak)
IPC_MESSAGE_HANDLER(TtsHostMsg_Pause, OnPause)
IPC_MESSAGE_HANDLER(TtsHostMsg_Resume, OnResume)
IPC_MESSAGE_HANDLER(TtsHostMsg_Cancel, OnCancel)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void TtsMessageFilter::OnChannelClosing() {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&TtsMessageFilter::OnChannelClosingInUIThread, this));
}
void TtsMessageFilter::OnDestruct() const {
BrowserThread::DeleteOnUIThread::Destruct(this);
}
void TtsMessageFilter::OnInitializeVoiceList() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
TtsController* tts_controller = TtsController::GetInstance();
std::vector<VoiceData> voices;
tts_controller->GetVoices(browser_context_, &voices);
std::vector<TtsVoice> out_voices;
out_voices.resize(voices.size());
for (size_t i = 0; i < voices.size(); ++i) {
TtsVoice& out_voice = out_voices[i];
out_voice.voice_uri = voices[i].name;
out_voice.name = voices[i].name;
out_voice.lang = voices[i].lang;
out_voice.local_service = !voices[i].remote;
out_voice.is_default = (i == 0);
}
Send(new TtsMsg_SetVoiceList(out_voices));
}
void TtsMessageFilter::OnSpeak(const TtsUtteranceRequest& request) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
scoped_ptr<Utterance> utterance(new Utterance(browser_context_));
utterance->set_src_id(request.id);
utterance->set_text(request.text);
utterance->set_lang(request.lang);
utterance->set_voice_name(request.voice);
utterance->set_can_enqueue(true);
UtteranceContinuousParameters params;
params.rate = request.rate;
params.pitch = request.pitch;
params.volume = request.volume;
utterance->set_continuous_parameters(params);
utterance->set_event_delegate(weak_ptr_factory_.GetWeakPtr());
TtsController::GetInstance()->SpeakOrEnqueue(utterance.release());
}
void TtsMessageFilter::OnPause() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
TtsController::GetInstance()->Pause();
}
void TtsMessageFilter::OnResume() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
TtsController::GetInstance()->Resume();
}
void TtsMessageFilter::OnCancel() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
TtsController::GetInstance()->Stop();
}
void TtsMessageFilter::OnTtsEvent(Utterance* utterance,
TtsEventType event_type,
int char_index,
const std::string& error_message) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
switch (event_type) {
case TTS_EVENT_START:
Send(new TtsMsg_DidStartSpeaking(utterance->src_id()));
break;
case TTS_EVENT_END:
Send(new TtsMsg_DidFinishSpeaking(utterance->src_id()));
break;
case TTS_EVENT_WORD:
Send(new TtsMsg_WordBoundary(utterance->src_id(), char_index));
break;
case TTS_EVENT_SENTENCE:
Send(new TtsMsg_SentenceBoundary(utterance->src_id(), char_index));
break;
case TTS_EVENT_MARKER:
Send(new TtsMsg_MarkerEvent(utterance->src_id(), char_index));
break;
case TTS_EVENT_INTERRUPTED:
Send(new TtsMsg_WasInterrupted(utterance->src_id()));
break;
case TTS_EVENT_CANCELLED:
Send(new TtsMsg_WasCancelled(utterance->src_id()));
break;
case TTS_EVENT_ERROR:
Send(new TtsMsg_SpeakingErrorOccurred(
utterance->src_id(), error_message));
break;
case TTS_EVENT_PAUSE:
Send(new TtsMsg_DidPauseSpeaking(utterance->src_id()));
break;
case TTS_EVENT_RESUME:
Send(new TtsMsg_DidResumeSpeaking(utterance->src_id()));
break;
}
}
void TtsMessageFilter::OnVoicesChanged() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
OnInitializeVoiceList();
}
void TtsMessageFilter::OnChannelClosingInUIThread() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
TtsController::GetInstance()->RemoveVoicesChangedDelegate(this);
weak_ptr_factory_.InvalidateWeakPtrs();
Release(); // Balanced in TtsMessageFilter().
}
TtsMessageFilter::~TtsMessageFilter() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!weak_ptr_factory_.HasWeakPtrs());
TtsController::GetInstance()->RemoveVoicesChangedDelegate(this);
}

View File

@@ -0,0 +1,64 @@
// 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.
#ifndef CHROME_BROWSER_SPEECH_TTS_MESSAGE_FILTER_H_
#define CHROME_BROWSER_SPEECH_TTS_MESSAGE_FILTER_H_
#include "base/memory/weak_ptr.h"
#include "chrome/browser/speech/tts_controller.h"
#include "chrome/common/tts_messages.h"
#include "content/public/browser/browser_message_filter.h"
namespace content {
class BrowserContext;
}
class TtsMessageFilter
: public content::BrowserMessageFilter,
public UtteranceEventDelegate,
public VoicesChangedDelegate {
public:
explicit TtsMessageFilter(int render_process_id,
content::BrowserContext* browser_context);
// content::BrowserMessageFilter implementation.
virtual void OverrideThreadForMessage(
const IPC::Message& message,
content::BrowserThread::ID* thread) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void OnChannelClosing() OVERRIDE;
virtual void OnDestruct() const OVERRIDE;
// UtteranceEventDelegate implementation.
virtual void OnTtsEvent(Utterance* utterance,
TtsEventType event_type,
int char_index,
const std::string& error_message) OVERRIDE;
// VoicesChangedDelegate implementation.
virtual void OnVoicesChanged() OVERRIDE;
private:
friend class content::BrowserThread;
friend class base::DeleteHelper<TtsMessageFilter>;
virtual ~TtsMessageFilter();
void OnInitializeVoiceList();
void OnSpeak(const TtsUtteranceRequest& utterance);
void OnPause();
void OnResume();
void OnCancel();
void OnChannelClosingInUIThread();
int render_process_id_;
content::BrowserContext* browser_context_;
base::WeakPtrFactory<TtsMessageFilter> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(TtsMessageFilter);
};
#endif // CHROME_BROWSER_SPEECH_TTS_MESSAGE_FILTER_H_

View File

@@ -0,0 +1,28 @@
// Copyright (c) 2012 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/speech/tts_platform.h"
#include <string>
bool TtsPlatformImpl::LoadBuiltInTtsExtension(
content::BrowserContext* browser_context) {
return false;
}
std::string TtsPlatformImpl::error() {
return error_;
}
void TtsPlatformImpl::clear_error() {
error_ = std::string();
}
void TtsPlatformImpl::set_error(const std::string& error) {
error_ = error;
}
void TtsPlatformImpl::WillSpeakUtteranceWithVoice(const Utterance* utterance,
const VoiceData& voice_data) {
}

View File

@@ -0,0 +1,81 @@
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_SPEECH_TTS_PLATFORM_H_
#define CHROME_BROWSER_SPEECH_TTS_PLATFORM_H_
#include <string>
#include "chrome/browser/speech/tts_controller.h"
// Abstract class that defines the native platform TTS interface,
// subclassed by specific implementations on Win, Mac, etc.
class TtsPlatformImpl {
public:
static TtsPlatformImpl* GetInstance();
// Returns true if this platform implementation is supported and available.
virtual bool PlatformImplAvailable() = 0;
// Some platforms may provide a built-in TTS extension. Returns true
// if the extension was not previously loaded and is now loading, and
// false if it's already loaded or if there's no extension to load.
// Will call TtsController::RetrySpeakingQueuedUtterances when
// the extension finishes loading.
virtual bool LoadBuiltInTtsExtension(
content::BrowserContext* browser_context);
// Speak the given utterance with the given parameters if possible,
// and return true on success. Utterance will always be nonempty.
// If rate, pitch, or volume are -1.0, they will be ignored.
//
// The TtsController will only try to speak one utterance at
// a time. If it wants to interrupt speech, it will always call Stop
// before speaking again.
virtual bool Speak(
int utterance_id,
const std::string& utterance,
const std::string& lang,
const VoiceData& voice,
const UtteranceContinuousParameters& params) = 0;
// Stop speaking immediately and return true on success.
virtual bool StopSpeaking() = 0;
// Returns whether any speech is on going.
virtual bool IsSpeaking() = 0;
// Append information about voices provided by this platform implementation
// to |out_voices|.
virtual void GetVoices(std::vector<VoiceData>* out_voices) = 0;
// Pause the current utterance, if any, until a call to Resume,
// Speak, or StopSpeaking.
virtual void Pause() = 0;
// Resume speaking the current utterance, if it was paused.
virtual void Resume() = 0;
// Allows the platform to monitor speech commands and the voices used
// for each one.
virtual void WillSpeakUtteranceWithVoice(const Utterance* utterance,
const VoiceData& voice_data);
virtual std::string error();
virtual void clear_error();
virtual void set_error(const std::string& error);
protected:
TtsPlatformImpl() {}
// On some platforms this may be a leaky singleton - do not rely on the
// destructor being called! http://crbug.com/122026
virtual ~TtsPlatformImpl() {}
std::string error_;
DISALLOW_COPY_AND_ASSIGN(TtsPlatformImpl);
};
#endif // CHROME_BROWSER_SPEECH_TTS_PLATFORM_H_

View File

@@ -0,0 +1,257 @@
// Copyright (c) 2012 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 <math.h>
#include <sapi.h>
#include "base/memory/singleton.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "base/win/scoped_comptr.h"
#include "chrome/browser/speech/tts_controller.h"
#include "chrome/browser/speech/tts_platform.h"
class TtsPlatformImplWin : public TtsPlatformImpl {
public:
virtual bool PlatformImplAvailable() {
return true;
}
virtual bool Speak(
int utterance_id,
const std::string& utterance,
const std::string& lang,
const VoiceData& voice,
const UtteranceContinuousParameters& params);
virtual bool StopSpeaking();
virtual void Pause();
virtual void Resume();
virtual bool IsSpeaking();
virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE;
// Get the single instance of this class.
static TtsPlatformImplWin* GetInstance();
static void __stdcall SpeechEventCallback(WPARAM w_param, LPARAM l_param);
private:
TtsPlatformImplWin();
virtual ~TtsPlatformImplWin() {}
void OnSpeechEvent();
base::win::ScopedComPtr<ISpVoice> speech_synthesizer_;
// These apply to the current utterance only.
std::wstring utterance_;
int utterance_id_;
int prefix_len_;
ULONG stream_number_;
int char_position_;
bool paused_;
friend struct DefaultSingletonTraits<TtsPlatformImplWin>;
DISALLOW_COPY_AND_ASSIGN(TtsPlatformImplWin);
};
// static
TtsPlatformImpl* TtsPlatformImpl::GetInstance() {
return TtsPlatformImplWin::GetInstance();
}
bool TtsPlatformImplWin::Speak(
int utterance_id,
const std::string& src_utterance,
const std::string& lang,
const VoiceData& voice,
const UtteranceContinuousParameters& params) {
std::wstring prefix;
std::wstring suffix;
if (!speech_synthesizer_.get())
return false;
// TODO(dmazzoni): support languages other than the default: crbug.com/88059
if (params.rate >= 0.0) {
// Map our multiplicative range of 0.1x to 10.0x onto Microsoft's
// linear range of -10 to 10:
// 0.1 -> -10
// 1.0 -> 0
// 10.0 -> 10
speech_synthesizer_->SetRate(static_cast<int32>(10 * log10(params.rate)));
}
if (params.pitch >= 0.0) {
// The TTS api allows a range of -10 to 10 for speech pitch.
// TODO(dtseng): cleanup if we ever use any other properties that
// require xml.
std::wstring pitch_value =
base::IntToString16(static_cast<int>(params.pitch * 10 - 10));
prefix = L"<pitch absmiddle=\"" + pitch_value + L"\">";
suffix = L"</pitch>";
}
if (params.volume >= 0.0) {
// The TTS api allows a range of 0 to 100 for speech volume.
speech_synthesizer_->SetVolume(static_cast<uint16>(params.volume * 100));
}
// TODO(dmazzoni): convert SSML to SAPI xml. http://crbug.com/88072
utterance_ = base::UTF8ToWide(src_utterance);
utterance_id_ = utterance_id;
char_position_ = 0;
std::wstring merged_utterance = prefix + utterance_ + suffix;
prefix_len_ = prefix.size();
HRESULT result = speech_synthesizer_->Speak(
merged_utterance.c_str(),
SPF_ASYNC,
&stream_number_);
return (result == S_OK);
}
bool TtsPlatformImplWin::StopSpeaking() {
if (speech_synthesizer_.get()) {
// Clear the stream number so that any further events relating to this
// utterance are ignored.
stream_number_ = 0;
if (IsSpeaking()) {
// Stop speech by speaking the empty string with the purge flag.
speech_synthesizer_->Speak(L"", SPF_ASYNC | SPF_PURGEBEFORESPEAK, NULL);
}
if (paused_) {
speech_synthesizer_->Resume();
paused_ = false;
}
}
return true;
}
void TtsPlatformImplWin::Pause() {
if (speech_synthesizer_.get() && utterance_id_ && !paused_) {
speech_synthesizer_->Pause();
paused_ = true;
TtsController::GetInstance()->OnTtsEvent(
utterance_id_, TTS_EVENT_PAUSE, char_position_, "");
}
}
void TtsPlatformImplWin::Resume() {
if (speech_synthesizer_.get() && utterance_id_ && paused_) {
speech_synthesizer_->Resume();
paused_ = false;
TtsController::GetInstance()->OnTtsEvent(
utterance_id_, TTS_EVENT_RESUME, char_position_, "");
}
}
bool TtsPlatformImplWin::IsSpeaking() {
if (speech_synthesizer_.get()) {
SPVOICESTATUS status;
HRESULT result = speech_synthesizer_->GetStatus(&status, NULL);
if (result == S_OK) {
if (status.dwRunningState == 0 || // 0 == waiting to speak
status.dwRunningState == SPRS_IS_SPEAKING) {
return true;
}
}
}
return false;
}
void TtsPlatformImplWin::GetVoices(
std::vector<VoiceData>* out_voices) {
// TODO: get all voices, not just default voice.
// http://crbug.com/88059
out_voices->push_back(VoiceData());
VoiceData& voice = out_voices->back();
voice.native = true;
voice.name = "native";
voice.events.insert(TTS_EVENT_START);
voice.events.insert(TTS_EVENT_END);
voice.events.insert(TTS_EVENT_MARKER);
voice.events.insert(TTS_EVENT_WORD);
voice.events.insert(TTS_EVENT_SENTENCE);
voice.events.insert(TTS_EVENT_PAUSE);
voice.events.insert(TTS_EVENT_RESUME);
}
void TtsPlatformImplWin::OnSpeechEvent() {
TtsController* controller = TtsController::GetInstance();
SPEVENT event;
while (S_OK == speech_synthesizer_->GetEvents(1, &event, NULL)) {
if (event.ulStreamNum != stream_number_)
continue;
switch (event.eEventId) {
case SPEI_START_INPUT_STREAM:
controller->OnTtsEvent(
utterance_id_, TTS_EVENT_START, 0, std::string());
break;
case SPEI_END_INPUT_STREAM:
char_position_ = utterance_.size();
controller->OnTtsEvent(
utterance_id_, TTS_EVENT_END, char_position_, std::string());
break;
case SPEI_TTS_BOOKMARK:
controller->OnTtsEvent(
utterance_id_, TTS_EVENT_MARKER, char_position_, std::string());
break;
case SPEI_WORD_BOUNDARY:
char_position_ = static_cast<ULONG>(event.lParam) - prefix_len_;
controller->OnTtsEvent(
utterance_id_, TTS_EVENT_WORD, char_position_,
std::string());
break;
case SPEI_SENTENCE_BOUNDARY:
char_position_ = static_cast<ULONG>(event.lParam) - prefix_len_;
controller->OnTtsEvent(
utterance_id_, TTS_EVENT_SENTENCE, char_position_,
std::string());
break;
}
}
}
TtsPlatformImplWin::TtsPlatformImplWin()
: utterance_id_(0),
prefix_len_(0),
stream_number_(0),
char_position_(0),
paused_(false) {
speech_synthesizer_.CreateInstance(CLSID_SpVoice);
if (speech_synthesizer_.get()) {
ULONGLONG event_mask =
SPFEI(SPEI_START_INPUT_STREAM) |
SPFEI(SPEI_TTS_BOOKMARK) |
SPFEI(SPEI_WORD_BOUNDARY) |
SPFEI(SPEI_SENTENCE_BOUNDARY) |
SPFEI(SPEI_END_INPUT_STREAM);
speech_synthesizer_->SetInterest(event_mask, event_mask);
speech_synthesizer_->SetNotifyCallbackFunction(
TtsPlatformImplWin::SpeechEventCallback, 0, 0);
}
}
// static
TtsPlatformImplWin* TtsPlatformImplWin::GetInstance() {
return Singleton<TtsPlatformImplWin,
LeakySingletonTraits<TtsPlatformImplWin> >::get();
}
// static
void TtsPlatformImplWin::SpeechEventCallback(
WPARAM w_param, LPARAM l_param) {
GetInstance()->OnSpeechEvent();
}

View File

@@ -0,0 +1,69 @@
// 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.
// Multiply-included message file, hence no include guard.
#include <vector>
#include "chrome/common/tts_utterance_request.h"
#include "ipc/ipc_message_macros.h"
#include "ipc/ipc_param_traits.h"
#define IPC_MESSAGE_START TtsMsgStart
IPC_STRUCT_TRAITS_BEGIN(TtsUtteranceRequest)
IPC_STRUCT_TRAITS_MEMBER(id)
IPC_STRUCT_TRAITS_MEMBER(text)
IPC_STRUCT_TRAITS_MEMBER(lang)
IPC_STRUCT_TRAITS_MEMBER(voice)
IPC_STRUCT_TRAITS_MEMBER(volume)
IPC_STRUCT_TRAITS_MEMBER(rate)
IPC_STRUCT_TRAITS_MEMBER(pitch)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(TtsVoice)
IPC_STRUCT_TRAITS_MEMBER(voice_uri)
IPC_STRUCT_TRAITS_MEMBER(name)
IPC_STRUCT_TRAITS_MEMBER(lang)
IPC_STRUCT_TRAITS_MEMBER(local_service)
IPC_STRUCT_TRAITS_MEMBER(is_default)
IPC_STRUCT_TRAITS_END()
// Renderer -> Browser messages.
IPC_MESSAGE_CONTROL0(TtsHostMsg_InitializeVoiceList)
IPC_MESSAGE_CONTROL1(TtsHostMsg_Speak,
TtsUtteranceRequest)
IPC_MESSAGE_CONTROL0(TtsHostMsg_Pause)
IPC_MESSAGE_CONTROL0(TtsHostMsg_Resume)
IPC_MESSAGE_CONTROL0(TtsHostMsg_Cancel)
// Browser -> Renderer messages.
IPC_MESSAGE_CONTROL1(TtsMsg_SetVoiceList,
std::vector<TtsVoice>)
IPC_MESSAGE_CONTROL1(TtsMsg_DidStartSpeaking,
int /* utterance id */)
IPC_MESSAGE_CONTROL1(TtsMsg_DidFinishSpeaking,
int /* utterance id */)
IPC_MESSAGE_CONTROL1(TtsMsg_DidPauseSpeaking,
int /* utterance id */)
IPC_MESSAGE_CONTROL1(TtsMsg_DidResumeSpeaking,
int /* utterance id */)
IPC_MESSAGE_CONTROL2(TtsMsg_WordBoundary,
int /* utterance id */,
int /* char index */)
IPC_MESSAGE_CONTROL2(TtsMsg_SentenceBoundary,
int /* utterance id */,
int /* char index */)
IPC_MESSAGE_CONTROL2(TtsMsg_MarkerEvent,
int /* utterance id */,
int /* char index */)
IPC_MESSAGE_CONTROL1(TtsMsg_WasInterrupted,
int /* utterance id */)
IPC_MESSAGE_CONTROL1(TtsMsg_WasCancelled,
int /* utterance id */)
IPC_MESSAGE_CONTROL2(TtsMsg_SpeakingErrorOccurred,
int /* utterance id */,
std::string /* error message */)

View File

@@ -0,0 +1,30 @@
// 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/common/tts_utterance_request.h"
TtsUtteranceRequest::TtsUtteranceRequest()
: id(0),
volume(1.0),
rate(1.0),
pitch(1.0) {
}
TtsUtteranceRequest::~TtsUtteranceRequest() {
}
TtsVoice::TtsVoice()
: local_service(true),
is_default(false) {
}
TtsVoice::~TtsVoice() {
}
TtsUtteranceResponse::TtsUtteranceResponse()
: id(0) {
}
TtsUtteranceResponse::~TtsUtteranceResponse() {
}

View File

@@ -0,0 +1,44 @@
// 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.
#ifndef CHROME_COMMON_TTS_UTTERANCE_REQUEST_H_
#define CHROME_COMMON_TTS_UTTERANCE_REQUEST_H_
#include <vector>
#include "base/basictypes.h"
#include "base/strings/string16.h"
struct TtsUtteranceRequest {
TtsUtteranceRequest();
~TtsUtteranceRequest();
int id;
std::string text;
std::string lang;
std::string voice;
float volume;
float rate;
float pitch;
};
struct TtsVoice {
TtsVoice();
~TtsVoice();
std::string voice_uri;
std::string name;
std::string lang;
bool local_service;
bool is_default;
};
struct TtsUtteranceResponse {
TtsUtteranceResponse();
~TtsUtteranceResponse();
int id;
};
#endif // CHROME_COMMON_TTS_UTTERANCE_REQUEST_H_

View File

@@ -17,10 +17,10 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/common/print_messages.h"
#include "content/public/common/web_preferences.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_thread.h"
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/web_preferences.h"
#include "net/base/escape.h"
#include "printing/metafile.h"
#include "printing/metafile_impl.h"
@@ -42,7 +42,8 @@
#include "third_party/WebKit/public/web/WebView.h"
#include "third_party/WebKit/public/web/WebViewClient.h"
#include "ui/base/resource/resource_bundle.h"
#include "webkit/common/webpreferences.h"
using content::WebPreferences;
namespace printing {
@@ -547,7 +548,7 @@ void PrepareFrameAndViewForPrint::CopySelection(
blink::WebView* web_view = blink::WebView::create(this);
owns_web_view_ = true;
content::ApplyWebPreferences(prefs, web_view);
content::RenderView::ApplyWebPreferences(prefs, web_view);
web_view->setMainFrame(blink::WebLocalFrame::create(this));
frame_.Reset(web_view->mainFrame()->toWebLocalFrame());
node_to_print_.reset();

View File

@@ -0,0 +1,200 @@
// 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/renderer/tts_dispatcher.h"
#include "base/basictypes.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/common/tts_messages.h"
#include "chrome/common/tts_utterance_request.h"
#include "content/public/renderer/render_thread.h"
#include "third_party/WebKit/public/platform/WebCString.h"
#include "third_party/WebKit/public/platform/WebSpeechSynthesisUtterance.h"
#include "third_party/WebKit/public/platform/WebSpeechSynthesisVoice.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebVector.h"
using content::RenderThread;
using blink::WebSpeechSynthesizerClient;
using blink::WebSpeechSynthesisUtterance;
using blink::WebSpeechSynthesisVoice;
using blink::WebString;
using blink::WebVector;
int TtsDispatcher::next_utterance_id_ = 1;
TtsDispatcher::TtsDispatcher(WebSpeechSynthesizerClient* client)
: synthesizer_client_(client) {
RenderThread::Get()->AddObserver(this);
}
TtsDispatcher::~TtsDispatcher() {
RenderThread::Get()->RemoveObserver(this);
}
bool TtsDispatcher::OnControlMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(TtsDispatcher, message)
IPC_MESSAGE_HANDLER(TtsMsg_SetVoiceList, OnSetVoiceList)
IPC_MESSAGE_HANDLER(TtsMsg_DidStartSpeaking, OnDidStartSpeaking)
IPC_MESSAGE_HANDLER(TtsMsg_DidFinishSpeaking, OnDidFinishSpeaking)
IPC_MESSAGE_HANDLER(TtsMsg_DidPauseSpeaking, OnDidPauseSpeaking)
IPC_MESSAGE_HANDLER(TtsMsg_DidResumeSpeaking, OnDidResumeSpeaking)
IPC_MESSAGE_HANDLER(TtsMsg_WordBoundary, OnWordBoundary)
IPC_MESSAGE_HANDLER(TtsMsg_SentenceBoundary, OnSentenceBoundary)
IPC_MESSAGE_HANDLER(TtsMsg_MarkerEvent, OnMarkerEvent)
IPC_MESSAGE_HANDLER(TtsMsg_WasInterrupted, OnWasInterrupted)
IPC_MESSAGE_HANDLER(TtsMsg_WasCancelled, OnWasCancelled)
IPC_MESSAGE_HANDLER(TtsMsg_SpeakingErrorOccurred, OnSpeakingErrorOccurred)
IPC_END_MESSAGE_MAP()
// Always return false because there may be multiple TtsDispatchers
// and we want them all to have a chance to handle this message.
return false;
}
void TtsDispatcher::updateVoiceList() {
RenderThread::Get()->Send(new TtsHostMsg_InitializeVoiceList());
}
void TtsDispatcher::speak(const WebSpeechSynthesisUtterance& web_utterance) {
int id = next_utterance_id_++;
utterance_id_map_[id] = web_utterance;
TtsUtteranceRequest utterance;
utterance.id = id;
utterance.text = web_utterance.text().utf8();
utterance.lang = web_utterance.lang().utf8();
utterance.voice = web_utterance.voice().utf8();
utterance.volume = web_utterance.volume();
utterance.rate = web_utterance.rate();
utterance.pitch = web_utterance.pitch();
RenderThread::Get()->Send(new TtsHostMsg_Speak(utterance));
}
void TtsDispatcher::pause() {
RenderThread::Get()->Send(new TtsHostMsg_Pause());
}
void TtsDispatcher::resume() {
RenderThread::Get()->Send(new TtsHostMsg_Resume());
}
void TtsDispatcher::cancel() {
RenderThread::Get()->Send(new TtsHostMsg_Cancel());
}
WebSpeechSynthesisUtterance TtsDispatcher::FindUtterance(int utterance_id) {
base::hash_map<int, WebSpeechSynthesisUtterance>::const_iterator iter =
utterance_id_map_.find(utterance_id);
if (iter == utterance_id_map_.end())
return WebSpeechSynthesisUtterance();
return iter->second;
}
void TtsDispatcher::OnSetVoiceList(const std::vector<TtsVoice>& voices) {
WebVector<WebSpeechSynthesisVoice> out_voices(voices.size());
for (size_t i = 0; i < voices.size(); ++i) {
out_voices[i] = WebSpeechSynthesisVoice();
out_voices[i].setVoiceURI(WebString::fromUTF8(voices[i].voice_uri));
out_voices[i].setName(WebString::fromUTF8(voices[i].name));
out_voices[i].setLanguage(WebString::fromUTF8(voices[i].lang));
out_voices[i].setIsLocalService(voices[i].local_service);
out_voices[i].setIsDefault(voices[i].is_default);
}
synthesizer_client_->setVoiceList(out_voices);
}
void TtsDispatcher::OnDidStartSpeaking(int utterance_id) {
if (utterance_id_map_.find(utterance_id) == utterance_id_map_.end())
return;
WebSpeechSynthesisUtterance utterance = FindUtterance(utterance_id);
if (utterance.isNull())
return;
synthesizer_client_->didStartSpeaking(utterance);
}
void TtsDispatcher::OnDidFinishSpeaking(int utterance_id) {
WebSpeechSynthesisUtterance utterance = FindUtterance(utterance_id);
if (utterance.isNull())
return;
synthesizer_client_->didFinishSpeaking(utterance);
utterance_id_map_.erase(utterance_id);
}
void TtsDispatcher::OnDidPauseSpeaking(int utterance_id) {
WebSpeechSynthesisUtterance utterance = FindUtterance(utterance_id);
if (utterance.isNull())
return;
synthesizer_client_->didPauseSpeaking(utterance);
}
void TtsDispatcher::OnDidResumeSpeaking(int utterance_id) {
WebSpeechSynthesisUtterance utterance = FindUtterance(utterance_id);
if (utterance.isNull())
return;
synthesizer_client_->didResumeSpeaking(utterance);
}
void TtsDispatcher::OnWordBoundary(int utterance_id, int char_index) {
CHECK(char_index >= 0);
WebSpeechSynthesisUtterance utterance = FindUtterance(utterance_id);
if (utterance.isNull())
return;
synthesizer_client_->wordBoundaryEventOccurred(
utterance, static_cast<unsigned>(char_index));
}
void TtsDispatcher::OnSentenceBoundary(int utterance_id, int char_index) {
CHECK(char_index >= 0);
WebSpeechSynthesisUtterance utterance = FindUtterance(utterance_id);
if (utterance.isNull())
return;
synthesizer_client_->sentenceBoundaryEventOccurred(
utterance, static_cast<unsigned>(char_index));
}
void TtsDispatcher::OnMarkerEvent(int utterance_id, int char_index) {
// Not supported yet.
}
void TtsDispatcher::OnWasInterrupted(int utterance_id) {
WebSpeechSynthesisUtterance utterance = FindUtterance(utterance_id);
if (utterance.isNull())
return;
// The web speech API doesn't support "interrupted".
synthesizer_client_->didFinishSpeaking(utterance);
utterance_id_map_.erase(utterance_id);
}
void TtsDispatcher::OnWasCancelled(int utterance_id) {
WebSpeechSynthesisUtterance utterance = FindUtterance(utterance_id);
if (utterance.isNull())
return;
// The web speech API doesn't support "cancelled".
synthesizer_client_->didFinishSpeaking(utterance);
utterance_id_map_.erase(utterance_id);
}
void TtsDispatcher::OnSpeakingErrorOccurred(int utterance_id,
const std::string& error_message) {
WebSpeechSynthesisUtterance utterance = FindUtterance(utterance_id);
if (utterance.isNull())
return;
// The web speech API doesn't support an error message.
synthesizer_client_->speakingErrorOccurred(utterance);
utterance_id_map_.erase(utterance_id);
}

View File

@@ -0,0 +1,78 @@
// 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.
#ifndef CHROME_RENDERER_TTS_DISPATCHER_H_
#define CHROME_RENDERER_TTS_DISPATCHER_H_
#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/containers/hash_tables.h"
#include "content/public/renderer/render_process_observer.h"
#include "third_party/WebKit/public/platform/WebSpeechSynthesizer.h"
#include "third_party/WebKit/public/platform/WebSpeechSynthesizerClient.h"
namespace IPC {
class Message;
}
struct TtsVoice;
// TtsDispatcher is a delegate for methods used by Blink for speech synthesis
// APIs. It's the complement of TtsDispatcherHost (owned by RenderViewHost).
// Each TtsDispatcher is owned by the WebSpeechSynthesizerClient in Blink;
// it registers itself to listen to IPC upon construction and unregisters
// itself when deleted. There can be multiple TtsDispatchers alive at once,
// so each one routes IPC messages to its WebSpeechSynthesizerClient only if
// the utterance id (which is globally unique) matches.
class TtsDispatcher
: public blink::WebSpeechSynthesizer,
public content::RenderProcessObserver {
public:
explicit TtsDispatcher(blink::WebSpeechSynthesizerClient* client);
private:
virtual ~TtsDispatcher();
// RenderProcessObserver override.
virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
// blink::WebSpeechSynthesizer implementation.
virtual void updateVoiceList() OVERRIDE;
virtual void speak(const blink::WebSpeechSynthesisUtterance& utterance)
OVERRIDE;
virtual void pause() OVERRIDE;
virtual void resume() OVERRIDE;
virtual void cancel() OVERRIDE;
blink::WebSpeechSynthesisUtterance FindUtterance(int utterance_id);
void OnSetVoiceList(const std::vector<TtsVoice>& voices);
void OnDidStartSpeaking(int utterance_id);
void OnDidFinishSpeaking(int utterance_id);
void OnDidPauseSpeaking(int utterance_id);
void OnDidResumeSpeaking(int utterance_id);
void OnWordBoundary(int utterance_id, int char_index);
void OnSentenceBoundary(int utterance_id, int char_index);
void OnMarkerEvent(int utterance_id, int char_index);
void OnWasInterrupted(int utterance_id);
void OnWasCancelled(int utterance_id);
void OnSpeakingErrorOccurred(int utterance_id,
const std::string& error_message);
// The WebKit client class that we use to send events back to the JS world.
// Weak reference, this will be valid as long as this object exists.
blink::WebSpeechSynthesizerClient* synthesizer_client_;
// Next utterance id, used to map response IPCs to utterance objects.
static int next_utterance_id_;
// Map from id to utterance objects.
base::hash_map<int, blink::WebSpeechSynthesisUtterance> utterance_id_map_;
DISALLOW_COPY_AND_ASSIGN(TtsDispatcher);
};
#endif // CHROME_RENDERER_TTS_DISPATCHER_H_

View File

@@ -0,0 +1,231 @@
// This is generated file. Do not modify directly.
// Path to the code generator: tools/generate_library_loader/generate_library_loader.py .
#include "library_loaders/libspeechd.h"
#include <dlfcn.h>
// Put these sanity checks here so that they fire at most once
// (to avoid cluttering the build output).
#if !defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN) && !defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
#error neither LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN nor LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED defined
#endif
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN) && defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
#error both LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN and LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED defined
#endif
LibSpeechdLoader::LibSpeechdLoader() : loaded_(false) {
}
LibSpeechdLoader::~LibSpeechdLoader() {
CleanUp(loaded_);
}
bool LibSpeechdLoader::Load(const std::string& library_name) {
if (loaded_)
return false;
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
library_ = dlopen(library_name.c_str(), RTLD_LAZY);
if (!library_)
return false;
#endif
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
spd_open =
reinterpret_cast<typeof(this->spd_open)>(
dlsym(library_, "spd_open"));
#endif
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
spd_open = &::spd_open;
#endif
if (!spd_open) {
CleanUp(true);
return false;
}
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
spd_say =
reinterpret_cast<typeof(this->spd_say)>(
dlsym(library_, "spd_say"));
#endif
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
spd_say = &::spd_say;
#endif
if (!spd_say) {
CleanUp(true);
return false;
}
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
spd_stop =
reinterpret_cast<typeof(this->spd_stop)>(
dlsym(library_, "spd_stop"));
#endif
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
spd_stop = &::spd_stop;
#endif
if (!spd_stop) {
CleanUp(true);
return false;
}
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
spd_close =
reinterpret_cast<typeof(this->spd_close)>(
dlsym(library_, "spd_close"));
#endif
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
spd_close = &::spd_close;
#endif
if (!spd_close) {
CleanUp(true);
return false;
}
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
spd_pause =
reinterpret_cast<typeof(this->spd_pause)>(
dlsym(library_, "spd_pause"));
#endif
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
spd_pause = &::spd_pause;
#endif
if (!spd_pause) {
CleanUp(true);
return false;
}
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
spd_resume =
reinterpret_cast<typeof(this->spd_resume)>(
dlsym(library_, "spd_resume"));
#endif
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
spd_resume = &::spd_resume;
#endif
if (!spd_resume) {
CleanUp(true);
return false;
}
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
spd_set_notification_on =
reinterpret_cast<typeof(this->spd_set_notification_on)>(
dlsym(library_, "spd_set_notification_on"));
#endif
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
spd_set_notification_on = &::spd_set_notification_on;
#endif
if (!spd_set_notification_on) {
CleanUp(true);
return false;
}
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
spd_set_voice_rate =
reinterpret_cast<typeof(this->spd_set_voice_rate)>(
dlsym(library_, "spd_set_voice_rate"));
#endif
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
spd_set_voice_rate = &::spd_set_voice_rate;
#endif
if (!spd_set_voice_rate) {
CleanUp(true);
return false;
}
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
spd_set_voice_pitch =
reinterpret_cast<typeof(this->spd_set_voice_pitch)>(
dlsym(library_, "spd_set_voice_pitch"));
#endif
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
spd_set_voice_pitch = &::spd_set_voice_pitch;
#endif
if (!spd_set_voice_pitch) {
CleanUp(true);
return false;
}
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
spd_list_synthesis_voices =
reinterpret_cast<typeof(this->spd_list_synthesis_voices)>(
dlsym(library_, "spd_list_synthesis_voices"));
#endif
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
spd_list_synthesis_voices = &::spd_list_synthesis_voices;
#endif
if (!spd_list_synthesis_voices) {
CleanUp(true);
return false;
}
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
spd_set_synthesis_voice =
reinterpret_cast<typeof(this->spd_set_synthesis_voice)>(
dlsym(library_, "spd_set_synthesis_voice"));
#endif
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
spd_set_synthesis_voice = &::spd_set_synthesis_voice;
#endif
if (!spd_set_synthesis_voice) {
CleanUp(true);
return false;
}
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
spd_list_modules =
reinterpret_cast<typeof(this->spd_list_modules)>(
dlsym(library_, "spd_list_modules"));
#endif
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
spd_list_modules = &::spd_list_modules;
#endif
if (!spd_list_modules) {
CleanUp(true);
return false;
}
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
spd_set_output_module =
reinterpret_cast<typeof(this->spd_set_output_module)>(
dlsym(library_, "spd_set_output_module"));
#endif
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
spd_set_output_module = &::spd_set_output_module;
#endif
if (!spd_set_output_module) {
CleanUp(true);
return false;
}
loaded_ = true;
return true;
}
void LibSpeechdLoader::CleanUp(bool unload) {
#if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
if (unload) {
dlclose(library_);
library_ = NULL;
}
#endif
loaded_ = false;
spd_open = NULL;
spd_say = NULL;
spd_stop = NULL;
spd_close = NULL;
spd_pause = NULL;
spd_resume = NULL;
spd_set_notification_on = NULL;
spd_set_voice_rate = NULL;
spd_set_voice_pitch = NULL;
spd_list_synthesis_voices = NULL;
spd_set_synthesis_voice = NULL;
spd_list_modules = NULL;
spd_set_output_module = NULL;
}

View File

@@ -5,4 +5,5 @@ upstream node:
* `process.type` String - Process's type, can be `browser` or `renderer`.
* `process.versions['atom-shell']` String - Version of atom-shell.
* `process.versions['chrome']` String - Version of Chromium.
* `process.resourcesPath` String - Path to JavaScript source codes.

View File

@@ -30,10 +30,10 @@ your distribution that should be delivered to final users.
## Packaging your app into a file
Apart from shipping your app by copying all its sources files, you can also
package your app into [asar](https://github.com/atom/asar) archive to avoid
package your app into an [asar](https://github.com/atom/asar) archive to avoid
exposing your app's source code to users.
To use the `asar` archive to replace the `app` folder, you need to rename the
To use an `asar` archive to replace the `app` folder, you need to rename the
archive to `app.asar`, and put it under atom-shell's resources directory,
atom-shell will then try read the archive and start from it.

View File

@@ -1,18 +1,18 @@
# Application packaging
To protect your app's resources and source code from the users, you can choose
to package your app into [asar][asar] archive with little changes to your source
code.
to package your app into an [asar][asar] archive with little changes to your
source code.
## Generating `asar` archive
The [asar][asar] archive is a simple tar-like format that concatenates files
An [asar][asar] archive is a simple tar-like format that concatenates files
into a single file, atom-shell can read arbitrary file in it without unpacking
the whole file.
Following is the steps to package your app into `asar` archive:
Following is the steps to package your app into an `asar` archive:
### 1. Install asar utility
### 1. Install the asar utility
```bash
$ npm install -g asar
@@ -27,13 +27,13 @@ $ asar pack your-app app.asar
## Using `asar` archives
In atom-shell there are two sets of APIs: Node APIs provided by Node.js, and Web
APIs provided by Chromium. Both APIs support reading file from `asar` archives.
APIs provided by Chromium. Both APIs support reading files from `asar` archives.
### Node API
With special patches in atom-shell, Node APIs like `fs.readFile` and `require`
treat `asar` archives as virtual directories, and the files in it as normal
files in filesystem.
files in the filesystem.
For example, suppose we have an `example.asar` archive under `/path/to`:
@@ -47,14 +47,14 @@ $ asar list /path/to/example.asar
/static/jquery.min.js
```
Read a file in `asar` archive:
Read a file in the `asar` archive:
```javascript
var fs = require('fs');
fs.readFileSync('/path/to/example.asar/file.txt');
```
List all files under the root of archive:
List all files under the root of the archive:
```javascript
var fs = require('fs');
@@ -69,8 +69,8 @@ require('/path/to/example.asar/dir/module.js');
### Web API
In web page files in archive can be requests by using the `asar:` protocol,
like node API, `asar` archives are treated as directories.
In a web page, files in archive can be requested by using the `asar:` protocol.
Like the Node API, `asar` archives are treated as directories.
For example, to get a file with `$.get`:
@@ -84,10 +84,10 @@ $.get('asar:/path/to/example.asar/file.txt', function(data) {
```
The `asar:` protocol can also be used to request normal files in filesystem,
just like the `file:` protocol. But unlike `file:` protocol, there is no slashes
(`//`) after `asar:`.
just like the `file:` protocol. But unlike `file:` protocol, there are no
slashes (`//`) after `asar:`.
You can also display a web page in `asar` archive with `BrowserWindow`:
You can also display a web page in an `asar` archive with `BrowserWindow`:
```javascript
var BrowserWindow = require('browser-window');
@@ -97,19 +97,19 @@ win.loadUrl('asar:/path/to/example.asar/static/index.html');
## Limitations on Node API
Even though we tried hard to make `asar` archives in Node API work like
Even though we tried hard to make `asar` archives in the Node API work like
directories as much as possible, there are still limitations due to the
low-level nature of Node API.
low-level nature of the Node API.
### Archives are read only
The archives can not be modifies so all Node APIs that can modify files will not
The archives can not be modified so all Node APIs that can modify files will not
work with `asar` archives.
### Working directory can not be set to directories in archive
Though `asar` archives are treated as directories, there are no actual
directories in the filesystem, so you can never set working directory to
directories in the filesystem, so you can never set the working directory to
directories in `asar` archives, passing them to `cwd` option of some APIs will
also cause errors.
@@ -132,7 +132,7 @@ APIs that requires extra unpacking are:
### Fake stat information of `fs.stat`
The `Stats` object returned by `fs.stat` and its friends on files in `asar`
archives are generated by guessing, because those files do not exist on
archives is generated by guessing, because those files do not exist on the
filesystem. So you should not trust the `Stats` object except for getting file
size and checking file type.

View File

@@ -1,4 +1,4 @@
# Usng native Node modules
# Using native Node modules
The native Node modules are supported by atom-shell, but since atom-shell is
using a different V8 version from official Node, you need to use `apm` instead

View File

@@ -31,6 +31,7 @@
# files on non-linux.
['OS!="linux" and OS!="openbsd" and OS!="freebsd"', {
'sources/': [
['exclude', '(^|/)library_loaders/'],
['exclude', '_linux(_unittest)?\\.(h|cc)$'],
['exclude', '(^|/)linux_[^/]*\\.(h|cc)$'],
['exclude', '(^|/)linux/'],

View File

@@ -1,6 +1,6 @@
{
"name": "atom-shell",
"version": "0.17.0",
"version": "0.18.1",
"licenses": [
{
@@ -10,7 +10,7 @@
],
"devDependencies": {
"atom-package-manager": "0.98.0",
"atom-package-manager": "0.102.0",
"coffee-script": "~1.7.1",
"coffeelint": "~1.3.0"
},

View File

@@ -4,7 +4,7 @@ import platform
import sys
BASE_URL = 'https://gh-contractor-zcbenz.s3.amazonaws.com/libchromiumcontent'
LIBCHROMIUMCONTENT_COMMIT = 'ef6f735cf946570a89bd6269121e1cd0911da4ab'
LIBCHROMIUMCONTENT_COMMIT = '9f5271d31e0f32eac5a20ef6f543e3f1d43ad645'
ARCH = {
'cygwin': '32bit',

View File

@@ -19,8 +19,8 @@ describe 'ipc module', ->
assert.equal a.id, 1127
it 'should search module from the user app', ->
assert.equal remote.process.mainModule.filename, path.resolve(__dirname, 'static', 'main.js')
assert.equal remote.process.mainModule.paths[0], path.resolve(__dirname, 'static', 'node_modules')
assert.equal path.normalize(remote.process.mainModule.filename), path.resolve(__dirname, 'static', 'main.js')
assert.equal path.normalize(remote.process.mainModule.paths[0]), path.resolve(__dirname, 'static', 'node_modules')
describe 'remote.createFunctionWithReturnValue', ->
it 'should be called in browser synchronously', ->

View File

@@ -373,3 +373,22 @@ describe 'asar package', ->
error: (err) ->
assert.equal err.status, 404
done()
it 'sets __dirname correctly', (done) ->
url = require 'url'
remote = require 'remote'
ipc = remote.require 'ipc'
BrowserWindow = remote.require 'browser-window'
after ->
w.destroy()
ipc.removeAllListeners 'dirname'
w = new BrowserWindow(show: false, width: 400, height: 400)
p = path.resolve fixtures, 'asar', 'web.asar', 'index.html'
u = url.format protocol: 'asar', slashed: false, pathname: p
console.log u
w.loadUrl u
ipc.on 'dirname', (event, dirname) ->
assert.equal dirname, path.dirname(p)
done()

BIN
spec/fixtures/asar/web.asar vendored Normal file

Binary file not shown.

View File

@@ -22,7 +22,7 @@ describe 'third-party module', ->
it 'emits file events correctly', (done) ->
pathwatcher = require 'pathwatcher'
temp.mkdir 'dir', (err, dir) ->
assert err == null
return done() if err
file = path.join dir, 'file'
fs.writeFileSync file, 'content'
watcher = pathwatcher.watch file, (event) ->

2
vendor/node vendored