| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ | 5 #ifndef HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ |
| 6 #define HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ | 6 #define HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "headless/public/headless_export.h" | 10 #include "headless/public/headless_export.h" |
| 11 #include "ui/gfx/geometry/size.h" |
| 11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 12 | 13 |
| 13 namespace headless { | 14 namespace headless { |
| 15 class HeadlessBrowserContext; |
| 16 class HeadlessBrowserImpl; |
| 14 class HeadlessDevToolsTarget; | 17 class HeadlessDevToolsTarget; |
| 15 | 18 |
| 16 // Class representing contents of a browser tab. Should be accessed from browser | 19 // Class representing contents of a browser tab. Should be accessed from browser |
| 17 // main thread. | 20 // main thread. |
| 18 class HEADLESS_EXPORT HeadlessWebContents { | 21 class HEADLESS_EXPORT HeadlessWebContents { |
| 19 public: | 22 public: |
| 23 class Builder; |
| 24 |
| 20 virtual ~HeadlessWebContents() {} | 25 virtual ~HeadlessWebContents() {} |
| 21 | 26 |
| 22 class Observer { | 27 class Observer { |
| 23 public: | 28 public: |
| 24 // All the following notifications will be called on browser main thread. | 29 // All the following notifications will be called on browser main thread. |
| 25 | 30 |
| 26 // Indicates that this HeadlessWebContents instance is now ready to be | 31 // Indicates that this HeadlessWebContents instance is now ready to be |
| 27 // inspected using a HeadlessDevToolsClient. | 32 // inspected using a HeadlessDevToolsClient. |
| 28 // | 33 // |
| 29 // TODO(altimin): Support this event for pages that aren't created by us. | 34 // TODO(altimin): Support this event for pages that aren't created by us. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 50 // Close this page. |HeadlessWebContents| object will be destroyed. | 55 // Close this page. |HeadlessWebContents| object will be destroyed. |
| 51 virtual void Close() = 0; | 56 virtual void Close() = 0; |
| 52 | 57 |
| 53 private: | 58 private: |
| 54 friend class HeadlessWebContentsImpl; | 59 friend class HeadlessWebContentsImpl; |
| 55 HeadlessWebContents() {} | 60 HeadlessWebContents() {} |
| 56 | 61 |
| 57 DISALLOW_COPY_AND_ASSIGN(HeadlessWebContents); | 62 DISALLOW_COPY_AND_ASSIGN(HeadlessWebContents); |
| 58 }; | 63 }; |
| 59 | 64 |
| 65 class HEADLESS_EXPORT HeadlessWebContents::Builder { |
| 66 public: |
| 67 ~Builder(); |
| 68 Builder(Builder&&); |
| 69 |
| 70 // Set an initial URL to ensure that the renderer gets initialized and |
| 71 // eventually becomes ready to be inspected. See |
| 72 // HeadlessWebContents::Observer::DevToolsTargetReady. The default URL is |
| 73 // about:blank. |
| 74 Builder& SetInitialURL(const GURL& initial_url); |
| 75 |
| 76 // Specify the initial window size (default is 800x600). |
| 77 Builder& SetWindowSize(const gfx::Size& size); |
| 78 |
| 79 // Set a browser context for storing session data (e.g., cookies, cache, local |
| 80 // storage) for the tab. Several tabs can share the same browser context. If |
| 81 // unset, the default browser context will be used. The browser context must |
| 82 // outlive this HeadlessWebContents. |
| 83 Builder& SetBrowserContext(HeadlessBrowserContext* browser_context); |
| 84 |
| 85 // The returned object is owned by HeadlessBrowser. Call |
| 86 // HeadlessWebContents::Close() to dispose it. |
| 87 HeadlessWebContents* Build(); |
| 88 |
| 89 private: |
| 90 friend class HeadlessBrowserImpl; |
| 91 friend class HeadlessWebContentsImpl; |
| 92 |
| 93 explicit Builder(HeadlessBrowserImpl* browser); |
| 94 |
| 95 HeadlessBrowserImpl* browser_; |
| 96 GURL initial_url_ = GURL("about:blank"); |
| 97 gfx::Size window_size_ = gfx::Size(800, 600); |
| 98 HeadlessBrowserContext* browser_context_; |
| 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(Builder); |
| 101 }; |
| 102 |
| 60 } // namespace headless | 103 } // namespace headless |
| 61 | 104 |
| 62 #endif // HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ | 105 #endif // HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ |
| OLD | NEW |