1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/views/constrained_window_views.h"
#include "content/public/browser/web_contents.h"
#include "ui/gfx/size.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/web_dialogs/web_dialog_delegate.h"
#include "ui/web_dialogs/web_dialog_ui.h"
using content::WebContents;
using ui::ConstrainedWebDialogDelegate;
using ui::ConstrainedWebDialogUI;
using ui::WebDialogDelegate;
namespace {
class ConstrainedWebDialogDelegateViews
: public ConstrainedWebDialogDelegateBase {
public:
ConstrainedWebDialogDelegateViews(
Profile* profile,
WebDialogDelegate* delegate,
WebDialogWebContentsDelegate* tab_delegate)
: ConstrainedWebDialogDelegateBase(profile, delegate, tab_delegate) {
WebContents* web_contents = tab()->web_contents();
if (tab_delegate) {
set_override_tab_delegate(tab_delegate);
web_contents->SetDelegate(tab_delegate);
} else {
web_contents->SetDelegate(this);
}
}
virtual ~ConstrainedWebDialogDelegateViews() {}
// WebDialogWebContentsDelegate interface.
virtual void CloseContents(WebContents* source) OVERRIDE {
window()->CloseConstrainedWindow();
}
private:
DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViews);
};
} // namespace
class ConstrainedWebDialogDelegateViewViews
: public views::WebView,
public ConstrainedWebDialogDelegate,
public views::WidgetDelegate {
public:
ConstrainedWebDialogDelegateViewViews(
Profile* profile,
WebDialogDelegate* delegate,
WebDialogWebContentsDelegate* tab_delegate);
virtual ~ConstrainedWebDialogDelegateViewViews();
void set_window(ConstrainedWindow* window) {
return impl_->set_window(window);
}
// ConstrainedWebDialogDelegate interface
virtual const WebDialogDelegate*
GetWebDialogDelegate() const OVERRIDE {
return impl_->GetWebDialogDelegate();
}
virtual WebDialogDelegate* GetWebDialogDelegate() OVERRIDE {
return impl_->GetWebDialogDelegate();
}
virtual void OnDialogCloseFromWebUI() OVERRIDE {
return impl_->OnDialogCloseFromWebUI();
}
virtual void ReleaseTabContentsOnDialogClose() OVERRIDE {
return impl_->ReleaseTabContentsOnDialogClose();
}
virtual ConstrainedWindow* window() OVERRIDE {
return impl_->window();
}
virtual TabContentsWrapper* tab() OVERRIDE {
return impl_->tab();
}
// views::WidgetDelegate interface.
virtual views::View* GetInitiallyFocusedView() OVERRIDE {
return this;
}
virtual bool CanResize() const OVERRIDE { return true; }
virtual void WindowClosing() OVERRIDE {
if (!impl_->closed_via_webui())
GetWebDialogDelegate()->OnDialogClosed(std::string());
}
virtual views::Widget* GetWidget() OVERRIDE {
return View::GetWidget();
}
virtual const views::Widget* GetWidget() const OVERRIDE {
return View::GetWidget();
}
virtual string16 GetWindowTitle() const OVERRIDE {
return impl_->closed_via_webui() ? string16() :
GetWebDialogDelegate()->GetDialogTitle();
}
virtual views::View* GetContentsView() OVERRIDE {
return this;
}
// views::WebView overrides.
virtual gfx::Size GetPreferredSize() OVERRIDE {
gfx::Size size;
if (!impl_->closed_via_webui())
GetWebDialogDelegate()->GetDialogSize(&size);
return size;
}
private:
scoped_ptr<ConstrainedWebDialogDelegateViews> impl_;
DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews);
};
ConstrainedWebDialogDelegateViewViews::ConstrainedWebDialogDelegateViewViews(
Profile* profile,
WebDialogDelegate* delegate,
WebDialogWebContentsDelegate* tab_delegate)
: views::WebView(profile),
impl_(new ConstrainedWebDialogDelegateViews(profile,
delegate,
tab_delegate)) {
SetWebContents(tab()->web_contents());
}
ConstrainedWebDialogDelegateViewViews::~ConstrainedWebDialogDelegateViewViews() {
}
ConstrainedWebDialogDelegate* ui::CreateConstrainedWebDialog(
Profile* profile,
WebDialogDelegate* delegate,
WebDialogWebContentsDelegate* tab_delegate,
TabContentsWrapper* container) {
ConstrainedWebDialogDelegateViewViews* constrained_delegate =
new ConstrainedWebDialogDelegateViewViews(profile, delegate, tab_delegate);
ConstrainedWindow* constrained_window =
new ConstrainedWindowViews(container, constrained_delegate);
constrained_delegate->set_window(constrained_window);
return constrained_delegate;
}
|