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_FRAME_H_ | 5 #ifndef HEADLESS_PUBLIC_HEADLESS_WEB_FRAME_H_ |
6 #define HEADLESS_PUBLIC_WEB_FRAME_H_ | 6 #define HEADLESS_PUBLIC_HEADLESS_WEB_FRAME_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/values.h" | 10 #include "base/values.h" |
11 #include "headless/public/headless_export.h" | 11 #include "headless/public/headless_export.h" |
12 #include "ui/gfx/geometry/size.h" | |
12 | 13 |
13 namespace headless { | 14 namespace headless { |
14 | 15 |
15 class WebDocument; | |
16 | |
17 // Class representing a frame in a web page (e.g. main frame or an iframe). | 16 // Class representing a frame in a web page (e.g. main frame or an iframe). |
18 // Should be accessed from renderer main thread. | 17 // Should be accessed from renderer main thread. |
19 class HEADLESS_EXPORT WebFrame { | 18 class HEADLESS_EXPORT HeadlessWebFrame { |
20 public: | 19 public: |
21 virtual ~WebFrame() {} | 20 virtual ~HeadlessWebFrame() {} |
22 | 21 |
23 using ScriptExecutionCallback = | 22 using ScriptExecutionCallback = |
24 base::Callback<void(const std::vector<scoped_ptr<base::Value>>&)>; | 23 base::Callback<void(const std::vector<scoped_ptr<base::Value>>&)>; |
25 | 24 |
26 // Schedule given script for execution. | 25 // Schedule given script for execution. |
27 virtual void ExecuteScript(const std::string& source_code) = 0; | 26 virtual void ExecuteScript(const std::string& source_code) = 0; |
pfeldman
2016/02/09 19:49:51
I think we should be reusing the remote debugging
Sami
2016/02/09 21:40:51
Done.
| |
28 | 27 |
29 // Execute given script and return its result. | 28 // Execute given script and return its result. |
30 // Returned value will be converted to json (base::Value). | 29 // Returned value will be converted to json (base::Value). |
31 // Special effects to bear in mind: | 30 // Special effects to bear in mind: |
32 // - Boolean will be converted to base::FundamentalValue (no surprises here). | 31 // - Boolean will be converted to base::FundamentalValue (no surprises here). |
33 // - Number will be converted to base::FundamentalValue. | 32 // - Number will be converted to base::FundamentalValue. |
34 // - Array will be converted to base::ListValue. | 33 // - Array will be converted to base::ListValue. |
35 // Note: All non-numerical properties will be omitted | 34 // Note: All non-numerical properties will be omitted |
36 // (e.g. "array = [1, 2, 3]; array['property'] = 'value'; return array" | 35 // (e.g. "array = [1, 2, 3]; array['property'] = 'value'; return array" |
37 // will return [1, 2, 3]). | 36 // will return [1, 2, 3]). |
38 // - Object will be converted to base::DictionaryValue | 37 // - Object will be converted to base::DictionaryValue |
39 // Note: Only string can be key in base::DictionaryValue, so all non-string | 38 // Note: Only string can be key in base::DictionaryValue, so all non-string |
40 // properties will be omitted | 39 // properties will be omitted |
41 // (e.g. "obj = Object(); obj['key'] = 'value'; obj[0] = 42;" will return | 40 // (e.g. "obj = Object(); obj['key'] = 'value'; obj[0] = 42;" will return |
42 // {"key":"value"}). | 41 // {"key":"value"}). |
43 virtual void ExecuteScriptAndReturnValue( | 42 virtual void ExecuteScriptAndReturnValue( |
pfeldman
2016/02/09 19:49:51
Here you go, we don't need to reinvent the wheel h
Sami
2016/02/09 21:40:51
Done.
| |
44 const std::string& source_code, | 43 const std::string& source_code, |
45 const ScriptExecutionCallback& callback) = 0; | 44 const ScriptExecutionCallback& callback) = 0; |
46 | 45 |
47 virtual std::string ContentAsText(size_t max_chars) const = 0; | 46 virtual std::string ContentAsText(size_t max_chars) const = 0; |
48 virtual std::string ContentAsMarkup() const = 0; | 47 virtual std::string ContentAsMarkup() const = 0; |
49 virtual proto::Document ContentAsProtobuf() const = 0; | |
50 | 48 |
51 virtual gfx::Size GetScrollOffset() const = 0; | 49 virtual gfx::Size GetScrollOffset() const = 0; |
pfeldman
2016/02/09 19:49:51
Are these provisional or are there clients for the
Sami
2016/02/09 21:40:51
PhantomJS at least exposes these, not sure if anyo
| |
52 virtual void SetScrollOffset(const gfx::Size& offset) = 0; | 50 virtual void SetScrollOffset(const gfx::Size& offset) = 0; |
53 | 51 |
54 virtual float GetPageScaleFactor() const = 0; | 52 virtual float GetPageScaleFactor() const = 0; |
pfeldman
2016/02/09 19:49:51
ditto
Sami
2016/02/09 21:40:51
Same for these. Perhaps the emulation path could h
| |
55 virtual void SetPageScaleFactor(float page_scale_factor) = 0; | 53 virtual void SetPageScaleFactor(float page_scale_factor) = 0; |
56 | 54 |
55 protected: | |
56 HeadlessWebFrame() {} | |
57 | |
57 private: | 58 private: |
58 DISALLOW_COPY_AND_ASSIGN(WebFrame); | 59 DISALLOW_COPY_AND_ASSIGN(HeadlessWebFrame); |
59 }; | 60 }; |
60 | 61 |
61 } // namespace headless | 62 } // namespace headless |
62 | 63 |
63 #endif // HEADLESS_PUBLIC_WEB_FRAME_H_ | 64 #endif // HEADLESS_PUBLIC_HEADLESS_WEB_FRAME_H_ |
OLD | NEW |