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

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

Issue 1292003004: Elide origins displayed on web notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move origin_url to message_center::Notification Created 5 years, 4 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 "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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 if (icon_bitmap_ptr) { 298 if (icon_bitmap_ptr) {
299 NotificationConversionHelper::NotificationBitmapToGfxImage( 299 NotificationConversionHelper::NotificationBitmapToGfxImage(
300 image_scale, bitmap_sizes.button_icon_size, *icon_bitmap_ptr, 300 image_scale, bitmap_sizes.button_icon_size, *icon_bitmap_ptr,
301 &info.icon); 301 &info.icon);
302 } 302 }
303 optional_fields.buttons.push_back(info); 303 optional_fields.buttons.push_back(info);
304 } 304 }
305 } 305 }
306 306
307 if (options->context_message) { 307 if (options->context_message) {
308 optional_fields.context_message = 308 optional_fields.context_message.message =
309 base::UTF8ToUTF16(*options->context_message); 309 base::UTF8ToUTF16(*options->context_message);
310 optional_fields.context_message.use_origin_as_context = false;
310 } 311 }
311 312
312 bool has_image = options->image_bitmap.get() && 313 bool has_image = options->image_bitmap.get() &&
313 NotificationConversionHelper::NotificationBitmapToGfxImage( 314 NotificationConversionHelper::NotificationBitmapToGfxImage(
314 image_scale, bitmap_sizes.image_size, 315 image_scale, bitmap_sizes.image_size,
315 *options->image_bitmap, &optional_fields.image); 316 *options->image_bitmap, &optional_fields.image);
316 317
317 // We should have an image if and only if the type is an image type. 318 // We should have an image if and only if the type is an image type.
318 if (has_image != (type == message_center::NOTIFICATION_TYPE_IMAGE)) { 319 if (has_image != (type == message_center::NOTIFICATION_TYPE_IMAGE)) {
319 SetError(kExtraImageProvided); 320 SetError(kExtraImageProvided);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 optional_fields.items.push_back(item); 352 optional_fields.items.push_back(item);
352 } 353 }
353 } 354 }
354 355
355 if (options->is_clickable.get()) 356 if (options->is_clickable.get())
356 optional_fields.clickable = *options->is_clickable; 357 optional_fields.clickable = *options->is_clickable;
357 358
358 NotificationsApiDelegate* api_delegate(new NotificationsApiDelegate( 359 NotificationsApiDelegate* api_delegate(new NotificationsApiDelegate(
359 this, GetProfile(), extension_->id(), id)); // ownership is passed to 360 this, GetProfile(), extension_->id(), id)); // ownership is passed to
360 // Notification 361 // Notification
361 Notification notification(type, 362 Notification notification(
362 extension_->url(), 363 type, title, message, icon,
363 title, 364 message_center::NotifierId(message_center::NotifierId::APPLICATION,
364 message, 365 extension_->id()),
365 icon, 366 base::UTF8ToUTF16(extension_->name()), extension_->url(),
366 message_center::NotifierId( 367 api_delegate->id(), optional_fields, api_delegate);
367 message_center::NotifierId::APPLICATION,
368 extension_->id()),
369 base::UTF8ToUTF16(extension_->name()),
370 api_delegate->id(),
371 optional_fields,
372 api_delegate);
373 368
374 g_browser_process->notification_ui_manager()->Add(notification, GetProfile()); 369 g_browser_process->notification_ui_manager()->Add(notification, GetProfile());
375 return true; 370 return true;
376 } 371 }
377 372
378 bool NotificationsApiFunction::UpdateNotification( 373 bool NotificationsApiFunction::UpdateNotification(
379 const std::string& id, 374 const std::string& id,
380 api::notifications::NotificationOptions* options, 375 api::notifications::NotificationOptions* options,
381 Notification* notification) { 376 Notification* notification) {
382 NotificationBitmapSizes bitmap_sizes = GetNotificationBitmapSizes(); 377 NotificationBitmapSizes bitmap_sizes = GetNotificationBitmapSizes();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 image_scale, bitmap_sizes.button_icon_size, *icon_bitmap_ptr, 431 image_scale, bitmap_sizes.button_icon_size, *icon_bitmap_ptr,
437 &button.icon); 432 &button.icon);
438 } 433 }
439 buttons.push_back(button); 434 buttons.push_back(button);
440 } 435 }
441 notification->set_buttons(buttons); 436 notification->set_buttons(buttons);
442 } 437 }
443 438
444 if (options->context_message) { 439 if (options->context_message) {
445 notification->set_context_message( 440 notification->set_context_message(
446 base::UTF8ToUTF16(*options->context_message)); 441 base::UTF8ToUTF16(*options->context_message),
442 false /* use_origin_as_context */);
447 } 443 }
448 444
449 gfx::Image image; 445 gfx::Image image;
450 bool has_image = 446 bool has_image =
451 options->image_bitmap.get() && 447 options->image_bitmap.get() &&
452 NotificationConversionHelper::NotificationBitmapToGfxImage( 448 NotificationConversionHelper::NotificationBitmapToGfxImage(
453 image_scale, bitmap_sizes.image_size, *options->image_bitmap, &image); 449 image_scale, bitmap_sizes.image_size, *options->image_bitmap, &image);
454 450
455 if (has_image) { 451 if (has_image) {
456 // We should have an image if and only if the type is an image type. 452 // We should have an image if and only if the type is an image type.
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 ? api::notifications::PERMISSION_LEVEL_GRANTED 682 ? api::notifications::PERMISSION_LEVEL_GRANTED
687 : api::notifications::PERMISSION_LEVEL_DENIED; 683 : api::notifications::PERMISSION_LEVEL_DENIED;
688 684
689 SetResult(new base::StringValue(api::notifications::ToString(result))); 685 SetResult(new base::StringValue(api::notifications::ToString(result)));
690 SendResponse(true); 686 SendResponse(true);
691 687
692 return true; 688 return true;
693 } 689 }
694 690
695 } // namespace extensions 691 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698