Chromium Code Reviews| Index: headless/lib/browser/headless_browser_context.h |
| diff --git a/headless/lib/browser/headless_browser_context.h b/headless/lib/browser/headless_browser_context.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c95b95520993b57258b8df46632e463e70c985e9 |
| --- /dev/null |
| +++ b/headless/lib/browser/headless_browser_context.h |
| @@ -0,0 +1,99 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_CONTEXT_H_ |
| +#define HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_CONTEXT_H_ |
| + |
| +#include "base/files/file_path.h" |
| +#include "content/public/browser/browser_context.h" |
| +#include "content/public/browser/content_browser_client.h" |
| +#include "content/public/browser/resource_context.h" |
| +#include "headless/lib/browser/headless_url_request_context_getter.h" |
| +#include "headless/public/headless_browser.h" |
| + |
| +namespace headless { |
| + |
| +class HeadlessBrowserContext : public content::BrowserContext { |
| + public: |
| + explicit HeadlessBrowserContext(const HeadlessBrowser::Options& options); |
| + ~HeadlessBrowserContext() override; |
| + |
| + // BrowserContext implementation: |
| + scoped_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate( |
| + const base::FilePath& partition_path) override; |
| + base::FilePath GetPath() const override; |
| + bool IsOffTheRecord() const override; |
| + net::URLRequestContextGetter* GetRequestContext() override; |
| + net::URLRequestContextGetter* GetRequestContextForRenderProcess( |
| + int renderer_child_id) override; |
| + net::URLRequestContextGetter* GetMediaRequestContext() override; |
| + net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( |
| + int renderer_child_id) override; |
| + net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition( |
| + const base::FilePath& partition_path, |
| + bool in_memory) override; |
| + content::ResourceContext* GetResourceContext() override; |
| + content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; |
| + content::BrowserPluginGuestManager* GetGuestManager() override; |
| + storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override; |
| + content::PushMessagingService* GetPushMessagingService() override; |
| + content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; |
| + content::PermissionManager* GetPermissionManager() override; |
| + content::BackgroundSyncController* GetBackgroundSyncController() override; |
| + |
| + // Clears |protocol_handlers| but does not take ownership of it. |
| + scoped_refptr<net::URLRequestContextGetter> CreateRequestContext( |
| + content::ProtocolHandlerMap* protocol_handlers, |
| + content::URLRequestInterceptorScopedVector request_interceptors); |
|
Ryan Sleevi
2016/02/22 22:01:21
STYLE: The documentation for this (which appears t
Sami
2016/02/23 20:19:07
Agreed -- refactored this into HeadlessContentBrow
|
| + |
| + const HeadlessBrowser::Options& options() const { return options_; } |
| + |
| + private: |
| + // Contains net::URLRequestContextGetter required for resource loading. |
| + class HeadlessResourceContext : public content::ResourceContext { |
|
Ryan Sleevi
2016/02/22 21:11:13
Why don't you simply forward declare this class, a
Sami
2016/02/23 20:19:07
Done.
|
| + public: |
| + HeadlessResourceContext(); |
| + ~HeadlessResourceContext() override; |
| + |
| + // ResourceContext implementation: |
| + net::HostResolver* GetHostResolver() override; |
| + net::URLRequestContext* GetRequestContext() override; |
| + |
| + void set_url_request_context_getter( |
| + scoped_refptr<net::URLRequestContextGetter> getter) { |
| + getter_ = getter; |
| + } |
| + |
| + private: |
| + scoped_refptr<net::URLRequestContextGetter> getter_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(HeadlessResourceContext); |
| + }; |
| + |
| + // Used by HeadlessBrowserContext to initiate and set different types of |
| + // URLRequestContextGetter. |
|
Ryan Sleevi
2016/02/22 22:01:21
Document that it does, not how it's used. https://
Sami
2016/02/23 20:19:07
Removed.
|
| + HeadlessURLRequestContextGetter* CreateURLRequestContextGetter( |
| + content::ProtocolHandlerMap* protocol_handlers, |
| + content::URLRequestInterceptorScopedVector request_interceptors); |
| + |
| + void set_url_request_context_getter( |
| + scoped_refptr<HeadlessURLRequestContextGetter> getter) { |
| + url_request_getter_ = getter; |
|
Ryan Sleevi
2016/02/22 21:11:13
This is a weird API that you have two different cl
Sami
2016/02/23 20:19:07
Agreed, I've now only made one of them hang on to
|
| + } |
| + |
| + // Performs initialization of the HeadlessBrowserContext while IO is still |
| + // allowed on the current thread. |
| + void InitWhileIOAllowed(); |
| + |
| + base::FilePath path_; |
| + scoped_ptr<HeadlessResourceContext> resource_context_; |
| + scoped_refptr<net::URLRequestContextGetter> url_request_getter_; |
| + HeadlessBrowser::Options options_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserContext); |
| +}; |
| + |
| +} // namespace headless |
| + |
| +#endif // HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_CONTEXT_H_ |