Use web contents type enum and add converter
This commit is contained in:
parent
fc2b5eebc0
commit
c7b2545b1b
3 changed files with 26 additions and 20 deletions
|
@ -26,7 +26,7 @@ bool IsWebContents(v8::Isolate* isolate, content::RenderProcessHost* process) {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto api_web_contents = WebContents::CreateFrom(isolate, web_contents);
|
auto api_web_contents = WebContents::CreateFrom(isolate, web_contents);
|
||||||
return !api_web_contents->IsRemote();
|
return api_web_contents->GetType() != WebContents::Type::REMOTE;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -187,6 +187,22 @@ struct Converter<content::SavePageType> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Converter<atom::api::WebContents::Type> {
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
atom::api::WebContents::Type val) {
|
||||||
|
std::string type = "";
|
||||||
|
switch (val) {
|
||||||
|
case atom::api::WebContents::Type::BROWSER_WINDOW: type = "window"; break;
|
||||||
|
case atom::api::WebContents::Type::WEB_VIEW: type = "webview"; break;
|
||||||
|
case atom::api::WebContents::Type::REMOTE: type = "remote"; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return mate::ConvertToV8(isolate, type);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
||||||
|
|
||||||
|
@ -744,13 +760,8 @@ int WebContents::GetID() const {
|
||||||
return web_contents()->GetRenderProcessHost()->GetID();
|
return web_contents()->GetRenderProcessHost()->GetID();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string WebContents::GetType() const {
|
WebContents::Type WebContents::GetType() const {
|
||||||
switch (type_) {
|
return type_;
|
||||||
case BROWSER_WINDOW: return "window";
|
|
||||||
case WEB_VIEW: return "webview";
|
|
||||||
case REMOTE: return "remote";
|
|
||||||
default: return "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebContents::Equal(const WebContents* web_contents) const {
|
bool WebContents::Equal(const WebContents* web_contents) const {
|
||||||
|
@ -1197,10 +1208,6 @@ bool WebContents::IsGuest() const {
|
||||||
return type_ == WEB_VIEW;
|
return type_ == WEB_VIEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebContents::IsRemote() const {
|
|
||||||
return type_ == REMOTE;
|
|
||||||
}
|
|
||||||
|
|
||||||
v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
|
v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
|
||||||
WebContentsPreferences* web_preferences =
|
WebContentsPreferences* web_preferences =
|
||||||
WebContentsPreferences::FromWebContents(web_contents());
|
WebContentsPreferences::FromWebContents(web_contents());
|
||||||
|
|
|
@ -43,6 +43,12 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
public CommonWebContentsDelegate,
|
public CommonWebContentsDelegate,
|
||||||
public content::WebContentsObserver {
|
public content::WebContentsObserver {
|
||||||
public:
|
public:
|
||||||
|
enum Type {
|
||||||
|
BROWSER_WINDOW, // Used by BrowserWindow.
|
||||||
|
WEB_VIEW, // Used by <webview>.
|
||||||
|
REMOTE, // Thin wrap around an existing WebContents.
|
||||||
|
};
|
||||||
|
|
||||||
// For node.js callback function type: function(error, buffer)
|
// For node.js callback function type: function(error, buffer)
|
||||||
using PrintToPDFCallback =
|
using PrintToPDFCallback =
|
||||||
base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>;
|
base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>;
|
||||||
|
@ -59,7 +65,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::ObjectTemplate> prototype);
|
||||||
|
|
||||||
int GetID() const;
|
int GetID() const;
|
||||||
std::string GetType() const;
|
Type GetType() const;
|
||||||
bool Equal(const WebContents* web_contents) const;
|
bool Equal(const WebContents* web_contents) const;
|
||||||
void LoadURL(const GURL& url, const mate::Dictionary& options);
|
void LoadURL(const GURL& url, const mate::Dictionary& options);
|
||||||
void DownloadURL(const GURL& url);
|
void DownloadURL(const GURL& url);
|
||||||
|
@ -139,7 +145,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
// Methods for creating <webview>.
|
// Methods for creating <webview>.
|
||||||
void SetSize(const SetSizeParams& params);
|
void SetSize(const SetSizeParams& params);
|
||||||
bool IsGuest() const;
|
bool IsGuest() const;
|
||||||
bool IsRemote() const;
|
|
||||||
|
|
||||||
// Callback triggered on permission response.
|
// Callback triggered on permission response.
|
||||||
void OnEnterFullscreenModeForTab(content::WebContents* source,
|
void OnEnterFullscreenModeForTab(content::WebContents* source,
|
||||||
|
@ -269,12 +274,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
void DevToolsClosed() override;
|
void DevToolsClosed() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum Type {
|
|
||||||
BROWSER_WINDOW, // Used by BrowserWindow.
|
|
||||||
WEB_VIEW, // Used by <webview>.
|
|
||||||
REMOTE, // Thin wrap around an existing WebContents.
|
|
||||||
};
|
|
||||||
|
|
||||||
AtomBrowserContext* GetBrowserContext() const;
|
AtomBrowserContext* GetBrowserContext() const;
|
||||||
|
|
||||||
uint32_t GetNextRequestId() {
|
uint32_t GetNextRequestId() {
|
||||||
|
|
Loading…
Reference in a new issue