| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "content/shell/shell_login_dialog.h" | 5 #include "content/shell/shell_login_dialog.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/bundle_locations.h" | 10 #include "base/mac/bundle_locations.h" |
| 11 #import "base/mac/cocoa_protocols.h" | 11 #import "base/mac/cocoa_protocols.h" |
| 12 #import "base/memory/scoped_nsobject.h" | 12 #import "base/memory/scoped_nsobject.h" |
| 13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #import "ui/base/cocoa/nib_loading.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 const int kUsernameFieldTag = 1; | 19 const int kUsernameFieldTag = 1; |
| 19 const int kPasswordFieldTag = 2; | 20 const int kPasswordFieldTag = 2; |
| 20 | 21 |
| 21 } // namespace | 22 } // namespace |
| 22 | 23 |
| 23 // Helper object that receives the notification that the dialog/sheet is | 24 // Helper object that receives the notification that the dialog/sheet is |
| 24 // going away. | 25 // going away. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 41 | 42 |
| 42 @implementation ShellLoginDialogHelper | 43 @implementation ShellLoginDialogHelper |
| 43 | 44 |
| 44 - (NSAlert*)alert { | 45 - (NSAlert*)alert { |
| 45 alert_.reset([[NSAlert alloc] init]); | 46 alert_.reset([[NSAlert alloc] init]); |
| 46 [alert_ setAccessoryView:[self accessoryView]]; | 47 [alert_ setAccessoryView:[self accessoryView]]; |
| 47 return alert_; | 48 return alert_; |
| 48 } | 49 } |
| 49 | 50 |
| 50 - (NSView*)accessoryView { | 51 - (NSView*)accessoryView { |
| 51 scoped_nsobject<NSNib> nib( | 52 NSView* accessory_view = ui::GetViewFromNib(@"HttpAuth"); |
| 52 [[NSNib alloc] initWithNibNamed:@"HttpAuth" | 53 if (!accessory_view) |
| 53 bundle:base::mac::FrameworkBundle()]); | |
| 54 if (!nib) | |
| 55 return nil; | 54 return nil; |
| 56 | 55 |
| 57 NSArray* objects; | 56 usernameField_ = [accessory_view viewWithTag:kUsernameFieldTag]; |
| 58 BOOL success = [nib instantiateNibWithOwner:nil | 57 passwordField_ = [accessory_view viewWithTag:kPasswordFieldTag]; |
| 59 topLevelObjects:&objects]; | 58 return accessory_view; |
| 60 if (!success) | |
| 61 return nil; | |
| 62 [objects makeObjectsPerformSelector:@selector(release)]; | |
| 63 | |
| 64 for (NSView* view in objects) { | |
| 65 if (![view isKindOfClass:[NSView class]]) | |
| 66 continue; | |
| 67 | |
| 68 usernameField_ = [view viewWithTag:kUsernameFieldTag]; | |
| 69 passwordField_ = [view viewWithTag:kPasswordFieldTag]; | |
| 70 return view; | |
| 71 } | |
| 72 | |
| 73 return nil; | |
| 74 } | 59 } |
| 75 | 60 |
| 76 - (void)focus { | 61 - (void)focus { |
| 77 [[alert_ window] makeFirstResponder:usernameField_]; | 62 [[alert_ window] makeFirstResponder:usernameField_]; |
| 78 } | 63 } |
| 79 | 64 |
| 80 - (void)alertDidEnd:(NSAlert*)alert | 65 - (void)alertDidEnd:(NSAlert*)alert |
| 81 returnCode:(int)returnCode | 66 returnCode:(int)returnCode |
| 82 contextInfo:(void*)contextInfo { | 67 contextInfo:(void*)contextInfo { |
| 83 if (returnCode == NSRunStoppedResponse) | 68 if (returnCode == NSRunStoppedResponse) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 [helper_ release]; | 114 [helper_ release]; |
| 130 helper_ = nil; | 115 helper_ = nil; |
| 131 } | 116 } |
| 132 | 117 |
| 133 void ShellLoginDialog::PlatformRequestCancelled() { | 118 void ShellLoginDialog::PlatformRequestCancelled() { |
| 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 135 [helper_ cancel]; | 120 [helper_ cancel]; |
| 136 } | 121 } |
| 137 | 122 |
| 138 } // namespace content | 123 } // namespace content |
| OLD | NEW |