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

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

Issue 1135213004: Returning error when NotificationConversionHelper::NotificationBitmapToGfxImage() get failed in not… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactors().back()); 308 ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactors().back());
309 309
310 // Update optional fields if provided. 310 // Update optional fields if provided.
311 if (options->type != api::notifications::TEMPLATE_TYPE_NONE) 311 if (options->type != api::notifications::TEMPLATE_TYPE_NONE)
312 notification->set_type(MapApiTemplateTypeToType(options->type)); 312 notification->set_type(MapApiTemplateTypeToType(options->type));
313 if (options->title) 313 if (options->title)
314 notification->set_title(base::UTF8ToUTF16(*options->title)); 314 notification->set_title(base::UTF8ToUTF16(*options->title));
315 if (options->message) 315 if (options->message)
316 notification->set_message(base::UTF8ToUTF16(*options->message)); 316 notification->set_message(base::UTF8ToUTF16(*options->message));
317 317
318 // TODO(dewittj): Return error if this fails. 318 // TODO(dewittj): Return error if this fails.
Peter Beverloo 2015/05/13 10:52:42 This TODO is now redundant.
Deepak 2015/05/13 13:21:11 Done.
319 if (options->icon_bitmap) { 319 if (options->icon_bitmap) {
320 gfx::Image icon; 320 gfx::Image icon;
321 NotificationConversionHelper::NotificationBitmapToGfxImage( 321 if (!NotificationConversionHelper::NotificationBitmapToGfxImage(
322 image_scale, bitmap_sizes.icon_size, options->icon_bitmap.get(), &icon); 322 image_scale, bitmap_sizes.icon_size, options->icon_bitmap.get(),
323 &icon)) {
324 SetError(kUnableToDecodeIconError);
325 return false;
326 }
323 notification->set_icon(icon); 327 notification->set_icon(icon);
324 } 328 }
325 329
326 gfx::Image app_icon_mask; 330 if (options->app_icon_mask_url.get()) {
327 if (NotificationConversionHelper::NotificationBitmapToGfxImage( 331 gfx::Image app_icon_mask;
328 image_scale, 332 if (!NotificationConversionHelper::NotificationBitmapToGfxImage(
Peter Beverloo 2015/05/13 10:54:04 On a slightly higher-level note, now that most cal
Deepak 2015/05/13 13:21:11 Done.
329 bitmap_sizes.app_icon_mask_size, 333 image_scale, bitmap_sizes.app_icon_mask_size,
330 options->app_icon_mask_bitmap.get(), 334 options->app_icon_mask_bitmap.get(), &app_icon_mask)) {
331 &app_icon_mask)) { 335 SetError(kUnableToDecodeIconError);
336 return false;
337 }
332 notification->set_small_image(app_icon_mask); 338 notification->set_small_image(app_icon_mask);
333 } 339 }
334 340
335 if (options->priority) 341 if (options->priority)
336 notification->set_priority(*options->priority); 342 notification->set_priority(*options->priority);
337 343
338 if (options->event_time) 344 if (options->event_time)
339 notification->set_timestamp(base::Time::FromJsTime(*options->event_time)); 345 notification->set_timestamp(base::Time::FromJsTime(*options->event_time));
340 346
341 if (options->buttons) { 347 if (options->buttons) {
(...skipping 13 matching lines...) Expand all
355 buttons.push_back(button); 361 buttons.push_back(button);
356 } 362 }
357 notification->set_buttons(buttons); 363 notification->set_buttons(buttons);
358 } 364 }
359 365
360 if (options->context_message) { 366 if (options->context_message) {
361 notification->set_context_message( 367 notification->set_context_message(
362 base::UTF8ToUTF16(*options->context_message)); 368 base::UTF8ToUTF16(*options->context_message));
363 } 369 }
364 370
365 gfx::Image image; 371 gfx::Image image;
Peter Beverloo 2015/05/13 10:52:42 You can now move this to within the body of the ne
Deepak 2015/05/13 13:21:11 Done.
366 bool has_image = NotificationConversionHelper::NotificationBitmapToGfxImage( 372 if (options->image_url.get()) {
367 image_scale, 373 bool has_image = NotificationConversionHelper::NotificationBitmapToGfxImage(
368 bitmap_sizes.image_size, 374 image_scale,
369 options->image_bitmap.get(), 375 bitmap_sizes.image_size,
370 &image); 376 options->image_bitmap.get(),
371 if (has_image) { 377 &image);
378 if (!has_image) {
379 SetError(kUnableToDecodeIconError);
380 return false;
381 }
372 // We should have an image if and only if the type is an image type. 382 // We should have an image if and only if the type is an image type.
373 if (notification->type() != message_center::NOTIFICATION_TYPE_IMAGE) { 383 if (notification->type() != message_center::NOTIFICATION_TYPE_IMAGE) {
374 SetError(kExtraImageProvided); 384 SetError(kExtraImageProvided);
375 return false; 385 return false;
376 } 386 }
377 notification->set_image(image); 387 notification->set_image(image);
378 } 388 }
379 389
380 if (options->progress) { 390 if (options->progress) {
381 // We should have progress if and only if the type is a progress type. 391 // We should have progress if and only if the type is a progress type.
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 ? api::notifications::PERMISSION_LEVEL_GRANTED 610 ? api::notifications::PERMISSION_LEVEL_GRANTED
601 : api::notifications::PERMISSION_LEVEL_DENIED; 611 : api::notifications::PERMISSION_LEVEL_DENIED;
602 612
603 SetResult(new base::StringValue(api::notifications::ToString(result))); 613 SetResult(new base::StringValue(api::notifications::ToString(result)));
604 SendResponse(true); 614 SendResponse(true);
605 615
606 return true; 616 return true;
607 } 617 }
608 618
609 } // namespace extensions 619 } // 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