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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
// Copyright (c) 2011 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/notifications/balloon_host.h"
#include "chrome/browser/notifications/balloon.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_preferences_util.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
#include "chrome/common/extensions/extension_messages.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
#include "content/browser/renderer_host/browser_render_process_host.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/site_instance.h"
#include "content/common/bindings_policy.h"
#include "content/common/notification_service.h"
#include "content/common/notification_source.h"
#include "content/common/notification_type.h"
#include "content/common/renderer_preferences.h"
#include "content/common/view_messages.h"
#include "ipc/ipc_message.h"
#include "webkit/glue/webpreferences.h"
BalloonHost::BalloonHost(Balloon* balloon)
: render_view_host_(NULL),
balloon_(balloon),
initialized_(false),
should_notify_on_disconnect_(false),
enable_web_ui_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(
extension_function_dispatcher_(GetProfile(), this)) {
CHECK(balloon_);
site_instance_ = SiteInstance::CreateSiteInstanceForURL(balloon_->profile(),
GetURL());
}
void BalloonHost::Shutdown() {
NotifyDisconnect();
if (render_view_host_) {
render_view_host_->Shutdown();
render_view_host_ = NULL;
}
}
Browser* BalloonHost::GetBrowser() {
// Notifications aren't associated with a particular browser.
return NULL;
}
gfx::NativeView BalloonHost::GetNativeViewOfHost() {
// TODO(aa): Should this return the native view of the BalloonView*?
return NULL;
}
TabContents* BalloonHost::GetAssociatedTabContents() const {
return NULL;
}
const string16& BalloonHost::GetSource() const {
return balloon_->notification().display_source();
}
WebPreferences BalloonHost::GetWebkitPrefs() {
WebPreferences web_prefs =
RenderViewHostDelegateHelper::GetWebkitPrefs(GetProfile(),
enable_web_ui_);
web_prefs.allow_scripts_to_close_windows = true;
return web_prefs;
}
SiteInstance* BalloonHost::GetSiteInstance() const {
return site_instance_.get();
}
Profile* BalloonHost::GetProfile() const {
return balloon_->profile();
}
const GURL& BalloonHost::GetURL() const {
return balloon_->notification().content_url();
}
void BalloonHost::Close(RenderViewHost* render_view_host) {
balloon_->CloseByScript();
NotifyDisconnect();
}
void BalloonHost::RenderViewCreated(RenderViewHost* render_view_host) {
render_view_host->Send(new ViewMsg_DisableScrollbarsForSmallWindows(
render_view_host->routing_id(), balloon_->min_scrollbar_size()));
render_view_host->WasResized();
render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode(
render_view_host->routing_id(),
kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow));
}
void BalloonHost::RenderViewReady(RenderViewHost* render_view_host) {
should_notify_on_disconnect_ = true;
NotificationService::current()->Notify(
NotificationType::NOTIFY_BALLOON_CONNECTED,
Source<BalloonHost>(this), NotificationService::NoDetails());
}
void BalloonHost::RenderViewGone(RenderViewHost* render_view_host,
base::TerminationStatus status,
int error_code) {
Close(render_view_host);
}
ViewType::Type BalloonHost::GetRenderViewType() const {
return ViewType::NOTIFICATION;
}
RenderViewHostDelegate::View* BalloonHost::GetViewDelegate() {
return this;
}
bool BalloonHost::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(BalloonHost, message)
IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void BalloonHost::OnRequest(const ExtensionHostMsg_Request_Params& params) {
extension_function_dispatcher_.Dispatch(params, render_view_host_);
}
// RenderViewHostDelegate::View methods implemented to allow links to
// open pages in new tabs.
void BalloonHost::CreateNewWindow(
int route_id,
const ViewHostMsg_CreateWindow_Params& params) {
delegate_view_helper_.CreateNewWindow(
route_id,
balloon_->profile(),
site_instance_.get(),
ChromeWebUIFactory::GetInstance()->GetWebUIType(balloon_->profile(),
balloon_->notification().content_url()),
this,
params.window_container_type,
params.frame_name);
}
void BalloonHost::ShowCreatedWindow(int route_id,
WindowOpenDisposition disposition,
const gfx::Rect& initial_pos,
bool user_gesture) {
// Don't allow pop-ups from notifications.
if (disposition == NEW_POPUP)
return;
TabContents* contents = delegate_view_helper_.GetCreatedWindow(route_id);
if (!contents)
return;
Browser* browser = BrowserList::GetLastActiveWithProfile(balloon_->profile());
if (!browser)
return;
browser->AddTabContents(contents, disposition, initial_pos, user_gesture);
}
bool BalloonHost::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
bool* is_keyboard_shortcut) {
return false;
}
void BalloonHost::UpdatePreferredSize(const gfx::Size& new_size) {
balloon_->SetContentPreferredSize(new_size);
}
void BalloonHost::HandleMouseDown() {
balloon_->OnClick();
}
RendererPreferences BalloonHost::GetRendererPrefs(Profile* profile) const {
RendererPreferences preferences;
renderer_preferences_util::UpdateFromSystemSettings(&preferences, profile);
return preferences;
}
void BalloonHost::Init() {
DCHECK(!render_view_host_) << "BalloonViewHost already initialized.";
RenderViewHost* rvh = new RenderViewHost(
site_instance_.get(), this, MSG_ROUTING_NONE, NULL);
if (enable_web_ui_)
rvh->AllowBindings(BindingsPolicy::WEB_UI);
// Do platform-specific initialization.
render_view_host_ = rvh;
InitRenderWidgetHostView();
DCHECK(render_widget_host_view());
rvh->SetView(render_widget_host_view());
rvh->CreateRenderView(string16());
rvh->NavigateToURL(balloon_->notification().content_url());
initialized_ = true;
}
void BalloonHost::EnableWebUI() {
DCHECK(render_view_host_ == NULL) <<
"EnableWebUI has to be called before a renderer is created.";
enable_web_ui_ = true;
}
void BalloonHost::UpdateInspectorSetting(const std::string& key,
const std::string& value) {
RenderViewHostDelegateHelper::UpdateInspectorSetting(
GetProfile(), key, value);
}
void BalloonHost::ClearInspectorSettings() {
RenderViewHostDelegateHelper::ClearInspectorSettings(GetProfile());
}
BalloonHost::~BalloonHost() {
DCHECK(!render_view_host_);
}
void BalloonHost::NotifyDisconnect() {
if (!should_notify_on_disconnect_)
return;
should_notify_on_disconnect_ = false;
NotificationService::current()->Notify(
NotificationType::NOTIFY_BALLOON_DISCONNECTED,
Source<BalloonHost>(this), NotificationService::NoDetails());
}
bool BalloonHost::IsRenderViewReady() const {
return should_notify_on_disconnect_;
}
|