atom_browser_context.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright (c) 2013 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_ATOM_BROWSER_CONTEXT_H_
  5. #define ATOM_BROWSER_ATOM_BROWSER_CONTEXT_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/callback_list.h"
  9. #include "brightray/browser/browser_context.h"
  10. namespace atom {
  11. class AtomBlobReader;
  12. class AtomDownloadManagerDelegate;
  13. class AtomNetworkDelegate;
  14. class AtomPermissionManager;
  15. class WebViewManager;
  16. struct CookieDetails;
  17. class AtomBrowserContext : public brightray::BrowserContext {
  18. public:
  19. // Get or create the BrowserContext according to its |partition| and
  20. // |in_memory|. The |options| will be passed to constructor when there is no
  21. // existing BrowserContext.
  22. static scoped_refptr<AtomBrowserContext> From(
  23. const std::string& partition,
  24. bool in_memory,
  25. const base::DictionaryValue& options = base::DictionaryValue());
  26. void SetUserAgent(const std::string& user_agent);
  27. // Register callbacks that needs to notified on any cookie store changes.
  28. std::unique_ptr<base::CallbackList<void(const CookieDetails*)>::Subscription>
  29. RegisterCookieChangeCallback(
  30. const base::Callback<void(const CookieDetails*)>& cb);
  31. // brightray::URLRequestContextGetter::Delegate:
  32. std::unique_ptr<net::NetworkDelegate> CreateNetworkDelegate() override;
  33. std::string GetUserAgent() override;
  34. std::unique_ptr<net::URLRequestJobFactory> CreateURLRequestJobFactory(
  35. content::ProtocolHandlerMap* protocol_handlers) override;
  36. net::HttpCache::BackendFactory* CreateHttpCacheBackendFactory(
  37. const base::FilePath& base_path) override;
  38. std::unique_ptr<net::CertVerifier> CreateCertVerifier(
  39. brightray::RequireCTDelegate* ct_delegate) override;
  40. std::vector<std::string> GetCookieableSchemes() override;
  41. void NotifyCookieChange(const net::CanonicalCookie& cookie,
  42. bool removed,
  43. net::CookieStore::ChangeCause cause) override;
  44. // content::BrowserContext:
  45. content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
  46. content::BrowserPluginGuestManager* GetGuestManager() override;
  47. content::PermissionManager* GetPermissionManager() override;
  48. // brightray::BrowserContext:
  49. void RegisterPrefs(PrefRegistrySimple* pref_registry) override;
  50. AtomBlobReader* GetBlobReader();
  51. void set_cookie_change_subscription(
  52. std::unique_ptr<
  53. base::CallbackList<void(const CookieDetails*)>::Subscription>
  54. subscription) {
  55. cookie_change_subscription_.swap(subscription);
  56. }
  57. protected:
  58. AtomBrowserContext(const std::string& partition,
  59. bool in_memory,
  60. const base::DictionaryValue& options);
  61. ~AtomBrowserContext() override;
  62. private:
  63. std::unique_ptr<AtomDownloadManagerDelegate> download_manager_delegate_;
  64. std::unique_ptr<WebViewManager> guest_manager_;
  65. std::unique_ptr<AtomPermissionManager> permission_manager_;
  66. std::unique_ptr<AtomBlobReader> blob_reader_;
  67. std::string user_agent_;
  68. bool use_cache_;
  69. base::CallbackList<void(const CookieDetails*)> cookie_change_sub_list_;
  70. std::unique_ptr<base::CallbackList<void(const CookieDetails*)>::Subscription>
  71. cookie_change_subscription_;
  72. DISALLOW_COPY_AND_ASSIGN(AtomBrowserContext);
  73. };
  74. } // namespace atom
  75. #endif // ATOM_BROWSER_ATOM_BROWSER_CONTEXT_H_