Index: chrome/browser/ui/window_snapshot/window_snapshot_mac.mm |
diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm b/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm |
new file mode 100755 |
index 0000000000000000000000000000000000000000..10999aba0d098b603725ab3e0faf7a35b39e3936 |
--- /dev/null |
+++ b/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm |
@@ -0,0 +1,45 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/window_snapshot/window_snapshot.h" |
+ |
+#import <Cocoa/Cocoa.h> |
+ |
+#include "base/logging.h" |
+#include "base/mac/scoped_cftyperef.h" |
+#include "base/scoped_nsobject.h" |
+ |
+namespace browser { |
+ |
+void GrabWindowSnapshot(gfx::NativeWindow window, |
+ std::vector<unsigned char>* png_representation, |
+ int* width, int* height) { |
+ png_representation->clear(); |
+ *width = 0; |
+ *height = 0; |
+ |
+ // Make sure to grab the "window frame" view so we get current tab + |
+ // tabstrip. |
+ NSView* view = [[window contentView] superview]; |
+ base::mac::ScopedCFTypeRef<CGImageRef> windowSnapshot(CGWindowListCreateImage( |
+ CGRectNull, kCGWindowListOptionIncludingWindow, |
+ [[view window] windowNumber], kCGWindowImageBoundsIgnoreFraming)); |
+ if (CGImageGetWidth(windowSnapshot) <= 0) |
+ return; |
+ |
+ scoped_nsobject<NSBitmapImageRep> rep( |
+ [[NSBitmapImageRep alloc] initWithCGImage:windowSnapshot]); |
+ NSData* data = [rep representationUsingType:NSPNGFileType properties:nil]; |
+ const unsigned char* buf = static_cast<const unsigned char*>([data bytes]); |
+ NSUInteger length = [data length]; |
+ if (buf == NULL || length == 0) |
+ return; |
+ |
+ *width = static_cast<int>([rep pixelsWide]); |
+ *height = static_cast<int>([rep pixelsHigh]); |
+ png_representation->assign(buf, buf + length); |
+ DCHECK(png_representation->size() > 0); |
+} |
+ |
+} // namespace browser |