2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-05-02 16:05:09 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/api/atom_api_app.h"
|
2013-05-02 16:05:09 +00:00
|
|
|
|
2014-03-16 01:13:06 +00:00
|
|
|
#include <string>
|
2014-08-13 12:24:35 +00:00
|
|
|
#include <vector>
|
2014-03-16 01:13:06 +00:00
|
|
|
|
2015-04-29 07:13:46 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include <shlobj.h>
|
|
|
|
#endif
|
|
|
|
|
2014-11-16 15:04:31 +00:00
|
|
|
#include "atom/browser/api/atom_api_menu.h"
|
2015-06-23 15:40:41 +00:00
|
|
|
#include "atom/browser/api/atom_api_session.h"
|
2015-10-28 11:34:01 +00:00
|
|
|
#include "atom/browser/api/atom_api_web_contents.h"
|
2014-08-19 13:26:45 +00:00
|
|
|
#include "atom/browser/atom_browser_context.h"
|
2015-06-18 09:01:23 +00:00
|
|
|
#include "atom/browser/atom_browser_main_parts.h"
|
2014-08-19 13:26:45 +00:00
|
|
|
#include "atom/browser/browser.h"
|
2015-10-28 11:34:01 +00:00
|
|
|
#include "atom/browser/login_handler.h"
|
2015-08-07 10:10:19 +00:00
|
|
|
#include "atom/common/native_mate_converters/callback.h"
|
2015-10-31 13:39:07 +00:00
|
|
|
#include "atom/common/native_mate_converters/net_converter.h"
|
2014-08-19 13:26:45 +00:00
|
|
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
2015-09-07 08:29:54 +00:00
|
|
|
#include "atom/common/node_includes.h"
|
2015-10-07 04:15:48 +00:00
|
|
|
#include "atom/common/options_switches.h"
|
2013-05-17 07:39:44 +00:00
|
|
|
#include "base/command_line.h"
|
2014-08-12 15:01:56 +00:00
|
|
|
#include "base/environment.h"
|
|
|
|
#include "base/files/file_path.h"
|
|
|
|
#include "base/path_service.h"
|
2015-01-19 01:11:27 +00:00
|
|
|
#include "brightray/browser/brightray_paths.h"
|
2015-06-11 15:22:07 +00:00
|
|
|
#include "content/public/browser/client_certificate_delegate.h"
|
2015-06-25 12:28:07 +00:00
|
|
|
#include "content/public/browser/gpu_data_manager.h"
|
2015-10-07 04:15:48 +00:00
|
|
|
#include "content/public/common/content_switches.h"
|
2014-04-17 09:13:46 +00:00
|
|
|
#include "native_mate/dictionary.h"
|
|
|
|
#include "native_mate/object_template_builder.h"
|
2015-06-11 15:22:07 +00:00
|
|
|
#include "net/ssl/ssl_cert_request_info.h"
|
2015-09-16 08:16:21 +00:00
|
|
|
#include "ui/base/l10n/l10n_util.h"
|
2013-12-11 07:48:19 +00:00
|
|
|
|
2015-04-29 07:13:46 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#endif
|
|
|
|
|
2014-04-17 09:13:46 +00:00
|
|
|
using atom::Browser;
|
|
|
|
|
2014-11-17 09:19:41 +00:00
|
|
|
namespace mate {
|
|
|
|
|
2014-11-17 09:35:51 +00:00
|
|
|
#if defined(OS_WIN)
|
2014-11-17 09:19:41 +00:00
|
|
|
template<>
|
|
|
|
struct Converter<Browser::UserTask> {
|
2015-05-22 11:11:22 +00:00
|
|
|
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
2014-11-17 09:19:41 +00:00
|
|
|
Browser::UserTask* out) {
|
|
|
|
mate::Dictionary dict;
|
|
|
|
if (!ConvertFromV8(isolate, val, &dict))
|
|
|
|
return false;
|
2014-11-17 09:26:44 +00:00
|
|
|
if (!dict.Get("program", &(out->program)) ||
|
|
|
|
!dict.Get("title", &(out->title)))
|
|
|
|
return false;
|
2014-11-17 09:35:51 +00:00
|
|
|
if (dict.Get("iconPath", &(out->icon_path)) &&
|
|
|
|
!dict.Get("iconIndex", &(out->icon_index)))
|
|
|
|
return false;
|
2014-11-17 09:26:44 +00:00
|
|
|
dict.Get("arguments", &(out->arguments));
|
|
|
|
dict.Get("description", &(out->description));
|
|
|
|
return true;
|
2014-11-17 09:19:41 +00:00
|
|
|
}
|
|
|
|
};
|
2014-11-17 09:35:51 +00:00
|
|
|
#endif
|
2014-11-17 09:19:41 +00:00
|
|
|
|
2015-06-11 15:22:07 +00:00
|
|
|
template<>
|
|
|
|
struct Converter<scoped_refptr<net::X509Certificate>> {
|
|
|
|
static v8::Local<v8::Value> ToV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const scoped_refptr<net::X509Certificate>& val) {
|
|
|
|
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
|
|
|
std::string encoded_data;
|
|
|
|
net::X509Certificate::GetPEMEncoded(
|
|
|
|
val->os_cert_handle(), &encoded_data);
|
|
|
|
dict.Set("data", encoded_data);
|
|
|
|
dict.Set("issuerName", val->issuer().GetDisplayName());
|
|
|
|
return dict.GetHandle();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-11-17 09:19:41 +00:00
|
|
|
} // namespace mate
|
|
|
|
|
|
|
|
|
2013-05-02 16:05:09 +00:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2014-08-19 13:26:45 +00:00
|
|
|
namespace {
|
|
|
|
|
2015-01-19 01:52:15 +00:00
|
|
|
// Return the path constant from string.
|
|
|
|
int GetPathConstant(const std::string& name) {
|
|
|
|
if (name == "appData")
|
|
|
|
return brightray::DIR_APP_DATA;
|
|
|
|
else if (name == "userData")
|
|
|
|
return brightray::DIR_USER_DATA;
|
2015-01-19 05:09:42 +00:00
|
|
|
else if (name == "cache")
|
|
|
|
return brightray::DIR_CACHE;
|
|
|
|
else if (name == "userCache")
|
|
|
|
return brightray::DIR_USER_CACHE;
|
2015-01-19 02:01:58 +00:00
|
|
|
else if (name == "home")
|
|
|
|
return base::DIR_HOME;
|
2015-01-19 05:31:09 +00:00
|
|
|
else if (name == "temp")
|
|
|
|
return base::DIR_TEMP;
|
|
|
|
else if (name == "userDesktop")
|
|
|
|
return base::DIR_USER_DESKTOP;
|
|
|
|
else if (name == "exe")
|
|
|
|
return base::FILE_EXE;
|
|
|
|
else if (name == "module")
|
|
|
|
return base::FILE_MODULE;
|
2015-01-19 01:52:15 +00:00
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-10-22 08:24:35 +00:00
|
|
|
bool NotificationCallbackWrapper(
|
|
|
|
const ProcessSingleton::NotificationCallback& callback,
|
2015-10-22 11:02:21 +00:00
|
|
|
const base::CommandLine::StringVector& cmd,
|
2015-10-22 09:12:09 +00:00
|
|
|
const base::FilePath& cwd) {
|
|
|
|
// Make sure the callback is called after app gets ready.
|
|
|
|
if (Browser::Get()->is_ready()) {
|
|
|
|
callback.Run(cmd, cwd);
|
|
|
|
} else {
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner(
|
|
|
|
base::ThreadTaskRunnerHandle::Get());
|
|
|
|
task_runner->PostTask(
|
|
|
|
FROM_HERE, base::Bind(base::IgnoreResult(callback), cmd, cwd));
|
|
|
|
}
|
|
|
|
// ProcessSingleton needs to know whether current process is quiting.
|
2015-10-22 08:24:35 +00:00
|
|
|
return !Browser::Get()->is_shutting_down();
|
|
|
|
}
|
|
|
|
|
2015-06-11 15:22:07 +00:00
|
|
|
void OnClientCertificateSelected(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
std::shared_ptr<content::ClientCertificateDelegate> delegate,
|
|
|
|
mate::Arguments* args) {
|
|
|
|
mate::Dictionary cert_data;
|
|
|
|
if (!(args->Length() == 1 && args->GetNext(&cert_data))) {
|
|
|
|
args->ThrowError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string encoded_data;
|
|
|
|
cert_data.Get("data", &encoded_data);
|
|
|
|
|
|
|
|
auto certs =
|
|
|
|
net::X509Certificate::CreateCertificateListFromBytes(
|
|
|
|
encoded_data.data(), encoded_data.size(),
|
|
|
|
net::X509Certificate::FORMAT_AUTO);
|
|
|
|
delegate->ContinueWithCertificate(certs[0].get());
|
|
|
|
}
|
|
|
|
|
2015-10-28 11:34:01 +00:00
|
|
|
void PassLoginInformation(scoped_refptr<LoginHandler> login_handler,
|
|
|
|
mate::Arguments* args) {
|
|
|
|
base::string16 username, password;
|
|
|
|
if (args->GetNext(&username) && args->GetNext(&password))
|
|
|
|
login_handler->Login(username, password);
|
|
|
|
else
|
|
|
|
login_handler->CancelAuth();
|
|
|
|
}
|
|
|
|
|
2014-08-19 13:26:45 +00:00
|
|
|
} // namespace
|
|
|
|
|
2014-04-17 09:13:46 +00:00
|
|
|
App::App() {
|
2013-05-03 02:53:54 +00:00
|
|
|
Browser::Get()->AddObserver(this);
|
2015-06-25 12:28:07 +00:00
|
|
|
content::GpuDataManager::GetInstance()->AddObserver(this);
|
2013-05-03 02:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
App::~App() {
|
|
|
|
Browser::Get()->RemoveObserver(this);
|
2015-06-25 12:28:07 +00:00
|
|
|
content::GpuDataManager::GetInstance()->RemoveObserver(this);
|
2013-05-03 02:53:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 03:33:42 +00:00
|
|
|
void App::OnBeforeQuit(bool* prevent_default) {
|
|
|
|
*prevent_default = Emit("before-quit");
|
|
|
|
}
|
|
|
|
|
2013-05-03 02:53:54 +00:00
|
|
|
void App::OnWillQuit(bool* prevent_default) {
|
|
|
|
*prevent_default = Emit("will-quit");
|
|
|
|
}
|
|
|
|
|
|
|
|
void App::OnWindowAllClosed() {
|
|
|
|
Emit("window-all-closed");
|
|
|
|
}
|
|
|
|
|
2014-09-25 13:47:54 +00:00
|
|
|
void App::OnQuit() {
|
|
|
|
Emit("quit");
|
2015-10-21 20:17:56 +00:00
|
|
|
|
2015-10-21 20:04:50 +00:00
|
|
|
if (process_singleton_.get()) {
|
2015-10-22 06:59:12 +00:00
|
|
|
process_singleton_->Cleanup();
|
2015-10-21 20:04:50 +00:00
|
|
|
process_singleton_.reset();
|
|
|
|
}
|
2014-09-25 13:47:54 +00:00
|
|
|
}
|
|
|
|
|
2013-05-30 08:03:10 +00:00
|
|
|
void App::OnOpenFile(bool* prevent_default, const std::string& file_path) {
|
2015-01-15 01:51:54 +00:00
|
|
|
*prevent_default = Emit("open-file", file_path);
|
2013-05-30 08:03:10 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 08:10:38 +00:00
|
|
|
void App::OnOpenURL(const std::string& url) {
|
2015-01-15 01:51:54 +00:00
|
|
|
Emit("open-url", url);
|
2013-07-10 08:10:38 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 02:05:53 +00:00
|
|
|
void App::OnActivate(bool has_visible_windows) {
|
|
|
|
Emit("activate", has_visible_windows);
|
2015-09-14 11:28:13 +00:00
|
|
|
}
|
|
|
|
|
2013-06-03 07:31:46 +00:00
|
|
|
void App::OnWillFinishLaunching() {
|
|
|
|
Emit("will-finish-launching");
|
|
|
|
}
|
|
|
|
|
2013-05-30 11:12:14 +00:00
|
|
|
void App::OnFinishLaunching() {
|
2015-06-24 08:14:49 +00:00
|
|
|
// Create the defaultSession.
|
|
|
|
v8::Locker locker(isolate());
|
|
|
|
v8::HandleScope handle_scope(isolate());
|
|
|
|
auto browser_context = static_cast<AtomBrowserContext*>(
|
|
|
|
AtomBrowserMainParts::Get()->browser_context());
|
|
|
|
auto handle = Session::CreateFrom(isolate(), browser_context);
|
|
|
|
default_session_.Reset(isolate(), handle.ToV8());
|
2015-10-21 20:17:56 +00:00
|
|
|
|
2013-12-27 03:08:26 +00:00
|
|
|
Emit("ready");
|
2013-05-30 11:12:14 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 15:22:07 +00:00
|
|
|
void App::OnSelectCertificate(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
net::SSLCertRequestInfo* cert_request_info,
|
|
|
|
scoped_ptr<content::ClientCertificateDelegate> delegate) {
|
|
|
|
std::shared_ptr<content::ClientCertificateDelegate>
|
|
|
|
shared_delegate(delegate.release());
|
|
|
|
bool prevent_default =
|
|
|
|
Emit("select-certificate",
|
|
|
|
api::WebContents::CreateFrom(isolate(), web_contents),
|
|
|
|
cert_request_info->host_and_port.ToString(),
|
|
|
|
cert_request_info->client_certs,
|
|
|
|
base::Bind(&OnClientCertificateSelected,
|
|
|
|
isolate(),
|
|
|
|
shared_delegate));
|
|
|
|
|
|
|
|
// Default to first certificate from the platform store.
|
|
|
|
if (!prevent_default)
|
|
|
|
shared_delegate->ContinueWithCertificate(
|
|
|
|
cert_request_info->client_certs[0].get());
|
|
|
|
}
|
|
|
|
|
2015-10-28 11:34:01 +00:00
|
|
|
void App::OnLogin(LoginHandler* login_handler) {
|
2015-10-28 13:00:39 +00:00
|
|
|
// Convert the args explicitly since they will be passed for twice.
|
|
|
|
v8::Locker locker(isolate());
|
|
|
|
v8::HandleScope handle_scope(isolate());
|
|
|
|
auto web_contents =
|
|
|
|
WebContents::CreateFrom(isolate(), login_handler->GetWebContents());
|
|
|
|
auto request = mate::ConvertToV8(isolate(), login_handler->request());
|
|
|
|
auto auth_info = mate::ConvertToV8(isolate(), login_handler->auth_info());
|
|
|
|
auto callback = mate::ConvertToV8(
|
|
|
|
isolate(),
|
2015-10-28 12:13:06 +00:00
|
|
|
base::Bind(&PassLoginInformation, make_scoped_refptr(login_handler)));
|
2015-10-28 11:34:01 +00:00
|
|
|
|
2015-10-28 13:00:39 +00:00
|
|
|
bool prevent_default =
|
|
|
|
Emit("login", web_contents, request, auth_info, callback);
|
|
|
|
|
|
|
|
// Also pass it to WebContents.
|
|
|
|
if (!prevent_default)
|
|
|
|
prevent_default =
|
|
|
|
web_contents->Emit("login", request, auth_info, callback);
|
|
|
|
|
|
|
|
// Default behavior is to always cancel the auth.
|
2015-10-28 11:34:01 +00:00
|
|
|
if (!prevent_default)
|
|
|
|
login_handler->CancelAuth();
|
|
|
|
}
|
|
|
|
|
2015-06-25 12:28:07 +00:00
|
|
|
void App::OnGpuProcessCrashed(base::TerminationStatus exit_code) {
|
2015-06-25 14:01:57 +00:00
|
|
|
Emit("gpu-process-crashed");
|
2015-06-25 12:28:07 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 04:24:58 +00:00
|
|
|
base::FilePath App::GetPath(mate::Arguments* args, const std::string& name) {
|
|
|
|
bool succeed = false;
|
2014-08-12 15:01:56 +00:00
|
|
|
base::FilePath path;
|
2015-01-19 01:52:15 +00:00
|
|
|
int key = GetPathConstant(name);
|
|
|
|
if (key >= 0)
|
2015-01-19 04:24:58 +00:00
|
|
|
succeed = PathService::Get(key, &path);
|
|
|
|
if (!succeed)
|
|
|
|
args->ThrowError("Failed to get path");
|
2015-01-19 01:11:27 +00:00
|
|
|
return path;
|
2014-08-12 15:01:56 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 04:24:58 +00:00
|
|
|
void App::SetPath(mate::Arguments* args,
|
|
|
|
const std::string& name,
|
|
|
|
const base::FilePath& path) {
|
|
|
|
bool succeed = false;
|
2015-01-19 01:52:15 +00:00
|
|
|
int key = GetPathConstant(name);
|
|
|
|
if (key >= 0)
|
2015-01-19 04:24:58 +00:00
|
|
|
succeed = PathService::Override(key, path);
|
|
|
|
if (!succeed)
|
|
|
|
args->ThrowError("Failed to set path");
|
2015-01-19 01:52:15 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 11:12:24 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2015-04-28 19:08:31 +00:00
|
|
|
void App::SetAppUserModelId(const std::string& app_id) {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
base::string16 app_id_utf16 = base::UTF8ToUTF16(app_id);
|
|
|
|
SetCurrentProcessExplicitAppUserModelID(app_id_utf16.c_str());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-10-16 23:45:54 +00:00
|
|
|
void App::AllowNTLMCredentialsForAllDomains(bool should_allow) {
|
|
|
|
auto browser_context = static_cast<AtomBrowserContext*>(
|
|
|
|
AtomBrowserMainParts::Get()->browser_context());
|
|
|
|
browser_context->AllowNTLMCredentialsForAllDomains(should_allow);
|
|
|
|
}
|
|
|
|
|
2015-09-16 08:16:21 +00:00
|
|
|
std::string App::GetLocale() {
|
|
|
|
return l10n_util::GetApplicationLocale("");
|
|
|
|
}
|
|
|
|
|
2015-06-23 15:40:41 +00:00
|
|
|
v8::Local<v8::Value> App::DefaultSession(v8::Isolate* isolate) {
|
2015-06-24 08:14:49 +00:00
|
|
|
if (default_session_.IsEmpty())
|
|
|
|
return v8::Null(isolate);
|
|
|
|
else
|
|
|
|
return v8::Local<v8::Value>::New(isolate, default_session_);
|
2015-06-23 15:40:41 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 08:24:35 +00:00
|
|
|
bool App::MakeSingleInstance(
|
|
|
|
const ProcessSingleton::NotificationCallback& callback) {
|
2015-10-22 06:59:12 +00:00
|
|
|
if (process_singleton_.get())
|
|
|
|
return false;
|
2015-10-21 20:17:56 +00:00
|
|
|
|
2015-10-22 06:59:12 +00:00
|
|
|
base::FilePath user_dir;
|
|
|
|
PathService::Get(brightray::DIR_USER_DATA, &user_dir);
|
2015-10-22 09:12:09 +00:00
|
|
|
process_singleton_.reset(new ProcessSingleton(
|
|
|
|
user_dir, base::Bind(NotificationCallbackWrapper, callback)));
|
2015-10-20 01:02:54 +00:00
|
|
|
|
2015-10-22 06:59:12 +00:00
|
|
|
switch (process_singleton_->NotifyOtherProcessOrCreate()) {
|
2015-10-19 23:21:03 +00:00
|
|
|
case ProcessSingleton::NotifyResult::LOCK_ERROR:
|
|
|
|
case ProcessSingleton::NotifyResult::PROFILE_IN_USE:
|
|
|
|
case ProcessSingleton::NotifyResult::PROCESS_NOTIFIED:
|
2015-10-22 06:59:12 +00:00
|
|
|
process_singleton_.reset();
|
2015-10-19 23:21:03 +00:00
|
|
|
return true;
|
2015-10-22 08:55:54 +00:00
|
|
|
case ProcessSingleton::NotifyResult::PROCESS_NONE:
|
|
|
|
default: // Shouldn't be needed, but VS warns if it is not there.
|
|
|
|
return false;
|
2015-10-19 23:21:03 +00:00
|
|
|
}
|
2015-10-19 21:43:04 +00:00
|
|
|
}
|
|
|
|
|
2014-04-17 09:13:46 +00:00
|
|
|
mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) {
|
2014-10-30 14:27:29 +00:00
|
|
|
auto browser = base::Unretained(Browser::Get());
|
2014-04-17 09:13:46 +00:00
|
|
|
return mate::ObjectTemplateBuilder(isolate)
|
2014-10-30 14:27:29 +00:00
|
|
|
.SetMethod("quit", base::Bind(&Browser::Quit, browser))
|
|
|
|
.SetMethod("focus", base::Bind(&Browser::Focus, browser))
|
|
|
|
.SetMethod("getVersion", base::Bind(&Browser::GetVersion, browser))
|
|
|
|
.SetMethod("setVersion", base::Bind(&Browser::SetVersion, browser))
|
|
|
|
.SetMethod("getName", base::Bind(&Browser::GetName, browser))
|
|
|
|
.SetMethod("setName", base::Bind(&Browser::SetName, browser))
|
|
|
|
.SetMethod("isReady", base::Bind(&Browser::is_ready, browser))
|
2014-11-17 05:05:06 +00:00
|
|
|
.SetMethod("addRecentDocument",
|
|
|
|
base::Bind(&Browser::AddRecentDocument, browser))
|
2014-11-17 08:13:47 +00:00
|
|
|
.SetMethod("clearRecentDocuments",
|
|
|
|
base::Bind(&Browser::ClearRecentDocuments, browser))
|
2014-11-17 09:19:41 +00:00
|
|
|
#if defined(OS_WIN)
|
2014-11-17 11:32:11 +00:00
|
|
|
.SetMethod("setUserTasks",
|
|
|
|
base::Bind(&Browser::SetUserTasks, browser))
|
2014-11-17 09:19:41 +00:00
|
|
|
#endif
|
2015-01-19 01:52:15 +00:00
|
|
|
.SetMethod("setPath", &App::SetPath)
|
|
|
|
.SetMethod("getPath", &App::GetPath)
|
2015-04-28 22:49:16 +00:00
|
|
|
.SetMethod("setDesktopName", &App::SetDesktopName)
|
2015-06-23 15:40:41 +00:00
|
|
|
.SetMethod("setAppUserModelId", &App::SetAppUserModelId)
|
2015-10-16 23:55:28 +00:00
|
|
|
.SetMethod("allowNTLMCredentialsForAllDomains",
|
|
|
|
&App::AllowNTLMCredentialsForAllDomains)
|
2015-09-16 08:16:21 +00:00
|
|
|
.SetMethod("getLocale", &App::GetLocale)
|
2015-10-20 00:36:21 +00:00
|
|
|
.SetMethod("makeSingleInstance", &App::MakeSingleInstance)
|
2015-06-23 15:40:41 +00:00
|
|
|
.SetProperty("defaultSession", &App::DefaultSession);
|
2013-05-30 11:24:47 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 05:43:48 +00:00
|
|
|
// static
|
2014-04-17 09:13:46 +00:00
|
|
|
mate::Handle<App> App::Create(v8::Isolate* isolate) {
|
|
|
|
return CreateHandle(isolate, new App);
|
2013-12-05 02:26:01 +00:00
|
|
|
}
|
|
|
|
|
2014-04-17 09:13:46 +00:00
|
|
|
} // namespace api
|
2013-12-05 02:32:58 +00:00
|
|
|
|
2014-04-17 09:13:46 +00:00
|
|
|
} // namespace atom
|
2013-12-05 02:32:58 +00:00
|
|
|
|
|
|
|
|
2014-04-17 09:13:46 +00:00
|
|
|
namespace {
|
2013-05-17 07:39:44 +00:00
|
|
|
|
2014-04-17 09:13:46 +00:00
|
|
|
void AppendSwitch(const std::string& switch_string, mate::Arguments* args) {
|
2015-03-10 22:27:27 +00:00
|
|
|
auto command_line = base::CommandLine::ForCurrentProcess();
|
2015-10-07 04:15:48 +00:00
|
|
|
|
|
|
|
if (switch_string == atom::switches::kPpapiFlashPath ||
|
|
|
|
switch_string == atom::switches::kClientCertificate ||
|
|
|
|
switch_string == switches::kLogNetLog) {
|
|
|
|
base::FilePath path;
|
|
|
|
args->GetNext(&path);
|
|
|
|
command_line->AppendSwitchPath(switch_string, path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-24 01:41:54 +00:00
|
|
|
std::string value;
|
2014-04-17 09:13:46 +00:00
|
|
|
if (args->GetNext(&value))
|
2015-03-10 22:27:27 +00:00
|
|
|
command_line->AppendSwitchASCII(switch_string, value);
|
2014-04-17 09:13:46 +00:00
|
|
|
else
|
2015-03-10 22:27:27 +00:00
|
|
|
command_line->AppendSwitch(switch_string);
|
2013-05-17 07:39:44 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 08:19:56 +00:00
|
|
|
#if defined(OS_MACOSX)
|
2014-04-17 09:13:46 +00:00
|
|
|
int DockBounce(const std::string& type) {
|
2013-08-06 08:19:56 +00:00
|
|
|
int request_id = -1;
|
|
|
|
if (type == "critical")
|
|
|
|
request_id = Browser::Get()->DockBounce(Browser::BOUNCE_CRITICAL);
|
|
|
|
else if (type == "informational")
|
|
|
|
request_id = Browser::Get()->DockBounce(Browser::BOUNCE_INFORMATIONAL);
|
2014-04-17 09:13:46 +00:00
|
|
|
return request_id;
|
2013-08-06 08:19:56 +00:00
|
|
|
}
|
2014-11-16 15:04:31 +00:00
|
|
|
|
|
|
|
void DockSetMenu(atom::api::Menu* menu) {
|
|
|
|
Browser::Get()->DockSetMenu(menu->model());
|
|
|
|
}
|
2014-04-17 09:13:46 +00:00
|
|
|
#endif
|
2013-08-06 08:19:56 +00:00
|
|
|
|
2015-05-22 11:11:22 +00:00
|
|
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context, void* priv) {
|
2014-06-29 12:48:44 +00:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
2015-03-10 22:27:27 +00:00
|
|
|
auto command_line = base::CommandLine::ForCurrentProcess();
|
2013-08-06 08:19:56 +00:00
|
|
|
|
2014-04-17 09:13:46 +00:00
|
|
|
mate::Dictionary dict(isolate, exports);
|
|
|
|
dict.Set("app", atom::api::App::Create(isolate));
|
|
|
|
dict.SetMethod("appendSwitch", &AppendSwitch);
|
|
|
|
dict.SetMethod("appendArgument",
|
2015-03-10 22:27:27 +00:00
|
|
|
base::Bind(&base::CommandLine::AppendArg,
|
2014-04-17 09:13:46 +00:00
|
|
|
base::Unretained(command_line)));
|
2013-08-06 08:19:56 +00:00
|
|
|
#if defined(OS_MACOSX)
|
2014-11-16 15:04:31 +00:00
|
|
|
auto browser = base::Unretained(Browser::Get());
|
2014-04-17 09:13:46 +00:00
|
|
|
dict.SetMethod("dockBounce", &DockBounce);
|
|
|
|
dict.SetMethod("dockCancelBounce",
|
2014-11-16 15:04:31 +00:00
|
|
|
base::Bind(&Browser::DockCancelBounce, browser));
|
2014-04-17 09:13:46 +00:00
|
|
|
dict.SetMethod("dockSetBadgeText",
|
2014-11-16 15:04:31 +00:00
|
|
|
base::Bind(&Browser::DockSetBadgeText, browser));
|
2014-04-17 09:13:46 +00:00
|
|
|
dict.SetMethod("dockGetBadgeText",
|
2014-11-16 15:04:31 +00:00
|
|
|
base::Bind(&Browser::DockGetBadgeText, browser));
|
|
|
|
dict.SetMethod("dockHide", base::Bind(&Browser::DockHide, browser));
|
|
|
|
dict.SetMethod("dockShow", base::Bind(&Browser::DockShow, browser));
|
|
|
|
dict.SetMethod("dockSetMenu", &DockSetMenu);
|
2014-04-17 09:13:46 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2014-06-29 12:48:44 +00:00
|
|
|
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_app, Initialize)
|