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/manage_passwords_bubble_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_cocoa.h" |
6 | 6 |
7 #include "base/mac/scoped_block.h" | 7 #include "base/mac/scoped_block.h" |
8 #include "chrome/browser/ui/browser_dialogs.h" | 8 #include "chrome/browser/ui/browser_dialogs.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" |
| 11 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 12 #include "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h" |
10 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_controller.h" | 13 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_controller.h" |
| 14 #include "chrome/browser/ui/passwords/manage_passwords_icon.h" |
11 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 15 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
12 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
13 | 17 |
14 typedef void (^Callback)(void); | 18 typedef void (^Callback)(void); |
15 | 19 |
16 @interface ManagePasswordsBubbleCocoaNotificationBridge : NSObject { | 20 @interface ManagePasswordsBubbleCocoaNotificationBridge : NSObject { |
17 base::mac::ScopedBlock<Callback> callback_; | 21 base::mac::ScopedBlock<Callback> callback_; |
18 } | 22 } |
19 - (id)initWithCallback:(Callback)callback; | 23 - (id)initWithCallback:(Callback)callback; |
20 - (void)onClose; | 24 - (void)onClose; |
21 @end | 25 @end |
22 | 26 |
23 @implementation ManagePasswordsBubbleCocoaNotificationBridge | 27 @implementation ManagePasswordsBubbleCocoaNotificationBridge |
24 - (id)initWithCallback:(Callback)callback { | 28 - (id)initWithCallback:(Callback)callback { |
25 if ((self = [super init])) { | 29 if ((self = [super init])) { |
26 callback_.reset(callback, base::scoped_policy::RETAIN); | 30 callback_.reset(callback, base::scoped_policy::RETAIN); |
27 } | 31 } |
28 return self; | 32 return self; |
29 } | 33 } |
30 - (void)onClose { | 34 - (void)onClose { |
31 callback_.get()(); | 35 callback_.get()(); |
32 } | 36 } |
33 @end | 37 @end |
34 | 38 |
| 39 namespace chrome { |
| 40 void ShowManagePasswordsBubble(content::WebContents* webContents) { |
| 41 if (ManagePasswordsBubbleCocoa::instance()) { |
| 42 // The bubble is currently shown for some other tab. We should close it now |
| 43 // and open for |webContents|. |
| 44 ManagePasswordsBubbleCocoa::instance()->Close(); |
| 45 } |
| 46 ManagePasswordsUIController* controller = |
| 47 ManagePasswordsUIController::FromWebContents(webContents); |
| 48 NSWindow* window = webContents->GetTopLevelNativeWindow(); |
| 49 BrowserWindowController* bwc = |
| 50 [BrowserWindowController browserWindowControllerForWindow:window]; |
| 51 ManagePasswordsBubbleCocoa::ShowBubble( |
| 52 webContents, |
| 53 password_manager::ui::IsAutomaticDisplayState(controller->state()) |
| 54 ? ManagePasswordsBubble::AUTOMATIC |
| 55 : ManagePasswordsBubble::USER_ACTION, |
| 56 [bwc locationBarBridge]->manage_passwords_decoration()->icon()); |
| 57 } |
| 58 } // namespace chrome |
| 59 |
35 ManagePasswordsBubbleCocoa::ManagePasswordsBubbleCocoa( | 60 ManagePasswordsBubbleCocoa::ManagePasswordsBubbleCocoa( |
36 content::WebContents* webContents, | 61 content::WebContents* webContents, |
37 DisplayReason displayReason) | 62 DisplayReason displayReason, |
| 63 ManagePasswordsIcon* icon) |
38 : ManagePasswordsBubble(webContents, displayReason), | 64 : ManagePasswordsBubble(webContents, displayReason), |
| 65 icon_(icon), |
39 closing_(false), | 66 closing_(false), |
40 controller_(nil), | 67 controller_(nil), |
41 webContents_(webContents), | 68 webContents_(webContents), |
42 bridge_(nil) { | 69 bridge_(nil) { |
| 70 icon_->SetActive(true); |
43 } | 71 } |
44 | 72 |
45 ManagePasswordsBubbleCocoa::~ManagePasswordsBubbleCocoa() { | 73 ManagePasswordsBubbleCocoa::~ManagePasswordsBubbleCocoa() { |
46 [[NSNotificationCenter defaultCenter] removeObserver:bridge_]; | 74 [[NSNotificationCenter defaultCenter] removeObserver:bridge_]; |
47 // Clear the global instance pointer. | 75 // Clear the global instance pointer. |
48 bubble_ = NULL; | 76 bubble_ = NULL; |
| 77 icon_->SetActive(false); |
49 } | 78 } |
50 | 79 |
51 ManagePasswordsBubbleCocoa* ManagePasswordsBubbleCocoa::bubble_ = NULL; | 80 ManagePasswordsBubbleCocoa* ManagePasswordsBubbleCocoa::bubble_ = NULL; |
52 | 81 |
53 void ManagePasswordsBubbleCocoa::Show() { | 82 void ManagePasswordsBubbleCocoa::Show() { |
54 // Create and show the bubble. | 83 // Create and show the bubble. |
55 NSView* browserView = webContents_->GetNativeView(); | 84 NSView* browserView = webContents_->GetNativeView(); |
56 DCHECK(browserView); | 85 DCHECK(browserView); |
57 NSWindow* browserWindow = [browserView window]; | 86 NSWindow* browserWindow = [browserView window]; |
58 DCHECK(browserWindow); | 87 DCHECK(browserWindow); |
(...skipping 23 matching lines...) Expand all Loading... |
82 [controller_ close]; | 111 [controller_ close]; |
83 } | 112 } |
84 } | 113 } |
85 | 114 |
86 void ManagePasswordsBubbleCocoa::OnClose() { | 115 void ManagePasswordsBubbleCocoa::OnClose() { |
87 delete this; | 116 delete this; |
88 } | 117 } |
89 | 118 |
90 // static | 119 // static |
91 void ManagePasswordsBubbleCocoa::ShowBubble(content::WebContents* webContents, | 120 void ManagePasswordsBubbleCocoa::ShowBubble(content::WebContents* webContents, |
92 DisplayReason displayReason) { | 121 DisplayReason displayReason, |
| 122 ManagePasswordsIcon* icon) { |
93 if (bubble_) | 123 if (bubble_) |
94 return; | 124 return; |
95 bubble_ = new ManagePasswordsBubbleCocoa(webContents, displayReason); | 125 bubble_ = new ManagePasswordsBubbleCocoa(webContents, displayReason, icon); |
96 bubble_->Show(); | 126 bubble_->Show(); |
97 } | 127 } |
OLD | NEW |