Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / autofill / autofill_dialog_sign_in_delegate.cc
blob5dba33bbdbcfcbba603c9b802435375c7f2a3d4c
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 "third_party/WebKit/public/web/WebInputEvent.h"
15 #include "ui/base/window_open_disposition.h"
17 namespace autofill {
19 namespace {
21 using content::OpenURLParams;
23 // Signals if |params| require opening inside the current WebContents.
24 bool IsInPageTransition(const OpenURLParams& params) {
25 return params.disposition == CURRENT_TAB;
28 // Indicates if the open action specified by |params| should happen in the
29 // Autofill dialog (when true) or in the browser (when false).
30 bool ShouldOpenInBrowser(const OpenURLParams& params) {
31 return !IsInPageTransition(params) || !wallet::IsSignInRelatedUrl(params.url);
34 // Adjusts |params| to account for the fact that the open request originated in
35 // the dialog, but will be executed in the browser.
36 OpenURLParams AdjustToOpenInBrowser(const OpenURLParams& params) {
37 if (!IsInPageTransition(params) || wallet::IsSignInRelatedUrl(params.url))
38 return params;
40 content::OpenURLParams new_params = params;
41 new_params.disposition = NEW_FOREGROUND_TAB;
42 return new_params;
45 } // namespace
47 AutofillDialogSignInDelegate::AutofillDialogSignInDelegate(
48 AutofillDialogView* dialog_view,
49 content::WebContents* dialog_web_contents,
50 content::WebContents* originating_web_contents,
51 const gfx::Size& minimum_size,
52 const gfx::Size& maximum_size)
53 : WebContentsObserver(dialog_web_contents),
54 dialog_view_(dialog_view),
55 originating_web_contents_(originating_web_contents) {
56 DCHECK(dialog_view_);
57 dialog_web_contents->SetDelegate(this);
59 content::RendererPreferences* prefs =
60 dialog_web_contents->GetMutableRendererPrefs();
61 prefs->browser_handles_non_local_top_level_requests = true;
62 dialog_web_contents->GetRenderViewHost()->SyncRendererPrefs();
64 UpdateLimitsAndEnableAutoResize(minimum_size, maximum_size);
67 void AutofillDialogSignInDelegate::ResizeDueToAutoResize(
68 content::WebContents* source,
69 const gfx::Size& preferred_size) {
70 dialog_view_->OnSignInResize(preferred_size);
73 content::WebContents* AutofillDialogSignInDelegate::OpenURLFromTab(
74 content::WebContents* source,
75 const content::OpenURLParams& params) {
76 if (ShouldOpenInBrowser(params))
77 return originating_web_contents_->OpenURL(AdjustToOpenInBrowser(params));
79 source->GetController().LoadURL(params.url,
80 params.referrer,
81 params.transition,
82 std::string());
83 return source;
86 // This gets invoked whenever there is an attempt to open a new window/tab.
87 // Reroute to the original browser.
88 void AutofillDialogSignInDelegate::AddNewContents(
89 content::WebContents* source,
90 content::WebContents* new_contents,
91 WindowOpenDisposition disposition,
92 const gfx::Rect& initial_rect,
93 bool user_gesture,
94 bool* was_blocked) {
95 chrome::AddWebContents(
96 chrome::FindBrowserWithWebContents(originating_web_contents_),
97 source, new_contents, disposition, initial_rect, user_gesture,
98 was_blocked);
101 bool AutofillDialogSignInDelegate::PreHandleGestureEvent(
102 content::WebContents* source,
103 const blink::WebGestureEvent& event) {
104 // Disable pinch zooming.
105 return event.type == blink::WebGestureEvent::GesturePinchBegin ||
106 event.type == blink::WebGestureEvent::GesturePinchUpdate ||
107 event.type == blink::WebGestureEvent::GesturePinchEnd;
110 void AutofillDialogSignInDelegate::RenderViewCreated(
111 content::RenderViewHost* render_view_host) {
112 EnableAutoResize();
114 // Set the initial size as soon as we have an RVH to avoid bad size jumping.
115 dialog_view_->OnSignInResize(minimum_size_);
118 void AutofillDialogSignInDelegate::UpdateLimitsAndEnableAutoResize(
119 const gfx::Size& minimum_size,
120 const gfx::Size& maximum_size) {
121 minimum_size_ = minimum_size;
122 maximum_size_ = maximum_size;
123 EnableAutoResize();
126 void AutofillDialogSignInDelegate::EnableAutoResize() {
127 DCHECK(!minimum_size_.IsEmpty());
128 DCHECK(!maximum_size_.IsEmpty());
129 content::RenderViewHost* host = web_contents()->GetRenderViewHost();
130 if (host)
131 host->EnableAutoResize(minimum_size_, maximum_size_);
134 } // namespace autofill