Chromium Code Reviews| Index: headless/public/headless_web_contents.h |
| diff --git a/headless/public/web_contents.h b/headless/public/headless_web_contents.h |
| similarity index 64% |
| rename from headless/public/web_contents.h |
| rename to headless/public/headless_web_contents.h |
| index 634cdb4ff3c5cca96e7b324c1706dde6bfb29dbf..d503e9a97e047a178494d7fa404d658d947050bd 100644 |
| --- a/headless/public/web_contents.h |
| +++ b/headless/public/headless_web_contents.h |
| @@ -2,29 +2,31 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef HEADLESS_PUBLIC_WEB_CONTENTS_H_ |
| -#define HEADLESS_PUBLIC_WEB_CONTENTS_H_ |
| +#ifndef HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ |
| +#define HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ |
| #include "base/callback.h" |
| #include "base/macros.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "headless/public/headless_export.h" |
| +#include "ui/gfx/geometry/size.h" |
| #include "url/gurl.h" |
| class SkBitmap; |
| namespace content { |
|
pfeldman
2016/02/09 19:49:51
Do you envision content/ to leak into the headless
Sami
2016/02/09 21:40:51
Right, the idea is to insulate the clients from co
|
| +class NavigationController; |
| class WebContents; |
| } |
| namespace headless { |
| -class WebFrame; |
| +class HeadlessWebFrame; |
| -// Class representing contents of a browser tab. |
| -// Should be accessed from browser main thread. |
| -class HEADLESS_EXPORT WebContents { |
| +// Class representing contents of a browser tab. Should be accessed from browser |
| +// main thread. |
| +class HEADLESS_EXPORT HeadlessWebContents { |
| public: |
| - virtual ~WebContents() {} |
| + virtual ~HeadlessWebContents() {} |
| class Observer { |
| public: |
| @@ -34,7 +36,7 @@ class HEADLESS_EXPORT WebContents { |
| virtual void OnLoadProgressChanged(double progress) = 0; |
| virtual void AddMessageToConsole(const std::string& message) = 0; |
| - virtual bool ShouldSuppressDialogs(WebContents* source) = 0; |
| + virtual bool ShouldSuppressDialogs(HeadlessWebContents* source) = 0; |
| virtual void OnModalAlertDialog(const std::string& message) = 0; |
|
pfeldman
2016/02/09 19:49:51
How is this one accepted programmatically? That's
Sami
2016/02/09 21:40:51
This one was accepted automatically (unlike the tw
|
| virtual bool OnModalConfirmDialog(const std::string& message) = 0; |
| virtual std::string OnModalPromptDialog( |
| @@ -42,9 +44,17 @@ class HEADLESS_EXPORT WebContents { |
| const std::string& default_value) = 0; |
| protected: |
| - explicit Observer(WebContents* web_contents); |
| + // Use this constructor when the observer's lifetime matches that of the |
| + // HeadlessWebContents. |
| + explicit Observer(HeadlessWebContents* web_contents); |
| + |
| + // This constructor creates a detached observer. Use Observe() to attach it |
| + // to a HeadlessWebContents instance. |
| + Observer(); |
| virtual ~Observer(); |
| + void Observe(HeadlessWebContents* web_contents); |
| + |
| private: |
| class ObserverImpl; |
| scoped_ptr<ObserverImpl> observer_; |
| @@ -66,34 +76,34 @@ class HEADLESS_EXPORT WebContents { |
| virtual Settings* GetSettings() = 0; |
| virtual const Settings* GetSettings() const = 0; |
| - virtual NavigationController* GetController() = 0; |
| - virtual const NavigationController* GetController() const = 0; |
| + virtual content::NavigationController* GetController() = 0; |
| + virtual const content::NavigationController* GetController() const = 0; |
| virtual std::string GetTitle() const = 0; |
| virtual const GURL& GetVisibleURL() const = 0; |
| virtual const GURL& GetLastCommittedURL() const = 0; |
| virtual bool IsLoading() const = 0; |
| - virtual bool SetViewportSize(const gfx::Size& size) const = 0; |
| + virtual void SetViewportSize(const gfx::Size& size) = 0; |
|
pfeldman
2016/02/09 19:49:51
Looks at how much more powerful the emulation one
Sami
2016/02/09 21:40:51
Yep, let's try to use that one.
|
| // Returns main frame for web page. Note that the returned interface should |
| // only be used on the renderer main thread. |
| - virtual WebFrame* GetMainFrame() = 0; |
| + virtual HeadlessWebFrame* GetMainFrame() = 0; |
| // Requests browser tab to navigate to given url. |
| virtual void OpenURL(const GURL& url) = 0; |
|
pfeldman
2016/02/09 19:49:51
http://chromedevtools.github.io/debugger-protocol-
Sami
2016/02/09 21:40:51
Ditto. However I still wanted to keep this one aro
|
| + // Renders an image of the web contents. |
| using ScreenshotCallback = base::Callback<void(scoped_ptr<SkBitmap>)>; |
|
pfeldman
2016/02/09 19:49:51
http://chromedevtools.github.io/debugger-protocol-
Sami
2016/02/09 21:40:51
Removed for now.
|
| - // Requests an image of web contents. |
| - virtual void GetScreenshot(const ScreenshotCallback& callback) = 0; |
| + virtual void TakeScreenshot(const ScreenshotCallback& callback) = 0; |
| protected: |
| - virtual content::WebContents* web_contents() = 0; |
| + HeadlessWebContents() {} |
| private: |
| - DISALLOW_COPY_AND_ASSIGN(WebContents); |
| + DISALLOW_COPY_AND_ASSIGN(HeadlessWebContents); |
| }; |
| } // namespace headless |
| -#endif // HEADLESS_PUBLIC_WEB_CONTENTS_H_ |
| +#endif // HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ |