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

Side by Side Diff: extensions/renderer/set_icon_natives.cc

Issue 545513002: tryAllocPixels returns bool, allocPixels requires success (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/renderer/set_icon_natives.h" 5 #include "extensions/renderer/set_icon_natives.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "content/public/common/common_param_traits.h" 10 #include "content/public/common/common_param_traits.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 int data_length = 63 int data_length =
64 data->Get(v8::String::NewFromUtf8(isolate, "length"))->Int32Value(); 64 data->Get(v8::String::NewFromUtf8(isolate, "length"))->Int32Value();
65 if (data_length != 4 * width * height) { 65 if (data_length != 4 * width * height) {
66 isolate->ThrowException( 66 isolate->ThrowException(
67 v8::Exception::Error(v8::String::NewFromUtf8(isolate, kInvalidData))); 67 v8::Exception::Error(v8::String::NewFromUtf8(isolate, kInvalidData)));
68 return false; 68 return false;
69 } 69 }
70 70
71 SkBitmap bitmap; 71 SkBitmap bitmap;
72 if (!bitmap.allocN32Pixels(width, height)) { 72 if (!bitmap.tryAllocN32Pixels(width, height)) {
73 isolate->ThrowException( 73 isolate->ThrowException(
74 v8::Exception::Error(v8::String::NewFromUtf8(isolate, kNoMemory))); 74 v8::Exception::Error(v8::String::NewFromUtf8(isolate, kNoMemory)));
75 return false; 75 return false;
76 } 76 }
77 bitmap.eraseARGB(0, 0, 0, 0); 77 bitmap.eraseARGB(0, 0, 0, 0);
78 78
79 uint32_t* pixels = bitmap.getAddr32(0, 0); 79 uint32_t* pixels = bitmap.getAddr32(0, 0);
80 for (int t = 0; t < width * height; t++) { 80 for (int t = 0; t < width * height; t++) {
81 // |data| is RGBA, pixels is ARGB. 81 // |data| is RGBA, pixels is ARGB.
82 pixels[t] = SkPreMultiplyColor( 82 pixels[t] = SkPreMultiplyColor(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 bitmap_set_value); 140 bitmap_set_value);
141 if (details->Has(v8::String::NewFromUtf8(args.GetIsolate(), "tabId"))) { 141 if (details->Has(v8::String::NewFromUtf8(args.GetIsolate(), "tabId"))) {
142 dict->Set( 142 dict->Set(
143 v8::String::NewFromUtf8(args.GetIsolate(), "tabId"), 143 v8::String::NewFromUtf8(args.GetIsolate(), "tabId"),
144 details->Get(v8::String::NewFromUtf8(args.GetIsolate(), "tabId"))); 144 details->Get(v8::String::NewFromUtf8(args.GetIsolate(), "tabId")));
145 } 145 }
146 args.GetReturnValue().Set(dict); 146 args.GetReturnValue().Set(dict);
147 } 147 }
148 148
149 } // namespace extensions 149 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698