autofill_dialog_sign_in_delegate.cc revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
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#include "chrome/browser/ui/autofill/autofill_dialog_sign_in_delegate.h"
6
7#include "chrome/browser/ui/autofill/autofill_dialog_view.h"
8#include "content/public/browser/render_view_host.h"
9#include "content/public/browser/web_contents.h"
10
11namespace autofill {
12
13AutofillDialogSignInDelegate::AutofillDialogSignInDelegate(
14    AutofillDialogView* dialog_view,
15    content::WebContents* web_contents,
16    content::WebContentsDelegate* wrapped_delegate)
17    : WebContentsObserver(web_contents),
18      dialog_view_(dialog_view),
19      min_width_(400),
20      wrapped_delegate_(wrapped_delegate) {
21  DCHECK(wrapped_delegate_);
22  web_contents->SetDelegate(this);
23}
24
25void AutofillDialogSignInDelegate::ResizeDueToAutoResize(
26    content::WebContents* source, const gfx::Size& pref_size) {
27  dialog_view_->OnSignInResize(pref_size);
28}
29
30content::WebContents* AutofillDialogSignInDelegate::OpenURLFromTab(
31    content::WebContents* source,
32    const content::OpenURLParams& params) {
33  return wrapped_delegate_->OpenURLFromTab(source, params);
34}
35
36void AutofillDialogSignInDelegate::AddNewContents(
37    content::WebContents* source,
38    content::WebContents* new_contents,
39    WindowOpenDisposition disposition,
40    const gfx::Rect& initial_pos,
41    bool user_gesture,
42    bool* was_blocked) {
43  wrapped_delegate_->AddNewContents(source, new_contents, disposition,
44                                    initial_pos, user_gesture, was_blocked);
45}
46
47void AutofillDialogSignInDelegate::RenderViewCreated(
48    content::RenderViewHost* render_view_host) {
49  SetMinWidth(min_width_);
50
51  // Set the initial size as soon as we have an RVH to avoid
52  // bad size jumping.
53  dialog_view_->OnSignInResize(GetMinSize());
54}
55
56void AutofillDialogSignInDelegate::SetMinWidth(int width) {
57  min_width_ = width;
58  content::RenderViewHost* host = web_contents()->GetRenderViewHost();
59  if (host)
60    host->EnableAutoResize(GetMinSize(), GetMaxSize());
61}
62
63gfx::Size AutofillDialogSignInDelegate::GetMinSize() const {
64  return gfx::Size(min_width_, 331);
65}
66
67gfx::Size AutofillDialogSignInDelegate::GetMaxSize() const {
68  return gfx::Size(std::max(min_width_, 800), 600);
69}
70
71}  // namespace autofill
72