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

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

Issue 308053004: Add appIconMask to notification API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 6 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
« no previous file with comments | « no previous file | chrome/common/extensions/api/notifications.idl » ('j') | 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 if (!NotificationBitmapToGfxImage(image_scale, 278 if (!NotificationBitmapToGfxImage(image_scale,
279 bitmap_sizes.icon_size, 279 bitmap_sizes.icon_size,
280 options->icon_bitmap.get(), 280 options->icon_bitmap.get(),
281 &icon)) { 281 &icon)) {
282 SetError(kUnableToDecodeIconError); 282 SetError(kUnableToDecodeIconError);
283 return false; 283 return false;
284 } 284 }
285 285
286 // Then, handle any optional data that's been provided. 286 // Then, handle any optional data that's been provided.
287 message_center::RichNotificationData optional_fields; 287 message_center::RichNotificationData optional_fields;
288 if (options->app_icon_mask_url.get()) {
289 if (!NotificationBitmapToGfxImage(image_scale,
290 bitmap_sizes.app_icon_mask_size,
291 options->app_icon_mask_bitmap.get(),
292 &optional_fields.small_image)) {
293 SetError(kUnableToDecodeIconError);
294 return false;
295 }
296 }
297
288 if (options->priority.get()) 298 if (options->priority.get())
289 optional_fields.priority = *options->priority; 299 optional_fields.priority = *options->priority;
290 300
291 if (options->event_time.get()) 301 if (options->event_time.get())
292 optional_fields.timestamp = base::Time::FromJsTime(*options->event_time); 302 optional_fields.timestamp = base::Time::FromJsTime(*options->event_time);
293 303
294 if (options->buttons.get()) { 304 if (options->buttons.get()) {
295 // Currently we allow up to 2 buttons. 305 // Currently we allow up to 2 buttons.
296 size_t number_of_buttons = options->buttons->size(); 306 size_t number_of_buttons = options->buttons->size();
297 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; 307 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 notification->set_message(base::UTF8ToUTF16(*options->message)); 405 notification->set_message(base::UTF8ToUTF16(*options->message));
396 406
397 // TODO(dewittj): Return error if this fails. 407 // TODO(dewittj): Return error if this fails.
398 if (options->icon_bitmap) { 408 if (options->icon_bitmap) {
399 gfx::Image icon; 409 gfx::Image icon;
400 NotificationBitmapToGfxImage( 410 NotificationBitmapToGfxImage(
401 image_scale, bitmap_sizes.icon_size, options->icon_bitmap.get(), &icon); 411 image_scale, bitmap_sizes.icon_size, options->icon_bitmap.get(), &icon);
402 notification->set_icon(icon); 412 notification->set_icon(icon);
403 } 413 }
404 414
415 gfx::Image app_icon_mask;
416 if (NotificationBitmapToGfxImage(image_scale,
417 bitmap_sizes.app_icon_mask_size,
418 options->app_icon_mask_bitmap.get(),
419 &app_icon_mask)) {
420 notification->set_small_image(app_icon_mask);
421 }
422
405 if (options->priority) 423 if (options->priority)
406 notification->set_priority(*options->priority); 424 notification->set_priority(*options->priority);
407 425
408 if (options->event_time) 426 if (options->event_time)
409 notification->set_timestamp(base::Time::FromJsTime(*options->event_time)); 427 notification->set_timestamp(base::Time::FromJsTime(*options->event_time));
410 428
411 if (options->buttons) { 429 if (options->buttons) {
412 // Currently we allow up to 2 buttons. 430 // Currently we allow up to 2 buttons.
413 size_t number_of_buttons = options->buttons->size(); 431 size_t number_of_buttons = options->buttons->size();
414 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; 432 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons;
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 ? api::notifications::PERMISSION_LEVEL_GRANTED 684 ? api::notifications::PERMISSION_LEVEL_GRANTED
667 : api::notifications::PERMISSION_LEVEL_DENIED; 685 : api::notifications::PERMISSION_LEVEL_DENIED;
668 686
669 SetResult(new base::StringValue(api::notifications::ToString(result))); 687 SetResult(new base::StringValue(api::notifications::ToString(result)));
670 SendResponse(true); 688 SendResponse(true);
671 689
672 return true; 690 return true;
673 } 691 }
674 692
675 } // namespace extensions 693 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/api/notifications.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698