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

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

Issue 98543004: Remove usage of deprecated V8 APIs from c/r/extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years 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
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/renderer/extensions/set_icon_natives.h" 5 #include "chrome/renderer/extensions/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 "chrome/common/render_messages.h" 10 #include "chrome/common/render_messages.h"
(...skipping 27 matching lines...) Expand all
38 Value** bitmap_value) { 38 Value** bitmap_value) {
39 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); 39 v8::Isolate* isolate = context()->v8_context()->GetIsolate();
40 v8::Local<v8::Object> data = 40 v8::Local<v8::Object> data =
41 image_data->Get(v8::String::NewFromUtf8(isolate, "data"))->ToObject(); 41 image_data->Get(v8::String::NewFromUtf8(isolate, "data"))->ToObject();
42 int width = 42 int width =
43 image_data->Get(v8::String::NewFromUtf8(isolate, "width"))->Int32Value(); 43 image_data->Get(v8::String::NewFromUtf8(isolate, "width"))->Int32Value();
44 int height = 44 int height =
45 image_data->Get(v8::String::NewFromUtf8(isolate, "height"))->Int32Value(); 45 image_data->Get(v8::String::NewFromUtf8(isolate, "height"))->Int32Value();
46 46
47 if (width <= 0 || height <= 0) { 47 if (width <= 0 || height <= 0) {
48 v8::ThrowException(v8::Exception::Error( 48 isolate->ThrowException(v8::Exception::Error(
49 v8::String::NewFromUtf8(isolate, kInvalidDimensions))); 49 v8::String::NewFromUtf8(isolate, kInvalidDimensions)));
50 return false; 50 return false;
51 } 51 }
52 52
53 // We need to be able to safely check |data_length| == 4 * width * height 53 // We need to be able to safely check |data_length| == 4 * width * height
54 // without overflowing below. 54 // without overflowing below.
55 int max_width = (std::numeric_limits<int>::max() / 4) / height; 55 int max_width = (std::numeric_limits<int>::max() / 4) / height;
56 if (width > max_width) { 56 if (width > max_width) {
57 v8::ThrowException(v8::Exception::Error( 57 isolate->ThrowException(v8::Exception::Error(
58 v8::String::NewFromUtf8(isolate, kInvalidDimensions))); 58 v8::String::NewFromUtf8(isolate, kInvalidDimensions)));
59 return false; 59 return false;
60 } 60 }
61 61
62 int data_length = 62 int data_length =
63 data->Get(v8::String::NewFromUtf8(isolate, "length"))->Int32Value(); 63 data->Get(v8::String::NewFromUtf8(isolate, "length"))->Int32Value();
64 if (data_length != 4 * width * height) { 64 if (data_length != 4 * width * height) {
65 v8::ThrowException( 65 isolate->ThrowException(
66 v8::Exception::Error(v8::String::NewFromUtf8(isolate, kInvalidData))); 66 v8::Exception::Error(v8::String::NewFromUtf8(isolate, kInvalidData)));
67 return false; 67 return false;
68 } 68 }
69 69
70 SkBitmap bitmap; 70 SkBitmap bitmap;
71 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); 71 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
72 if (!bitmap.allocPixels()) { 72 if (!bitmap.allocPixels()) {
73 v8::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(
83 ((data->Get(v8::Integer::New(4*t + 3))->Int32Value() & 0xFF) << 24) | 83 ((data->Get(v8::Integer::New(4*t + 3))->Int32Value() & 0xFF) << 24) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 137
138 if (details->Has(v8::String::NewFromUtf8(args.GetIsolate(), "tabId"))) { 138 if (details->Has(v8::String::NewFromUtf8(args.GetIsolate(), "tabId"))) {
139 dict->SetInteger("tabId", 139 dict->SetInteger("tabId",
140 details->Get(v8::String::NewFromUtf8( 140 details->Get(v8::String::NewFromUtf8(
141 args.GetIsolate(), "tabId"))->Int32Value()); 141 args.GetIsolate(), "tabId"))->Int32Value());
142 } 142 }
143 143
144 ListValue list_value; 144 ListValue list_value;
145 list_value.Append(dict); 145 list_value.Append(dict);
146 146
147 std::string name = *v8::String::AsciiValue(args[0]); 147 std::string name = *v8::String::Utf8Value(args[0]);
148 int request_id = args[2]->Int32Value(); 148 int request_id = args[2]->Int32Value();
149 bool has_callback = args[3]->BooleanValue(); 149 bool has_callback = args[3]->BooleanValue();
150 bool for_io_thread = args[4]->BooleanValue(); 150 bool for_io_thread = args[4]->BooleanValue();
151 151
152 request_sender_->StartRequest(context(), 152 request_sender_->StartRequest(context(),
153 name, 153 name,
154 request_id, 154 request_id,
155 has_callback, 155 has_callback,
156 for_io_thread, 156 for_io_thread,
157 &list_value); 157 &list_value);
158 } 158 }
159 159
160 } // namespace extensions 160 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/send_request_natives.cc ('k') | chrome/renderer/extensions/unsafe_persistent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698