Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / one_click_signin_bubble_controller.mm
blobe66f5ff6d8f97b667d4e6fbdb4ee62c5c5de9532
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"
13 namespace {
15 void PerformClose(OneClickSigninBubbleController* controller) {
16   [controller close];
19 }  // namespace
21 @implementation OneClickSigninBubbleController
23 - (id)initWithBrowserWindowController:(BrowserWindowController*)controller
24                           webContents:(content::WebContents*)webContents
25                          errorMessage:(NSString*)errorMessage
26                              callback:(const BrowserWindow::StartSyncCallback&)
27                                                                   syncCallback{
28   viewController_.reset([[OneClickSigninViewController alloc]
29       initWithNibName:@"OneClickSigninBubble"
30           webContents:webContents
31          syncCallback:syncCallback
32         closeCallback:base::Bind(PerformClose, self)
33          isSyncDialog:NO
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
52                                               defer:NO]);
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:].
59     [self retain];
60   }
62   return self;
65 - (OneClickSigninViewController*)viewController {
66   return viewController_;
69 - (void)windowWillClose:(NSNotification*)notification {
70   [viewController_ viewWillClose];
71   [super windowWillClose:notification];
74 @end  // OneClickSigninBubbleController