Index: chrome/browser/notifications/balloon_contents_win.cc |
diff --git a/chrome/browser/notifications/balloon_contents_win.cc b/chrome/browser/notifications/balloon_contents_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..add319aa6fecf0baad47849e8d2669ec92757374 |
--- /dev/null |
+++ b/chrome/browser/notifications/balloon_contents_win.cc |
@@ -0,0 +1,129 @@ |
+// Copyright (c) 2009 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_contents_win.h" |
+ |
+#include "base/string_util.h" |
+#include "chrome/browser/browser_list.h" |
+#include "chrome/browser/notifications/balloons.h" |
+#include "chrome/browser/notifications/notification.h" |
+#include "chrome/browser/profile.h" |
+#include "chrome/browser/renderer_host/render_view_host.h" |
+#include "chrome/browser/renderer_host/render_widget_host_view_win.h" |
+#include "chrome/browser/renderer_host/site_instance.h" |
+#include "chrome/common/renderer_preferences.h" |
+#include "chrome/common/notification_type.h" |
+#include "chrome/common/notification_service.h" |
+#include "views/widget/widget.h" |
+#include "views/widget/widget_win.h" |
+ |
+BalloonContents::BalloonContents(Balloon* balloon) |
+ : balloon_(balloon), |
+ render_view_host_(NULL), |
+ notify_disconnection_(false), |
+ initialized_(false) { |
+ DCHECK(balloon); |
+} |
+ |
+void BalloonContents::Shutdown() { |
+ if (render_view_host_) { |
+ render_view_host_->Shutdown(); |
+ render_view_host_ = NULL; |
+ } |
+} |
+ |
+RendererPreferences BalloonContents::GetRendererPrefs() const { |
+ RendererPreferences prefs = RendererPreferences(); |
+ prefs.browser_handles_top_level_requests = true; |
+ return prefs; |
+} |
+ |
+WebPreferences BalloonContents::GetWebkitPrefs() { |
+ return WebPreferences(); |
+} |
+ |
+SiteInstance* BalloonContents::GetSiteInstance() const { |
+ return balloon_->site_instance(); |
+} |
+ |
+Profile* BalloonContents::GetProfile() const { |
+ return balloon_->profile(); |
+} |
+ |
+const GURL& BalloonContents::GetURL() const { |
+ return balloon_->notification().content_url(); |
+} |
+ |
+void BalloonContents::RequestOpenURL(const GURL& url, |
+ const GURL& referrer, |
+ WindowOpenDisposition disposition) { |
+ BrowserList::GetLastActive()->AddTabWithURL(url, referrer, PageTransition::LINK, true, 0, 0, GetSiteInstance()); |
+} |
+ |
+void BalloonContents::RendererReady(RenderViewHost* render_view_host) { |
+ NotifyConnected(); |
+} |
+ |
+void BalloonContents::RendererGone(RenderViewHost* render_view_host) { |
+ NotifyDisconnected(); |
+} |
+ |
+void BalloonContents::UpdateTitle(RenderViewHost* render_view_host, |
+ int32 page_id, |
+ const std::wstring& title) { |
+ title_ = title; |
+} |
+ |
+void BalloonContents::NotifyConnected() { |
+ notify_disconnection_ = true; |
+ NotificationService::current()->Notify(NotificationType::NOTIFY_BALLOON_CONNECTED, |
+ Source<Balloon>(balloon_), |
+ NotificationService::NoDetails()); |
+} |
+ |
+void BalloonContents::NotifyDisconnected() { |
+ if (!notify_disconnection_) { |
+ return; |
+ } |
+ notify_disconnection_ = false; |
+ NotificationService::current()->Notify(NotificationType::NOTIFY_BALLOON_DISCONNECTED, |
+ Source<Balloon>(balloon_), |
+ NotificationService::NoDetails()); |
+} |
+ |
+void BalloonContents::Init(HWND parent_hwnd) { |
+ DCHECK(!render_view_host_) << "Already initialized."; |
+ RenderViewHost* rvh = new RenderViewHost(balloon_->site_instance(), |
+ this, |
+ MSG_ROUTING_NONE, |
+ NULL); |
+ render_view_host_ = rvh; |
+ |
+ RenderWidgetHostViewWin* view = new RenderWidgetHostViewWin(rvh); |
+ rvh->set_view(view); |
+ |
+ // Create the HWND. Note: |
+ // RenderWidgetHostHWND supports windowed plugins, but if we ever also wanted |
+ // to support constrained windows with this, we would need an additional |
+ // HWND to parent off of because windowed plugin HWNDs cannot exist in the |
+ // same z-order as constrained windows. |
+ HWND hwnd = view->Create(parent_hwnd); |
+ view->ShowWindow(SW_SHOW); |
+ Attach(hwnd); |
+ |
+ // Start up the renderer. |
+ rvh->CreateRenderView(); |
+ rvh->NavigateToURL(balloon_->notification().content_url()); |
+ |
+ initialized_ = true; |
+} |
+ |
+void BalloonContents::ViewHierarchyChanged(bool is_add, views::View* parent, |
+ views::View* child) { |
+ |
+ NativeViewHost::ViewHierarchyChanged(is_add, parent, child); |
+ |
+ if (is_add && GetWidget() && !initialized_) |
+ Init(GetWidget()->GetNativeView()); |
+} |