Chromium Code Reviews| 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_WEB_CONTENTS_H_ | 5 #ifndef HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ |
| 6 #define HEADLESS_PUBLIC_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 "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "headless/public/headless_export.h" | 11 #include "headless/public/headless_export.h" |
| 12 #include "ui/gfx/geometry/size.h" | |
| 12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 13 | 14 |
| 14 class SkBitmap; | 15 class SkBitmap; |
| 15 | 16 |
| 16 namespace content { | 17 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
| |
| 18 class NavigationController; | |
| 17 class WebContents; | 19 class WebContents; |
| 18 } | 20 } |
| 19 | 21 |
| 20 namespace headless { | 22 namespace headless { |
| 21 class WebFrame; | 23 class HeadlessWebFrame; |
| 22 | 24 |
| 23 // Class representing contents of a browser tab. | 25 // Class representing contents of a browser tab. Should be accessed from browser |
| 24 // Should be accessed from browser main thread. | 26 // main thread. |
| 25 class HEADLESS_EXPORT WebContents { | 27 class HEADLESS_EXPORT HeadlessWebContents { |
| 26 public: | 28 public: |
| 27 virtual ~WebContents() {} | 29 virtual ~HeadlessWebContents() {} |
| 28 | 30 |
| 29 class Observer { | 31 class Observer { |
| 30 public: | 32 public: |
| 31 // Will be called on browser thread. | 33 // Will be called on browser thread. |
| 32 virtual void DidNavigateMainFrame() = 0; | 34 virtual void DidNavigateMainFrame() = 0; |
| 33 virtual void DocumentOnLoadCompletedInMainFrame() = 0; | 35 virtual void DocumentOnLoadCompletedInMainFrame() = 0; |
| 34 | 36 |
| 35 virtual void OnLoadProgressChanged(double progress) = 0; | 37 virtual void OnLoadProgressChanged(double progress) = 0; |
| 36 virtual void AddMessageToConsole(const std::string& message) = 0; | 38 virtual void AddMessageToConsole(const std::string& message) = 0; |
| 37 virtual bool ShouldSuppressDialogs(WebContents* source) = 0; | 39 virtual bool ShouldSuppressDialogs(HeadlessWebContents* source) = 0; |
| 38 virtual void OnModalAlertDialog(const std::string& message) = 0; | 40 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
| |
| 39 virtual bool OnModalConfirmDialog(const std::string& message) = 0; | 41 virtual bool OnModalConfirmDialog(const std::string& message) = 0; |
| 40 virtual std::string OnModalPromptDialog( | 42 virtual std::string OnModalPromptDialog( |
| 41 const std::string& message, | 43 const std::string& message, |
| 42 const std::string& default_value) = 0; | 44 const std::string& default_value) = 0; |
| 43 | 45 |
| 44 protected: | 46 protected: |
| 45 explicit Observer(WebContents* web_contents); | 47 // Use this constructor when the observer's lifetime matches that of the |
| 48 // HeadlessWebContents. | |
| 49 explicit Observer(HeadlessWebContents* web_contents); | |
| 50 | |
| 51 // This constructor creates a detached observer. Use Observe() to attach it | |
| 52 // to a HeadlessWebContents instance. | |
| 53 Observer(); | |
| 46 virtual ~Observer(); | 54 virtual ~Observer(); |
| 47 | 55 |
| 56 void Observe(HeadlessWebContents* web_contents); | |
| 57 | |
| 48 private: | 58 private: |
| 49 class ObserverImpl; | 59 class ObserverImpl; |
| 50 scoped_ptr<ObserverImpl> observer_; | 60 scoped_ptr<ObserverImpl> observer_; |
| 51 | 61 |
| 52 DISALLOW_COPY_AND_ASSIGN(Observer); | 62 DISALLOW_COPY_AND_ASSIGN(Observer); |
| 53 }; | 63 }; |
| 54 | 64 |
| 55 class Settings { | 65 class Settings { |
| 56 virtual void SetWebSecurityEnabled(bool enabled) = 0; | 66 virtual void SetWebSecurityEnabled(bool enabled) = 0; |
| 57 virtual void SetLocalStorageEnabled(bool enabled) = 0; | 67 virtual void SetLocalStorageEnabled(bool enabled) = 0; |
| 58 virtual void SetJavaScriptCanOpenWindowsAutomatically(bool enabled) = 0; | 68 virtual void SetJavaScriptCanOpenWindowsAutomatically(bool enabled) = 0; |
| 59 virtual void SetAllowScriptsToCloseWindows(bool enabled) = 0; | 69 virtual void SetAllowScriptsToCloseWindows(bool enabled) = 0; |
| 60 virtual void SetImagesEnabled(bool enabled) = 0; | 70 virtual void SetImagesEnabled(bool enabled) = 0; |
| 61 virtual void SetJavascriptEnabled(bool enabled) = 0; | 71 virtual void SetJavascriptEnabled(bool enabled) = 0; |
| 62 virtual void SetXSSAuditorEnabled(bool enabled) = 0; | 72 virtual void SetXSSAuditorEnabled(bool enabled) = 0; |
| 63 virtual void SetDefaultTextEncoding(const std::string& encoding) = 0; | 73 virtual void SetDefaultTextEncoding(const std::string& encoding) = 0; |
| 64 }; | 74 }; |
| 65 | 75 |
| 66 virtual Settings* GetSettings() = 0; | 76 virtual Settings* GetSettings() = 0; |
| 67 virtual const Settings* GetSettings() const = 0; | 77 virtual const Settings* GetSettings() const = 0; |
| 68 | 78 |
| 69 virtual NavigationController* GetController() = 0; | 79 virtual content::NavigationController* GetController() = 0; |
| 70 virtual const NavigationController* GetController() const = 0; | 80 virtual const content::NavigationController* GetController() const = 0; |
| 71 | 81 |
| 72 virtual std::string GetTitle() const = 0; | 82 virtual std::string GetTitle() const = 0; |
| 73 virtual const GURL& GetVisibleURL() const = 0; | 83 virtual const GURL& GetVisibleURL() const = 0; |
| 74 virtual const GURL& GetLastCommittedURL() const = 0; | 84 virtual const GURL& GetLastCommittedURL() const = 0; |
| 75 virtual bool IsLoading() const = 0; | 85 virtual bool IsLoading() const = 0; |
| 76 | 86 |
| 77 virtual bool SetViewportSize(const gfx::Size& size) const = 0; | 87 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.
| |
| 78 | 88 |
| 79 // Returns main frame for web page. Note that the returned interface should | 89 // Returns main frame for web page. Note that the returned interface should |
| 80 // only be used on the renderer main thread. | 90 // only be used on the renderer main thread. |
| 81 virtual WebFrame* GetMainFrame() = 0; | 91 virtual HeadlessWebFrame* GetMainFrame() = 0; |
| 82 | 92 |
| 83 // Requests browser tab to navigate to given url. | 93 // Requests browser tab to navigate to given url. |
| 84 virtual void OpenURL(const GURL& url) = 0; | 94 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
| |
| 85 | 95 |
| 96 // Renders an image of the web contents. | |
| 86 using ScreenshotCallback = base::Callback<void(scoped_ptr<SkBitmap>)>; | 97 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.
| |
| 87 // Requests an image of web contents. | 98 virtual void TakeScreenshot(const ScreenshotCallback& callback) = 0; |
| 88 virtual void GetScreenshot(const ScreenshotCallback& callback) = 0; | |
| 89 | 99 |
| 90 protected: | 100 protected: |
| 91 virtual content::WebContents* web_contents() = 0; | 101 HeadlessWebContents() {} |
| 92 | 102 |
| 93 private: | 103 private: |
| 94 DISALLOW_COPY_AND_ASSIGN(WebContents); | 104 DISALLOW_COPY_AND_ASSIGN(HeadlessWebContents); |
| 95 }; | 105 }; |
| 96 | 106 |
| 97 } // namespace headless | 107 } // namespace headless |
| 98 | 108 |
| 99 #endif // HEADLESS_PUBLIC_WEB_CONTENTS_H_ | 109 #endif // HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ |
| OLD | NEW |