Compare commits

..

108 Commits

Author SHA1 Message Date
Cheng Zhao
9dd68c7add Bump v0.17.0. 2014-10-01 18:12:03 +08:00
Cheng Zhao
1499d44584 gtk: Fix focusing on file dialog
Fixes atom/atom#3626.
2014-10-01 17:02:00 +08:00
Cheng Zhao
039903c6b2 mac: Don't create button without title, fixes #631 2014-10-01 15:51:32 +08:00
Cheng Zhao
5df1716144 Upgrade brightray 2014-10-01 15:26:16 +08:00
Cheng Zhao
f6d6a12c1a win: uv_poll_get_timeout is removed 2014-09-30 23:27:36 +08:00
Cheng Zhao
e316e4a267 Upgrade node to v0.11.4, fixes #669 2014-09-30 23:14:25 +08:00
Cheng Zhao
9d84f139eb Merge pull request #665 from atom/asar
Support loading apps in asar format
2014-09-30 20:53:38 +08:00
Cheng Zhao
ad70cb27bd linux: Fix compilation warning 2014-09-30 20:52:57 +08:00
Cheng Zhao
98fec2f317 Still use 14 for node_module_version
We haven't broken abi yet, still use 14 to be compatible with previous
versions.
2014-09-30 20:49:34 +08:00
Cheng Zhao
72fc1e8dc6 Increase node_module_version, fixes #533 2014-09-30 20:32:14 +08:00
Cheng Zhao
301014e4a6 win: asar: Support "\" as path separator 2014-09-30 20:12:48 +08:00
Cheng Zhao
927ec6ab7a spec: asar: fs.realpath 2014-09-30 15:37:46 +08:00
Cheng Zhao
37d45e2881 spec: asar: fs.realpathSync 2014-09-30 15:17:48 +08:00
Cheng Zhao
915c1b19d3 asar: Fix fs.realpath on package's root 2014-09-30 15:09:50 +08:00
Cheng Zhao
b87dfb964c asar: Add support in fs.realpath 2014-09-30 14:57:49 +08:00
Cheng Zhao
885ac53a48 asar: Add support in fs.realpathSync 2014-09-30 14:53:58 +08:00
Cheng Zhao
d77bf0440c docs: Add usage on app packaging 2014-09-29 23:05:02 +08:00
Cheng Zhao
5a0be6672d docs: Add reference on app packaging 2014-09-29 21:34:54 +08:00
Cheng Zhao
724cae7de1 Merge pull request #670 from alexanderneu/master
win: Fix total value in SetProgressBar API.
2014-09-29 20:59:24 +08:00
Alexander Neu
6c9769999b win: Fix total value in SetProgressBar API. 2014-09-29 12:50:51 +02:00
Cheng Zhao
2bf2ad094c spec: asar: Testing getting file in web page 2014-09-29 16:58:54 +08:00
Cheng Zhao
3eaf0fe82b spec: asar: child_process.fork 2014-09-29 16:41:49 +08:00
Cheng Zhao
013e7fb611 spec: asar: fs.open 2014-09-29 16:29:10 +08:00
Cheng Zhao
e24976c59f Fix overriding async node API 2014-09-29 16:28:51 +08:00
Cheng Zhao
e3ae062c5c spec: asar: fs.open 2014-09-29 16:05:19 +08:00
Cheng Zhao
5e6e173d59 spec: asar: fs.readdir 2014-09-29 15:30:56 +08:00
Cheng Zhao
3fcd571db0 spec: asar: Test getting stats of root in fs.lstat 2014-09-29 15:25:28 +08:00
Cheng Zhao
988fa73696 spec: asar: fs.readdirSync 2014-09-29 15:24:01 +08:00
Cheng Zhao
3c412e1cb8 Fix readdir on a linked directory 2014-09-29 15:23:28 +08:00
Cheng Zhao
a579f58454 spec: asar: fs.lstat 2014-09-29 15:00:13 +08:00
Cheng Zhao
35e867820e Make sure fs.stat and fs.lstat are async 2014-09-29 14:59:44 +08:00
Cheng Zhao
a757c62da5 Use "null" instead of "undefined" as no error 2014-09-29 14:57:10 +08:00
Cheng Zhao
370dd26745 spec: asar: fs.lstatSync 2014-09-29 14:45:19 +08:00
Cheng Zhao
e20697b870 spec: asar: fs.readFile 2014-09-28 23:36:45 +08:00
Cheng Zhao
4d01aa2772 Fix shifting args in fs.readFile 2014-09-28 23:36:12 +08:00
Cheng Zhao
4a485f9819 spec: asar: fs.readFileSync 2014-09-28 23:02:14 +08:00
Cheng Zhao
cebafeae40 Fix getting file from symbol linked directory. 2014-09-28 22:46:29 +08:00
Cheng Zhao
150739e19e Fix calling fs.open in fs.readFile wrapper 2014-09-28 22:45:29 +08:00
Cheng Zhao
38f83cacf9 Make some APIs work with archive.copyFileOut API. 2014-09-25 23:25:17 +08:00
Cheng Zhao
fc8ff314e2 Make docs follow 80 columns rule. 2014-09-25 23:22:29 +08:00
Cheng Zhao
8acf96d268 Make spliting paths faster. 2014-09-25 22:18:40 +08:00
Cheng Zhao
c49a44f944 Remove unneeded ArchiveFactory. 2014-09-25 21:54:59 +08:00
Cheng Zhao
390b804ca0 Make process.dlopen work for asar packages. 2014-09-25 21:49:28 +08:00
Cheng Zhao
05317ad81e Clean cached asar archives when quitting. 2014-09-25 21:49:01 +08:00
Cheng Zhao
d559275711 Emit "exit" event for "process" when quitting. 2014-09-25 21:48:30 +08:00
Cheng Zhao
909ff085ac Add "quit" event for app. 2014-09-25 21:48:15 +08:00
Cheng Zhao
dbbfef38b1 Cache asar archives on JavaScript side. 2014-09-25 20:48:32 +08:00
Cheng Zhao
4006b6407c Just use plain pointer for weak reference. 2014-09-25 20:38:12 +08:00
Cheng Zhao
c95a93ef1c Add a way to copy a file in archive into filesystem. 2014-09-25 16:56:50 +08:00
Cheng Zhao
e5e1e207b6 Also search for app.asar when starting app. 2014-09-24 20:09:41 +08:00
Cheng Zhao
e0c469183d Make sure fs.readdir calls its callback asynchronously. 2014-09-24 19:10:37 +08:00
Cheng Zhao
4d2e4ed573 Fill the stats object as much as we can. 2014-09-24 19:10:13 +08:00
Cheng Zhao
0cab034dab Make fs.readdir support asar package. 2014-09-24 18:44:00 +08:00
Cheng Zhao
9f9d209e3d Make options of fs.readFile work. 2014-09-24 16:24:22 +08:00
Cheng Zhao
8740147aa2 Make fs.readFile support asar package 2014-09-24 15:38:07 +08:00
Cheng Zhao
9b755620d3 Make fs.stat support asar package 2014-09-24 15:38:02 +08:00
Cheng Zhao
fa287c2422 Fix getting information for root. 2014-09-24 13:42:04 +08:00
Cheng Zhao
b6cded379e Fix __dirname and __filename in asar: protocol. 2014-09-24 13:23:37 +08:00
Cheng Zhao
8199ad2ae6 Add asar.stat method. 2014-09-24 12:02:33 +08:00
Cheng Zhao
0d09143a77 Add JavaScript bindings of asar::Archive. 2014-09-24 11:10:07 +08:00
Cheng Zhao
7081f7799b Separate the archive cache out to ArchiveFactory. 2014-09-23 22:31:45 +08:00
Cheng Zhao
b6583635d4 Caching the Archive object. 2014-09-23 21:48:40 +08:00
Cheng Zhao
b01db4aa09 Send file content in asar:// 2014-09-23 20:30:07 +08:00
Cheng Zhao
6d712da7e3 Read the archive's header when there is a url request 2014-09-23 19:14:30 +08:00
Cheng Zhao
9b71117171 Add asar:// protocol handler. 2014-09-23 12:13:46 +08:00
Cheng Zhao
50ea0f0b45 Merge pull request #659 from hokein/master
mac: Fix dock progress bar doesn't show after hiding, fixes #658.
2014-09-22 20:52:32 +08:00
Haojian Wu
fa8e158587 mac: Fix dock progress bar doesn't show after hiding, fixes #658. 2014-09-21 18:56:03 +08:00
Cheng Zhao
2768b1ff64 Fix creating empty chromedriver archive. 2014-09-20 15:29:46 +00:00
Cheng Zhao
b3770bc407 Bump v0.16.3. 2014-09-20 23:12:05 +08:00
Cheng Zhao
8f44046f9a Fix chromedriver's version in archive. 2014-09-20 23:09:49 +08:00
Cheng Zhao
a717235212 Only include chromedriver in vX.X.0 releases. 2014-09-20 22:39:52 +08:00
Cheng Zhao
805215be78 Merge pull request #655 from hokein/master
SetProgressBar API Implementation, fixes #635
2014-09-20 11:19:34 +08:00
Haojian Wu
e7fbe84644 Use app name as desktop name by default. 2014-09-18 22:58:17 +08:00
Cheng Zhao
9653f20995 win: Add "direct-write" option for BrowserWindow.
For atom/atom#3540.
2014-09-18 21:49:04 +08:00
Haojian Wu
e959a40b49 docs: setProgressBar API. 2014-09-18 19:32:58 +08:00
Haojian Wu
d9ce3f0ca3 linux: Implement SetProgressBar API. 2014-09-18 19:26:52 +08:00
Haojian Wu
d8f57a0ecc Correct code style. 2014-09-18 16:48:00 +08:00
Haojian Wu
c5e0b65cc7 mac: Implement SetProgressBar API. 2014-09-18 10:20:55 +08:00
Haojian Wu
b5e82dac6f win: Implement SetProgressBar API. 2014-09-17 09:42:47 +08:00
Cheng Zhao
1381d16f9c Merge pull request #652 from atom/chromedriver
Ship chromedriver and add docs on how to use it
2014-09-16 17:45:39 +08:00
Cheng Zhao
268508764f docs: use => using 2014-09-13 00:16:32 +08:00
Cheng Zhao
34109fa741 docs: Document how to use chromedriver. 2014-09-13 00:07:21 +08:00
Cheng Zhao
925ff2da5b Pretend to be Chrome by default.
This is used to cheat client web drivers.
2014-09-12 23:28:14 +08:00
Cheng Zhao
b8a6658ba9 Make our user agent string follow standard. 2014-09-12 23:08:13 +08:00
Cheng Zhao
4a4814b41c default_app: Don't quit when started as web driver. 2014-09-12 22:54:00 +08:00
Cheng Zhao
f952dae0d0 Create dist for chromedriver and upload it. 2014-09-12 22:10:06 +08:00
Cheng Zhao
cba155bcfb Add action to copy chromedriver. 2014-09-12 21:48:45 +08:00
Cheng Zhao
0f714c81cd Merge pull request #644 from lusbuab/patch-1
Correct parameter type of setHightlightMode()
2014-09-10 10:30:42 +09:00
Cheng Zhao
92b5dab3f9 Merge pull request #642 from hokein/master
Add Volume keys support in global-shortcut API, fix #630.
2014-09-10 10:30:26 +09:00
Florian
6ca238852a Correct parameter type of setHightlightMode() 2014-09-09 15:04:00 +02:00
Haojian Wu
d2368d2d3b Add Volume keys support in global-shortcut API, fix #630. 2014-09-09 20:56:47 +08:00
Cheng Zhao
88269a613a Bump v0.16.2. 2014-09-09 20:07:08 +08:00
Cheng Zhao
5696fe8ec8 No need to set "--harmony" in renderer process.
After Chrome 37 renderer process can work correctly without it.
2014-09-09 20:05:43 +08:00
Cheng Zhao
ba439b6824 Merge pull request #643 from atom/mac-tray
Add some OS X only Tray APIs
2014-09-09 21:00:27 +09:00
Cheng Zhao
c8a8576970 docs: Document the new Tray APIs. 2014-09-09 19:50:50 +08:00
Cheng Zhao
67cbecaba0 mac: Add "double-clicked" event for Tray. 2014-09-09 19:45:21 +08:00
Cheng Zhao
ec1db0c7bb mac: Add Tray.setHighlightMode API, fixes #425. 2014-09-09 19:39:39 +08:00
Cheng Zhao
4330d67e0d mac: Add Tray.setTitle API, fixes #560. 2014-09-09 19:36:15 +08:00
Cheng Zhao
db8de9e60d Make default_app focus the main window on startup. 2014-09-09 18:33:36 +08:00
Cheng Zhao
9c9a306095 Upgrade brightray. 2014-09-09 18:33:22 +08:00
Cheng Zhao
bda317b000 views: Set devtools window's icon, fixes #429. 2014-09-09 15:30:33 +08:00
Cheng Zhao
700510d63a mac: Don't activate window when showing. 2014-09-09 14:47:04 +08:00
Cheng Zhao
ab2714fda9 Merge pull request #641 from atom/web-runtime-flags
Add options for web runtime features
2014-09-09 14:43:08 +08:00
Cheng Zhao
33b94edcf0 Use PersistentDictionary to store web perferences. 2014-09-09 14:13:21 +08:00
Cheng Zhao
44d3e58ddb Make code more tidy. 2014-09-09 13:21:15 +08:00
Cheng Zhao
f08c3f9134 docs: Add options for web runtime features. 2014-09-09 11:14:44 +08:00
Cheng Zhao
8de90db429 Pass web runtime features by command line. 2014-09-09 11:08:30 +08:00
Cheng Zhao
81241b38eb Add switches of web runtime flags. 2014-09-09 10:33:31 +08:00
74 changed files with 2398 additions and 126 deletions

View File

