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

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

Issue 473423005: Revert of 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: 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 | 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"
13 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_controller.h" 10 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_controller.h"
14 #include "chrome/browser/ui/passwords/manage_passwords_icon.h"
15 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" 11 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
16 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
17 13
18 typedef void (^Callback)(void); 14 typedef void (^Callback)(void);
19 15
20 @interface ManagePasswordsBubbleCocoaNotificationBridge : NSObject { 16 @interface ManagePasswordsBubbleCocoaNotificationBridge : NSObject {
21 base::mac::ScopedBlock<Callback> callback_; 17 base::mac::ScopedBlock<Callback> callback_;
22 } 18 }
23 - (id)initWithCallback:(Callback)callback; 19 - (id)initWithCallback:(Callback)callback;
24 - (void)onClose; 20 - (void)onClose;
25 @end 21 @end
26 22
27 @implementation ManagePasswordsBubbleCocoaNotificationBridge 23 @implementation ManagePasswordsBubbleCocoaNotificationBridge
28 - (id)initWithCallback:(Callback)callback { 24 - (id)initWithCallback:(Callback)callback {
29 if ((self = [super init])) { 25 if ((self = [super init])) {
30 callback_.reset(callback, base::scoped_policy::RETAIN); 26 callback_.reset(callback, base::scoped_policy::RETAIN);
31 } 27 }
32 return self; 28 return self;
33 } 29 }
34 - (void)onClose { 30 - (void)onClose {
35 callback_.get()(); 31 callback_.get()();
36 } 32 }
37 @end 33 @end
38 34
39 // static 35 // static
40 ManagePasswordsBubbleCocoa* ManagePasswordsBubbleCocoa::bubble_ = NULL; 36 ManagePasswordsBubbleCocoa* ManagePasswordsBubbleCocoa::bubble_ = NULL;
41 37
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
65 ManagePasswordsBubbleCocoa::ManagePasswordsBubbleCocoa( 38 ManagePasswordsBubbleCocoa::ManagePasswordsBubbleCocoa(
66 content::WebContents* webContents, 39 content::WebContents* webContents,
67 DisplayReason displayReason, 40 DisplayReason displayReason)
68 ManagePasswordsIcon* icon)
69 : ManagePasswordsBubble(webContents, displayReason), 41 : ManagePasswordsBubble(webContents, displayReason),
70 icon_(icon),
71 closing_(false), 42 closing_(false),
72 controller_(nil), 43 controller_(nil),
73 webContents_(webContents), 44 webContents_(webContents),
74 bridge_(nil) { 45 bridge_(nil) {
75 icon_->SetActive(true);
76 } 46 }
77 47
78 ManagePasswordsBubbleCocoa::~ManagePasswordsBubbleCocoa() { 48 ManagePasswordsBubbleCocoa::~ManagePasswordsBubbleCocoa() {
79 [[NSNotificationCenter defaultCenter] removeObserver:bridge_]; 49 [[NSNotificationCenter defaultCenter] removeObserver:bridge_];
80 // Clear the global instance pointer. 50 // Clear the global instance pointer.
81 bubble_ = NULL; 51 bubble_ = NULL;
82 icon_->SetActive(false);
83 } 52 }
84 53
85 void ManagePasswordsBubbleCocoa::Show() { 54 void ManagePasswordsBubbleCocoa::Show() {
86 // Create and show the bubble. 55 // Create and show the bubble.
87 NSView* browserView = webContents_->GetNativeView(); 56 NSView* browserView = webContents_->GetNativeView();
88 DCHECK(browserView); 57 DCHECK(browserView);
89 NSWindow* browserWindow = [browserView window]; 58 NSWindow* browserWindow = [browserView window];
90 DCHECK(browserWindow); 59 DCHECK(browserWindow);
91 controller_ = [[ManagePasswordsBubbleController alloc] 60 controller_ = [[ManagePasswordsBubbleController alloc]
92 initWithParentWindow:browserWindow 61 initWithParentWindow:browserWindow
(...skipping 21 matching lines...) Expand all
114 [controller_ close]; 83 [controller_ close];
115 } 84 }
116 } 85 }
117 86
118 void ManagePasswordsBubbleCocoa::OnClose() { 87 void ManagePasswordsBubbleCocoa::OnClose() {
119 delete this; 88 delete this;
120 } 89 }
121 90
122 // static 91 // static
123 void ManagePasswordsBubbleCocoa::ShowBubble(content::WebContents* webContents, 92 void ManagePasswordsBubbleCocoa::ShowBubble(content::WebContents* webContents,
124 DisplayReason displayReason, 93 DisplayReason displayReason) {
125 ManagePasswordsIcon* icon) {
126 if (bubble_) 94 if (bubble_)
127 return; 95 return;
128 bubble_ = new ManagePasswordsBubbleCocoa(webContents, displayReason, icon); 96 bubble_ = new ManagePasswordsBubbleCocoa(webContents, displayReason);
129 bubble_->Show(); 97 bubble_->Show();
130 } 98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698