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.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_APP_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_APP_H_
|
2013-05-02 16:05:09 +00:00
|
|
|
|
2020-12-01 01:47:46 +00:00
|
|
|
#include <map>
|
2017-05-26 15:32:08 +00:00
|
|
|
#include <memory>
|
2014-03-16 01:13:06 +00:00
|
|
|
#include <string>
|
2016-09-15 13:37:35 +00:00
|
|
|
#include <vector>
|
2014-03-16 01:13:06 +00:00
|
|
|
|
2017-02-16 19:19:19 +00:00
|
|
|
#include "base/task/cancelable_task_tracker.h"
|
|
|
|
#include "chrome/browser/icon_manager.h"
|
2015-10-20 21:36:01 +00:00
|
|
|
#include "chrome/browser/process_singleton.h"
|
2017-05-16 00:41:45 +00:00
|
|
|
#include "content/public/browser/browser_child_process_observer.h"
|
2015-06-25 12:28:07 +00:00
|
|
|
#include "content/public/browser/gpu_data_manager_observer.h"
|
2017-05-16 00:41:45 +00:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2022-02-10 02:58:52 +00:00
|
|
|
#include "crypto/crypto_buildflags.h"
|
2019-10-24 05:47:58 +00:00
|
|
|
#include "gin/handle.h"
|
2019-04-20 17:20:37 +00:00
|
|
|
#include "net/base/completion_once_callback.h"
|
|
|
|
#include "net/base/completion_repeating_callback.h"
|
2017-08-20 21:35:04 +00:00
|
|
|
#include "net/ssl/client_cert_identity.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/api/process_metric.h"
|
|
|
|
#include "shell/browser/browser.h"
|
|
|
|
#include "shell/browser/browser_observer.h"
|
|
|
|
#include "shell/browser/electron_browser_client.h"
|
2020-07-28 23:43:43 +00:00
|
|
|
#include "shell/browser/event_emitter_mixin.h"
|
2019-10-24 05:47:58 +00:00
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
2019-09-06 05:52:54 +00:00
|
|
|
#include "shell/common/gin_helper/error_thrower.h"
|
2019-11-01 06:10:32 +00:00
|
|
|
#include "shell/common/gin_helper/promise.h"
|
2013-05-02 16:05:09 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(USE_NSS_CERTS)
|
2021-11-08 00:53:00 +00:00
|
|
|
#include "shell/browser/certificate_manager_model.h"
|
2016-04-19 05:17:28 +00:00
|
|
|
#endif
|
|
|
|
|
2014-08-19 13:26:45 +00:00
|
|
|
namespace base {
|
|
|
|
class FilePath;
|
|
|
|
}
|
|
|
|
|
2013-05-02 16:05:09 +00:00
|
|
|
namespace electron {
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-08-12 09:31:17 +00:00
|
|
|
enum class JumpListResult : int;
|
|
|
|
#endif
|
|
|
|
|
2013-05-02 16:05:09 +00:00
|
|
|
namespace api {
|
|
|
|
|
2015-11-18 02:07:03 +00:00
|
|
|
class App : public ElectronBrowserClient::Delegate,
|
2020-07-28 23:43:43 +00:00
|
|
|
public gin::Wrappable<App>,
|
|
|
|
public gin_helper::EventEmitterMixin<App>,
|
2015-06-25 12:28:07 +00:00
|
|
|
public BrowserObserver,
|
2017-05-16 00:41:45 +00:00
|
|
|
public content::GpuDataManagerObserver,
|
|
|
|
public content::BrowserChildProcessObserver {
|
2013-05-02 16:05:09 +00:00
|
|
|
public:
|
2018-04-18 01:44:10 +00:00
|
|
|
using FileIconCallback =
|
2019-04-27 04:42:56 +00:00
|
|
|
base::RepeatingCallback<void(v8::Local<v8::Value>, const gfx::Image&)>;
|
2016-11-02 18:57:16 +00:00
|
|
|
|
2019-10-24 05:47:58 +00:00
|
|
|
static gin::Handle<App> Create(v8::Isolate* isolate);
|
2020-05-19 17:18:12 +00:00
|
|
|
static App* Get();
|
2013-05-02 16:05:09 +00:00
|
|
|
|
2020-07-28 23:43:43 +00:00
|
|
|
// gin::Wrappable
|
|
|
|
static gin::WrapperInfo kWrapperInfo;
|
|
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) override;
|
|
|
|
const char* GetTypeName() override;
|
2016-04-25 01:17:54 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(USE_NSS_CERTS)
|
2016-04-18 05:11:31 +00:00
|
|
|
void OnCertificateManagerModelCreated(
|
2020-04-13 20:52:07 +00:00
|
|
|
base::Value options,
|
2019-04-20 17:20:37 +00:00
|
|
|
net::CompletionOnceCallback callback,
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<CertificateManagerModel> model);
|
2016-04-19 05:17:28 +00:00
|
|
|
#endif
|
2016-04-18 05:11:31 +00:00
|
|
|
|
2017-04-13 14:26:42 +00:00
|
|
|
base::FilePath GetAppPath() const;
|
2017-05-25 04:15:34 +00:00
|
|
|
void RenderProcessReady(content::RenderProcessHost* host);
|
2020-12-01 01:47:46 +00:00
|
|
|
void RenderProcessExited(content::RenderProcessHost* host);
|
2017-04-04 00:36:01 +00:00
|
|
|
|
2021-06-02 19:17:08 +00:00
|
|
|
static bool IsPackaged();
|
|
|
|
|
2020-07-28 23:43:43 +00:00
|
|
|
App();
|
2020-05-19 17:18:12 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
App(const App&) = delete;
|
|
|
|
App& operator=(const App&) = delete;
|
|
|
|
|
2020-05-19 17:18:12 +00:00
|
|
|
private:
|
2016-04-25 01:17:54 +00:00
|
|
|
~App() override;
|
2013-05-03 02:53:54 +00:00
|
|
|
|
2014-11-16 14:45:29 +00:00
|
|
|
// BrowserObserver:
|
2015-02-26 03:33:42 +00:00
|
|
|
void OnBeforeQuit(bool* prevent_default) override;
|
2014-11-16 14:45:29 +00: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 02:05:53 +00:00
|
|
|
void OnActivate(bool has_visible_windows) override;
|
2014-11-16 14:45:29 +00:00
|
|
|
void OnWillFinishLaunching() override;
|
2022-06-23 06:28:41 +00:00
|
|
|
void OnFinishLaunching(base::Value::Dict launch_info) override;
|
2016-07-11 21:32:14 +00:00
|
|
|
void OnAccessibilitySupportChanged() override;
|
2017-09-15 19:33:12 +00:00
|
|
|
void OnPreMainMessageLoopRun() override;
|
2020-04-13 23:39:26 +00:00
|
|
|
void OnPreCreateThreads() override;
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2018-04-18 01:44:10 +00: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,
|
2022-06-23 06:28:41 +00:00
|
|
|
base::Value::Dict user_info,
|
|
|
|
base::Value::Dict details) override;
|
|
|
|
void OnUserActivityWasContinued(const std::string& type,
|
|
|
|
base::Value::Dict user_info) override;
|
|
|
|
void OnUpdateUserActivityState(bool* prevent_default,
|
|
|
|
const std::string& type,
|
|
|
|
base::Value::Dict user_info) override;
|
2017-06-11 08:19:01 +00:00
|
|
|
void OnNewWindowForTab() override;
|
2020-06-16 17:03:41 +00:00
|
|
|
void OnDidBecomeActive() override;
|
2016-05-05 03:26:23 +00:00
|
|
|
#endif
|
2015-11-18 02:07:03 +00:00
|
|
|
|
|
|
|
// content::ContentBrowserClient:
|
2015-11-18 02:39:25 +00:00
|
|
|
void 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,
|
2019-05-13 21:24:39 +00:00
|
|
|
bool is_main_frame_request,
|
2015-11-18 02:39:25 +00:00
|
|
|
bool strict_enforcement,
|
2019-12-11 00:22:35 +00:00
|
|
|
base::OnceCallback<void(content::CertificateRequestResultType)> callback)
|
|
|
|
override;
|
2019-07-03 01:22:09 +00:00
|
|
|
base::OnceClosure SelectClientCertificate(
|
2015-06-11 15:22:07 +00:00
|
|
|
content::WebContents* web_contents,
|
|
|
|
net::SSLCertRequestInfo* cert_request_info,
|
2021-06-01 01:46:25 +00:00
|
|
|
net::ClientCertIdentityList identities,
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<content::ClientCertificateDelegate> delegate) override;
|
2017-12-07 04:12:38 +00:00
|
|
|
bool CanCreateWindow(content::RenderFrameHost* opener,
|
|
|
|
const GURL& opener_url,
|
|
|
|
const GURL& opener_top_level_frame_url,
|
2019-01-21 18:14:57 +00:00
|
|
|
const url::Origin& source_origin,
|
2017-12-07 04:12:38 +00: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,
|
2020-03-26 18:05:45 +00:00
|
|
|
const std::string& raw_features,
|
2018-04-11 08:42:14 +00:00
|
|
|
const scoped_refptr<network::ResourceRequestBody>& body,
|
2017-12-07 04:12:38 +00:00
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access) override;
|
2014-11-16 14:45:29 +00:00
|
|
|
|
2015-06-25 12:28:07 +00:00
|
|
|
// content::GpuDataManagerObserver:
|
2019-05-18 01:06:48 +00:00
|
|
|
void OnGpuInfoUpdate() override;
|
2022-04-12 11:19:14 +00:00
|
|
|
void OnGpuProcessCrashed() override;
|
2015-06-25 12:28:07 +00:00
|
|
|
|
2017-05-16 00:41:45 +00:00
|
|
|
// content::BrowserChildProcessObserver:
|
|
|
|
void BrowserChildProcessLaunchedAndConnected(
|
|
|
|
const content::ChildProcessData& data) override;
|
|
|
|
void BrowserChildProcessHostDisconnected(
|
|
|
|
const content::ChildProcessData& data) override;
|
2018-09-15 00:11:49 +00: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 00:41:45 +00:00
|
|
|
|
2014-04-17 09:13:46 +00:00
|
|
|
private:
|
2020-07-20 14:34:16 +00:00
|
|
|
void BrowserChildProcessCrashedOrKilled(
|
|
|
|
const content::ChildProcessData& data,
|
|
|
|
const content::ChildProcessTerminationInfo& info);
|
|
|
|
|
2017-04-13 01:59:12 +00:00
|
|
|
void SetAppPath(const base::FilePath& app_path);
|
2020-07-07 18:00:45 +00:00
|
|
|
void ChildProcessLaunched(int process_type,
|
2020-12-01 01:47:46 +00:00
|
|
|
int pid,
|
2020-07-07 18:00:45 +00:00
|
|
|
base::ProcessHandle handle,
|
2020-10-19 11:55:47 +00:00
|
|
|
const std::string& service_name = std::string(),
|
2020-07-07 18:00:45 +00:00
|
|
|
const std::string& name = std::string());
|
2020-12-01 01:47:46 +00:00
|
|
|
void ChildProcessDisconnected(int pid);
|
2017-04-04 00:36:01 +00:00
|
|
|
|
2019-09-06 05:52:54 +00:00
|
|
|
void SetAppLogsPath(gin_helper::ErrorThrower thrower,
|
2021-06-03 08:05:04 +00:00
|
|
|
absl::optional<base::FilePath> custom_path);
|
2019-04-19 05:04:58 +00:00
|
|
|
|
2015-01-19 01:52:15 +00:00
|
|
|
// Get/Set the pre-defined path in PathService.
|
2019-09-06 05:52:54 +00:00
|
|
|
base::FilePath GetPath(gin_helper::ErrorThrower thrower,
|
|
|
|
const std::string& name);
|
|
|
|
void SetPath(gin_helper::ErrorThrower thrower,
|
2015-01-19 04:24:58 +00:00
|
|
|
const std::string& name,
|
|
|
|
const base::FilePath& path);
|
2015-01-19 01:52:15 +00:00
|
|
|
|
2014-09-18 11:12:24 +00:00
|
|
|
void SetDesktopName(const std::string& desktop_name);
|
2016-06-02 12:49:29 +00:00
|
|
|
std::string GetLocale();
|
2018-11-20 20:33:23 +00:00
|
|
|
std::string GetLocaleCountryCode();
|
2022-09-23 18:50:46 +00:00
|
|
|
std::string GetSystemLocale(gin_helper::ErrorThrower thrower) const;
|
2022-05-23 05:20:54 +00:00
|
|
|
void OnSecondInstance(const base::CommandLine& cmd,
|
|
|
|
const base::FilePath& cwd,
|
|
|
|
const std::vector<const uint8_t> additional_data);
|
2018-05-07 15:29:18 +00:00
|
|
|
bool HasSingleInstanceLock() const;
|
2021-10-15 01:32:32 +00:00
|
|
|
bool RequestSingleInstanceLock(gin::Arguments* args);
|
2018-05-07 15:29:18 +00:00
|
|
|
void ReleaseSingleInstanceLock();
|
2020-07-28 23:43:43 +00:00
|
|
|
bool Relaunch(gin::Arguments* args);
|
2019-09-06 05:52:54 +00:00
|
|
|
void DisableHardwareAcceleration(gin_helper::ErrorThrower thrower);
|
|
|
|
void DisableDomainBlockingFor3DAPIs(gin_helper::ErrorThrower thrower);
|
2016-07-11 21:32:14 +00:00
|
|
|
bool IsAccessibilitySupportEnabled();
|
2019-09-06 05:52:54 +00:00
|
|
|
void SetAccessibilitySupportEnabled(gin_helper::ErrorThrower thrower,
|
|
|
|
bool enabled);
|
2020-07-28 23:43:43 +00:00
|
|
|
Browser::LoginItemSettings GetLoginItemSettings(gin::Arguments* args);
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(USE_NSS_CERTS)
|
2020-04-13 20:52:07 +00:00
|
|
|
void ImportCertificate(gin_helper::ErrorThrower thrower,
|
|
|
|
base::Value options,
|
|
|
|
net::CompletionOnceCallback callback);
|
2016-04-19 05:17:28 +00:00
|
|
|
#endif
|
2018-12-05 16:50:12 +00:00
|
|
|
v8::Local<v8::Promise> GetFileIcon(const base::FilePath& path,
|
2020-07-28 23:43:43 +00:00
|
|
|
gin::Arguments* args);
|
2015-10-21 20:17:56 +00:00
|
|
|
|
2019-10-24 05:47:58 +00:00
|
|
|
std::vector<gin_helper::Dictionary> GetAppMetrics(v8::Isolate* isolate);
|
2017-05-30 20:00:55 +00:00
|
|
|
v8::Local<v8::Value> GetGPUFeatureStatus(v8::Isolate* isolate);
|
2018-09-27 14:59:23 +00:00
|
|
|
v8::Local<v8::Promise> GetGPUInfo(v8::Isolate* isolate,
|
|
|
|
const std::string& info_type);
|
2019-09-06 05:52:54 +00:00
|
|
|
void EnableSandbox(gin_helper::ErrorThrower thrower);
|
2019-05-01 23:34:42 +00:00
|
|
|
void SetUserAgentFallback(const std::string& user_agent);
|
|
|
|
std::string GetUserAgentFallback();
|
2017-04-17 11:59:16 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2020-02-05 19:12:25 +00:00
|
|
|
void SetActivationPolicy(gin_helper::ErrorThrower thrower,
|
|
|
|
const std::string& policy);
|
2019-10-24 05:47:58 +00:00
|
|
|
bool MoveToApplicationsFolder(gin_helper::ErrorThrower, gin::Arguments* args);
|
2017-08-31 14:37:12 +00:00
|
|
|
bool IsInApplicationsFolder();
|
2019-02-14 22:29:20 +00:00
|
|
|
v8::Local<v8::Value> GetDockAPI(v8::Isolate* isolate);
|
2020-11-13 20:53:32 +00:00
|
|
|
bool IsRunningUnderRosettaTranslation() const;
|
2019-02-14 22:29:20 +00:00
|
|
|
v8::Global<v8::Value> dock_;
|
2017-08-31 14:37:12 +00:00
|
|
|
#endif
|
2019-03-14 20:39:52 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
|
2021-06-02 07:16:33 +00:00
|
|
|
bool IsRunningUnderARM64Translation() const;
|
|
|
|
#endif
|
|
|
|
|
2018-02-12 18:25:06 +00:00
|
|
|
#if defined(MAS_BUILD)
|
2019-04-24 18:29:59 +00:00
|
|
|
base::RepeatingCallback<void()> StartAccessingSecurityScopedResource(
|
2020-07-28 23:43:43 +00:00
|
|
|
gin::Arguments* args);
|
2018-02-12 18:25:06 +00:00
|
|
|
#endif
|
2017-08-31 14:37:12 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-08-12 09:31:17 +00:00
|
|
|
// Get the current Jump List settings.
|
|
|
|
v8::Local<v8::Value> GetJumpListSettings();
|
|
|
|
|
|
|
|
// Set or remove a custom Jump List for the application.
|
2020-07-28 23:43:43 +00:00
|
|
|
JumpListResult SetJumpList(v8::Local<v8::Value> val, gin::Arguments* args);
|
2022-02-10 02:58:52 +00:00
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
2016-08-12 09:31:17 +00:00
|
|
|
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<ProcessSingleton> process_singleton_;
|
2016-04-19 05:17:28 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(USE_NSS_CERTS)
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<CertificateManagerModel> certificate_manager_model_;
|
2016-04-19 05:17:28 +00:00
|
|
|
#endif
|
2014-08-19 13:26:45 +00:00
|
|
|
|
2017-02-17 08:33:46 +00:00
|
|
|
// Tracks tasks requesting file icons.
|
|
|
|
base::CancelableTaskTracker cancelable_task_tracker_;
|
|
|
|
|
2017-04-13 01:59:12 +00:00
|
|
|
base::FilePath app_path_;
|
2017-04-04 00:36:01 +00:00
|
|
|
|
2017-05-16 00:41:45 +00:00
|
|
|
using ProcessMetricMap =
|
2020-12-01 01:47:46 +00:00
|
|
|
std::map<int, std::unique_ptr<electron::ProcessMetric>>;
|
2017-05-16 00:41:45 +00:00
|
|
|
ProcessMetricMap app_metrics_;
|
|
|
|
|
2020-04-13 23:39:26 +00:00
|
|
|
bool disable_hw_acceleration_ = false;
|
|
|
|
bool disable_domain_blocking_for_3DAPIs_ = false;
|
2022-08-19 22:45:58 +00:00
|
|
|
bool watch_singleton_socket_on_ready_ = false;
|
2013-05-02 16:05:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_APP_H_
|