OLD | NEW |
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 21 matching lines...) Expand all Loading... |
32 RouteFunction( | 32 RouteFunction( |
33 "SetIconCommon", | 33 "SetIconCommon", |
34 base::Bind(&SetIconNatives::SetIconCommon, base::Unretained(this))); | 34 base::Bind(&SetIconNatives::SetIconCommon, base::Unretained(this))); |
35 } | 35 } |
36 | 36 |
37 bool SetIconNatives::ConvertImageDataToBitmapValue( | 37 bool SetIconNatives::ConvertImageDataToBitmapValue( |
38 const v8::Local<v8::Object> image_data, | 38 const v8::Local<v8::Object> image_data, |
39 v8::Local<v8::Value>* image_data_bitmap) { | 39 v8::Local<v8::Value>* image_data_bitmap) { |
40 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); | 40 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); |
41 v8::Local<v8::Object> data = | 41 v8::Local<v8::Object> data = |
42 image_data->Get(v8::String::NewFromUtf8(isolate, "data"))->ToObject(); | 42 image_data->Get(v8::String::NewFromUtf8(isolate, "data")) |
| 43 ->ToObject(isolate); |
43 int width = | 44 int width = |
44 image_data->Get(v8::String::NewFromUtf8(isolate, "width"))->Int32Value(); | 45 image_data->Get(v8::String::NewFromUtf8(isolate, "width"))->Int32Value(); |
45 int height = | 46 int height = |
46 image_data->Get(v8::String::NewFromUtf8(isolate, "height"))->Int32Value(); | 47 image_data->Get(v8::String::NewFromUtf8(isolate, "height"))->Int32Value(); |
47 | 48 |
48 if (width <= 0 || height <= 0) { | 49 if (width <= 0 || height <= 0) { |
49 isolate->ThrowException(v8::Exception::Error( | 50 isolate->ThrowException(v8::Exception::Error( |
50 v8::String::NewFromUtf8(isolate, kInvalidDimensions))); | 51 v8::String::NewFromUtf8(isolate, kInvalidDimensions))); |
51 return false; | 52 return false; |
52 } | 53 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 &buffer, context()->v8_context()->Global(), isolate); | 101 &buffer, context()->v8_context()->Global(), isolate); |
101 | 102 |
102 return true; | 103 return true; |
103 } | 104 } |
104 | 105 |
105 bool SetIconNatives::ConvertImageDataSetToBitmapValueSet( | 106 bool SetIconNatives::ConvertImageDataSetToBitmapValueSet( |
106 v8::Local<v8::Object>& details, | 107 v8::Local<v8::Object>& details, |
107 v8::Local<v8::Object>* bitmap_set_value) { | 108 v8::Local<v8::Object>* bitmap_set_value) { |
108 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); | 109 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); |
109 v8::Local<v8::Object> image_data_set = | 110 v8::Local<v8::Object> image_data_set = |
110 details->Get(v8::String::NewFromUtf8(isolate, "imageData"))->ToObject(); | 111 details->Get(v8::String::NewFromUtf8(isolate, "imageData")) |
| 112 ->ToObject(isolate); |
111 | 113 |
112 DCHECK(bitmap_set_value); | 114 DCHECK(bitmap_set_value); |
113 for (size_t i = 0; i < arraysize(kImageSizeKeys); i++) { | 115 for (size_t i = 0; i < arraysize(kImageSizeKeys); i++) { |
114 if (!image_data_set->Has( | 116 if (!image_data_set->Has( |
115 v8::String::NewFromUtf8(isolate, kImageSizeKeys[i]))) | 117 v8::String::NewFromUtf8(isolate, kImageSizeKeys[i]))) |
116 continue; | 118 continue; |
117 v8::Local<v8::Object> image_data = | 119 v8::Local<v8::Object> image_data = |
118 image_data_set->Get(v8::String::NewFromUtf8(isolate, kImageSizeKeys[i])) | 120 image_data_set->Get(v8::String::NewFromUtf8(isolate, kImageSizeKeys[i])) |
119 ->ToObject(); | 121 ->ToObject(isolate); |
120 v8::Local<v8::Value> image_data_bitmap; | 122 v8::Local<v8::Value> image_data_bitmap; |
121 if (!ConvertImageDataToBitmapValue(image_data, &image_data_bitmap)) | 123 if (!ConvertImageDataToBitmapValue(image_data, &image_data_bitmap)) |
122 return false; | 124 return false; |
123 (*bitmap_set_value)->Set( | 125 (*bitmap_set_value)->Set( |
124 v8::String::NewFromUtf8(isolate, kImageSizeKeys[i]), image_data_bitmap); | 126 v8::String::NewFromUtf8(isolate, kImageSizeKeys[i]), image_data_bitmap); |
125 } | 127 } |
126 return true; | 128 return true; |
127 } | 129 } |
128 | 130 |
129 void SetIconNatives::SetIconCommon( | 131 void SetIconNatives::SetIconCommon( |
130 const v8::FunctionCallbackInfo<v8::Value>& args) { | 132 const v8::FunctionCallbackInfo<v8::Value>& args) { |
131 CHECK_EQ(1, args.Length()); | 133 CHECK_EQ(1, args.Length()); |
132 CHECK(args[0]->IsObject()); | 134 CHECK(args[0]->IsObject()); |
133 v8::Local<v8::Object> details = args[0]->ToObject(); | 135 v8::Local<v8::Object> details = args[0]->ToObject(args.GetIsolate()); |
134 v8::Local<v8::Object> bitmap_set_value(v8::Object::New(args.GetIsolate())); | 136 v8::Local<v8::Object> bitmap_set_value(v8::Object::New(args.GetIsolate())); |
135 if (!ConvertImageDataSetToBitmapValueSet(details, &bitmap_set_value)) | 137 if (!ConvertImageDataSetToBitmapValueSet(details, &bitmap_set_value)) |
136 return; | 138 return; |
137 | 139 |
138 v8::Local<v8::Object> dict(v8::Object::New(args.GetIsolate())); | 140 v8::Local<v8::Object> dict(v8::Object::New(args.GetIsolate())); |
139 dict->Set(v8::String::NewFromUtf8(args.GetIsolate(), "imageData"), | 141 dict->Set(v8::String::NewFromUtf8(args.GetIsolate(), "imageData"), |
140 bitmap_set_value); | 142 bitmap_set_value); |
141 if (details->Has(v8::String::NewFromUtf8(args.GetIsolate(), "tabId"))) { | 143 if (details->Has(v8::String::NewFromUtf8(args.GetIsolate(), "tabId"))) { |
142 dict->Set( | 144 dict->Set( |
143 v8::String::NewFromUtf8(args.GetIsolate(), "tabId"), | 145 v8::String::NewFromUtf8(args.GetIsolate(), "tabId"), |
144 details->Get(v8::String::NewFromUtf8(args.GetIsolate(), "tabId"))); | 146 details->Get(v8::String::NewFromUtf8(args.GetIsolate(), "tabId"))); |
145 } | 147 } |
146 args.GetReturnValue().Set(dict); | 148 args.GetReturnValue().Set(dict); |
147 } | 149 } |
148 | 150 |
149 } // namespace extensions | 151 } // namespace extensions |
OLD | NEW |