Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Unified Diff: headless/lib/browser/headless_web_contents_impl.cc

Issue 1891843004: [headless] AddWindowTreeClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to latest master Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: headless/lib/browser/headless_web_contents_impl.cc
diff --git a/headless/lib/browser/headless_web_contents_impl.cc b/headless/lib/browser/headless_web_contents_impl.cc
index 94eae962f1a04aa81654068f6cac6a745da490f9..723032a83216f5b114e4e99bcc38c87cf15c2c0d 100644
--- a/headless/lib/browser/headless_web_contents_impl.cc
+++ b/headless/lib/browser/headless_web_contents_impl.cc
@@ -20,6 +20,7 @@
#include "content/public/common/bindings_policy.h"
#include "content/public/common/service_registry.h"
#include "content/public/renderer/render_frame.h"
+#include "headless/lib/browser/headless_browser_impl.h"
#include "headless/lib/browser/headless_devtools_client_impl.h"
#include "ui/aura/window.h"
@@ -56,23 +57,53 @@ class WebContentsObserverAdapter : public content::WebContentsObserver {
class HeadlessWebContentsImpl::Delegate : public content::WebContentsDelegate {
public:
- Delegate() {}
+ explicit Delegate(HeadlessBrowserImpl* browser) : browser_(browser) {}
+
+ void WebContentsCreated(content::WebContents* source_contents,
+ int opener_render_frame_id,
+ const std::string& frame_name,
+ const GURL& target_url,
+ content::WebContents* new_contents) override {
+ browser_->RegisterWebContents(
+ HeadlessWebContentsImpl::CreateFromWebContents(new_contents, browser_));
+ }
private:
+ HeadlessBrowserImpl* browser_; // Not owned.
DISALLOW_COPY_AND_ASSIGN(Delegate);
};
-HeadlessWebContentsImpl::HeadlessWebContentsImpl(
- content::BrowserContext* browser_context,
+// static
+std::unique_ptr<HeadlessWebContentsImpl> HeadlessWebContentsImpl::Create(
+ content::BrowserContext* context,
aura::Window* parent_window,
- const gfx::Size& initial_size)
- : web_contents_delegate_(new HeadlessWebContentsImpl::Delegate()) {
- content::WebContents::CreateParams create_params(browser_context, nullptr);
+ const gfx::Size& initial_size,
+ HeadlessBrowserImpl* browser) {
+ content::WebContents::CreateParams create_params(context, nullptr);
create_params.initial_size = initial_size;
- web_contents_.reset(content::WebContents::Create(create_params));
- web_contents_->SetDelegate(web_contents_delegate_.get());
+ std::unique_ptr<HeadlessWebContentsImpl> headless_web_contents =
+ base::WrapUnique(new HeadlessWebContentsImpl(
+ content::WebContents::Create(create_params), browser));
+
+ headless_web_contents->InitializeScreen(parent_window, initial_size);
+ return headless_web_contents;
+}
+
+// static
+std::unique_ptr<HeadlessWebContentsImpl>
+HeadlessWebContentsImpl::CreateFromWebContents(
+ content::WebContents* web_contents,
+ HeadlessBrowserImpl* browser) {
+ std::unique_ptr<HeadlessWebContentsImpl> headless_web_contents =
+ base::WrapUnique(new HeadlessWebContentsImpl(web_contents, browser));
+
+ return headless_web_contents;
+}
+
+void HeadlessWebContentsImpl::InitializeScreen(aura::Window* parent_window,
+ const gfx::Size& initial_size) {
aura::Window* contents = web_contents_->GetNativeView();
DCHECK(!parent_window->Contains(contents));
parent_window->AddChild(contents);
@@ -85,6 +116,15 @@ HeadlessWebContentsImpl::HeadlessWebContentsImpl(
host_view->SetSize(initial_size);
}
+HeadlessWebContentsImpl::HeadlessWebContentsImpl(
+ content::WebContents* web_contents,
+ HeadlessBrowserImpl* browser)
+ : web_contents_delegate_(new HeadlessWebContentsImpl::Delegate(browser)),
+ web_contents_(web_contents),
+ browser_(browser) {
+ web_contents_->SetDelegate(web_contents_delegate_.get());
+}
+
HeadlessWebContentsImpl::~HeadlessWebContentsImpl() {
web_contents_->Close();
}
@@ -100,6 +140,10 @@ bool HeadlessWebContentsImpl::OpenURL(const GURL& url) {
return true;
}
+void HeadlessWebContentsImpl::Close() {
+ browser_->DestroyWebContents(this);
+}
+
void HeadlessWebContentsImpl::AddObserver(Observer* observer) {
DCHECK(observer_map_.find(observer) == observer_map_.end());
observer_map_[observer] = base::WrapUnique(
« no previous file with comments | « headless/lib/browser/headless_web_contents_impl.h ('k') | headless/lib/browser/headless_window_tree_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698