2014-10-31 21:17:05 +03:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 13:49:37 +04:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-05-02 20:05:09 +04:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_API_ATOM_API_APP_H_
|
|
|
|
#define ATOM_BROWSER_API_ATOM_API_APP_H_
|
|
|
|
|
2017-05-26 18:32:08 +03:00
|
|
|
#include <memory>
|
2014-03-16 05:13:06 +04:00
|
|
|
#include <string>
|
2018-09-13 03:25:56 +03:00
|
|
|
#include <unordered_map>
|
2017-05-26 17:51:17 +03:00
|
|
|
#include <utility>
|
2016-09-15 16:37:35 +03:00
|
|
|
#include <vector>
|
2014-03-16 05:13:06 +04:00
|
|
|
|
2014-04-17 13:13:46 +04:00
|
|
|
#include "atom/browser/api/event_emitter.h"
|
2015-11-18 05:07:03 +03:00
|
|
|
#include "atom/browser/atom_browser_client.h"
|
2017-01-31 01:01:40 +03:00
|
|
|
#include "atom/browser/browser.h"
|
2014-03-16 04:30:26 +04:00
|
|
|
#include "atom/browser/browser_observer.h"
|
2015-10-20 00:43:04 +03:00
|
|
|
#include "atom/common/native_mate_converters/callback.h"
|
2018-06-28 00:06:08 +03:00
|
|
|
#include "atom/common/promise_util.h"
|
2017-04-17 14:59:16 +03:00
|
|
|
#include "base/process/process_iterator.h"
|
2017-02-16 22:19:19 +03:00
|
|
|
#include "base/task/cancelable_task_tracker.h"
|
|
|
|
#include "chrome/browser/icon_manager.h"
|
2015-10-21 00:36:01 +03:00
|
|
|
#include "chrome/browser/process_singleton.h"
|
2017-05-16 03:41:45 +03:00
|
|
|
#include "content/public/browser/browser_child_process_observer.h"
|
2015-06-25 15:28:07 +03:00
|
|
|
#include "content/public/browser/gpu_data_manager_observer.h"
|
2017-05-16 03:41:45 +03:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2017-04-28 07:07:35 +03:00
|
|
|
#include "native_mate/dictionary.h"
|
2014-04-17 13:13:46 +04:00
|
|
|
#include "native_mate/handle.h"
|
2016-04-18 08:11:31 +03:00
|
|
|
#include "net/base/completion_callback.h"
|
2017-08-21 00:35:04 +03:00
|
|
|
#include "net/ssl/client_cert_identity.h"
|
2013-05-02 20:05:09 +04:00
|
|
|
|
2016-04-19 08:17:28 +03:00
|
|
|
#if defined(USE_NSS_CERTS)
|
|
|
|
#include "chrome/browser/certificate_manager_model.h"
|
|
|
|
#endif
|
|
|
|
|
2014-08-19 17:26:45 +04:00
|
|
|
namespace base {
|
|
|
|
class FilePath;
|
|
|
|
}
|
|
|
|
|
2015-01-19 07:24:58 +03:00
|
|
|
namespace mate {
|
|
|
|
class Arguments;
|
2016-08-12 12:31:17 +03:00
|
|
|
} // namespace mate
|
2015-10-20 23:27:34 +03:00
|
|
|
|
2013-05-02 20:05:09 +04:00
|
|
|
namespace atom {
|
|
|
|
|
2016-08-12 12:31:17 +03:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
enum class JumpListResult : int;
|
|
|
|
#endif
|
|
|
|
|
2017-05-16 03:41:45 +03:00
|
|
|
struct ProcessMetric {
|
2017-05-26 18:53:26 +03:00
|
|
|
int type;
|
2017-05-16 03:41:45 +03:00
|
|
|
base::ProcessId pid;
|
|
|
|
std::unique_ptr<base::ProcessMetrics> metrics;
|
2017-05-26 17:51:17 +03:00
|
|
|
|
2017-05-26 18:53:26 +03:00
|
|
|
ProcessMetric(int type,
|
2017-05-16 03:41:45 +03:00
|
|
|
base::ProcessId pid,
|
2018-04-18 02:37:22 +03:00
|
|
|
std::unique_ptr<base::ProcessMetrics> metrics);
|
|
|
|
~ProcessMetric();
|
2017-05-16 03:41:45 +03:00
|
|
|
};
|
|
|
|
|
2013-05-02 20:05:09 +04:00
|
|
|
namespace api {
|
|
|
|
|
2015-11-18 05:07:03 +03:00
|
|
|
class App : public AtomBrowserClient::Delegate,
|
2016-04-25 04:17:54 +03:00
|
|
|
public mate::EventEmitter<App>,
|
2015-06-25 15:28:07 +03:00
|
|
|
public BrowserObserver,
|
2017-05-16 03:41:45 +03:00
|
|
|
public content::GpuDataManagerObserver,
|
|
|
|
public content::BrowserChildProcessObserver {
|
2013-05-02 20:05:09 +04:00
|
|
|
public:
|
2018-04-18 04:44:10 +03:00
|
|
|
using FileIconCallback =
|
|
|
|
base::Callback<void(v8::Local<v8::Value>, const gfx::Image&)>;
|
2016-11-02 21:57:16 +03:00
|
|
|
|
2014-04-17 13:13:46 +04:00
|
|
|
static mate::Handle<App> Create(v8::Isolate* isolate);
|
2013-05-02 20:05:09 +04:00
|
|
|
|
2016-04-25 04:17:54 +03:00
|
|
|
static void BuildPrototype(v8::Isolate* isolate,
|
2016-08-02 12:08:12 +03:00
|
|
|
v8::Local<v8::FunctionTemplate> prototype);
|
2016-04-25 04:17:54 +03:00
|
|
|
|
2016-04-19 08:17:28 +03:00
|
|
|
#if defined(USE_NSS_CERTS)
|
2016-04-18 08:11:31 +03:00
|
|
|
void OnCertificateManagerModelCreated(
|
2016-05-23 04:59:39 +03:00
|
|
|
std::unique_ptr<base::DictionaryValue> options,
|
2016-04-18 08:11:31 +03:00
|
|
|
const net::CompletionCallback& callback,
|
2016-05-23 04:59:39 +03:00
|
|
|
std::unique_ptr<CertificateManagerModel> model);
|
2016-04-19 08:17:28 +03:00
|
|
|
#endif
|
2016-04-18 08:11:31 +03:00
|
|
|
|
2017-04-13 17:26:42 +03:00
|
|
|
base::FilePath GetAppPath() const;
|
2017-05-25 07:15:34 +03:00
|
|
|
void RenderProcessReady(content::RenderProcessHost* host);
|
2017-05-26 18:32:08 +03:00
|
|
|
void RenderProcessDisconnected(base::ProcessId host_pid);
|
2017-09-14 16:08:18 +03:00
|
|
|
void PreMainMessageLoopRun();
|
2017-04-04 03:36:01 +03:00
|
|
|
|
2013-05-03 06:53:54 +04:00
|
|
|
protected:
|
2016-04-25 04:17:54 +03:00
|
|
|
explicit App(v8::Isolate* isolate);
|
|
|
|
~App() override;
|
2013-05-03 06:53:54 +04:00
|
|
|
|
2014-11-16 17:45:29 +03:00
|
|
|
// BrowserObserver:
|
2015-02-26 06:33:42 +03:00
|
|
|
void OnBeforeQuit(bool* prevent_default) override;
|
2014-11-16 17:45:29 +03:00
|
|
|
void OnWillQuit(bool* prevent_default) override;
|
|
|
|
void OnWindowAllClosed() override;
|
|
|
|
void OnQuit() override;
|
|
|
|
void OnOpenFile(bool* prevent_default, const std::string& file_path) override;
|
|
|
|
void OnOpenURL(const std::string& url) override;
|
2015-09-15 05:05:53 +03:00
|
|
|
void OnActivate(bool has_visible_windows) override;
|
2014-11-16 17:45:29 +03:00
|
|
|
void OnWillFinishLaunching() override;
|
2016-09-01 03:17:44 +03:00
|
|
|
void OnFinishLaunching(const base::DictionaryValue& launch_info) override;
|
2018-08-23 12:55:13 +03:00
|
|
|
void OnLogin(scoped_refptr<LoginHandler> login_handler,
|
2016-06-08 16:52:21 +03:00
|
|
|
const base::DictionaryValue& request_details) override;
|
2016-07-12 00:32:14 +03:00
|
|
|
void OnAccessibilitySupportChanged() override;
|
2017-09-15 22:33:12 +03:00
|
|
|
void OnPreMainMessageLoopRun() override;
|
2016-05-05 06:26:23 +03:00
|
|
|
#if defined(OS_MACOSX)
|
2018-04-18 04:44:10 +03:00
|
|
|
void OnWillContinueUserActivity(bool* prevent_default,
|
|
|
|
const std::string& type) override;
|
|
|
|
void OnDidFailToContinueUserActivity(const std::string& type,
|
|
|
|
const std::string& error) override;
|
|
|
|
void OnContinueUserActivity(bool* prevent_default,
|
|
|
|
const std::string& type,
|
|
|
|
const base::DictionaryValue& user_info) override;
|
2017-06-26 22:14:44 +03:00
|
|
|
void OnUserActivityWasContinued(
|
|
|
|
const std::string& type,
|
|
|
|
const base::DictionaryValue& user_info) override;
|
|
|
|
void OnUpdateUserActivityState(
|
2017-08-09 18:09:47 +03:00
|
|
|
bool* prevent_default,
|
2017-06-26 22:14:44 +03:00
|
|
|
const std::string& type,
|
|
|
|
const base::DictionaryValue& user_info) override;
|
2017-06-11 11:19:01 +03:00
|
|
|
void OnNewWindowForTab() override;
|
2016-05-05 06:26:23 +03:00
|
|
|
#endif
|
2015-11-18 05:07:03 +03:00
|
|
|
|
|
|
|
// content::ContentBrowserClient:
|
2015-11-18 05:39:25 +03:00
|
|
|
void AllowCertificateError(
|
2016-03-08 17:28:53 +03:00
|
|
|
content::WebContents* web_contents,
|
2015-11-18 05:39:25 +03:00
|
|
|
int cert_error,
|
|
|
|
const net::SSLInfo& ssl_info,
|
|
|
|
const GURL& request_url,
|
|
|
|
content::ResourceType resource_type,
|
|
|
|
bool strict_enforcement,
|
|
|
|
bool expired_previous_decision,
|
2016-11-30 10:30:03 +03:00
|
|
|
const base::Callback<void(content::CertificateRequestResultType)>&
|
|
|
|
callback) override;
|
2015-11-18 05:07:03 +03:00
|
|
|
void SelectClientCertificate(
|
2015-06-11 18:22:07 +03:00
|
|
|
content::WebContents* web_contents,
|
|
|
|
net::SSLCertRequestInfo* cert_request_info,
|
2017-08-21 00:35:04 +03:00
|
|
|
net::ClientCertIdentityList client_certs,
|
2016-05-23 04:59:39 +03:00
|
|
|
std::unique_ptr<content::ClientCertificateDelegate> delegate) override;
|
2017-12-07 07:12:38 +03:00
|
|
|
bool CanCreateWindow(content::RenderFrameHost* opener,
|
|
|
|
const GURL& opener_url,
|
|
|
|
const GURL& opener_top_level_frame_url,
|
2019-01-21 21:14:57 +03:00
|
|
|
const url::Origin& source_origin,
|
2017-12-07 07:12:38 +03:00
|
|
|
content::mojom::WindowContainerType container_type,
|
|
|
|
const GURL& target_url,
|
|
|
|
const content::Referrer& referrer,
|
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
const blink::mojom::WindowFeatures& features,
|
|
|
|
const std::vector<std::string>& additional_features,
|
2018-04-11 11:42:14 +03:00
|
|
|
const scoped_refptr<network::ResourceRequestBody>& body,
|
2017-12-07 07:12:38 +03:00
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access) override;
|
2014-11-16 17:45:29 +03:00
|
|
|
|
2015-06-25 15:28:07 +03:00
|
|
|
// content::GpuDataManagerObserver:
|
2016-09-18 03:00:45 +03:00
|
|
|
void OnGpuProcessCrashed(base::TerminationStatus status) override;
|
2015-06-25 15:28:07 +03:00
|
|
|
|
2017-05-16 03:41:45 +03:00
|
|
|
// content::BrowserChildProcessObserver:
|
|
|
|
void BrowserChildProcessLaunchedAndConnected(
|
|
|
|
const content::ChildProcessData& data) override;
|
|
|
|
void BrowserChildProcessHostDisconnected(
|
|
|
|
const content::ChildProcessData& data) override;
|
2018-09-15 03:11:49 +03:00
|
|
|
void BrowserChildProcessCrashed(
|
|
|
|
const content::ChildProcessData& data,
|
|
|
|
const content::ChildProcessTerminationInfo& info) override;
|
|
|
|
void BrowserChildProcessKilled(
|
|
|
|
const content::ChildProcessData& data,
|
|
|
|
const content::ChildProcessTerminationInfo& info) override;
|
2017-05-16 03:41:45 +03:00
|
|
|
|
2014-04-17 13:13:46 +04:00
|
|
|
private:
|
2017-04-13 04:59:12 +03:00
|
|
|
void SetAppPath(const base::FilePath& app_path);
|
2017-05-25 07:15:34 +03:00
|
|
|
void ChildProcessLaunched(int process_type, base::ProcessHandle handle);
|
|
|
|
void ChildProcessDisconnected(base::ProcessId pid);
|
2017-04-04 03:36:01 +03:00
|
|
|
|
2015-01-19 04:52:15 +03:00
|
|
|
// Get/Set the pre-defined path in PathService.
|
2015-01-19 07:24:58 +03:00
|
|
|
base::FilePath GetPath(mate::Arguments* args, const std::string& name);
|
|
|
|
void SetPath(mate::Arguments* args,
|
|
|
|
const std::string& name,
|
|
|
|
const base::FilePath& path);
|
2015-01-19 04:52:15 +03:00
|
|
|
|
2014-09-18 15:12:24 +04:00
|
|
|
void SetDesktopName(const std::string& desktop_name);
|
2016-06-02 15:49:29 +03:00
|
|
|
std::string GetLocale();
|
2018-11-20 23:33:23 +03:00
|
|
|
std::string GetLocaleCountryCode();
|
2018-05-07 18:29:18 +03:00
|
|
|
void OnSecondInstance(const base::CommandLine::StringVector& cmd,
|
|
|
|
const base::FilePath& cwd);
|
|
|
|
bool HasSingleInstanceLock() const;
|
|
|
|
bool RequestSingleInstanceLock();
|
|
|
|
void ReleaseSingleInstanceLock();
|
2016-06-02 15:49:29 +03:00
|
|
|
bool Relaunch(mate::Arguments* args);
|
2016-06-06 14:19:55 +03:00
|
|
|
void DisableHardwareAcceleration(mate::Arguments* args);
|
2017-07-14 01:27:03 +03:00
|
|
|
void DisableDomainBlockingFor3DAPIs(mate::Arguments* args);
|
2016-07-12 00:32:14 +03:00
|
|
|
bool IsAccessibilitySupportEnabled();
|
2019-01-04 18:20:06 +03:00
|
|
|
void SetAccessibilitySupportEnabled(bool enabled, mate::Arguments* args);
|
2017-01-31 01:01:40 +03:00
|
|
|
Browser::LoginItemSettings GetLoginItemSettings(mate::Arguments* args);
|
2016-04-19 08:17:28 +03:00
|
|
|
#if defined(USE_NSS_CERTS)
|
2016-04-20 06:15:49 +03:00
|
|
|
void ImportCertificate(const base::DictionaryValue& options,
|
|
|
|
const net::CompletionCallback& callback);
|
2016-04-19 08:17:28 +03:00
|
|
|
#endif
|
2018-12-05 19:50:12 +03:00
|
|
|
v8::Local<v8::Promise> GetFileIcon(const base::FilePath& path,
|
|
|
|
mate::Arguments* args);
|
2015-10-21 23:17:56 +03:00
|
|
|
|
2017-05-16 03:41:45 +03:00
|
|
|
std::vector<mate::Dictionary> GetAppMetrics(v8::Isolate* isolate);
|
2017-05-30 23:00:55 +03:00
|
|
|
v8::Local<v8::Value> GetGPUFeatureStatus(v8::Isolate* isolate);
|
2018-09-27 17:59:23 +03:00
|
|
|
v8::Local<v8::Promise> GetGPUInfo(v8::Isolate* isolate,
|
|
|
|
const std::string& info_type);
|
2018-10-10 07:32:09 +03:00
|
|
|
void EnableSandbox(mate::Arguments* args);
|
2017-04-17 14:59:16 +03:00
|
|
|
|
2017-08-31 17:37:12 +03:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
bool MoveToApplicationsFolder(mate::Arguments* args);
|
|
|
|
bool IsInApplicationsFolder();
|
|
|
|
#endif
|
2018-02-12 21:25:06 +03:00
|
|
|
#if defined(MAS_BUILD)
|
|
|
|
base::Callback<void()> StartAccessingSecurityScopedResource(
|
2018-04-18 04:44:10 +03:00
|
|
|
mate::Arguments* args);
|
2018-02-12 21:25:06 +03:00
|
|
|
#endif
|
2017-08-31 17:37:12 +03:00
|
|
|
|
2016-08-12 12:31:17 +03:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Get the current Jump List settings.
|
|
|
|
v8::Local<v8::Value> GetJumpListSettings();
|
|
|
|
|
|
|
|
// Set or remove a custom Jump List for the application.
|
|
|
|
JumpListResult SetJumpList(v8::Local<v8::Value> val, mate::Arguments* args);
|
|
|
|
#endif // defined(OS_WIN)
|
|
|
|
|
2016-05-23 04:59:39 +03:00
|
|
|
std::unique_ptr<ProcessSingleton> process_singleton_;
|
2016-04-19 08:17:28 +03:00
|
|
|
|
|
|
|
#if defined(USE_NSS_CERTS)
|
2016-05-23 04:59:39 +03:00
|
|
|
std::unique_ptr<CertificateManagerModel> certificate_manager_model_;
|
2016-04-19 08:17:28 +03:00
|
|
|
#endif
|
2014-08-19 17:26:45 +04:00
|
|
|
|
2017-02-17 11:33:46 +03:00
|
|
|
// Tracks tasks requesting file icons.
|
|
|
|
base::CancelableTaskTracker cancelable_task_tracker_;
|
|
|
|
|
2017-04-13 04:59:12 +03:00
|
|
|
base::FilePath app_path_;
|
2017-04-04 03:36:01 +03:00
|
|
|
|
2017-05-16 03:41:45 +03:00
|
|
|
using ProcessMetricMap =
|
2018-04-18 04:44:10 +03:00
|
|
|
std::unordered_map<base::ProcessId, std::unique_ptr<atom::ProcessMetric>>;
|
2017-05-16 03:41:45 +03:00
|
|
|
ProcessMetricMap app_metrics_;
|
|
|
|
|
2013-05-03 06:53:54 +04:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(App);
|
2013-05-02 20:05:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_API_ATOM_API_APP_H_
|