| 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_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_ | 5 #ifndef HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_ |
| 6 #define HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_ | 6 #define HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <unordered_map> | 11 #include <unordered_map> |
| 12 | 12 |
| 13 #include "content/public/browser/render_process_host_observer.h" |
| 13 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
| 14 #include "headless/public/headless_devtools_target.h" | 15 #include "headless/public/headless_devtools_target.h" |
| 15 #include "headless/public/headless_web_contents.h" | 16 #include "headless/public/headless_web_contents.h" |
| 16 | 17 |
| 17 namespace aura { | 18 namespace aura { |
| 18 class Window; | 19 class Window; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 class BrowserContext; | 23 class BrowserContext; |
| 23 class DevToolsAgentHost; | 24 class DevToolsAgentHost; |
| 24 class WebContents; | 25 class WebContents; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace gfx { | 28 namespace gfx { |
| 28 class Size; | 29 class Size; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace headless { | 32 namespace headless { |
| 32 class HeadlessDevToolsHostImpl; | 33 class HeadlessDevToolsHostImpl; |
| 33 class HeadlessBrowserImpl; | 34 class HeadlessBrowserImpl; |
| 34 class WebContentsObserverAdapter; | 35 class WebContentsObserverAdapter; |
| 35 | 36 |
| 36 class HeadlessWebContentsImpl : public HeadlessWebContents, | 37 class HeadlessWebContentsImpl : public HeadlessWebContents, |
| 37 public HeadlessDevToolsTarget, | 38 public HeadlessDevToolsTarget, |
| 39 public content::RenderProcessHostObserver, |
| 38 public content::WebContentsObserver { | 40 public content::WebContentsObserver { |
| 39 public: | 41 public: |
| 40 ~HeadlessWebContentsImpl() override; | 42 ~HeadlessWebContentsImpl() override; |
| 41 | 43 |
| 42 static HeadlessWebContentsImpl* From(HeadlessWebContents* web_contents); | 44 static HeadlessWebContentsImpl* From(HeadlessWebContents* web_contents); |
| 43 | 45 |
| 44 static std::unique_ptr<HeadlessWebContentsImpl> Create( | 46 static std::unique_ptr<HeadlessWebContentsImpl> Create( |
| 45 HeadlessWebContents::Builder* builder, | 47 HeadlessWebContents::Builder* builder, |
| 46 aura::Window* parent_window); | 48 aura::Window* parent_window); |
| 47 | 49 |
| 48 // Takes ownership of |web_contents|. | 50 // Takes ownership of |web_contents|. |
| 49 static std::unique_ptr<HeadlessWebContentsImpl> CreateFromWebContents( | 51 static std::unique_ptr<HeadlessWebContentsImpl> CreateFromWebContents( |
| 50 content::WebContents* web_contents, | 52 content::WebContents* web_contents, |
| 51 HeadlessBrowserContextImpl* browser_context); | 53 HeadlessBrowserContextImpl* browser_context); |
| 52 | 54 |
| 53 // HeadlessWebContents implementation: | 55 // HeadlessWebContents implementation: |
| 54 void AddObserver(Observer* observer) override; | 56 void AddObserver(Observer* observer) override; |
| 55 void RemoveObserver(Observer* observer) override; | 57 void RemoveObserver(Observer* observer) override; |
| 56 HeadlessDevToolsTarget* GetDevToolsTarget() override; | 58 HeadlessDevToolsTarget* GetDevToolsTarget() override; |
| 57 | 59 |
| 58 // HeadlessDevToolsTarget implementation: | 60 // HeadlessDevToolsTarget implementation: |
| 59 void AttachClient(HeadlessDevToolsClient* client) override; | 61 void AttachClient(HeadlessDevToolsClient* client) override; |
| 60 void DetachClient(HeadlessDevToolsClient* client) override; | 62 void DetachClient(HeadlessDevToolsClient* client) override; |
| 61 | 63 |
| 64 // RenderProcessHostObserver implementation: |
| 65 void RenderProcessExited(content::RenderProcessHost* host, |
| 66 base::TerminationStatus status, |
| 67 int exit_code) override; |
| 68 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; |
| 69 |
| 62 // content::WebContentsObserver implementation: | 70 // content::WebContentsObserver implementation: |
| 63 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; | 71 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; |
| 64 | 72 |
| 65 content::WebContents* web_contents() const; | 73 content::WebContents* web_contents() const; |
| 66 bool OpenURL(const GURL& url); | 74 bool OpenURL(const GURL& url); |
| 67 | 75 |
| 68 void Close() override; | 76 void Close() override; |
| 69 | 77 |
| 70 std::string GetDevToolsAgentHostId(); | 78 std::string GetDevToolsAgentHostId(); |
| 71 | 79 |
| 72 HeadlessBrowserImpl* browser() const; | 80 HeadlessBrowserImpl* browser() const; |
| 73 HeadlessBrowserContextImpl* browser_context() const; | 81 HeadlessBrowserContextImpl* browser_context() const; |
| 74 | 82 |
| 75 private: | 83 private: |
| 76 // Takes ownership of |web_contents|. | 84 // Takes ownership of |web_contents|. |
| 77 HeadlessWebContentsImpl(content::WebContents* web_contents, | 85 HeadlessWebContentsImpl(content::WebContents* web_contents, |
| 78 HeadlessBrowserContextImpl* browser_context); | 86 HeadlessBrowserContextImpl* browser_context); |
| 79 | 87 |
| 80 void InitializeScreen(aura::Window* parent_window, | 88 void InitializeScreen(aura::Window* parent_window, |
| 81 const gfx::Size& initial_size); | 89 const gfx::Size& initial_size); |
| 82 | 90 |
| 83 using MojoService = HeadlessWebContents::Builder::MojoService; | 91 using MojoService = HeadlessWebContents::Builder::MojoService; |
| 84 | 92 |
| 85 class Delegate; | 93 class Delegate; |
| 86 std::unique_ptr<Delegate> web_contents_delegate_; | 94 std::unique_ptr<Delegate> web_contents_delegate_; |
| 87 std::unique_ptr<content::WebContents> web_contents_; | 95 std::unique_ptr<content::WebContents> web_contents_; |
| 88 scoped_refptr<content::DevToolsAgentHost> agent_host_; | 96 scoped_refptr<content::DevToolsAgentHost> agent_host_; |
| 89 std::list<MojoService> mojo_services_; | 97 std::list<MojoService> mojo_services_; |
| 90 | 98 |
| 91 HeadlessBrowserContextImpl* browser_context_; // Not owned. | 99 HeadlessBrowserContextImpl* browser_context_; // Not owned. |
| 100 content::RenderProcessHost* render_process_host_; // Not owned. |
| 92 | 101 |
| 93 using ObserverMap = | 102 using ObserverMap = |
| 94 std::unordered_map<HeadlessWebContents::Observer*, | 103 std::unordered_map<HeadlessWebContents::Observer*, |
| 95 std::unique_ptr<WebContentsObserverAdapter>>; | 104 std::unique_ptr<WebContentsObserverAdapter>>; |
| 96 ObserverMap observer_map_; | 105 ObserverMap observer_map_; |
| 97 | 106 |
| 98 DISALLOW_COPY_AND_ASSIGN(HeadlessWebContentsImpl); | 107 DISALLOW_COPY_AND_ASSIGN(HeadlessWebContentsImpl); |
| 99 }; | 108 }; |
| 100 | 109 |
| 101 } // namespace headless | 110 } // namespace headless |
| 102 | 111 |
| 103 #endif // HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_ | 112 #endif // HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_ |
| OLD | NEW |