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

Side by Side Diff: chrome/browser/ui/views/ash/balloon_view_ash.cc

Issue 11189099: Re-factor Ash Message Center code part 4/4 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 2 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
« no previous file with comments | « chrome/browser/ui/views/ash/balloon_collection_impl_ash.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/views/ash/balloon_view_ash.h" 5 #include "chrome/browser/ui/views/ash/balloon_view_ash.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/web_notification/message_center.h"
8 #include "ash/system/web_notification/web_notification_tray.h" 9 #include "ash/system/web_notification/web_notification_tray.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/favicon/favicon_util.h" 12 #include "chrome/browser/favicon/favicon_util.h"
12 #include "chrome/browser/notifications/balloon_collection.h" 13 #include "chrome/browser/notifications/balloon_collection.h"
13 #include "chrome/browser/notifications/notification.h" 14 #include "chrome/browser/notifications/notification.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/icon_messages.h" 16 #include "chrome/common/icon_messages.h"
16 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
17 #include "content/public/browser/render_view_host.h" 18 #include "content/public/browser/render_view_host.h"
18 #include "content/public/browser/site_instance.h" 19 #include "content/public/browser/site_instance.h"
19 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
20 #include "content/public/browser/web_contents_delegate.h" 21 #include "content/public/browser/web_contents_delegate.h"
21 #include "content/public/browser/web_contents_observer.h" 22 #include "content/public/browser/web_contents_observer.h"
22 #include "ipc/ipc_message.h" 23 #include "ipc/ipc_message.h"
23 #include "ipc/ipc_message_macros.h" 24 #include "ipc/ipc_message_macros.h"
24 #include "ui/gfx/image/image_skia.h" 25 #include "ui/gfx/image/image_skia.h"
25 #include "webkit/glue/image_resource_fetcher.h" 26 #include "webkit/glue/image_resource_fetcher.h"
26 27
27 namespace { 28 namespace {
28 29
29 const int kNotificationIconImageSize = 32; 30 const int kNotificationIconImageSize = 32;
30 31
31 ash::WebNotificationTray* GetWebNotificationTray() { 32 message_center::MessageCenter* GetMessageCenter() {
32 return ash::Shell::GetInstance()->GetWebNotificationTray(); 33 return ash::Shell::GetInstance()->GetWebNotificationTray()->message_center();
33 } 34 }
34 35
35 } // namespace 36 } // namespace
36 37
37 class BalloonViewAsh::IconFetcher : public content::WebContentsObserver { 38 class BalloonViewAsh::IconFetcher : public content::WebContentsObserver {
38 public: 39 public:
39 IconFetcher(content::WebContents* web_contents, 40 IconFetcher(content::WebContents* web_contents,
40 const std::string& notification_id, 41 const std::string& notification_id,
41 const GURL& icon_url) 42 const GURL& icon_url)
42 : content::WebContentsObserver(web_contents), 43 : content::WebContentsObserver(web_contents),
(...skipping 17 matching lines...) Expand all
60 return message_handled; 61 return message_handled;
61 } 62 }
62 63
63 void OnDidDownloadFavicon(int id, 64 void OnDidDownloadFavicon(int id,
64 const GURL& image_url, 65 const GURL& image_url,
65 bool errored, 66 bool errored,
66 int requested_size, 67 int requested_size,
67 const std::vector<SkBitmap>& bitmaps) { 68 const std::vector<SkBitmap>& bitmaps) {
68 if (image_url != icon_url_ || id != request_id_ || bitmaps.empty()) 69 if (image_url != icon_url_ || id != request_id_ || bitmaps.empty())
69 return; 70 return;
70 GetWebNotificationTray()->SetNotificationImage( 71 GetMessageCenter()->SetNotificationImage(
71 notification_id_, gfx::ImageSkia(bitmaps[0])); 72 notification_id_, gfx::ImageSkia(bitmaps[0]));
72 } 73 }
73 74
74 private: 75 private:
75 int request_id_; 76 int request_id_;
76 std::string notification_id_; 77 std::string notification_id_;
77 GURL icon_url_; 78 GURL icon_url_;
78 79
79 DISALLOW_COPY_AND_ASSIGN(IconFetcher); 80 DISALLOW_COPY_AND_ASSIGN(IconFetcher);
80 }; 81 };
81 82
82 BalloonViewAsh::BalloonViewAsh(BalloonCollection* collection) 83 BalloonViewAsh::BalloonViewAsh(BalloonCollection* collection)
83 : collection_(collection), 84 : collection_(collection),
84 balloon_(NULL) { 85 balloon_(NULL) {
85 } 86 }
86 87
87 BalloonViewAsh::~BalloonViewAsh() { 88 BalloonViewAsh::~BalloonViewAsh() {
88 } 89 }
89 90
90 // BalloonView interface. 91 // BalloonView interface.
91 void BalloonViewAsh::Show(Balloon* balloon) { 92 void BalloonViewAsh::Show(Balloon* balloon) {
92 balloon_ = balloon; 93 balloon_ = balloon;
93 const Notification& notification = balloon_->notification(); 94 const Notification& notification = balloon_->notification();
94 current_notification_id_ = notification.notification_id(); 95 current_notification_id_ = notification.notification_id();
95 std::string extension_id = GetExtensionId(balloon); 96 std::string extension_id = GetExtensionId(balloon);
96 GetWebNotificationTray()->AddNotification(current_notification_id_, 97 GetMessageCenter()->AddNotification(current_notification_id_,
97 notification.title(), 98 notification.title(),
98 notification.body(), 99 notification.body(),
99 notification.display_source(), 100 notification.display_source(),
100 extension_id); 101 extension_id);
101 FetchIcon(notification); 102 FetchIcon(notification);
102 } 103 }
103 104
104 void BalloonViewAsh::Update() { 105 void BalloonViewAsh::Update() {
105 const Notification& notification = balloon_->notification(); 106 const Notification& notification = balloon_->notification();
106 std::string new_notification_id = notification.notification_id(); 107 std::string new_notification_id = notification.notification_id();
107 GetWebNotificationTray()->UpdateNotification(current_notification_id_, 108 GetMessageCenter()->UpdateNotification(current_notification_id_,
108 new_notification_id, 109 new_notification_id,
109 notification.title(), 110 notification.title(),
110 notification.body()); 111 notification.body());
111 current_notification_id_ = new_notification_id; 112 current_notification_id_ = new_notification_id;
112 FetchIcon(notification); 113 FetchIcon(notification);
113 } 114 }
114 115
115 void BalloonViewAsh::RepositionToBalloon() { 116 void BalloonViewAsh::RepositionToBalloon() {
116 } 117 }
117 118
118 void BalloonViewAsh::Close(bool by_user) { 119 void BalloonViewAsh::Close(bool by_user) {
119 Notification notification(balloon_->notification()); // Copy notification 120 Notification notification(balloon_->notification()); // Copy notification
120 collection_->OnBalloonClosed(balloon_); // Deletes balloon. 121 collection_->OnBalloonClosed(balloon_); // Deletes balloon.
121 notification.Close(by_user); 122 notification.Close(by_user);
122 GetWebNotificationTray()->RemoveNotification(notification.notification_id()); 123 GetMessageCenter()->RemoveNotification(notification.notification_id());
123 } 124 }
124 125
125 gfx::Size BalloonViewAsh::GetSize() const { 126 gfx::Size BalloonViewAsh::GetSize() const {
126 return gfx::Size(); 127 return gfx::Size();
127 } 128 }
128 129
129 BalloonHost* BalloonViewAsh::GetHost() const { 130 BalloonHost* BalloonViewAsh::GetHost() const {
130 return NULL; 131 return NULL;
131 } 132 }
132 133
133 void BalloonViewAsh::FetchIcon(const Notification& notification) { 134 void BalloonViewAsh::FetchIcon(const Notification& notification) {
134 if (!notification.icon().isNull()) { 135 if (!notification.icon().isNull()) {
135 ash::Shell::GetInstance()->GetWebNotificationTray()->SetNotificationImage( 136 GetMessageCenter()->SetNotificationImage(
136 notification.notification_id(), notification.icon()); 137 notification.notification_id(), notification.icon());
137 return; 138 return;
138 } 139 }
139 if (notification.icon_url().is_empty()) 140 if (notification.icon_url().is_empty())
140 return; 141 return;
141 content::RenderViewHost* rvh = notification.GetRenderViewHost(); 142 content::RenderViewHost* rvh = notification.GetRenderViewHost();
142 if (!rvh) { 143 if (!rvh) {
143 LOG(WARNING) << "Notification has icon url but no RenderViewHost"; 144 LOG(WARNING) << "Notification has icon url but no RenderViewHost";
144 return; 145 return;
145 } 146 }
(...skipping 12 matching lines...) Expand all
158 ExtensionService* extension_service = 159 ExtensionService* extension_service =
159 balloon_->profile()->GetExtensionService(); 160 balloon_->profile()->GetExtensionService();
160 const GURL& origin = balloon_->notification().origin_url(); 161 const GURL& origin = balloon_->notification().origin_url();
161 const extensions::Extension* extension = 162 const extensions::Extension* extension =
162 extension_service->extensions()->GetExtensionOrAppByURL( 163 extension_service->extensions()->GetExtensionOrAppByURL(
163 ExtensionURLInfo(origin)); 164 ExtensionURLInfo(origin));
164 if (extension) 165 if (extension)
165 return extension->id(); 166 return extension->id();
166 return std::string(); 167 return std::string();
167 } 168 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/ash/balloon_collection_impl_ash.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698