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
|
|
|
|
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"
|
2015-10-28 11:34:01 +00:00
|
|
|
#include "atom/browser/login_handler.h"
|
2016-06-02 12:49:29 +00:00
|
|
|
#include "atom/browser/relauncher.h"
|
|
|
|
#include "atom/common/atom_command_line.h"
|
2015-08-07 10:10:19 +00:00
|
|
|
#include "atom/common/native_mate_converters/callback.h"
|
2014-08-19 13:26:45 +00:00
|
|
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
2015-11-18 02:39:25 +00:00
|
|
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
2016-01-23 23:30:14 +00:00
|
|
|
#include "atom/common/native_mate_converters/image_converter.h"
|
2016-04-18 15:35:33 +00:00
|
|
|
#include "atom/common/native_mate_converters/net_converter.h"
|
|
|
|
#include "atom/common/native_mate_converters/value_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"
|
2016-04-18 05:11:31 +00:00
|
|
|
#include "base/files/file_util.h"
|
2014-08-12 15:01:56 +00:00
|
|
|
#include "base/path_service.h"
|
2016-05-10 23:47:50 +00:00
|
|
|
#include "base/strings/string_util.h"
|
2017-05-16 00:41:45 +00:00
|
|
|
#include "base/sys_info.h"
|
2015-01-19 01:11:27 +00:00
|
|
|
#include "brightray/browser/brightray_paths.h"
|
2017-02-17 08:33:46 +00:00
|
|
|
#include "chrome/browser/browser_process.h"
|
2016-11-02 18:57:16 +00:00
|
|
|
#include "chrome/browser/icon_manager.h"
|
2015-11-13 05:05:16 +00:00
|
|
|
#include "chrome/common/chrome_paths.h"
|
2017-05-30 17:06:08 +00:00
|
|
|
#include "content/browser/gpu/compositor_util.h"
|
2017-07-13 22:27:03 +00:00
|
|
|
#include "content/browser/gpu/gpu_data_manager_impl.h"
|
2016-07-11 21:04:56 +00:00
|
|
|
#include "content/public/browser/browser_accessibility_state.h"
|
2017-04-27 18:09:27 +00:00
|
|
|
#include "content/public/browser/browser_child_process_host.h"
|
2017-05-16 00:41:45 +00:00
|
|
|
#include "content/public/browser/child_process_data.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-11-18 02:39:25 +00:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
2015-10-07 04:15:48 +00:00
|
|
|
#include "content/public/common/content_switches.h"
|
2016-10-07 10:45:30 +00:00
|
|
|
#include "media/audio/audio_manager.h"
|
2014-04-17 09:13:46 +00:00
|
|
|
#include "native_mate/object_template_builder.h"
|
2017-10-23 07:54:17 +00:00
|
|
|
#include "net/ssl/client_cert_identity.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"
|
2016-01-23 23:30:14 +00:00
|
|
|
#include "ui/gfx/image/image.h"
|
2013-12-11 07:48:19 +00:00
|
|
|
|
2015-04-29 07:13:46 +00:00
|
|
|
#if defined(OS_WIN)
|
2016-08-12 09:31:17 +00:00
|
|
|
#include "atom/browser/ui/win/jump_list.h"
|
2015-04-29 07:13:46 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#endif
|
|
|
|
|
2017-08-31 14:37:12 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
#include "atom/browser/ui/cocoa/atom_bundle_mover.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
|
|
|
}
|
|
|
|
};
|
2016-08-12 09:31:17 +00:00
|
|
|
|
|
|
|
using atom::JumpListItem;
|
|
|
|
using atom::JumpListCategory;
|
|
|
|
using atom::JumpListResult;
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct Converter<JumpListItem::Type> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
|
|
|
JumpListItem::Type* out) {
|
|
|
|
std::string item_type;
|
|
|
|
if (!ConvertFromV8(isolate, val, &item_type))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (item_type == "task")
|
|
|
|
*out = JumpListItem::Type::TASK;
|
|
|
|
else if (item_type == "separator")
|
|
|
|
*out = JumpListItem::Type::SEPARATOR;
|
|
|
|
else if (item_type == "file")
|
|
|
|
*out = JumpListItem::Type::FILE;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
JumpListItem::Type val) {
|
|
|
|
std::string item_type;
|
|
|
|
switch (val) {
|
|
|
|
case JumpListItem::Type::TASK:
|
|
|
|
item_type = "task";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JumpListItem::Type::SEPARATOR:
|
|
|
|
item_type = "separator";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JumpListItem::Type::FILE:
|
|
|
|
item_type = "file";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return mate::ConvertToV8(isolate, item_type);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct Converter<JumpListItem> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
|
|
|
JumpListItem* out) {
|
|
|
|
mate::Dictionary dict;
|
|
|
|
if (!ConvertFromV8(isolate, val, &dict))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!dict.Get("type", &(out->type)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (out->type) {
|
|
|
|
case JumpListItem::Type::TASK:
|
|
|
|
if (!dict.Get("program", &(out->path)) ||
|
|
|
|
!dict.Get("title", &(out->title)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (dict.Get("iconPath", &(out->icon_path)) &&
|
|
|
|
!dict.Get("iconIndex", &(out->icon_index)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
dict.Get("args", &(out->arguments));
|
|
|
|
dict.Get("description", &(out->description));
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case JumpListItem::Type::SEPARATOR:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case JumpListItem::Type::FILE:
|
|
|
|
return dict.Get("path", &(out->path));
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
const JumpListItem& val) {
|
|
|
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
|
|
|
dict.Set("type", val.type);
|
|
|
|
|
|
|
|
switch (val.type) {
|
|
|
|
case JumpListItem::Type::TASK:
|
|
|
|
dict.Set("program", val.path);
|
|
|
|
dict.Set("args", val.arguments);
|
|
|
|
dict.Set("title", val.title);
|
|
|
|
dict.Set("iconPath", val.icon_path);
|
|
|
|
dict.Set("iconIndex", val.icon_index);
|
|
|
|
dict.Set("description", val.description);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JumpListItem::Type::SEPARATOR:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JumpListItem::Type::FILE:
|
|
|
|
dict.Set("path", val.path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return dict.GetHandle();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct Converter<JumpListCategory::Type> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
|
|
|
JumpListCategory::Type* out) {
|
|
|
|
std::string category_type;
|
|
|
|
if (!ConvertFromV8(isolate, val, &category_type))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (category_type == "tasks")
|
|
|
|
*out = JumpListCategory::Type::TASKS;
|
|
|
|
else if (category_type == "frequent")
|
|
|
|
*out = JumpListCategory::Type::FREQUENT;
|
|
|
|
else if (category_type == "recent")
|
|
|
|
*out = JumpListCategory::Type::RECENT;
|
|
|
|
else if (category_type == "custom")
|
|
|
|
*out = JumpListCategory::Type::CUSTOM;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
JumpListCategory::Type val) {
|
|
|
|
std::string category_type;
|
|
|
|
switch (val) {
|
|
|
|
case JumpListCategory::Type::TASKS:
|
|
|
|
category_type = "tasks";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JumpListCategory::Type::FREQUENT:
|
|
|
|
category_type = "frequent";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JumpListCategory::Type::RECENT:
|
|
|
|
category_type = "recent";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JumpListCategory::Type::CUSTOM:
|
|
|
|
category_type = "custom";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return mate::ConvertToV8(isolate, category_type);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct Converter<JumpListCategory> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
|
|
|
JumpListCategory* out) {
|
|
|
|
mate::Dictionary dict;
|
|
|
|
if (!ConvertFromV8(isolate, val, &dict))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (dict.Get("name", &(out->name)) && out->name.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!dict.Get("type", &(out->type))) {
|
|
|
|
if (out->name.empty())
|
|
|
|
out->type = JumpListCategory::Type::TASKS;
|
|
|
|
else
|
|
|
|
out->type = JumpListCategory::Type::CUSTOM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((out->type == JumpListCategory::Type::TASKS) ||
|
|
|
|
(out->type == JumpListCategory::Type::CUSTOM)) {
|
|
|
|
if (!dict.Get("items", &(out->items)))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// static
|
|
|
|
template<>
|
|
|
|
struct Converter<JumpListResult> {
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, JumpListResult val) {
|
|
|
|
std::string result_code;
|
|
|
|
switch (val) {
|
|
|
|
case JumpListResult::SUCCESS:
|
|
|
|
result_code = "ok";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JumpListResult::ARGUMENT_ERROR:
|
|
|
|
result_code = "argumentError";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JumpListResult::GENERIC_ERROR:
|
|
|
|
result_code = "error";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JumpListResult::CUSTOM_CATEGORY_SEPARATOR_ERROR:
|
|
|
|
result_code = "invalidSeparatorError";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JumpListResult::MISSING_FILE_TYPE_REGISTRATION_ERROR:
|
|
|
|
result_code = "fileTypeRegistrationError";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JumpListResult::CUSTOM_CATEGORY_ACCESS_DENIED_ERROR:
|
|
|
|
result_code = "customCategoryAccessDeniedError";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ConvertToV8(isolate, result_code);
|
|
|
|
}
|
|
|
|
};
|
2014-11-17 09:35:51 +00:00
|
|
|
#endif
|
2014-11-17 09:19:41 +00:00
|
|
|
|
2016-07-07 23:29:09 +00:00
|
|
|
template<>
|
|
|
|
struct Converter<Browser::LoginItemSettings> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
|
|
|
Browser::LoginItemSettings* out) {
|
|
|
|
mate::Dictionary dict;
|
|
|
|
if (!ConvertFromV8(isolate, val, &dict))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
dict.Get("openAtLogin", &(out->open_at_login));
|
|
|
|
dict.Get("openAsHidden", &(out->open_as_hidden));
|
2017-01-30 22:01:40 +00:00
|
|
|
dict.Get("path", &(out->path));
|
|
|
|
dict.Get("args", &(out->args));
|
2016-07-07 23:29:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
Browser::LoginItemSettings val) {
|
|
|
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
|
|
|
dict.Set("openAtLogin", val.open_at_login);
|
|
|
|
dict.Set("openAsHidden", val.open_as_hidden);
|
|
|
|
dict.Set("restoreState", val.restore_state);
|
2016-07-07 23:29:58 +00:00
|
|
|
dict.Set("wasOpenedAtLogin", val.opened_at_login);
|
|
|
|
dict.Set("wasOpenedAsHidden", val.opened_as_hidden);
|
2016-07-07 23:29:09 +00:00
|
|
|
return dict.GetHandle();
|
|
|
|
}
|
|
|
|
};
|
2014-11-17 09:19:41 +00:00
|
|
|
|
2016-11-30 07:30:03 +00:00
|
|
|
template<>
|
|
|
|
struct Converter<content::CertificateRequestResultType> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
|
|
|
content::CertificateRequestResultType* out) {
|
|
|
|
bool b;
|
|
|
|
if (!ConvertFromV8(isolate, val, &b))
|
|
|
|
return false;
|
|
|
|
*out = b ? content::CERTIFICATE_REQUEST_RESULT_TYPE_CONTINUE :
|
|
|
|
content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mate
|
2014-11-17 09:19:41 +00:00
|
|
|
|
2013-05-02 16:05:09 +00:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2014-08-19 13:26:45 +00:00
|
|
|
namespace {
|
|
|
|
|
2017-04-27 04:04:53 +00:00
|
|
|
class AppIdProcessIterator : public base::ProcessIterator {
|
|
|
|
public:
|
|
|
|
AppIdProcessIterator() : base::ProcessIterator(nullptr) {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool IncludeEntry() override {
|
|
|
|
return (entry().parent_pid() == base::GetCurrentProcId() ||
|
|
|
|
entry().pid() == base::GetCurrentProcId());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-11-04 06:59:18 +00:00
|
|
|
IconLoader::IconSize GetIconSizeByString(const std::string& size) {
|
2016-11-03 18:23:40 +00:00
|
|
|
if (size == "small") {
|
|
|
|
return IconLoader::IconSize::SMALL;
|
|
|
|
} else if (size == "large") {
|
|
|
|
return IconLoader::IconSize::LARGE;
|
|
|
|
}
|
|
|
|
return IconLoader::IconSize::NORMAL;
|
2016-11-03 18:43:53 +00:00
|
|
|
}
|
2016-11-03 18:23:40 +00:00
|
|
|
|
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;
|
2017-08-03 22:50:56 +00:00
|
|
|
else if (name == "logs")
|
|
|
|
return brightray::DIR_APP_LOGS;
|
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;
|
2015-11-13 05:05:16 +00:00
|
|
|
else if (name == "userDesktop" || name == "desktop")
|
2015-01-19 05:31:09 +00:00
|
|
|
return base::DIR_USER_DESKTOP;
|
|
|
|
else if (name == "exe")
|
|
|
|
return base::FILE_EXE;
|
|
|
|
else if (name == "module")
|
|
|
|
return base::FILE_MODULE;
|
2015-11-13 05:05:16 +00:00
|
|
|
else if (name == "documents")
|
|
|
|
return chrome::DIR_USER_DOCUMENTS;
|
|
|
|
else if (name == "downloads")
|
|
|
|
return chrome::DIR_DEFAULT_DOWNLOADS;
|
|
|
|
else if (name == "music")
|
|
|
|
return chrome::DIR_USER_MUSIC;
|
|
|
|
else if (name == "pictures")
|
|
|
|
return chrome::DIR_USER_PICTURES;
|
|
|
|
else if (name == "videos")
|
|
|
|
return chrome::DIR_USER_VIDEOS;
|
2016-06-08 20:37:27 +00:00
|
|
|
else if (name == "pepperFlashSystemPlugin")
|
|
|
|
return chrome::FILE_PEPPER_FLASH_SYSTEM_PLUGIN;
|
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()) {
|
2017-09-20 02:40:49 +00:00
|
|
|
callback.Run(cmd, cwd);
|
2015-10-22 09:12:09 +00:00
|
|
|
} 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();
|
|
|
|
}
|
|
|
|
|
2017-10-23 07:54:17 +00:00
|
|
|
void GotPrivateKey(std::shared_ptr<content::ClientCertificateDelegate> delegate,
|
|
|
|
scoped_refptr<net::X509Certificate> cert,
|
|
|
|
scoped_refptr<net::SSLPrivateKey> private_key) {
|
|
|
|
delegate->ContinueWithCertificate(cert, private_key);
|
|
|
|
}
|
|
|
|
|
2015-06-11 15:22:07 +00:00
|
|
|
void OnClientCertificateSelected(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
std::shared_ptr<content::ClientCertificateDelegate> delegate,
|
2017-10-23 07:54:17 +00:00
|
|
|
std::shared_ptr<net::ClientCertIdentityList> identities,
|
2015-06-11 15:22:07 +00:00
|
|
|
mate::Arguments* args) {
|
2016-12-07 10:03:56 +00:00
|
|
|
if (args->Length() == 2) {
|
2017-08-31 20:18:09 +00:00
|
|
|
delegate->ContinueWithCertificate(nullptr, nullptr);
|
2016-12-07 10:03:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> val;
|
|
|
|
args->GetNext(&val);
|
|
|
|
if (val->IsNull()) {
|
2017-08-31 20:18:09 +00:00
|
|
|
delegate->ContinueWithCertificate(nullptr, nullptr);
|
2015-06-11 15:22:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-07 10:03:56 +00:00
|
|
|
mate::Dictionary cert_data;
|
|
|
|
if (!mate::ConvertFromV8(isolate, val, &cert_data)) {
|
|
|
|
args->ThrowError("Must pass valid certificate object.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-17 11:48:09 +00:00
|
|
|
std::string data;
|
2016-03-05 09:57:46 +00:00
|
|
|
if (!cert_data.Get("data", &data))
|
|
|
|
return;
|
2015-06-11 15:22:07 +00:00
|
|
|
|
2016-03-05 09:57:46 +00:00
|
|
|
auto certs = net::X509Certificate::CreateCertificateListFromBytes(
|
2016-08-17 11:48:09 +00:00
|
|
|
data.c_str(), data.length(), net::X509Certificate::FORMAT_AUTO);
|
2017-08-31 20:18:09 +00:00
|
|
|
if (!certs.empty()) {
|
|
|
|
scoped_refptr<net::X509Certificate> cert(certs[0].get());
|
2017-10-23 07:54:17 +00:00
|
|
|
for (size_t i = 0; i < identities->size(); ++i) {
|
|
|
|
if (cert->Equals((*identities)[i]->certificate())) {
|
|
|
|
net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
|
|
|
|
std::move((*identities)[i]),
|
|
|
|
base::Bind(&GotPrivateKey, delegate, std::move(cert)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-08-31 20:18:09 +00:00
|
|
|
}
|
2015-06-11 15:22:07 +00:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-04-19 05:17:28 +00:00
|
|
|
#if defined(USE_NSS_CERTS)
|
2016-04-18 15:35:33 +00:00
|
|
|
int ImportIntoCertStore(
|
2016-04-18 05:11:31 +00:00
|
|
|
CertificateManagerModel* model,
|
2016-04-18 15:35:33 +00:00
|
|
|
const base::DictionaryValue& options) {
|
|
|
|
std::string file_data, cert_path;
|
|
|
|
base::string16 password;
|
|
|
|
net::CertificateList imported_certs;
|
2016-04-19 05:17:28 +00:00
|
|
|
int rv = -1;
|
2016-04-20 03:15:49 +00:00
|
|
|
options.GetString("certificate", &cert_path);
|
2016-04-18 15:35:33 +00:00
|
|
|
options.GetString("password", &password);
|
|
|
|
|
|
|
|
if (!cert_path.empty()) {
|
|
|
|
if (base::ReadFileToString(base::FilePath(cert_path), &file_data)) {
|
2017-04-17 08:17:02 +00:00
|
|
|
auto module = model->cert_db()->GetPrivateSlot();
|
|
|
|
rv = model->ImportFromPKCS12(module.get(),
|
2016-04-18 15:35:33 +00:00
|
|
|
file_data,
|
|
|
|
password,
|
|
|
|
true,
|
|
|
|
&imported_certs);
|
|
|
|
if (imported_certs.size() > 1) {
|
|
|
|
auto it = imported_certs.begin();
|
2016-04-18 16:56:37 +00:00
|
|
|
++it; // skip first which would be the client certificate.
|
2016-04-18 15:35:33 +00:00
|
|
|
for (; it != imported_certs.end(); ++it)
|
|
|
|
rv &= model->SetCertTrust(it->get(),
|
2016-04-18 16:56:37 +00:00
|
|
|
net::CA_CERT,
|
|
|
|
net::NSSCertDatabase::TRUSTED_SSL);
|
2016-04-18 15:35:33 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-18 05:11:31 +00:00
|
|
|
}
|
2016-04-18 15:35:33 +00:00
|
|
|
return rv;
|
2016-04-18 05:11:31 +00:00
|
|
|
}
|
2016-04-19 05:17:28 +00:00
|
|
|
#endif
|
2016-04-18 05:11:31 +00:00
|
|
|
|
2016-11-06 12:21:21 +00:00
|
|
|
void OnIconDataAvailable(v8::Isolate* isolate,
|
|
|
|
const App::FileIconCallback& callback,
|
2016-11-02 18:57:16 +00:00
|
|
|
gfx::Image* icon) {
|
2016-11-06 09:58:01 +00:00
|
|
|
v8::Locker locker(isolate);
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
|
2016-11-05 18:23:49 +00:00
|
|
|
if (icon && !icon->IsEmpty()) {
|
|
|
|
callback.Run(v8::Null(isolate), *icon);
|
|
|
|
} else {
|
|
|
|
v8::Local<v8::String> error_message =
|
|
|
|
v8::String::NewFromUtf8(isolate, "Failed to get file icon.");
|
|
|
|
callback.Run(v8::Exception::Error(error_message), gfx::Image());
|
|
|
|
}
|
2016-11-02 18:57:16 +00:00
|
|
|
}
|
|
|
|
|
2014-08-19 13:26:45 +00:00
|
|
|
} // namespace
|
|
|
|
|
2016-04-25 01:17:54 +00:00
|
|
|
App::App(v8::Isolate* isolate) {
|
2015-11-18 02:07:03 +00:00
|
|
|
static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())->set_delegate(this);
|
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);
|
2017-05-25 04:15:34 +00:00
|
|
|
base::ProcessId pid = base::GetCurrentProcId();
|
2017-05-16 00:41:45 +00:00
|
|
|
std::unique_ptr<atom::ProcessMetric> process_metric(
|
2017-05-26 14:51:17 +00:00
|
|
|
new atom::ProcessMetric(
|
2017-05-26 15:53:26 +00:00
|
|
|
content::PROCESS_TYPE_BROWSER,
|
2017-05-26 14:51:17 +00:00
|
|
|
pid,
|
|
|
|
base::ProcessMetrics::CreateCurrentProcessMetrics()));
|
2017-05-16 00:41:45 +00:00
|
|
|
app_metrics_[pid] = std::move(process_metric);
|
2016-04-25 01:17:54 +00:00
|
|
|
Init(isolate);
|
2013-05-03 02:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
App::~App() {
|
2015-11-18 02:07:03 +00:00
|
|
|
static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())->set_delegate(
|
|
|
|
nullptr);
|
2013-05-03 02:53:54 +00:00
|
|
|
Browser::Get()->RemoveObserver(this);
|
2015-06-25 12:28:07 +00:00
|
|
|
content::GpuDataManager::GetInstance()->RemoveObserver(this);
|
2017-05-16 00:41:45 +00:00
|
|
|
content::BrowserChildProcessObserver::Remove(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");
|
|
|
|
}
|
|
|
|
|
2015-12-10 02:19:51 +00:00
|
|
|
void App::OnQuit() {
|
|
|
|
int exitCode = AtomBrowserMainParts::Get()->GetExitCode();
|
|
|
|
Emit("quit", exitCode);
|
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");
|
|
|
|
}
|
|
|
|
|
2016-09-01 00:17:44 +00:00
|
|
|
void App::OnFinishLaunching(const base::DictionaryValue& launch_info) {
|
2016-10-07 20:44:31 +00:00
|
|
|
#if defined(OS_LINUX)
|
2016-10-07 10:45:30 +00:00
|
|
|
// Set the application name for audio streams shown in external
|
|
|
|
// applications. Only affects pulseaudio currently.
|
|
|
|
media::AudioManager::SetGlobalAppName(Browser::Get()->GetName());
|
2016-10-07 20:44:31 +00:00
|
|
|
#endif
|
2016-09-01 00:17:44 +00:00
|
|
|
Emit("ready", launch_info);
|
2017-09-14 13:08:18 +00:00
|
|
|
}
|
2017-09-14 12:33:13 +00:00
|
|
|
|
2016-07-11 21:32:14 +00:00
|
|
|
void App::OnAccessibilitySupportChanged() {
|
|
|
|
Emit("accessibility-support-changed", IsAccessibilitySupportEnabled());
|
2016-07-11 21:04:56 +00:00
|
|
|
}
|
|
|
|
|
2017-12-22 15:55:57 +00:00
|
|
|
void App::OnPreMainMessageLoopRun() {
|
|
|
|
content::BrowserChildProcessObserver::Add(this);
|
|
|
|
}
|
|
|
|
|
2016-05-05 03:26:23 +00:00
|
|
|
#if defined(OS_MACOSX)
|
2017-06-26 19:14:44 +00:00
|
|
|
void App::OnWillContinueUserActivity(
|
|
|
|
bool* prevent_default,
|
|
|
|
const std::string& type) {
|
|
|
|
*prevent_default = Emit("will-continue-activity", type);
|
|
|
|
}
|
2017-09-14 07:12:34 +00:00
|
|
|
|
2017-06-26 19:14:44 +00:00
|
|
|
void App::OnDidFailToContinueUserActivity(
|
|
|
|
const std::string& type,
|
|
|
|
const std::string& error) {
|
|
|
|
Emit("continue-activity-error", type, error);
|
|
|
|
}
|
2017-09-14 07:12:34 +00:00
|
|
|
|
2016-05-05 03:26:23 +00:00
|
|
|
void App::OnContinueUserActivity(
|
|
|
|
bool* prevent_default,
|
|
|
|
const std::string& type,
|
2016-05-05 07:26:44 +00:00
|
|
|
const base::DictionaryValue& user_info) {
|
2016-04-30 05:08:19 +00:00
|
|
|
*prevent_default = Emit("continue-activity", type, user_info);
|
2016-04-30 00:36:04 +00:00
|
|
|
}
|
2017-09-14 07:12:34 +00:00
|
|
|
|
2017-06-26 19:14:44 +00:00
|
|
|
void App::OnUserActivityWasContinued(
|
|
|
|
const std::string& type,
|
|
|
|
const base::DictionaryValue& user_info) {
|
|
|
|
Emit("activity-was-continued", type, user_info);
|
|
|
|
}
|
2017-09-14 07:12:34 +00:00
|
|
|
|
2017-06-26 19:14:44 +00:00
|
|
|
void App::OnUpdateUserActivityState(
|
2017-08-09 15:09:47 +00:00
|
|
|
bool* prevent_default,
|
2017-06-26 19:14:44 +00:00
|
|
|
const std::string& type,
|
|
|
|
const base::DictionaryValue& user_info) {
|
2017-08-09 15:09:47 +00:00
|
|
|
*prevent_default = Emit("update-activity-state", type, user_info);
|
2017-06-26 19:14:44 +00:00
|
|
|
}
|
2017-09-14 07:12:34 +00:00
|
|
|
|
2017-06-11 08:19:01 +00:00
|
|
|
void App::OnNewWindowForTab() {
|
|
|
|
Emit("new-window-for-tab");
|
|
|
|
}
|
2016-05-05 03:26:23 +00:00
|
|
|
#endif
|
2016-04-30 00:36:04 +00:00
|
|
|
|
2016-06-08 13:52:21 +00:00
|
|
|
void App::OnLogin(LoginHandler* login_handler,
|
|
|
|
const base::DictionaryValue& request_details) {
|
2015-10-28 13:00:39 +00:00
|
|
|
v8::Locker locker(isolate());
|
|
|
|
v8::HandleScope handle_scope(isolate());
|
2017-11-19 22:08:11 +00:00
|
|
|
bool prevent_default = false;
|
|
|
|
content::WebContents* web_contents = login_handler->GetWebContents();
|
|
|
|
if (web_contents) {
|
|
|
|
prevent_default =
|
|
|
|
Emit("login",
|
|
|
|
WebContents::CreateFrom(isolate(), web_contents),
|
|
|
|
request_details,
|
|
|
|
login_handler->auth_info(),
|
|
|
|
base::Bind(&PassLoginInformation,
|
|
|
|
make_scoped_refptr(login_handler)));
|
|
|
|
}
|
2015-10-28 11:34:01 +00:00
|
|
|
|
2015-10-28 13:00:39 +00:00
|
|
|
// Default behavior is to always cancel the auth.
|
2015-10-28 11:34:01 +00:00
|
|
|
if (!prevent_default)
|
|
|
|
login_handler->CancelAuth();
|
|
|
|
}
|
|
|
|
|
2017-12-07 04:12:38 +00:00
|
|
|
bool App::CanCreateWindow(
|
|
|
|
content::RenderFrameHost* opener,
|
|
|
|
const GURL& opener_url,
|
|
|
|
const GURL& opener_top_level_frame_url,
|
|
|
|
const GURL& source_origin,
|
|
|
|
content::mojom::WindowContainerType container_type,
|
2016-10-09 23:30:38 +00:00
|
|
|
const GURL& target_url,
|
2017-12-07 04:12:38 +00:00
|
|
|
const content::Referrer& referrer,
|
2016-10-09 23:30:38 +00:00
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
2017-12-07 04:12:38 +00:00
|
|
|
const blink::mojom::WindowFeatures& features,
|
|
|
|
const std::vector<std::string>& additional_features,
|
2017-08-12 17:45:31 +00:00
|
|
|
const scoped_refptr<content::ResourceRequestBody>& body,
|
2017-12-07 04:12:38 +00:00
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access) {
|
2016-03-31 14:21:18 +00:00
|
|
|
v8::Locker locker(isolate());
|
|
|
|
v8::HandleScope handle_scope(isolate());
|
|
|
|
content::WebContents* web_contents =
|
2017-08-04 21:38:06 +00:00
|
|
|
content::WebContents::FromRenderFrameHost(opener);
|
2016-03-31 14:21:18 +00:00
|
|
|
if (web_contents) {
|
|
|
|
auto api_web_contents = WebContents::CreateFrom(isolate(), web_contents);
|
2017-12-07 04:12:38 +00:00
|
|
|
api_web_contents->OnCreateWindow(target_url, frame_name, disposition,
|
|
|
|
additional_features, body);
|
2016-03-31 14:21:18 +00:00
|
|
|
}
|
2017-12-07 04:12:38 +00:00
|
|
|
|
|
|
|
return false;
|
2016-03-31 14:21:18 +00:00
|
|
|
}
|
|
|
|
|
2015-11-18 02:39:25 +00:00
|
|
|
void App::AllowCertificateError(
|
2016-03-08 14:28:53 +00:00
|
|
|
content::WebContents* web_contents,
|
2015-11-18 02:39:25 +00:00
|
|
|
int cert_error,
|
|
|
|
const net::SSLInfo& ssl_info,
|
|
|
|
const GURL& request_url,
|
|
|
|
content::ResourceType resource_type,
|
|
|
|
bool overridable,
|
|
|
|
bool strict_enforcement,
|
|
|
|
bool expired_previous_decision,
|
2016-11-30 07:30:03 +00:00
|
|
|
const base::Callback<void(content::CertificateRequestResultType)>&
|
|
|
|
callback) {
|
2015-11-18 02:39:25 +00:00
|
|
|
v8::Locker locker(isolate());
|
|
|
|
v8::HandleScope handle_scope(isolate());
|
|
|
|
bool prevent_default = Emit("certificate-error",
|
|
|
|
WebContents::CreateFrom(isolate(), web_contents),
|
|
|
|
request_url,
|
2015-11-18 03:35:26 +00:00
|
|
|
net::ErrorToString(cert_error),
|
2015-11-18 02:39:25 +00:00
|
|
|
ssl_info.cert,
|
|
|
|
callback);
|
|
|
|
|
|
|
|
// Deny the certificate by default.
|
|
|
|
if (!prevent_default)
|
2016-11-30 07:30:03 +00:00
|
|
|
callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
|
2015-11-18 02:39:25 +00:00
|
|
|
}
|
|
|
|
|
2015-11-18 02:07:03 +00:00
|
|
|
void App::SelectClientCertificate(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
net::SSLCertRequestInfo* cert_request_info,
|
2017-08-20 21:35:04 +00:00
|
|
|
net::ClientCertIdentityList identities,
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<content::ClientCertificateDelegate> delegate) {
|
2015-11-18 02:07:03 +00:00
|
|
|
std::shared_ptr<content::ClientCertificateDelegate>
|
|
|
|
shared_delegate(delegate.release());
|
2017-08-20 21:35:04 +00:00
|
|
|
|
|
|
|
// Convert the ClientCertIdentityList to a CertificateList
|
|
|
|
// to avoid changes in the API.
|
|
|
|
auto client_certs = net::CertificateList();
|
|
|
|
for (const std::unique_ptr<net::ClientCertIdentity>& identity : identities)
|
|
|
|
client_certs.push_back(identity->certificate());
|
|
|
|
|
2017-10-23 07:54:17 +00:00
|
|
|
auto shared_identities =
|
|
|
|
std::make_shared<net::ClientCertIdentityList>(std::move(identities));
|
|
|
|
|
2015-11-18 02:07:03 +00:00
|
|
|
bool prevent_default =
|
2015-11-18 02:10:21 +00:00
|
|
|
Emit("select-client-certificate",
|
2015-11-18 02:39:25 +00:00
|
|
|
WebContents::CreateFrom(isolate(), web_contents),
|
2017-10-23 07:54:17 +00:00
|
|
|
cert_request_info->host_and_port.ToString(), std::move(client_certs),
|
|
|
|
base::Bind(&OnClientCertificateSelected, isolate(), shared_delegate,
|
|
|
|
shared_identities));
|
2015-11-18 02:07:03 +00:00
|
|
|
|
|
|
|
// Default to first certificate from the platform store.
|
2017-08-31 20:18:09 +00:00
|
|
|
if (!prevent_default) {
|
2017-10-23 07:54:17 +00:00
|
|
|
scoped_refptr<net::X509Certificate> cert =
|
|
|
|
(*shared_identities)[0]->certificate();
|
|
|
|
net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
|
|
|
|
std::move((*shared_identities)[0]),
|
|
|
|
base::Bind(&GotPrivateKey, shared_delegate, std::move(cert)));
|
2017-08-31 20:18:09 +00:00
|
|
|
}
|
2015-11-18 02:07:03 +00:00
|
|
|
}
|
|
|
|
|
2016-09-18 00:00:45 +00:00
|
|
|
void App::OnGpuProcessCrashed(base::TerminationStatus status) {
|
|
|
|
Emit("gpu-process-crashed",
|
|
|
|
status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
|
2015-06-25 12:28:07 +00:00
|
|
|
}
|
|
|
|
|
2017-05-16 00:41:45 +00:00
|
|
|
void App::BrowserChildProcessLaunchedAndConnected(
|
|
|
|
const content::ChildProcessData& data) {
|
2017-05-26 14:51:17 +00:00
|
|
|
ChildProcessLaunched(data.process_type, data.handle);
|
2017-05-16 00:41:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void App::BrowserChildProcessHostDisconnected(
|
|
|
|
const content::ChildProcessData& data) {
|
2017-05-26 14:51:17 +00:00
|
|
|
ChildProcessDisconnected(base::GetProcId(data.handle));
|
2017-05-16 00:41:45 +00:00
|
|
|
}
|
|
|
|
|
2017-05-26 15:32:08 +00:00
|
|
|
void App::BrowserChildProcessCrashed(const content::ChildProcessData& data,
|
|
|
|
int exit_code) {
|
|
|
|
ChildProcessDisconnected(base::GetProcId(data.handle));
|
|
|
|
}
|
|
|
|
|
|
|
|
void App::BrowserChildProcessKilled(const content::ChildProcessData& data,
|
|
|
|
int exit_code) {
|
|
|
|
ChildProcessDisconnected(base::GetProcId(data.handle));
|
|
|
|
}
|
|
|
|
|
2017-05-26 14:51:17 +00:00
|
|
|
void App::RenderProcessReady(content::RenderProcessHost* host) {
|
|
|
|
ChildProcessLaunched(content::PROCESS_TYPE_RENDERER, host->GetHandle());
|
2017-05-16 00:41:45 +00:00
|
|
|
}
|
|
|
|
|
2017-05-26 15:32:08 +00:00
|
|
|
void App::RenderProcessDisconnected(base::ProcessId host_pid) {
|
|
|
|
ChildProcessDisconnected(host_pid);
|
2017-05-16 00:41:45 +00:00
|
|
|
}
|
|
|
|
|
2017-05-26 15:32:08 +00:00
|
|
|
void App::ChildProcessLaunched(int process_type, base::ProcessHandle handle) {
|
2017-05-20 04:28:52 +00:00
|
|
|
auto pid = base::GetProcId(handle);
|
2017-05-16 00:41:45 +00:00
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
2017-05-26 14:51:17 +00:00
|
|
|
std::unique_ptr<base::ProcessMetrics> metrics(
|
2017-05-26 16:25:35 +00:00
|
|
|
base::ProcessMetrics::CreateProcessMetrics(
|
|
|
|
handle, content::BrowserChildProcessHost::GetPortProvider()));
|
2017-05-16 00:41:45 +00:00
|
|
|
#else
|
2017-05-26 14:51:17 +00:00
|
|
|
std::unique_ptr<base::ProcessMetrics> metrics(
|
2017-05-26 16:25:35 +00:00
|
|
|
base::ProcessMetrics::CreateProcessMetrics(handle));
|
2017-05-16 00:41:45 +00:00
|
|
|
#endif
|
|
|
|
std::unique_ptr<atom::ProcessMetric> process_metric(
|
2017-05-26 15:53:26 +00:00
|
|
|
new atom::ProcessMetric(process_type, pid, std::move(metrics)));
|
2017-05-16 00:41:45 +00:00
|
|
|
app_metrics_[pid] = std::move(process_metric);
|
|
|
|
}
|
|
|
|
|
2017-05-26 14:51:17 +00:00
|
|
|
void App::ChildProcessDisconnected(base::ProcessId pid) {
|
2017-05-16 00:41:45 +00:00
|
|
|
app_metrics_.erase(pid);
|
|
|
|
}
|
|
|
|
|
2017-04-13 14:26:42 +00:00
|
|
|
base::FilePath App::GetAppPath() const {
|
2017-04-04 00:36:01 +00:00
|
|
|
return app_path_;
|
|
|
|
}
|
|
|
|
|
2017-04-13 01:59:12 +00:00
|
|
|
void App::SetAppPath(const base::FilePath& app_path) {
|
2017-04-04 00:36:01 +00:00
|
|
|
app_path_ = app_path;
|
|
|
|
}
|
|
|
|
|
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);
|
2015-11-13 05:05:16 +00:00
|
|
|
if (!succeed)
|
2016-10-06 16:14:16 +00:00
|
|
|
args->ThrowError("Failed to get '" + name + "' 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) {
|
2016-04-21 05:37:29 +00:00
|
|
|
if (!path.IsAbsolute()) {
|
2016-10-06 16:14:16 +00:00
|
|
|
args->ThrowError("Path must be absolute");
|
2016-04-21 05:37:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-19 04:24:58 +00:00
|
|
|
bool succeed = false;
|
2015-01-19 01:52:15 +00:00
|
|
|
int key = GetPathConstant(name);
|
|
|
|
if (key >= 0)
|
2016-04-21 05:37:29 +00:00
|
|
|
succeed = PathService::OverrideAndCreateIfNeeded(key, path, true, false);
|
2015-01-19 04:24:58 +00:00
|
|
|
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)
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
2014-09-18 11:12:24 +00:00
|
|
|
env->SetVar("CHROME_DESKTOP", desktop_name);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-09-16 08:16:21 +00:00
|
|
|
std::string App::GetLocale() {
|
2017-12-16 09:21:29 +00:00
|
|
|
return g_browser_process->GetApplicationLocale();
|
2015-09-16 08:16:21 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 08:24:35 +00:00
|
|
|
bool App::MakeSingleInstance(
|
|
|
|
const ProcessSingleton::NotificationCallback& callback) {
|
2017-12-11 07:55:49 +00:00
|
|
|
auto process_singleton = AtomBrowserMainParts::Get()->process_singleton();
|
|
|
|
if (process_singleton_created_)
|
2015-10-22 06:59:12 +00:00
|
|
|
return false;
|
2015-10-21 20:17:56 +00:00
|
|
|
|
2017-12-11 07:55:49 +00:00
|
|
|
process_singleton->RegisterSingletonNotificationCallback(
|
|
|
|
base::Bind(NotificationCallbackWrapper, callback));
|
2015-10-20 01:02:54 +00:00
|
|
|
|
2017-12-11 07:55:49 +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:
|
2017-12-11 07:55:49 +00:00
|
|
|
case ProcessSingleton::NotifyResult::PROCESS_NOTIFIED: {
|
|
|
|
process_singleton_created_ = true;
|
2015-10-19 23:21:03 +00:00
|
|
|
return true;
|
2017-12-11 07:55:49 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2016-05-26 18:07:19 +00:00
|
|
|
void App::ReleaseSingleInstance() {
|
2017-12-11 07:55:49 +00:00
|
|
|
auto process_singleton = AtomBrowserMainParts::Get()->process_singleton();
|
|
|
|
if (process_singleton) {
|
|
|
|
process_singleton->Cleanup();
|
2016-05-26 18:07:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-02 12:49:29 +00:00
|
|
|
bool App::Relaunch(mate::Arguments* js_args) {
|
|
|
|
// Parse parameters.
|
|
|
|
bool override_argv = false;
|
|
|
|
base::FilePath exec_path;
|
|
|
|
relauncher::StringVector args;
|
|
|
|
|
|
|
|
mate::Dictionary options;
|
|
|
|
if (js_args->GetNext(&options)) {
|
2016-06-03 03:08:45 +00:00
|
|
|
if (options.Get("execPath", &exec_path) | options.Get("args", &args))
|
2016-06-02 12:49:29 +00:00
|
|
|
override_argv = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!override_argv) {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
const relauncher::StringVector& argv = atom::AtomCommandLine::wargv();
|
|
|
|
#else
|
|
|
|
const relauncher::StringVector& argv = atom::AtomCommandLine::argv();
|
|
|
|
#endif
|
|
|
|
return relauncher::RelaunchApp(argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
relauncher::StringVector argv;
|
|
|
|
argv.reserve(1 + args.size());
|
|
|
|
|
|
|
|
if (exec_path.empty()) {
|
|
|
|
base::FilePath current_exe_path;
|
|
|
|
PathService::Get(base::FILE_EXE, ¤t_exe_path);
|
|
|
|
argv.push_back(current_exe_path.value());
|
|
|
|
} else {
|
|
|
|
argv.push_back(exec_path.value());
|
|
|
|
}
|
|
|
|
|
|
|
|
argv.insert(argv.end(), args.begin(), args.end());
|
|
|
|
|
|
|
|
return relauncher::RelaunchApp(argv);
|
|
|
|
}
|
|
|
|
|
2016-06-06 11:19:55 +00:00
|
|
|
void App::DisableHardwareAcceleration(mate::Arguments* args) {
|
|
|
|
if (Browser::Get()->is_ready()) {
|
|
|
|
args->ThrowError("app.disableHardwareAcceleration() can only be called "
|
|
|
|
"before app is ready");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
content::GpuDataManager::GetInstance()->DisableHardwareAcceleration();
|
|
|
|
}
|
|
|
|
|
2017-07-13 22:27:03 +00:00
|
|
|
void App::DisableDomainBlockingFor3DAPIs(mate::Arguments* args) {
|
|
|
|
if (Browser::Get()->is_ready()) {
|
|
|
|
args->ThrowError(
|
|
|
|
"app.disableDomainBlockingFor3DAPIs() can only be called "
|
|
|
|
"before app is ready");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
content::GpuDataManagerImpl::GetInstance()
|
|
|
|
->DisableDomainBlockingFor3DAPIsForTesting();
|
|
|
|
}
|
|
|
|
|
2016-07-11 21:32:14 +00:00
|
|
|
bool App::IsAccessibilitySupportEnabled() {
|
2016-07-11 21:04:56 +00:00
|
|
|
auto ax_state = content::BrowserAccessibilityState::GetInstance();
|
|
|
|
return ax_state->IsAccessibleBrowser();
|
|
|
|
}
|
|
|
|
|
2017-08-27 14:53:25 +00:00
|
|
|
void App::SetAccessibilitySupportEnabled(bool enabled) {
|
2017-08-24 14:22:28 +00:00
|
|
|
auto ax_state = content::BrowserAccessibilityState::GetInstance();
|
2017-08-27 14:53:25 +00:00
|
|
|
if (enabled) {
|
2017-08-24 14:22:28 +00:00
|
|
|
ax_state->OnScreenReaderDetected();
|
|
|
|
} else {
|
|
|
|
ax_state->DisableAccessibility();
|
|
|
|
}
|
|
|
|
Browser::Get()->OnAccessibilitySupportChanged();
|
|
|
|
}
|
|
|
|
|
2017-01-30 22:01:40 +00:00
|
|
|
Browser::LoginItemSettings App::GetLoginItemSettings(mate::Arguments* args) {
|
|
|
|
Browser::LoginItemSettings options;
|
|
|
|
args->GetNext(&options);
|
|
|
|
return Browser::Get()->GetLoginItemSettings(options);
|
|
|
|
}
|
|
|
|
|
2016-04-19 05:17:28 +00:00
|
|
|
#if defined(USE_NSS_CERTS)
|
2016-04-20 03:15:49 +00:00
|
|
|
void App::ImportCertificate(
|
2016-04-18 15:35:33 +00:00
|
|
|
const base::DictionaryValue& options,
|
2016-04-18 05:11:31 +00:00
|
|
|
const net::CompletionCallback& callback) {
|
2016-07-12 13:45:15 +00:00
|
|
|
auto browser_context = AtomBrowserContext::From("", false);
|
2016-04-18 05:11:31 +00:00
|
|
|
if (!certificate_manager_model_) {
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<base::DictionaryValue> copy = options.CreateDeepCopy();
|
2016-06-22 07:10:36 +00:00
|
|
|
CertificateManagerModel::Create(
|
|
|
|
browser_context.get(),
|
2016-04-18 15:35:33 +00:00
|
|
|
base::Bind(&App::OnCertificateManagerModelCreated,
|
|
|
|
base::Unretained(this),
|
|
|
|
base::Passed(©),
|
|
|
|
callback));
|
2016-04-18 05:11:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-18 15:35:33 +00:00
|
|
|
int rv = ImportIntoCertStore(certificate_manager_model_.get(), options);
|
2016-04-18 05:11:31 +00:00
|
|
|
callback.Run(rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void App::OnCertificateManagerModelCreated(
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<base::DictionaryValue> options,
|
2016-04-18 05:11:31 +00:00
|
|
|
const net::CompletionCallback& callback,
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<CertificateManagerModel> model) {
|
2016-04-18 05:11:31 +00:00
|
|
|
certificate_manager_model_ = std::move(model);
|
2016-04-18 15:35:33 +00:00
|
|
|
int rv = ImportIntoCertStore(certificate_manager_model_.get(),
|
|
|
|
*(options.get()));
|
2016-04-18 05:11:31 +00:00
|
|
|
callback.Run(rv);
|
|
|
|
}
|
2016-04-19 05:17:28 +00:00
|
|
|
#endif
|
2016-04-18 05:11:31 +00:00
|
|
|
|
2016-08-12 09:31:17 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
v8::Local<v8::Value> App::GetJumpListSettings() {
|
|
|
|
JumpList jump_list(Browser::Get()->GetAppUserModelID());
|
|
|
|
|
|
|
|
int min_items = 10;
|
|
|
|
std::vector<JumpListItem> removed_items;
|
|
|
|
if (jump_list.Begin(&min_items, &removed_items)) {
|
|
|
|
// We don't actually want to change anything, so abort the transaction.
|
|
|
|
jump_list.Abort();
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Failed to begin Jump List transaction.";
|
|
|
|
}
|
|
|
|
|
|
|
|
auto dict = mate::Dictionary::CreateEmpty(isolate());
|
|
|
|
dict.Set("minItems", min_items);
|
|
|
|
dict.Set("removedItems", mate::ConvertToV8(isolate(), removed_items));
|
|
|
|
return dict.GetHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
JumpListResult App::SetJumpList(v8::Local<v8::Value> val,
|
|
|
|
mate::Arguments* args) {
|
|
|
|
std::vector<JumpListCategory> categories;
|
|
|
|
bool delete_jump_list = val->IsNull();
|
|
|
|
if (!delete_jump_list &&
|
|
|
|
!mate::ConvertFromV8(args->isolate(), val, &categories)) {
|
|
|
|
args->ThrowError("Argument must be null or an array of categories");
|
|
|
|
return JumpListResult::ARGUMENT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
JumpList jump_list(Browser::Get()->GetAppUserModelID());
|
|
|
|
|
|
|
|
if (delete_jump_list) {
|
|
|
|
return jump_list.Delete()
|
|
|
|
? JumpListResult::SUCCESS
|
|
|
|
: JumpListResult::GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a transaction that updates the JumpList of this application.
|
|
|
|
if (!jump_list.Begin())
|
|
|
|
return JumpListResult::GENERIC_ERROR;
|
|
|
|
|
|
|
|
JumpListResult result = jump_list.AppendCategories(categories);
|
|
|
|
// AppendCategories may have failed to add some categories, but it's better
|
|
|
|
// to have something than nothing so try to commit the changes anyway.
|
|
|
|
if (!jump_list.Commit()) {
|
|
|
|
LOG(ERROR) << "Failed to commit changes to custom Jump List.";
|
|
|
|
// It's more useful to return the earlier error code that might give
|
|
|
|
// some indication as to why the transaction actually failed, so don't
|
|
|
|
// overwrite it with a "generic error" code here.
|
|
|
|
if (result == JumpListResult::SUCCESS)
|
|
|
|
result = JumpListResult::GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif // defined(OS_WIN)
|
|
|
|
|
2016-11-02 18:57:16 +00:00
|
|
|
void App::GetFileIcon(const base::FilePath& path,
|
2016-11-03 18:04:56 +00:00
|
|
|
mate::Arguments* args) {
|
2016-11-04 06:59:18 +00:00
|
|
|
mate::Dictionary options;
|
2016-11-03 18:04:56 +00:00
|
|
|
IconLoader::IconSize icon_size;
|
|
|
|
FileIconCallback callback;
|
|
|
|
|
2016-11-06 12:21:21 +00:00
|
|
|
v8::Locker locker(isolate());
|
|
|
|
v8::HandleScope handle_scope(isolate());
|
2016-11-06 09:58:01 +00:00
|
|
|
|
2016-11-05 18:55:23 +00:00
|
|
|
base::FilePath normalized_path = path.NormalizePathSeparators();
|
|
|
|
|
2016-11-03 18:23:40 +00:00
|
|
|
if (!args->GetNext(&options)) {
|
2016-11-03 18:04:56 +00:00
|
|
|
icon_size = IconLoader::IconSize::NORMAL;
|
2016-11-03 18:23:40 +00:00
|
|
|
} else {
|
|
|
|
std::string icon_size_string;
|
2016-11-04 06:59:18 +00:00
|
|
|
options.Get("size", &icon_size_string);
|
2016-11-03 18:23:40 +00:00
|
|
|
icon_size = GetIconSizeByString(icon_size_string);
|
2016-11-03 18:04:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!args->GetNext(&callback)) {
|
2016-11-10 18:34:30 +00:00
|
|
|
args->ThrowError("Missing required callback function");
|
2016-11-03 18:04:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-17 08:33:46 +00:00
|
|
|
auto icon_manager = g_browser_process->GetIconManager();
|
|
|
|
gfx::Image* icon =
|
|
|
|
icon_manager->LookupIconFromFilepath(normalized_path, icon_size);
|
2016-11-02 18:57:16 +00:00
|
|
|
if (icon) {
|
2016-11-06 12:21:21 +00:00
|
|
|
callback.Run(v8::Null(isolate()), *icon);
|
2016-11-02 18:57:16 +00:00
|
|
|
} else {
|
2017-02-17 08:33:46 +00:00
|
|
|
icon_manager->LoadIcon(
|
|
|
|
normalized_path, icon_size,
|
|
|
|
base::Bind(&OnIconDataAvailable, isolate(), callback),
|
|
|
|
&cancelable_task_tracker_);
|
2016-11-02 18:57:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-16 00:41:45 +00:00
|
|
|
std::vector<mate::Dictionary> App::GetAppMetrics(v8::Isolate* isolate) {
|
2017-04-27 04:04:53 +00:00
|
|
|
std::vector<mate::Dictionary> result;
|
2017-05-16 00:41:45 +00:00
|
|
|
int processor_count = base::SysInfo::NumberOfProcessors();
|
2017-04-17 11:59:16 +00:00
|
|
|
|
2017-05-16 00:41:45 +00:00
|
|
|
for (const auto& process_metric : app_metrics_) {
|
2017-05-04 20:27:35 +00:00
|
|
|
mate::Dictionary pid_dict = mate::Dictionary::CreateEmpty(isolate);
|
|
|
|
mate::Dictionary memory_dict = mate::Dictionary::CreateEmpty(isolate);
|
2017-05-16 00:41:45 +00:00
|
|
|
mate::Dictionary cpu_dict = mate::Dictionary::CreateEmpty(isolate);
|
2017-04-27 04:04:53 +00:00
|
|
|
|
2017-05-04 20:27:35 +00:00
|
|
|
memory_dict.Set("workingSetSize",
|
2017-05-26 15:35:43 +00:00
|
|
|
static_cast<double>(
|
|
|
|
process_metric.second->metrics->GetWorkingSetSize() >> 10));
|
2017-05-04 20:27:35 +00:00
|
|
|
memory_dict.Set("peakWorkingSetSize",
|
2017-05-26 15:35:43 +00:00
|
|
|
static_cast<double>(
|
|
|
|
process_metric.second->metrics->GetPeakWorkingSetSize() >> 10));
|
2017-04-17 11:59:16 +00:00
|
|
|
|
|
|
|
size_t private_bytes, shared_bytes;
|
2017-05-26 15:35:43 +00:00
|
|
|
if (process_metric.second->metrics->GetMemoryBytes(&private_bytes,
|
|
|
|
&shared_bytes)) {
|
2017-05-04 20:27:35 +00:00
|
|
|
memory_dict.Set("privateBytes", static_cast<double>(private_bytes >> 10));
|
|
|
|
memory_dict.Set("sharedBytes", static_cast<double>(shared_bytes >> 10));
|
2017-04-17 11:59:16 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 20:27:35 +00:00
|
|
|
pid_dict.Set("memory", memory_dict);
|
2017-05-16 00:41:45 +00:00
|
|
|
cpu_dict.Set("percentCPUUsage",
|
|
|
|
process_metric.second->metrics->GetPlatformIndependentCPUUsage()
|
|
|
|
/ processor_count);
|
2017-10-27 21:21:46 +00:00
|
|
|
|
|
|
|
#if !defined(OS_WIN)
|
2017-05-16 00:41:45 +00:00
|
|
|
cpu_dict.Set("idleWakeupsPerSecond",
|
|
|
|
process_metric.second->metrics->GetIdleWakeupsPerSecond());
|
2017-10-27 21:21:46 +00:00
|
|
|
#else
|
|
|
|
// Chrome's underlying process_metrics.cc will throw a non-fatal warning
|
|
|
|
// that this method isn't implemented on Windows, so set it to 0 instead
|
|
|
|
// of calling it
|
|
|
|
cpu_dict.Set("idleWakeupsPerSecond", 0);
|
|
|
|
#endif
|
|
|
|
|
2017-05-16 00:41:45 +00:00
|
|
|
pid_dict.Set("cpu", cpu_dict);
|
|
|
|
pid_dict.Set("pid", process_metric.second->pid);
|
2017-05-26 15:53:26 +00:00
|
|
|
pid_dict.Set("type",
|
|
|
|
content::GetProcessTypeNameInEnglish(process_metric.second->type));
|
2017-05-04 20:27:35 +00:00
|
|
|
result.push_back(pid_dict);
|
2017-04-17 11:59:16 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 04:07:35 +00:00
|
|
|
return result;
|
2017-04-17 11:59:16 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 20:00:55 +00:00
|
|
|
v8::Local<v8::Value> App::GetGPUFeatureStatus(v8::Isolate* isolate) {
|
|
|
|
auto status = content::GetFeatureStatus();
|
|
|
|
return mate::ConvertToV8(isolate,
|
|
|
|
status ? *status : base::DictionaryValue());
|
2017-05-30 17:06:08 +00:00
|
|
|
}
|
|
|
|
|
2017-06-26 21:13:41 +00:00
|
|
|
void App::EnableMixedSandbox(mate::Arguments* args) {
|
|
|
|
if (Browser::Get()->is_ready()) {
|
|
|
|
args->ThrowError("app.enableMixedSandbox() can only be called "
|
|
|
|
"before app is ready");
|
|
|
|
return;
|
|
|
|
}
|
2017-06-28 15:33:06 +00:00
|
|
|
|
2017-06-26 21:13:41 +00:00
|
|
|
auto command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
if (command_line->HasSwitch(::switches::kNoSandbox)) {
|
2017-06-28 15:33:06 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
const base::CommandLine::CharType* noSandboxArg = L"--no-sandbox";
|
|
|
|
#else
|
|
|
|
const base::CommandLine::CharType* noSandboxArg = "--no-sandbox";
|
|
|
|
#endif
|
|
|
|
|
2017-06-26 21:13:41 +00:00
|
|
|
// Remove the --no-sandbox switch
|
2017-06-28 15:33:06 +00:00
|
|
|
base::CommandLine::StringVector modified_command_line;
|
|
|
|
for (auto& arg : command_line->argv()) {
|
|
|
|
if (arg.compare(noSandboxArg) != 0) {
|
|
|
|
modified_command_line.push_back(arg);
|
|
|
|
}
|
2017-06-26 21:13:41 +00:00
|
|
|
}
|
|
|
|
command_line->InitFromArgv(modified_command_line);
|
|
|
|
}
|
|
|
|
command_line->AppendSwitch(switches::kEnableMixedSandbox);
|
|
|
|
}
|
|
|
|
|
2017-08-31 14:37:12 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
bool App::MoveToApplicationsFolder(mate::Arguments* args) {
|
|
|
|
return ui::cocoa::AtomBundleMover::Move(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool App::IsInApplicationsFolder() {
|
|
|
|
return ui::cocoa::AtomBundleMover::IsCurrentAppInApplicationsFolder();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-04-25 01:17:54 +00:00
|
|
|
// static
|
|
|
|
mate::Handle<App> App::Create(v8::Isolate* isolate) {
|
2016-04-25 01:40:19 +00:00
|
|
|
return mate::CreateHandle(isolate, new App(isolate));
|
2016-04-25 01:17:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void App::BuildPrototype(
|
2016-08-02 09:08:12 +00:00
|
|
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
2016-08-02 10:28:12 +00:00
|
|
|
prototype->SetClassName(mate::StringToV8(isolate, "App"));
|
2014-10-30 14:27:29 +00:00
|
|
|
auto browser = base::Unretained(Browser::Get());
|
2016-08-02 09:08:12 +00:00
|
|
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
2014-10-30 14:27:29 +00:00
|
|
|
.SetMethod("quit", base::Bind(&Browser::Quit, browser))
|
2015-12-10 02:09:59 +00:00
|
|
|
.SetMethod("exit", base::Bind(&Browser::Exit, browser))
|
2014-10-30 14:27:29 +00:00
|
|
|
.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))
|
2015-11-03 07:09:31 +00:00
|
|
|
.SetMethod("setAppUserModelId",
|
|
|
|
base::Bind(&Browser::SetAppUserModelID, browser))
|
2016-04-25 05:17:01 +00:00
|
|
|
.SetMethod("isDefaultProtocolClient",
|
|
|
|
base::Bind(&Browser::IsDefaultProtocolClient, browser))
|
2016-03-21 18:24:25 +00:00
|
|
|
.SetMethod("setAsDefaultProtocolClient",
|
|
|
|
base::Bind(&Browser::SetAsDefaultProtocolClient, browser))
|
2016-03-24 17:55:09 +00:00
|
|
|
.SetMethod("removeAsDefaultProtocolClient",
|
|
|
|
base::Bind(&Browser::RemoveAsDefaultProtocolClient, browser))
|
2016-07-01 08:39:01 +00:00
|
|
|
.SetMethod("setBadgeCount", base::Bind(&Browser::SetBadgeCount, browser))
|
|
|
|
.SetMethod("getBadgeCount", base::Bind(&Browser::GetBadgeCount, browser))
|
2017-01-30 22:01:40 +00:00
|
|
|
.SetMethod("getLoginItemSettings", &App::GetLoginItemSettings)
|
2016-07-11 17:57:53 +00:00
|
|
|
.SetMethod("setLoginItemSettings",
|
|
|
|
base::Bind(&Browser::SetLoginItemSettings, browser))
|
2016-01-29 21:51:06 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
.SetMethod("hide", base::Bind(&Browser::Hide, browser))
|
2016-01-30 20:40:32 +00:00
|
|
|
.SetMethod("show", base::Bind(&Browser::Show, browser))
|
2016-04-30 05:05:36 +00:00
|
|
|
.SetMethod("setUserActivity",
|
|
|
|
base::Bind(&Browser::SetUserActivity, browser))
|
2016-07-07 21:29:43 +00:00
|
|
|
.SetMethod("getCurrentActivityType",
|
|
|
|
base::Bind(&Browser::GetCurrentActivityType, browser))
|
2017-06-26 19:14:44 +00:00
|
|
|
.SetMethod("invalidateCurrentActivity",
|
|
|
|
base::Bind(&Browser::InvalidateCurrentActivity, browser))
|
|
|
|
.SetMethod("updateCurrentActivity",
|
|
|
|
base::Bind(&Browser::UpdateCurrentActivity, browser))
|
2016-10-10 20:30:58 +00:00
|
|
|
.SetMethod("setAboutPanelOptions",
|
|
|
|
base::Bind(&Browser::SetAboutPanelOptions, browser))
|
2016-01-29 21:51:06 +00:00
|
|
|
#endif
|
2014-11-17 09:19:41 +00:00
|
|
|
#if defined(OS_WIN)
|
2016-07-01 08:39:01 +00:00
|
|
|
.SetMethod("setUserTasks", base::Bind(&Browser::SetUserTasks, browser))
|
2016-08-12 09:31:17 +00:00
|
|
|
.SetMethod("getJumpListSettings", &App::GetJumpListSettings)
|
|
|
|
.SetMethod("setJumpList", &App::SetJumpList)
|
2016-07-01 08:39:01 +00:00
|
|
|
#endif
|
|
|
|
#if defined(OS_LINUX)
|
|
|
|
.SetMethod("isUnityRunning",
|
|
|
|
base::Bind(&Browser::IsUnityRunning, browser))
|
2014-11-17 09:19:41 +00:00
|
|
|
#endif
|
2017-04-04 00:36:01 +00:00
|
|
|
.SetMethod("setAppPath", &App::SetAppPath)
|
|
|
|
.SetMethod("getAppPath", &App::GetAppPath)
|
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-09-16 08:16:21 +00:00
|
|
|
.SetMethod("getLocale", &App::GetLocale)
|
2016-04-19 05:17:28 +00:00
|
|
|
#if defined(USE_NSS_CERTS)
|
2016-04-20 03:15:49 +00:00
|
|
|
.SetMethod("importCertificate", &App::ImportCertificate)
|
2016-04-18 15:35:33 +00:00
|
|
|
#endif
|
2016-05-26 18:07:19 +00:00
|
|
|
.SetMethod("makeSingleInstance", &App::MakeSingleInstance)
|
2016-06-02 12:49:29 +00:00
|
|
|
.SetMethod("releaseSingleInstance", &App::ReleaseSingleInstance)
|
2016-06-06 11:19:55 +00:00
|
|
|
.SetMethod("relaunch", &App::Relaunch)
|
2016-07-11 21:44:32 +00:00
|
|
|
.SetMethod("isAccessibilitySupportEnabled",
|
2016-07-11 21:32:14 +00:00
|
|
|
&App::IsAccessibilitySupportEnabled)
|
2017-08-24 14:22:28 +00:00
|
|
|
.SetMethod("setAccessibilitySupportEnabled",
|
|
|
|
&App::SetAccessibilitySupportEnabled)
|
2016-06-06 11:19:55 +00:00
|
|
|
.SetMethod("disableHardwareAcceleration",
|
2016-11-02 18:57:16 +00:00
|
|
|
&App::DisableHardwareAcceleration)
|
2017-07-13 22:27:03 +00:00
|
|
|
.SetMethod("disableDomainBlockingFor3DAPIs",
|
|
|
|
&App::DisableDomainBlockingFor3DAPIs)
|
2017-04-17 11:59:16 +00:00
|
|
|
.SetMethod("getFileIcon", &App::GetFileIcon)
|
2017-05-26 14:51:17 +00:00
|
|
|
.SetMethod("getAppMetrics", &App::GetAppMetrics)
|
2017-05-30 17:06:08 +00:00
|
|
|
.SetMethod("getGPUFeatureStatus", &App::GetGPUFeatureStatus)
|
2017-06-28 15:37:56 +00:00
|
|
|
.SetMethod("enableMixedSandbox", &App::EnableMixedSandbox)
|
2017-05-26 14:51:17 +00:00
|
|
|
// TODO(juturu): Remove in 2.0, deprecate before then with warnings
|
2017-08-31 14:37:12 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
.SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder)
|
|
|
|
.SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder)
|
|
|
|
#endif
|
2017-05-26 14:51:17 +00:00
|
|
|
.SetMethod("getAppMemoryInfo", &App::GetAppMetrics);
|
2013-05-30 11:24:47 +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
|
|
|
|
2016-05-10 23:47:50 +00:00
|
|
|
if (base::EndsWith(switch_string, "-path",
|
|
|
|
base::CompareCase::INSENSITIVE_ASCII) ||
|
2015-10-07 04:15:48 +00:00
|
|
|
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);
|
2016-08-02 11:38:35 +00:00
|
|
|
dict.Set("App", atom::api::App::GetConstructor(isolate)->GetFunction());
|
2014-04-17 09:13:46 +00:00
|
|
|
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));
|
2016-05-10 19:02:56 +00:00
|
|
|
dict.SetMethod("dockDownloadFinished",
|
|
|
|
base::Bind(&Browser::DockDownloadFinished, 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));
|
2016-08-01 22:22:37 +00:00
|
|
|
dict.SetMethod("dockIsVisible", base::Bind(&Browser::DockIsVisible, browser));
|
2014-11-16 15:04:31 +00:00
|
|
|
dict.SetMethod("dockSetMenu", &DockSetMenu);
|
2016-01-23 23:30:14 +00:00
|
|
|
dict.SetMethod("dockSetIcon", base::Bind(&Browser::DockSetIcon, browser));
|
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)
|