From 7b61c5c9d00af2d986414549487cd2ea36844313 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Thu, 28 Jul 2016 12:10:56 +0200 Subject: [PATCH] removed some junk and added offscreen webcontents type --- atom/app/atom_main_delegate.cc | 42 --- atom/app/atom_main_delegate.h | 18 -- atom/browser/api/atom_api_web_contents.cc | 28 +- atom/browser/api/atom_api_web_contents.h | 3 + atom/browser/atom_browser_context.cc | 2 + default_app/default_app.js | 358 +++++++++++----------- vendor/brightray | 2 +- 7 files changed, 205 insertions(+), 248 deletions(-) diff --git a/atom/app/atom_main_delegate.cc b/atom/app/atom_main_delegate.cc index 89851e07801e..d075cd5d04a7 100644 --- a/atom/app/atom_main_delegate.cc +++ b/atom/app/atom_main_delegate.cc @@ -22,13 +22,6 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" -#include "base/memory/ptr_util.h" -#include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/browser/renderer_host/render_widget_host_impl.h" -#include "atom/browser/osr_window.h" - -#include "content/public/browser/web_contents.h" - namespace atom { namespace { @@ -109,8 +102,6 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) { _set_invalid_parameter_handler(InvalidParameterHandler); #endif - render_view_host_factory_.reset(new AtomRenderViewHostFactory); - return brightray::MainDelegate::BasicStartupComplete(exit_code); } @@ -183,37 +174,4 @@ AtomMainDelegate::CreateContentClient() { return std::unique_ptr(new AtomContentClient); } -AtomRenderViewHostFactory::AtomRenderViewHostFactory() { - //std::cout << "AtomRenderViewHostFactory" << std::endl; - content::RenderViewHostFactory::UnregisterFactory(); - content::RenderViewHostFactory::RegisterFactory( this ); -} - -AtomRenderViewHostFactory::~AtomRenderViewHostFactory() { - //std::cout << "~AtomRenderViewHostFactory" << std::endl; -} - -content::RenderViewHost* AtomRenderViewHostFactory::CreateRenderViewHost( - content::SiteInstance* instance, - content::RenderViewHostDelegate* delegate, - content::RenderWidgetHostDelegate* widget_delegate, - int32_t routing_id, - int32_t main_frame_routing_id, - bool swapped_out) { - - std::cout << delegate << std::endl; - std::cout << widget_delegate << std::endl; - - auto widget_host_impl = new content::RenderWidgetHostImpl( - widget_delegate, instance->GetProcess(), routing_id, false); - - auto view_host_impl = new content::RenderViewHostImpl(instance, - base::WrapUnique(widget_host_impl), delegate, main_frame_routing_id, - swapped_out, true); - - //new OffScreenWindow(widget_host_impl); - - return view_host_impl; -} - } // namespace atom diff --git a/atom/app/atom_main_delegate.h b/atom/app/atom_main_delegate.h index f9c93076a192..02204267fa6b 100644 --- a/atom/app/atom_main_delegate.h +++ b/atom/app/atom_main_delegate.h @@ -10,25 +10,8 @@ #include "brightray/common/main_delegate.h" #include "brightray/common/content_client.h" -#include "content/browser/renderer_host/render_view_host_factory.h" - namespace atom { -class AtomRenderViewHostFactory : public content::RenderViewHostFactory { -public: - - AtomRenderViewHostFactory(); - ~AtomRenderViewHostFactory(); - - content::RenderViewHost* CreateRenderViewHost( - content::SiteInstance* instance, - content::RenderViewHostDelegate* delegate, - content::RenderWidgetHostDelegate* widget_delegate, - int32_t routing_id, - int32_t main_frame_routing_id, - bool swapped_out); -}; - class AtomMainDelegate : public brightray::MainDelegate { public: AtomMainDelegate(); @@ -65,7 +48,6 @@ class AtomMainDelegate : public brightray::MainDelegate { std::unique_ptr browser_client_; std::unique_ptr renderer_client_; std::unique_ptr utility_client_; - std::unique_ptr render_view_host_factory_; DISALLOW_COPY_AND_ASSIGN(AtomMainDelegate); }; diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 99636b425b44..d1b30830c925 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -196,6 +196,7 @@ struct Converter { case Type::BROWSER_WINDOW: type = "window"; break; case Type::REMOTE: type = "remote"; break; case Type::WEB_VIEW: type = "webview"; break; + case Type::OFF_SCREEN: type = "offscreen"; break; default: break; } return mate::ConvertToV8(isolate, type); @@ -211,6 +212,8 @@ struct Converter { *out = Type::WEB_VIEW; } else if (type == "backgroundPage") { *out = Type::BACKGROUND_PAGE; + } else if (type == "offscreen") { + *out = Type::OFF_SCREEN; } else { return false; } @@ -287,9 +290,8 @@ WebContents::WebContents(v8::Isolate* isolate, type_ = WEB_VIEW; else if (options.Get("isBackgroundPage", &b) && b) type_ = BACKGROUND_PAGE; - - bool offscreen = false; - options.Get("offScreen", &offscreen); + else if (options.Get("offscreen", &b) && b) + type_ = OFF_SCREEN; // Obtain the session. std::string partition; @@ -313,7 +315,7 @@ WebContents::WebContents(v8::Isolate* isolate, guest_delegate_.reset(new WebViewGuestDelegate); params.guest_delegate = guest_delegate_.get(); web_contents = content::WebContents::Create(params); - } else if(offscreen) { + } else if(IsOffScreen()) { content::WebContents::CreateParams params(session->browser_context()); auto view = new OffScreenWebContentsView(); @@ -382,7 +384,7 @@ bool WebContents::AddMessageToConsole(content::WebContents* source, const base::string16& message, int32_t line_no, const base::string16& source_id) { - if (type_ == BROWSER_WINDOW) { + if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN)) { return false; } else { Emit("console-message", level, message, line_no, source_id); @@ -393,7 +395,7 @@ bool WebContents::AddMessageToConsole(content::WebContents* source, void WebContents::OnCreateWindow(const GURL& target_url, const std::string& frame_name, WindowOpenDisposition disposition) { - if (type_ == BROWSER_WINDOW) + if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN)) Emit("-new-window", target_url, frame_name, disposition); else Emit("new-window", target_url, frame_name, disposition); @@ -403,7 +405,7 @@ content::WebContents* WebContents::OpenURLFromTab( content::WebContents* source, const content::OpenURLParams& params) { if (params.disposition != CURRENT_TAB) { - if (type_ == BROWSER_WINDOW) + if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN)) Emit("-new-window", params.url, "", params.disposition); else Emit("new-window", params.url, "", params.disposition); @@ -420,7 +422,7 @@ content::WebContents* WebContents::OpenURLFromTab( void WebContents::BeforeUnloadFired(content::WebContents* tab, bool proceed, bool* proceed_to_fire_unload) { - if (type_ == BROWSER_WINDOW) + if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN)) *proceed_to_fire_unload = proceed; else *proceed_to_fire_unload = true; @@ -433,7 +435,7 @@ void WebContents::MoveContents(content::WebContents* source, void WebContents::CloseContents(content::WebContents* source) { Emit("close"); - if (type_ == BROWSER_WINDOW && owner_window()) + if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN) && owner_window()) owner_window()->CloseContents(source); } @@ -487,13 +489,13 @@ void WebContents::ExitFullscreenModeForTab(content::WebContents* source) { void WebContents::RendererUnresponsive(content::WebContents* source) { Emit("unresponsive"); - if (type_ == BROWSER_WINDOW && owner_window()) + if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN) && owner_window()) owner_window()->RendererUnresponsive(source); } void WebContents::RendererResponsive(content::WebContents* source) { Emit("responsive"); - if (type_ == BROWSER_WINDOW && owner_window()) + if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN) && owner_window()) owner_window()->RendererResponsive(source); } @@ -1348,6 +1350,10 @@ bool WebContents::IsGuest() const { return type_ == WEB_VIEW; } +bool WebContents::IsOffScreen() const { + return type_ == OFF_SCREEN; +} + 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 203dd9d42617..939f86fa546e 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -50,6 +50,7 @@ class WebContents : public mate::TrackableObject, BROWSER_WINDOW, // Used by BrowserWindow. REMOTE, // Thin wrap around an existing WebContents. WEB_VIEW, // Used by . + OFF_SCREEN, // Used for offscreen rendering }; // For node.js callback function type: function(error, buffer) @@ -156,6 +157,8 @@ class WebContents : public mate::TrackableObject, // Methods for creating . void SetSize(const SetSizeParams& params); bool IsGuest() const; + + bool IsOffScreen() const; // Callback triggered on permission response. void OnEnterFullscreenModeForTab(content::WebContents* source, diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index d87047ce283c..703ce07fe953 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -87,6 +87,8 @@ AtomBrowserContext::AtomBrowserContext( // Read options. use_cache_ = true; options.GetBoolean("cache", &use_cache_); + + InitPrefs(); } AtomBrowserContext::~AtomBrowserContext() { diff --git a/default_app/default_app.js b/default_app/default_app.js index 60544ac5af78..6cfad4366d59 100644 --- a/default_app/default_app.js +++ b/default_app/default_app.js @@ -32,7 +32,7 @@ exports.load = (appUrl) => { backgroundColor: '#FFFFFF', useContentSize: true, webPreferences: { - offScreen: true, + offscreen: true, nodeIntegration: false } }) @@ -74,7 +74,7 @@ exports.load = (appUrl) => { nodeIntegration: false } }) - mainWindow2.loadURL(appUrl) + mainWindow2.loadURL("http://4danatomy.com") mainWindow2.focus() /*mainWindow2.webContents.on('dom-ready', () => { mainWindow2.webContents.beginFrameSubscription(() => { @@ -92,179 +92,185 @@ exports.load = (appUrl) => { start2 = end2 })*/ - // - // mainWindow3 = new BrowserWindow({ - // width: 800, - // height: 600, - // autoHideMenuBar: true, - // backgroundColor: '#FFFFFF', - // useContentSize: true, - // webPreferences: { - // nodeIntegration: false - // } - // }) - // mainWindow3.loadURL(appUrl) - // mainWindow3.focus() - // mainWindow3.webContents.on('dom-ready', () => { - // mainWindow3.webContents.beginFrameSubscription(() => { - // console.log("asd") - // }) - // }) - // - // var start3, end3 - // start3 = +new Date(); - // mainWindow3.webContents.on('paint', (e, rect, w, h, data) => { - // end3 = +new Date(); - // - // const d = end3 - start3 - // console.log(`browser #3: ${d < 10 ? ` ${d}` : d} ms`) - // - // start3 = end3 - // }) - // - // mainWindow4 = new BrowserWindow({ - // width: 800, - // height: 600, - // autoHideMenuBar: true, - // backgroundColor: '#FFFFFF', - // useContentSize: true, - // webPreferences: { - // nodeIntegration: false - // } - // }) - // mainWindow4.loadURL(appUrl) - // mainWindow4.focus() - // mainWindow4.webContents.on('dom-ready', () => { - // mainWindow4.webContents.beginFrameSubscription(() => { - // console.log("asd") - // }) - // }) - // - // var start4, end4 - // start4 = +new Date(); - // mainWindow4.webContents.on('paint', (e, rect, w, h, data) => { - // end4 = +new Date(); - // - // const d = end4 - start4 - // console.log(`browser #4: ${d < 10 ? ` ${d}` : d} ms`) - // - // start4 = end4 - // }) - // - // mainWindow5 = new BrowserWindow({ - // width: 800, - // height: 600, - // autoHideMenuBar: true, - // backgroundColor: '#FFFFFF', - // useContentSize: true, - // webPreferences: { - // nodeIntegration: false - // } - // }) - // mainWindow5.loadURL(appUrl) - // mainWindow5.focus() - // mainWindow5.webContents.on('dom-ready', () => { - // mainWindow5.webContents.beginFrameSubscription(() => { - // console.log("asd") - // }) - // }) - // - // var start5, end5 - // start5 = +new Date(); - // mainWindow5.webContents.on('paint', (e, rect, w, h, data) => { - // end5 = +new Date(); - // - // const d = end5 - start5 - // console.log(`browser #5: ${d < 10 ? ` ${d}` : d} ms`) - // - // start5 = end5 - // }) - // - // mainWindow6 = new BrowserWindow({ - // width: 800, - // height: 600, - // autoHideMenuBar: true, - // backgroundColor: '#FFFFFF', - // useContentSize: true, - // webPreferences: { - // nodeIntegration: false - // } - // }) - // mainWindow6.loadURL(appUrl) - // mainWindow6.focus() - // mainWindow6.webContents.on('dom-ready', () => { - // mainWindow6.webContents.beginFrameSubscription(() => { - // console.log("asd") - // }) - // }) - // - // var start6, end6 - // start6 = +new Date(); - // mainWindow6.webContents.on('paint', (e, rect, w, h, data) => { - // end6 = +new Date(); - // - // const d = end6 - start6 - // console.log(`browser #6: ${d < 10 ? ` ${d}` : d} ms`) - // - // start6 = end6 - // }) - // - // mainWindow7 = new BrowserWindow({ - // width: 800, - // height: 600, - // autoHideMenuBar: true, - // backgroundColor: '#FFFFFF', - // useContentSize: true, - // webPreferences: { - // nodeIntegration: false - // } - // }) - // mainWindow7.loadURL(appUrl) - // mainWindow7.focus() - // mainWindow7.webContents.on('dom-ready', () => { - // mainWindow7.webContents.beginFrameSubscription(() => { - // console.log("asd") - // }) - // }) - // - // var start7, end7 - // start7 = +new Date(); - // mainWindow7.webContents.on('paint', (e, rect, w, h, data) => { - // end7 = +new Date(); - // - // const d = end7 - start7 - // console.log(`browser #7: ${d < 10 ? ` ${d}` : d} ms`) - // - // start7 = end7 - // }) - // - // mainWindow8 = new BrowserWindow({ - // width: 800, - // height: 600, - // autoHideMenuBar: true, - // backgroundColor: '#FFFFFF', - // useContentSize: true, - // webPreferences: { - // nodeIntegration: false - // } - // }) - // mainWindow8.loadURL(appUrl) - // mainWindow8.focus() - // mainWindow8.webContents.on('dom-ready', () => { - // mainWindow8.webContents.beginFrameSubscription(() => { - // console.log("asd") - // }) - // }) - // - // var start8, end8 - // start8 = +new Date(); - // mainWindow8.webContents.on('paint', (e, rect, w, h, data) => { - // end8 = +new Date(); - // - // const d = end8 - start8 - // console.log(`browser #8: ${d < 10 ? ` ${d}` : d} ms`) - // - // start8 = end8 - // }) + + mainWindow3 = new BrowserWindow({ + width: 800, + height: 600, + autoHideMenuBar: true, + backgroundColor: '#FFFFFF', + useContentSize: true, + webPreferences: { + offscreen: true, + nodeIntegration: false + } + }) + mainWindow3.loadURL(appUrl) + mainWindow3.focus() + mainWindow3.webContents.on('dom-ready', () => { + mainWindow3.webContents.beginFrameSubscription(() => { + console.log("asd") + }) + }) + + var start3, end3 + start3 = +new Date(); + mainWindow3.webContents.on('paint', (e, rect, w, h, data) => { + end3 = +new Date(); + + const d = end3 - start3 + console.log(`browser #3: ${d < 10 ? ` ${d}` : d} ms`) + + start3 = end3 + }) + + mainWindow4 = new BrowserWindow({ + width: 800, + height: 600, + autoHideMenuBar: true, + backgroundColor: '#FFFFFF', + useContentSize: true, + webPreferences: { + offscreen: true, + nodeIntegration: false + } + }) + mainWindow4.loadURL(appUrl) + mainWindow4.focus() + mainWindow4.webContents.on('dom-ready', () => { + mainWindow4.webContents.beginFrameSubscription(() => { + console.log("asd") + }) + }) + + var start4, end4 + start4 = +new Date(); + mainWindow4.webContents.on('paint', (e, rect, w, h, data) => { + end4 = +new Date(); + + const d = end4 - start4 + console.log(`browser #4: ${d < 10 ? ` ${d}` : d} ms`) + + start4 = end4 + }) + + mainWindow5 = new BrowserWindow({ + width: 800, + height: 600, + autoHideMenuBar: true, + backgroundColor: '#FFFFFF', + useContentSize: true, + webPreferences: { + offscreen: true, + nodeIntegration: false + } + }) + mainWindow5.loadURL(appUrl) + mainWindow5.focus() + mainWindow5.webContents.on('dom-ready', () => { + mainWindow5.webContents.beginFrameSubscription(() => { + console.log("asd") + }) + }) + + var start5, end5 + start5 = +new Date(); + mainWindow5.webContents.on('paint', (e, rect, w, h, data) => { + end5 = +new Date(); + + const d = end5 - start5 + console.log(`browser #5: ${d < 10 ? ` ${d}` : d} ms`) + + start5 = end5 + }) + + mainWindow6 = new BrowserWindow({ + width: 800, + height: 600, + autoHideMenuBar: true, + backgroundColor: '#FFFFFF', + useContentSize: true, + webPreferences: { + offscreen: true, + nodeIntegration: false + } + }) + mainWindow6.loadURL(appUrl) + mainWindow6.focus() + mainWindow6.webContents.on('dom-ready', () => { + mainWindow6.webContents.beginFrameSubscription(() => { + console.log("asd") + }) + }) + + var start6, end6 + start6 = +new Date(); + mainWindow6.webContents.on('paint', (e, rect, w, h, data) => { + end6 = +new Date(); + + const d = end6 - start6 + console.log(`browser #6: ${d < 10 ? ` ${d}` : d} ms`) + + start6 = end6 + }) + + mainWindow7 = new BrowserWindow({ + width: 800, + height: 600, + autoHideMenuBar: true, + backgroundColor: '#FFFFFF', + useContentSize: true, + webPreferences: { + offscreen: true, + nodeIntegration: false + } + }) + mainWindow7.loadURL(appUrl) + mainWindow7.focus() + mainWindow7.webContents.on('dom-ready', () => { + mainWindow7.webContents.beginFrameSubscription(() => { + console.log("asd") + }) + }) + + var start7, end7 + start7 = +new Date(); + mainWindow7.webContents.on('paint', (e, rect, w, h, data) => { + end7 = +new Date(); + + const d = end7 - start7 + console.log(`browser #7: ${d < 10 ? ` ${d}` : d} ms`) + + start7 = end7 + }) + + mainWindow8 = new BrowserWindow({ + width: 800, + height: 600, + autoHideMenuBar: true, + backgroundColor: '#FFFFFF', + useContentSize: true, + webPreferences: { + offscreen: true, + nodeIntegration: false + } + }) + mainWindow8.loadURL(appUrl) + mainWindow8.focus() + mainWindow8.webContents.on('dom-ready', () => { + mainWindow8.webContents.beginFrameSubscription(() => { + console.log("asd") + }) + }) + + var start8, end8 + start8 = +new Date(); + mainWindow8.webContents.on('paint', (e, rect, w, h, data) => { + end8 = +new Date(); + + const d = end8 - start8 + console.log(`browser #8: ${d < 10 ? ` ${d}` : d} ms`) + + start8 = end8 + }) }) } diff --git a/vendor/brightray b/vendor/brightray index fa17fc6b68c4..230dd2823724 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit fa17fc6b68c43188ba4f85ba8fb87d66914a0be4 +Subproject commit 230dd282372480256006d1beda7b970d1b5c517f