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