Allow api::WebContents to fully wrap an existing content::WebContents.

- Add an overload to `WebContents::CreateFrom` that accepts a type parameter. If
  type is `REMOTE`, initialization is the same as before(a thin wrapper). If
  not, the `api::WebContents` will be fully initialized, as if it was created by
  `api::WebContents::Create`.
- Move common initialization code to `InitWithSessionAndOptions`.
This commit is contained in:
Thiago de Arruda 2016-08-16 21:15:10 -03:00
parent 1b1541fe1a
commit 0b3b29938f
2 changed files with 39 additions and 7 deletions

View file

@ -58,6 +58,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
// Create from an existing WebContents.
static mate::Handle<WebContents> CreateFrom(
v8::Isolate* isolate, content::WebContents* web_contents);
static mate::Handle<WebContents> CreateFrom(
v8::Isolate* isolate, content::WebContents* web_contents, Type type);
// Create a new WebContents.
static mate::Handle<WebContents> Create(
@ -191,10 +193,17 @@ class WebContents : public mate::TrackableObject<WebContents>,
v8::Local<v8::Value> 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<class Session> session,
const mate::Dictionary& options);
// content::WebContentsDelegate:
bool AddMessageToConsole(content::WebContents* source,
int32_t level,