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

Side by Side Diff: chrome/browser/views/notifications/balloon_view_host.cc

Issue 338051: Adds UI components for desktop notifications, including balloon view classes ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: use notused.png resources for try servers Created 11 years, 1 month 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
« no previous file with comments | « chrome/browser/views/notifications/balloon_view_host.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/views/notifications/balloon_view_host.h"
6
7 #include "base/string_util.h"
8 #include "chrome/browser/browser_list.h"
9 #include "chrome/browser/notifications/balloon.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.h"
14 #if defined(OS_WIN)
15 #include "chrome/browser/renderer_host/render_widget_host_view_win.h"
16 #endif
17 #include "chrome/browser/renderer_host/site_instance.h"
18 #include "chrome/common/notification_service.h"
19 #include "chrome/common/notification_type.h"
20 #include "chrome/common/renderer_preferences.h"
21 #include "views/widget/widget.h"
22 #include "views/widget/widget_win.h"
23
24 BalloonViewHost::BalloonViewHost(Balloon* balloon)
25 : balloon_(balloon),
26 site_instance_(SiteInstance::CreateSiteInstance(balloon->profile())),
27 render_view_host_(NULL),
28 should_notify_on_disconnect_(false),
29 initialized_(false) {
30 DCHECK(balloon_);
31 }
32
33 void BalloonViewHost::Shutdown() {
34 if (render_view_host_) {
35 render_view_host_->Shutdown();
36 render_view_host_ = NULL;
37 }
38 }
39
40 RendererPreferences BalloonViewHost::GetRendererPrefs() const {
41 // We want links (a.k.a. top_level_requests) to be forwarded to the browser so
42 // that we can open them in a new tab rather than in the balloon.
43 RendererPreferences prefs = RendererPreferences();
44 prefs.browser_handles_top_level_requests = true;
45 return prefs;
46 }
47
48 void BalloonViewHost::RequestOpenURL(const GURL& url,
49 const GURL& referrer,
50 WindowOpenDisposition disposition) {
51 // Always open a link triggered within the notification balloon in a new tab.
52 BrowserList::GetLastActive()->AddTabWithURL(url, referrer,
53 PageTransition::LINK, true, 0, 0, GetSiteInstance());
54 }
55
56 void BalloonViewHost::RendererReady(RenderViewHost* /* render_view_host */) {
57 should_notify_on_disconnect_ = true;
58 NotificationService::current()->Notify(
59 NotificationType::NOTIFY_BALLOON_CONNECTED,
60 Source<Balloon>(balloon_), NotificationService::NoDetails());
61 }
62
63 void BalloonViewHost::RendererGone(RenderViewHost* /* render_view_host */) {
64 if (!should_notify_on_disconnect_)
65 return;
66
67 should_notify_on_disconnect_ = false;
68 NotificationService::current()->Notify(
69 NotificationType::NOTIFY_BALLOON_DISCONNECTED,
70 Source<Balloon>(balloon_), NotificationService::NoDetails());
71 }
72
73 void BalloonViewHost::Init(gfx::NativeView parent_hwnd) {
74 DCHECK(!render_view_host_) << "BalloonViewHost already initialized.";
75 RenderViewHost* rvh = new RenderViewHost(site_instance_.get(),
76 this, MSG_ROUTING_NONE);
77 render_view_host_ = rvh;
78
79 // Pointer is owned by the RVH.
80 RenderWidgetHostView* view = RenderWidgetHostView::CreateViewForWidget(rvh);
81 rvh->set_view(view);
82
83 // TODO(johnnyg): http://crbug.com/23954. Need a cross-platform solution.
84 #if defined(OS_WIN)
85 RenderWidgetHostViewWin* view_win =
86 static_cast<RenderWidgetHostViewWin*>(view);
87
88 // Create the HWND.
89 HWND hwnd = view_win->Create(parent_hwnd);
90 view_win->ShowWindow(SW_SHOW);
91 Attach(hwnd);
92 #else
93 NOTIMPLEMENTED();
94 #endif
95
96 // Start up the renderer and point it at the balloon contents URL.
97 rvh->CreateRenderView();
98 rvh->NavigateToURL(balloon_->notification().content_url());
99 initialized_ = true;
100 }
101
102 void BalloonViewHost::ViewHierarchyChanged(bool is_add, views::View* parent,
103 views::View* child) {
104 NativeViewHost::ViewHierarchyChanged(is_add, parent, child);
105 if (is_add && GetWidget() && !initialized_)
106 Init(GetWidget()->GetNativeView());
107 }
OLDNEW
« no previous file with comments | « chrome/browser/views/notifications/balloon_view_host.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698