OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/mac/mac_util.h" | 5 #include "base/mac/mac_util.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
12 #include "base/message_loop.h" | |
13 #include "base/scoped_nsobject.h" | 12 #include "base/scoped_nsobject.h" |
14 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
15 | 14 |
16 namespace base { | 15 namespace base { |
17 namespace mac { | 16 namespace mac { |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 // a count of currently outstanding requests for full screen mode from browser | 20 // a count of currently outstanding requests for full screen mode from browser |
22 // windows, plugins, etc. | 21 // windows, plugins, etc. |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 // NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | 221 // NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
223 // return ![defaults objectForKey:@"AppleMiniaturizeOnDoubleClick"] || | 222 // return ![defaults objectForKey:@"AppleMiniaturizeOnDoubleClick"] || |
224 // [defaults boolForKey:@"AppleMiniaturizeOnDoubleClick"]; | 223 // [defaults boolForKey:@"AppleMiniaturizeOnDoubleClick"]; |
225 BOOL methodImplemented = | 224 BOOL methodImplemented = |
226 [NSWindow respondsToSelector:@selector(_shouldMiniaturizeOnDoubleClick)]; | 225 [NSWindow respondsToSelector:@selector(_shouldMiniaturizeOnDoubleClick)]; |
227 DCHECK(methodImplemented); | 226 DCHECK(methodImplemented); |
228 return !methodImplemented || | 227 return !methodImplemented || |
229 [NSWindow performSelector:@selector(_shouldMiniaturizeOnDoubleClick)]; | 228 [NSWindow performSelector:@selector(_shouldMiniaturizeOnDoubleClick)]; |
230 } | 229 } |
231 | 230 |
232 void GrabWindowSnapshot(NSWindow* window, | |
233 std::vector<unsigned char>* png_representation, | |
234 int* width, int* height) { | |
235 png_representation->clear(); | |
236 *width = 0; | |
237 *height = 0; | |
238 | |
239 // Make sure to grab the "window frame" view so we get current tab + | |
240 // tabstrip. | |
241 NSView* view = [[window contentView] superview]; | |
242 ScopedCFTypeRef<CGImageRef> windowSnapshot(CGWindowListCreateImage( | |
243 CGRectNull, kCGWindowListOptionIncludingWindow, | |
244 [[view window] windowNumber], kCGWindowImageBoundsIgnoreFraming)); | |
245 if (CGImageGetWidth(windowSnapshot) <= 0) | |
246 return; | |
247 | |
248 scoped_nsobject<NSBitmapImageRep> rep( | |
249 [[NSBitmapImageRep alloc] initWithCGImage:windowSnapshot]); | |
250 NSData* data = [rep representationUsingType:NSPNGFileType properties:nil]; | |
251 const unsigned char* buf = static_cast<const unsigned char*>([data bytes]); | |
252 NSUInteger length = [data length]; | |
253 if (buf == NULL || length == 0) | |
254 return; | |
255 | |
256 *width = static_cast<int>([rep pixelsWide]); | |
257 *height = static_cast<int>([rep pixelsHigh]); | |
258 png_representation->assign(buf, buf + length); | |
259 DCHECK(png_representation->size() > 0); | |
260 } | |
261 | |
262 void ActivateProcess(pid_t pid) { | 231 void ActivateProcess(pid_t pid) { |
263 ProcessSerialNumber process; | 232 ProcessSerialNumber process; |
264 OSStatus status = GetProcessForPID(pid, &process); | 233 OSStatus status = GetProcessForPID(pid, &process); |
265 if (status == noErr) { | 234 if (status == noErr) { |
266 SetFrontProcess(&process); | 235 SetFrontProcess(&process); |
267 } else { | 236 } else { |
268 LOG(WARNING) << "Unable to get process for pid " << pid; | 237 LOG(WARNING) << "Unable to get process for pid " << pid; |
269 } | 238 } |
270 } | 239 } |
271 | 240 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); | 475 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); |
507 if (!item.get()) { | 476 if (!item.get()) { |
508 LOG(ERROR) << "Process launched at Login but can't access Login Item List."; | 477 LOG(ERROR) << "Process launched at Login but can't access Login Item List."; |
509 return false; | 478 return false; |
510 } | 479 } |
511 return IsHiddenLoginItem(item); | 480 return IsHiddenLoginItem(item); |
512 } | 481 } |
513 | 482 |
514 } // namespace mac | 483 } // namespace mac |
515 } // namespace base | 484 } // namespace base |
OLD | NEW |