diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index a5a06b2670d3..869defb6c02c 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -258,17 +258,25 @@ void OnCapturePageDone(base::Callback callback, } // namespace WebContents::WebContents(v8::Isolate* isolate, - content::WebContents* web_contents) + content::WebContents* web_contents, + Type type) : content::WebContentsObserver(web_contents), embedder_(nullptr), - type_(REMOTE), + type_(type), request_id_(0), background_throttling_(true), enable_devtools_(true) { - web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent()); - Init(isolate); - AttachAsUserData(web_contents); + if (type == REMOTE) { + web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent()); + Init(isolate); + AttachAsUserData(web_contents); + } else { + const mate::Dictionary options = mate::Dictionary::CreateEmpty(isolate); + auto session = Session::CreateFrom(isolate, GetBrowserContext()); + session_.Reset(isolate, session.ToV8()); + InitWithSessionAndOptions(isolate, web_contents, session, options); + } } WebContents::WebContents(v8::Isolate* isolate, @@ -336,6 +344,13 @@ WebContents::WebContents(v8::Isolate* isolate, web_contents = content::WebContents::Create(params); } + InitWithSessionAndOptions(isolate, web_contents, session, options); +} + +void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate, + content::WebContents *web_contents, + mate::Handle session, + const mate::Dictionary& options) { Observe(web_contents); InitWithWebContents(web_contents, session->browser_context()); @@ -1605,7 +1620,15 @@ mate::Handle WebContents::CreateFrom( return mate::CreateHandle(isolate, static_cast(existing)); // Otherwise create a new WebContents wrapper object. - return mate::CreateHandle(isolate, new WebContents(isolate, web_contents)); + return mate::CreateHandle(isolate, new WebContents(isolate, web_contents, + REMOTE)); +} + +mate::Handle WebContents::CreateFrom( + v8::Isolate* isolate, content::WebContents* web_contents, Type type) { + // Otherwise create a new WebContents wrapper object. + return mate::CreateHandle(isolate, new WebContents(isolate, web_contents, + type)); } // static diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 908a2f0d179f..e47bb06fb309 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -58,6 +58,8 @@ class WebContents : public mate::TrackableObject, // Create from an existing WebContents. static mate::Handle CreateFrom( v8::Isolate* isolate, content::WebContents* web_contents); + static mate::Handle CreateFrom( + v8::Isolate* isolate, content::WebContents* web_contents, Type type); // Create a new WebContents. static mate::Handle Create( @@ -191,10 +193,17 @@ class WebContents : public mate::TrackableObject, v8::Local Debugger(v8::Isolate* isolate); protected: - WebContents(v8::Isolate* isolate, content::WebContents* web_contents); + WebContents(v8::Isolate* isolate, + content::WebContents* web_contents, + Type type); WebContents(v8::Isolate* isolate, const mate::Dictionary& options); ~WebContents(); + void InitWithSessionAndOptions(v8::Isolate* isolate, + content::WebContents *web_contents, + mate::Handle session, + const mate::Dictionary& options); + // content::WebContentsDelegate: bool AddMessageToConsole(content::WebContents* source, int32_t level,