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.
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#ifndef SHELL_BROWSER_API_ELECTRON_API_SESSION_H_
|
|
|
|
#define SHELL_BROWSER_API_ELECTRON_API_SESSION_H_
|
2015-06-16 09:23:29 +00:00
|
|
|
|
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
|
|
|
|
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"
|
2019-10-25 13:03:28 +00:00
|
|
|
#include "gin/handle.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/net/resolve_proxy_helper.h"
|
2019-11-01 06:10:32 +00:00
|
|
|
#include "shell/common/gin_helper/promise.h"
|
2019-10-25 13:03:28 +00:00
|
|
|
#include "shell/common/gin_helper/trackable_object.h"
|
2015-06-16 09:23:29 +00:00
|
|
|
|
2015-06-24 03:59:11 +00:00
|
|
|
class GURL;
|
|
|
|
|
2015-07-30 02:38:04 +00:00
|
|
|
namespace base {
|
|
|
|
class FilePath;
|
|
|
|
}
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
namespace gin_helper {
|
2015-09-27 13:19:52 +00:00
|
|
|
class Dictionary;
|
2019-10-25 13:03:28 +00:00
|
|
|
}
|
2015-08-10 07:28:18 +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 {
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
class Session : public gin_helper::TrackableObject<Session>,
|
2018-04-18 01:44:10 +00:00
|
|
|
public 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);
|
2015-06-16 09:23:29 +00:00
|
|
|
|
2016-07-12 12:01:49 +00:00
|
|
|
// Gets the Session of |partition|.
|
2019-10-25 13:03:28 +00:00
|
|
|
static gin::Handle<Session> FromPartition(
|
2018-04-18 01:44:10 +00:00
|
|
|
v8::Isolate* isolate,
|
|
|
|
const std::string& partition,
|
2019-10-30 05:30:59 +00:00
|
|
|
base::DictionaryValue options = base::DictionaryValue());
|
2015-09-05 14:39:48 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext* browser_context() const {
|
|
|
|
return browser_context_.get();
|
|
|
|
}
|
2015-07-15 12:35:38 +00:00
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
// gin_helper::TrackableObject:
|
2015-12-03 08:04:46 +00:00
|
|
|
static void BuildPrototype(v8::Isolate* isolate,
|
2016-08-02 09:08:12 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> prototype);
|
2015-12-03 08:04:46 +00:00
|
|
|
|
2016-06-22 06:57:51 +00:00
|
|
|
// Methods.
|
2019-10-25 13:03:28 +00:00
|
|
|
v8::Local<v8::Promise> ResolveProxy(gin_helper::Arguments* args);
|
2019-04-30 22:09:17 +00:00
|
|
|
v8::Local<v8::Promise> GetCacheSize();
|
|
|
|
v8::Local<v8::Promise> ClearCache();
|
2019-10-25 13:03:28 +00:00
|
|
|
v8::Local<v8::Promise> ClearStorageData(gin_helper::Arguments* args);
|
2016-01-12 15:28:12 +00:00
|
|
|
void FlushStorageData();
|
2019-10-25 13:03:28 +00:00
|
|
|
v8::Local<v8::Promise> SetProxy(gin_helper::Arguments* args);
|
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();
|
2019-10-25 13:03:28 +00:00
|
|
|
void SetCertVerifyProc(v8::Local<v8::Value> proc,
|
|
|
|
gin_helper::Arguments* args);
|
2016-01-31 21:35:34 +00:00
|
|
|
void SetPermissionRequestHandler(v8::Local<v8::Value> val,
|
2019-10-25 13:03:28 +00:00
|
|
|
gin_helper::Arguments* args);
|
2018-08-28 14:05:08 +00:00
|
|
|
void SetPermissionCheckHandler(v8::Local<v8::Value> val,
|
2019-10-25 13:03:28 +00:00
|
|
|
gin_helper::Arguments* args);
|
|
|
|
v8::Local<v8::Promise> ClearHostResolverCache(gin_helper::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);
|
2019-10-25 13:03:28 +00:00
|
|
|
void SetUserAgent(const std::string& user_agent, gin_helper::Arguments* args);
|
2016-06-22 06:57:51 +00:00
|
|
|
std::string GetUserAgent();
|
2019-03-14 15:11:01 +00:00
|
|
|
v8::Local<v8::Promise> GetBlobData(v8::Isolate* isolate,
|
|
|
|
const std::string& uuid);
|
2019-08-29 03:27:20 +00:00
|
|
|
void DownloadURL(const GURL& url);
|
2019-10-25 13:03:28 +00:00
|
|
|
void CreateInterruptedDownload(const gin_helper::Dictionary& options);
|
2017-12-05 06:59:15 +00:00
|
|
|
void SetPreloads(const std::vector<base::FilePath::StringType>& preloads);
|
2017-12-05 02:50:06 +00:00
|
|
|
std::vector<base::FilePath::StringType> 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);
|
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);
|
2019-10-25 13:03:28 +00:00
|
|
|
void Preconnect(const gin_helper::Dictionary& options,
|
|
|
|
gin_helper::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);
|
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);
|
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)
|
2020-01-13 22:56:28 +00:00
|
|
|
v8::Local<v8::Promise> LoadExtension(const base::FilePath& extension_path);
|
|
|
|
void RemoveExtension(const std::string& extension_id);
|
|
|
|
v8::Local<v8::Value> GetExtension(const std::string& extension_id);
|
|
|
|
v8::Local<v8::Value> GetAllExtensions();
|
2019-07-24 23:01:08 +00:00
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
|
|
|
private:
|
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_;
|
2015-06-16 09:23:29 +00:00
|
|
|
|
2019-08-13 05:47:35 +00:00
|
|
|
// Cached object.
|
|
|
|
v8::Global<v8::Value> web_request_;
|
|
|
|
|
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
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
scoped_refptr<ElectronBrowserContext> browser_context_;
|
2015-06-18 10:38:32 +00:00
|
|
|
|
2015-06-16 09:23:29 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(Session);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
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
|
|
|
#endif // SHELL_BROWSER_API_ELECTRON_API_SESSION_H_
|