removed some junk and added offscreen webcontents type

This commit is contained in:
Heilig Benedek 2016-07-28 12:10:56 +02:00
parent 0dbe4bc417
commit 7b61c5c9d0
7 changed files with 205 additions and 248 deletions

View file

@ -22,13 +22,6 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.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 atom {
namespace { namespace {
@ -109,8 +102,6 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
_set_invalid_parameter_handler(InvalidParameterHandler); _set_invalid_parameter_handler(InvalidParameterHandler);
#endif #endif
render_view_host_factory_.reset(new AtomRenderViewHostFactory);
return brightray::MainDelegate::BasicStartupComplete(exit_code); return brightray::MainDelegate::BasicStartupComplete(exit_code);
} }
@ -183,37 +174,4 @@ AtomMainDelegate::CreateContentClient() {
return std::unique_ptr<brightray::ContentClient>(new AtomContentClient); return std::unique_ptr<brightray::ContentClient>(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 } // namespace atom

View file

@ -10,25 +10,8 @@
#include "brightray/common/main_delegate.h" #include "brightray/common/main_delegate.h"
#include "brightray/common/content_client.h" #include "brightray/common/content_client.h"
#include "content/browser/renderer_host/render_view_host_factory.h"
namespace atom { 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 { class AtomMainDelegate : public brightray::MainDelegate {
public: public:
AtomMainDelegate(); AtomMainDelegate();
@ -65,7 +48,6 @@ class AtomMainDelegate : public brightray::MainDelegate {
std::unique_ptr<content::ContentBrowserClient> browser_client_; std::unique_ptr<content::ContentBrowserClient> browser_client_;
std::unique_ptr<content::ContentRendererClient> renderer_client_; std::unique_ptr<content::ContentRendererClient> renderer_client_;
std::unique_ptr<content::ContentUtilityClient> utility_client_; std::unique_ptr<content::ContentUtilityClient> utility_client_;
std::unique_ptr<AtomRenderViewHostFactory> render_view_host_factory_;
DISALLOW_COPY_AND_ASSIGN(AtomMainDelegate); DISALLOW_COPY_AND_ASSIGN(AtomMainDelegate);
}; };

View file

@ -196,6 +196,7 @@ struct Converter<atom::api::WebContents::Type> {
case Type::BROWSER_WINDOW: type = "window"; break; case Type::BROWSER_WINDOW: type = "window"; break;
case Type::REMOTE: type = "remote"; break; case Type::REMOTE: type = "remote"; break;
case Type::WEB_VIEW: type = "webview"; break; case Type::WEB_VIEW: type = "webview"; break;
case Type::OFF_SCREEN: type = "offscreen"; break;
default: break; default: break;
} }
return mate::ConvertToV8(isolate, type); return mate::ConvertToV8(isolate, type);
@ -211,6 +212,8 @@ struct Converter<atom::api::WebContents::Type> {
*out = Type::WEB_VIEW; *out = Type::WEB_VIEW;
} else if (type == "backgroundPage") { } else if (type == "backgroundPage") {
*out = Type::BACKGROUND_PAGE; *out = Type::BACKGROUND_PAGE;
} else if (type == "offscreen") {
*out = Type::OFF_SCREEN;
} else { } else {
return false; return false;
} }
@ -287,9 +290,8 @@ WebContents::WebContents(v8::Isolate* isolate,
type_ = WEB_VIEW; type_ = WEB_VIEW;
else if (options.Get("isBackgroundPage", &b) && b) else if (options.Get("isBackgroundPage", &b) && b)
type_ = BACKGROUND_PAGE; type_ = BACKGROUND_PAGE;
else if (options.Get("offscreen", &b) && b)
bool offscreen = false; type_ = OFF_SCREEN;
options.Get("offScreen", &offscreen);
// Obtain the session. // Obtain the session.
std::string partition; std::string partition;
@ -313,7 +315,7 @@ WebContents::WebContents(v8::Isolate* isolate,
guest_delegate_.reset(new WebViewGuestDelegate); guest_delegate_.reset(new WebViewGuestDelegate);
params.guest_delegate = guest_delegate_.get(); params.guest_delegate = guest_delegate_.get();
web_contents = content::WebContents::Create(params); web_contents = content::WebContents::Create(params);
} else if(offscreen) { } else if(IsOffScreen()) {
content::WebContents::CreateParams params(session->browser_context()); content::WebContents::CreateParams params(session->browser_context());
auto view = new OffScreenWebContentsView(); auto view = new OffScreenWebContentsView();
@ -382,7 +384,7 @@ bool WebContents::AddMessageToConsole(content::WebContents* source,
const base::string16& message, const base::string16& message,
int32_t line_no, int32_t line_no,
const base::string16& source_id) { const base::string16& source_id) {
if (type_ == BROWSER_WINDOW) { if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN)) {
return false; return false;
} else { } else {
Emit("console-message", level, message, line_no, source_id); 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, void WebContents::OnCreateWindow(const GURL& target_url,
const std::string& frame_name, const std::string& frame_name,
WindowOpenDisposition disposition) { WindowOpenDisposition disposition) {
if (type_ == BROWSER_WINDOW) if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN))
Emit("-new-window", target_url, frame_name, disposition); Emit("-new-window", target_url, frame_name, disposition);
else else
Emit("new-window", target_url, frame_name, disposition); Emit("new-window", target_url, frame_name, disposition);
@ -403,7 +405,7 @@ content::WebContents* WebContents::OpenURLFromTab(
content::WebContents* source, content::WebContents* source,
const content::OpenURLParams& params) { const content::OpenURLParams& params) {
if (params.disposition != CURRENT_TAB) { if (params.disposition != CURRENT_TAB) {
if (type_ == BROWSER_WINDOW) if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN))
Emit("-new-window", params.url, "", params.disposition); Emit("-new-window", params.url, "", params.disposition);
else else
Emit("new-window", params.url, "", params.disposition); Emit("new-window", params.url, "", params.disposition);
@ -420,7 +422,7 @@ content::WebContents* WebContents::OpenURLFromTab(
void WebContents::BeforeUnloadFired(content::WebContents* tab, void WebContents::BeforeUnloadFired(content::WebContents* tab,
bool proceed, bool proceed,
bool* proceed_to_fire_unload) { bool* proceed_to_fire_unload) {
if (type_ == BROWSER_WINDOW) if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN))
*proceed_to_fire_unload = proceed; *proceed_to_fire_unload = proceed;
else else
*proceed_to_fire_unload = true; *proceed_to_fire_unload = true;
@ -433,7 +435,7 @@ void WebContents::MoveContents(content::WebContents* source,
void WebContents::CloseContents(content::WebContents* source) { void WebContents::CloseContents(content::WebContents* source) {
Emit("close"); Emit("close");
if (type_ == BROWSER_WINDOW && owner_window()) if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN) && owner_window())
owner_window()->CloseContents(source); owner_window()->CloseContents(source);
} }
@ -487,13 +489,13 @@ void WebContents::ExitFullscreenModeForTab(content::WebContents* source) {
void WebContents::RendererUnresponsive(content::WebContents* source) { void WebContents::RendererUnresponsive(content::WebContents* source) {
Emit("unresponsive"); Emit("unresponsive");
if (type_ == BROWSER_WINDOW && owner_window()) if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN) && owner_window())
owner_window()->RendererUnresponsive(source); owner_window()->RendererUnresponsive(source);
} }
void WebContents::RendererResponsive(content::WebContents* source) { void WebContents::RendererResponsive(content::WebContents* source) {
Emit("responsive"); Emit("responsive");
if (type_ == BROWSER_WINDOW && owner_window()) if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN) && owner_window())
owner_window()->RendererResponsive(source); owner_window()->RendererResponsive(source);
} }
@ -1348,6 +1350,10 @@ bool WebContents::IsGuest() const {
return type_ == WEB_VIEW; return type_ == WEB_VIEW;
} }
bool WebContents::IsOffScreen() const {
return type_ == OFF_SCREEN;
}
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());

