| OLD | NEW |
| 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/profile.h" | 11 #include "chrome/browser/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 |
| 23 BalloonHost::BalloonHost(Balloon* balloon) | 47 BalloonHost::BalloonHost(Balloon* balloon) |
| 24 : render_view_host_(NULL), | 48 : render_view_host_(NULL), |
| 25 balloon_(balloon), | 49 balloon_(balloon), |
| 26 initialized_(false), | 50 initialized_(false), |
| 27 should_notify_on_disconnect_(false), | 51 should_notify_on_disconnect_(false), |
| 28 enable_dom_ui_(false) { | 52 enable_dom_ui_(false) { |
| 29 DCHECK(balloon_); | 53 DCHECK(balloon_); |
| 30 | 54 |
| 31 // If the notification is for an extension URL, make sure to use the extension | 55 // If the notification is for an extension URL, make sure to use the extension |
| 32 // process to render it, so that it can communicate with other views in the | 56 // process to render it, so that it can communicate with other views in the |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 109 |
| 86 void BalloonHost::Close(RenderViewHost* render_view_host) { | 110 void BalloonHost::Close(RenderViewHost* render_view_host) { |
| 87 balloon_->CloseByScript(); | 111 balloon_->CloseByScript(); |
| 88 NotifyDisconnect(); | 112 NotifyDisconnect(); |
| 89 } | 113 } |
| 90 | 114 |
| 91 void BalloonHost::RenderViewCreated(RenderViewHost* render_view_host) { | 115 void BalloonHost::RenderViewCreated(RenderViewHost* render_view_host) { |
| 92 render_view_host->Send(new ViewMsg_DisableScrollbarsForSmallWindows( | 116 render_view_host->Send(new ViewMsg_DisableScrollbarsForSmallWindows( |
| 93 render_view_host->routing_id(), balloon_->min_scrollbar_size())); | 117 render_view_host->routing_id(), balloon_->min_scrollbar_size())); |
| 94 render_view_host->WasResized(); | 118 render_view_host->WasResized(); |
| 119 #if !defined(OS_MACOSX) |
| 95 render_view_host->EnablePreferredSizeChangedMode( | 120 render_view_host->EnablePreferredSizeChangedMode( |
| 96 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); | 121 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); |
| 122 #endif |
| 97 } | 123 } |
| 98 | 124 |
| 99 void BalloonHost::RenderViewReady(RenderViewHost* render_view_host) { | 125 void BalloonHost::RenderViewReady(RenderViewHost* render_view_host) { |
| 100 should_notify_on_disconnect_ = true; | 126 should_notify_on_disconnect_ = true; |
| 101 NotificationService::current()->Notify( | 127 NotificationService::current()->Notify( |
| 102 NotificationType::NOTIFY_BALLOON_CONNECTED, | 128 NotificationType::NOTIFY_BALLOON_CONNECTED, |
| 103 Source<BalloonHost>(this), NotificationService::NoDetails()); | 129 Source<BalloonHost>(this), NotificationService::NoDetails()); |
| 104 } | 130 } |
| 105 | 131 |
| 106 void BalloonHost::RenderViewGone(RenderViewHost* render_view_host) { | 132 void BalloonHost::RenderViewGone(RenderViewHost* render_view_host) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 rvh->AllowBindings(BindingsPolicy::DOM_UI); | 217 rvh->AllowBindings(BindingsPolicy::DOM_UI); |
| 192 } | 218 } |
| 193 | 219 |
| 194 // Do platform-specific initialization. | 220 // Do platform-specific initialization. |
| 195 render_view_host_ = rvh; | 221 render_view_host_ = rvh; |
| 196 InitRenderWidgetHostView(); | 222 InitRenderWidgetHostView(); |
| 197 DCHECK(render_widget_host_view()); | 223 DCHECK(render_widget_host_view()); |
| 198 | 224 |
| 199 rvh->set_view(render_widget_host_view()); | 225 rvh->set_view(render_widget_host_view()); |
| 200 rvh->CreateRenderView(string16()); | 226 rvh->CreateRenderView(string16()); |
| 227 #if defined(OS_MACOSX) |
| 228 rvh->set_paint_observer(new BalloonPaintObserver(this)); |
| 229 #endif |
| 201 rvh->NavigateToURL(balloon_->notification().content_url()); | 230 rvh->NavigateToURL(balloon_->notification().content_url()); |
| 202 | 231 |
| 203 initialized_ = true; | 232 initialized_ = true; |
| 204 } | 233 } |
| 205 | 234 |
| 206 void BalloonHost::EnableDOMUI() { | 235 void BalloonHost::EnableDOMUI() { |
| 207 DCHECK(render_view_host_ == NULL) << | 236 DCHECK(render_view_host_ == NULL) << |
| 208 "EnableDOMUI has to be called before a renderer is created."; | 237 "EnableDOMUI has to be called before a renderer is created."; |
| 209 enable_dom_ui_ = true; | 238 enable_dom_ui_ = true; |
| 210 } | 239 } |
| 211 | 240 |
| 212 void BalloonHost::UpdateInspectorSetting(const std::string& key, | 241 void BalloonHost::UpdateInspectorSetting(const std::string& key, |
| 213 const std::string& value) { | 242 const std::string& value) { |
| 214 RenderViewHostDelegateHelper::UpdateInspectorSetting( | 243 RenderViewHostDelegateHelper::UpdateInspectorSetting( |
| 215 GetProfile(), key, value); | 244 GetProfile(), key, value); |
| 216 } | 245 } |
| 217 | 246 |
| 218 void BalloonHost::ClearInspectorSettings() { | 247 void BalloonHost::ClearInspectorSettings() { |
| 219 RenderViewHostDelegateHelper::ClearInspectorSettings(GetProfile()); | 248 RenderViewHostDelegateHelper::ClearInspectorSettings(GetProfile()); |
| 220 } | 249 } |
| 221 | 250 |
| 222 BalloonHost::~BalloonHost() {} | 251 void BalloonHost::RenderWidgetHostDidPaint() { |
| 252 render_view_host_->set_paint_observer(NULL); |
| 253 render_view_host_->EnablePreferredSizeChangedMode( |
| 254 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); |
| 255 } |
| 256 |
| 257 BalloonHost::~BalloonHost() { |
| 258 DCHECK(!render_view_host_); |
| 259 } |
| 223 | 260 |
| 224 void BalloonHost::NotifyDisconnect() { | 261 void BalloonHost::NotifyDisconnect() { |
| 225 if (!should_notify_on_disconnect_) | 262 if (!should_notify_on_disconnect_) |
| 226 return; | 263 return; |
| 227 | 264 |
| 228 should_notify_on_disconnect_ = false; | 265 should_notify_on_disconnect_ = false; |
| 229 NotificationService::current()->Notify( | 266 NotificationService::current()->Notify( |
| 230 NotificationType::NOTIFY_BALLOON_DISCONNECTED, | 267 NotificationType::NOTIFY_BALLOON_DISCONNECTED, |
| 231 Source<BalloonHost>(this), NotificationService::NoDetails()); | 268 Source<BalloonHost>(this), NotificationService::NoDetails()); |
| 232 } | 269 } |
| OLD | NEW |