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

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

Issue 1825913002: [Extensions] Convert APIs to use movable types [7] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Steven's Created 4 years, 8 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // Use distinct buckets for 1-16 notification action buttons, and an 315 // Use distinct buckets for 1-16 notification action buttons, and an
316 // overflow bucket for 17 or more action buttons. Does not impact how many 316 // overflow bucket for 17 or more action buttons. Does not impact how many
317 // action buttons are shown. 317 // action buttons are shown.
318 UMA_HISTOGRAM_ENUMERATION("Notifications.ExtensionNotificationActionCount", 318 UMA_HISTOGRAM_ENUMERATION("Notifications.ExtensionNotificationActionCount",
319 number_of_buttons, 17); 319 number_of_buttons, 17);
320 320
321 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; 321 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons;
322 322
323 for (size_t i = 0; i < number_of_buttons; i++) { 323 for (size_t i = 0; i < number_of_buttons; i++) {
324 message_center::ButtonInfo info( 324 message_center::ButtonInfo info(
325 base::UTF8ToUTF16((*options->buttons)[i]->title)); 325 base::UTF8ToUTF16((*options->buttons)[i].title));
326 extensions::api::notifications::NotificationBitmap* icon_bitmap_ptr = 326 extensions::api::notifications::NotificationBitmap* icon_bitmap_ptr =
327 (*options->buttons)[i]->icon_bitmap.get(); 327 (*options->buttons)[i].icon_bitmap.get();
328 if (icon_bitmap_ptr) { 328 if (icon_bitmap_ptr) {
329 NotificationConversionHelper::NotificationBitmapToGfxImage( 329 NotificationConversionHelper::NotificationBitmapToGfxImage(
330 image_scale, bitmap_sizes.button_icon_size, *icon_bitmap_ptr, 330 image_scale, bitmap_sizes.button_icon_size, *icon_bitmap_ptr,
331 &info.icon); 331 &info.icon);
332 } 332 }
333 optional_fields.buttons.push_back(info); 333 optional_fields.buttons.push_back(info);
334 } 334 }
335 } 335 }
336 336
337 if (options->context_message) { 337 if (options->context_message) {
(...skipping 28 matching lines...) Expand all
366 optional_fields.progress = *options->progress; 366 optional_fields.progress = *options->progress;
367 // Progress value should range from 0 to 100. 367 // Progress value should range from 0 to 100.
368 if (optional_fields.progress < 0 || optional_fields.progress > 100) { 368 if (optional_fields.progress < 0 || optional_fields.progress > 100) {
369 SetError(kInvalidProgressValue); 369 SetError(kInvalidProgressValue);
370 return false; 370 return false;
371 } 371 }
372 } 372 }
373 373
374 if (has_list_items) { 374 if (has_list_items) {
375 using api::notifications::NotificationItem; 375 using api::notifications::NotificationItem;
376 std::vector<linked_ptr<NotificationItem> >::iterator i; 376 for (const NotificationItem& api_item : *options->items) {
377 for (i = options->items->begin(); i != options->items->end(); ++i) { 377 optional_fields.items.push_back(message_center::NotificationItem(
378 message_center::NotificationItem item( 378 base::UTF8ToUTF16(api_item.title),
379 base::UTF8ToUTF16(i->get()->title), 379 base::UTF8ToUTF16(api_item.message)));
380 base::UTF8ToUTF16(i->get()->message));
381 optional_fields.items.push_back(item);
382 } 380 }
383 } 381 }
384 382
385 if (options->is_clickable.get()) 383 if (options->is_clickable.get())
386 optional_fields.clickable = *options->is_clickable; 384 optional_fields.clickable = *options->is_clickable;
387 385
388 NotificationsApiDelegate* api_delegate(new NotificationsApiDelegate( 386 NotificationsApiDelegate* api_delegate(new NotificationsApiDelegate(
389 this, GetProfile(), extension_->id(), id)); // ownership is passed to 387 this, GetProfile(), extension_->id(), id)); // ownership is passed to
390 // Notification 388 // Notification
391 Notification notification( 389 Notification notification(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 notification->set_timestamp(base::Time::FromJsTime(*options->event_time)); 455 notification->set_timestamp(base::Time::FromJsTime(*options->event_time));
458 456
459 if (options->buttons) { 457 if (options->buttons) {
460 // Currently we allow up to 2 buttons. 458 // Currently we allow up to 2 buttons.
461 size_t number_of_buttons = options->buttons->size(); 459 size_t number_of_buttons = options->buttons->size();
462 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; 460 number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons;
463 461
464 std::vector<message_center::ButtonInfo> buttons; 462 std::vector<message_center::ButtonInfo> buttons;
465 for (size_t i = 0; i < number_of_buttons; i++) { 463 for (size_t i = 0; i < number_of_buttons; i++) {
466 message_center::ButtonInfo button( 464 message_center::ButtonInfo button(
467 base::UTF8ToUTF16((*options->buttons)[i]->title)); 465 base::UTF8ToUTF16((*options->buttons)[i].title));
468 extensions::api::notifications::NotificationBitmap* icon_bitmap_ptr = 466 extensions::api::notifications::NotificationBitmap* icon_bitmap_ptr =
469 (*options->buttons)[i]->icon_bitmap.get(); 467 (*options->buttons)[i].icon_bitmap.get();
470 if (icon_bitmap_ptr) { 468 if (icon_bitmap_ptr) {
471 NotificationConversionHelper::NotificationBitmapToGfxImage( 469 NotificationConversionHelper::NotificationBitmapToGfxImage(
472 image_scale, bitmap_sizes.button_icon_size, *icon_bitmap_ptr, 470 image_scale, bitmap_sizes.button_icon_size, *icon_bitmap_ptr,
473 &button.icon); 471 &button.icon);
474 } 472 }
475 buttons.push_back(button); 473 buttons.push_back(button);
476 } 474 }
477 notification->set_buttons(buttons); 475 notification->set_buttons(buttons);
478 } 476 }
479 477
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 512
515 if (options->items.get() && options->items->size() > 0) { 513 if (options->items.get() && options->items->size() > 0) {
516 // We should have list items if and only if the type is a multiple type. 514 // We should have list items if and only if the type is a multiple type.
517 if (notification->type() != message_center::NOTIFICATION_TYPE_MULTIPLE) { 515 if (notification->type() != message_center::NOTIFICATION_TYPE_MULTIPLE) {
518 SetError(kExtraListItemsProvided); 516 SetError(kExtraListItemsProvided);
519 return false; 517 return false;
520 } 518 }
521 519
522 std::vector<message_center::NotificationItem> items; 520 std::vector<message_center::NotificationItem> items;
523 using api::notifications::NotificationItem; 521 using api::notifications::NotificationItem;
524 std::vector<linked_ptr<NotificationItem> >::iterator i; 522 for (const NotificationItem& api_item : *options->items) {
525 for (i = options->items->begin(); i != options->items->end(); ++i) { 523 items.push_back(message_center::NotificationItem(
526 message_center::NotificationItem item( 524 base::UTF8ToUTF16(api_item.title),
527 base::UTF8ToUTF16(i->get()->title), 525 base::UTF8ToUTF16(api_item.message)));
528 base::UTF8ToUTF16(i->get()->message));
529 items.push_back(item);
530 } 526 }
531 notification->set_items(items); 527 notification->set_items(items);
532 } 528 }
533 529
534 // Then override if it's already set. 530 // Then override if it's already set.
535 if (options->is_clickable.get()) 531 if (options->is_clickable.get())
536 notification->set_clickable(*options->is_clickable); 532 notification->set_clickable(*options->is_clickable);
537 533
538 g_browser_process->notification_ui_manager()->Update(*notification, 534 g_browser_process->notification_ui_manager()->Update(*notification,
539 GetProfile()); 535 GetProfile());
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 ? api::notifications::PERMISSION_LEVEL_GRANTED 718 ? api::notifications::PERMISSION_LEVEL_GRANTED
723 : api::notifications::PERMISSION_LEVEL_DENIED; 719 : api::notifications::PERMISSION_LEVEL_DENIED;
724 720
725 SetResult(new base::StringValue(api::notifications::ToString(result))); 721 SetResult(new base::StringValue(api::notifications::ToString(result)));
726 SendResponse(true); 722 SendResponse(true);
727 723
728 return true; 724 return true;
729 } 725 }
730 726
731 } // namespace extensions 727 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698