| 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 |
| 90 void ManagePasswordsBubbleCocoa::Close(bool no_animation) { |
| 91 if (no_animation) { |
| 92 InfoBubbleWindow* window = base::mac::ObjCCastStrict<InfoBubbleWindow>( |
| 93 [controller_ window]); |
| 94 [window setAllowedAnimations:info_bubble::kAnimateNone]; |
| 95 } |
| 96 [controller_ close]; |
| 97 } |
| 98 |
| 91 void ManagePasswordsBubbleCocoa::Close() { | 99 void ManagePasswordsBubbleCocoa::Close() { |
| 92 if (!closing_) { | 100 Close(false); |
| 93 closing_ = true; | |
| 94 [controller_ close]; | |
| 95 } | |
| 96 } | 101 } |
| 97 | 102 |
| 98 void ManagePasswordsBubbleCocoa::OnClose() { | 103 void ManagePasswordsBubbleCocoa::OnClose() { |
| 99 delete this; | 104 delete this; |
| 100 } | 105 } |
| 101 | 106 |
| 102 // static | 107 // static |
| 103 void ManagePasswordsBubbleCocoa::Show(content::WebContents* webContents, | 108 void ManagePasswordsBubbleCocoa::Show(content::WebContents* webContents, |
| 104 bool user_action) { | 109 bool user_action) { |
| 105 if (bubble_) { | 110 if (bubble_) { |
| 106 // The bubble is currently shown. It's to be reopened with the new content. | 111 // The bubble is currently shown. It's to be reopened with the new content. |
| 107 // Disable closing animation so that it's destroyed immediately. | 112 // Disable closing animation so that it's destroyed immediately. |
| 108 InfoBubbleWindow* window = base::mac::ObjCCastStrict<InfoBubbleWindow>( | 113 bubble_->Close(true); |
| 109 [bubble_->controller_ window]); | |
| 110 [window setAllowedAnimations:info_bubble::kAnimateNone]; | |
| 111 bubble_->Close(); | |
| 112 } | 114 } |
| 113 DCHECK(!bubble_); | 115 DCHECK(!bubble_); |
| 114 | 116 |
| 115 NSWindow* window = [webContents->GetNativeView() window]; | 117 NSWindow* window = [webContents->GetNativeView() window]; |
| 116 if (!window) { | 118 if (!window) { |
| 117 // The tab isn't active right now. | 119 // The tab isn't active right now. |
| 118 return; | 120 return; |
| 119 } | 121 } |
| 120 BrowserWindowController* bwc = | 122 BrowserWindowController* bwc = |
| 121 [BrowserWindowController browserWindowControllerForWindow:window]; | 123 [BrowserWindowController browserWindowControllerForWindow:window]; |
| 122 bubble_ = new ManagePasswordsBubbleCocoa( | 124 bubble_ = new ManagePasswordsBubbleCocoa( |
| 123 webContents, user_action ? ManagePasswordsBubbleModel::USER_ACTION | 125 webContents, user_action ? ManagePasswordsBubbleModel::USER_ACTION |
| 124 : ManagePasswordsBubbleModel::AUTOMATIC, | 126 : ManagePasswordsBubbleModel::AUTOMATIC, |
| 125 [bwc locationBarBridge]->manage_passwords_decoration()->icon()); | 127 [bwc locationBarBridge]->manage_passwords_decoration()->icon()); |
| 126 | 128 |
| 127 bubble_->Show(user_action); | 129 bubble_->Show(user_action); |
| 128 } | 130 } |
| OLD | NEW |