Merge atom/master
This commit is contained in:
commit
3f0d598a59
137 changed files with 3700 additions and 2419 deletions
|
@ -218,7 +218,8 @@ WebContents::WebContents(content::WebContents* web_contents)
|
|||
|
||||
WebContents::WebContents(v8::Isolate* isolate,
|
||||
const mate::Dictionary& options)
|
||||
: request_id_(0) {
|
||||
: embedder_(nullptr),
|
||||
request_id_(0) {
|
||||
// Whether it is a guest WebContents.
|
||||
bool is_guest = false;
|
||||
options.Get("isGuest", &is_guest);
|
||||
|
@ -273,10 +274,10 @@ WebContents::WebContents(v8::Isolate* isolate,
|
|||
guest_delegate_->Initialize(this);
|
||||
|
||||
NativeWindow* owner_window = nullptr;
|
||||
WebContents* embedder = nullptr;
|
||||
if (options.Get("embedder", &embedder) && embedder) {
|
||||
if (options.Get("embedder", &embedder_) && embedder_) {
|
||||
// New WebContents's owner_window is the embedder's owner_window.
|
||||
auto relay = NativeWindowRelay::FromWebContents(embedder->web_contents());
|
||||
auto relay =
|
||||
NativeWindowRelay::FromWebContents(embedder_->web_contents());
|
||||
if (relay)
|
||||
owner_window = relay->window.get();
|
||||
}
|
||||
|
@ -296,6 +297,7 @@ WebContents::~WebContents() {
|
|||
// The WebContentsDestroyed will not be called automatically because we
|
||||
// unsubscribe from webContents before destroying it. So we have to manually
|
||||
// call it here to make sure "destroyed" event is emitted.
|
||||
RenderViewDeleted(web_contents()->GetRenderViewHost());
|
||||
WebContentsDestroyed();
|
||||
}
|
||||
}
|
||||
|
@ -485,17 +487,7 @@ void WebContents::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
|
|||
}
|
||||
|
||||
void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
|
||||
int process_id = render_view_host->GetProcess()->GetID();
|
||||
Emit("render-view-deleted", process_id);
|
||||
|
||||
// process.emit('ATOM_BROWSER_RELEASE_RENDER_VIEW', processId);
|
||||
// Tell the rpc server that a render view has been deleted and we need to
|
||||
// release all objects owned by it.
|
||||
v8::Locker locker(isolate());
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
node::Environment* env = node::Environment::GetCurrent(isolate());
|
||||
mate::EmitEvent(isolate(), env->process_object(),
|
||||
"ATOM_BROWSER_RELEASE_RENDER_VIEW", process_id);
|
||||
Emit("render-view-deleted", render_view_host->GetProcess()->GetID());
|
||||
}
|
||||
|
||||
void WebContents::RenderProcessGone(base::TerminationStatus status) {
|
||||
|
@ -675,9 +667,6 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) {
|
|||
// be destroyed on close, and WebContentsDestroyed would be called for it, so
|
||||
// we need to make sure the api::WebContents is also deleted.
|
||||
void WebContents::WebContentsDestroyed() {
|
||||
// The RenderViewDeleted was not called when the WebContents is destroyed.
|
||||
RenderViewDeleted(web_contents()->GetRenderViewHost());
|
||||
|
||||
// This event is only for internal use, which is emitted when WebContents is
|
||||
// being destroyed.
|
||||
Emit("will-destroy");
|
||||
|
@ -710,6 +699,14 @@ bool WebContents::Equal(const WebContents* web_contents) const {
|
|||
}
|
||||
|
||||
void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
||||
if (!url.is_valid()) {
|
||||
Emit("did-fail-load",
|
||||
static_cast<int>(net::ERR_INVALID_URL),
|
||||
net::ErrorToShortString(net::ERR_INVALID_URL),
|
||||
url.possibly_invalid_spec());
|
||||
return;
|
||||
}
|
||||
|
||||
content::NavigationController::LoadURLParams params(url);
|
||||
|
||||
GURL http_referrer;
|
||||
|
@ -1064,11 +1061,9 @@ void WebContents::BeginFrameSubscription(
|
|||
const FrameSubscriber::FrameCaptureCallback& callback) {
|
||||
const auto view = web_contents()->GetRenderWidgetHostView();
|
||||
if (view) {
|
||||
FrameSubscriber* frame_subscriber = new FrameSubscriber(
|
||||
isolate(), view, callback);
|
||||
scoped_ptr<FrameSubscriber::Subscriber> del_frame_subscriber(
|
||||
frame_subscriber->GetSubscriber());
|
||||
view->BeginFrameSubscription(del_frame_subscriber.Pass());
|
||||
scoped_ptr<FrameSubscriber> frame_subscriber(new FrameSubscriber(
|
||||
isolate(), view, callback));
|
||||
view->BeginFrameSubscription(frame_subscriber.Pass());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1122,6 +1117,12 @@ v8::Local<v8::Value> WebContents::Session(v8::Isolate* isolate) {
|
|||
return v8::Local<v8::Value>::New(isolate, session_);
|
||||
}
|
||||
|
||||
content::WebContents* WebContents::HostWebContents() {
|
||||
if (!embedder_)
|
||||
return nullptr;
|
||||
return embedder_->web_contents();
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> WebContents::DevToolsWebContents(v8::Isolate* isolate) {
|
||||
if (devtools_web_contents_.IsEmpty())
|
||||
return v8::Null(isolate);
|
||||
|
@ -1205,6 +1206,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
|||
.SetMethod("addWorkSpace", &WebContents::AddWorkSpace)
|
||||
.SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace)
|
||||
.SetProperty("session", &WebContents::Session)
|
||||
.SetProperty("hostWebContents", &WebContents::HostWebContents)
|
||||
.SetProperty("devToolsWebContents", &WebContents::DevToolsWebContents)
|
||||
.SetProperty("debugger", &WebContents::Debugger);
|
||||
}
|
||||
|
|
|
@ -147,6 +147,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
|
||||
// Properties.
|
||||
v8::Local<v8::Value> Session(v8::Isolate* isolate);
|
||||
content::WebContents* HostWebContents();
|
||||
v8::Local<v8::Value> DevToolsWebContents(v8::Isolate* isolate);
|
||||
v8::Local<v8::Value> Debugger(v8::Isolate* isolate);
|
||||
|
||||
|
@ -287,6 +288,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
|
||||
scoped_ptr<WebViewGuestDelegate> guest_delegate_;
|
||||
|
||||
// The host webcontents that may contain this webcontents.
|
||||
WebContents* embedder_;
|
||||
|
||||
// The type of current WebContents.
|
||||
Type type_;
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ void TranslateOldOptions(v8::Isolate* isolate, v8::Local<v8::Object> options) {
|
|||
|
||||
// Converts binary data to Buffer.
|
||||
v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
||||
auto buffer = node::Buffer::New(isolate, static_cast<char*>(val), size);
|
||||
auto buffer = node::Buffer::Copy(isolate, static_cast<char*>(val), size);
|
||||
if (buffer.IsEmpty())
|
||||
return v8::Null(isolate);
|
||||
else
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
#include "base/bind.h"
|
||||
#include "atom/common/node_includes.h"
|
||||
#include "media/base/video_frame.h"
|
||||
#include "media/base/yuv_convert.h"
|
||||
#include "ui/gfx/screen.h"
|
||||
|
||||
#include "content/public/browser/render_widget_host.h"
|
||||
|
@ -16,75 +14,36 @@ namespace atom {
|
|||
|
||||
namespace api {
|
||||
|
||||
using Subscriber = FrameSubscriber::Subscriber;
|
||||
|
||||
FrameSubscriber::FrameSubscriber(v8::Isolate* isolate,
|
||||
content::RenderWidgetHostView* view,
|
||||
const FrameCaptureCallback& callback)
|
||||
: isolate_(isolate), callback_(callback), pending_frames(0), view_(view) {
|
||||
subscriber_ = new Subscriber(this);
|
||||
: isolate_(isolate), view_(view), callback_(callback), weak_factory_(this) {
|
||||
}
|
||||
|
||||
Subscriber::Subscriber(
|
||||
FrameSubscriber* frame_subscriber) : frame_subscriber_(frame_subscriber) {
|
||||
}
|
||||
|
||||
Subscriber::~Subscriber() {
|
||||
frame_subscriber_->subscriber_ = NULL;
|
||||
frame_subscriber_->RequestDestruct();
|
||||
}
|
||||
|
||||
bool Subscriber::ShouldCaptureFrame(
|
||||
bool FrameSubscriber::ShouldCaptureFrame(
|
||||
const gfx::Rect& damage_rect,
|
||||
base::TimeTicks present_time,
|
||||
scoped_refptr<media::VideoFrame>* storage,
|
||||
DeliverFrameCallback* callback) {
|
||||
const auto view = frame_subscriber_->view_;
|
||||
const auto host = view ? view->GetRenderWidgetHost() : nullptr;
|
||||
if (!view || !host)
|
||||
const auto host = view_ ? view_->GetRenderWidgetHost() : nullptr;
|
||||
if (!view_ || !host)
|
||||
return false;
|
||||
|
||||
const gfx::Size view_size = view->GetViewBounds().size();
|
||||
|
||||
gfx::Size bitmap_size = view_size;
|
||||
const gfx::NativeView native_view = view->GetNativeView();
|
||||
gfx::Screen* const screen = gfx::Screen::GetScreenFor(native_view);
|
||||
const float scale =
|
||||
screen->GetDisplayNearestWindow(native_view).device_scale_factor();
|
||||
if (scale > 1.0f)
|
||||
bitmap_size = gfx::ScaleToCeiledSize(view_size, scale);
|
||||
const auto size = view_->GetVisibleViewportSize();
|
||||
|
||||
host->CopyFromBackingStore(
|
||||
gfx::Rect(view_size),
|
||||
bitmap_size,
|
||||
gfx::Rect(size),
|
||||
size,
|
||||
base::Bind(&FrameSubscriber::OnFrameDelivered,
|
||||
base::Unretained(frame_subscriber_),
|
||||
frame_subscriber_->callback_),
|
||||
weak_factory_.GetWeakPtr(), callback_),
|
||||
kBGRA_8888_SkColorType);
|
||||
|
||||
frame_subscriber_->pending_frames++;
|
||||
return false;
|
||||
}
|
||||
|
||||
Subscriber* FrameSubscriber::GetSubscriber() {
|
||||
return subscriber_;
|
||||
}
|
||||
|
||||
bool FrameSubscriber::RequestDestruct() {
|
||||
bool deletable = (subscriber_ == NULL && pending_frames == 0);
|
||||
// Destruct FrameSubscriber if we're not waiting for frames and the
|
||||
// subscription has ended
|
||||
if (deletable)
|
||||
delete this;
|
||||
|
||||
return deletable;
|
||||
}
|
||||
|
||||
void FrameSubscriber::OnFrameDelivered(const FrameCaptureCallback& callback,
|
||||
const SkBitmap& bitmap, content::ReadbackResponse response) {
|
||||
pending_frames--;
|
||||
|
||||
if (RequestDestruct() || subscriber_ == NULL || bitmap.computeSize64() == 0)
|
||||
if (bitmap.computeSize64() == 0)
|
||||
return;
|
||||
|
||||
v8::Locker locker(isolate_);
|
||||
|
|
|
@ -6,55 +6,40 @@
|
|||
#define ATOM_BROWSER_API_FRAME_SUBSCRIBER_H_
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "content/public/browser/render_widget_host_view.h"
|
||||
#include "content/public/browser/render_widget_host_view_frame_subscriber.h"
|
||||
#include "content/public/browser/readback_types.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
class FrameSubscriber {
|
||||
class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
|
||||
public:
|
||||
using FrameCaptureCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
||||
|
||||
// Inner class that is the actual subscriber sent to chromium
|
||||
class Subscriber :
|
||||
public content::RenderWidgetHostViewFrameSubscriber {
|
||||
public:
|
||||
explicit Subscriber(FrameSubscriber* frame_subscriber);
|
||||
|
||||
bool ShouldCaptureFrame(const gfx::Rect& damage_rect,
|
||||
base::TimeTicks present_time,
|
||||
scoped_refptr<media::VideoFrame>* storage,
|
||||
DeliverFrameCallback* callback) override;
|
||||
|
||||
~Subscriber();
|
||||
private:
|
||||
FrameSubscriber* frame_subscriber_;
|
||||
};
|
||||
|
||||
FrameSubscriber(v8::Isolate* isolate,
|
||||
content::RenderWidgetHostView* view,
|
||||
const FrameCaptureCallback& callback);
|
||||
|
||||
Subscriber* GetSubscriber();
|
||||
bool ShouldCaptureFrame(const gfx::Rect& damage_rect,
|
||||
base::TimeTicks present_time,
|
||||
scoped_refptr<media::VideoFrame>* storage,
|
||||
DeliverFrameCallback* callback) override;
|
||||
|
||||
private:
|
||||
void OnFrameDelivered(const FrameCaptureCallback& callback,
|
||||
const SkBitmap& bitmap, content::ReadbackResponse response);
|
||||
|
||||
bool RequestDestruct();
|
||||
|
||||
v8::Isolate* isolate_;
|
||||
content::RenderWidgetHostView* view_;
|
||||
FrameCaptureCallback callback_;
|
||||
Subscriber* subscriber_;
|
||||
int pending_frames;
|
||||
|
||||
base::WeakPtrFactory<FrameSubscriber> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FrameSubscriber);
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const EventEmitter = require('events').EventEmitter;
|
||||
const bindings = process.atomBinding('session');
|
||||
const PERSIST_PERFIX = 'persist:';
|
||||
const PERSIST_PREFIX = 'persist:';
|
||||
|
||||
// Returns the Session from |partition| string.
|
||||
exports.fromPartition = function(partition) {
|
||||
|
@ -10,8 +10,8 @@ exports.fromPartition = function(partition) {
|
|||
if (partition === '') {
|
||||
return exports.defaultSession;
|
||||
}
|
||||
if (partition.startsWith(PERSIST_PERFIX)) {
|
||||
return bindings.fromPartition(partition.substr(PERSIST_PERFIX.length), false);
|
||||
if (partition.startsWith(PERSIST_PREFIX)) {
|
||||
return bindings.fromPartition(partition.substr(PERSIST_PREFIX.length), false);
|
||||
} else {
|
||||
return bindings.fromPartition(partition, true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue