Return screenshot's data buffer instead of directly saving to file.
This commit is contained in:
parent
36ecb35cb1
commit
8d6764e0a0
2 changed files with 10 additions and 26 deletions
|
@ -200,14 +200,12 @@ bool NativeWindow::SetIcon(const std::string& str_path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::CapturePage(const gfx::Rect& rect,
|
void NativeWindow::CapturePage(const gfx::Rect& rect,
|
||||||
const base::FilePath& path,
|
|
||||||
const CapturePageCallback& callback) {
|
const CapturePageCallback& callback) {
|
||||||
GetWebContents()->GetRenderViewHost()->CopyFromBackingStore(
|
GetWebContents()->GetRenderViewHost()->CopyFromBackingStore(
|
||||||
rect,
|
rect,
|
||||||
gfx::Size(),
|
gfx::Size(),
|
||||||
base::Bind(&NativeWindow::OnCapturePageDone,
|
base::Bind(&NativeWindow::OnCapturePageDone,
|
||||||
base::Unretained(this),
|
base::Unretained(this),
|
||||||
path,
|
|
||||||
callback));
|
callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,27 +385,13 @@ void NativeWindow::Observe(int type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::OnCapturePageDone(const base::FilePath& filename,
|
void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
|
||||||
const CapturePageCallback& callback,
|
|
||||||
bool succeed,
|
bool succeed,
|
||||||
const SkBitmap& bitmap) {
|
const SkBitmap& bitmap) {
|
||||||
if (!succeed) {
|
|
||||||
callback.Run(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<unsigned char> data;
|
std::vector<unsigned char> data;
|
||||||
bool encoded = gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &data);
|
if (succeed)
|
||||||
if (!encoded) {
|
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &data);
|
||||||
callback.Run(false);
|
callback.Run(data);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int written = file_util::WriteFile(
|
|
||||||
filename,
|
|
||||||
reinterpret_cast<const char*>(&data[0]),
|
|
||||||
data.size());
|
|
||||||
callback.Run(written > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::OnRendererMessage(const string16& channel,
|
void NativeWindow::OnRendererMessage(const string16& channel,
|
||||||
|
|
|
@ -49,6 +49,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
public content::WebContentsObserver,
|
public content::WebContentsObserver,
|
||||||
public content::NotificationObserver {
|
public content::NotificationObserver {
|
||||||
public:
|
public:
|
||||||
|
typedef base::Callback<void(const std::vector<unsigned char>& buffer)>
|
||||||
|
CapturePageCallback;
|
||||||
|
|
||||||
virtual ~NativeWindow();
|
virtual ~NativeWindow();
|
||||||
|
|
||||||
// Create window with existing WebContents.
|
// Create window with existing WebContents.
|
||||||
|
@ -108,11 +111,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
virtual void RestartHangMonitorTimeout();
|
virtual void RestartHangMonitorTimeout();
|
||||||
virtual bool SetIcon(const std::string& path);
|
virtual bool SetIcon(const std::string& path);
|
||||||
|
|
||||||
// Captures the page with |rect| and saves the image to |path|, |callback|
|
// Captures the page with |rect|, |callback| would be called when capturing is
|
||||||
// would be called when capturing is done.
|
// done.
|
||||||
typedef base::Callback<void(bool succeed)> CapturePageCallback;
|
|
||||||
virtual void CapturePage(const gfx::Rect& rect,
|
virtual void CapturePage(const gfx::Rect& rect,
|
||||||
const base::FilePath& path,
|
|
||||||
const CapturePageCallback& callback);
|
const CapturePageCallback& callback);
|
||||||
|
|
||||||
// The same with closing a tab in a real browser.
|
// The same with closing a tab in a real browser.
|
||||||
|
@ -192,8 +193,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
void RendererUnresponsiveDelayed();
|
void RendererUnresponsiveDelayed();
|
||||||
|
|
||||||
// Called when CapturePage has done.
|
// Called when CapturePage has done.
|
||||||
void OnCapturePageDone(const base::FilePath& filename,
|
void OnCapturePageDone(const CapturePageCallback& callback,
|
||||||
const CapturePageCallback& callback,
|
|
||||||
bool succeed,
|
bool succeed,
|
||||||
const SkBitmap& bitmap);
|
const SkBitmap& bitmap);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue