| 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 #import "chrome/browser/ui/cocoa/login_prompt_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/login_prompt_cocoa.h" |
| 6 | 6 |
| 7 #include "base/mac/bundle_locations.h" | 7 #include "base/mac/bundle_locations.h" |
| 8 #include "base/mac/mac_util.h" | 8 #include "base/mac/mac_util.h" |
| 9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 class LoginHandlerMac : public LoginHandler, | 36 class LoginHandlerMac : public LoginHandler, |
| 37 public ConstrainedWindowMacDelegate { | 37 public ConstrainedWindowMacDelegate { |
| 38 public: | 38 public: |
| 39 LoginHandlerMac(net::AuthChallengeInfo* auth_info, net::URLRequest* request) | 39 LoginHandlerMac(net::AuthChallengeInfo* auth_info, net::URLRequest* request) |
| 40 : LoginHandler(auth_info, request) { | 40 : LoginHandler(auth_info, request) { |
| 41 } | 41 } |
| 42 | 42 |
| 43 // LoginModelObserver implementation. | 43 // LoginModelObserver implementation. |
| 44 virtual void OnAutofillDataAvailable( | 44 virtual void OnAutofillDataAvailable( |
| 45 const base::string16& username, | 45 const base::string16& username, |
| 46 const base::string16& password) OVERRIDE { | 46 const base::string16& password) override { |
| 47 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 47 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 48 | 48 |
| 49 [sheet_controller_ autofillLogin:base::SysUTF16ToNSString(username) | 49 [sheet_controller_ autofillLogin:base::SysUTF16ToNSString(username) |
| 50 password:base::SysUTF16ToNSString(password)]; | 50 password:base::SysUTF16ToNSString(password)]; |
| 51 } | 51 } |
| 52 virtual void OnLoginModelDestroying() OVERRIDE {} | 52 virtual void OnLoginModelDestroying() override {} |
| 53 | 53 |
| 54 // LoginHandler: | 54 // LoginHandler: |
| 55 virtual void BuildViewForPasswordManager( | 55 virtual void BuildViewForPasswordManager( |
| 56 password_manager::PasswordManager* manager, | 56 password_manager::PasswordManager* manager, |
| 57 const base::string16& explanation) OVERRIDE { | 57 const base::string16& explanation) override { |
| 58 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 58 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 59 | 59 |
| 60 sheet_controller_.reset( | 60 sheet_controller_.reset( |
| 61 [[LoginHandlerSheet alloc] initWithLoginHandler:this]); | 61 [[LoginHandlerSheet alloc] initWithLoginHandler:this]); |
| 62 | 62 |
| 63 SetModel(manager); | 63 SetModel(manager); |
| 64 | 64 |
| 65 [sheet_controller_ setExplanation:base::SysUTF16ToNSString(explanation)]; | 65 [sheet_controller_ setExplanation:base::SysUTF16ToNSString(explanation)]; |
| 66 | 66 |
| 67 // Scary thread safety note: This can potentially be called *after* SetAuth | 67 // Scary thread safety note: This can potentially be called *after* SetAuth |
| 68 // or CancelAuth (say, if the request was cancelled before the UI thread got | 68 // or CancelAuth (say, if the request was cancelled before the UI thread got |
| 69 // control). However, that's OK since any UI interaction in those functions | 69 // control). However, that's OK since any UI interaction in those functions |
| 70 // will occur via an InvokeLater on the UI thread, which is guaranteed | 70 // will occur via an InvokeLater on the UI thread, which is guaranteed |
| 71 // to happen after this is called (since this was InvokeLater'd first). | 71 // to happen after this is called (since this was InvokeLater'd first). |
| 72 WebContents* requesting_contents = GetWebContentsForLogin(); | 72 WebContents* requesting_contents = GetWebContentsForLogin(); |
| 73 DCHECK(requesting_contents); | 73 DCHECK(requesting_contents); |
| 74 | 74 |
| 75 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( | 75 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( |
| 76 [[CustomConstrainedWindowSheet alloc] | 76 [[CustomConstrainedWindowSheet alloc] |
| 77 initWithCustomWindow:[sheet_controller_ window]]); | 77 initWithCustomWindow:[sheet_controller_ window]]); |
| 78 constrained_window_.reset(new ConstrainedWindowMac( | 78 constrained_window_.reset(new ConstrainedWindowMac( |
| 79 this, requesting_contents, sheet)); | 79 this, requesting_contents, sheet)); |
| 80 | 80 |
| 81 NotifyAuthNeeded(); | 81 NotifyAuthNeeded(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 virtual void CloseDialog() OVERRIDE { | 84 virtual void CloseDialog() override { |
| 85 // The hosting dialog may have been freed. | 85 // The hosting dialog may have been freed. |
| 86 if (constrained_window_) | 86 if (constrained_window_) |
| 87 constrained_window_->CloseWebContentsModalDialog(); | 87 constrained_window_->CloseWebContentsModalDialog(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Overridden from ConstrainedWindowMacDelegate: | 90 // Overridden from ConstrainedWindowMacDelegate: |
| 91 virtual void OnConstrainedWindowClosed( | 91 virtual void OnConstrainedWindowClosed( |
| 92 ConstrainedWindowMac* window) OVERRIDE { | 92 ConstrainedWindowMac* window) override { |
| 93 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 93 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 94 SetModel(NULL); | 94 SetModel(NULL); |
| 95 ReleaseSoon(); | 95 ReleaseSoon(); |
| 96 | 96 |
| 97 constrained_window_.reset(); | 97 constrained_window_.reset(); |
| 98 sheet_controller_.reset(); | 98 sheet_controller_.reset(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void OnLoginPressed(const base::string16& username, | 101 void OnLoginPressed(const base::string16& username, |
| 102 const base::string16& password) { | 102 const base::string16& password) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 // Resize the text field. | 184 // Resize the text field. |
| 185 CGFloat windowDelta = [GTMUILocalizerAndLayoutTweaker | 185 CGFloat windowDelta = [GTMUILocalizerAndLayoutTweaker |
| 186 sizeToFitFixedWidthTextField:explanationField_]; | 186 sizeToFitFixedWidthTextField:explanationField_]; |
| 187 | 187 |
| 188 NSRect newFrame = [[self window] frame]; | 188 NSRect newFrame = [[self window] frame]; |
| 189 newFrame.size.height += windowDelta; | 189 newFrame.size.height += windowDelta; |
| 190 [[self window] setFrame:newFrame display:NO]; | 190 [[self window] setFrame:newFrame display:NO]; |
| 191 } | 191 } |
| 192 | 192 |
| 193 @end | 193 @end |
| OLD | NEW |