Add BrowserWindow.capturePage API.
This commit is contained in:
parent
a0548530e7
commit
3b4a45ac65
3 changed files with 40 additions and 1 deletions
|
@ -14,6 +14,7 @@
|
|||
#include "ui/gfx/point.h"
|
||||
#include "ui/gfx/rect.h"
|
||||
#include "ui/gfx/size.h"
|
||||
#include "vendor/node/src/node_buffer.h"
|
||||
|
||||
using content::V8ValueConverter;
|
||||
using content::NavigationController;
|
||||
|
@ -82,6 +83,20 @@ void Window::OnRendererCrashed() {
|
|||
Emit("crashed");
|
||||
}
|
||||
|
||||
void Window::OnCapturePageDone(v8::Persistent<v8::Function> callback,
|
||||
const std::vector<unsigned char>& data) {
|
||||
v8::HandleScope scope;
|
||||
|
||||
// TODO Use new Buffer API when we updated to node v0.12.x.
|
||||
node::Buffer* buffer = node::Buffer::New(
|
||||
reinterpret_cast<const char*>(data.data()),
|
||||
data.size());
|
||||
|
||||
v8::Handle<v8::Value> arg = buffer->handle_;
|
||||
callback->Call(v8::Context::GetCurrent()->Global(), 1, &arg);
|
||||
callback.Dispose(v8::Isolate::GetCurrent());
|
||||
}
|
||||
|
||||
// static
|
||||
v8::Handle<v8::Value> Window::New(const v8::Arguments &args) {
|
||||
v8::HandleScope scope;
|
||||
|
@ -480,6 +495,22 @@ v8::Handle<v8::Value> Window::RestartHangMonitorTimeout(
|
|||
return v8::Undefined();
|
||||
}
|
||||
|
||||
// static
|
||||
v8::Handle<v8::Value> Window::CapturePage(const v8::Arguments& args) {
|
||||
UNWRAP_WINDOW_AND_CHECK;
|
||||
|
||||
gfx::Rect rect;
|
||||
v8::Persistent<v8::Function> callback;
|
||||
if (!FromV8Arguments(args, &rect, &callback))
|
||||
return node::ThrowTypeError("Bad argument");
|
||||
|
||||
self->window_->CapturePage(rect, base::Bind(&Window::OnCapturePageDone,
|
||||
base::Unretained(self),
|
||||
callback));
|
||||
|
||||
return v8::Undefined();
|
||||
}
|
||||
|
||||
// static
|
||||
v8::Handle<v8::Value> Window::GetPageTitle(const v8::Arguments &args) {
|
||||
UNWRAP_WINDOW_AND_CHECK;
|
||||
|
@ -721,6 +752,7 @@ void Window::Initialize(v8::Handle<v8::Object> target) {
|
|||
NODE_SET_PROTOTYPE_METHOD(t,
|
||||
"restartHangMonitorTimeout",
|
||||
RestartHangMonitorTimeout);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "capturePage", CapturePage);
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "getPageTitle", GetPageTitle);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "isLoading", IsLoading);
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#ifndef ATOM_BROWSER_API_ATOM_API_WINDOW_H_
|
||||
#define ATOM_BROWSER_API_ATOM_API_WINDOW_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "browser/api/atom_api_event_emitter.h"
|
||||
#include "browser/native_window_observer.h"
|
||||
|
@ -87,6 +89,7 @@ class Window : public EventEmitter,
|
|||
static v8::Handle<v8::Value> IsWebViewFocused(const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> RestartHangMonitorTimeout(
|
||||
const v8::Arguments &args);
|
||||
static v8::Handle<v8::Value> CapturePage(const v8::Arguments& args);
|
||||
|
||||
// APIs for WebContents.
|
||||
static v8::Handle<v8::Value> GetPageTitle(const v8::Arguments &args);
|
||||
|
@ -110,6 +113,10 @@ class Window : public EventEmitter,
|
|||
static v8::Handle<v8::Value> Reload(const v8::Arguments &args);
|
||||
static v8::Handle<v8::Value> ReloadIgnoringCache(const v8::Arguments &args);
|
||||
|
||||
// Called when capturePage is done.
|
||||
void OnCapturePageDone(v8::Persistent<v8::Function> callback,
|
||||
const std::vector<unsigned char>& data);
|
||||
|
||||
scoped_ptr<NativeWindow> window_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Window);
|
||||
|
|
2
vendor/node
vendored
2
vendor/node
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 7f44fac0fd64af7ec172c9606af1f3cec684a9ce
|
||||
Subproject commit 24c11bdc794c2b7b79163cb4737046f8de42446d
|
Loading…
Reference in a new issue