cleaning up osr pt1

This commit is contained in:
gellert 2016-07-29 14:50:27 +02:00
parent fdff60132c
commit 6abf7475b8
13 changed files with 196 additions and 239 deletions

View file

@ -70,9 +70,7 @@
#include "content/browser/web_contents/web_contents_impl.h"
#include "atom/browser/osr_web_contents_view.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "atom/browser/osr_web_contents_view.h"
#include "atom/browser/osr_render_widget_host_view.h"
#include "atom/common/node_includes.h"
@ -291,7 +289,7 @@ WebContents::WebContents(v8::Isolate* isolate,
else if (options.Get("isBackgroundPage", &b) && b)
type_ = BACKGROUND_PAGE;
else if (options.Get("offscreen", &b) && b)
type_ = OFF_SCREEN;
type_ = OFF_SCREEN;
// Obtain the session.
std::string partition;
@ -316,16 +314,19 @@ WebContents::WebContents(v8::Isolate* isolate,
params.guest_delegate = guest_delegate_.get();
web_contents = content::WebContents::Create(params);
} else if(IsOffScreen()) {
content::WebContents::CreateParams params(session->browser_context());
content::WebContents::CreateParams params(session->browser_context());
auto view = new OffScreenWebContentsView();
params.view = view;
params.delegate_view = view;
web_contents = content::WebContents::Create(params);
view->SetWebContents(web_contents);
} else {
content::WebContents::CreateParams params(session->browser_context());
view->SetWebContents(web_contents);
paint_callback_ = base::Bind(&WebContents::OnPaint, base::Unretained(this),
isolate);
} else {
content::WebContents::CreateParams params(session->browser_context());
web_contents = content::WebContents::Create(params);
}
@ -401,6 +402,14 @@ void WebContents::OnCreateWindow(const GURL& target_url,
Emit("new-window", target_url, frame_name, disposition);
}
void WebContents::RenderViewReady() {
if (IsOffScreen()) {
const auto rwhv = web_contents()->GetRenderWidgetHostView();
auto osr_rwhv = static_cast<OffScreenRenderWidgetHostView *>(rwhv);
osr_rwhv->SetPaintCallback(&paint_callback_);
}
}
content::WebContents* WebContents::OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) {
@ -1226,30 +1235,12 @@ void WebContents::BeginFrameSubscription(mate::Arguments* args) {
const auto view = web_contents()->GetRenderWidgetHostView();
if (view) {
// std::unique_ptr<FrameSubscriber> frame_subscriber(new FrameSubscriber(
// isolate(), view, callback, only_dirty));
// view->BeginFrameSubscription(std::move(frame_subscriber));
paint_isolate_ = args->isolate();
auto v = static_cast<OffScreenWindow *>(view);
paint_callback_ = base::Bind(&WebContents::OnPaint,
base::Unretained(this));
v->SetPaintCallback(&paint_callback_);
std::unique_ptr<FrameSubscriber> frame_subscriber(new FrameSubscriber(
isolate(), view, callback, only_dirty));
view->BeginFrameSubscription(std::move(frame_subscriber));
}
}
void WebContents::OnPaint(
const gfx::Rect& damage_rect,
int bitmap_width,
int bitmap_height,
void* bitmap_pixels) {
v8::MaybeLocal<v8::Object> buffer = node::Buffer::New(paint_isolate_
, (char *)bitmap_pixels, sizeof(bitmap_pixels));
Emit("paint", damage_rect, bitmap_width, bitmap_height, buffer.ToLocalChecked());
}
void WebContents::EndFrameSubscription() {
const auto view = web_contents()->GetRenderWidgetHostView();
if (view)
@ -1396,6 +1387,19 @@ v8::Local<v8::Value> WebContents::Debugger(v8::Isolate* isolate) {
return v8::Local<v8::Value>::New(isolate, debugger_);
}
void WebContents::OnPaint(
v8::Isolate* isolate,
const gfx::Rect& damage_rect,
int bitmap_width,
int bitmap_height,
void* bitmap_pixels) {
v8::MaybeLocal<v8::Object> buffer = node::Buffer::New(isolate
, (char *)bitmap_pixels, sizeof(bitmap_pixels));
Emit("paint", damage_rect, bitmap_width, bitmap_height,
buffer.ToLocalChecked());
}
// static
void WebContents::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype) {

View file

@ -18,7 +18,7 @@
#include "native_mate/handle.h"
#include "ui/gfx/image/image.h"
#include "atom/browser/osr_window.h"
#include "atom/browser/osr_output_device.h"
namespace blink {
struct WebDeviceEmulationParams;
@ -145,7 +145,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
// Subscribe to the frame updates.
void BeginFrameSubscription(mate::Arguments* args);
void EndFrameSubscription();
void OnPaint(const gfx::Rect&, int, int, void*);
void OnPaint(v8::Isolate*, const gfx::Rect&, int, int, void*);
// Dragging native items.
void StartDrag(const mate::Dictionary& item, mate::Arguments* args);
@ -157,7 +157,7 @@ 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.
@ -272,6 +272,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
void MediaStartedPlaying(const MediaPlayerId& id) override;
void MediaStoppedPlaying(const MediaPlayerId& id) override;
void DidChangeThemeColor(SkColor theme_color) override;
void RenderViewReady() override;
// brightray::InspectableWebContentsDelegate:
void DevToolsReloadPage() override;
@ -309,8 +310,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
v8::Global<v8::Value> devtools_web_contents_;
v8::Global<v8::Value> debugger_;
v8::Isolate* paint_isolate_;
std::unique_ptr<WebViewGuestDelegate> guest_delegate_;
// The host webcontents that may contain this webcontents.

View file

@ -4,9 +4,9 @@
#include "atom/browser/api/atom_api_web_contents.h"
// @interface NSWindow
// - (BOOL)isKeyWindow;
// @end
@interface NSWindow
- (BOOL)isKeyWindow;
@end
namespace atom {