1 // Copyright (c) 2012 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/one_click_signin_bubble_controller.h"
7 #include "base/strings/sys_string_conversions.h"
8 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
9 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
10 #import "chrome/browser/ui/cocoa/one_click_signin_view_controller.h"
11 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
15 void PerformClose(OneClickSigninBubbleController* controller) {
21 @implementation OneClickSigninBubbleController
23 - (id)initWithBrowserWindowController:(BrowserWindowController*)controller
24 webContents:(content::WebContents*)webContents
25 errorMessage:(NSString*)errorMessage
26 callback:(const BrowserWindow::StartSyncCallback&)
28 viewController_.reset([[OneClickSigninViewController alloc]
29 initWithNibName:@"OneClickSigninBubble"
30 webContents:webContents
31 syncCallback:syncCallback
32 closeCallback:base::Bind(PerformClose, self)
34 email:base::string16()
35 errorMessage:errorMessage]);
37 NSWindow* parentWindow = [controller window];
39 // Set the anchor point to right below the wrench menu.
40 NSView* wrenchButton = [[controller toolbarController] wrenchButton];
41 const NSRect bounds = [wrenchButton bounds];
42 NSPoint anchorPoint = NSMakePoint(NSMidX(bounds), NSMaxY(bounds));
43 anchorPoint = [wrenchButton convertPoint:anchorPoint toView:nil];
44 anchorPoint = [parentWindow convertBaseToScreen:anchorPoint];
46 // Create an empty window into which content is placed.
47 NSRect viewBounds = [[viewController_ view] bounds];
48 base::scoped_nsobject<InfoBubbleWindow> window(
49 [[InfoBubbleWindow alloc] initWithContentRect:viewBounds
50 styleMask:NSBorderlessWindowMask
51 backing:NSBackingStoreBuffered
53 if (self = [super initWithWindow:window
54 parentWindow:parentWindow
55 anchoredAt:anchorPoint]) {
56 [[window contentView] addSubview:[viewController_ view]];
57 // This class will release itself when the bubble closes. See
58 // -[BaseBubbleController windowWillClose:].
65 - (OneClickSigninViewController*)viewController {
66 return viewController_;
69 - (void)windowWillClose:(NSNotification*)notification {
70 [viewController_ viewWillClose];
71 [super windowWillClose:notification];
74 @end // OneClickSigninBubbleController