Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(781)

Unified Diff: ui/snapshot/snapshot_mac.mm

Issue 2650903003: Revert of [devtools] Support different encodings for Page.CaptureScreenshot. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/snapshot/snapshot_ios.mm ('k') | ui/snapshot/snapshot_mac_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/snapshot/snapshot_mac.mm
diff --git a/ui/snapshot/snapshot_mac.mm b/ui/snapshot/snapshot_mac.mm
index 40cfaaf0e2fea90db89860e6482708696a5669eb..9761cb7f5086136f36de50109e04e7e0e92222eb 100644
--- a/ui/snapshot/snapshot_mac.mm
+++ b/ui/snapshot/snapshot_mac.mm
@@ -9,6 +9,7 @@
#include "base/callback.h"
#include "base/logging.h"
#include "base/mac/scoped_cftyperef.h"
+#include "base/mac/scoped_nsobject.h"
#include "base/mac/sdk_forward_declarations.h"
#include "base/task_runner.h"
#include "ui/gfx/geometry/rect.h"
@@ -17,8 +18,8 @@
namespace ui {
bool GrabViewSnapshot(gfx::NativeView view,
- const gfx::Rect& snapshot_bounds,
- gfx::Image* image) {
+ std::vector<unsigned char>* png_representation,
+ const gfx::Rect& snapshot_bounds) {
NSWindow* window = [view window];
NSScreen* screen = [[NSScreen screens] firstObject];
gfx::Rect screen_bounds = gfx::Rect(NSRectToCGRect([screen frame]));
@@ -42,6 +43,8 @@
DCHECK_LE(screen_snapshot_bounds.right(), view_bounds.right());
DCHECK_LE(screen_snapshot_bounds.bottom(), view_bounds.bottom());
+ png_representation->clear();
+
base::ScopedCFTypeRef<CGImageRef> windowSnapshot(
CGWindowListCreateImage(screen_snapshot_bounds.ToCGRect(),
kCGWindowListOptionIncludingWindow,
@@ -50,19 +53,27 @@
if (CGImageGetWidth(windowSnapshot) <= 0)
return false;
- NSImage* nsImage =
- [[NSImage alloc] initWithCGImage:windowSnapshot size:NSZeroSize];
- *image = gfx::Image(nsImage);
+ base::scoped_nsobject<NSBitmapImageRep> rep(
+ [[NSBitmapImageRep alloc] initWithCGImage:windowSnapshot]);
+ NSData* data = [rep representationUsingType:NSPNGFileType properties:@{}];
+ const unsigned char* buf = static_cast<const unsigned char*>([data bytes]);
+ NSUInteger length = [data length];
+ if (buf == NULL || length == 0)
+ return false;
+
+ png_representation->assign(buf, buf + length);
+ DCHECK(!png_representation->empty());
+
return true;
}
bool GrabWindowSnapshot(gfx::NativeWindow window,
- const gfx::Rect& snapshot_bounds,
- gfx::Image* image) {
+ std::vector<unsigned char>* png_representation,
+ const gfx::Rect& snapshot_bounds) {
// Make sure to grab the "window frame" view so we get current tab +
// tabstrip.
- return GrabViewSnapshot([[window contentView] superview], snapshot_bounds,
- image);
+ return GrabViewSnapshot([[window contentView] superview], png_representation,
+ snapshot_bounds);
}
void GrabWindowSnapshotAndScaleAsync(
@@ -74,17 +85,21 @@
callback.Run(gfx::Image());
}
-void GrabViewSnapshotAsync(gfx::NativeView view,
- const gfx::Rect& source_rect,
- const GrabWindowSnapshotAsyncCallback& callback) {
- callback.Run(gfx::Image());
+void GrabViewSnapshotAsync(
+ gfx::NativeView view,
+ const gfx::Rect& source_rect,
+ scoped_refptr<base::TaskRunner> background_task_runner,
+ const GrabWindowSnapshotAsyncPNGCallback& callback) {
+ callback.Run(scoped_refptr<base::RefCountedBytes>());
}
-void GrabWindowSnapshotAsync(gfx::NativeWindow window,
- const gfx::Rect& source_rect,
- const GrabWindowSnapshotAsyncCallback& callback) {
+void GrabWindowSnapshotAsync(
+ gfx::NativeWindow window,
+ const gfx::Rect& source_rect,
+ scoped_refptr<base::TaskRunner> background_task_runner,
+ const GrabWindowSnapshotAsyncPNGCallback& callback) {
return GrabViewSnapshotAsync([[window contentView] superview], source_rect,
- callback);
+ background_task_runner, callback);
}
} // namespace ui
« no previous file with comments | « ui/snapshot/snapshot_ios.mm ('k') | ui/snapshot/snapshot_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698