Mac: Fix crash on older 10.7 versions when building with the 10.7 SDK (issue #1026).

git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1547@1352 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2013-07-30 15:48:11 +00:00
parent c69f78fef2
commit 545db3266f
2 changed files with 43 additions and 4 deletions

View File

@ -63,7 +63,7 @@ patches = [
'path': '../content/common/',
},
{
# Fix crash on 10.6 when building with the 10.7 SDK
# Fix crash on 10.6 and older 10.7 versions when building with the 10.7 SDK.
# http://code.google.com/p/chromiumembedded/issues/detail?id=1026
'name': 'renderer_host_1026',
'path': '../content/browser/renderer_host/',

View File

@ -2,14 +2,53 @@ Index: render_widget_host_view_mac.mm
===================================================================
--- render_widget_host_view_mac.mm (revision 211613)
+++ render_widget_host_view_mac.mm (working copy)
@@ -2380,13 +2380,20 @@
@@ -4,6 +4,7 @@
#include "content/browser/renderer_host/render_widget_host_view_mac.h"
+#import <objc/runtime.h>
#include <QuartzCore/QuartzCore.h>
#include "base/bind.h"
@@ -129,6 +130,29 @@
return modifiers;
}
+// This method will return YES for OS X versions 10.7.3 and later, and NO
+// otherwise.
+// Used to prevent a crash when building with the 10.7 SDK and accessing the
+// notification below. See: http://crbug.com/260595.
+static BOOL SupportsBackingPropertiesChangedNotification() {
+ // windowDidChangeBackingProperties: method has been added to the
+ // NSWindowDelegate protocol in 10.7.3, at the same time as the
+ // NSWindowDidChangeBackingPropertiesNotification notification was added.
+ // If the protocol contains this method description, the notification should
+ // be supported as well.
+ Protocol* windowDelegateProtocol = NSProtocolFromString(@"NSWindowDelegate");
+ struct objc_method_description methodDescription =
+ protocol_getMethodDescription(
+ windowDelegateProtocol,
+ @selector(windowDidChangeBackingProperties:),
+ NO,
+ YES);
+
+ // If the protocol does not contain the method, the returned method
+ // description is {NULL, NULL}
+ return methodDescription.name != NULL || methodDescription.types != NULL;
+}
+
static float ScaleFactor(NSView* view) {
return ui::GetScaleFactorScale(ui::GetScaleFactorForNativeView(view));
}
@@ -2380,13 +2404,21 @@
NSNotificationCenter* notificationCenter =
[NSNotificationCenter defaultCenter];
+
+ // Backing property notifications crash on 10.6 when building with the 10.7
+ // SDK, see http://crbug.com/260595.
+ BOOL supportsBackingPropertiesNotification = base::mac::IsOSLionOrLater();
+ static BOOL supportsBackingPropertiesNotification =
+ SupportsBackingPropertiesChangedNotification();
+
if (oldWindow) {
+ if (supportsBackingPropertiesNotification) {
@ -27,7 +66,7 @@ Index: render_widget_host_view_mac.mm
name:NSWindowDidMoveNotification
object:oldWindow];
[notificationCenter
@@ -2395,13 +2402,15 @@
@@ -2395,13 +2427,15 @@
object:oldWindow];
}
if (newWindow) {