Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(885)

Side by Side Diff: chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_cocoa.mm

Issue 444603003: Hook up the Mac password bubble to the browser and add browser tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix views build Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
35 // static 39 // static
36 ManagePasswordsBubbleCocoa* ManagePasswordsBubbleCocoa::bubble_ = NULL; 40 ManagePasswordsBubbleCocoa* ManagePasswordsBubbleCocoa::bubble_ = NULL;
37 41
42 namespace chrome {
43 void ShowManagePasswordsBubble(content::WebContents* webContents) {
44 ManagePasswordsBubbleCocoa* instance = ManagePasswordsBubbleCocoa::instance();
45 if (instance && (instance->webContents_ != webContents)) {
46 // The bubble is currently shown for some other tab. We should close it now
47 // and open for |webContents|.
48 instance->Close();
49 }
50
51 ManagePasswordsUIController* controller =
52 ManagePasswordsUIController::FromWebContents(webContents);
53 NSWindow* window = webContents->GetTopLevelNativeWindow();
54 BrowserWindowController* bwc =
55 [BrowserWindowController browserWindowControllerForWindow:window];
56 ManagePasswordsBubbleCocoa::ShowBubble(
57 webContents,
58 password_manager::ui::IsAutomaticDisplayState(controller->state())
59 ? ManagePasswordsBubble::AUTOMATIC
60 : ManagePasswordsBubble::USER_ACTION,
61 [bwc locationBarBridge]->manage_passwords_decoration()->icon());
62 }
63 } // namespace chrome
64
38 ManagePasswordsBubbleCocoa::ManagePasswordsBubbleCocoa( 65 ManagePasswordsBubbleCocoa::ManagePasswordsBubbleCocoa(
39 content::WebContents* webContents, 66 content::WebContents* webContents,
40 DisplayReason displayReason) 67 DisplayReason displayReason,
68 ManagePasswordsIcon* icon)
41 : ManagePasswordsBubble(webContents, displayReason), 69 : ManagePasswordsBubble(webContents, displayReason),
70 icon_(icon),
42 closing_(false), 71 closing_(false),
43 controller_(nil), 72 controller_(nil),
44 webContents_(webContents), 73 webContents_(webContents),
45 bridge_(nil) { 74 bridge_(nil) {
75 icon_->SetActive(true);
46 } 76 }
47 77
48 ManagePasswordsBubbleCocoa::~ManagePasswordsBubbleCocoa() { 78 ManagePasswordsBubbleCocoa::~ManagePasswordsBubbleCocoa() {
49 [[NSNotificationCenter defaultCenter] removeObserver:bridge_]; 79 [[NSNotificationCenter defaultCenter] removeObserver:bridge_];
50 // Clear the global instance pointer. 80 // Clear the global instance pointer.
51 bubble_ = NULL; 81 bubble_ = NULL;
82 icon_->SetActive(false);
52 } 83 }
53 84
54 void ManagePasswordsBubbleCocoa::Show() { 85 void ManagePasswordsBubbleCocoa::Show() {
55 // Create and show the bubble. 86 // Create and show the bubble.
56 NSView* browserView = webContents_->GetNativeView(); 87 NSView* browserView = webContents_->GetNativeView();
57 DCHECK(browserView); 88 DCHECK(browserView);
58 NSWindow* browserWindow = [browserView window]; 89 NSWindow* browserWindow = [browserView window];
59 DCHECK(browserWindow); 90 DCHECK(browserWindow);
60 controller_ = [[ManagePasswordsBubbleController alloc] 91 controller_ = [[ManagePasswordsBubbleController alloc]
61 initWithParentWindow:browserWindow 92 initWithParentWindow:browserWindow
(...skipping 21 matching lines...) Expand all
83 [controller_ close]; 114 [controller_ close];
84 } 115 }
85 } 116 }
86 117
87 void ManagePasswordsBubbleCocoa::OnClose() { 118 void ManagePasswordsBubbleCocoa::OnClose() {
88 delete this; 119 delete this;
89 } 120 }
90 121
91 // static 122 // static
92 void ManagePasswordsBubbleCocoa::ShowBubble(content::WebContents* webContents, 123 void ManagePasswordsBubbleCocoa::ShowBubble(content::WebContents* webContents,
93 DisplayReason displayReason) { 124 DisplayReason displayReason,
125 ManagePasswordsIcon* icon) {
94 if (bubble_) 126 if (bubble_)
95 return; 127 return;
96 bubble_ = new ManagePasswordsBubbleCocoa(webContents, displayReason); 128 bubble_ = new ManagePasswordsBubbleCocoa(webContents, displayReason, icon);
97 bubble_->Show(); 129 bubble_->Show();
98 } 130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698