autofill_sign_in_container.mm revision 1e9bf3e0803691d0a228da41fc608347b6db4340
1// Copyright (c) 2013 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. 4 5#import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h" 6 7#import <Cocoa/Cocoa.h> 8 9#include "base/strings/sys_string_conversions.h" 10#include "chrome/browser/profiles/profile.h" 11#include "chrome/browser/ui/autofill/autofill_dialog_sign_in_delegate.h" 12#include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h" 13#include "components/autofill/content/browser/wallet/wallet_service_url.h" 14#include "content/public/browser/web_contents.h" 15#include "content/public/browser/web_contents_view.h" 16 17@implementation AutofillSignInContainer 18 19@synthesize preferredSize = preferredSize_; 20 21- (id)initWithDialog:(autofill::AutofillDialogCocoa*)dialog { 22 if (self = [super init]) { 23 dialog_ = dialog; 24 } 25 return self; 26} 27 28- (void)loadView { 29 webContents_.reset( 30 content::WebContents::Create( 31 content::WebContents::CreateParams(dialog_->delegate()->profile()))); 32 NSView* webContentView = webContents_->GetView()->GetNativeView(); 33 [self setView:webContentView]; 34} 35 36- (void)loadSignInPage { 37 DCHECK(webContents_.get()); 38 39 // Prevent accidentaly empty |maxSize_|. 40 if (NSEqualSizes(NSMakeSize(0, 0), maxSize_)) { 41 maxSize_ = [[[self view] window] frame].size; 42 } 43 44 signInDelegate_.reset( 45 new autofill::AutofillDialogSignInDelegate( 46 dialog_, webContents_.get(), 47 dialog_->delegate()->GetWebContents()->GetDelegate(), 48 gfx::Size(NSSizeToCGSize(minSize_)), 49 gfx::Size(NSSizeToCGSize(maxSize_)))); 50 webContents_->GetController().LoadURL( 51 dialog_->delegate()->SignInUrl(), 52 content::Referrer(), 53 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 54 std::string()); 55} 56 57- (content::NavigationController*)navigationController { 58 return &webContents_->GetController(); 59} 60 61- (content::WebContents*)webContents { 62 return webContents_.get(); 63} 64 65- (void)constrainSizeToMinimum:(NSSize)minSize maximum:(NSSize)maxSize { 66 minSize_ = minSize; 67 maxSize_ = maxSize; 68 69 // Notify the web contents of its new auto-resize limits. 70 if (signInDelegate_ && ![[self view] isHidden]) { 71 signInDelegate_->UpdateLimitsAndEnableAutoResize( 72 gfx::Size(NSSizeToCGSize(minSize_)), 73 gfx::Size(NSSizeToCGSize(maxSize_))); 74 } 75} 76 77- (void)setPreferredSize:(NSSize)size { 78 preferredSize_ = size; 79 80 // Always request re-layout if preferredSize changes. 81 id delegate = [[[self view] window] windowController]; 82 if ([delegate respondsToSelector:@selector(requestRelayout)]) 83 [delegate performSelector:@selector(requestRelayout)]; 84} 85 86@end 87