OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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. |
| 4 |
| 5 #include "chrome/browser/notifications/balloon_contents_win.h" |
| 6 |
| 7 #include "base/string_util.h" |
| 8 #include "chrome/browser/browser_list.h" |
| 9 #include "chrome/browser/notifications/balloons.h" |
| 10 #include "chrome/browser/notifications/notification.h" |
| 11 #include "chrome/browser/profile.h" |
| 12 #include "chrome/browser/renderer_host/render_view_host.h" |
| 13 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" |
| 14 #include "chrome/browser/renderer_host/site_instance.h" |
| 15 #include "chrome/common/renderer_preferences.h" |
| 16 #include "chrome/common/notification_type.h" |
| 17 #include "chrome/common/notification_service.h" |
| 18 #include "views/widget/widget.h" |
| 19 #include "views/widget/widget_win.h" |
| 20 |
| 21 BalloonContents::BalloonContents(Balloon* balloon) |
| 22 : balloon_(balloon), |
| 23 render_view_host_(NULL), |
| 24 notify_disconnection_(false), |
| 25 initialized_(false) { |
| 26 DCHECK(balloon); |
| 27 } |
| 28 |
| 29 void BalloonContents::Shutdown() { |
| 30 if (render_view_host_) { |
| 31 render_view_host_->Shutdown(); |
| 32 render_view_host_ = NULL; |
| 33 } |
| 34 } |
| 35 |
| 36 RendererPreferences BalloonContents::GetRendererPrefs() const { |
| 37 RendererPreferences prefs = RendererPreferences(); |
| 38 prefs.browser_handles_top_level_requests = true; |
| 39 return prefs; |
| 40 } |
| 41 |
| 42 WebPreferences BalloonContents::GetWebkitPrefs() { |
| 43 return WebPreferences(); |
| 44 } |
| 45 |
| 46 SiteInstance* BalloonContents::GetSiteInstance() const { |
| 47 return balloon_->site_instance(); |
| 48 } |
| 49 |
| 50 Profile* BalloonContents::GetProfile() const { |
| 51 return balloon_->profile(); |
| 52 } |
| 53 |
| 54 const GURL& BalloonContents::GetURL() const { |
| 55 return balloon_->notification().content_url(); |
| 56 } |
| 57 |
| 58 void BalloonContents::RequestOpenURL(const GURL& url, |
| 59 const GURL& referrer, |
| 60 WindowOpenDisposition disposition) { |
| 61 BrowserList::GetLastActive()->AddTabWithURL(url, referrer, PageTransition::LIN
K, true, 0, 0, GetSiteInstance()); |
| 62 } |
| 63 |
| 64 void BalloonContents::RendererReady(RenderViewHost* render_view_host) { |
| 65 NotifyConnected(); |
| 66 } |
| 67 |
| 68 void BalloonContents::RendererGone(RenderViewHost* render_view_host) { |
| 69 NotifyDisconnected(); |
| 70 } |
| 71 |
| 72 void BalloonContents::UpdateTitle(RenderViewHost* render_view_host, |
| 73 int32 page_id, |
| 74 const std::wstring& title) { |
| 75 title_ = title; |
| 76 } |
| 77 |
| 78 void BalloonContents::NotifyConnected() { |
| 79 notify_disconnection_ = true; |
| 80 NotificationService::current()->Notify(NotificationType::NOTIFY_BALLOON_CONNEC
TED, |
| 81 Source<Balloon>(balloon_), |
| 82 NotificationService::NoDetails()); |
| 83 } |
| 84 |
| 85 void BalloonContents::NotifyDisconnected() { |
| 86 if (!notify_disconnection_) { |
| 87 return; |
| 88 } |
| 89 notify_disconnection_ = false; |
| 90 NotificationService::current()->Notify(NotificationType::NOTIFY_BALLOON_DISCON
NECTED, |
| 91 Source<Balloon>(balloon_), |
| 92 NotificationService::NoDetails()); |
| 93 } |
| 94 |
| 95 void BalloonContents::Init(HWND parent_hwnd) { |
| 96 DCHECK(!render_view_host_) << "Already initialized."; |
| 97 RenderViewHost* rvh = new RenderViewHost(balloon_->site_instance(), |
| 98 this, |
| 99 MSG_ROUTING_NONE, |
| 100 NULL); |
| 101 render_view_host_ = rvh; |
| 102 |
| 103 RenderWidgetHostViewWin* view = new RenderWidgetHostViewWin(rvh); |
| 104 rvh->set_view(view); |
| 105 |
| 106 // Create the HWND. Note: |
| 107 // RenderWidgetHostHWND supports windowed plugins, but if we ever also wanted |
| 108 // to support constrained windows with this, we would need an additional |
| 109 // HWND to parent off of because windowed plugin HWNDs cannot exist in the |
| 110 // same z-order as constrained windows. |
| 111 HWND hwnd = view->Create(parent_hwnd); |
| 112 view->ShowWindow(SW_SHOW); |
| 113 Attach(hwnd); |
| 114 |
| 115 // Start up the renderer. |
| 116 rvh->CreateRenderView(); |
| 117 rvh->NavigateToURL(balloon_->notification().content_url()); |
| 118 |
| 119 initialized_ = true; |
| 120 } |
| 121 |
| 122 void BalloonContents::ViewHierarchyChanged(bool is_add, views::View* parent, |
| 123 views::View* child) { |
| 124 |
| 125 NativeViewHost::ViewHierarchyChanged(is_add, parent, child); |
| 126 |
| 127 if (is_add && GetWidget() && !initialized_) |
| 128 Init(GetWidget()->GetNativeView()); |
| 129 } |
OLD | NEW |