atom_api_session.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright (c) 2015 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_API_ATOM_API_SESSION_H_
  5. #define ATOM_BROWSER_API_ATOM_API_SESSION_H_
  6. #include <string>
  7. #include <vector>
  8. #include "atom/browser/api/trackable_object.h"
  9. #include "atom/browser/atom_blob_reader.h"
  10. #include "atom/browser/net/resolve_proxy_helper.h"
  11. #include "atom/common/promise_util.h"
  12. #include "base/values.h"
  13. #include "content/public/browser/download_manager.h"
  14. #include "native_mate/handle.h"
  15. class GURL;
  16. namespace base {
  17. class FilePath;
  18. }
  19. namespace mate {
  20. class Arguments;
  21. class Dictionary;
  22. } // namespace mate
  23. namespace net {
  24. class ProxyConfig;
  25. }
  26. namespace atom {
  27. class AtomBrowserContext;
  28. namespace api {
  29. class Session : public mate::TrackableObject<Session>,
  30. public content::DownloadManager::Observer {
  31. public:
  32. enum class CacheAction {
  33. CLEAR,
  34. STATS,
  35. };
  36. // Gets or creates Session from the |browser_context|.
  37. static mate::Handle<Session> CreateFrom(v8::Isolate* isolate,
  38. AtomBrowserContext* browser_context);
  39. // Gets the Session of |partition|.
  40. static mate::Handle<Session> FromPartition(
  41. v8::Isolate* isolate,
  42. const std::string& partition,
  43. const base::DictionaryValue& options = base::DictionaryValue());
  44. AtomBrowserContext* browser_context() const { return browser_context_.get(); }
  45. // mate::TrackableObject:
  46. static void BuildPrototype(v8::Isolate* isolate,
  47. v8::Local<v8::FunctionTemplate> prototype);
  48. // Methods.
  49. v8::Local<v8::Promise> ResolveProxy(mate::Arguments* args);
  50. v8::Local<v8::Promise> GetCacheSize();
  51. v8::Local<v8::Promise> ClearCache();
  52. v8::Local<v8::Promise> ClearStorageData(mate::Arguments* args);
  53. void FlushStorageData();
  54. v8::Local<v8::Promise> SetProxy(mate::Arguments* args);
  55. void SetDownloadPath(const base::FilePath& path);
  56. void EnableNetworkEmulation(const mate::Dictionary& options);
  57. void DisableNetworkEmulation();
  58. void SetCertVerifyProc(v8::Local<v8::Value> proc, mate::Arguments* args);
  59. void SetPermissionRequestHandler(v8::Local<v8::Value> val,
  60. mate::Arguments* args);
  61. void SetPermissionCheckHandler(v8::Local<v8::Value> val,
  62. mate::Arguments* args);
  63. v8::Local<v8::Promise> ClearHostResolverCache(mate::Arguments* args);
  64. v8::Local<v8::Promise> ClearAuthCache(mate::Arguments* args);
  65. void AllowNTLMCredentialsForDomains(const std::string& domains);
  66. void SetUserAgent(const std::string& user_agent, mate::Arguments* args);
  67. std::string GetUserAgent();
  68. v8::Local<v8::Promise> GetBlobData(v8::Isolate* isolate,
  69. const std::string& uuid);
  70. void CreateInterruptedDownload(const mate::Dictionary& options);
  71. void SetPreloads(const std::vector<base::FilePath::StringType>& preloads);
  72. std::vector<base::FilePath::StringType> GetPreloads() const;
  73. v8::Local<v8::Value> Cookies(v8::Isolate* isolate);
  74. v8::Local<v8::Value> Protocol(v8::Isolate* isolate);
  75. v8::Local<v8::Value> WebRequest(v8::Isolate* isolate);
  76. v8::Local<v8::Value> NetLog(v8::Isolate* isolate);
  77. protected:
  78. Session(v8::Isolate* isolate, AtomBrowserContext* browser_context);
  79. ~Session() override;
  80. // content::DownloadManager::Observer:
  81. void OnDownloadCreated(content::DownloadManager* manager,
  82. download::DownloadItem* item) override;
  83. private:
  84. // Cached object.
  85. v8::Global<v8::Value> cookies_;
  86. v8::Global<v8::Value> protocol_;
  87. v8::Global<v8::Value> web_request_;
  88. v8::Global<v8::Value> net_log_;
  89. // The client id to enable the network throttler.
  90. base::UnguessableToken network_emulation_token_;
  91. scoped_refptr<AtomBrowserContext> browser_context_;
  92. DISALLOW_COPY_AND_ASSIGN(Session);
  93. };
  94. } // namespace api
  95. } // namespace atom
  96. #endif // ATOM_BROWSER_API_ATOM_API_SESSION_H_