1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import "ui/base/cocoa/nib_loading.h"
7 #include "base/mac/bundle_locations.h"
8 #include "base/mac/scoped_nsobject.h"
12 NSView* GetViewFromNib(NSString* name) {
13 base::scoped_nsobject<NSNib> nib(
14 [[NSNib alloc] initWithNibNamed:name
15 bundle:base::mac::FrameworkBundle()]);
20 BOOL success = [nib instantiateNibWithOwner:nil
21 topLevelObjects:&objects];
25 // When loading a nib manually (as opposed to using an NSWindowController or
26 // NSViewController), all the top-level objects need to be explicitly
28 // http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html#//apple_ref/doc/uid/10000051i-CH4-SW10
29 // for more information.
30 [objects makeObjectsPerformSelector:@selector(release)];
32 // For some strange reason, even nibs that appear to have but one top-level
33 // object often have more (an NSApplication, etc.). Filter out what isn't
35 for (NSView* view in objects) {
36 if (![view isKindOfClass:[NSView class]])
39 return [[view retain] autorelease];