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

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

Issue 505123002: Revert "Revert of Hook up the Mac password bubble to the browser and add browser tests. (patchset #… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix include for real this time Created 6 years, 3 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
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 DCHECK(icon_);
76 icon_->SetActive(true);
46 } 77 }
47 78
48 ManagePasswordsBubbleCocoa::~ManagePasswordsBubbleCocoa() { 79 ManagePasswordsBubbleCocoa::~ManagePasswordsBubbleCocoa() {
49 [[NSNotificationCenter defaultCenter] removeObserver:bridge_]; 80 [[NSNotificationCenter defaultCenter] removeObserver:bridge_];
50 // Clear the global instance pointer. 81 // Clear the global instance pointer.
51 bubble_ = NULL; 82 bubble_ = NULL;
83 if (icon_)
84 icon_->SetActive(false);
52 } 85 }
53 86
54 void ManagePasswordsBubbleCocoa::Show() { 87 void ManagePasswordsBubbleCocoa::Show() {
55 // Create and show the bubble. 88 // Create and show the bubble.
56 NSView* browserView = webContents_->GetNativeView(); 89 NSView* browserView = webContents_->GetNativeView();
57 DCHECK(browserView); 90 DCHECK(browserView);
58 NSWindow* browserWindow = [browserView window]; 91 NSWindow* browserWindow = [browserView window];
59 DCHECK(browserWindow); 92 DCHECK(browserWindow);
60 controller_ = [[ManagePasswordsBubbleController alloc] 93 controller_ = [[ManagePasswordsBubbleController alloc]
61 initWithParentWindow:browserWindow 94 initWithParentWindow:browserWindow
(...skipping 21 matching lines...) Expand all
83 [controller_ close]; 116 [controller_ close];
84 } 117 }
85 } 118 }
86 119
87 void ManagePasswordsBubbleCocoa::OnClose() { 120 void ManagePasswordsBubbleCocoa::OnClose() {
88 delete this; 121 delete this;
89 } 122 }
90 123
91 // static 124 // static
92 void ManagePasswordsBubbleCocoa::ShowBubble(content::WebContents* webContents, 125 void ManagePasswordsBubbleCocoa::ShowBubble(content::WebContents* webContents,
93 DisplayReason displayReason) { 126 DisplayReason displayReason,
127 ManagePasswordsIcon* icon) {
94 if (bubble_) 128 if (bubble_)
95 return; 129 return;
96 bubble_ = new ManagePasswordsBubbleCocoa(webContents, displayReason); 130 bubble_ = new ManagePasswordsBubbleCocoa(webContents, displayReason, icon);
97 bubble_->Show(); 131 bubble_->Show();
98 } 132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698