Skip to content

Commit

Permalink
Manage webview with CommonWebContentsDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Jun 5, 2015
1 parent 92b15c8 commit c32aac0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
23 changes: 12 additions & 11 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ WebContents::WebContents(const mate::Dictionary& options)
if (options.Get("isGuest", &is_guest) && is_guest)
params.guest_delegate = this;

storage_.reset(brightray::InspectableWebContents::Create(params));
Observe(storage_->GetWebContents());
web_contents()->SetDelegate(this);
auto web_contents = content::WebContents::Create(params);
InitWithWebContents(web_contents, GetWindowFromGuest(web_contents));

Observe(GetWebContents());
}

WebContents::~WebContents() {
Expand Down Expand Up @@ -449,7 +450,7 @@ void WebContents::WillAttach(content::WebContents* embedder_web_contents,
}

void WebContents::Destroy() {
if (storage_) {
if (is_guest()) {
// When force destroying the "destroyed" event is not emitted.
WebContentsDestroyed();

Expand All @@ -458,7 +459,7 @@ void WebContents::Destroy() {
guest_host_ = nullptr;

Observe(nullptr);
storage_.reset();
DestroyWebContents();
}
}

Expand Down Expand Up @@ -544,22 +545,22 @@ void WebContents::ExecuteJavaScript(const base::string16& code) {
}

void WebContents::OpenDevTools() {
storage_->SetCanDock(false);
storage_->ShowDevTools();
inspectable_web_contents()->SetCanDock(false);
inspectable_web_contents()->ShowDevTools();
}

void WebContents::CloseDevTools() {
storage_->CloseDevTools();
inspectable_web_contents()->CloseDevTools();
}

bool WebContents::IsDevToolsOpened() {
return storage_->IsDevToolsViewShowing();
return inspectable_web_contents()->IsDevToolsViewShowing();
}

void WebContents::InspectElement(int x, int y) {
OpenDevTools();
scoped_refptr<content::DevToolsAgentHost> agent(
content::DevToolsAgentHost::GetOrCreateFor(storage_->GetWebContents()));
content::DevToolsAgentHost::GetOrCreateFor(web_contents()));
agent->InspectElement(x, y);
}

Expand Down Expand Up @@ -710,7 +711,7 @@ void WebContents::InspectServiceWorker() {
if (agent_host->GetType() ==
content::DevToolsAgentHost::TYPE_SERVICE_WORKER) {
OpenDevTools();
storage_->AttachTo(agent_host);
inspectable_web_contents()->AttachTo(agent_host);
break;
}
}
Expand Down
3 changes: 0 additions & 3 deletions atom/browser/api/atom_api_web_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,6 @@ class WebContents : public mate::EventEmitter,
// Stores whether the contents of the guest can be transparent.
bool guest_opaque_;

// Stores the WebContents that managed by this class.
scoped_ptr<brightray::InspectableWebContents> storage_;

// The WebContents that attaches this guest view.
content::WebContents* embedder_web_contents_;

Expand Down

0 comments on commit c32aac0

Please sign in to comment.