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;
|
||||
|
||||
auto api_web_contents = WebContents::CreateFrom(isolate, web_contents);
|
||||
return !api_web_contents->IsRemote();
|
||||
return api_web_contents->GetType() != WebContents::Type::REMOTE;
|
||||
}
|
||||
|
||||
} // 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
|
||||
|
||||
|
||||
|
@ -744,13 +760,8 @@ int WebContents::GetID() const {
|
|||
return web_contents()->GetRenderProcessHost()->GetID();
|
||||
}
|
||||
|
||||
std::string WebContents::GetType() const {
|
||||
switch (type_) {
|
||||
case BROWSER_WINDOW: return "window";
|
||||
case WEB_VIEW: return "webview";
|
||||
case REMOTE: return "remote";
|
||||
default: return "";
|
||||
}
|
||||
WebContents::Type WebContents::GetType() const {
|
||||
return type_;
|
||||
}
|
||||
|
||||
bool WebContents::Equal(const WebContents* web_contents) const {
|
||||
|
@ -1197,10 +1208,6 @@ bool WebContents::IsGuest() const {
|
|||
return type_ == WEB_VIEW;
|
||||
}
|
||||
|
||||
bool WebContents::IsRemote() const {
|
||||
return type_ == REMOTE;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
|
||||
WebContentsPreferences* web_preferences =
|
||||
WebContentsPreferences::FromWebContents(web_contents());
|
||||
|
|
|
@ -43,6 +43,12 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
public CommonWebContentsDelegate,
|
||||
public content::WebContentsObserver {
|
||||
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)
|
||||
using PrintToPDFCallback =
|
||||
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);
|
||||
|
||||
int GetID() const;
|
||||
std::string GetType() const;
|
||||
Type GetType() const;
|
||||
bool Equal(const WebContents* web_contents) const;
|
||||
void LoadURL(const GURL& url, const mate::Dictionary& options);
|
||||
void DownloadURL(const GURL& url);
|
||||
|
@ -139,7 +145,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
// Methods for creating <webview>.
|
||||
void SetSize(const SetSizeParams& params);
|
||||
bool IsGuest() const;
|
||||
bool IsRemote() const;
|
||||
|
||||
// Callback triggered on permission response.
|
||||
void OnEnterFullscreenModeForTab(content::WebContents* source,
|
||||
|
@ -269,12 +274,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
void DevToolsClosed() override;
|
||||
|
||||
private:
|
||||
enum Type {
|
||||
BROWSER_WINDOW, // Used by BrowserWindow.
|
||||
WEB_VIEW, // Used by <webview>.
|
||||
REMOTE, // Thin wrap around an existing WebContents.
|
||||
};
|
||||
|
||||
AtomBrowserContext* GetBrowserContext() const;
|
||||
|
||||
uint32_t GetNextRequestId() {
|
||||
|
|
Loading…
Reference in a new issue