View file

@ -50,6 +50,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
BROWSER_WINDOW, // Used by BrowserWindow. BROWSER_WINDOW, // Used by BrowserWindow.
REMOTE, // Thin wrap around an existing WebContents. REMOTE, // Thin wrap around an existing WebContents.
WEB_VIEW, // Used by <webview>. WEB_VIEW, // Used by <webview>.
OFF_SCREEN, // Used for offscreen rendering
}; };
// For node.js callback function type: function(error, buffer) // For node.js callback function type: function(error, buffer)
@ -156,6 +157,8 @@ 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 IsOffScreen() const;
// Callback triggered on permission response. // Callback triggered on permission response.
void OnEnterFullscreenModeForTab(content::WebContents* source, void OnEnterFullscreenModeForTab(content::WebContents* source,

View file

@ -87,6 +87,8 @@ AtomBrowserContext::AtomBrowserContext(
// Read options. // Read options.
use_cache_ = true; use_cache_ = true;
options.GetBoolean("cache", &use_cache_); options.GetBoolean("cache", &use_cache_);
InitPrefs();
} }
AtomBrowserContext::~AtomBrowserContext() { AtomBrowserContext::~AtomBrowserContext() {

View file

@ -32,7 +32,7 @@ exports.load = (appUrl) => {
backgroundColor: '#FFFFFF', backgroundColor: '#FFFFFF',
useContentSize: true, useContentSize: true,
webPreferences: { webPreferences: {
offScreen: true, offscreen: true,
nodeIntegration: false nodeIntegration: false
} }
}) })
@ -74,7 +74,7 @@ exports.load = (appUrl) => {
nodeIntegration: false nodeIntegration: false
} }
}) })
mainWindow2.loadURL(appUrl) mainWindow2.loadURL("http://4danatomy.com")
mainWindow2.focus() mainWindow2.focus()
/*mainWindow2.webContents.on('dom-ready', () => { /*mainWindow2.webContents.on('dom-ready', () => {
mainWindow2.webContents.beginFrameSubscription(() => { mainWindow2.webContents.beginFrameSubscription(() => {
@ -92,179 +92,185 @@ exports.load = (appUrl) => {
start2 = end2 start2 = end2
})*/ })*/
//
// mainWindow3 = new BrowserWindow({ mainWindow3 = new BrowserWindow({
// width: 800, width: 800,
// height: 600, height: 600,
// autoHideMenuBar: true, autoHideMenuBar: true,
// backgroundColor: '#FFFFFF', backgroundColor: '#FFFFFF',
// useContentSize: true, useContentSize: true,
// webPreferences: { webPreferences: {
// nodeIntegration: false offscreen: true,
// } nodeIntegration: false
// }) }
// mainWindow3.loadURL(appUrl) })
// mainWindow3.focus() mainWindow3.loadURL(appUrl)
// mainWindow3.webContents.on('dom-ready', () => { mainWindow3.focus()
// mainWindow3.webContents.beginFrameSubscription(() => { mainWindow3.webContents.on('dom-ready', () => {
// console.log("asd") mainWindow3.webContents.beginFrameSubscription(() => {
// }) console.log("asd")
// }) })
// })
// var start3, end3
// start3 = +new Date(); var start3, end3
// mainWindow3.webContents.on('paint', (e, rect, w, h, data) => { start3 = +new Date();
// end3 = +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`) const d = end3 - start3
// console.log(`browser #3: ${d < 10 ? ` ${d}` : d} ms`)
// start3 = end3
// }) start3 = end3
// })
// mainWindow4 = new BrowserWindow({
// width: 800, mainWindow4 = new BrowserWindow({
// height: 600, width: 800,
// autoHideMenuBar: true, height: 600,
// backgroundColor: '#FFFFFF', autoHideMenuBar: true,
// useContentSize: true, backgroundColor: '#FFFFFF',
// webPreferences: { useContentSize: true,
// nodeIntegration: false webPreferences: {
// } offscreen: true,
// }) nodeIntegration: false
// mainWindow4.loadURL(appUrl) }
// mainWindow4.focus() })
// mainWindow4.webContents.on('dom-ready', () => { mainWindow4.loadURL(appUrl)
// mainWindow4.webContents.beginFrameSubscription(() => { mainWindow4.focus()
// console.log("asd") 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) => { var start4, end4
// end4 = +new Date(); start4 = +new Date();
// mainWindow4.webContents.on('paint', (e, rect, w, h, data) => {
// const d = end4 - start4 end4 = +new Date();
// console.log(`browser #4: ${d < 10 ? ` ${d}` : d} ms`)
// const d = end4 - start4
// start4 = end4 console.log(`browser #4: ${d < 10 ? ` ${d}` : d} ms`)
// })
// start4 = end4
// mainWindow5 = new BrowserWindow({ })
// width: 800,
// height: 600, mainWindow5 = new BrowserWindow({
// autoHideMenuBar: true, width: 800,
// backgroundColor: '#FFFFFF', height: 600,
// useContentSize: true, autoHideMenuBar: true,
// webPreferences: { backgroundColor: '#FFFFFF',
// nodeIntegration: false useContentSize: true,
// } webPreferences: {
// }) offscreen: true,
// mainWindow5.loadURL(appUrl) nodeIntegration: false
// mainWindow5.focus() }
// mainWindow5.webContents.on('dom-ready', () => { })
// mainWindow5.webContents.beginFrameSubscription(() => { mainWindow5.loadURL(appUrl)
// console.log("asd") 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(); var start5, end5
// start5 = +new Date();
// const d = end5 - start5 mainWindow5.webContents.on('paint', (e, rect, w, h, data) => {
// console.log(`browser #5: ${d < 10 ? ` ${d}` : d} ms`) end5 = +new Date();
//
// start5 = end5 const d = end5 - start5
// }) console.log(`browser #5: ${d < 10 ? ` ${d}` : d} ms`)
//
// mainWindow6 = new BrowserWindow({ start5 = end5
// width: 800, })
// height: 600,
// autoHideMenuBar: true, mainWindow6 = new BrowserWindow({
// backgroundColor: '#FFFFFF', width: 800,
// useContentSize: true, height: 600,
// webPreferences: { autoHideMenuBar: true,
// nodeIntegration: false backgroundColor: '#FFFFFF',
// } useContentSize: true,
// }) webPreferences: {
// mainWindow6.loadURL(appUrl) offscreen: true,
// mainWindow6.focus() nodeIntegration: false
// mainWindow6.webContents.on('dom-ready', () => { }
// mainWindow6.webContents.beginFrameSubscription(() => { })
// console.log("asd") mainWindow6.loadURL(appUrl)
// }) mainWindow6.focus()
// }) mainWindow6.webContents.on('dom-ready', () => {
// mainWindow6.webContents.beginFrameSubscription(() => {
// var start6, end6 console.log("asd")
// start6 = +new Date(); })
// mainWindow6.webContents.on('paint', (e, rect, w, h, data) => { })
// end6 = +new Date();
// var start6, end6
// const d = end6 - start6 start6 = +new Date();
// console.log(`browser #6: ${d < 10 ? ` ${d}` : d} ms`) mainWindow6.webContents.on('paint', (e, rect, w, h, data) => {
// end6 = +new Date();
// start6 = end6
// }) const d = end6 - start6
// console.log(`browser #6: ${d < 10 ? ` ${d}` : d} ms`)
// mainWindow7 = new BrowserWindow({
// width: 800, start6 = end6
// height: 600, })
// autoHideMenuBar: true,
// backgroundColor: '#FFFFFF', mainWindow7 = new BrowserWindow({
// useContentSize: true, width: 800,
// webPreferences: { height: 600,
// nodeIntegration: false autoHideMenuBar: true,
// } backgroundColor: '#FFFFFF',
// }) useContentSize: true,
// mainWindow7.loadURL(appUrl) webPreferences: {
// mainWindow7.focus() offscreen: true,
// mainWindow7.webContents.on('dom-ready', () => { nodeIntegration: false
// mainWindow7.webContents.beginFrameSubscription(() => { }
// console.log("asd") })
// }) mainWindow7.loadURL(appUrl)
// }) mainWindow7.focus()
// mainWindow7.webContents.on('dom-ready', () => {
// var start7, end7 mainWindow7.webContents.beginFrameSubscription(() => {
// start7 = +new Date(); console.log("asd")
// mainWindow7.webContents.on('paint', (e, rect, w, h, data) => { })
// end7 = +new Date(); })
//
// const d = end7 - start7 var start7, end7
// console.log(`browser #7: ${d < 10 ? ` ${d}` : d} ms`) start7 = +new Date();
// mainWindow7.webContents.on('paint', (e, rect, w, h, data) => {
// start7 = end7 end7 = +new Date();
// })
// const d = end7 - start7
// mainWindow8 = new BrowserWindow({ console.log(`browser #7: ${d < 10 ? ` ${d}` : d} ms`)
// width: 800,
// height: 600, start7 = end7
// autoHideMenuBar: true, })
// backgroundColor: '#FFFFFF',
// useContentSize: true, mainWindow8 = new BrowserWindow({
// webPreferences: { width: 800,
// nodeIntegration: false height: 600,
// } autoHideMenuBar: true,
// }) backgroundColor: '#FFFFFF',
// mainWindow8.loadURL(appUrl) useContentSize: true,
// mainWindow8.focus() webPreferences: {
// mainWindow8.webContents.on('dom-ready', () => { offscreen: true,
// mainWindow8.webContents.beginFrameSubscription(() => { nodeIntegration: false
// console.log("asd") }
// }) })
// }) mainWindow8.loadURL(appUrl)
// mainWindow8.focus()
// var start8, end8 mainWindow8.webContents.on('dom-ready', () => {
// start8 = +new Date(); mainWindow8.webContents.beginFrameSubscription(() => {
// mainWindow8.webContents.on('paint', (e, rect, w, h, data) => { console.log("asd")
// end8 = +new Date(); })
// })
// const d = end8 - start8
// console.log(`browser #8: ${d < 10 ? ` ${d}` : d} ms`) var start8, end8
// start8 = +new Date();
// start8 = end8 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
})
}) })
} }

2
vendor/brightray vendored

@ -1 +1 @@
Subproject commit fa17fc6b68c43188ba4f85ba8fb87d66914a0be4 Subproject commit 230dd282372480256006d1beda7b970d1b5c517f