refactor: remove potential double free when managing WebContents (#15280)

* refactor: remove -new-contents-created event

Chromium expects us to take ownership of WebContents in AddNewContents,
we should not create V8 wrapper in WebContentsCreated, otherwise we
would have WebContents being managed by 2 unique_ptr at the same time.

* refactor: make CreateAndTake take unique_ptr
This commit is contained in:
Cheng Zhao 2018-10-23 03:02:25 +09:00 committed by Charles Kerr
parent e8e7edf017
commit cb9be091aa
8 changed files with 59 additions and 101 deletions

View file

@ -5,19 +5,25 @@
#ifndef ATOM_BROWSER_CHILD_WEB_CONTENTS_TRACKER_H_
#define ATOM_BROWSER_CHILD_WEB_CONTENTS_TRACKER_H_
#include "content/public/browser/web_contents_observer.h"
#include <string>
#include "content/public/browser/web_contents_user_data.h"
namespace atom {
// ChildWebContentsTracker tracks child WebContents
// created by native `window.open()`
class ChildWebContentsTracker : public content::WebContentsObserver {
public:
explicit ChildWebContentsTracker(content::WebContents* web_contents);
static bool IsChildWebContents(content::WebContents* web_contents);
struct ChildWebContentsTracker
: public content::WebContentsUserData<ChildWebContentsTracker> {
GURL url;
std::string frame_name;
protected:
void WebContentsDestroyed() override;
explicit ChildWebContentsTracker(content::WebContents* web_contents) {}
private:
friend class content::WebContentsUserData<ChildWebContentsTracker>;
DISALLOW_COPY_AND_ASSIGN(ChildWebContentsTracker);
};
} // namespace atom