@@ -39,6 +39,7 @@
'atom/common/api/lib/screen.coffee',
'atom/common/api/lib/shell.coffee',
'atom/common/lib/init.coffee',
'atom/common/lib/asar.coffee',
'atom/renderer/lib/chrome-api.coffee',
'atom/renderer/lib/init.coffee',
'atom/renderer/lib/inspector.coffee',
@@ -121,6 +122,10 @@
'atom/browser/native_window_observer.h',
'atom/browser/net/adapter_request_job.cc',
'atom/browser/net/adapter_request_job.h',
'atom/browser/net/asar/asar_protocol_handler.cc',
'atom/browser/net/asar/asar_protocol_handler.h',
'atom/browser/net/asar/url_request_asar_job.cc',
'atom/browser/net/asar/url_request_asar_job.h',
'atom/browser/net/atom_url_request_job_factory.cc',
'atom/browser/net/atom_url_request_job_factory.h',
'atom/browser/net/url_request_string_job.cc',
@@ -174,6 +179,7 @@
'atom/browser/window_list.h',
'atom/browser/window_list_observer.h',
'atom/common/api/api_messages.h',
'atom/common/api/atom_api_asar.cc',
'atom/common/api/atom_api_clipboard.cc',
'atom/common/api/atom_api_crash_reporter.cc',
'atom/common/api/atom_api_id_weak_map.cc',
@@ -186,6 +192,10 @@
'atom/common/api/atom_bindings.h',
'atom/common/api/object_life_monitor.cc',
'atom/common/api/object_life_monitor.h',
'atom/common/asar/archive.cc',
'atom/common/asar/archive.h',
'atom/common/asar/scoped_temporary_file.cc',
'atom/common/asar/scoped_temporary_file.h',
'atom/common/common_message_generator.cc',
'atom/common/common_message_generator.h',
'atom/common/crash_reporter/crash_reporter.cc',
@@ -539,6 +549,7 @@
'vendor/breakpad/src',
],
'cflags': [
'-Wno-deprecated-declarations',
'-Wno-empty-body',
],
'dependencies': [
@@ -688,6 +699,36 @@
}], # OS=="linux"
],
}, # target <(project_name>_dump_symbols
{
'target_name': 'copy_chromedriver',
'type': 'none',
'actions': [
{
'action_name': 'Copy ChromeDriver Binary',
'variables': {
'conditions': [
['OS=="win"', {
'chromedriver_binary': 'chromedriver.exe',
},{
'chromedriver_binary': 'chromedriver',
}],
],
},
'inputs': [
'<(libchromiumcontent_library_dir)/<(chromedriver_binary)',
],
'outputs': [
'<(PRODUCT_DIR)/<(chromedriver_binary)',
],
'action': [
'python',
'tools/copy_binary.py',
'<@(_inputs)',
'<@(_outputs)',
],
}
],
}, # copy_chromedriver
],
'conditions': [
['OS=="mac"', {

View File

@@ -7,6 +7,8 @@
#include <string>
#include <vector>
#include "atom/common/chrome_version.h"
namespace atom {
AtomContentClient::AtomContentClient() {
@@ -15,6 +17,10 @@ AtomContentClient::AtomContentClient() {
AtomContentClient::~AtomContentClient() {
}
std::string AtomContentClient::GetProduct() const {
return "Chrome/" CHROME_VERSION_STRING;
}
void AtomContentClient::AddAdditionalSchemes(
std::vector<std::string>* standard_schemes,
std::vector<std::string>* savable_schemes) {

View File

@@ -19,6 +19,7 @@ class AtomContentClient : public brightray::ContentClient {
protected:
// content::ContentClient:
virtual std::string GetProduct() const OVERRIDE;
virtual void AddAdditionalSchemes(
std::vector<std::string>* standard_schemes,
std::vector<std::string>* savable_schemes) OVERRIDE;

View File

@@ -91,6 +91,10 @@ void App::OnWindowAllClosed() {
Emit("window-all-closed");
}
void App::OnQuit() {
Emit("quit");
}
void App::OnOpenFile(bool* prevent_default, const std::string& file_path) {
base::ListValue args;
args.AppendString(file_path);
@@ -134,6 +138,13 @@ void App::ResolveProxy(const GURL& url, ResolveProxyCallback callback) {
new ResolveProxyHelper(url, callback);
}
void App::SetDesktopName(const std::string& desktop_name) {
#if defined(OS_LINUX)
scoped_ptr<base::Environment> env(base::Environment::Create());
env->SetVar("CHROME_DESKTOP", desktop_name);
#endif
}
mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
Browser* browser = Browser::Get();
@@ -151,7 +162,8 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
.SetMethod("setName", base::Bind(&Browser::SetName,
base::Unretained(browser)))
.SetMethod("getDataPath", &App::GetDataPath)
.SetMethod("resolveProxy", &App::ResolveProxy);
.SetMethod("resolveProxy", &App::ResolveProxy)
.SetMethod("setDesktopName", &App::SetDesktopName);
}
// static

View File

@@ -36,6 +36,7 @@ class App : public mate::EventEmitter,
// BrowserObserver implementations:
virtual void OnWillQuit(bool* prevent_default) OVERRIDE;
virtual void OnWindowAllClosed() OVERRIDE;
virtual void OnQuit() OVERRIDE;
virtual void OnOpenFile(bool* prevent_default,
const std::string& file_path) OVERRIDE;
virtual void OnOpenURL(const std::string& url) OVERRIDE;
@@ -50,6 +51,7 @@ class App : public mate::EventEmitter,
private:
base::FilePath GetDataPath();
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
void SetDesktopName(const std::string& desktop_name);
DISALLOW_COPY_AND_ASSIGN(App);
};

View File

@@ -23,7 +23,7 @@ struct Converter<file_dialog::Filter> {
static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val,
file_dialog::Filter* out) {
mate::Dictionary dict(isolate);
mate::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
if (!dict.Get("name", &(out->first)))

View File

@@ -36,6 +36,10 @@ void Tray::OnClicked() {
Emit("clicked");
}
void Tray::OnDoubleClicked() {
Emit("double-clicked");
}
void Tray::SetImage(const gfx::ImageSkia& image) {
tray_icon_->SetImage(image);
}
@@ -48,6 +52,14 @@ void Tray::SetToolTip(const std::string& tool_tip) {
tray_icon_->SetToolTip(tool_tip);
}
void Tray::SetTitle(const std::string& title) {
tray_icon_->SetTitle(title);
}
void Tray::SetHighlightMode(bool highlight) {
tray_icon_->SetHighlightMode(highlight);
}
void Tray::SetContextMenu(Menu* menu) {
tray_icon_->SetContextMenu(menu->model());
}
@@ -59,6 +71,8 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
.SetMethod("setImage", &Tray::SetImage)
.SetMethod("setPressedImage", &Tray::SetPressedImage)
.SetMethod("setToolTip", &Tray::SetToolTip)
.SetMethod("setTitle", &Tray::SetTitle)
.SetMethod("setHighlightMode", &Tray::SetHighlightMode)
.SetMethod("_setContextMenu", &Tray::SetContextMenu);
}

View File

@@ -37,10 +37,13 @@ class Tray : public mate::EventEmitter,
// TrayIcon implementations:
virtual void OnClicked() OVERRIDE;
virtual void OnDoubleClicked() OVERRIDE;
void SetImage(const gfx::ImageSkia& image);
void SetPressedImage(const gfx::ImageSkia& image);
void SetToolTip(const std::string& tool_tip);
void SetTitle(const std::string& title);
void SetHighlightMode(bool highlight);
void SetContextMenu(Menu* menu);
private:

View File

@@ -366,6 +366,10 @@ void Window::Print(mate::Arguments* args) {
window_->Print(settings.silent, settings.print_backgournd);
}
void Window::SetProgressBar(double progress) {
window_->SetProgressBar(progress);
}
mate::Handle<WebContents> Window::GetWebContents(v8::Isolate* isolate) const {
return WebContents::Create(isolate, window_->GetWebContents());
}
@@ -428,6 +432,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
.SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
.SetMethod("capturePage", &Window::CapturePage)
.SetMethod("print", &Window::Print)
.SetMethod("setProgressBar", &Window::SetProgressBar)
.SetMethod("_getWebContents", &Window::GetWebContents)
.SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents);
}

View File

@@ -103,6 +103,7 @@ class Window : public mate::EventEmitter,
bool IsDocumentEdited();
void CapturePage(mate::Arguments* args);
void Print(mate::Arguments* args);
void SetProgressBar(double progress);
// APIs for WebContents.
mate::Handle<WebContents> GetWebContents(v8::Isolate* isolate) const;

View File

@@ -6,6 +6,7 @@
#include "atom/browser/atom_browser_main_parts.h"
#include "atom/browser/net/atom_url_request_job_factory.h"
#include "atom/browser/net/asar/asar_protocol_handler.h"
#include "base/threading/sequenced_worker_pool.h"
#include "base/threading/worker_pool.h"
#include "chrome/browser/browser_process.h"
@@ -20,6 +21,12 @@ using content::BrowserThread;
namespace atom {
namespace {
const char* kAsarScheme = "asar";
} // namespace
AtomBrowserContext::AtomBrowserContext()
: fake_browser_process_(new BrowserProcess),
job_factory_(new AtomURLRequestJobFactory) {
@@ -44,6 +51,10 @@ net::URLRequestJobFactory* AtomBrowserContext::CreateURLRequestJobFactory(
url::kFileScheme, new net::FileProtocolHandler(
BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
job_factory->SetProtocolHandler(
kAsarScheme, new asar::AsarProtocolHandler(
BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
// Set up interceptors in the reverse order.
scoped_ptr<net::URLRequestJobFactory> top_job_factory =

View File

@@ -37,6 +37,8 @@ void Browser::Quit() {
}
void Browser::Shutdown() {
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnQuit());
is_quiting_ = true;
base::MessageLoop::current()->Quit();
}

View File

@@ -18,6 +18,9 @@ class BrowserObserver {
// method will not be called, instead it will call OnWillQuit.
virtual void OnWindowAllClosed() {}
// The browser is quitting.
virtual void OnQuit() {}
// The browser has opened a file by double clicking in Finder or dragging the
// file to the Dock icon. (OS X only)
virtual void OnOpenFile(bool* prevent_default,

View File

@@ -21,6 +21,7 @@ app.on('ready', function() {
'use-content-size': true,
});
mainWindow.loadUrl('file://' + __dirname + '/index.html');
mainWindow.focus();
if (process.platform == 'darwin') {
var template = [

View File

@@ -11,11 +11,13 @@ app.on('window-all-closed', function() {
// Parse command line options.
var argv = process.argv.slice(1);
var option = { file: null, version: null };
var option = { file: null, version: null, webdriver: null };
for (var i in argv) {
if (argv[i] == '--version' || argv[i] == '-v') {
option.version = true;
break;
} else if (argv[i] == '--test-type=webdriver') {
option.webdriver = true;
} else if (argv[i][0] == '-') {
continue;
} else {
@@ -26,7 +28,7 @@ for (var i in argv) {
// Start the specified app if there is one specified in command line, otherwise
// start the default app.
if (option.file) {
if (option.file && !option.webdriver) {
try {
// Override app name and version.
var packagePath = path.resolve(option.file);

View File

@@ -52,20 +52,25 @@ setImmediate ->
detail: message
buttons: ['OK']
# Emit 'exit' event on quit.
require('app').on 'quit', ->
process.emit 'exit'
# Load the RPC server.
require './rpc-server.js'
# Now we try to load app's package.json.
packageJson = null
packagePath = path.join process.resourcesPath, 'app'
try
# First we try to load process.resourcesPath/app
packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json')))
catch error
# If not found then we load browser/default_app
packagePath = path.join process.resourcesPath, 'default_app'
packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json')))
searchPaths = [ 'app', 'app.asar', 'default_app' ]
for packagePath in searchPaths
try
packagePath = path.join process.resourcesPath, packagePath
packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json')))
catch e
continue
throw new Error("Unable to find a valid app") unless packageJson?
# Set application's version.
app = require 'app'
@@ -77,6 +82,12 @@ setImmediate ->
else if packageJson.name?
app.setName packageJson.name
# Set application's desktop name.
if packageJson.desktopName?
app.setDesktopName packageJson.desktopName
else
app.setDesktopName '#{app.getName()}.desktop'
# Load the chrome extension support.
require './chrome-extension.js'

View File

@@ -41,6 +41,7 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/renderer_preferences.h"
#include "content/public/common/user_agent.h"
#include "ipc/ipc_message_macros.h"
@@ -55,6 +56,28 @@ using content::NavigationEntry;
namespace atom {
namespace {
// Array of available web runtime features.
const char* kWebRuntimeFeatures[] = {
switches::kExperimentalFeatures,
switches::kExperimentalCanvasFeatures,
switches::kSubpixelFontScaling,
switches::kOverlayScrollbars,
switches::kOverlayFullscreenVideo,
switches::kSharedWorker,
};
std::string RemoveWhitespace(const std::string& str) {
std::string trimmed;
if (base::RemoveChars(str, " ", &trimmed))
return trimmed;
else
return str;
}
} // namespace
NativeWindow::NativeWindow(content::WebContents* web_contents,
const mate::Dictionary& options)
: content::WebContentsObserver(web_contents),
@@ -92,8 +115,8 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
// Override the user agent to contain application and atom-shell's version.
Browser* browser = Browser::Get();
std::string product_name = base::StringPrintf(
"%s/%s Chrome/%s Atom-Shell/" ATOM_VERSION_STRING,
browser->GetName().c_str(),
"%s/%s Chrome/%s AtomShell/" ATOM_VERSION_STRING,
RemoveWhitespace(browser->GetName()).c_str(),
browser->GetVersion().c_str(),
CHROME_VERSION_STRING);
web_contents->GetMutableRendererPrefs()->user_agent_override =
@@ -325,6 +348,24 @@ void NativeWindow::AppendExtraCommandLineSwitches(
if (zoom_factor_ != 1.0)
command_line->AppendSwitchASCII(switches::kZoomFactor,
base::DoubleToString(zoom_factor_));
if (web_preferences_.IsEmpty())
return;
bool b;
#if defined(OS_WIN)
// Check if DirectWrite is disabled.
if (web_preferences_.Get(switches::kDirectWrite, &b) && !b)
command_line->AppendSwitch(::switches::kDisableDirectWrite);
#endif
// This set of options are not availabe in WebPreferences, so we have to pass
// them via command line and enable them in renderer procss.
for (size_t i = 0; i < arraysize(kWebRuntimeFeatures); ++i) {
const char* feature = kWebRuntimeFeatures[i];
if (web_preferences_.Get(feature, &b))
command_line->AppendSwitchASCII(feature, b ? "true" : "false");
}
}
void NativeWindow::OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs) {
@@ -333,25 +374,23 @@ void NativeWindow::OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs) {
bool b;
std::vector<base::FilePath> list;
mate::Dictionary web_preferences(web_preferences_.isolate(),
web_preferences_.NewHandle());
if (web_preferences.Get("javascript", &b))
if (web_preferences_.Get("javascript", &b))
prefs->javascript_enabled = b;
if (web_preferences.Get("web-security", &b))
if (web_preferences_.Get("web-security", &b))
prefs->web_security_enabled = b;
if (web_preferences.Get("images", &b))
if (web_preferences_.Get("images", &b))
prefs->images_enabled = b;
if (web_preferences.Get("java", &b))
if (web_preferences_.Get("java", &b))
prefs->java_enabled = b;
if (web_preferences.Get("text-areas-are-resizable", &b))
if (web_preferences_.Get("text-areas-are-resizable", &b))
prefs->text_areas_are_resizable = b;
if (web_preferences.Get("webgl", &b))
if (web_preferences_.Get("webgl", &b))
prefs->experimental_webgl_enabled = b;
if (web_preferences.Get("webaudio", &b))
if (web_preferences_.Get("webaudio", &b))
prefs->webaudio_enabled = b;
if (web_preferences.Get("plugins", &b))
if (web_preferences_.Get("plugins", &b))
prefs->plugins_enabled = b;
if (web_preferences.Get("extra-plugin-dirs", &list))
if (web_preferences_.Get("extra-plugin-dirs", &list))
for (size_t i = 0; i < list.size(); ++i)
content::PluginService::GetInstance()->AddExtraPluginDir(list[i]);
}

View File

@@ -20,7 +20,7 @@
#include "brightray/browser/inspectable_web_contents_impl.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_observer.h"
#include "native_mate/scoped_persistent.h"
#include "native_mate/persistent_dictionary.h"
#include "ui/gfx/image/image_skia.h"
struct WebPreferences;
@@ -140,6 +140,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
virtual void SetMenu(ui::MenuModel* menu);
virtual bool HasModalDialog();
virtual gfx::NativeWindow GetNativeWindow() = 0;
virtual void SetProgressBar(double progress) = 0;
virtual bool IsClosed() const { return is_closed_; }
virtual void OpenDevTools();
@@ -298,7 +299,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
base::CancelableClosure window_unresposive_closure_;
// Web preferences.
mate::ScopedPersistent<v8::Object> web_preferences_;
mate::PersistentDictionary web_preferences_;
// Page's default zoom factor.
double zoom_factor_;

View File

@@ -65,6 +65,7 @@ class NativeWindowMac : public NativeWindow {
virtual bool IsDocumentEdited() OVERRIDE;
virtual bool HasModalDialog() OVERRIDE;
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
virtual void SetProgressBar(double progress) OVERRIDE;
// Returns true if |point| in local Cocoa coordinate system falls within
// the draggable region.

View File

@@ -193,6 +193,39 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
@end
@interface AtomProgressBar : NSProgressIndicator
@end
@implementation AtomProgressBar
- (void)drawRect:(NSRect)dirtyRect {
if (self.style != NSProgressIndicatorBarStyle)
return;
// Draw edges of rounded rect.
NSRect rect = NSInsetRect([self bounds], 1.0, 1.0);
CGFloat radius = rect.size.height / 2;
NSBezierPath* bezier_path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius];
[bezier_path setLineWidth:2.0];
[[NSColor grayColor] set];
[bezier_path stroke];
// Fill the rounded rect.
rect = NSInsetRect(rect, 2.0, 2.0);
radius = rect.size.height / 2;
bezier_path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius];
[bezier_path setLineWidth:1.0];
[bezier_path addClip];
// Calculate the progress width.
rect.size.width = floor(rect.size.width * ([self doubleValue] / [self maxValue]));
// Fill the progress bar with color blue.
[[NSColor colorWithSRGBRed:0.2 green:0.6 blue:1 alpha:1] set];
NSRectFill(rect);
}
@end
namespace atom {
NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
@@ -301,7 +334,7 @@ bool NativeWindowMac::IsFocused() {
}
void NativeWindowMac::Show() {
[window_ makeKeyAndOrderFront:nil];
[window_ orderFrontRegardless];
}
void NativeWindowMac::Hide() {
@@ -517,6 +550,42 @@ gfx::NativeWindow NativeWindowMac::GetNativeWindow() {
return window_;
}
void NativeWindowMac::SetProgressBar(double progress) {
NSDockTile* dock_tile = [NSApp dockTile];
// For the first time API invoked, we need to create a ContentView in DockTile.
if (dock_tile.contentView == NULL) {
NSImageView* image_view = [[NSImageView alloc] init];
[image_view setImage:[NSApp applicationIconImage]];
[dock_tile setContentView:image_view];
NSProgressIndicator* progress_indicator = [[AtomProgressBar alloc]
initWithFrame:NSMakeRect(0.0f, 0.0f, dock_tile.size.width, 15.0)];
[progress_indicator setStyle:NSProgressIndicatorBarStyle];
[progress_indicator setIndeterminate:NO];
[progress_indicator setBezeled:YES];
[progress_indicator setMinValue:0];
[progress_indicator setMaxValue:1];
[progress_indicator setHidden:NO];
[image_view addSubview:progress_indicator];
}
NSProgressIndicator* progress_indicator =
static_cast<NSProgressIndicator*>([[[dock_tile contentView] subviews]
objectAtIndex:0]);
if (progress < 0) {
[progress_indicator setHidden:YES];
} else if (progress > 1) {
[progress_indicator setHidden:NO];
[progress_indicator setIndeterminate:YES];
[progress_indicator setDoubleValue:1];
} else {
[progress_indicator setHidden:NO];
[progress_indicator setDoubleValue:progress];
}
[dock_tile display];
}
bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const {
if (!draggable_region_)
return false;

View File

@@ -43,7 +43,9 @@
#elif defined(OS_WIN)
#include "atom/browser/ui/views/win_frame_view.h"
#include "base/win/scoped_comptr.h"
#include "base/win/windows_version.h"
#include "ui/base/win/shell.h"
#include "ui/views/win/hwnd_util.h"
#endif
namespace atom {
@@ -479,6 +481,33 @@ gfx::NativeWindow NativeWindowViews::GetNativeWindow() {
return window_->GetNativeWindow();
}
void NativeWindowViews::SetProgressBar(double progress) {
#if defined(OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_WIN7)
return;
base::win::ScopedComPtr<ITaskbarList3> taskbar;
if (FAILED(taskbar.CreateInstance(CLSID_TaskbarList, NULL,
CLSCTX_INPROC_SERVER) ||
FAILED(taskbar->HrInit()))) {
return;
}
HWND frame = views::HWNDForNativeWindow(GetNativeWindow());
if (progress > 1.0) {
taskbar->SetProgressState(frame, TBPF_INDETERMINATE);
} else if (progress < 0) {
taskbar->SetProgressState(frame, TBPF_NOPROGRESS);
} else if (progress >= 0) {
taskbar->SetProgressValue(frame,
static_cast<int>(progress * 100),
100);
}
#elif defined(USE_X11)
if (unity::IsRunning()) {
unity::SetProgressFraction(progress);
}
#endif
}
gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() {
return GetNativeWindow()->GetHost()->GetAcceleratedWidget();
}
@@ -613,6 +642,10 @@ views::NonClientFrameView* NativeWindowViews::CreateNonClientFrameView(
return NULL;
}
gfx::ImageSkia NativeWindowViews::GetDevToolsWindowIcon() {
return GetWindowAppIcon();
}
void NativeWindowViews::HandleMouseDown() {
// Hide menu bar when web view is clicked.
if (menu_bar_autohide_ && menu_bar_visible_) {

View File

@@ -71,6 +71,7 @@ class NativeWindowViews : public NativeWindow,
virtual bool IsKiosk() OVERRIDE;
virtual void SetMenu(ui::MenuModel* menu_model) OVERRIDE;
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
virtual void SetProgressBar(double value) OVERRIDE;
gfx::AcceleratedWidget GetAcceleratedWidget();
@@ -105,6 +106,9 @@ class NativeWindowViews : public NativeWindow,
virtual views::NonClientFrameView* CreateNonClientFrameView(
views::Widget* widget) OVERRIDE;
// brightray::InspectableWebContentsDelegate:
virtual gfx::ImageSkia GetDevToolsWindowIcon() OVERRIDE;
// content::WebContentsDelegate:
virtual void HandleMouseDown() OVERRIDE;
virtual void HandleKeyboardEvent(

View File

@@ -0,0 +1,91 @@
// 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/net/asar/asar_protocol_handler.h"
#include "atom/browser/net/asar/url_request_asar_job.h"
#include "atom/common/asar/archive.h"
#include "net/base/filename_util.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_request_error_job.h"
#include "net/url_request/url_request_file_job.h"
namespace asar {
namespace {
const base::FilePath::CharType kAsarExtension[] = FILE_PATH_LITERAL(".asar");
// Get the relative path in asar archive.
bool GetAsarPath(const base::FilePath& full_path,
base::FilePath* asar_path,
base::FilePath* relative_path) {
base::FilePath iter = full_path;
while (true) {
base::FilePath dirname = iter.DirName();
if (iter.MatchesExtension(kAsarExtension))
break;
else if (iter == dirname)
return false;
iter = dirname;
}
base::FilePath tail;
if (!iter.AppendRelativePath(full_path, &tail))
return false;
*asar_path = iter;
*relative_path = tail;
return true;
}
} // namespace
AsarProtocolHandler::AsarProtocolHandler(
const scoped_refptr<base::TaskRunner>& file_task_runner)
: file_task_runner_(file_task_runner) {}
AsarProtocolHandler::~AsarProtocolHandler() {
}
Archive* AsarProtocolHandler::GetOrCreateAsarArchive(
const base::FilePath& path) const {
if (!archives_.contains(path)) {
scoped_ptr<Archive> archive(new Archive(path));
if (!archive->Init())
return nullptr;
archives_.set(path, archive.Pass());
}
return archives_.get(path);
}
net::URLRequestJob* AsarProtocolHandler::MaybeCreateJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const {
base::FilePath full_path;
net::FileURLToFilePath(request->url(), &full_path);
// Create asar:// job when the path contains "xxx.asar/", otherwise treat the
// URL request as file://.
base::FilePath asar_path, relative_path;
if (!GetAsarPath(full_path, &asar_path, &relative_path))
return new net::URLRequestFileJob(request, network_delegate, full_path,
file_task_runner_);
Archive* archive = GetOrCreateAsarArchive(asar_path);
if (!archive)
return new net::URLRequestErrorJob(request, network_delegate,
net::ERR_FILE_NOT_FOUND);
return new URLRequestAsarJob(request, network_delegate, archive,
relative_path, file_task_runner_);
}
bool AsarProtocolHandler::IsSafeRedirectTarget(const GURL& location) const {
return false;
}
} // namespace asar

View File

@@ -0,0 +1,45 @@
// 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_NET_ASAR_ASAR_PROTOCOL_HANDLER_H_
#define ATOM_BROWSER_NET_ASAR_ASAR_PROTOCOL_HANDLER_H_
#include "base/containers/scoped_ptr_hash_map.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "net/url_request/url_request_job_factory.h"
namespace base {
class TaskRunner;
}
namespace asar {
class Archive;
class AsarProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
public:
explicit AsarProtocolHandler(
const scoped_refptr<base::TaskRunner>& file_task_runner);
virtual ~AsarProtocolHandler();
Archive* GetOrCreateAsarArchive(const base::FilePath& path) const;
// net::URLRequestJobFactory::ProtocolHandler:
virtual net::URLRequestJob* MaybeCreateJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE;
virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE;
private:
const scoped_refptr<base::TaskRunner> file_task_runner_;
mutable base::ScopedPtrHashMap<base::FilePath, Archive> archives_;
DISALLOW_COPY_AND_ASSIGN(AsarProtocolHandler);
};
} // namespace asar
#endif // ATOM_BROWSER_NET_ASAR_ASAR_PROTOCOL_HANDLER_H_

View File

@@ -0,0 +1,142 @@
// 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/net/asar/url_request_asar_job.h"
#include <string>
#include "net/base/file_stream.h"
#include "net/base/io_buffer.h"
#include "net/base/mime_util.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_request_status.h"
namespace asar {
URLRequestAsarJob::URLRequestAsarJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate,
Archive* archive,
const base::FilePath& file_path,
const scoped_refptr<base::TaskRunner>& file_task_runner)
: net::URLRequestJob(request, network_delegate),
archive_(archive),
file_path_(file_path),
stream_(new net::FileStream(file_task_runner)),
remaining_bytes_(0),
file_task_runner_(file_task_runner),
weak_ptr_factory_(this) {}
URLRequestAsarJob::~URLRequestAsarJob() {}
void URLRequestAsarJob::Start() {
if (!archive_ || !archive_->GetFileInfo(file_path_, &file_info_)) {
NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED,
net::ERR_FILE_NOT_FOUND));
return;
}
remaining_bytes_ = static_cast<int64>(file_info_.size);
int flags = base::File::FLAG_OPEN |
base::File::FLAG_READ |
base::File::FLAG_ASYNC;
int rv = stream_->Open(archive_->path(), flags,
base::Bind(&URLRequestAsarJob::DidOpen,
weak_ptr_factory_.GetWeakPtr()));
if (rv != net::ERR_IO_PENDING)
DidOpen(rv);
}
void URLRequestAsarJob::Kill() {
weak_ptr_factory_.InvalidateWeakPtrs();
URLRequestJob::Kill();
}
bool URLRequestAsarJob::ReadRawData(net::IOBuffer* dest,
int dest_size,
int* bytes_read) {
if (remaining_bytes_ < dest_size)
dest_size = static_cast<int>(remaining_bytes_);
// If we should copy zero bytes because |remaining_bytes_| is zero, short
// circuit here.
if (!dest_size) {
*bytes_read = 0;
return true;
}
int rv = stream_->Read(dest,
dest_size,
base::Bind(&URLRequestAsarJob::DidRead,
weak_ptr_factory_.GetWeakPtr(),
make_scoped_refptr(dest)));
if (rv >= 0) {
// Data is immediately available.
*bytes_read = rv;
remaining_bytes_ -= rv;
DCHECK_GE(remaining_bytes_, 0);
return true;
}
// Otherwise, a read error occured. We may just need to wait...
if (rv == net::ERR_IO_PENDING) {
SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0));
} else {
NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, rv));
}
return false;
}
bool URLRequestAsarJob::GetMimeType(std::string* mime_type) const {
return net::GetMimeTypeFromFile(file_path_, mime_type);
}
void URLRequestAsarJob::DidOpen(int result) {
if (result != net::OK) {
NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, result));
return;
}
int rv = stream_->Seek(net::FROM_BEGIN,
file_info_.offset,
base::Bind(&URLRequestAsarJob::DidSeek,
weak_ptr_factory_.GetWeakPtr()));
if (rv != net::ERR_IO_PENDING) {
// stream_->Seek() failed, so pass an intentionally erroneous value
// into DidSeek().
DidSeek(-1);
}
}
void URLRequestAsarJob::DidSeek(int64 result) {
if (result != static_cast<int64>(file_info_.offset)) {
NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED,
net::ERR_REQUEST_RANGE_NOT_SATISFIABLE));
return;
}
set_expected_content_size(remaining_bytes_);
NotifyHeadersComplete();
}
void URLRequestAsarJob::DidRead(scoped_refptr<net::IOBuffer> buf, int result) {
if (result > 0) {
SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status
remaining_bytes_ -= result;
DCHECK_GE(remaining_bytes_, 0);
}
buf = NULL;
if (result == 0) {
NotifyDone(net::URLRequestStatus());
} else if (result < 0) {
NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, result));
}
NotifyReadComplete(result);
}
} // namespace asar

View File

@@ -0,0 +1,72 @@
// 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_NET_ASAR_URL_REQUEST_ASAR_JOB_H_
#define ATOM_BROWSER_NET_ASAR_URL_REQUEST_ASAR_JOB_H_
#include <string>
#include "atom/common/asar/archive.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "net/url_request/url_request_job.h"
namespace base {
class TaskRunner;
}
namespace net {
class FileStream;
}
namespace asar {
class URLRequestAsarJob : public net::URLRequestJob {
public:
URLRequestAsarJob(net::URLRequest* request,
net::NetworkDelegate* network_delegate,
Archive* archive,
const base::FilePath& file_path,
const scoped_refptr<base::TaskRunner>& file_task_runner);
// net::URLRequestJob:
virtual void Start() OVERRIDE;
virtual void Kill() OVERRIDE;
virtual bool ReadRawData(net::IOBuffer* buf,
int buf_size,
int* bytes_read) OVERRIDE;
virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
protected:
virtual ~URLRequestAsarJob();
private:
// Callback after opening file on a background thread.
void DidOpen(int result);
// Callback after seeking to the beginning of |byte_range_| in the file
// on a background thread.
void DidSeek(int64 result);
// Callback after data is asynchronously read from the file into |buf|.
void DidRead(scoped_refptr<net::IOBuffer> buf, int result);
Archive* archive_;
Archive::FileInfo file_info_;
base::FilePath file_path_;
scoped_ptr<net::FileStream> stream_;
int64 remaining_bytes_;
const scoped_refptr<base::TaskRunner> file_task_runner_;
base::WeakPtrFactory<URLRequestAsarJob> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(URLRequestAsarJob);
};
} // namespace asar
#endif // ATOM_BROWSER_NET_ASAR_URL_REQUEST_ASAR_JOB_H_

View File

@@ -17,7 +17,7 @@
<key>CFBundleIconFile</key>
<string>atom.icns</string>
<key>CFBundleVersion</key>
<string>0.16.1</string>
<string>0.17.0</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,16,1,0
PRODUCTVERSION 0,16,1,0
FILEVERSION 0,17,0,0
PRODUCTVERSION 0,17,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@@ -68,12 +68,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "GitHub, Inc."
VALUE "FileDescription", "Atom-Shell"
VALUE "FileVersion", "0.16.1"
VALUE "FileVersion", "0.17.0"
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.16.1"
VALUE "ProductVersion", "0.17.0"
VALUE "SquirrelAwareVersion", "1"
END
END

View File

@@ -21,6 +21,7 @@
#include "chrome/browser/ui/libgtk2ui/gtk2_signal.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/views/widget/desktop_aura/x11_desktop_handler.h"
namespace file_dialog {
@@ -114,6 +115,11 @@ class FileChooserDialog {
g_signal_connect(dialog_, "response",
G_CALLBACK(OnFileDialogResponseThunk), this);
gtk_widget_show_all(dialog_);
// We need to call gtk_window_present after making the widgets visible to
// make sure window gets correctly raised and gets focus.
int time = views::X11DesktopHandler::get()->wm_user_time_ms();
gtk_window_present_with_time(GTK_WINDOW(dialog_), time);
}
void RunSaveAsynchronous(const SaveDialogCallback& callback) {

View File

@@ -75,6 +75,9 @@ NSAlert* CreateNSAlert(NativeWindow* parent_window,
for (size_t i = 0; i < buttons.size(); ++i) {
NSString* title = base::SysUTF8ToNSString(buttons[i]);
// An empty title causes crash on OS X.
if (buttons[i].empty())
title = @"(empty)";
NSButton* button = [alert addButtonWithTitle:title];
[button setTag:i];
}

View File

@@ -12,8 +12,18 @@ TrayIcon::TrayIcon() {
TrayIcon::~TrayIcon() {
}
void TrayIcon::SetTitle(const std::string& title) {
}
void TrayIcon::SetHighlightMode(bool highlight) {
}
void TrayIcon::NotifyClicked() {
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked());
}
void TrayIcon::NotifyDoubleClicked() {
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDoubleClicked());
}
} // namespace atom

View File

@@ -31,12 +31,21 @@ class TrayIcon {
// status icon (e.g. Ubuntu Unity).
virtual void SetToolTip(const std::string& tool_tip) = 0;
// Sets the title displayed aside of the status icon in the status bar. This
// only works on OS X.
virtual void SetTitle(const std::string& title);
// Sets whether the status icon is highlighted when it is clicked. This only
// works on OS X.
virtual void SetHighlightMode(bool highlight);
// Set the context menu for this icon.
virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) = 0;
void AddObserver(TrayIconObserver* obs) { observers_.AddObserver(obs); }
void RemoveObserver(TrayIconObserver* obs) { observers_.RemoveObserver(obs); }
void NotifyClicked();
void NotifyDoubleClicked();
protected:
TrayIcon();

View File

@@ -25,6 +25,8 @@ class TrayIconCocoa : public TrayIcon {
virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE;
virtual void SetPressedImage(const gfx::ImageSkia& image) OVERRIDE;
virtual void SetToolTip(const std::string& tool_tip) OVERRIDE;
virtual void SetTitle(const std::string& title) OVERRIDE;
virtual void SetHighlightMode(bool highlight) OVERRIDE;
virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) OVERRIDE;
private:

View File

@@ -13,6 +13,7 @@
}
- (id)initWithIcon:(atom::TrayIconCocoa*)icon;
- (void)handleClick:(id)sender;
- (void)handleDoubleClick:(id)sender;
@end // @interface StatusItemController
@@ -24,10 +25,13 @@
}
- (void)handleClick:(id)sender {
DCHECK(trayIcon_);
trayIcon_->NotifyClicked();
}
- (void)handleDoubleClick:(id)sender {
trayIcon_->NotifyDoubleClicked();
}
@end
namespace atom {
@@ -40,6 +44,7 @@ TrayIconCocoa::TrayIconCocoa() {
[item_ setEnabled:YES];
[item_ setTarget:controller_];
[item_ setAction:@selector(handleClick:)];
[item_ setDoubleAction:@selector(handleDoubleClick:)];
[item_ setHighlightMode:YES];
}
@@ -68,6 +73,14 @@ void TrayIconCocoa::SetToolTip(const std::string& tool_tip) {
[item_ setToolTip:base::SysUTF8ToNSString(tool_tip)];
}
void TrayIconCocoa::SetTitle(const std::string& title) {
[item_ setTitle:base::SysUTF8ToNSString(title)];
}
void TrayIconCocoa::SetHighlightMode(bool highlight) {
[item_ setHighlightMode:highlight];
}
void TrayIconCocoa::SetContextMenu(ui::SimpleMenuModel* menu_model) {
menu_.reset([[AtomMenuController alloc] initWithModel:menu_model]);
[item_ setMenu:[menu_ menu]];

View File

@@ -10,6 +10,7 @@ namespace atom {
class TrayIconObserver {
public:
virtual void OnClicked() {}
virtual void OnDoubleClicked() {}
protected:
virtual ~TrayIconObserver() {}

View File

@@ -0,0 +1,117 @@
// 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 <vector>
#include "atom/common/asar/archive.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "native_mate/arguments.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "native_mate/wrappable.h"
#include "atom/common/node_includes.h"
namespace {
class Archive : public mate::Wrappable {
public:
static v8::Handle<v8::Value> Create(v8::Isolate* isolate,
const base::FilePath& path) {
scoped_ptr<asar::Archive> archive(new asar::Archive(path));
if (!archive->Init())
return v8::False(isolate);
return (new Archive(archive.Pass()))->GetWrapper(isolate);
}
protected:
explicit Archive(scoped_ptr<asar::Archive> archive)
: archive_(archive.Pass()) {}
// Reads the offset and size of file.
v8::Handle<v8::Value> GetFileInfo(v8::Isolate* isolate,
const base::FilePath& path) {
asar::Archive::FileInfo info;
if (!archive_ || !archive_->GetFileInfo(path, &info))
return v8::False(isolate);
mate::Dictionary dict(isolate, v8::Object::New(isolate));
dict.Set("size", info.size);
dict.Set("offset", info.offset);
return dict.GetHandle();
}
// Returns a fake result of fs.stat(path).
v8::Handle<v8::Value> Stat(v8::Isolate* isolate,
const base::FilePath& path) {
asar::Archive::Stats stats;
if (!archive_ || !archive_->Stat(path, &stats))
return v8::False(isolate);
mate::Dictionary dict(isolate, v8::Object::New(isolate));
dict.Set("size", stats.size);
dict.Set("offset", stats.offset);
dict.Set("isFile", stats.is_file);
dict.Set("isDirectory", stats.is_directory);
dict.Set("isLink", stats.is_link);
return dict.GetHandle();
}
// Returns all files under a directory.
v8::Handle<v8::Value> Readdir(v8::Isolate* isolate,
const base::FilePath& path) {
std::vector<base::FilePath> files;
if (!archive_ || !archive_->Readdir(path, &files))
return v8::False(isolate);
return mate::ConvertToV8(isolate, files);
}
// Returns the path of file with symbol link resolved.
v8::Handle<v8::Value> Realpath(v8::Isolate* isolate,
const base::FilePath& path) {
base::FilePath realpath;
if (!archive_ || !archive_->Realpath(path, &realpath))
return v8::False(isolate);
return mate::ConvertToV8(isolate, realpath);
}
// Copy the file out into a temporary file and returns the new path.
v8::Handle<v8::Value> CopyFileOut(v8::Isolate* isolate,
const base::FilePath& path) {
base::FilePath new_path;
if (!archive_ || !archive_->CopyFileOut(path, &new_path))
return v8::False(isolate);
return mate::ConvertToV8(isolate, new_path);
}
// Free the resources used by archive.
void Destroy() {
archive_.reset();
}
// mate::Wrappable:
mate::ObjectTemplateBuilder GetObjectTemplateBuilder(v8::Isolate* isolate) {
return mate::ObjectTemplateBuilder(isolate)
.SetValue("path", archive_->path())
.SetMethod("getFileInfo", &Archive::GetFileInfo)
.SetMethod("stat", &Archive::Stat)
.SetMethod("readdir", &Archive::Readdir)
.SetMethod("realpath", &Archive::Realpath)
.SetMethod("copyFileOut", &Archive::CopyFileOut)
.SetMethod("destroy", &Archive::Destroy);
}
private:
scoped_ptr<asar::Archive> archive_;
DISALLOW_COPY_AND_ASSIGN(Archive);
};
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
v8::Handle<v8::Context> context, void* priv) {
mate::Dictionary dict(context->GetIsolate(), exports);
dict.SetMethod("createArchive", &Archive::Create);
}
} // namespace
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_common_asar, Initialize)

252
atom/common/asar/archive.cc Normal file
View File

@@ -0,0 +1,252 @@
// 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/common/asar/archive.h"
#include <string>
#include <vector>
#include "atom/common/asar/scoped_temporary_file.h"
#include "base/files/file.h"
#include "base/logging.h"
#include "base/pickle.h"
#include "base/json/json_string_value_serializer.h"
#include "base/strings/string_number_conversions.h"
namespace asar {
namespace {
#if defined(OS_WIN)
const char kSeparators[] = "\\/";
#else
const char kSeparators[] = "/";
#endif
bool GetNodeFromPath(std::string path,
const base::DictionaryValue* root,
const base::DictionaryValue** out);
// Gets the "files" from "dir".
bool GetFilesNode(const base::DictionaryValue* root,
const base::DictionaryValue* dir,
const base::DictionaryValue** out) {
// Test for symbol linked directory.
std::string link;
if (dir->GetStringWithoutPathExpansion("link", &link)) {
const base::DictionaryValue* linked_node = NULL;
if (!GetNodeFromPath(link, root, &linked_node))
return false;
dir = linked_node;
}
return dir->GetDictionaryWithoutPathExpansion("files", out);
}
// Gets sub-file "name" from "dir".
bool GetChildNode(const base::DictionaryValue* root,
const std::string& name,
const base::DictionaryValue* dir,
const base::DictionaryValue** out) {
const base::DictionaryValue* files = NULL;
return GetFilesNode(root, dir, &files) &&
files->GetDictionaryWithoutPathExpansion(name, out);
}
// Gets the node of "path" from "root".
bool GetNodeFromPath(std::string path,
const base::DictionaryValue* root,
const base::DictionaryValue** out) {
if (path == "") {
*out = root;
return true;
}
const base::DictionaryValue* dir = root;
for (size_t delimiter_position = path.find_first_of(kSeparators);
delimiter_position != std::string::npos;
delimiter_position = path.find_first_of(kSeparators)) {
const base::DictionaryValue* child = NULL;
if (!GetChildNode(root, path.substr(0, delimiter_position), dir, &child))
return false;
dir = child;
path.erase(0, delimiter_position + 1);
}
return GetChildNode(root, path, dir, out);
}
bool FillFileInfoWithNode(Archive::FileInfo* info,
uint32 header_size,
const base::DictionaryValue* node) {
std::string offset;
if (!node->GetString("offset", &offset))
return false;
if (!base::StringToUint64(offset, &info->offset))
return false;
int size;
if (!node->GetInteger("size", &size))
return false;
info->offset += header_size;
info->size = static_cast<uint32>(size);
return true;
}
} // namespace
Archive::Archive(const base::FilePath& path)
: path_(path),
header_size_(0) {
}
Archive::~Archive() {
}
bool Archive::Init() {
base::File file(path_, base::File::FLAG_OPEN | base::File::FLAG_READ);
if (!file.IsValid())
return false;
std::vector<char> buf;
int len;
buf.resize(8);
len = file.ReadAtCurrentPos(buf.data(), buf.size());
if (len != static_cast<int>(buf.size())) {
PLOG(ERROR) << "Failed to read header size from " << path_.value();
return false;
}
uint32 size;
if (!PickleIterator(Pickle(buf.data(), buf.size())).ReadUInt32(&size)) {
LOG(ERROR) << "Failed to parse header size from " << path_.value();
return false;
}
buf.resize(size);
len = file.ReadAtCurrentPos(buf.data(), buf.size());
if (len != static_cast<int>(buf.size())) {
PLOG(ERROR) << "Failed to read header from " << path_.value();
return false;
}
std::string header;
if (!PickleIterator(Pickle(buf.data(), buf.size())).ReadString(&header)) {
LOG(ERROR) << "Failed to parse header from " << path_.value();
return false;
}
std::string error;
JSONStringValueSerializer serializer(&header);
base::Value* value = serializer.Deserialize(NULL, &error);
if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) {
LOG(ERROR) << "Failed to parse header: " << error;
return false;
}
header_size_ = 8 + size;
header_.reset(static_cast<base::DictionaryValue*>(value));
return true;
}
bool Archive::GetFileInfo(const base::FilePath& path, FileInfo* info) {
if (!header_)
return false;
const base::DictionaryValue* node;
if (!GetNodeFromPath(path.AsUTF8Unsafe(), header_.get(), &node))
return false;
std::string link;
if (node->GetString("link", &link))
return GetFileInfo(base::FilePath::FromUTF8Unsafe(link), info);
return FillFileInfoWithNode(info, header_size_, node);
}
bool Archive::Stat(const base::FilePath& path, Stats* stats) {
if (!header_)
return false;
const base::DictionaryValue* node;
if (!GetNodeFromPath(path.AsUTF8Unsafe(), header_.get(), &node))
return false;
if (node->HasKey("link")) {
stats->is_file = false;
stats->is_link = true;
return true;
}
if (node->HasKey("files")) {
stats->is_file = false;
stats->is_directory = true;
return true;
}
return FillFileInfoWithNode(stats, header_size_, node);
}
bool Archive::Readdir(const base::FilePath& path,
std::vector<base::FilePath>* list) {
if (!header_)
return false;
const base::DictionaryValue* node;
if (!GetNodeFromPath(path.AsUTF8Unsafe(), header_.get(), &node))
return false;
const base::DictionaryValue* files;
if (!GetFilesNode(header_.get(), node, &files))
return false;
base::DictionaryValue::Iterator iter(*files);
while (!iter.IsAtEnd()) {
list->push_back(base::FilePath::FromUTF8Unsafe(iter.key()));
iter.Advance();
}
return true;
}
bool Archive::Realpath(const base::FilePath& path, base::FilePath* realpath) {
if (!header_)
return false;
const base::DictionaryValue* node;
if (!GetNodeFromPath(path.AsUTF8Unsafe(), header_.get(), &node))
return false;
std::string link;
if (node->GetString("link", &link)) {
*realpath = base::FilePath::FromUTF8Unsafe(link);
return true;
}
*realpath = path;
return true;
}
bool Archive::CopyFileOut(const base::FilePath& path, base::FilePath* out) {
if (external_files_.contains(path)) {
*out = external_files_.get(path)->path();
return true;
}
FileInfo info;
if (!GetFileInfo(path, &info))
return false;
scoped_ptr<ScopedTemporaryFile> temp_file(new ScopedTemporaryFile);
if (!temp_file->InitFromFile(path_, info.offset, info.size))
return false;
*out = temp_file->path();
external_files_.set(path, temp_file.Pass());
return true;
}
} // namespace asar

View File

@@ -0,0 +1,76 @@
// 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_ASAR_ARCHIVE_H_
#define ATOM_COMMON_ASAR_ARCHIVE_H_
#include <vector>
#include "base/containers/scoped_ptr_hash_map.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
namespace base {
class DictionaryValue;
}
namespace asar {
class ScopedTemporaryFile;
// This class represents an asar package, and provides methods to read
// information from it.
class Archive {
public:
struct FileInfo {
FileInfo() : size(0), offset(0) {}
uint32 size;
uint64 offset;
};
struct Stats : public FileInfo {
Stats() : is_file(true), is_directory(false), is_link(false) {}
bool is_file;
bool is_directory;
bool is_link;
};
explicit Archive(const base::FilePath& path);
virtual ~Archive();
// Read and parse the header.
bool Init();
// Get the info of a file.
bool GetFileInfo(const base::FilePath& path, FileInfo* info);
// Fs.stat(path).
bool Stat(const base::FilePath& path, Stats* stats);
// Fs.readdir(path).
bool Readdir(const base::FilePath& path, std::vector<base::FilePath>* files);
// Fs.realpath(path).
bool Realpath(const base::FilePath& path, base::FilePath* realpath);
// Copy the file into a temporary file, and return the new path.
bool CopyFileOut(const base::FilePath& path, base::FilePath* out);
base::FilePath path() const { return path_; }
base::DictionaryValue* header() const { return header_.get(); }
private:
base::FilePath path_;
uint32 header_size_;
scoped_ptr<base::DictionaryValue> header_;
// Cached external temporary files.
base::ScopedPtrHashMap<base::FilePath, ScopedTemporaryFile> external_files_;
DISALLOW_COPY_AND_ASSIGN(Archive);
};
} // namespace asar
#endif // ATOM_COMMON_ASAR_ARCHIVE_H_

View File

@@ -0,0 +1,54 @@
// 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/common/asar/scoped_temporary_file.h"
#include <vector>
#include "base/file_util.h"
#include "base/threading/thread_restrictions.h"
namespace asar {
ScopedTemporaryFile::ScopedTemporaryFile() {
}
ScopedTemporaryFile::~ScopedTemporaryFile() {
if (!path_.empty()) {
base::ThreadRestrictions::ScopedAllowIO allow_io;
base::DeleteFile(path_, false);
}
}
bool ScopedTemporaryFile::Init() {
if (!path_.empty())
return true;
base::ThreadRestrictions::ScopedAllowIO allow_io;
return base::CreateTemporaryFile(&path_);
}
bool ScopedTemporaryFile::InitFromFile(const base::FilePath& path,
uint64 offset, uint64 size) {
if (!Init())
return false;
base::File src(path, base::File::FLAG_OPEN | base::File::FLAG_READ);
if (!src.IsValid())
return false;
std::vector<char> buf(size);
int len = src.Read(offset, buf.data(), buf.size());
if (len != static_cast<int>(size))
return false;
base::File dest(path_, base::File::FLAG_OPEN | base::File::FLAG_WRITE);
if (!dest.IsValid())
return false;
return dest.WriteAtCurrentPos(buf.data(), buf.size()) ==
static_cast<int>(size);
}
} // namespace asar

View File

@@ -0,0 +1,37 @@
// 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_ASAR_SCOPED_TEMPORARY_FILE_H_
#define ATOM_COMMON_ASAR_SCOPED_TEMPORARY_FILE_H_
#include "base/files/file_path.h"
namespace asar {
// An object representing a temporary file that should be cleaned up when this
// object goes out of scope. Note that since deletion occurs during the
// destructor, no further error handling is possible if the directory fails to
// be deleted. As a result, deletion is not guaranteed by this class.
class ScopedTemporaryFile {
public:
ScopedTemporaryFile();
virtual ~ScopedTemporaryFile();
// Init an empty temporary file.
bool Init();
// Init an temporary file and fill it with content of |path|.
bool InitFromFile(const base::FilePath& path, uint64 offset, uint64 size);
base::FilePath path() const { return path_; }
private:
base::FilePath path_;
DISALLOW_COPY_AND_ASSIGN(ScopedTemporaryFile);
};
} // namespace asar
#endif // ATOM_COMMON_ASAR_SCOPED_TEMPORARY_FILE_H_

View File

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

296
atom/common/lib/asar.coffee Normal file
View File

@@ -0,0 +1,296 @@
asar = process.atomBinding 'asar'
child_process = require 'child_process'
fs = require 'fs'
path = require 'path'
util = require 'util'
# Cache asar archive objects.
cachedArchives = {}
getOrCreateArchive = (p) ->
archive = cachedArchives[p]
return archive if archive?
archive = asar.createArchive p
return false unless archive
cachedArchives[p] = archive
# Clean cache on quit.
process.on 'exit', ->
archive.destroy() for p, archive of cachedArchives
# Separate asar package's path from full path.
splitPath = (p) ->
return [false] if typeof p isnt 'string'
return [true, p, ''] if p.substr(-5) is '.asar'
index = p.lastIndexOf ".asar#{path.sep}"
return [false] if index is -1
[true, p.substr(0, index + 5), p.substr(index + 6)]
# Convert asar archive's Stats object to fs's Stats object.
nextInode = 0
uid = if process.getuid? then process.getuid() else 0
gid = if process.getgid? then process.getgid() else 0
asarStatsToFsStats = (stats) ->
{
dev: 1,
ino: ++nextInode,
mode: 33188,
nlink: 1,
uid: uid,
gid: gid,
rdev: 0,
size: stats.size
isFile: -> stats.isFile
isDirectory: -> stats.isDirectory
isSymbolicLink: -> stats.isLink
isBlockDevice: -> false
isCharacterDevice: -> false
isFIFO: -> false
isSocket: -> false
}
# Create a ENOENT error.
createNotFoundError = (asarPath, filePath) ->
error = new Error("ENOENT, #{filePath} not found in #{asarPath}")
error.code = "ENOENT"
error.errno = -2
error
# Override fs APIs.
lstatSync = fs.lstatSync
fs.lstatSync = (p) ->
[isAsar, asarPath, filePath] = splitPath p
return lstatSync p unless isAsar
archive = getOrCreateArchive asarPath
throw new Error("Invalid package #{asarPath}") unless archive
stats = archive.stat filePath
throw createNotFoundError(asarPath, filePath) unless stats
asarStatsToFsStats stats
lstat = fs.lstat
fs.lstat = (p, callback) ->
[isAsar, asarPath, filePath] = splitPath p
return lstat p, callback unless isAsar
archive = getOrCreateArchive asarPath
return callback new Error("Invalid package #{asarPath}") unless archive
stats = getOrCreateArchive(asarPath).stat filePath
return callback createNotFoundError(asarPath, filePath) unless stats
process.nextTick -> callback null, asarStatsToFsStats stats
statSync = fs.statSync
fs.statSync = (p) ->
[isAsar, asarPath, filePath] = splitPath p
return statSync p unless isAsar
# Do not distinguish links for now.
fs.lstatSync p
stat = fs.stat
fs.stat = (p, callback) ->
[isAsar, asarPath, filePath] = splitPath p
return stat p, callback unless isAsar
# Do not distinguish links for now.
process.nextTick -> fs.lstat p, callback
statSyncNoException = fs.statSyncNoException
fs.statSyncNoException = (p) ->
[isAsar, asarPath, filePath] = splitPath p
return statSyncNoException p unless isAsar
archive = getOrCreateArchive asarPath
return false unless archive
stats = archive.stat filePath
return false unless stats
asarStatsToFsStats stats
realpathSync = fs.realpathSync
fs.realpathSync = (p) ->
[isAsar, asarPath, filePath] = splitPath p
return realpathSync.apply this, arguments unless isAsar
archive = getOrCreateArchive asarPath
throw new Error("Invalid package #{asarPath}") unless archive
real = archive.realpath filePath
throw createNotFoundError(asarPath, filePath) if real is false
path.join realpathSync(asarPath), real
realpath = fs.realpath
fs.realpath = (p, cache, callback) ->
[isAsar, asarPath, filePath] = splitPath p
return realpath.apply this, arguments unless isAsar
if typeof cache is 'function'
callback = cache
cache = undefined
archive = getOrCreateArchive asarPath
return callback new Error("Invalid package #{asarPath}") unless archive
real = archive.realpath filePath
return callback createNotFoundError(asarPath, filePath) if real is false
realpath asarPath, (err, p) ->
return callback err if err
callback null, path.join(p, real)
exists = fs.exists
fs.exists = (p, callback) ->
[isAsar, asarPath, filePath] = splitPath p
return exists p, callback unless isAsar
archive = getOrCreateArchive asarPath
return callback new Error("Invalid package #{asarPath}") unless archive
process.nextTick -> callback archive.stat(filePath) isnt false
existsSync = fs.existsSync
fs.existsSync = (p) ->
[isAsar, asarPath, filePath] = splitPath p
return existsSync p unless isAsar
archive = getOrCreateArchive asarPath
return false unless archive
archive.stat(filePath) isnt false
open = fs.open
readFile = fs.readFile
fs.readFile = (p, options, callback) ->
[isAsar, asarPath, filePath] = splitPath p
return readFile.apply this, arguments unless isAsar
if typeof options is 'function'
callback = options
options = undefined
archive = getOrCreateArchive asarPath
return callback new Error("Invalid package #{asarPath}") unless archive
info = archive.getFileInfo filePath
return callback createNotFoundError(asarPath, filePath) unless info
if not options
options = encoding: null, flag: 'r'
else if util.isString options
options = encoding: options, flag: 'r'
else if not util.isObject options
throw new TypeError('Bad arguments')
flag = options.flag || 'r'
encoding = options.encoding
buffer = new Buffer(info.size)
open archive.path, flag, (error, fd) ->
return callback error if error
fs.read fd, buffer, 0, info.size, info.offset, (error) ->
fs.close fd, ->
callback error, if encoding then buffer.toString encoding else buffer
openSync = fs.openSync
readFileSync = fs.readFileSync
fs.readFileSync = (p, options) ->
[isAsar, asarPath, filePath] = splitPath p
return readFileSync.apply this, arguments unless isAsar
archive = getOrCreateArchive asarPath
throw new Error("Invalid package #{asarPath}") unless archive
info = archive.getFileInfo filePath
throw createNotFoundError(asarPath, filePath) unless info
if not options
options = encoding: null, flag: 'r'
else if util.isString options
options = encoding: options, flag: 'r'
else if not util.isObject options
throw new TypeError('Bad arguments')
flag = options.flag || 'r'
encoding = options.encoding
buffer = new Buffer(info.size)
fd = openSync archive.path, flag
try
fs.readSync fd, buffer, 0, info.size, info.offset
catch e
throw e
finally
fs.closeSync fd
if encoding then buffer.toString encoding else buffer
readdir = fs.readdir
fs.readdir = (p, callback) ->
[isAsar, asarPath, filePath] = splitPath p
return readdir.apply this, arguments unless isAsar
archive = getOrCreateArchive asarPath
return callback new Error("Invalid package #{asarPath}") unless archive
files = archive.readdir filePath
return callback createNotFoundError(asarPath, filePath) unless files
process.nextTick -> callback null, files
readdirSync = fs.readdirSync
fs.readdirSync = (p) ->
[isAsar, asarPath, filePath] = splitPath p
return readdirSync.apply this, arguments unless isAsar
archive = getOrCreateArchive asarPath
throw new Error("Invalid package #{asarPath}") unless archive
files = archive.readdir filePath
throw createNotFoundError(asarPath, filePath) unless files
files
# Override APIs that rely on passing file path instead of content to C++.
overrideAPISync = (module, name, arg = 0) ->
old = module[name]
module[name] = ->
p = arguments[arg]
[isAsar, asarPath, filePath] = splitPath p
return old.apply this, arguments unless isAsar
archive = getOrCreateArchive asarPath
throw new Error("Invalid package #{asarPath}") unless archive
newPath = archive.copyFileOut filePath
throw createNotFoundError(asarPath, filePath) unless newPath
arguments[arg] = newPath
old.apply this, arguments
overrideAPI = (module, name, arg = 0) ->
old = module[name]
module[name] = ->
p = arguments[arg]
[isAsar, asarPath, filePath] = splitPath p
return old.apply this, arguments unless isAsar
callback = arguments[arguments.length - 1]
return overrideAPISync module, name, arg unless typeof callback is 'function'
archive = getOrCreateArchive asarPath
return callback new Error("Invalid package #{asarPath}") unless archive
newPath = archive.copyFileOut filePath
return callback createNotFoundError(asarPath, filePath) unless newPath
arguments[arg] = newPath
old.apply this, arguments
overrideAPI fs, 'open'
overrideAPI child_process, 'execFile'
overrideAPISync process, 'dlopen', 1
overrideAPISync require('module')._extensions, '.node', 1
overrideAPISync fs, 'openSync'
overrideAPISync child_process, 'fork'

View File

@@ -6,7 +6,7 @@ process.atomBinding = (name) ->
try
process.binding "atom_#{process.type}_#{name}"
catch e
process.binding "atom_common_#{name}" if e.message is 'No such module'
process.binding "atom_common_#{name}" if /No such module/.test e.message
# Add common/api/lib to module search paths.
globalPaths = Module.globalPaths
@@ -33,3 +33,6 @@ global.clearImmediate = timers.clearImmediate
if process.type is 'browser'
global.setTimeout = wrapWithActivateUvLoop timers.setTimeout
global.setInterval = wrapWithActivateUvLoop timers.setInterval
# Add support for asar packages.
require './asar'

View File

@@ -69,6 +69,7 @@ REFERENCE_MODULE(atom_browser_protocol);
REFERENCE_MODULE(atom_browser_global_shortcut);
REFERENCE_MODULE(atom_browser_tray);
REFERENCE_MODULE(atom_browser_window);
REFERENCE_MODULE(atom_common_asar);
REFERENCE_MODULE(atom_common_clipboard);
REFERENCE_MODULE(atom_common_crash_reporter);
REFERENCE_MODULE(atom_common_id_weak_map);

View File

@@ -39,7 +39,7 @@ void NodeBindingsWin::PollEvents() {
ULONG_PTR key;
OVERLAPPED* overlapped;
timeout = uv_get_poll_timeout(uv_loop_);
timeout = uv_backend_timeout(uv_loop_);
GetQueuedCompletionStatus(uv_loop_->iocp,
&bytes,
&key,

View File

@@ -57,6 +57,17 @@ const char kEnableLargerThanScreen[] = "enable-larger-than-screen";
// Forces to use dark theme on Linux.
const char kDarkTheme[] = "dark-theme";
// Enable DirectWrite on Windows.
const char kDirectWrite[] = "direct-write";
// Web runtime features.
const char kExperimentalFeatures[] = "experimental-features";
const char kExperimentalCanvasFeatures[] = "experimental-canvas-features";
const char kSubpixelFontScaling[] = "subpixel-font-scaling";
const char kOverlayScrollbars[] = "overlay-scrollbars";
const char kOverlayFullscreenVideo[] = "overlay-fullscreen-video";
const char kSharedWorker[] = "shared-worker";
} // namespace switches
} // namespace atom

View File

@@ -35,6 +35,14 @@ extern const char kZoomFactor[];
extern const char kAutoHideMenuBar[];
extern const char kEnableLargerThanScreen[];
extern const char kDarkTheme[];
extern const char kDirectWrite[];
extern const char kExperimentalFeatures[];
extern const char kExperimentalCanvasFeatures[];
extern const char kSubpixelFontScaling[];
extern const char kOverlayScrollbars[];
extern const char kOverlayFullscreenVideo[];
extern const char kSharedWorker[];
} // namespace switches

View File

@@ -20,6 +20,7 @@
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
#include "atom/common/node_includes.h"
@@ -34,6 +35,19 @@ const char* kSecurityManualEnableIframe = "manual-enable-iframe";
const char* kSecurityDisable = "disable";
const char* kSecurityEnableNodeIntegration = "enable-node-integration";
bool IsSwitchEnabled(base::CommandLine* command_line,
const char* switch_string,
bool* enabled) {
std::string value = command_line->GetSwitchValueASCII(switch_string);
if (value == "true")
*enabled = true;
else if (value == "false")
*enabled = false;
else
return false;
return true;
}
// Helper class to forward the WillReleaseScriptContext message to the client.
class AtomRenderFrameObserver : public content::RenderFrameObserver {
public:
@@ -73,10 +87,6 @@ AtomRendererClient::AtomRendererClient()
node_integration_ = ALL;
if (IsNodeBindingEnabled()) {
// Always enable harmony when node binding is on.
std::string flags("--harmony");
v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size()));
node_bindings_.reset(NodeBindings::Create(false));
atom_bindings_.reset(new AtomRendererBindings);
}
@@ -86,6 +96,8 @@ AtomRendererClient::~AtomRendererClient() {
}
void AtomRendererClient::WebKitInitialized() {
EnableWebRuntimeFeatures();
if (!IsNodeBindingEnabled())
return;
@@ -220,4 +232,21 @@ bool AtomRendererClient::IsNodeBindingEnabled(blink::WebFrame* frame) {
return true;
}
void AtomRendererClient::EnableWebRuntimeFeatures() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
bool b;
if (IsSwitchEnabled(command_line, switches::kExperimentalFeatures, &b))
blink::WebRuntimeFeatures::enableExperimentalFeatures(b);
if (IsSwitchEnabled(command_line, switches::kExperimentalCanvasFeatures, &b))
blink::WebRuntimeFeatures::enableExperimentalCanvasFeatures(b);
if (IsSwitchEnabled(command_line, switches::kSubpixelFontScaling, &b))
blink::WebRuntimeFeatures::enableSubpixelFontScaling(b);
if (IsSwitchEnabled(command_line, switches::kOverlayScrollbars, &b))
blink::WebRuntimeFeatures::enableOverlayScrollbars(b);
if (IsSwitchEnabled(command_line, switches::kOverlayFullscreenVideo, &b))
blink::WebRuntimeFeatures::enableOverlayFullscreenVideo(b);
if (IsSwitchEnabled(command_line, switches::kSharedWorker, &b))
blink::WebRuntimeFeatures::enableSharedWorker(b);
}
} // namespace atom

View File

@@ -61,6 +61,8 @@ class AtomRendererClient : public content::ContentRendererClient,
bool is_server_redirect,
bool* send_referrer) OVERRIDE;
void EnableWebRuntimeFeatures();
std::vector<node::Environment*> web_page_envs_;
scoped_ptr<NodeBindings> node_bindings_;

View File

@@ -24,8 +24,12 @@ require path.resolve(__dirname, '..', '..', 'common', 'lib', 'init.js')
global.require = require
global.module = module
# Set the __filename to the path of html file if it's file:// protocol.
if window.location.protocol is 'file:'
# Emit the 'exit' event when page is unloading.
window.addEventListener 'unload', ->
process.emit 'exit'
# 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'
window.location.pathname.substr 1

View File

@@ -21,8 +21,8 @@ namespace extensions {
// forwards its output to the base class for processing.
//
// This class does two things:
// 1. Intercepts media keys. Uses an event tap for intercepting media keys
// (PlayPause, NextTrack, PreviousTrack).
// 1. Intercepts media/volume keys. Uses an event tap for intercepting media keys
// (PlayPause, NextTrack, PreviousTrack) and volume keys(VolumeUp, VolumeDown, VolumeMute).
// 2. Binds keyboard shortcuts (hot keys). Carbon RegisterEventHotKey API for
// binding to non-media key global hot keys (eg. Command-Shift-1).
class GlobalShortcutListenerMac : public GlobalShortcutListener {
@@ -38,7 +38,7 @@ class GlobalShortcutListenerMac : public GlobalShortcutListener {
// Keyboard event callbacks.
void OnHotKeyEvent(EventHotKeyID hot_key_id);
bool OnMediaKeyEvent(int key_code);
bool OnMediaOrVolumeKeyEvent(int key_code);
// GlobalShortcutListener implementation.
virtual void StartListening() OVERRIDE;
@@ -52,16 +52,16 @@ class GlobalShortcutListenerMac : public GlobalShortcutListener {
bool RegisterHotKey(const ui::Accelerator& accelerator, KeyId hot_key_id);
void UnregisterHotKey(const ui::Accelerator& accelerator);
// Enable and disable the media key event tap.
void StartWatchingMediaKeys();
void StopWatchingMediaKeys();
// Enable and disable the media/volume key event tap.
void StartWatchingMediaOrVolumeKeys();
void StopWatchingMediaOrVolumeKeys();
// Enable and disable the hot key event handler.
void StartWatchingHotKeys();
void StopWatchingHotKeys();
// Whether or not any media keys are currently registered.
bool IsAnyMediaKeyRegistered();
// Whether or not any media/volume keys are currently registered.
bool IsAnyMediaOrVolumeKeyRegistered();
// Whether or not any hot keys are currently registered.
bool IsAnyHotKeyRegistered();
@@ -80,7 +80,7 @@ class GlobalShortcutListenerMac : public GlobalShortcutListener {
// The hotkey identifier for the next global shortcut that is added.
KeyId hot_key_id_;
// A map of all hotkeys (media keys and shortcuts) mapping to their
// A map of all hotkeys (media/volume keys and shortcuts) mapping to their
// corresponding hotkey IDs. For quickly finding if an accelerator is
// registered.
AcceleratorIdMap accelerator_ids_;
@@ -91,7 +91,7 @@ class GlobalShortcutListenerMac : public GlobalShortcutListener {
// Keyboard shortcut IDs to hotkeys map for unregistration.
IdHotKeyRefMap id_hot_key_refs_;
// Event tap for intercepting mac media keys.
// Event tap for intercepting mac media/volume keys.
CFMachPortRef event_tap_;
CFRunLoopSourceRef event_tap_source_;

View File

@@ -19,11 +19,11 @@ using extensions::GlobalShortcutListenerMac;
namespace {
// The media keys subtype. No official docs found, but widely known.
// The media/volume keys subtype. No official docs found, but widely known.
// http://lists.apple.com/archives/cocoa-dev/2007/Aug/msg00499.html
const int kSystemDefinedEventMediaKeysSubtype = 8;
const int kSystemDefinedEventMediaAndVolumeKeysSubtype = 8;
ui::KeyboardCode MediaKeyCodeToKeyboardCode(int key_code) {
ui::KeyboardCode MediaOrVolumeKeyCodeToKeyboardCode(int key_code) {
switch (key_code) {
case NX_KEYTYPE_PLAY:
return ui::VKEY_MEDIA_PLAY_PAUSE;
@@ -33,17 +33,26 @@ ui::KeyboardCode MediaKeyCodeToKeyboardCode(int key_code) {
case NX_KEYTYPE_NEXT:
case NX_KEYTYPE_FAST:
return ui::VKEY_MEDIA_NEXT_TRACK;
case NX_KEYTYPE_SOUND_UP:
return ui::VKEY_VOLUME_UP;
case NX_KEYTYPE_SOUND_DOWN:
return ui::VKEY_VOLUME_DOWN;
case NX_KEYTYPE_MUTE:
return ui::VKEY_VOLUME_MUTE;
}
return ui::VKEY_UNKNOWN;
}
bool IsMediaKey(const ui::Accelerator& accelerator) {
bool IsMediaOrVolumeKey(const ui::Accelerator& accelerator) {
if (accelerator.modifiers() != 0)
return false;
return (accelerator.key_code() == ui::VKEY_MEDIA_NEXT_TRACK ||
accelerator.key_code() == ui::VKEY_MEDIA_PREV_TRACK ||
accelerator.key_code() == ui::VKEY_MEDIA_PLAY_PAUSE ||
accelerator.key_code() == ui::VKEY_MEDIA_STOP);
accelerator.key_code() == ui::VKEY_MEDIA_STOP ||
accelerator.key_code() == ui::VKEY_VOLUME_UP ||
accelerator.key_code() == ui::VKEY_VOLUME_DOWN ||
accelerator.key_code() == ui::VKEY_VOLUME_MUTE);
}
} // namespace
@@ -77,8 +86,8 @@ GlobalShortcutListenerMac::~GlobalShortcutListenerMac() {
// If keys are still registered, make sure we stop the tap. Again, this
// should never happen.
if (IsAnyMediaKeyRegistered())
StopWatchingMediaKeys();
if (IsAnyMediaOrVolumeKeyRegistered())
StopWatchingMediaOrVolumeKeys();
if (IsAnyHotKeyRegistered())
StopWatchingHotKeys();
@@ -114,9 +123,11 @@ void GlobalShortcutListenerMac::OnHotKeyEvent(EventHotKeyID hot_key_id) {
NotifyKeyPressed(accelerator);
}
bool GlobalShortcutListenerMac::OnMediaKeyEvent(int media_key_code) {
bool GlobalShortcutListenerMac::OnMediaOrVolumeKeyEvent(
int media_or_volume_key_code) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
ui::KeyboardCode key_code = MediaKeyCodeToKeyboardCode(media_key_code);
ui::KeyboardCode key_code = MediaOrVolumeKeyCodeToKeyboardCode(
media_or_volume_key_code);
// Create an accelerator corresponding to the keyCode.
ui::Accelerator accelerator(key_code, 0);
// Look for a match with a bound hot_key.
@@ -133,10 +144,10 @@ bool GlobalShortcutListenerMac::RegisterAcceleratorImpl(
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(accelerator_ids_.find(accelerator) == accelerator_ids_.end());
if (IsMediaKey(accelerator)) {
if (!IsAnyMediaKeyRegistered()) {
// If this is the first media key registered, start the event tap.
StartWatchingMediaKeys();
if (IsMediaOrVolumeKey(accelerator)) {
if (!IsAnyMediaOrVolumeKeyRegistered()) {
// If this is the first media/volume key registered, start the event tap.
StartWatchingMediaOrVolumeKeys();
}
} else {
// Register hot_key if they are non-media keyboard shortcuts.
@@ -161,7 +172,7 @@ void GlobalShortcutListenerMac::UnregisterAcceleratorImpl(
DCHECK(accelerator_ids_.find(accelerator) != accelerator_ids_.end());
// Unregister the hot_key if it's a keyboard shortcut.
if (!IsMediaKey(accelerator))
if (!IsMediaOrVolumeKey(accelerator))
UnregisterHotKey(accelerator);
// Remove hot_key from the mappings.
@@ -169,11 +180,11 @@ void GlobalShortcutListenerMac::UnregisterAcceleratorImpl(
id_accelerators_.erase(key_id);
accelerator_ids_.erase(accelerator);
if (IsMediaKey(accelerator)) {
// If we unregistered a media key, and now no media keys are registered,
// stop the media key tap.
if (!IsAnyMediaKeyRegistered())
StopWatchingMediaKeys();
if (IsMediaOrVolumeKey(accelerator)) {
// If we unregistered a media/volume key, and now no media/volume keys are registered,
// stop the media/volume key tap.
if (!IsAnyMediaOrVolumeKeyRegistered())
StopWatchingMediaOrVolumeKeys();
} else {
// If we unregistered a hot key, and no more hot keys are registered, remove
// the hot key handler.
@@ -226,12 +237,12 @@ void GlobalShortcutListenerMac::UnregisterHotKey(
id_hot_key_refs_.erase(key_id);
}
void GlobalShortcutListenerMac::StartWatchingMediaKeys() {
void GlobalShortcutListenerMac::StartWatchingMediaOrVolumeKeys() {
// Make sure there's no existing event tap.
DCHECK(event_tap_ == NULL);
DCHECK(event_tap_source_ == NULL);
// Add an event tap to intercept the system defined media key events.
// Add an event tap to intercept the system defined media/volume key events.
event_tap_ = CGEventTapCreate(kCGSessionEventTap,
kCGHeadInsertEventTap,
kCGEventTapOptionDefault,
@@ -254,7 +265,7 @@ void GlobalShortcutListenerMac::StartWatchingMediaKeys() {
kCFRunLoopCommonModes);
}
void GlobalShortcutListenerMac::StopWatchingMediaKeys() {
void GlobalShortcutListenerMac::StopWatchingMediaOrVolumeKeys() {
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), event_tap_source_,
kCFRunLoopCommonModes);
// Ensure both event tap and source are initialized.
@@ -287,11 +298,11 @@ void GlobalShortcutListenerMac::StopWatchingHotKeys() {
event_handler_ = NULL;
}
bool GlobalShortcutListenerMac::IsAnyMediaKeyRegistered() {
// Iterate through registered accelerators, looking for media keys.
bool GlobalShortcutListenerMac::IsAnyMediaOrVolumeKeyRegistered() {
// Iterate through registered accelerators, looking for media/volume keys.
AcceleratorIdMap::iterator it;
for (it = accelerator_ids_.begin(); it != accelerator_ids_.end(); ++it) {
if (IsMediaKey(it->first))
if (IsMediaOrVolumeKey(it->first))
return true;
}
return false;
@@ -300,7 +311,7 @@ bool GlobalShortcutListenerMac::IsAnyMediaKeyRegistered() {
bool GlobalShortcutListenerMac::IsAnyHotKeyRegistered() {
AcceleratorIdMap::iterator it;
for (it = accelerator_ids_.begin(); it != accelerator_ids_.end(); ++it) {
if (!IsMediaKey(it->first))
if (!IsMediaOrVolumeKey(it->first))
return true;
}
return false;
@@ -329,20 +340,24 @@ CGEventRef GlobalShortcutListenerMac::EventTapCallback(
return event;
}
// Ignore events that are not system defined media keys.
// Ignore events that are not system defined media/volume keys.
if (type != NX_SYSDEFINED ||
[ns_event type] != NSSystemDefined ||
[ns_event subtype] != kSystemDefinedEventMediaKeysSubtype) {
[ns_event subtype] != kSystemDefinedEventMediaAndVolumeKeysSubtype) {
return event;
}
NSInteger data1 = [ns_event data1];
// Ignore media keys that aren't previous, next and play/pause.
// Ignore media keys that aren't previous, next and play/pause and
// volume keys that aren't up, down and mute.
// Magical constants are from http://weblog.rogueamoeba.com/2007/09/29/
int key_code = (data1 & 0xFFFF0000) >> 16;
if (key_code != NX_KEYTYPE_PLAY && key_code != NX_KEYTYPE_NEXT &&
key_code != NX_KEYTYPE_PREVIOUS && key_code != NX_KEYTYPE_FAST &&
key_code != NX_KEYTYPE_REWIND) {
key_code != NX_KEYTYPE_REWIND &&
key_code != NX_KEYTYPE_SOUND_UP &&
key_code != NX_KEYTYPE_SOUND_DOWN &&
key_code != NX_KEYTYPE_MUTE) {
return event;
}
@@ -353,8 +368,8 @@ CGEventRef GlobalShortcutListenerMac::EventTapCallback(
if (!is_key_pressed)
return event;
// Now we have a media key that we care about. Send it to the caller.
bool was_handled = shortcut_listener->OnMediaKeyEvent(key_code);
// Now we have a media/volume key that we care about. Send it to the caller.
bool was_handled = shortcut_listener->OnMediaOrVolumeKeyEvent(key_code);
// Prevent event from proagating to other apps if handled by Chrome.
if (was_handled)

View File

@@ -1,6 +1,7 @@
{
'variables': {
'clang': 0,
'openssl_no_asm': 1,
'conditions': [
['OS=="mac" or OS=="linux"', {
'clang': 1,

View File

@@ -2,8 +2,10 @@
* [Quick start](tutorial/quick-start.md)
* [Application distribution](tutorial/application-distribution.md)
* [Use native node modules](tutorial/use-native-node-modules.md)
* [Application packaging](tutorial/application-packaging.md)
* [Using native node modules](tutorial/using-native-node-modules.md)
* [Debugging browser process](tutorial/debugging-browser-process.md)
* [Using Selenium and WebDriver](tutorial/using-selenium-and-webdriver.md)
* [DevTools extension](tutorial/devtools-extension.md)
## API references

View File

@@ -45,6 +45,10 @@ terminating the application.
See description of `window-all-closed` for the differences between `will-quit`
and it.
## Event: quit
Emitted when application is quitting.
## Event: open-file
* `event` Event

View File

@@ -80,6 +80,14 @@ normal browsers, see [Web Security](web-security.md) for more.
should use `__dirname` or `process.resourcesPath` to join the paths to
make them absolute, using relative paths would make atom-shell search
under current working directory.
* `experimental-features` Boolean
* `experimental-canvas-features` Boolean
* `subpixel-font-scaling` Boolean
* `overlay-scrollbars` Boolean
* `overlay-fullscreen-video` Boolean
* `shared-worker` Boolean
* `direct-write` Boolean - Whether the DirectWrite font rendering system on
Windows is enabled
Creates a new `BrowserWindow` with native properties set by the `options`.
Usually you only need to set the `width` and `height`, other properties will
@@ -480,6 +488,19 @@ Sets the `menu` as the window top menu.
__Note:__ This API is not available on OS X.
### BrowserWindow.setProgressBar(progress)
* `progress` Double
Sets progress value in progress bar. Valid range is [0, 1.0].
Remove progress bar when progress < 0;
Change to indeterminate mode when progress > 1.
On Linux platform, only supports Unity desktop environment, you need to specify
the `*.desktop` file name to `desktopName` field in `package.json`. By default,
it will assume `app.getName().desktop`.
## Class: WebContents
A `WebContents` is responsible for rendering and controlling a web page.

View File

@@ -48,6 +48,12 @@ Creates a new tray icon associated with the `image`.
Emitted when the tray icon is clicked.
### Event: 'double-clicked'
Emitted when the tray icon is double clicked.
This is only implmented on OS X.
### Tray.setImage(image)
* `image` [Image](image.md)
@@ -64,8 +70,28 @@ Sets the `image` associated with this tray icon when pressed.
* `toolTip` String
Sets the hover text for this tray icon.
### Tray.setTitle(title)
* `title` String
Sets the title displayed aside of the tray icon in the status bar.
This is only implmented on OS X.
### Tray.setHighlightMode(highlight)
* `highlight` Boolean
Sets whether the tray icon is highlighted when it is clicked.
This is only implmented on OS X.
### Tray.setContextMenu(menu)
* `menu` Menu
Set the context menu for this icon.
[event-emitter]: http://nodejs.org/api/events.html#events_class_events_eventemitter

View File

@@ -27,7 +27,19 @@ Then execute `Atom.app` (or `atom` on Linux, and `atom.exe` on Windows), and
atom-shell will start as your app. The `atom-shell` directory would then be
your distribution that should be delivered to final users.
## Build with grunt
## 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
exposing your app's source code to users.
To use the `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.
More details can be found in [Application packaging](application-packaging.md).
## Building with grunt
If you build your application with `grunt` there is a grunt task that can
download atom-shell for your current platform automatically:

View File

@@ -0,0 +1,139 @@
# 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.
## Generating `asar` archive
The [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:
### 1. Install asar utility
```bash
$ npm install -g asar
```
### 2. Package with `asar pack`
```bash
$ 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.
### 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.
For example, suppose we have an `example.asar` archive under `/path/to`:
```bash
$ asar list /path/to/example.asar
/app.js
/file.txt
/dir/module.js
/static/index.html
/static/main.css
/static/jquery.min.js
```
Read a file in `asar` archive:
```javascript
var fs = require('fs');
fs.readFileSync('/path/to/example.asar/file.txt');
```
List all files under the root of archive:
```javascript
var fs = require('fs');
fs.readdirSync('/path/to/example.asar');
```
Use a module from the archive:
```javascript
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.
For example, to get a file with `$.get`:
```html
<script>
var $ = require('./jquery.min.js');
$.get('asar:/path/to/example.asar/file.txt', function(data) {
console.log(data);
});
</script>
```
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:`.
You can also display a web page in `asar` archive with `BrowserWindow`:
```javascript
var BrowserWindow = require('browser-window');
var win = new BrowserWindow({width: 800, height: 600});
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
directories as much as possible, there are still limitations due to the
low-level nature of Node API.
### Archives are read only
The archives can not be modifies 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 `asar` archives, passing them to `cwd` option of some APIs will
also cause errors.
### Extra unpacking on some APIs
Most `fs` APIs can read file or get file's information from `asar` archives
without unpacking, but for some APIs that rely on passing the real file path to
underlying system calls, atom-shell will extract the needed file into a
temporary file and pass the path of the temporary file to the APIs to make them
work. This adds a little overhead for those APIs.
APIs that requires extra unpacking are:
* `child_process.execFile`
* `child_process.fork`
* `fs.open`
* `fs.openSync`
* `process.dlopen` - Used by `require` on native modules
### 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
filesystem. So you should not trust the `Stats` object except for getting file
size and checking file type.
[asar]: https://github.com/atom/asar

View File

@@ -8,8 +8,8 @@ a variant of the Node.js runtime which is focused on desktop applications
instead of web servers.
It doesn't mean atom-shell is a JavaScript binding to GUI libraries. Instead,
atom-shell uses web pages as its GUI, so you could also see it as a minimal Chromium
browser, controlled by JavaScript.
atom-shell uses web pages as its GUI, so you could also see it as a minimal
Chromium browser, controlled by JavaScript.
### The browser side
@@ -18,9 +18,11 @@ are two types of JavaScript scripts: the server side scripts and the client side
scripts. Server-side JavaScript is that which runs on the Node.js
runtime, while client-side JavaScript runs inside the user's browser.
In atom-shell we have similar concepts: Since atom-shell displays a GUI by showing
web pages, we have **scripts that run in the web page**, and also **scripts run by the atom-shell runtime**, which creates those web pages.
Like Node.js, we call them **client scripts**, and **browser scripts** (meaning the browser replaces the concept of the server here).
In atom-shell we have similar concepts: Since atom-shell displays a GUI by
showing web pages, we have **scripts that run in the web page**, and also
**scripts run by the atom-shell runtime**, which creates those web pages.
Like Node.js, we call them **client scripts**, and **browser scripts**
(meaning the browser replaces the concept of the server here).
In traditional Node.js applications, communication between server and
client is usually facilitated via web sockets. In atom-shell, we have provided
@@ -30,19 +32,20 @@ support.
### Web page and Node.js
Normal web pages are designed to not reach outside of the browser, which makes them
unsuitable for interacting with native systems. Atom-shell provides Node.js APIs
in web pages so you can access native resources from web pages, just like
Normal web pages are designed to not reach outside of the browser, which makes
them unsuitable for interacting with native systems. Atom-shell provides Node.js
APIs in web pages so you can access native resources from web pages, just like
[Node-Webkit](https://github.com/rogerwang/node-webkit).
But unlike Node-Webkit, you cannot do native GUI related operations in web
pages. Instead you need to do them on the browser side by sending messages to it, or
using the easy [remote](../api/remote.md) module.
pages. Instead you need to do them on the browser side by sending messages to
it, or using the easy [remote](../api/remote.md) module.
## Write your first atom-shell app
Generally, an atom-shell app would be structured like this (see the [hello-atom](https://github.com/dougnukem/hello-atom) repo for reference):
Generally, an atom-shell app would be structured like this (see the
[hello-atom](https://github.com/dougnukem/hello-atom) repo for reference):
```text
your-app/
@@ -51,10 +54,10 @@ your-app/
└── index.html
```
The format of `package.json` is exactly the same as that of Node's modules, and the
script specified by the `main` field is the startup script of your app, which
will run on the browser side. An example of your `package.json` might look like
this:
The format of `package.json` is exactly the same as that of Node's modules, and
the script specified by the `main` field is the startup script of your app,
which will run on the browser side. An example of your `package.json` might look
like this:
```json
{
@@ -123,8 +126,8 @@ Finally the `index.html` is the web page you want to show:
After you're done writing your app, you can create a distribution by
following the [Application distribution](./application-distribution.md) guide
and then execute the packaged app.
You can also just use the downloaded atom-shell binary to execute your app directly.
and then execute the packaged app. You can also just use the downloaded
atom-shell binary to execute your app directly.
On Windows:
@@ -144,4 +147,5 @@ On Mac OS X:
$ ./Atom.app/Contents/MacOS/Atom your-app/
```
`Atom.app` here is part of the atom-shell's release package, you can download it from [here](https://github.com/atom/atom-shell/releases).
`Atom.app` here is part of the atom-shell's release package, you can download
it from [here](https://github.com/atom/atom-shell/releases).

View File

@@ -1,4 +1,4 @@
# Use native Node modules
# Usng 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

@@ -0,0 +1,72 @@
# Using Selenium and WebDriver
From [chromedriver - WebDriver for Google Chrome][chrome-driver]:
> WebDriver is an open source tool for automated testing of web apps across many
> browsers. It provides capabilities for navigating to web pages, user input,
> JavaScript execution, and more. ChromeDriver is a standalone server which
> implements WebDriver's wire protocol for Chromium. It is being developed by
> members of the Chromium and WebDriver teams.
In atom-shell's [releases](https://github.com/atom/atom-shell/releases) page you
can find archives of `chromedriver`, there is no difference between atom-shell's
distribution of `chromedriver` and upstream ones, so in order to use
`chromedriver` together with atom-shell, you will need some special setup.
Also notice that only minor version update releases (e.g. `vX.X.0` releases)
include `chromedriver` archives, because `chromedriver` doesn't change as
frequent as atom-shell itself.
## Setting up with WebDriverJs
[WebDriverJs](https://code.google.com/p/selenium/wiki/WebDriverJs) provided
a Node package for testing with web driver, we will use it as an example.
### 1. Start chrome driver
First you need to download the `chromedriver` binary, and run it:
```bash
$ ./chromedriver
Starting ChromeDriver (v2.10.291558) on port 9515
Only local connections are allowed.
```
Remember the port number `9515`, which will be used later
### 2. Install WebDriverJS
```bash
$ npm install selenium-webdriver
```
### 3. Connect to chrome driver
The usage of `selenium-webdriver` with atom-shell is basically the same with
upstream, except that you have to manually specify how to connect chrome driver
and where to find atom-shell's binary:
```javascript
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
// The "9515" is the port opened by chrome driver.
usingServer('http://localhost:9515').
withCapabilities({chromeOptions: {
// Here is the path to your atom-shell binary.
binary: '/Path-to-Your-App.app/Contents/MacOS/Atom'}}).
build();
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
return driver.getTitle().then(function(title) {
return title === 'webdriver - Google Search';
});
}, 1000);
driver.quit();
```
[chrome-driver]: https://code.google.com/p/chromedriver/

View File

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

View File

@@ -4,7 +4,7 @@ import os
import re
import sys
from lib.util import execute, get_atom_shell_version, scoped_cwd
from lib.util import execute, get_atom_shell_version, parse_version, scoped_cwd
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
@@ -35,17 +35,6 @@ def main():
git_push()
def parse_version(version):
if version[0] == 'v':
version = version[1:]
vs = version.split('.')
if len(vs) > 4:
return vs[0:4]
else:
return vs + ['0'] * (4 - len(vs))
def increase_version(versions, index):
for i in range(index + 1, 4):
versions[i] = '0'

View File

@@ -11,7 +11,7 @@ import tarfile
from lib.config import LIBCHROMIUMCONTENT_COMMIT, BASE_URL, TARGET_PLATFORM, \
DIST_ARCH
from lib.util import scoped_cwd, rm_rf, get_atom_shell_version, make_zip, \
safe_mkdir, execute
safe_mkdir, execute, get_chromedriver_version
ATOM_SHELL_VERSION = get_atom_shell_version()
@@ -104,6 +104,7 @@ def main():
download_libchromiumcontent_symbols(args.url)
create_symbols()
copy_binaries()
copy_chromedriver()
copy_headers()
copy_license()
@@ -112,6 +113,7 @@ def main():
create_version()
create_dist_zip()
create_chromedriver_zip()
create_symbols_zip()
create_header_tarball()
@@ -142,6 +144,15 @@ def copy_binaries():
symlinks=True)
def copy_chromedriver():
build = os.path.join(SOURCE_ROOT, 'script', 'build.py')
execute([sys.executable, build, '-c', 'Release', '-t', 'copy_chromedriver'])
binary = 'chromedriver'
if TARGET_PLATFORM == 'win32':
binary += '.exe'
shutil.copy2(os.path.join(OUT_DIR, binary), DIST_DIR)
def copy_headers():
os.mkdir(DIST_HEADERS_DIR)
# Copy standard node headers from node. repository.
@@ -232,6 +243,20 @@ def create_dist_zip():
make_zip(zip_file, files, dirs)
def create_chromedriver_zip():
dist_name = 'chromedriver-{0}-{1}-{2}.zip'.format(get_chromedriver_version(),
TARGET_PLATFORM, DIST_ARCH)
zip_file = os.path.join(SOURCE_ROOT, 'dist', dist_name)
with scoped_cwd(DIST_DIR):
files = ['LICENSE']
if TARGET_PLATFORM == 'win32':
files += ['chromedriver.exe']
else:
files += ['chromedriver']
make_zip(zip_file, files, [])
def create_symbols_zip():
dist_name = 'atom-shell-{0}-{1}-{2}-symbols.zip'.format(ATOM_SHELL_VERSION,
TARGET_PLATFORM,

View File

@@ -146,6 +146,24 @@ def get_atom_shell_version():
return subprocess.check_output(['git', 'describe', '--tags']).strip()
def get_chromedriver_version():
SOURCE_ROOT = os.path.abspath(os.path.join(__file__, '..', '..', '..'))
chromedriver = os.path.join(SOURCE_ROOT, 'out', 'Release', 'chromedriver')
output = subprocess.check_output([chromedriver, '-v']).strip()
return 'v' + output[13:]
def parse_version(version):
if version[0] == 'v':
version = version[1:]
vs = version.split('.')
if len(vs) > 4:
return vs[0:4]
else:
return vs + ['0'] * (4 - len(vs))
def s3_config():
config = (os.environ.get('ATOM_SHELL_S3_BUCKET', ''),
os.environ.get('ATOM_SHELL_S3_ACCESS_KEY', ''),

View File

@@ -9,13 +9,15 @@ import sys
import tempfile
from lib.config import DIST_ARCH, TARGET_PLATFORM
from lib.util import get_atom_shell_version, scoped_cwd, safe_mkdir, execute, \
from lib.util import execute, get_atom_shell_version, parse_version, \
get_chromedriver_version, scoped_cwd, safe_mkdir, \
s3_config, s3put
from lib.github import GitHub
ATOM_SHELL_REPO = 'atom/atom-shell'
ATOM_SHELL_VERSION = get_atom_shell_version()
CHROMEDRIVER_VERSION = get_chromedriver_version()
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
OUT_DIR = os.path.join(SOURCE_ROOT, 'out', 'Release')
@@ -26,6 +28,9 @@ DIST_NAME = 'atom-shell-{0}-{1}-{2}.zip'.format(ATOM_SHELL_VERSION,
SYMBOLS_NAME = 'atom-shell-{0}-{1}-{2}-symbols.zip'.format(ATOM_SHELL_VERSION,
TARGET_PLATFORM,
DIST_ARCH)
CHROMEDRIVER_NAME = 'chromedriver-{0}-{1}-{2}.zip'.format(CHROMEDRIVER_VERSION,
TARGET_PLATFORM,
DIST_ARCH)
def main():
@@ -49,6 +54,11 @@ def main():
upload_atom_shell(github, release_id, os.path.join(DIST_DIR, DIST_NAME))
upload_atom_shell(github, release_id, os.path.join(DIST_DIR, SYMBOLS_NAME))
# Upload chromedriver for minor version update.
if parse_version(args.version)[2] == '0':
upload_atom_shell(github, release_id,
os.path.join(DIST_DIR, CHROMEDRIVER_NAME))
# Upload node's headers to S3.
bucket, access_key, secret_key = s3_config()
upload_node(bucket, access_key, secret_key, ATOM_SHELL_VERSION)

375
spec/asar-spec.coffee Normal file
View File

@@ -0,0 +1,375 @@
assert = require 'assert'
fs = require 'fs'
path = require 'path'
describe 'asar package', ->
fixtures = path.join __dirname, 'fixtures'
describe 'node api', ->
describe 'fs.readFileSync', ->
it 'reads a normal file', ->
file1 = path.join fixtures, 'asar', 'a.asar', 'file1'
assert.equal fs.readFileSync(file1).toString(), 'file1\n'
file2 = path.join fixtures, 'asar', 'a.asar', 'file2'
assert.equal fs.readFileSync(file2).toString(), 'file2\n'
file3 = path.join fixtures, 'asar', 'a.asar', 'file3'
assert.equal fs.readFileSync(file3).toString(), 'file3\n'
it 'reads a linked file', ->
p = path.join fixtures, 'asar', 'a.asar', 'link1'
assert.equal fs.readFileSync(p).toString(), 'file1\n'
it 'reads a file from linked directory', ->
p = path.join fixtures, 'asar', 'a.asar', 'link2', 'file1'
assert.equal fs.readFileSync(p).toString(), 'file1\n'
p = path.join fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1'
assert.equal fs.readFileSync(p).toString(), 'file1\n'
it 'throws ENOENT error when can not find file', ->
p = path.join fixtures, 'asar', 'a.asar', 'not-exist'
throws = -> fs.readFileSync p
assert.throws throws, /ENOENT/
describe 'fs.readFile', ->
it 'reads a normal file', (done) ->
p = path.join fixtures, 'asar', 'a.asar', 'file1'
fs.readFile p, (err, content) ->
assert.equal err, null
assert.equal String(content), 'file1\n'
done()
it 'reads a linked file', (done) ->
p = path.join fixtures, 'asar', 'a.asar', 'link1'
fs.readFile p, (err, content) ->
assert.equal err, null
assert.equal String(content), 'file1\n'
done()
it 'reads a file from linked directory', (done) ->
p = path.join fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1'
fs.readFile p, (err, content) ->
assert.equal err, null
assert.equal String(content), 'file1\n'
done()
it 'throws ENOENT error when can not find file', (done) ->
p = path.join fixtures, 'asar', 'a.asar', 'not-exist'
fs.readFile p, (err, content) ->
assert.equal err.code, 'ENOENT'
done()
describe 'fs.lstatSync', ->
it 'returns information of root', ->
p = path.join fixtures, 'asar', 'a.asar'
stats = fs.lstatSync p
assert.equal stats.isFile(), false
assert.equal stats.isDirectory(), true
assert.equal stats.isSymbolicLink(), false
assert.equal stats.size, 0
it 'returns information of a normal file', ->
for file in ['file1', 'file2', 'file3', path.join('dir1', 'file1'), path.join('link2', 'file1')]
p = path.join fixtures, 'asar', 'a.asar', file
stats = fs.lstatSync p
assert.equal stats.isFile(), true
assert.equal stats.isDirectory(), false
assert.equal stats.isSymbolicLink(), false
assert.equal stats.size, 6
it 'returns information of a normal directory', ->
for file in ['dir1', 'dir2', 'dir3']
p = path.join fixtures, 'asar', 'a.asar', file
stats = fs.lstatSync p
assert.equal stats.isFile(), false
assert.equal stats.isDirectory(), true
assert.equal stats.isSymbolicLink(), false
assert.equal stats.size, 0
it 'returns information of a linked file', ->
for file in ['link1', path.join('dir1', 'link1'), path.join('link2', 'link2')]
p = path.join fixtures, 'asar', 'a.asar', file
stats = fs.lstatSync p
assert.equal stats.isFile(), false
assert.equal stats.isDirectory(), false
assert.equal stats.isSymbolicLink(), true
assert.equal stats.size, 0
it 'returns information of a linked directory', ->
for file in ['link2', path.join('dir1', 'link2'), path.join('link2', 'link2')]
p = path.join fixtures, 'asar', 'a.asar', file
stats = fs.lstatSync p
assert.equal stats.isFile(), false
assert.equal stats.isDirectory(), false
assert.equal stats.isSymbolicLink(), true
assert.equal stats.size, 0
it 'throws ENOENT error when can not find file', ->
for file in ['file4', 'file5', path.join('dir1', 'file4')]
p = path.join fixtures, 'asar', 'a.asar', file
throws = -> fs.lstatSync p
assert.throws throws, /ENOENT/
describe 'fs.lstat', ->
it 'returns information of root', (done) ->
p = path.join fixtures, 'asar', 'a.asar'
stats = fs.lstat p, (err, stats) ->
assert.equal err, null
assert.equal stats.isFile(), false
assert.equal stats.isDirectory(), true
assert.equal stats.isSymbolicLink(), false
assert.equal stats.size, 0
done()
it 'returns information of a normal file', (done) ->
p = path.join fixtures, 'asar', 'a.asar', 'link2', 'file1'
stats = fs.lstat p, (err, stats) ->
assert.equal err, null
assert.equal stats.isFile(), true
assert.equal stats.isDirectory(), false
assert.equal stats.isSymbolicLink(), false
assert.equal stats.size, 6
done()
it 'returns information of a normal directory', (done) ->
p = path.join fixtures, 'asar', 'a.asar', 'dir1'
stats = fs.lstat p, (err, stats) ->
assert.equal err, null
assert.equal stats.isFile(), false
assert.equal stats.isDirectory(), true
assert.equal stats.isSymbolicLink(), false
assert.equal stats.size, 0
done()
it 'returns information of a linked file', (done) ->
p = path.join fixtures, 'asar', 'a.asar', 'link2', 'link1'
stats = fs.lstat p, (err, stats) ->
assert.equal err, null
assert.equal stats.isFile(), false
assert.equal stats.isDirectory(), false
assert.equal stats.isSymbolicLink(), true
assert.equal stats.size, 0
done()
it 'returns information of a linked directory', (done) ->
p = path.join fixtures, 'asar', 'a.asar', 'link2', 'link2'
stats = fs.lstat p, (err, stats) ->
assert.equal err, null
assert.equal stats.isFile(), false
assert.equal stats.isDirectory(), false
assert.equal stats.isSymbolicLink(), true
assert.equal stats.size, 0
done()
it 'throws ENOENT error when can not find file', (done) ->
p = path.join fixtures, 'asar', 'a.asar', 'file4'
stats = fs.lstat p, (err, stats) ->
assert.equal err.code, 'ENOENT'
done()
describe 'fs.realpathSync', ->
it 'returns real path root', ->
parent = fs.realpathSync path.join(fixtures, 'asar')
p = 'a.asar'
r = fs.realpathSync path.join(parent, p)
assert.equal r, path.join(parent, p)
it 'returns real path of a normal file', ->
parent = fs.realpathSync path.join(fixtures, 'asar')
p = path.join 'a.asar', 'file1'
r = fs.realpathSync path.join(parent, p)
assert.equal r, path.join(parent, p)
it 'returns real path of a normal directory', ->
parent = fs.realpathSync path.join(fixtures, 'asar')
p = path.join 'a.asar', 'dir1'
r = fs.realpathSync path.join(parent, p)
assert.equal r, path.join(parent, p)
it 'returns real path of a linked file', ->
parent = fs.realpathSync path.join(fixtures, 'asar')
p = path.join 'a.asar', 'link2', 'link1'
r = fs.realpathSync path.join(parent, p)
assert.equal r, path.join(parent, 'a.asar', 'file1')
it 'returns real path of a linked directory', ->
parent = fs.realpathSync path.join(fixtures, 'asar')
p = path.join 'a.asar', 'link2', 'link2'
r = fs.realpathSync path.join(parent, p)
assert.equal r, path.join(parent, 'a.asar', 'dir1')
it 'throws ENOENT error when can not find file', ->
parent = fs.realpathSync path.join(fixtures, 'asar')
p = path.join 'a.asar', 'not-exist'
throws = -> fs.realpathSync path.join(parent, p)
assert.throws throws, /ENOENT/
describe 'fs.realpath', ->
it 'returns real path root', (done) ->
parent = fs.realpathSync path.join(fixtures, 'asar')
p = 'a.asar'
fs.realpath path.join(parent, p), (err, r) ->
assert.equal err, null
assert.equal r, path.join(parent, p)
done()
it 'returns real path of a normal file', (done) ->
parent = fs.realpathSync path.join(fixtures, 'asar')
p = path.join 'a.asar', 'file1'
fs.realpath path.join(parent, p), (err, r) ->
assert.equal err, null
assert.equal r, path.join(parent, p)
done()
it 'returns real path of a normal directory', (done) ->
parent = fs.realpathSync path.join(fixtures, 'asar')
p = path.join 'a.asar', 'dir1'
fs.realpath path.join(parent, p), (err, r) ->
assert.equal err, null
assert.equal r, path.join(parent, p)
done()
it 'returns real path of a linked file', (done) ->
parent = fs.realpathSync path.join(fixtures, 'asar')
p = path.join 'a.asar', 'link2', 'link1'
fs.realpath path.join(parent, p), (err, r) ->
assert.equal err, null
assert.equal r, path.join(parent, 'a.asar', 'file1')
done()
it 'returns real path of a linked directory', (done) ->
parent = fs.realpathSync path.join(fixtures, 'asar')
p = path.join 'a.asar', 'link2', 'link2'
fs.realpath path.join(parent, p), (err, r) ->
assert.equal err, null
assert.equal r, path.join(parent, 'a.asar', 'dir1')
done()
it 'throws ENOENT error when can not find file', (done) ->
parent = fs.realpathSync path.join(fixtures, 'asar')
p = path.join 'a.asar', 'not-exist'
fs.realpath path.join(parent, p), (err, stats) ->
assert.equal err.code, 'ENOENT'
done()
describe 'fs.readdirSync', ->
it 'reads dirs from root', ->
p = path.join fixtures, 'asar', 'a.asar'
dirs = fs.readdirSync p
assert.deepEqual dirs, ['dir1', 'dir2', 'dir3', 'file1', 'file2', 'file3', 'link1', 'link2', 'ping.js']
it 'reads dirs from a normal dir', ->
p = path.join fixtures, 'asar', 'a.asar', 'dir1'
dirs = fs.readdirSync p
assert.deepEqual dirs, ['file1', 'file2', 'file3', 'link1', 'link2']
it 'reads dirs from a linked dir', ->
p = path.join fixtures, 'asar', 'a.asar', 'link2', 'link2'
dirs = fs.readdirSync p
assert.deepEqual dirs, ['file1', 'file2', 'file3', 'link1', 'link2']
it 'throws ENOENT error when can not find file', ->
p = path.join fixtures, 'asar', 'a.asar', 'not-exist'
throws = -> fs.readdirSync p
assert.throws throws, /ENOENT/
describe 'fs.readdir', ->
it 'reads dirs from root', (done) ->
p = path.join fixtures, 'asar', 'a.asar'
dirs = fs.readdir p, (err, dirs) ->
assert.equal err, null
assert.deepEqual dirs, ['dir1', 'dir2', 'dir3', 'file1', 'file2', 'file3', 'link1', 'link2', 'ping.js']
done()
it 'reads dirs from a normal dir', (done) ->
p = path.join fixtures, 'asar', 'a.asar', 'dir1'
dirs = fs.readdir p, (err, dirs) ->
assert.equal err, null
assert.deepEqual dirs, ['file1', 'file2', 'file3', 'link1', 'link2']
done()
it 'reads dirs from a linked dir', (done) ->
p = path.join fixtures, 'asar', 'a.asar', 'link2', 'link2'
dirs = fs.readdir p, (err, dirs) ->
assert.equal err, null
assert.deepEqual dirs, ['file1', 'file2', 'file3', 'link1', 'link2']
done()
it 'throws ENOENT error when can not find file', (done) ->
p = path.join fixtures, 'asar', 'a.asar', 'not-exist'
fs.readdir p, (err, stats) ->
assert.equal err.code, 'ENOENT'
done()
describe 'fs.openSync', ->
it 'opens a normal/linked/under-linked-directory file', ->
for file in ['file1', 'link1', path.join('link2', 'file1')]
p = path.join fixtures, 'asar', 'a.asar', file
fd = fs.openSync p, 'r'
buffer = new Buffer(6)
fs.readSync fd, buffer, 0, 6, 0
assert.equal String(buffer), 'file1\n'
fs.closeSync fd
it 'throws ENOENT error when can not find file', ->
p = path.join fixtures, 'asar', 'a.asar', 'not-exist'
throws = -> fs.openSync p
assert.throws throws, /ENOENT/
describe 'fs.open', ->
it 'opens a normal file', (done) ->
p = path.join fixtures, 'asar', 'a.asar', 'file1'
fs.open p, 'r', (err, fd) ->
assert.equal err, null
buffer = new Buffer(6)
fs.read fd, buffer, 0, 6, 0, (err) ->
assert.equal err, null
assert.equal String(buffer), 'file1\n'
fs.close fd, done
it 'throws ENOENT error when can not find file', (done) ->
p = path.join fixtures, 'asar', 'a.asar', 'not-exist'
fs.open p, (err, stats) ->
assert.equal err.code, 'ENOENT'
done()
describe 'child_process.fork', ->
child_process = require 'child_process'
it 'opens a normal js file', (done) ->
child = child_process.fork path.join(fixtures, 'asar', 'a.asar', 'ping.js')
child.on 'message', (msg) ->
assert.equal msg, 'message'
done()
child.send 'message'
it 'throws ENOENT error when can not find file', ->
p = path.join fixtures, 'asar', 'a.asar', 'not-exist'
throws = -> child_process.fork p
assert.throws throws, /ENOENT/
describe 'asar protocol', ->
it 'can request a file in package', (done) ->
p = path.resolve fixtures, 'asar', 'a.asar', 'file1'
$.get "asar:#{p}", (data) ->
assert.equal data, 'file1\n'
done()
it 'can request a linked file in package', (done) ->
p = path.resolve fixtures, 'asar', 'a.asar', 'link2', 'link1'
$.get "asar:#{p}", (data) ->
assert.equal data, 'file1\n'
done()
it 'can request a file in filesystem', (done) ->
p = path.resolve fixtures, 'asar', 'file'
$.get "asar:#{p}", (data) ->
assert.equal data, 'file\n'
done()
it 'gets 404 when file is not found', (done) ->
p = path.resolve fixtures, 'asar', 'a.asar', 'no-exist'
$.ajax
url: "asar:#{p}"
error: (err) ->
assert.equal err.status, 404
done()

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

Binary file not shown.

1
spec/fixtures/asar/file vendored Normal file
View File

@@ -0,0 +1 @@
file

12
tools/copy_binary.py Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env python
import os
import shutil
import stat
import sys
src = sys.argv[1]
dist = sys.argv[2]
shutil.copyfile(src, dist)
os.chmod(dist, os.stat(dist).st_mode | stat.S_IEXEC)

2
vendor/node vendored