OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h " | 5 #include "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h " |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 web_contents_(std::move(web_contents)), | 60 web_contents_(std::move(web_contents)), |
61 wait_for_size_(wait_for_size), | 61 wait_for_size_(wait_for_size), |
62 host_web_contents_(host_web_contents), | 62 host_web_contents_(host_web_contents), |
63 window_frame_(frame) { | 63 window_frame_(frame) { |
64 if (!wait_for_size_) | 64 if (!wait_for_size_) |
65 DisplayModal(); | 65 DisplayModal(); |
66 } | 66 } |
67 | 67 |
68 SigninViewControllerDelegateMac::~SigninViewControllerDelegateMac() {} | 68 SigninViewControllerDelegateMac::~SigninViewControllerDelegateMac() {} |
69 | 69 |
70 void SigninViewControllerDelegateMac::OnConstrainedWindowClosed( | |
71 ConstrainedWindowMac* window) { | |
72 ResetSigninViewControllerDelegate(); | |
73 delete this; | |
74 } | |
75 | |
76 // static | 70 // static |
77 std::unique_ptr<content::WebContents> | 71 std::unique_ptr<content::WebContents> |
78 SigninViewControllerDelegateMac::CreateGaiaWebContents( | 72 SigninViewControllerDelegateMac::CreateGaiaWebContents( |
79 content::WebContentsDelegate* delegate, | 73 content::WebContentsDelegate* delegate, |
80 profiles::BubbleViewMode mode, | 74 profiles::BubbleViewMode mode, |
81 Profile* profile, | 75 Profile* profile, |
82 signin_metrics::AccessPoint access_point) { | 76 signin_metrics::AccessPoint access_point) { |
83 GURL url = | 77 GURL url = |
84 signin::GetSigninURLFromBubbleViewMode(profile, mode, access_point); | 78 signin::GetSigninURLFromBubbleViewMode(profile, mode, access_point); |
85 | 79 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | 132 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
139 | 133 |
140 NSView* webview = web_contents->GetNativeView(); | 134 NSView* webview = web_contents->GetNativeView(); |
141 [webview | 135 [webview |
142 setFrameSize:NSMakeSize(kModalDialogWidth, kSigninErrorDialogHeight)]; | 136 setFrameSize:NSMakeSize(kModalDialogWidth, kSigninErrorDialogHeight)]; |
143 | 137 |
144 return web_contents; | 138 return web_contents; |
145 } | 139 } |
146 | 140 |
147 void SigninViewControllerDelegateMac::PerformClose() { | 141 void SigninViewControllerDelegateMac::PerformClose() { |
148 if (constrained_window_.get()) | 142 if (window_.get()) { |
149 constrained_window_->CloseWebContentsModalDialog(); | 143 [host_web_contents_->GetTopLevelNativeWindow() endSheet:window_]; |
144 window_.reset(nil); | |
145 ResetSigninViewControllerDelegate(); | |
msarda
2017/01/10 14:16:13
I think it would be better to use a DeleteSoon her
jlebel
2017/01/10 15:43:35
As we talked offline, this would require to move t
| |
146 delete this; | |
147 } | |
150 } | 148 } |
151 | 149 |
152 void SigninViewControllerDelegateMac::ResizeNativeView(int height) { | 150 void SigninViewControllerDelegateMac::ResizeNativeView(int height) { |
153 if (wait_for_size_) { | 151 if (wait_for_size_) { |
154 [window_.get().contentView | 152 [window_.get().contentView |
155 setFrameSize:NSMakeSize(kModalDialogWidth, | 153 setFrameSize:NSMakeSize(kModalDialogWidth, |
156 height)]; | 154 height)]; |
157 window_frame_.size = NSMakeSize(kModalDialogWidth, height); | 155 window_frame_.size = NSMakeSize(kModalDialogWidth, height); |
158 DisplayModal(); | 156 DisplayModal(); |
159 } | 157 } |
160 } | 158 } |
161 | 159 |
162 void SigninViewControllerDelegateMac::DisplayModal() { | 160 void SigninViewControllerDelegateMac::DisplayModal() { |
163 window_.reset( | 161 window_.reset( |
164 [[ConstrainedWindowCustomWindow alloc] | 162 [[ConstrainedWindowCustomWindow alloc] |
165 initWithContentRect:window_frame_]); | 163 initWithContentRect:window_frame_]); |
166 | 164 |
167 window_.get().contentView = web_contents_->GetNativeView(); | 165 window_.get().contentView = web_contents_->GetNativeView(); |
168 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( | 166 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( |
169 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window_]); | 167 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window_]); |
170 constrained_window_ = | 168 [host_web_contents_->GetTopLevelNativeWindow() beginSheet:window_ |
171 CreateAndShowWebModalDialogMac(this, host_web_contents_, sheet); | 169 completionHandler:nil]; |
172 } | 170 } |
173 | 171 |
174 void SigninViewControllerDelegateMac::HandleKeyboardEvent( | 172 void SigninViewControllerDelegateMac::HandleKeyboardEvent( |
175 content::WebContents* source, | 173 content::WebContents* source, |
176 const content::NativeWebKeyboardEvent& event) { | 174 const content::NativeWebKeyboardEvent& event) { |
177 int chrome_command_id = [BrowserWindowUtils getCommandId:event]; | 175 int chrome_command_id = [BrowserWindowUtils getCommandId:event]; |
178 bool can_handle_command = [BrowserWindowUtils isTextEditingEvent:event] || | 176 bool can_handle_command = [BrowserWindowUtils isTextEditingEvent:event] || |
179 chrome_command_id == IDC_CLOSE_WINDOW || | 177 chrome_command_id == IDC_CLOSE_WINDOW || |
180 chrome_command_id == IDC_EXIT; | 178 chrome_command_id == IDC_EXIT; |
181 if ([BrowserWindowUtils shouldHandleKeyboardEvent:event] && | 179 if ([BrowserWindowUtils shouldHandleKeyboardEvent:event] && |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 SigninViewControllerDelegate::CreateSigninErrorDelegate( | 218 SigninViewControllerDelegate::CreateSigninErrorDelegate( |
221 SigninViewController* signin_view_controller, | 219 SigninViewController* signin_view_controller, |
222 Browser* browser) { | 220 Browser* browser) { |
223 return new SigninViewControllerDelegateMac( | 221 return new SigninViewControllerDelegateMac( |
224 signin_view_controller, | 222 signin_view_controller, |
225 SigninViewControllerDelegateMac::CreateSigninErrorWebContents( | 223 SigninViewControllerDelegateMac::CreateSigninErrorWebContents( |
226 browser->profile()), | 224 browser->profile()), |
227 browser->tab_strip_model()->GetActiveWebContents(), | 225 browser->tab_strip_model()->GetActiveWebContents(), |
228 NSMakeRect(0, 0, kModalDialogWidth, kSigninErrorDialogHeight), true); | 226 NSMakeRect(0, 0, kModalDialogWidth, kSigninErrorDialogHeight), true); |
229 } | 227 } |
OLD | NEW |