Index: content/browser/web_contents/web_contents_view_mac.mm |
diff --git a/content/browser/web_contents/web_contents_view_mac.mm b/content/browser/web_contents/web_contents_view_mac.mm |
index 42348a97bca9cd9c2c15006740f5fcafc521d603..20c97b8fda21f15ca37dbfccc2c575e172505fdf 100644 |
--- a/content/browser/web_contents/web_contents_view_mac.mm |
+++ b/content/browser/web_contents/web_contents_view_mac.mm |
@@ -8,7 +8,9 @@ |
#include <string> |
+#import "base/mac/mac_util.h" |
#import "base/mac/scoped_sending_event.h" |
+#include "base/mac/sdk_forward_declarations.h" |
#include "base/message_loop/message_loop.h" |
#import "base/message_loop/message_pump_mac.h" |
#include "content/browser/frame_host/popup_menu_helper_mac.h" |
@@ -594,4 +596,45 @@ void WebContentsViewMac::CloseTab() { |
[subview setFrame:self.bounds]; |
} |
+- (void)viewWillMoveToWindow:(NSWindow*)newWindow { |
+ NSWindow* oldWindow = [self window]; |
+ |
+ NSNotificationCenter* notificationCenter = |
+ [NSNotificationCenter defaultCenter]; |
+ |
+ // Occlusion notification APIs are new in Mavericks. |
+ bool supportsOcclusionAPIs = base::mac::IsOSMavericksOrLater(); |
+ |
+ if (supportsOcclusionAPIs) { |
+ if (oldWindow) { |
+ [notificationCenter |
+ removeObserver:self |
+ name:NSWindowDidChangeOcclusionStateNotification |
+ object:oldWindow]; |
+ } |
+ if (newWindow) { |
+ [notificationCenter |
+ addObserver:self |
+ selector:@selector(windowChangedOcclusionState:) |
+ name:NSWindowDidChangeOcclusionStateNotification |
+ object:newWindow]; |
+ } |
+ } |
+} |
+ |
+- (void)windowChangedOcclusionState:(NSNotification*)notification { |
+ DCHECK(base::mac::IsOSMavericksOrLater()); |
+ NSWindow* window = [notification object]; |
+ WebContentsImpl* webContents = [self webContents]; |
+ if (window && webContents) { |
+ if ([window occlusionState] & NSWindowOcclusionStateVisible) { |
+ if (!webContents->should_normally_be_visible()) |
+ webContents->WasShown(); |
+ } else { |
+ if (webContents->should_normally_be_visible()) |
+ webContents->WasHidden(); |
+ } |
+ } |
+} |
+ |
@end |