Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/passwords/passwords_bubble_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_cocoa.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/mac/scoped_block.h" | 8 #include "base/mac/scoped_block.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 | 38 |
| 39 // static | 39 // static |
| 40 ManagePasswordsBubbleCocoa* ManagePasswordsBubbleCocoa::bubble_ = NULL; | 40 ManagePasswordsBubbleCocoa* ManagePasswordsBubbleCocoa::bubble_ = NULL; |
| 41 | 41 |
| 42 ManagePasswordsBubbleCocoa::ManagePasswordsBubbleCocoa( | 42 ManagePasswordsBubbleCocoa::ManagePasswordsBubbleCocoa( |
| 43 content::WebContents* webContents, | 43 content::WebContents* webContents, |
| 44 ManagePasswordsBubbleModel::DisplayReason displayReason, | 44 ManagePasswordsBubbleModel::DisplayReason displayReason, |
| 45 ManagePasswordsIcon* icon) | 45 ManagePasswordsIcon* icon) |
| 46 : model_(webContents, displayReason), | 46 : model_(webContents, displayReason), |
| 47 icon_(icon), | 47 icon_(icon), |
| 48 closing_(false), | |
| 49 controller_(nil), | 48 controller_(nil), |
| 50 webContents_(webContents), | 49 webContents_(webContents), |
| 51 bridge_(nil) { | 50 bridge_(nil) { |
| 52 DCHECK(icon_); | 51 DCHECK(icon_); |
| 53 icon_->SetActive(true); | 52 icon_->SetActive(true); |
| 54 } | 53 } |
| 55 | 54 |
| 56 ManagePasswordsBubbleCocoa::~ManagePasswordsBubbleCocoa() { | 55 ManagePasswordsBubbleCocoa::~ManagePasswordsBubbleCocoa() { |
| 57 [[NSNotificationCenter defaultCenter] removeObserver:bridge_]; | 56 [[NSNotificationCenter defaultCenter] removeObserver:bridge_]; |
| 58 // Clear the global bubble_ pointer. | 57 // Clear the global bubble_ pointer. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 81 initWithCallback:^{ | 80 initWithCallback:^{ |
| 82 OnClose(); | 81 OnClose(); |
| 83 }]); | 82 }]); |
| 84 [[NSNotificationCenter defaultCenter] | 83 [[NSNotificationCenter defaultCenter] |
| 85 addObserver:bridge_ | 84 addObserver:bridge_ |
| 86 selector:@selector(onClose) | 85 selector:@selector(onClose) |
| 87 name:NSWindowWillCloseNotification | 86 name:NSWindowWillCloseNotification |
| 88 object:[controller_ window]]; | 87 object:[controller_ window]]; |
| 89 } | 88 } |
| 90 | 89 |
| 91 void ManagePasswordsBubbleCocoa::Close() { | 90 void ManagePasswordsBubbleCocoa::Close(bool no_animation) { |
| 92 if (!closing_) { | 91 if (no_animation) { |
| 93 closing_ = true; | 92 InfoBubbleWindow* window = base::mac::ObjCCastStrict<InfoBubbleWindow>( |
| 94 [controller_ close]; | 93 [controller_ window]); |
| 94 [window setAllowedAnimations:info_bubble::kAnimateNone]; | |
| 95 } | 95 } |
| 96 [controller_ close]; | |
| 96 } | 97 } |
| 97 | 98 |
| 98 void ManagePasswordsBubbleCocoa::OnClose() { | 99 void ManagePasswordsBubbleCocoa::OnClose() { |
| 99 delete this; | 100 delete this; |
| 100 } | 101 } |
| 101 | 102 |
| 102 // static | 103 // static |
| 103 void ManagePasswordsBubbleCocoa::Show(content::WebContents* webContents, | 104 void ManagePasswordsBubbleCocoa::Show(content::WebContents* webContents, |
| 104 bool user_action) { | 105 bool user_action) { |
| 105 if (bubble_) { | 106 if (bubble_) { |
| 106 // The bubble is currently shown. It's to be reopened with the new content. | 107 // The bubble is currently shown. It's to be reopened with the new content. |
| 107 // Disable closing animation so that it's destroyed immediately. | 108 // Disable closing animation so that it's destroyed immediately. |
| 108 InfoBubbleWindow* window = base::mac::ObjCCastStrict<InfoBubbleWindow>( | 109 bubble_->Close(true); |
|
vabr (Chromium)
2016/07/28 16:59:12
If this is the only callsite, then why don't you h
vasilii
2016/07/28 17:11:37
It's not. There is also ManagePasswordsDecoration:
vabr (Chromium)
2016/07/28 17:14:17
But that one contains a Close call without argumen
| |
| 109 [bubble_->controller_ window]); | |
| 110 [window setAllowedAnimations:info_bubble::kAnimateNone]; | |
| 111 bubble_->Close(); | |
| 112 } | 110 } |
| 113 DCHECK(!bubble_); | 111 DCHECK(!bubble_); |
| 114 | 112 |
| 115 NSWindow* window = [webContents->GetNativeView() window]; | 113 NSWindow* window = [webContents->GetNativeView() window]; |
| 116 if (!window) { | 114 if (!window) { |
| 117 // The tab isn't active right now. | 115 // The tab isn't active right now. |
| 118 return; | 116 return; |
| 119 } | 117 } |
| 120 BrowserWindowController* bwc = | 118 BrowserWindowController* bwc = |
| 121 [BrowserWindowController browserWindowControllerForWindow:window]; | 119 [BrowserWindowController browserWindowControllerForWindow:window]; |
| 122 bubble_ = new ManagePasswordsBubbleCocoa( | 120 bubble_ = new ManagePasswordsBubbleCocoa( |
| 123 webContents, user_action ? ManagePasswordsBubbleModel::USER_ACTION | 121 webContents, user_action ? ManagePasswordsBubbleModel::USER_ACTION |
| 124 : ManagePasswordsBubbleModel::AUTOMATIC, | 122 : ManagePasswordsBubbleModel::AUTOMATIC, |
| 125 [bwc locationBarBridge]->manage_passwords_decoration()->icon()); | 123 [bwc locationBarBridge]->manage_passwords_decoration()->icon()); |
| 126 | 124 |
| 127 bubble_->Show(user_action); | 125 bubble_->Show(user_action); |
| 128 } | 126 } |
| OLD | NEW |