]> khamidou — GitHub mirrors - electron.git/commitdiff
Manage webview with CommonWebContentsDelegate
authorCheng Zhao <zcbenz@gmail.com>
Fri, 5 Jun 2015 07:01:51 +0000 (15:01 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 5 Jun 2015 07:01:51 +0000 (15:01 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h

index 6ec4ea0b679d1fa5b2de8d0d4ab81f1a0efcddc3..01d96921e0639930ee5ef064bc593a0b17c937c9 100644 (file)
@@ -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() {
@@ -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();
 
@@ -458,7 +459,7 @@ void WebContents::Destroy() {
     guest_host_ = nullptr;
 
     Observe(nullptr);
-    storage_.reset();
+    DestroyWebContents();
   }
 }
 
@@ -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);
 }
 
@@ -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;
     }
   }
index e70b25d72353262fe156bf233db7296785885f51..056e7f3f699cfa344184b14259bb997a8f693aef 100644 (file)
@@ -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_;