2015-06-16 09:23:29 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SESSION_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SESSION_H_
|
2015-06-16 09:23:29 +00:00
|
|
|
|
2024-01-10 22:23:35 +00:00
|
|
|
#include <optional>
|
2015-06-24 03:59:11 +00:00
|
|
|
#include <string>
|
2017-09-16 15:13:55 +00:00
|
|
|
#include <vector>
|
2015-06-24 03:59:11 +00:00
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2024-07-22 09:31:32 +00:00
|
|
|
#include "base/memory/raw_ref.h"
|
2024-07-08 10:55:48 +00:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2016-07-12 12:53:19 +00:00
|
|
|
#include "base/values.h"
|
2015-08-30 18:52:01 +00:00
|
|
|
#include "content/public/browser/download_manager.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2020-05-19 17:18:12 +00:00
|
|
|
#include "gin/wrappable.h"
|
2024-09-17 19:58:56 +00:00
|
|
|
#include "services/network/public/mojom/host_resolver.mojom-forward.h"
|
|
|
|
#include "services/network/public/mojom/ssl_config.mojom-forward.h"
|
2020-05-19 17:18:12 +00:00
|
|
|
#include "shell/browser/event_emitter_mixin.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/net/resolve_proxy_helper.h"
|
2020-07-20 19:13:33 +00:00
|
|
|
#include "shell/common/gin_helper/cleaned_up_at_exit.h"
|
2023-02-20 20:57:38 +00:00
|
|
|
#include "shell/common/gin_helper/constructible.h"
|
2020-05-19 17:18:12 +00:00
|
|
|
#include "shell/common/gin_helper/pinnable.h"
|
2015-06-16 09:23:29 +00:00
|
|
|
|
2020-03-10 09:39:40 +00:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
#include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h" // nogncheck
|
|
|
|
#endif
|
|
|
|
|
2020-09-23 19:29:08 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
#include "extensions/browser/extension_registry.h"
|
|
|
|
#include "extensions/browser/extension_registry_observer.h"
|
|
|
|
#endif
|
|
|
|
|
2015-06-24 03:59:11 +00:00
|
|
|
class GURL;
|
|
|
|
|
2015-07-30 02:38:04 +00:00
|
|
|
namespace base {
|
|
|
|
class FilePath;
|
|
|
|
}
|
|
|
|
|
2020-05-19 17:18:12 +00:00
|
|
|
namespace gin {
|
|
|
|
class Arguments;
|
2024-07-29 17:42:57 +00:00
|
|
|
template <typename T>
|
|
|
|
class Handle;
|
|
|
|
} // namespace gin
|
|
|
|
|
|
|
|
namespace gin_helper {
|
|
|
|
class Dictionary;
|
|
|
|
class ErrorThrower;
|
|
|
|
} // namespace gin_helper
|
2020-05-19 17:18:12 +00:00
|
|
|
|
2015-10-22 17:26:36 +00:00
|
|
|
namespace net {
|
|
|
|
class ProxyConfig;
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2015-06-16 09:23:29 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
class ElectronBrowserContext;
|
2015-06-23 15:40:41 +00:00
|
|
|
|
2015-06-16 09:23:29 +00:00
|
|
|
namespace api {
|
|
|
|
|
2024-09-04 23:40:02 +00:00
|
|
|
class Session final : public gin::Wrappable<Session>,
|
|
|
|
public gin_helper::Pinnable<Session>,
|
|
|
|
public gin_helper::Constructible<Session>,
|
|
|
|
public gin_helper::EventEmitterMixin<Session>,
|
|
|
|
public gin_helper::CleanedUpAtExit,
|
2020-03-10 09:39:40 +00:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
2024-09-04 23:40:02 +00:00
|
|
|
private SpellcheckHunspellDictionary::Observer,
|
2020-09-23 19:29:08 +00:00
|
|
|
#endif
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2024-09-04 23:40:02 +00:00
|
|
|
private extensions::ExtensionRegistryObserver,
|
2020-03-10 09:39:40 +00:00
|
|
|
#endif
|
2024-09-04 23:40:02 +00:00
|
|
|
private content::DownloadManager::Observer {
|
2015-06-16 09:23:29 +00:00
|
|
|
public:
|
2015-06-24 07:37:04 +00:00
|
|
|
// Gets or creates Session from the |browser_context|.
|
2020-02-04 20:19:40 +00:00
|
|
|
static gin::Handle<Session> CreateFrom(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
ElectronBrowserContext* browser_context);
|
2023-02-20 20:57:38 +00:00
|
|
|
static gin::Handle<Session> New(); // Dummy, do not use!
|
2015-06-16 09:23:29 +00:00
|
|
|
|
2020-05-19 17:18:12 +00:00
|
|
|
static Session* FromBrowserContext(content::BrowserContext* context);
|
|
|
|
|
2016-07-12 12:01:49 +00:00
|
|
|
// Gets the Session of |partition|.
|
2022-07-05 15:25:18 +00:00
|
|
|
static gin::Handle<Session> FromPartition(v8::Isolate* isolate,
|
|
|
|
const std::string& partition,
|
|
|
|
base::Value::Dict options = {});
|
2015-09-05 14:39:48 +00:00
|
|
|
|
2023-03-20 14:34:49 +00:00
|
|
|
// Gets the Session based on |path|.
|
2024-01-10 22:23:35 +00:00
|
|
|
static std::optional<gin::Handle<Session>> FromPath(
|
2023-03-20 14:34:49 +00:00
|
|
|
v8::Isolate* isolate,
|
|
|
|
const base::FilePath& path,
|
|
|
|
base::Value::Dict options = {});
|
|
|
|
|
2024-07-02 21:53:36 +00:00
|
|
|
ElectronBrowserContext* browser_context() const {
|
|
|
|
return &browser_context_.get();
|
|
|
|
}
|
2015-07-15 12:35:38 +00:00
|
|
|
|
2020-05-19 17:18:12 +00:00
|
|
|
// gin::Wrappable
|
|
|
|
static gin::WrapperInfo kWrapperInfo;
|
2023-02-20 20:57:38 +00:00
|
|
|
static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>);
|
2023-07-10 09:49:20 +00:00
|
|
|
static const char* GetClassName() { return "Session"; }
|
2020-05-19 17:18:12 +00:00
|
|
|
const char* GetTypeName() override;
|
2015-12-03 08:04:46 +00:00
|
|
|
|
2016-06-22 06:57:51 +00:00
|
|
|
// Methods.
|
2023-04-05 14:06:14 +00:00
|
|
|
v8::Local<v8::Promise> ResolveHost(
|
|
|
|
std::string host,
|
2024-01-10 22:23:35 +00:00
|
|
|
std::optional<network::mojom::ResolveHostParametersPtr> params);
|
2020-05-19 17:18:12 +00:00
|
|
|
v8::Local<v8::Promise> ResolveProxy(gin::Arguments* args);
|
2019-04-30 22:09:17 +00:00
|
|
|
v8::Local<v8::Promise> GetCacheSize();
|
|
|
|
v8::Local<v8::Promise> ClearCache();
|
2020-05-19 17:18:12 +00:00
|
|
|
v8::Local<v8::Promise> ClearStorageData(gin::Arguments* args);
|
2016-01-12 15:28:12 +00:00
|
|
|
void FlushStorageData();
|
2020-05-19 17:18:12 +00:00
|
|
|
v8::Local<v8::Promise> SetProxy(gin::Arguments* args);
|
2020-10-27 06:50:06 +00:00
|
|
|
v8::Local<v8::Promise> ForceReloadProxyConfig();
|
2015-07-30 02:38:04 +00:00
|
|
|
void SetDownloadPath(const base::FilePath& path);
|
2019-10-25 13:03:28 +00:00
|
|
|
void EnableNetworkEmulation(const gin_helper::Dictionary& options);
|
2015-09-27 13:19:52 +00:00
|
|
|
void DisableNetworkEmulation();
|
2020-05-19 17:18:12 +00:00
|
|
|
void SetCertVerifyProc(v8::Local<v8::Value> proc, gin::Arguments* args);
|
2016-01-31 21:35:34 +00:00
|
|
|
void SetPermissionRequestHandler(v8::Local<v8::Value> val,
|
2020-05-19 17:18:12 +00:00
|
|
|
gin::Arguments* args);
|
2018-08-28 14:05:08 +00:00
|
|
|
void SetPermissionCheckHandler(v8::Local<v8::Value> val,
|
2020-05-19 17:18:12 +00:00
|
|
|
gin::Arguments* args);
|
2021-09-23 11:00:11 +00:00
|
|
|
void SetDevicePermissionHandler(v8::Local<v8::Value> val,
|
|
|
|
gin::Arguments* args);
|
2023-05-30 16:35:25 +00:00
|
|
|
void SetUSBProtectedClassesHandler(v8::Local<v8::Value> val,
|
|
|
|
gin::Arguments* args);
|
2022-09-26 14:19:58 +00:00
|
|
|
void SetBluetoothPairingHandler(v8::Local<v8::Value> val,
|
|
|
|
gin::Arguments* args);
|
2020-05-19 17:18:12 +00:00
|
|
|
v8::Local<v8::Promise> ClearHostResolverCache(gin::Arguments* args);
|
2019-05-03 21:30:25 +00:00
|
|
|
v8::Local<v8::Promise> ClearAuthCache();
|
2016-05-23 05:29:55 +00:00
|
|
|
void AllowNTLMCredentialsForDomains(const std::string& domains);
|
2020-05-19 17:18:12 +00:00
|
|
|
void SetUserAgent(const std::string& user_agent, gin::Arguments* args);
|
2016-06-22 06:57:51 +00:00
|
|
|
std::string GetUserAgent();
|
2020-09-23 20:22:10 +00:00
|
|
|
void SetSSLConfig(network::mojom::SSLConfigPtr config);
|
2020-03-11 07:02:22 +00:00
|
|
|
bool IsPersistent();
|
2019-03-14 15:11:01 +00:00
|
|
|
v8::Local<v8::Promise> GetBlobData(v8::Isolate* isolate,
|
|
|
|
const std::string& uuid);
|
2023-06-21 13:31:28 +00:00
|
|
|
void DownloadURL(const GURL& url, gin::Arguments* args);
|
2019-10-25 13:03:28 +00:00
|
|
|
void CreateInterruptedDownload(const gin_helper::Dictionary& options);
|
2020-11-10 17:06:03 +00:00
|
|
|
void SetPreloads(const std::vector<base::FilePath>& preloads);
|
|
|
|
std::vector<base::FilePath> GetPreloads() const;
|
2015-06-16 09:23:29 +00:00
|
|
|
v8::Local<v8::Value> Cookies(v8::Isolate* isolate);
|
2016-06-08 14:31:27 +00:00
|
|
|
v8::Local<v8::Value> Protocol(v8::Isolate* isolate);
|
2020-02-20 23:19:06 +00:00
|
|
|
v8::Local<v8::Value> ServiceWorkerContext(v8::Isolate* isolate);
|
2015-12-01 04:52:22 +00:00
|
|
|
v8::Local<v8::Value> WebRequest(v8::Isolate* isolate);
|
2018-10-04 18:08:56 +00:00
|
|
|
v8::Local<v8::Value> NetLog(v8::Isolate* isolate);
|
2020-05-19 17:18:12 +00:00
|
|
|
void Preconnect(const gin_helper::Dictionary& options, gin::Arguments* args);
|
2020-10-08 16:45:36 +00:00
|
|
|
v8::Local<v8::Promise> CloseAllConnections();
|
2021-04-27 16:54:28 +00:00
|
|
|
v8::Local<v8::Value> GetPath(v8::Isolate* isolate);
|
2022-03-15 20:34:53 +00:00
|
|
|
void SetCodeCachePath(gin::Arguments* args);
|
|
|
|
v8::Local<v8::Promise> ClearCodeCaches(const gin_helper::Dictionary& options);
|
2024-04-01 16:09:01 +00:00
|
|
|
v8::Local<v8::Value> ClearData(gin_helper::ErrorThrower thrower,
|
|
|
|
gin::Arguments* args);
|
2019-10-31 20:11:51 +00:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
base::Value GetSpellCheckerLanguages();
|
|
|
|
void SetSpellCheckerLanguages(gin_helper::ErrorThrower thrower,
|
|
|
|
const std::vector<std::string>& languages);
|
2020-02-10 22:08:53 +00:00
|
|
|
v8::Local<v8::Promise> ListWordsInSpellCheckerDictionary();
|
2019-11-26 21:16:43 +00:00
|
|
|
bool AddWordToSpellCheckerDictionary(const std::string& word);
|
2020-02-10 22:07:25 +00:00
|
|
|
bool RemoveWordFromSpellCheckerDictionary(const std::string& word);
|
2020-11-11 15:29:18 +00:00
|
|
|
void SetSpellCheckerEnabled(bool b);
|
|
|
|
bool IsSpellCheckerEnabled() const;
|
2019-10-31 20:11:51 +00:00
|
|
|
#endif
|
2015-06-16 09:23:29 +00:00
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2021-02-01 22:41:08 +00:00
|
|
|
v8::Local<v8::Promise> LoadExtension(const base::FilePath& extension_path,
|
|
|
|
gin::Arguments* args);
|
2020-01-13 22:56:28 +00:00
|
|
|
void RemoveExtension(const std::string& extension_id);
|
|
|
|
v8::Local<v8::Value> GetExtension(const std::string& extension_id);
|
|
|
|
v8::Local<v8::Value> GetAllExtensions();
|
2020-09-23 19:29:08 +00:00
|
|
|
|
|
|
|
// extensions::ExtensionRegistryObserver:
|
|
|
|
void OnExtensionLoaded(content::BrowserContext* browser_context,
|
|
|
|
const extensions::Extension* extension) override;
|
|
|
|
void OnExtensionReady(content::BrowserContext* browser_context,
|
|
|
|
const extensions::Extension* extension) override;
|
|
|
|
void OnExtensionUnloaded(content::BrowserContext* browser_context,
|
|
|
|
const extensions::Extension* extension,
|
|
|
|
extensions::UnloadedExtensionReason reason) override;
|
2019-07-24 23:01:08 +00:00
|
|
|
#endif
|
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
Session(const Session&) = delete;
|
|
|
|
Session& operator=(const Session&) = delete;
|
|
|
|
|
2016-06-22 06:57:51 +00:00
|
|
|
protected:
|
2020-02-04 20:19:40 +00:00
|
|
|
Session(v8::Isolate* isolate, ElectronBrowserContext* browser_context);
|
2018-04-17 23:03:51 +00:00
|
|
|
~Session() override;
|
2016-06-22 06:57:51 +00:00
|
|
|
|
|
|
|
// content::DownloadManager::Observer:
|
|
|
|
void OnDownloadCreated(content::DownloadManager* manager,
|
2018-04-10 15:29:26 +00:00
|
|
|
download::DownloadItem* item) override;
|
2016-06-22 06:57:51 +00:00
|
|
|
|
2020-03-10 09:39:40 +00:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
2020-03-05 19:58:19 +00:00
|
|
|
// SpellcheckHunspellDictionary::Observer
|
|
|
|
void OnHunspellDictionaryInitialized(const std::string& language) override;
|
|
|
|
void OnHunspellDictionaryDownloadBegin(const std::string& language) override;
|
|
|
|
void OnHunspellDictionaryDownloadSuccess(
|
|
|
|
const std::string& language) override;
|
|
|
|
void OnHunspellDictionaryDownloadFailure(
|
|
|
|
const std::string& language) override;
|
2020-03-10 09:39:40 +00:00
|
|
|
#endif
|
2020-03-05 19:58:19 +00:00
|
|
|
|
2016-06-22 06:57:51 +00:00
|
|
|
private:
|
2022-08-22 21:15:32 +00:00
|
|
|
void SetDisplayMediaRequestHandler(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val);
|
|
|
|
|
2019-12-05 09:46:34 +00:00
|
|
|
// Cached gin_helper::Wrappable objects.
|
2015-06-16 09:23:29 +00:00
|
|
|
v8::Global<v8::Value> cookies_;
|
2016-06-08 14:31:27 +00:00
|
|
|
v8::Global<v8::Value> protocol_;
|
2018-10-04 18:08:56 +00:00
|
|
|
v8::Global<v8::Value> net_log_;
|
2020-02-20 23:19:06 +00:00
|
|
|
v8::Global<v8::Value> service_worker_context_;
|
2019-08-13 05:47:35 +00:00
|
|
|
v8::Global<v8::Value> web_request_;
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<v8::Isolate> isolate_;
|
2021-03-29 10:45:08 +00:00
|
|
|
|
2018-10-02 18:08:10 +00:00
|
|
|
// The client id to enable the network throttler.
|
|
|
|
base::UnguessableToken network_emulation_token_;
|
2016-04-18 04:59:15 +00:00
|
|
|
|
2024-07-02 21:53:36 +00:00
|
|
|
const raw_ref<ElectronBrowserContext> browser_context_;
|
2024-07-08 10:55:48 +00:00
|
|
|
|
|
|
|
base::WeakPtrFactory<Session> weak_factory_{this};
|
2015-06-16 09:23:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2015-06-16 09:23:29 +00:00
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SESSION_H_
|