Manage webview with CommonWebContentsDelegate
This commit is contained in:
parent
92b15c81e9
commit
c32aac0a56
2 changed files with 12 additions and 14 deletions
|
@ -135,9 +135,10 @@ WebContents::WebContents(const mate::Dictionary& options)
|
||||||
if (options.Get("isGuest", &is_guest) && is_guest)
|
if (options.Get("isGuest", &is_guest) && is_guest)
|
||||||
params.guest_delegate = this;
|
params.guest_delegate = this;
|
||||||
|
|
||||||
storage_.reset(brightray::InspectableWebContents::Create(params));
|
auto web_contents = content::WebContents::Create(params);
|
||||||
Observe(storage_->GetWebContents());
|
InitWithWebContents(web_contents, GetWindowFromGuest(web_contents));
|
||||||
web_contents()->SetDelegate(this);
|
|
||||||
|
Observe(GetWebContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
WebContents::~WebContents() {
|
WebContents::~WebContents() {
|
||||||
|
@ -449,7 +450,7 @@ void WebContents::WillAttach(content::WebContents* embedder_web_contents,
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::Destroy() {
|
void WebContents::Destroy() {
|
||||||
if (storage_) {
|
if (is_guest()) {
|
||||||
// When force destroying the "destroyed" event is not emitted.
|
// When force destroying the "destroyed" event is not emitted.
|
||||||
WebContentsDestroyed();
|
WebContentsDestroyed();
|
||||||
|
|
||||||
|
@ -458,7 +459,7 @@ void WebContents::Destroy() {
|
||||||
guest_host_ = nullptr;
|
guest_host_ = nullptr;
|
||||||
|
|
||||||
Observe(nullptr);
|
Observe(nullptr);
|
||||||
storage_.reset();
|
DestroyWebContents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,22 +545,22 @@ void WebContents::ExecuteJavaScript(const base::string16& code) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::OpenDevTools() {
|
void WebContents::OpenDevTools() {
|
||||||
storage_->SetCanDock(false);
|
inspectable_web_contents()->SetCanDock(false);
|
||||||
storage_->ShowDevTools();
|
inspectable_web_contents()->ShowDevTools();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::CloseDevTools() {
|
void WebContents::CloseDevTools() {
|
||||||
storage_->CloseDevTools();
|
inspectable_web_contents()->CloseDevTools();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebContents::IsDevToolsOpened() {
|
bool WebContents::IsDevToolsOpened() {
|
||||||
return storage_->IsDevToolsViewShowing();
|
return inspectable_web_contents()->IsDevToolsViewShowing();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::InspectElement(int x, int y) {
|
void WebContents::InspectElement(int x, int y) {
|
||||||
OpenDevTools();
|
OpenDevTools();
|
||||||
scoped_refptr<content::DevToolsAgentHost> agent(
|
scoped_refptr<content::DevToolsAgentHost> agent(
|
||||||
content::DevToolsAgentHost::GetOrCreateFor(storage_->GetWebContents()));
|
content::DevToolsAgentHost::GetOrCreateFor(web_contents()));
|
||||||
agent->InspectElement(x, y);
|
agent->InspectElement(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,7 +711,7 @@ void WebContents::InspectServiceWorker() {
|
||||||
if (agent_host->GetType() ==
|
if (agent_host->GetType() ==
|
||||||
content::DevToolsAgentHost::TYPE_SERVICE_WORKER) {
|
content::DevToolsAgentHost::TYPE_SERVICE_WORKER) {
|
||||||
OpenDevTools();
|
OpenDevTools();
|
||||||
storage_->AttachTo(agent_host);
|
inspectable_web_contents()->AttachTo(agent_host);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -239,9 +239,6 @@ class WebContents : public mate::EventEmitter,
|
||||||
// Stores whether the contents of the guest can be transparent.
|
// Stores whether the contents of the guest can be transparent.
|
||||||
bool guest_opaque_;
|
bool guest_opaque_;
|
||||||
|
|
||||||
// Stores the WebContents that managed by this class.
|
|
||||||
scoped_ptr<brightray::InspectableWebContents> storage_;
|
|
||||||
|
|
||||||
// The WebContents that attaches this guest view.
|
// The WebContents that attaches this guest view.
|
||||||
content::WebContents* embedder_web_contents_;
|
content::WebContents* embedder_web_contents_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue