1 // Copyright (c) 2012 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/webui/constrained_web_dialog_delegate_base.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/renderer_preferences_util.h"
11 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h"
12 #include "components/ui/zoom/zoom_controller.h"
13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/renderer_preferences.h"
16 #include "ipc/ipc_message.h"
17 #include "ui/web_dialogs/web_dialog_delegate.h"
18 #include "ui/web_dialogs/web_dialog_ui.h"
20 using content::NativeWebKeyboardEvent
;
21 using content::WebContents
;
22 using ui::WebDialogDelegate
;
23 using ui::WebDialogWebContentsDelegate
;
25 ConstrainedWebDialogDelegateBase::ConstrainedWebDialogDelegateBase(
26 content::BrowserContext
* browser_context
,
27 WebDialogDelegate
* delegate
,
28 WebDialogWebContentsDelegate
* tab_delegate
)
29 : WebDialogWebContentsDelegate(browser_context
,
30 new ChromeWebContentsHandler
),
31 web_dialog_delegate_(delegate
),
32 closed_via_webui_(false),
33 release_contents_on_close_(false) {
36 WebContents::Create(WebContents::CreateParams(browser_context
)));
37 ui_zoom::ZoomController::CreateForWebContents(web_contents_
.get());
39 override_tab_delegate_
.reset(tab_delegate
);
40 web_contents_
->SetDelegate(tab_delegate
);
42 web_contents_
->SetDelegate(this);
44 content::RendererPreferences
* prefs
=
45 web_contents_
->GetMutableRendererPrefs();
46 renderer_preferences_util::UpdateFromSystemSettings(
47 prefs
, Profile::FromBrowserContext(browser_context
), web_contents_
.get());
49 web_contents_
->GetRenderViewHost()->SyncRendererPrefs();
51 // Set |this| as a delegate so the ConstrainedWebDialogUI can retrieve it.
52 ConstrainedWebDialogUI::SetConstrainedDelegate(web_contents_
.get(), this);
54 web_contents_
->GetController().LoadURL(delegate
->GetDialogContentURL(),
56 ui::PAGE_TRANSITION_AUTO_TOPLEVEL
,
60 ConstrainedWebDialogDelegateBase::~ConstrainedWebDialogDelegateBase() {
61 if (release_contents_on_close_
)
62 ignore_result(web_contents_
.release());
65 const WebDialogDelegate
*
66 ConstrainedWebDialogDelegateBase::GetWebDialogDelegate() const {
67 return web_dialog_delegate_
.get();
71 ConstrainedWebDialogDelegateBase::GetWebDialogDelegate() {
72 return web_dialog_delegate_
.get();
75 void ConstrainedWebDialogDelegateBase::OnDialogCloseFromWebUI() {
76 closed_via_webui_
= true;
77 CloseContents(web_contents_
.get());
80 bool ConstrainedWebDialogDelegateBase::closed_via_webui() const {
81 return closed_via_webui_
;
84 void ConstrainedWebDialogDelegateBase::ReleaseWebContentsOnDialogClose() {
85 release_contents_on_close_
= true;
88 gfx::NativeWindow
ConstrainedWebDialogDelegateBase::GetNativeDialog() {
93 WebContents
* ConstrainedWebDialogDelegateBase::GetWebContents() {
94 return web_contents_
.get();
97 void ConstrainedWebDialogDelegateBase::HandleKeyboardEvent(
98 content::WebContents
* source
,
99 const NativeWebKeyboardEvent
& event
) {
102 gfx::Size
ConstrainedWebDialogDelegateBase::GetMinimumSize() const {
107 gfx::Size
ConstrainedWebDialogDelegateBase::GetMaximumSize() const {
112 gfx::Size
ConstrainedWebDialogDelegateBase::GetPreferredSize() const {