Browse Source

std::unique_ptr<WebContents>

Jeremy Apthorp 6 years ago
parent
commit
a5b09e25ea

+ 11 - 10
atom/browser/api/atom_api_web_contents.cc

@@ -362,7 +362,7 @@ WebContents::WebContents(v8::Isolate* isolate,
   }
   session_.Reset(isolate, session.ToV8());
 
-  content::WebContents* web_contents;
+  std::unique_ptr<content::WebContents> web_contents;
   if (IsGuest()) {
     scoped_refptr<content::SiteInstance> site_instance =
         content::SiteInstance::CreateForURL(session->browser_context(),
@@ -405,7 +405,7 @@ WebContents::WebContents(v8::Isolate* isolate,
     web_contents = content::WebContents::Create(params);
   }
 
-  InitWithSessionAndOptions(isolate, web_contents, session, options);
+  InitWithSessionAndOptions(isolate, web_contents.release(), session, options);
 }
 
 void WebContents::InitZoomController(content::WebContents* web_contents,
@@ -537,16 +537,17 @@ void WebContents::WebContentsCreated(content::WebContents* source_contents,
   Emit("-web-contents-created", api_web_contents, target_url, frame_name);
 }
 
-void WebContents::AddNewContents(content::WebContents* source,
-                                 content::WebContents* new_contents,
-                                 WindowOpenDisposition disposition,
-                                 const gfx::Rect& initial_rect,
-                                 bool user_gesture,
-                                 bool* was_blocked) {
-  new ChildWebContentsTracker(new_contents);
+void WebContents::AddNewContents(
+    content::WebContents* source,
+    std::unique_ptr<content::WebContents> new_contents,
+    WindowOpenDisposition disposition,
+    const gfx::Rect& initial_rect,
+    bool user_gesture,
+    bool* was_blocked) {
+  new ChildWebContentsTracker(new_contents.get());
   v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
-  auto api_web_contents = CreateFrom(isolate(), new_contents);
+  auto api_web_contents = CreateFrom(isolate(), new_contents.release());
   if (Emit("-add-new-contents", api_web_contents, disposition, user_gesture,
            initial_rect.x(), initial_rect.y(), initial_rect.width(),
            initial_rect.height())) {

+ 1 - 1
atom/browser/api/atom_api_web_contents.h

@@ -300,7 +300,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
                           const GURL& target_url,
                           content::WebContents* new_contents) override;
   void AddNewContents(content::WebContents* source,
-                      content::WebContents* new_contents,
+                      std::unique_ptr<content::WebContents> new_contents,
                       WindowOpenDisposition disposition,
                       const gfx::Rect& initial_rect,
                       bool user_gesture,

+ 10 - 5
atom/browser/web_view_guest_delegate.cc

@@ -4,6 +4,8 @@
 
 #include "atom/browser/web_view_guest_delegate.h"
 
+#include <memory>
+
 #include "atom/browser/api/atom_api_web_contents.h"
 #include "atom/common/native_mate_converters/gurl_converter.h"
 #include "content/browser/web_contents/web_contents_impl.h"
@@ -104,13 +106,16 @@ content::WebContents* WebViewGuestDelegate::CreateNewGuestWindow(
   guest_params.initial_size =
       embedder_web_contents_->GetContainerBounds().size();
   guest_params.context = embedder_web_contents_->GetNativeView();
-  auto* guest_contents = content::WebContents::Create(guest_params);
+  std::unique_ptr<content::WebContents> guest_contents =
+      content::WebContents::Create(guest_params);
+  content::RenderWidgetHost* render_widget_host =
+      guest_contents->GetRenderViewHost()->GetWidget();
   auto* guest_contents_impl =
-      static_cast<content::WebContentsImpl*>(guest_contents);
-  guest_contents_impl->GetView()->CreateViewForWidget(
-      guest_contents->GetRenderViewHost()->GetWidget(), false);
+      static_cast<content::WebContentsImpl*>(guest_contents.release());
+  guest_contents_impl->GetView()->CreateViewForWidget(render_widget_host,
+                                                      false);
 
-  return guest_contents;
+  return guest_contents_impl;
 }
 
 }  // namespace atom

+ 2 - 3
brightray/browser/inspectable_web_contents_impl.cc

@@ -320,9 +320,8 @@ void InspectableWebContentsImpl::ShowDevTools() {
       DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(this));
 
   if (!external_devtools_web_contents_) {  // no external devtools
-    managed_devtools_web_contents_.reset(
-        content::WebContents::Create(content::WebContents::CreateParams(
-            web_contents_->GetBrowserContext())));
+    managed_devtools_web_contents_ = content::WebContents::Create(
+        content::WebContents::CreateParams(web_contents_->GetBrowserContext()));
     managed_devtools_web_contents_->SetDelegate(this);
   }