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

Side by Side Diff: chrome/browser/extensions/api/notifications/notifications_api.cc

Issue 1188213002: Making icon url for buttons in notification optional. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « no previous file | 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/extensions/api/notifications/notifications_api.h" 5 #include "chrome/browser/extensions/api/notifications/notifications_api.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 if (options->buttons.get()) { 287 if (options->buttons.get()) {
288 // Currently we allow up to 2 buttons. 288 // Currently we allow up to 2 buttons.
289 size_t number_of_buttons = options->buttons->size(); 289 size_t number_of_buttons = options->buttons->size();
290 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; 290 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons;
291 291
292 for (size_t i = 0; i < number_of_buttons; i++) { 292 for (size_t i = 0; i < number_of_buttons; i++) {
293 message_center::ButtonInfo info( 293 message_center::ButtonInfo info(
294 base::UTF8ToUTF16((*options->buttons)[i]->title)); 294 base::UTF8ToUTF16((*options->buttons)[i]->title));
295 extensions::api::notifications::NotificationBitmap* icon_bitmap_ptr = 295 extensions::api::notifications::NotificationBitmap* icon_bitmap_ptr =
296 (*options->buttons)[i]->icon_bitmap.get(); 296 (*options->buttons)[i]->icon_bitmap.get();
297 // As icon url for button is optional so icon_bitmap_ptr can be null.
Peter Beverloo 2015/06/22 13:00:12 nit: grammer. I personally wouldn't bother with th
297 if (icon_bitmap_ptr) { 298 if (icon_bitmap_ptr) {
298 NotificationConversionHelper::NotificationBitmapToGfxImage( 299 NotificationConversionHelper::NotificationBitmapToGfxImage(
299 image_scale, bitmap_sizes.button_icon_size, *icon_bitmap_ptr, 300 image_scale, bitmap_sizes.button_icon_size, *icon_bitmap_ptr,
300 &info.icon); 301 &info.icon);
301 optional_fields.buttons.push_back(info);
302 } 302 }
303 optional_fields.buttons.push_back(info);
303 } 304 }
304 } 305 }
305 306
306 if (options->context_message) { 307 if (options->context_message) {
307 optional_fields.context_message = 308 optional_fields.context_message =
308 base::UTF8ToUTF16(*options->context_message); 309 base::UTF8ToUTF16(*options->context_message);
309 } 310 }
310 311
311 bool has_image = options->image_bitmap.get() && 312 bool has_image = options->image_bitmap.get() &&
312 NotificationConversionHelper::NotificationBitmapToGfxImage( 313 NotificationConversionHelper::NotificationBitmapToGfxImage(
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 // Currently we allow up to 2 buttons. 424 // Currently we allow up to 2 buttons.
424 size_t number_of_buttons = options->buttons->size(); 425 size_t number_of_buttons = options->buttons->size();
425 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; 426 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons;
426 427
427 std::vector<message_center::ButtonInfo> buttons; 428 std::vector<message_center::ButtonInfo> buttons;
428 for (size_t i = 0; i < number_of_buttons; i++) { 429 for (size_t i = 0; i < number_of_buttons; i++) {
429 message_center::ButtonInfo button( 430 message_center::ButtonInfo button(
430 base::UTF8ToUTF16((*options->buttons)[i]->title)); 431 base::UTF8ToUTF16((*options->buttons)[i]->title));
431 extensions::api::notifications::NotificationBitmap* icon_bitmap_ptr = 432 extensions::api::notifications::NotificationBitmap* icon_bitmap_ptr =
432 (*options->buttons)[i]->icon_bitmap.get(); 433 (*options->buttons)[i]->icon_bitmap.get();
434 // As icon url for button is optional so icon_bitmap_ptr can be null.
433 if (icon_bitmap_ptr) { 435 if (icon_bitmap_ptr) {
434 NotificationConversionHelper::NotificationBitmapToGfxImage( 436 NotificationConversionHelper::NotificationBitmapToGfxImage(
435 image_scale, bitmap_sizes.button_icon_size, *icon_bitmap_ptr, 437 image_scale, bitmap_sizes.button_icon_size, *icon_bitmap_ptr,
436 &button.icon); 438 &button.icon);
437 buttons.push_back(button);
438 } 439 }
440 buttons.push_back(button);
439 } 441 }
440 notification->set_buttons(buttons); 442 notification->set_buttons(buttons);
441 } 443 }
442 444
443 if (options->context_message) { 445 if (options->context_message) {
444 notification->set_context_message( 446 notification->set_context_message(
445 base::UTF8ToUTF16(*options->context_message)); 447 base::UTF8ToUTF16(*options->context_message));
446 } 448 }
447 449
448 gfx::Image image; 450 gfx::Image image;
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 ? api::notifications::PERMISSION_LEVEL_GRANTED 685 ? api::notifications::PERMISSION_LEVEL_GRANTED
684 : api::notifications::PERMISSION_LEVEL_DENIED; 686 : api::notifications::PERMISSION_LEVEL_DENIED;
685 687
686 SetResult(new base::StringValue(api::notifications::ToString(result))); 688 SetResult(new base::StringValue(api::notifications::ToString(result)));
687 SendResponse(true); 689 SendResponse(true);
688 690
689 return true; 691 return true;
690 } 692 }
691 693
692 } // namespace extensions 694 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698