From c7b2545b1b49b8fad26d4c7ee4da052556682dad Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 14 Jun 2016 09:09:54 -0700 Subject: [PATCH] Use web contents type enum and add converter --- .../api/atom_api_render_process_preferences.cc | 2 +- atom/browser/api/atom_api_web_contents.cc | 29 ++++++++++++++-------- atom/browser/api/atom_api_web_contents.h | 15 ++++++----- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/atom/browser/api/atom_api_render_process_preferences.cc b/atom/browser/api/atom_api_render_process_preferences.cc index 6add082..4781f06 100644 --- a/atom/browser/api/atom_api_render_process_preferences.cc +++ b/atom/browser/api/atom_api_render_process_preferences.cc @@ -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 diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 21c4359..0591129 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -187,6 +187,22 @@ struct Converter { } }; +template<> +struct Converter { + static v8::Local 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 WebContents::GetWebPreferences(v8::Isolate* isolate) { WebContentsPreferences* web_preferences = WebContentsPreferences::FromWebContents(web_contents()); diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 075eb3a..9bf9dd3 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -43,6 +43,12 @@ class WebContents : public mate::TrackableObject, public CommonWebContentsDelegate, public content::WebContentsObserver { public: + enum Type { + BROWSER_WINDOW, // Used by BrowserWindow. + WEB_VIEW, // Used by . + REMOTE, // Thin wrap around an existing WebContents. + }; + // For node.js callback function type: function(error, buffer) using PrintToPDFCallback = base::Callback, v8::Local)>; @@ -59,7 +65,7 @@ class WebContents : public mate::TrackableObject, v8::Local 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, // Methods for creating . 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, void DevToolsClosed() override; private: - enum Type { - BROWSER_WINDOW, // Used by BrowserWindow. - WEB_VIEW, // Used by . - REMOTE, // Thin wrap around an existing WebContents. - }; - AtomBrowserContext* GetBrowserContext() const; uint32_t GetNextRequestId() { -- 2.7.4