Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / autofill / autofill_dialog_sign_in_delegate.cc
blob987a0a8ff83cfefb07db589302e8467eac02fc54
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.
5 #include "chrome/browser/ui/autofill/autofill_dialog_sign_in_delegate.h"
7 #include "chrome/browser/ui/autofill/autofill_dialog_view.h"
8 #include "chrome/browser/ui/browser_finder.h"
9 #include "chrome/browser/ui/browser_tabstrip.h"
10 #include "components/autofill/content/browser/wallet/wallet_service_url.h"
11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/common/renderer_preferences.h"
14 #include "ui/base/window_open_disposition.h"
16 namespace autofill {
18 namespace {
20 using content::OpenURLParams;
22 // Signals if |params| require opening inside the current WebContents.
23 bool IsInPageTransition(const OpenURLParams& params) {
24 return params.disposition == CURRENT_TAB;
27 // Indicates if the open action specified by |params| should happen in the
28 // Autofill dialog (when true) or in the browser (when false).
29 bool ShouldOpenInBrowser(const OpenURLParams& params) {
30 return !IsInPageTransition(params) || !wallet::IsSignInRelatedUrl(params.url);
33 // Adjusts |params| to account for the fact that the open request originated in
34 // the dialog, but will be executed in the browser.
35 OpenURLParams AdjustToOpenInBrowser(const OpenURLParams& params) {
36 if (!IsInPageTransition(params) || wallet::IsSignInRelatedUrl(params.url))
37 return params;
39 content::OpenURLParams new_params = params;
40 new_params.disposition = NEW_FOREGROUND_TAB;
41 return new_params;
44 } // namespace
46 AutofillDialogSignInDelegate::AutofillDialogSignInDelegate(
47 AutofillDialogView* dialog_view,
48 content::WebContents* dialog_web_contents,
49 content::WebContents* originating_web_contents,
50 const gfx::Size& minimum_size,
51 const gfx::Size& maximum_size)
52 : WebContentsObserver(dialog_web_contents),
53 dialog_view_(dialog_view),
54 originating_web_contents_(originating_web_contents) {
55 DCHECK(dialog_view_);
56 dialog_web_contents->SetDelegate(this);
58 content::RendererPreferences* prefs =
59 dialog_web_contents->GetMutableRendererPrefs();
60 prefs->browser_handles_non_local_top_level_requests = true;
61 dialog_web_contents->GetRenderViewHost()->SyncRendererPrefs();
63 UpdateLimitsAndEnableAutoResize(minimum_size, maximum_size);
66 void AutofillDialogSignInDelegate::ResizeDueToAutoResize(
67 content::WebContents* source,
68 const gfx::Size& preferred_size) {
69 dialog_view_->OnSignInResize(preferred_size);
72 content::WebContents* AutofillDialogSignInDelegate::OpenURLFromTab(
73 content::WebContents* source,
74 const content::OpenURLParams& params) {
75 if (ShouldOpenInBrowser(params))
76 return originating_web_contents_->OpenURL(AdjustToOpenInBrowser(params));
78 source->GetController().LoadURL(params.url,
79 params.referrer,
80 params.transition,
81 std::string());
82 return source;
85 // This gets invoked whenever there is an attempt to open a new window/tab.
86 // Reroute to the original browser.
87 void AutofillDialogSignInDelegate::AddNewContents(
88 content::WebContents* source,
89 content::WebContents* new_contents,
90 WindowOpenDisposition disposition,
91 const gfx::Rect& initial_pos,
92 bool user_gesture,
93 bool* was_blocked) {
94 chrome::AddWebContents(
95 chrome::FindBrowserWithWebContents(originating_web_contents_),
96 source, new_contents, disposition, initial_pos, user_gesture,
97 was_blocked);
100 void AutofillDialogSignInDelegate::RenderViewCreated(
101 content::RenderViewHost* render_view_host) {
102 EnableAutoResize();
104 // Set the initial size as soon as we have an RVH to avoid bad size jumping.
105 dialog_view_->OnSignInResize(minimum_size_);
108 void AutofillDialogSignInDelegate::UpdateLimitsAndEnableAutoResize(
109 const gfx::Size& minimum_size,
110 const gfx::Size& maximum_size) {
111 minimum_size_ = minimum_size;
112 maximum_size_ = maximum_size;
113 EnableAutoResize();
116 void AutofillDialogSignInDelegate::EnableAutoResize() {
117 DCHECK(!minimum_size_.IsEmpty());
118 DCHECK(!maximum_size_.IsEmpty());
119 content::RenderViewHost* host = web_contents()->GetRenderViewHost();
120 if (host)
121 host->EnableAutoResize(minimum_size_, maximum_size_);
124 } // namespace autofill