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