Skip to content

Commit

Permalink
mac: Use instantiateWithOwner: instead of deprecated instantiateNibWi…
Browse files Browse the repository at this point in the history
…thOwner:

The old API used to retain all objects in the nib.  The new one doesn't, so
do that manually.

No behavior change.

Similar to https://codereview.chromium.org/1836363002/

BUG=622481
TBR=avi

Review-Url: https://codereview.chromium.org/2116103002
Cr-Commit-Position: refs/heads/master@{#403550}
  • Loading branch information
nico authored and Commit bot committed Jul 1, 2016
1 parent c5a1c91 commit 17c246d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions base/mac/sdk_forward_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ BASE_EXPORT extern NSString* const NSAppearanceNameVibrantLight;
@property BOOL allowsExpansionToolTips;
@end

@interface NSNib (MountainLionSDK)
- (BOOL)instantiateWithOwner:(id)owner
topLevelObjects:(NSArray**)topLevelObjects;
@end

#endif // MAC_OS_X_VERSION_10_8

// Once Chrome no longer supports OSX 10.8, everything within this preprocessor
Expand Down
6 changes: 5 additions & 1 deletion chrome/browser/chrome_browser_main_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "base/mac/foundation_util.h"
#include "base/mac/mac_util.h"
#include "base/mac/scoped_nsobject.h"
#include "base/mac/sdk_forward_declarations.h"
#include "base/path_service.h"
#include "base/threading/thread_task_runner_handle.h"
#import "chrome/browser/app_controller_mac.h"
Expand Down Expand Up @@ -149,7 +150,10 @@ void EnsureMetadataNeverIndexFile(const base::FilePath& user_data_dir) {
bundle:base::mac::FrameworkBundle()]);
// TODO(viettrungluu): crbug.com/20504 - This currently leaks, so if you
// change this, you'll probably need to change the Valgrind suppression.
[nib instantiateNibWithOwner:NSApp topLevelObjects:nil];
NSArray* top_level_objects = nil;
[nib instantiateWithOwner:NSApp topLevelObjects:&top_level_objects];
for (NSObject* object : top_level_objects)
[object retain];
// Make sure the app controller has been created.
DCHECK([NSApp delegate]);
}
Expand Down
6 changes: 5 additions & 1 deletion content/shell/browser/shell_browser_main_parts_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "base/mac/bundle_locations.h"
#include "base/mac/scoped_nsobject.h"
#include "base/mac/sdk_forward_declarations.h"
#include "content/shell/browser/shell_application_mac.h"

namespace content {
Expand All @@ -19,7 +20,10 @@
base::scoped_nsobject<NSNib> nib(
[[NSNib alloc] initWithNibNamed:@"MainMenu"
bundle:base::mac::FrameworkBundle()]);
[nib instantiateNibWithOwner:NSApp topLevelObjects:nil];
NSArray* top_level_objects = nil;
[nib instantiateWithOwner:NSApp topLevelObjects:nil];
for (NSObject* object : top_level_objects)
[object retain];
}

} // namespace content
6 changes: 1 addition & 5 deletions ui/base/cocoa/nib_loading.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@

#include "base/mac/bundle_locations.h"
#include "base/mac/scoped_nsobject.h"

@interface NSNib (MountainLionSDK)
- (BOOL)instantiateWithOwner:(nullable id)owner
topLevelObjects:(NSArray* __nonnull* __nullable)topLevelObjects;
@end
#include "base/mac/sdk_forward_declarations.h"

namespace ui {

Expand Down

0 comments on commit 17c246d

Please sign in to comment.