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

Side by Side Diff: chrome/browser/notifications/sync_notifier/synced_notification.cc

Issue 19771013: Adapting the UI to bring it closer to the spec, and fixing image fetching. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adapting the UI: fix unit tests Created 7 years, 5 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
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/notifications/sync_notifier/synced_notification.h" 5 #include "chrome/browser/notifications/sync_notifier/synced_notification.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/strings/string_util.h"
8 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
9 #include "base/time/time.h" 10 #include "base/time/time.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/notifications/notification.h" 13 #include "chrome/browser/notifications/notification.h"
13 #include "chrome/browser/notifications/notification_ui_manager.h" 14 #include "chrome/browser/notifications/notification_ui_manager.h"
14 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h" 15 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "sync/protocol/sync.pb.h" 17 #include "sync/protocol/sync.pb.h"
17 #include "sync/protocol/synced_notification_specifics.pb.h" 18 #include "sync/protocol/synced_notification_specifics.pb.h"
18 #include "ui/gfx/image/image.h" 19 #include "ui/gfx/image/image.h"
19 #include "ui/message_center/message_center_util.h" 20 #include "ui/message_center/message_center_util.h"
20 #include "ui/message_center/notification_types.h" 21 #include "ui/message_center/notification_types.h"
21 22
22 namespace { 23 namespace {
23 const char kExtensionScheme[] = "chrome-extension://"; 24 const char kExtensionScheme[] = "chrome-extension://";
25 const char kDefaultSyncedNotificationScheme[] = "https:";
24 26
25 // Today rich notifications only supports two buttons, make sure we don't 27 // Today rich notifications only supports two buttons, make sure we don't
26 // try to supply them with more than this number of buttons. 28 // try to supply them with more than this number of buttons.
27 const unsigned int kMaxNotificationButtonIndex = 2; 29 const unsigned int kMaxNotificationButtonIndex = 2;
28 30
29 bool UseRichNotifications() { 31 bool UseRichNotifications() {
30 return message_center::IsRichNotificationEnabled(); 32 return message_center::IsRichNotificationEnabled();
31 } 33 }
32 34
35 // Schema-less specs default badly in windows. If we find one, add the schema
36 // we expect instead of allowing windows specific GURL code to make it default
37 // to "file:".
38 GURL AddDefaultSchemaIfNeeded(std::string& url_spec) {
39 if (StartsWithASCII(url_spec, std::string("//"), false))
40 return GURL(std::string(kDefaultSyncedNotificationScheme) + url_spec);
41
42 return GURL(url_spec);
43 }
44
33 } // namespace 45 } // namespace
34 46
35 namespace notifier { 47 namespace notifier {
36 48
37 COMPILE_ASSERT(static_cast<sync_pb::CoalescedSyncedNotification_ReadState>( 49 COMPILE_ASSERT(static_cast<sync_pb::CoalescedSyncedNotification_ReadState>(
38 SyncedNotification::kUnread) == 50 SyncedNotification::kUnread) ==
39 sync_pb::CoalescedSyncedNotification_ReadState_UNREAD, 51 sync_pb::CoalescedSyncedNotification_ReadState_UNREAD,
40 local_enum_must_match_protobuf_enum); 52 local_enum_must_match_protobuf_enum);
41 COMPILE_ASSERT(static_cast<sync_pb::CoalescedSyncedNotification_ReadState>( 53 COMPILE_ASSERT(static_cast<sync_pb::CoalescedSyncedNotification_ReadState>(
42 SyncedNotification::kRead) == 54 SyncedNotification::kRead) ==
(...skipping 26 matching lines...) Expand all
69 } 81 }
70 82
71 void SyncedNotification::OnFetchComplete(const GURL url, 83 void SyncedNotification::OnFetchComplete(const GURL url,
72 const SkBitmap* bitmap) { 84 const SkBitmap* bitmap) {
73 // TODO(petewil): Add timeout mechanism in case bitmaps take too long. Do we 85 // TODO(petewil): Add timeout mechanism in case bitmaps take too long. Do we
74 // already have one built into URLFetcher? 86 // already have one built into URLFetcher?
75 // Make sure we are on the thread we expect. 87 // Make sure we are on the thread we expect.
76 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 88 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
77 89
78 // Match the incoming bitmaps to URLs. In case this is a dup, make sure to 90 // Match the incoming bitmaps to URLs. In case this is a dup, make sure to
79 // Try all potentially matching urls. 91 // try all potentially matching urls.
80 if (GetAppIconUrl() == url && bitmap != NULL) { 92 if (GetAppIconUrl() == url && bitmap != NULL) {
81 app_icon_bitmap_ = gfx::Image::CreateFrom1xBitmap(*bitmap); 93 app_icon_bitmap_ = gfx::Image::CreateFrom1xBitmap(*bitmap);
82 } 94 }
83 if (GetImageUrl() == url && bitmap != NULL) { 95 if (GetImageUrl() == url && bitmap != NULL) {
84 image_bitmap_ = gfx::Image::CreateFrom1xBitmap(*bitmap); 96 image_bitmap_ = gfx::Image::CreateFrom1xBitmap(*bitmap);
85 } 97 }
98 if (GetProfilePictureUrl(0) == url && bitmap != NULL) {
99 sender_bitmap_ = gfx::Image::CreateFrom1xBitmap(*bitmap);
100 }
86 101
87 // If this URL matches one or more button bitmaps, save them off. 102 // If this URL matches one or more button bitmaps, save them off.
88 for (unsigned int i = 0; i < GetButtonCount(); ++i) { 103 for (unsigned int i = 0; i < GetButtonCount(); ++i) {
89 if (GetButtonIconUrl(i) == url && bitmap != NULL) 104 if (GetButtonIconUrl(i) == url && bitmap != NULL)
90 button_bitmaps_[i] = gfx::Image::CreateFrom1xBitmap(*bitmap); 105 button_bitmaps_[i] = gfx::Image::CreateFrom1xBitmap(*bitmap);
91 } 106 }
92 107
93 // Count off the bitmaps as they arrive. 108 // Count off the bitmaps as they arrive.
94 --active_fetcher_count_; 109 --active_fetcher_count_;
95 DCHECK_GE(active_fetcher_count_, 0); 110 DCHECK_GE(active_fetcher_count_, 0);
(...skipping 20 matching lines...) Expand all
116 profile_ = profile; 131 profile_ = profile;
117 DCHECK_EQ(active_fetcher_count_, 0); 132 DCHECK_EQ(active_fetcher_count_, 0);
118 133
119 // Ensure our bitmap vector has as many entries as there are buttons, 134 // Ensure our bitmap vector has as many entries as there are buttons,
120 // so that when the bitmaps arrive the vector has a slot for them. 135 // so that when the bitmaps arrive the vector has a slot for them.
121 for (unsigned int i = 0; i < GetButtonCount(); ++i) { 136 for (unsigned int i = 0; i < GetButtonCount(); ++i) {
122 button_bitmaps_.push_back(gfx::Image()); 137 button_bitmaps_.push_back(gfx::Image());
123 AddBitmapToFetchQueue(GetButtonIconUrl(i)); 138 AddBitmapToFetchQueue(GetButtonIconUrl(i));
124 } 139 }
125 140
141 // If there is a profile image bitmap, fetch it
142 if (GetProfilePictureCount() > 0) {
143 // TODO(petewil): When we have the capacity to display more than one bitmap,
144 // modify this code to fetch as many as we can display
145 AddBitmapToFetchQueue(GetProfilePictureUrl(0));
146 }
147
126 // If the URL is non-empty, add it to our queue of URLs to fetch. 148 // If the URL is non-empty, add it to our queue of URLs to fetch.
127 AddBitmapToFetchQueue(GetAppIconUrl()); 149 AddBitmapToFetchQueue(GetAppIconUrl());
128 AddBitmapToFetchQueue(GetImageUrl()); 150 AddBitmapToFetchQueue(GetImageUrl());
129 151
130 // If there are no bitmaps, call show now. 152 // If there are no bitmaps, call show now.
131 if (active_fetcher_count_ == 0) { 153 if (active_fetcher_count_ == 0) {
132 Show(notification_manager, notifier_service, profile); 154 Show(notification_manager, notifier_service, profile);
133 } 155 }
134 } 156 }
135 157
(...skipping 28 matching lines...) Expand all
164 notification_manager->CancelById(GetKey()); 186 notification_manager->CancelById(GetKey());
165 DVLOG(2) << "Dismissed notification arrived" 187 DVLOG(2) << "Dismissed notification arrived"
166 << GetHeading() << " " << GetText(); 188 << GetHeading() << " " << GetText();
167 return; 189 return;
168 } 190 }
169 191
170 // Set up the fields we need to send and create a Notification object. 192 // Set up the fields we need to send and create a Notification object.
171 GURL image_url = GetImageUrl(); 193 GURL image_url = GetImageUrl();
172 string16 text = UTF8ToUTF16(GetText()); 194 string16 text = UTF8ToUTF16(GetText());
173 string16 heading = UTF8ToUTF16(GetHeading()); 195 string16 heading = UTF8ToUTF16(GetHeading());
196 string16 description = UTF8ToUTF16(GetDescription());
197 string16 annotation = UTF8ToUTF16(GetAnnotation());
174 // TODO(petewil): Eventually put the display name of the sending service here. 198 // TODO(petewil): Eventually put the display name of the sending service here.
175 string16 display_source = UTF8ToUTF16(GetOriginUrl().spec()); 199 string16 display_source = UTF8ToUTF16(GetOriginUrl().spec());
176 string16 replace_key = UTF8ToUTF16(GetKey()); 200 string16 replace_key = UTF8ToUTF16(GetKey());
201 string16 notification_heading = heading;
202 string16 notification_text = text;
177 203
178 // The delegate will eventually catch calls that the notification 204 // The delegate will eventually catch calls that the notification
179 // was read or deleted, and send the changes back to the server. 205 // was read or deleted, and send the changes back to the server.
180 scoped_refptr<NotificationDelegate> delegate = 206 scoped_refptr<NotificationDelegate> delegate =
181 new ChromeNotifierDelegate(GetKey(), notifier_service); 207 new ChromeNotifierDelegate(GetKey(), notifier_service);
182 208
183 // Some inputs and fields are only used if there is a notification center. 209 // Some inputs and fields are only used if there is a notification center.
184 if (UseRichNotifications()) { 210 if (UseRichNotifications()) {
185 base::Time creation_time = 211 base::Time creation_time =
186 base::Time::FromDoubleT(static_cast<double>(GetCreationTime())); 212 base::Time::FromDoubleT(static_cast<double>(GetCreationTime()));
(...skipping 15 matching lines...) Expand all
202 // Fill the optional fields with the information we need to make a 228 // Fill the optional fields with the information we need to make a
203 // notification. 229 // notification.
204 message_center::RichNotificationData rich_notification_data; 230 message_center::RichNotificationData rich_notification_data;
205 rich_notification_data.timestamp = creation_time; 231 rich_notification_data.timestamp = creation_time;
206 if (priority != SyncedNotification::kUndefinedPriority) 232 if (priority != SyncedNotification::kUndefinedPriority)
207 rich_notification_data.priority = priority; 233 rich_notification_data.priority = priority;
208 234
209 // Fill in the button data. 235 // Fill in the button data.
210 // TODO(petewil): Today Rich notifiations are limited to two buttons. 236 // TODO(petewil): Today Rich notifiations are limited to two buttons.
211 // When rich notifications supports more, remove the 237 // When rich notifications supports more, remove the
212 // "&& i < kMaxNotificationButtonIndex" below. 238 // "&& i < kMaxNotificationButtonIndex" clause below.
213 for (unsigned int i = 0; 239 for (unsigned int i = 0;
214 i < button_count 240 i < button_count
215 && i < button_bitmaps_.size() 241 && i < button_bitmaps_.size()
216 && i < kMaxNotificationButtonIndex; 242 && i < kMaxNotificationButtonIndex;
217 ++i) { 243 ++i) {
218 // Stop at the first button with no title 244 // Stop at the first button with no title
219 std::string title = GetButtonTitle(i); 245 std::string title = GetButtonTitle(i);
220 if (title.empty()) 246 if (title.empty())
221 break; 247 break;
222 message_center::ButtonInfo button_info(UTF8ToUTF16(title)); 248 message_center::ButtonInfo button_info(UTF8ToUTF16(title));
223 if (!button_bitmaps_[i].IsEmpty()) 249 if (!button_bitmaps_[i].IsEmpty())
224 button_info.icon = button_bitmaps_[i]; 250 button_info.icon = button_bitmaps_[i];
225 rich_notification_data.buttons.push_back(button_info); 251 rich_notification_data.buttons.push_back(button_info);
226 } 252 }
227 253
228 // Fill in the bitmap images. 254 // Fill in the bitmap images.
229 if (!image_bitmap_.IsEmpty()) 255 if (!image_bitmap_.IsEmpty())
230 rich_notification_data.image = image_bitmap_; 256 rich_notification_data.image = image_bitmap_;
231 257
232 // Fill the individual notification fields for a multiple notification. 258 // Fill the individual notification fields for a multiple notification.
233 if (notification_count > 1) { 259 if (notification_count > 1) {
234 for (int ii = 0; ii < notification_count; ++ii) { 260 for (int ii = 0; ii < notification_count; ++ii) {
235 message_center::NotificationItem item( 261 message_center::NotificationItem item(
236 UTF8ToUTF16(GetContainedNotificationTitle(ii)), 262 UTF8ToUTF16(GetContainedNotificationTitle(ii)),
237 UTF8ToUTF16(GetContainedNotificationMessage(ii))); 263 UTF8ToUTF16(GetContainedNotificationMessage(ii)));
238 rich_notification_data.items.push_back(item); 264 rich_notification_data.items.push_back(item);
239 } 265 }
240 } 266 }
241 267
268 // Set the heading and text appropriately for the message type.
269 notification_text = annotation;
270 if (notification_type == message_center::NOTIFICATION_TYPE_IMAGE) {
271 // For an image, fill in the description field.
272 notification_text = description;
273 } else if (notification_count == 1) {
274 // For a single collapsed info entry, use the contained message if any.
275 std::string comment_body = GetContainedNotificationMessage(0);
276 std::string comment_header = GetContainedNotificationTitle(0);
277 if (!comment_header.empty() && !comment_body.empty())
278 notification_text = UTF8ToUTF16(comment_header) + UTF8ToUTF16(" ") +
279 UTF8ToUTF16(comment_body);
280 }
281
282 // If there is a single person sending, use their picture instead of the app
283 // icon.
284 // TODO(petewil): Someday combine multiple profile photos here.
285 gfx::Image icon_bitmap = app_icon_bitmap_;
286 if (GetProfilePictureCount() == 1) {
287 icon_bitmap = sender_bitmap_;
288 }
289
242 Notification ui_notification(notification_type, 290 Notification ui_notification(notification_type,
243 GetOriginUrl(), 291 GetOriginUrl(),
244 heading, 292 notification_heading,
245 text, 293 notification_text,
246 app_icon_bitmap_, 294 icon_bitmap,
247 WebKit::WebTextDirectionDefault, 295 WebKit::WebTextDirectionDefault,
248 display_source, 296 display_source,
249 replace_key, 297 replace_key,
250 rich_notification_data, 298 rich_notification_data,
251 delegate.get()); 299 delegate.get());
252 notification_manager->Add(ui_notification, profile); 300 notification_manager->Add(ui_notification, profile);
253 } else { 301 } else {
254 302 // In this case we have a Webkit Notification, not a Rich Notification.
255 Notification ui_notification(GetOriginUrl(), 303 Notification ui_notification(GetOriginUrl(),
256 GetAppIconUrl(), 304 GetAppIconUrl(),
257 heading, 305 notification_heading,
258 text, 306 notification_text,
259 WebKit::WebTextDirectionDefault, 307 WebKit::WebTextDirectionDefault,
260 display_source, 308 display_source,
261 replace_key, 309 replace_key,
262 delegate.get()); 310 delegate.get());
263 311
264 notification_manager->Add(ui_notification, profile); 312 notification_manager->Add(ui_notification, profile);
265 } 313 }
266 314
267 DVLOG(1) << "Showing Synced Notification! " << heading << " " << text 315 DVLOG(1) << "Showing Synced Notification! " << heading << " " << text
268 << " " << GetAppIconUrl() << " " << replace_key << " " 316 << " " << GetAppIconUrl() << " " << replace_key << " "
269 << GetReadState(); 317 << GetReadState();
270 318
271 return; 319 return;
272 } 320 }
273 321
274 // This should detect even small changes in case the server updated the 322 // This should detect even small changes in case the server updated the
275 // notification. 323 // notification. We ignore the timestamp if other fields match.
276 // TODO(petewil): Should I also ignore the timestamp if other fields match?
277 bool SyncedNotification::EqualsIgnoringReadState( 324 bool SyncedNotification::EqualsIgnoringReadState(
278 const SyncedNotification& other) const { 325 const SyncedNotification& other) const {
279 if (GetTitle() == other.GetTitle() && 326 if (GetTitle() == other.GetTitle() &&
280 GetHeading() == other.GetHeading() && 327 GetHeading() == other.GetHeading() &&
281 GetDescription() == other.GetDescription() && 328 GetDescription() == other.GetDescription() &&
329 GetAnnotation() == other.GetAnnotation() &&
282 GetAppId() == other.GetAppId() && 330 GetAppId() == other.GetAppId() &&
283 GetKey() == other.GetKey() && 331 GetKey() == other.GetKey() &&
284 GetOriginUrl() == other.GetOriginUrl() && 332 GetOriginUrl() == other.GetOriginUrl() &&
285 GetAppIconUrl() == other.GetAppIconUrl() && 333 GetAppIconUrl() == other.GetAppIconUrl() &&
286 GetImageUrl() == other.GetImageUrl() && 334 GetImageUrl() == other.GetImageUrl() &&
287 GetText() == other.GetText() && 335 GetText() == other.GetText() &&
288 // We intentionally skip read state 336 // We intentionally skip read state
289 GetCreationTime() == other.GetCreationTime() && 337 GetCreationTime() == other.GetCreationTime() &&
290 GetPriority() == other.GetPriority() && 338 GetPriority() == other.GetPriority() &&
291 GetDefaultDestinationTitle() == other.GetDefaultDestinationTitle() && 339 GetDefaultDestinationTitle() == other.GetDefaultDestinationTitle() &&
292 GetDefaultDestinationIconUrl() == other.GetDefaultDestinationIconUrl() && 340 GetDefaultDestinationIconUrl() == other.GetDefaultDestinationIconUrl() &&
293 GetNotificationCount() == other.GetNotificationCount() && 341 GetNotificationCount() == other.GetNotificationCount() &&
294 GetButtonCount() == other.GetButtonCount()) { 342 GetButtonCount() == other.GetButtonCount() &&
343 GetProfilePictureCount() == other.GetProfilePictureCount()) {
295 344
296 // If all the surface data matched, check, to see if contained data also 345 // If all the surface data matched, check, to see if contained data also
297 // matches, titles and messages. 346 // matches, titles and messages.
298 size_t count = GetNotificationCount(); 347 size_t count = GetNotificationCount();
299 for (size_t ii = 0; ii < count; ++ii) { 348 for (size_t ii = 0; ii < count; ++ii) {
300 if (GetContainedNotificationTitle(ii) != 349 if (GetContainedNotificationTitle(ii) !=
301 other.GetContainedNotificationTitle(ii)) 350 other.GetContainedNotificationTitle(ii))
302 return false; 351 return false;
303 if (GetContainedNotificationMessage(ii) != 352 if (GetContainedNotificationMessage(ii) !=
304 other.GetContainedNotificationMessage(ii)) 353 other.GetContainedNotificationMessage(ii))
305 return false; 354 return false;
306 } 355 }
307 356
308 // Make sure buttons match. 357 // Make sure buttons match.
309 count = GetButtonCount(); 358 count = GetButtonCount();
310 for (size_t jj = 0; jj < count; ++jj) { 359 for (size_t jj = 0; jj < count; ++jj) {
311 if (GetButtonTitle(jj) != other.GetButtonTitle(jj)) 360 if (GetButtonTitle(jj) != other.GetButtonTitle(jj))
312 return false; 361 return false;
313 if (GetButtonIconUrl(jj) != other.GetButtonIconUrl(jj)) 362 if (GetButtonIconUrl(jj) != other.GetButtonIconUrl(jj))
314 return false; 363 return false;
315 } 364 }
316 365
366 // Make sure profile icons match
367 count = GetButtonCount();
368 for (size_t kk = 0; kk < count; ++kk) {
369 if (GetProfilePictureUrl(kk) != other.GetProfilePictureUrl(kk))
370 return false;
371 }
372
317 // If buttons and notifications matched, they are equivalent. 373 // If buttons and notifications matched, they are equivalent.
318 return true; 374 return true;
319 } 375 }
320 376
321 return false; 377 return false;
322 } 378 }
323 379
324 // Set the read state on the notification, returns true for success. 380 // Set the read state on the notification, returns true for success.
325 void SyncedNotification::SetReadState(const ReadState& read_state) { 381 void SyncedNotification::SetReadState(const ReadState& read_state) {
326 382
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 418
363 std::string SyncedNotification::GetDescription() const { 419 std::string SyncedNotification::GetDescription() const {
364 if (!specifics_.coalesced_notification().render_info().collapsed_info(). 420 if (!specifics_.coalesced_notification().render_info().collapsed_info().
365 simple_collapsed_layout().has_description()) 421 simple_collapsed_layout().has_description())
366 return std::string(); 422 return std::string();
367 423
368 return specifics_.coalesced_notification().render_info().collapsed_info(). 424 return specifics_.coalesced_notification().render_info().collapsed_info().
369 simple_collapsed_layout().description(); 425 simple_collapsed_layout().description();
370 } 426 }
371 427
428 std::string SyncedNotification::GetAnnotation() const {
429 if (!specifics_.coalesced_notification().render_info().collapsed_info().
430 simple_collapsed_layout().has_annotation())
431 return std::string();
432
433 return specifics_.coalesced_notification().render_info().collapsed_info().
434 simple_collapsed_layout().annotation();
435 }
436
372 std::string SyncedNotification::GetAppId() const { 437 std::string SyncedNotification::GetAppId() const {
373 if (!specifics_.coalesced_notification().has_app_id()) 438 if (!specifics_.coalesced_notification().has_app_id())
374 return std::string(); 439 return std::string();
375 return specifics_.coalesced_notification().app_id(); 440 return specifics_.coalesced_notification().app_id();
376 } 441 }
377 442
378 std::string SyncedNotification::GetKey() const { 443 std::string SyncedNotification::GetKey() const {
379 if (!specifics_.coalesced_notification().has_key()) 444 if (!specifics_.coalesced_notification().has_key())
380 return std::string(); 445 return std::string();
381 return specifics_.coalesced_notification().key(); 446 return specifics_.coalesced_notification().key();
382 } 447 }
383 448
384 GURL SyncedNotification::GetOriginUrl() const { 449 GURL SyncedNotification::GetOriginUrl() const {
385 std::string origin_url(kExtensionScheme); 450 std::string origin_url(kExtensionScheme);
386 origin_url += GetAppId(); 451 origin_url += GetAppId();
387 return GURL(origin_url); 452 return GURL(origin_url);
388 } 453 }
389 454
390 // TODO(petewil): This only returns the first icon. Make all the icons
391 // available.
392 GURL SyncedNotification::GetAppIconUrl() const { 455 GURL SyncedNotification::GetAppIconUrl() const {
393 if (specifics_.coalesced_notification().render_info().expanded_info(). 456 if (!specifics_.coalesced_notification().render_info().collapsed_info().
394 collapsed_info_size() == 0) 457 simple_collapsed_layout().has_app_icon())
395 return GURL(); 458 return GURL();
396 459
397 if (!specifics_.coalesced_notification().render_info().expanded_info(). 460 std::string url_spec = specifics_.coalesced_notification().render_info().
398 collapsed_info(0).simple_collapsed_layout().has_app_icon()) 461 collapsed_info().simple_collapsed_layout().app_icon().url();
462
463 return AddDefaultSchemaIfNeeded(url_spec);
464 }
465
466 // TODO(petewil): This ignores all but the first image. If Rich Notifications
467 // supports more images someday, then fetch all images.
468 GURL SyncedNotification::GetImageUrl() const {
469 if (specifics_.coalesced_notification().render_info().collapsed_info().
470 simple_collapsed_layout().media_size() == 0)
399 return GURL(); 471 return GURL();
400 472
401 return GURL(specifics_.coalesced_notification().render_info(). 473 if (!specifics_.coalesced_notification().render_info().collapsed_info().
402 expanded_info().collapsed_info(0).simple_collapsed_layout(). 474 simple_collapsed_layout().media(0).image().has_url())
403 app_icon().url());
404 }
405
406 // TODO(petewil): This currenly only handles the first image from the first
407 // collapsed item, someday return all images.
408 GURL SyncedNotification::GetImageUrl() const {
409 if (specifics_.coalesced_notification().render_info().expanded_info().
410 simple_expanded_layout().media_size() == 0)
411 return GURL(); 475 return GURL();
412 476
413 if (!specifics_.coalesced_notification().render_info().expanded_info(). 477 std::string url_spec = specifics_.coalesced_notification().render_info().
414 simple_expanded_layout().media(0).image().has_url()) 478 collapsed_info().simple_collapsed_layout().media(0).image().url();
415 return GURL();
416 479
417 return GURL(specifics_.coalesced_notification().render_info(). 480 return AddDefaultSchemaIfNeeded(url_spec);
418 expanded_info().simple_expanded_layout().media(0).image().url());
419 } 481 }
420 482
421 std::string SyncedNotification::GetText() const { 483 std::string SyncedNotification::GetText() const {
422 if (!specifics_.coalesced_notification().render_info().expanded_info(). 484 if (!specifics_.coalesced_notification().render_info().expanded_info().
423 simple_expanded_layout().has_text()) 485 simple_expanded_layout().has_text())
424 return std::string(); 486 return std::string();
425 487
426 return specifics_.coalesced_notification().render_info().expanded_info(). 488 return specifics_.coalesced_notification().render_info().expanded_info().
427 simple_expanded_layout().text(); 489 simple_expanded_layout().text();
428 } 490 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 size_t SyncedNotification::GetNotificationCount() const { 546 size_t SyncedNotification::GetNotificationCount() const {
485 return specifics_.coalesced_notification().render_info(). 547 return specifics_.coalesced_notification().render_info().
486 expanded_info().collapsed_info_size(); 548 expanded_info().collapsed_info_size();
487 } 549 }
488 550
489 size_t SyncedNotification::GetButtonCount() const { 551 size_t SyncedNotification::GetButtonCount() const {
490 return specifics_.coalesced_notification().render_info().collapsed_info(). 552 return specifics_.coalesced_notification().render_info().collapsed_info().
491 target_size(); 553 target_size();
492 } 554 }
493 555
556 size_t SyncedNotification::GetProfilePictureCount() const {
557 return specifics_.coalesced_notification().render_info().collapsed_info().
558 simple_collapsed_layout().profile_image_size();
559 }
560
561 GURL SyncedNotification::GetProfilePictureUrl(unsigned int which_url) const {
562 if (GetProfilePictureCount() <= which_url)
563 return GURL();
564
565 std::string url_spec = specifics_.coalesced_notification().render_info().
566 collapsed_info().simple_collapsed_layout().profile_image(which_url).
567 image_url();
568
569 return AddDefaultSchemaIfNeeded(url_spec);
570 }
571
572
494 std::string SyncedNotification::GetDefaultDestinationTitle() const { 573 std::string SyncedNotification::GetDefaultDestinationTitle() const {
495 if (!specifics_.coalesced_notification().render_info().collapsed_info(). 574 if (!specifics_.coalesced_notification().render_info().collapsed_info().
496 default_destination().icon().has_alt_text()) { 575 default_destination().icon().has_alt_text()) {
497 return std::string(); 576 return std::string();
498 } 577 }
499 return specifics_.coalesced_notification().render_info().collapsed_info(). 578 return specifics_.coalesced_notification().render_info().collapsed_info().
500 default_destination().icon().alt_text(); 579 default_destination().icon().alt_text();
501 } 580 }
502 581
503 GURL SyncedNotification::GetDefaultDestinationIconUrl() const { 582 GURL SyncedNotification::GetDefaultDestinationIconUrl() const {
504 if (!specifics_.coalesced_notification().render_info().collapsed_info(). 583 if (!specifics_.coalesced_notification().render_info().collapsed_info().
505 default_destination().icon().has_url()) { 584 default_destination().icon().has_url()) {
506 return GURL(); 585 return GURL();
507 } 586 }
508 return GURL(specifics_.coalesced_notification().render_info(). 587 std::string url_spec = specifics_.coalesced_notification().render_info().
509 collapsed_info().default_destination().icon().url()); 588 collapsed_info().default_destination().icon().url();
589
590 return AddDefaultSchemaIfNeeded(url_spec);
510 } 591 }
511 592
512 GURL SyncedNotification::GetDefaultDestinationUrl() const { 593 GURL SyncedNotification::GetDefaultDestinationUrl() const {
513 if (!specifics_.coalesced_notification().render_info().collapsed_info(). 594 if (!specifics_.coalesced_notification().render_info().collapsed_info().
514 default_destination().has_url()) { 595 default_destination().has_url()) {
515 return GURL(); 596 return GURL();
516 } 597 }
517 return GURL(specifics_.coalesced_notification().render_info(). 598 std::string url_spec = specifics_.coalesced_notification().render_info().
518 collapsed_info().default_destination().url()); 599 collapsed_info().default_destination().url();
600
601 return AddDefaultSchemaIfNeeded(url_spec);
519 } 602 }
520 603
521 std::string SyncedNotification::GetButtonTitle( 604 std::string SyncedNotification::GetButtonTitle(
522 unsigned int which_button) const { 605 unsigned int which_button) const {
523 // Must ensure that we have a target before trying to access it. 606 // Must ensure that we have a target before trying to access it.
524 if (GetButtonCount() <= which_button) 607 if (GetButtonCount() <= which_button)
525 return std::string(); 608 return std::string();
526 if (!specifics_.coalesced_notification().render_info().collapsed_info(). 609 if (!specifics_.coalesced_notification().render_info().collapsed_info().
527 target(which_button).action().icon().has_alt_text()) { 610 target(which_button).action().icon().has_alt_text()) {
528 return std::string(); 611 return std::string();
529 } 612 }
530 return specifics_.coalesced_notification().render_info().collapsed_info(). 613 return specifics_.coalesced_notification().render_info().collapsed_info().
531 target(which_button).action().icon().alt_text(); 614 target(which_button).action().icon().alt_text();
532 } 615 }
533 616
534 GURL SyncedNotification::GetButtonIconUrl(unsigned int which_button) const { 617 GURL SyncedNotification::GetButtonIconUrl(unsigned int which_button) const {
535 // Must ensure that we have a target before trying to access it. 618 // Must ensure that we have a target before trying to access it.
536 if (GetButtonCount() <= which_button) 619 if (GetButtonCount() <= which_button)
537 return GURL(); 620 return GURL();
538 if (!specifics_.coalesced_notification().render_info().collapsed_info(). 621 if (!specifics_.coalesced_notification().render_info().collapsed_info().
539 target(which_button).action().icon().has_url()) { 622 target(which_button).action().icon().has_url()) {
540 return GURL(); 623 return GURL();
541 } 624 }
542 return GURL(specifics_.coalesced_notification().render_info(). 625 std::string url_spec = specifics_.coalesced_notification().render_info().
543 collapsed_info().target(which_button).action().icon().url()); 626 collapsed_info().target(which_button).action().icon().url();
627
628 return AddDefaultSchemaIfNeeded(url_spec);
544 } 629 }
545 630
546 GURL SyncedNotification::GetButtonUrl(unsigned int which_button) const { 631 GURL SyncedNotification::GetButtonUrl(unsigned int which_button) const {
547 // Must ensure that we have a target before trying to access it. 632 // Must ensure that we have a target before trying to access it.
548 if (GetButtonCount() <= which_button) 633 if (GetButtonCount() <= which_button)
549 return GURL(); 634 return GURL();
550 if (!specifics_.coalesced_notification().render_info().collapsed_info(). 635 if (!specifics_.coalesced_notification().render_info().collapsed_info().
551 target(which_button).action().has_url()) { 636 target(which_button).action().has_url()) {
552 return GURL(); 637 return GURL();
553 } 638 }
554 return GURL(specifics_.coalesced_notification().render_info(). 639 std::string url_spec = specifics_.coalesced_notification().render_info().
555 collapsed_info().target(which_button).action().url()); 640 collapsed_info().target(which_button).action().url();
641
642 return AddDefaultSchemaIfNeeded(url_spec);
556 } 643 }
557 644
558 std::string SyncedNotification::GetContainedNotificationTitle( 645 std::string SyncedNotification::GetContainedNotificationTitle(
559 int index) const { 646 int index) const {
560 if (specifics_.coalesced_notification().render_info().expanded_info(). 647 if (specifics_.coalesced_notification().render_info().expanded_info().
561 collapsed_info_size() < index + 1) 648 collapsed_info_size() < index + 1)
562 return std::string(); 649 return std::string();
563 650
564 return specifics_.coalesced_notification().render_info().expanded_info(). 651 return specifics_.coalesced_notification().render_info().expanded_info().
565 collapsed_info(index).simple_collapsed_layout().heading(); 652 collapsed_info(index).simple_collapsed_layout().heading();
566 } 653 }
567 654
568 std::string SyncedNotification::GetContainedNotificationMessage( 655 std::string SyncedNotification::GetContainedNotificationMessage(
569 int index) const { 656 int index) const {
570 if (specifics_.coalesced_notification().render_info().expanded_info(). 657 if (specifics_.coalesced_notification().render_info().expanded_info().
571 collapsed_info_size() < index + 1) 658 collapsed_info_size() < index + 1)
572 return std::string(); 659 return std::string();
573 660
574 return specifics_.coalesced_notification().render_info().expanded_info(). 661 return specifics_.coalesced_notification().render_info().expanded_info().
575 collapsed_info(index).simple_collapsed_layout().description(); 662 collapsed_info(index).simple_collapsed_layout().description();
576 } 663 }
577 664
578 } // namespace notifier 665 } // namespace notifier
OLDNEW
« no previous file with comments | « chrome/browser/notifications/sync_notifier/synced_notification.h ('k') | sync/protocol/synced_notification_render.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698