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/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<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

View file

@ -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<content::ContentBrowserClient> browser_client_;
std::unique_ptr<content::ContentRendererClient> renderer_client_;
std::unique_ptr<content::ContentUtilityClient> utility_client_;
std::unique_ptr<AtomRenderViewHostFactory> render_view_host_factory_;
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::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<atom::api::WebContents::Type> {
*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<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
WebContentsPreferences* web_preferences =
WebContentsPreferences::FromWebContents(web_contents());

View file

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

View file

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

View file

@ -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
})
})
}

2
vendor/brightray vendored

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