autofill_dialog_sign_in_delegate.cc revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
1// Copyright 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    const gfx::Size& minimum_size,
18    const gfx::Size& maximum_size)
19    : WebContentsObserver(web_contents),
20      dialog_view_(dialog_view),
21      wrapped_delegate_(wrapped_delegate) {
22  DCHECK(dialog_view_);
23  DCHECK(wrapped_delegate_);
24  web_contents->SetDelegate(this);
25  UpdateLimitsAndEnableAutoResize(minimum_size, maximum_size);
26}
27
28void AutofillDialogSignInDelegate::ResizeDueToAutoResize(
29    content::WebContents* source,
30    const gfx::Size& preferred_size) {
31  dialog_view_->OnSignInResize(preferred_size);
32}
33
34content::WebContents* AutofillDialogSignInDelegate::OpenURLFromTab(
35    content::WebContents* source,
36    const content::OpenURLParams& params) {
37  return wrapped_delegate_->OpenURLFromTab(source, params);
38}
39
40void AutofillDialogSignInDelegate::AddNewContents(
41    content::WebContents* source,
42    content::WebContents* new_contents,
43    WindowOpenDisposition disposition,
44    const gfx::Rect& initial_pos,
45    bool user_gesture,
46    bool* was_blocked) {
47  wrapped_delegate_->AddNewContents(source, new_contents, disposition,
48                                    initial_pos, user_gesture, was_blocked);
49}
50
51void AutofillDialogSignInDelegate::RenderViewCreated(
52    content::RenderViewHost* render_view_host) {
53  EnableAutoResize();
54
55  // Set the initial size as soon as we have an RVH to avoid bad size jumping.
56  dialog_view_->OnSignInResize(minimum_size_);
57}
58
59void AutofillDialogSignInDelegate::UpdateLimitsAndEnableAutoResize(
60    const gfx::Size& minimum_size,
61    const gfx::Size& maximum_size) {
62  minimum_size_ = minimum_size;
63  maximum_size_ = maximum_size;
64  EnableAutoResize();
65}
66
67void AutofillDialogSignInDelegate::EnableAutoResize() {
68  content::RenderViewHost* host = web_contents()->GetRenderViewHost();
69  if (host)
70    host->EnableAutoResize(minimum_size_, maximum_size_);
71}
72
73}  // namespace autofill
74