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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_controller.h"
7 #include "base/mac/scoped_nsobject.h"
8 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
9 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
10 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
11 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_manage_view_controller.h"
12 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
13 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_account_chooser_view_controller.h"
14 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_blacklist_view_controller.h"
15 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_confirmation_view_controller.h"
16 #include "ui/base/cocoa/window_size_constants.h"
18 @interface ManagePasswordsBubbleController ()
19 // Updates the content view controller according to the current state.
23 @implementation ManagePasswordsBubbleController
24 - (id)initWithParentWindow:(NSWindow*)parentWindow
25 model:(ManagePasswordsBubbleModel*)model {
26 NSRect contentRect = ui::kWindowSizeDeterminedLater;
27 base::scoped_nsobject<InfoBubbleWindow> window(
28 [[InfoBubbleWindow alloc] initWithContentRect:contentRect
29 styleMask:NSBorderlessWindowMask
30 backing:NSBackingStoreBuffered
32 if ((self = [super initWithWindow:window
33 parentWindow:parentWindow
34 anchoredAt:NSZeroPoint])) {
41 - (void)showWindow:(id)sender {
43 [super showWindow:sender];
47 [currentController_ bubbleWillDisappear];
52 // Find the next view controller.
53 currentController_.reset();
54 if (model_->state() == password_manager::ui::PENDING_PASSWORD_STATE) {
55 currentController_.reset(
56 [[ManagePasswordsBubblePendingViewController alloc]
59 } else if (model_->state() == password_manager::ui::CONFIRMATION_STATE) {
60 currentController_.reset(
61 [[ManagePasswordsBubbleConfirmationViewController alloc]
64 } else if (model_->state() == password_manager::ui::MANAGE_STATE) {
65 currentController_.reset([[ManagePasswordsBubbleManageViewController alloc]
68 } else if (model_->state() == password_manager::ui::BLACKLIST_STATE) {
69 currentController_.reset(
70 [[ManagePasswordsBubbleBlacklistViewController alloc]
73 } else if (model_->state() ==
74 password_manager::ui::CREDENTIAL_REQUEST_STATE) {
75 currentController_.reset(
76 [[ManagePasswordsBubbleAccountChooserViewController alloc]
85 - (void)performLayout {
86 if (!currentController_)
90 NSWindow* window = [self window];
91 [[window contentView] setSubviews:@[ [currentController_ view] ]];
94 BrowserWindowController* controller = [BrowserWindowController
95 browserWindowControllerForWindow:[self parentWindow]];
97 [controller locationBarBridge]->GetManagePasswordsBubblePoint();
98 anchorPoint = [[self parentWindow] convertBaseToScreen:anchorPoint];
99 [self setAnchorPoint:anchorPoint];
102 CGFloat height = NSHeight([[currentController_ view] frame]) +
103 info_bubble::kBubbleArrowHeight;
104 CGFloat width = NSWidth([[currentController_ view] frame]);
105 CGFloat x = anchorPoint.x - width +
106 info_bubble::kBubbleArrowXOffset +
107 (0.5 * info_bubble::kBubbleArrowWidth);
108 CGFloat y = anchorPoint.y - height;
109 [window setFrame:NSMakeRect(x, y, width, height)
111 animate:[window isVisible]];
114 #pragma mark ManagePasswordsBubbleContentViewDelegate
116 - (void)viewShouldDismiss {
120 #pragma mark ManagePasswordsBubblePendingViewDelegate
122 - (void)passwordShouldNeverBeSavedOnSiteWithExistingPasswords {
123 currentController_.reset([[ManagePasswordsBubbleNeverSaveViewController alloc]
126 [self performLayout];
129 #pragma mark ManagePasswordsBubbleNeverSaveViewDelegate
131 - (void)neverSavePasswordCancelled {
137 @implementation ManagePasswordsBubbleController (Testing)
139 - (NSViewController*)currentController {
140 return currentController_.get();