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 710fc84c4c9fe3849bf3da7f42ed82419ba44d11..42db63f54b4a54db9ff9f3a30e7866ca076fc92d 100644 |
--- a/headless/lib/browser/headless_web_contents_impl.cc |
+++ b/headless/lib/browser/headless_web_contents_impl.cc |
@@ -102,6 +102,26 @@ class HeadlessWebContentsImpl::Delegate : public content::WebContentsDelegate { |
contents->GetRenderViewHost()->GetWidget()->Focus(); |
} |
+ void CloseContents(content::WebContents* source) override { |
+ if (!browser_context_) { |
+ return; |
+ } |
+ |
+ std::vector<HeadlessWebContents*> all_contents = |
+ browser_context_->GetAllWebContents(); |
+ |
+ for (HeadlessWebContents* wc : all_contents) { |
+ if (!wc) { |
+ continue; |
+ } |
+ HeadlessWebContentsImpl* hwc = HeadlessWebContentsImpl::From(wc); |
+ if (hwc->web_contents() == source) { |
+ wc->Close(); |
+ return; |
+ } |
+ } |
+ } |
+ |
private: |
HeadlessBrowserContextImpl* browser_context_; // Not owned. |
DISALLOW_COPY_AND_ASSIGN(Delegate); |
@@ -157,7 +177,6 @@ HeadlessWebContentsImpl::HeadlessWebContentsImpl( |
} |
HeadlessWebContentsImpl::~HeadlessWebContentsImpl() { |
- web_contents_->Close(); |
if (render_process_host_) |
render_process_host_->RemoveObserver(this); |
} |