| 
									
										
										
										
											2015-06-16 17:23:29 +08: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 12:19:40 -08:00
										 |  |  | #ifndef SHELL_BROWSER_API_ELECTRON_API_SESSION_H_
 | 
					
						
							|  |  |  | #define SHELL_BROWSER_API_ELECTRON_API_SESSION_H_
 | 
					
						
							| 
									
										
										
										
											2015-06-16 17:23:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 11:59:11 +08:00
										 |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2017-09-17 01:13:55 +10:00
										 |  |  | #include <vector>
 | 
					
						
							| 
									
										
										
										
											2015-06-24 11:59:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-12 21:53:19 +09:00
										 |  |  | #include "base/values.h"
 | 
					
						
							| 
									
										
										
										
											2015-08-31 00:22:01 +05:30
										 |  |  | #include "content/public/browser/download_manager.h"
 | 
					
						
							| 
									
										
										
										
											2019-07-24 19:01:08 -04:00
										 |  |  | #include "electron/buildflags/buildflags.h"
 | 
					
						
							| 
									
										
										
										
											2019-10-25 22:03:28 +09:00
										 |  |  | #include "gin/handle.h"
 | 
					
						
							| 
									
										
										
										
											2020-05-19 10:18:12 -07:00
										 |  |  | #include "gin/wrappable.h"
 | 
					
						
							| 
									
										
										
										
											2020-09-23 13:22:10 -07:00
										 |  |  | #include "services/network/public/mojom/ssl_config.mojom.h"
 | 
					
						
							| 
									
										
										
										
											2020-05-19 10:18:12 -07:00
										 |  |  | #include "shell/browser/event_emitter_mixin.h"
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:46:59 -07:00
										 |  |  | #include "shell/browser/net/resolve_proxy_helper.h"
 | 
					
						
							| 
									
										
										
										
											2020-07-20 12:13:33 -07:00
										 |  |  | #include "shell/common/gin_helper/cleaned_up_at_exit.h"
 | 
					
						
							| 
									
										
										
										
											2020-05-19 10:18:12 -07:00
										 |  |  | #include "shell/common/gin_helper/error_thrower.h"
 | 
					
						
							|  |  |  | #include "shell/common/gin_helper/function_template_extensions.h"
 | 
					
						
							|  |  |  | #include "shell/common/gin_helper/pinnable.h"
 | 
					
						
							| 
									
										
										
										
											2019-11-01 15:10:32 +09:00
										 |  |  | #include "shell/common/gin_helper/promise.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-16 17:23:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-10 10:39:40 +01:00
										 |  |  | #if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
 | 
					
						
							|  |  |  | #include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h"  // nogncheck
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-23 15:29:08 -04:00
										 |  |  | #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
 | 
					
						
							|  |  |  | #include "extensions/browser/extension_registry.h"
 | 
					
						
							|  |  |  | #include "extensions/browser/extension_registry_observer.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 11:59:11 +08:00
										 |  |  | class GURL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-30 10:38:04 +08:00
										 |  |  | namespace base { | 
					
						
							|  |  |  | class FilePath; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-25 22:03:28 +09:00
										 |  |  | namespace gin_helper { | 
					
						
							| 
									
										
										
										
											2015-09-27 18:49:52 +05:30
										 |  |  | class Dictionary; | 
					
						
							| 
									
										
										
										
											2019-10-25 22:03:28 +09:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-08-10 15:28:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-19 10:18:12 -07:00
										 |  |  | namespace gin { | 
					
						
							|  |  |  | class Arguments; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 22:56:36 +05:30
										 |  |  | namespace net { | 
					
						
							|  |  |  | class ProxyConfig; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  | namespace electron { | 
					
						
							| 
									
										
										
										
											2015-06-16 17:23:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-04 12:19:40 -08:00
										 |  |  | class ElectronBrowserContext; | 
					
						
							| 
									
										
										
										
											2015-06-23 23:40:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 17:23:29 +08:00
										 |  |  | namespace api { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-19 10:18:12 -07:00
										 |  |  | class Session : public gin::Wrappable<Session>, | 
					
						
							|  |  |  |                 public gin_helper::Pinnable<Session>, | 
					
						
							|  |  |  |                 public gin_helper::EventEmitterMixin<Session>, | 
					
						
							| 
									
										
										
										
											2020-07-20 12:13:33 -07:00
										 |  |  |                 public gin_helper::CleanedUpAtExit, | 
					
						
							| 
									
										
										
										
											2020-03-10 10:39:40 +01:00
										 |  |  | #if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
 | 
					
						
							|  |  |  |                 public SpellcheckHunspellDictionary::Observer, | 
					
						
							| 
									
										
										
										
											2020-09-23 15:29:08 -04:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
 | 
					
						
							|  |  |  |                 public extensions::ExtensionRegistryObserver, | 
					
						
							| 
									
										
										
										
											2020-03-10 10:39:40 +01:00
										 |  |  | #endif
 | 
					
						
							|  |  |  |                 public content::DownloadManager::Observer { | 
					
						
							| 
									
										
										
										
											2015-06-16 17:23:29 +08:00
										 |  |  |  public: | 
					
						
							| 
									
										
										
										
											2015-06-24 15:37:04 +08:00
										 |  |  |   // Gets or creates Session from the |browser_context|.
 | 
					
						
							| 
									
										
										
										
											2020-02-04 12:19:40 -08:00
										 |  |  |   static gin::Handle<Session> CreateFrom( | 
					
						
							|  |  |  |       v8::Isolate* isolate, | 
					
						
							|  |  |  |       ElectronBrowserContext* browser_context); | 
					
						
							| 
									
										
										
										
											2015-06-16 17:23:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-19 10:18:12 -07:00
										 |  |  |   static Session* FromBrowserContext(content::BrowserContext* context); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-12 21:01:49 +09:00
										 |  |  |   // Gets the Session of |partition|.
 | 
					
						
							| 
									
										
										
										
											2019-10-25 22:03:28 +09:00
										 |  |  |   static gin::Handle<Session> FromPartition( | 
					
						
							| 
									
										
										
										
											2018-04-17 21:44:10 -04:00
										 |  |  |       v8::Isolate* isolate, | 
					
						
							|  |  |  |       const std::string& partition, | 
					
						
							| 
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 |  |  |       base::DictionaryValue options = base::DictionaryValue()); | 
					
						
							| 
									
										
										
										
											2015-09-05 22:39:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-17 13:21:53 -07:00
										 |  |  |   ElectronBrowserContext* browser_context() const { return browser_context_; } | 
					
						
							| 
									
										
										
										
											2015-07-15 18:05:38 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-19 10:18:12 -07:00
										 |  |  |   // gin::Wrappable
 | 
					
						
							|  |  |  |   static gin::WrapperInfo kWrapperInfo; | 
					
						
							|  |  |  |   gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | 
					
						
							|  |  |  |       v8::Isolate* isolate) override; | 
					
						
							|  |  |  |   const char* GetTypeName() override; | 
					
						
							| 
									
										
										
										
											2015-12-03 16:04:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 15:57:51 +09:00
										 |  |  |   // Methods.
 | 
					
						
							| 
									
										
										
										
											2020-05-19 10:18:12 -07:00
										 |  |  |   v8::Local<v8::Promise> ResolveProxy(gin::Arguments* args); | 
					
						
							| 
									
										
										
										
											2019-04-30 15:09:17 -07:00
										 |  |  |   v8::Local<v8::Promise> GetCacheSize(); | 
					
						
							|  |  |  |   v8::Local<v8::Promise> ClearCache(); | 
					
						
							| 
									
										
										
										
											2020-05-19 10:18:12 -07:00
										 |  |  |   v8::Local<v8::Promise> ClearStorageData(gin::Arguments* args); | 
					
						
							| 
									
										
										
										
											2016-01-12 20:58:12 +05:30
										 |  |  |   void FlushStorageData(); | 
					
						
							| 
									
										
										
										
											2020-05-19 10:18:12 -07:00
										 |  |  |   v8::Local<v8::Promise> SetProxy(gin::Arguments* args); | 
					
						
							| 
									
										
										
										
											2020-10-27 14:50:06 +08:00
										 |  |  |   v8::Local<v8::Promise> ForceReloadProxyConfig(); | 
					
						
							| 
									
										
										
										
											2015-07-30 10:38:04 +08:00
										 |  |  |   void SetDownloadPath(const base::FilePath& path); | 
					
						
							| 
									
										
										
										
											2019-10-25 22:03:28 +09:00
										 |  |  |   void EnableNetworkEmulation(const gin_helper::Dictionary& options); | 
					
						
							| 
									
										
										
										
											2015-09-27 18:49:52 +05:30
										 |  |  |   void DisableNetworkEmulation(); | 
					
						
							| 
									
										
										
										
											2020-05-19 10:18:12 -07:00
										 |  |  |   void SetCertVerifyProc(v8::Local<v8::Value> proc, gin::Arguments* args); | 
					
						
							| 
									
										
										
										
											2016-02-01 03:05:34 +05:30
										 |  |  |   void SetPermissionRequestHandler(v8::Local<v8::Value> val, | 
					
						
							| 
									
										
										
										
											2020-05-19 10:18:12 -07:00
										 |  |  |                                    gin::Arguments* args); | 
					
						
							| 
									
										
										
										
											2018-08-29 02:05:08 +12:00
										 |  |  |   void SetPermissionCheckHandler(v8::Local<v8::Value> val, | 
					
						
							| 
									
										
										
										
											2020-05-19 10:18:12 -07:00
										 |  |  |                                  gin::Arguments* args); | 
					
						
							|  |  |  |   v8::Local<v8::Promise> ClearHostResolverCache(gin::Arguments* args); | 
					
						
							| 
									
										
										
										
											2019-05-03 14:30:25 -07:00
										 |  |  |   v8::Local<v8::Promise> ClearAuthCache(); | 
					
						
							| 
									
										
										
										
											2016-05-23 10:59:55 +05:30
										 |  |  |   void AllowNTLMCredentialsForDomains(const std::string& domains); | 
					
						
							| 
									
										
										
										
											2020-05-19 10:18:12 -07:00
										 |  |  |   void SetUserAgent(const std::string& user_agent, gin::Arguments* args); | 
					
						
							| 
									
										
										
										
											2016-06-22 15:57:51 +09:00
										 |  |  |   std::string GetUserAgent(); | 
					
						
							| 
									
										
										
										
											2020-09-23 13:22:10 -07:00
										 |  |  |   void SetSSLConfig(network::mojom::SSLConfigPtr config); | 
					
						
							| 
									
										
										
										
											2020-03-11 00:02:22 -07:00
										 |  |  |   bool IsPersistent(); | 
					
						
							| 
									
										
										
										
											2019-03-14 08:11:01 -07:00
										 |  |  |   v8::Local<v8::Promise> GetBlobData(v8::Isolate* isolate, | 
					
						
							|  |  |  |                                      const std::string& uuid); | 
					
						
							| 
									
										
										
										
											2019-08-29 05:27:20 +02:00
										 |  |  |   void DownloadURL(const GURL& url); | 
					
						
							| 
									
										
										
										
											2019-10-25 22:03:28 +09:00
										 |  |  |   void CreateInterruptedDownload(const gin_helper::Dictionary& options); | 
					
						
							| 
									
										
										
										
											2020-11-10 09:06:03 -08:00
										 |  |  |   void SetPreloads(const std::vector<base::FilePath>& preloads); | 
					
						
							|  |  |  |   std::vector<base::FilePath> GetPreloads() const; | 
					
						
							| 
									
										
										
										
											2015-06-16 17:23:29 +08:00
										 |  |  |   v8::Local<v8::Value> Cookies(v8::Isolate* isolate); | 
					
						
							| 
									
										
										
										
											2016-06-08 20:01:27 +05:30
										 |  |  |   v8::Local<v8::Value> Protocol(v8::Isolate* isolate); | 
					
						
							| 
									
										
										
										
											2020-02-20 15:19:06 -08:00
										 |  |  |   v8::Local<v8::Value> ServiceWorkerContext(v8::Isolate* isolate); | 
					
						
							| 
									
										
										
										
											2015-12-01 10:22:22 +05:30
										 |  |  |   v8::Local<v8::Value> WebRequest(v8::Isolate* isolate); | 
					
						
							| 
									
										
										
										
											2018-10-04 23:38:56 +05:30
										 |  |  |   v8::Local<v8::Value> NetLog(v8::Isolate* isolate); | 
					
						
							| 
									
										
										
										
											2020-05-19 10:18:12 -07:00
										 |  |  |   void Preconnect(const gin_helper::Dictionary& options, gin::Arguments* args); | 
					
						
							| 
									
										
										
										
											2020-10-09 00:45:36 +08:00
										 |  |  |   v8::Local<v8::Promise> CloseAllConnections(); | 
					
						
							| 
									
										
										
										
											2021-04-27 09:54:28 -07:00
										 |  |  |   v8::Local<v8::Value> GetPath(v8::Isolate* isolate); | 
					
						
							| 
									
										
										
										
											2019-10-31 13:11:51 -07:00
										 |  |  | #if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
 | 
					
						
							|  |  |  |   base::Value GetSpellCheckerLanguages(); | 
					
						
							|  |  |  |   void SetSpellCheckerLanguages(gin_helper::ErrorThrower thrower, | 
					
						
							|  |  |  |                                 const std::vector<std::string>& languages); | 
					
						
							| 
									
										
										
										
											2020-02-10 14:08:53 -08:00
										 |  |  |   v8::Local<v8::Promise> ListWordsInSpellCheckerDictionary(); | 
					
						
							| 
									
										
										
										
											2019-11-26 13:16:43 -08:00
										 |  |  |   bool AddWordToSpellCheckerDictionary(const std::string& word); | 
					
						
							| 
									
										
										
										
											2020-02-10 14:07:25 -08:00
										 |  |  |   bool RemoveWordFromSpellCheckerDictionary(const std::string& word); | 
					
						
							| 
									
										
										
										
											2020-11-12 00:29:18 +09:00
										 |  |  |   void SetSpellCheckerEnabled(bool b); | 
					
						
							|  |  |  |   bool IsSpellCheckerEnabled() const; | 
					
						
							| 
									
										
										
										
											2019-10-31 13:11:51 -07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-06-16 17:23:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-24 19:01:08 -04:00
										 |  |  | #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
 | 
					
						
							| 
									
										
										
										
											2021-02-02 01:41:08 +03:00
										 |  |  |   v8::Local<v8::Promise> LoadExtension(const base::FilePath& extension_path, | 
					
						
							|  |  |  |                                        gin::Arguments* args); | 
					
						
							| 
									
										
										
										
											2020-01-13 14:56:28 -08: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 15:29:08 -04: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 19:01:08 -04:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 15:57:51 +09:00
										 |  |  |  protected: | 
					
						
							| 
									
										
										
										
											2020-02-04 12:19:40 -08:00
										 |  |  |   Session(v8::Isolate* isolate, ElectronBrowserContext* browser_context); | 
					
						
							| 
									
										
										
										
											2018-04-17 16:03:51 -07:00
										 |  |  |   ~Session() override; | 
					
						
							| 
									
										
										
										
											2016-06-22 15:57:51 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // content::DownloadManager::Observer:
 | 
					
						
							|  |  |  |   void OnDownloadCreated(content::DownloadManager* manager, | 
					
						
							| 
									
										
										
										
											2018-04-10 17:29:26 +02:00
										 |  |  |                          download::DownloadItem* item) override; | 
					
						
							| 
									
										
										
										
											2016-06-22 15:57:51 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-10 10:39:40 +01:00
										 |  |  | #if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
 | 
					
						
							| 
									
										
										
										
											2020-03-05 11:58:19 -08: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 10:39:40 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-03-05 11:58:19 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 15:57:51 +09:00
										 |  |  |  private: | 
					
						
							| 
									
										
										
										
											2019-12-05 18:46:34 +09:00
										 |  |  |   // Cached gin_helper::Wrappable objects.
 | 
					
						
							| 
									
										
										
										
											2015-06-16 17:23:29 +08:00
										 |  |  |   v8::Global<v8::Value> cookies_; | 
					
						
							| 
									
										
										
										
											2016-06-08 20:01:27 +05:30
										 |  |  |   v8::Global<v8::Value> protocol_; | 
					
						
							| 
									
										
										
										
											2018-10-04 23:38:56 +05:30
										 |  |  |   v8::Global<v8::Value> net_log_; | 
					
						
							| 
									
										
										
										
											2020-02-20 15:19:06 -08:00
										 |  |  |   v8::Global<v8::Value> service_worker_context_; | 
					
						
							| 
									
										
										
										
											2019-08-13 14:47:35 +09:00
										 |  |  |   v8::Global<v8::Value> web_request_; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-29 10:45:08 +00:00
										 |  |  |   v8::Isolate* isolate_; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-02 11:08:10 -07:00
										 |  |  |   // The client id to enable the network throttler.
 | 
					
						
							|  |  |  |   base::UnguessableToken network_emulation_token_; | 
					
						
							| 
									
										
										
										
											2016-04-18 13:59:15 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-17 13:21:53 -07:00
										 |  |  |   ElectronBrowserContext* browser_context_; | 
					
						
							| 
									
										
										
										
											2015-06-18 18:38:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 17:23:29 +08:00
										 |  |  |   DISALLOW_COPY_AND_ASSIGN(Session); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace api
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  | }  // namespace electron
 | 
					
						
							| 
									
										
										
										
											2015-06-16 17:23:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-04 12:19:40 -08:00
										 |  |  | #endif  // SHELL_BROWSER_API_ELECTRON_API_SESSION_H_
 |