Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: chrome/browser/notifications/balloon_host.cc

Issue 6010004: Refactor RenderWidgetHost::set_paint_observer() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove helper classes per review Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/notifications/balloon_host.h" 5 #include "chrome/browser/notifications/balloon_host.h"
6 6
7 #include "chrome/browser/browser_list.h" 7 #include "chrome/browser/browser_list.h"
8 #include "chrome/browser/extensions/extension_process_manager.h" 8 #include "chrome/browser/extensions/extension_process_manager.h"
9 #include "chrome/browser/notifications/balloon.h" 9 #include "chrome/browser/notifications/balloon.h"
10 #include "chrome/browser/notifications/notification.h" 10 #include "chrome/browser/notifications/notification.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/renderer_host/render_view_host.h" 12 #include "chrome/browser/renderer_host/render_view_host.h"
13 #include "chrome/browser/renderer_host/site_instance.h" 13 #include "chrome/browser/renderer_host/site_instance.h"
14 #include "chrome/browser/renderer_preferences_util.h" 14 #include "chrome/browser/renderer_preferences_util.h"
15 #include "chrome/common/bindings_policy.h" 15 #include "chrome/common/bindings_policy.h"
16 #include "chrome/common/notification_service.h" 16 #include "chrome/common/notification_service.h"
17 #include "chrome/common/notification_type.h" 17 #include "chrome/common/notification_type.h"
18 #include "chrome/common/render_messages.h" 18 #include "chrome/common/render_messages.h"
19 #include "chrome/common/renderer_preferences.h" 19 #include "chrome/common/renderer_preferences.h"
20 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
21 #include "webkit/glue/webpreferences.h" 21 #include "webkit/glue/webpreferences.h"
22 22
23 namespace {
24 class BalloonPaintObserver : public RenderWidgetHost::PaintObserver {
25 public:
26 explicit BalloonPaintObserver(BalloonHost* balloon_host)
27 : balloon_host_(balloon_host) {
28 }
29
30 virtual void RenderWidgetHostWillPaint(RenderWidgetHost* rhw) {}
31 virtual void RenderWidgetHostDidPaint(RenderWidgetHost* rwh);
32
33 private:
34 BalloonHost* balloon_host_;
35
36 DISALLOW_COPY_AND_ASSIGN(BalloonPaintObserver);
37 };
38
39 void BalloonPaintObserver::RenderWidgetHostDidPaint(RenderWidgetHost* rwh) {
40 balloon_host_->RenderWidgetHostDidPaint();
41 // WARNING: we may have been deleted (if the balloon host cleared the paint
42 // observer).
43 }
44
45 } // namespace
46
47 BalloonHost::BalloonHost(Balloon* balloon) 23 BalloonHost::BalloonHost(Balloon* balloon)
48 : render_view_host_(NULL), 24 : render_view_host_(NULL),
49 balloon_(balloon), 25 balloon_(balloon),
50 initialized_(false), 26 initialized_(false),
51 should_notify_on_disconnect_(false), 27 should_notify_on_disconnect_(false),
52 enable_dom_ui_(false) { 28 enable_dom_ui_(false) {
53 DCHECK(balloon_); 29 DCHECK(balloon_);
54 30
55 // If the notification is for an extension URL, make sure to use the extension 31 // If the notification is for an extension URL, make sure to use the extension
56 // process to render it, so that it can communicate with other views in the 32 // process to render it, so that it can communicate with other views in the
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 205 }
230 206
231 // Do platform-specific initialization. 207 // Do platform-specific initialization.
232 render_view_host_ = rvh; 208 render_view_host_ = rvh;
233 InitRenderWidgetHostView(); 209 InitRenderWidgetHostView();
234 DCHECK(render_widget_host_view()); 210 DCHECK(render_widget_host_view());
235 211
236 rvh->set_view(render_widget_host_view()); 212 rvh->set_view(render_widget_host_view());
237 rvh->CreateRenderView(string16()); 213 rvh->CreateRenderView(string16());
238 #if defined(OS_MACOSX) 214 #if defined(OS_MACOSX)
239 rvh->set_paint_observer(new BalloonPaintObserver(this)); 215 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DID_PAINT,
216 Source<RenderWidgetHost>(render_view_host));
240 #endif 217 #endif
241 rvh->NavigateToURL(balloon_->notification().content_url()); 218 rvh->NavigateToURL(balloon_->notification().content_url());
242 219
243 initialized_ = true; 220 initialized_ = true;
244 } 221 }
245 222
246 void BalloonHost::EnableDOMUI() { 223 void BalloonHost::EnableDOMUI() {
247 DCHECK(render_view_host_ == NULL) << 224 DCHECK(render_view_host_ == NULL) <<
248 "EnableDOMUI has to be called before a renderer is created."; 225 "EnableDOMUI has to be called before a renderer is created.";
249 enable_dom_ui_ = true; 226 enable_dom_ui_ = true;
250 } 227 }
251 228
252 void BalloonHost::UpdateInspectorSetting(const std::string& key, 229 void BalloonHost::UpdateInspectorSetting(const std::string& key,
253 const std::string& value) { 230 const std::string& value) {
254 RenderViewHostDelegateHelper::UpdateInspectorSetting( 231 RenderViewHostDelegateHelper::UpdateInspectorSetting(
255 GetProfile(), key, value); 232 GetProfile(), key, value);
256 } 233 }
257 234
258 void BalloonHost::ClearInspectorSettings() { 235 void BalloonHost::ClearInspectorSettings() {
259 RenderViewHostDelegateHelper::ClearInspectorSettings(GetProfile()); 236 RenderViewHostDelegateHelper::ClearInspectorSettings(GetProfile());
260 } 237 }
261 238
262 void BalloonHost::RenderWidgetHostDidPaint() { 239 void BalloonHost::Observe(NotificationType type,
263 render_view_host_->set_paint_observer(NULL); 240 const NotificationSource& source,
264 render_view_host_->EnablePreferredSizeChangedMode( 241 const NotificationDetails& details) {
265 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); 242 if (type == NotificationType::RENDER_WIDGET_HOST_DID_PAINT) {
243 registrar_.RemoveAll();
244 render_view_host_->EnablePreferredSizeChangedMode(
245 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
246 }
266 } 247 }
267 248
268 BalloonHost::~BalloonHost() { 249 BalloonHost::~BalloonHost() {
269 DCHECK(!render_view_host_); 250 DCHECK(!render_view_host_);
270 } 251 }
271 252
272 void BalloonHost::NotifyDisconnect() { 253 void BalloonHost::NotifyDisconnect() {
273 if (!should_notify_on_disconnect_) 254 if (!should_notify_on_disconnect_)
274 return; 255 return;
275 256
276 should_notify_on_disconnect_ = false; 257 should_notify_on_disconnect_ = false;
277 NotificationService::current()->Notify( 258 NotificationService::current()->Notify(
278 NotificationType::NOTIFY_BALLOON_DISCONNECTED, 259 NotificationType::NOTIFY_BALLOON_DISCONNECTED,
279 Source<BalloonHost>(this), NotificationService::NoDetails()); 260 Source<BalloonHost>(this), NotificationService::NoDetails());
280 } 261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698