OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <map> | 5 #include <map> |
6 #include <set> | 6 #include <set> |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "chrome/renderer/extensions/extension_process_bindings.h" | 10 #include "chrome/renderer/extensions/extension_process_bindings.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 } else if (name->Equals(v8::String::New("OpenChannelToTab"))) { | 204 } else if (name->Equals(v8::String::New("OpenChannelToTab"))) { |
205 return v8::FunctionTemplate::New(OpenChannelToTab); | 205 return v8::FunctionTemplate::New(OpenChannelToTab); |
206 } else if (name->Equals(v8::String::New("GetCurrentPageActions"))) { | 206 } else if (name->Equals(v8::String::New("GetCurrentPageActions"))) { |
207 return v8::FunctionTemplate::New(GetCurrentPageActions); | 207 return v8::FunctionTemplate::New(GetCurrentPageActions); |
208 } else if (name->Equals(v8::String::New("StartRequest"))) { | 208 } else if (name->Equals(v8::String::New("StartRequest"))) { |
209 return v8::FunctionTemplate::New(StartRequest); | 209 return v8::FunctionTemplate::New(StartRequest); |
210 } else if (name->Equals(v8::String::New("GetRenderViewId"))) { | 210 } else if (name->Equals(v8::String::New("GetRenderViewId"))) { |
211 return v8::FunctionTemplate::New(GetRenderViewId); | 211 return v8::FunctionTemplate::New(GetRenderViewId); |
212 } else if (name->Equals(v8::String::New("GetL10nMessage"))) { | 212 } else if (name->Equals(v8::String::New("GetL10nMessage"))) { |
213 return v8::FunctionTemplate::New(GetL10nMessage); | 213 return v8::FunctionTemplate::New(GetL10nMessage); |
214 } else if (name->Equals(v8::String::New("SetBrowserActionIcon"))) { | 214 } else if (name->Equals(v8::String::New("SetExtensionActionIcon"))) { |
215 return v8::FunctionTemplate::New(SetBrowserActionIcon); | 215 return v8::FunctionTemplate::New(SetExtensionActionIcon); |
216 } | 216 } |
217 | 217 |
218 return ExtensionBase::GetNativeFunction(name); | 218 return ExtensionBase::GetNativeFunction(name); |
219 } | 219 } |
220 | 220 |
221 private: | 221 private: |
222 static v8::Handle<v8::Value> GetExtensionAPIDefinition( | 222 static v8::Handle<v8::Value> GetExtensionAPIDefinition( |
223 const v8::Arguments& args) { | 223 const v8::Arguments& args) { |
224 return v8::String::New(GetStringResource<IDR_EXTENSION_API_JSON>()); | 224 return v8::String::New(GetStringResource<IDR_EXTENSION_API_JSON>()); |
225 } | 225 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 // Since we do the serialization in the v8 extension, we should always get | 400 // Since we do the serialization in the v8 extension, we should always get |
401 // valid JSON. | 401 // valid JSON. |
402 if (!value_args) { | 402 if (!value_args) { |
403 NOTREACHED() << "Invalid JSON passed to StartRequest."; | 403 NOTREACHED() << "Invalid JSON passed to StartRequest."; |
404 return v8::Undefined(); | 404 return v8::Undefined(); |
405 } | 405 } |
406 | 406 |
407 return StartRequestCommon(args, value_args); | 407 return StartRequestCommon(args, value_args); |
408 } | 408 } |
409 | 409 |
410 // A special request for setting the browser action icon. This function | 410 // A special request for setting the extension action icon. This function |
411 // accepts a canvas ImageData object, so it needs to do extra processing | 411 // accepts a canvas ImageData object, so it needs to do extra processing |
412 // before sending the request to the browser. | 412 // before sending the request to the browser. |
413 static v8::Handle<v8::Value> SetBrowserActionIcon(const v8::Arguments& args) { | 413 static v8::Handle<v8::Value> SetExtensionActionIcon(const v8::Arguments& args)
{ |
414 v8::Local<v8::Object> details = args[1]->ToObject(); | 414 v8::Local<v8::Object> details = args[1]->ToObject(); |
| 415 int tab_id = details->Get(v8::String::New("tabId"))->Int32Value(); |
415 v8::Local<v8::Object> image_data = | 416 v8::Local<v8::Object> image_data = |
416 details->Get(v8::String::New("imageData"))->ToObject(); | 417 details->Get(v8::String::New("imageData"))->ToObject(); |
417 v8::Local<v8::Object> data = | 418 v8::Local<v8::Object> data = |
418 image_data->Get(v8::String::New("data"))->ToObject(); | 419 image_data->Get(v8::String::New("data"))->ToObject(); |
419 int width = image_data->Get(v8::String::New("width"))->Int32Value(); | 420 int width = image_data->Get(v8::String::New("width"))->Int32Value(); |
420 int height = image_data->Get(v8::String::New("height"))->Int32Value(); | 421 int height = image_data->Get(v8::String::New("height"))->Int32Value(); |
421 | 422 |
422 int data_length = data->Get(v8::String::New("length"))->Int32Value(); | 423 int data_length = data->Get(v8::String::New("length"))->Int32Value(); |
423 if (data_length != 4 * width * height) { | 424 if (data_length != 4 * width * height) { |
424 NOTREACHED() << | 425 NOTREACHED() << "Invalid argument to setIcon. Expecting ImageData."; |
425 "Invalid argument to browserAction.setIcon. Expecting ImageData."; | |
426 return v8::Undefined(); | 426 return v8::Undefined(); |
427 } | 427 } |
428 | 428 |
429 SkBitmap bitmap; | 429 SkBitmap bitmap; |
430 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 430 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
431 bitmap.allocPixels(); | 431 bitmap.allocPixels(); |
432 bitmap.eraseARGB(0, 0, 0, 0); | 432 bitmap.eraseARGB(0, 0, 0, 0); |
433 | 433 |
434 uint32_t* pixels = bitmap.getAddr32(0, 0); | 434 uint32_t* pixels = bitmap.getAddr32(0, 0); |
435 for (int t = 0; t < width*height; t++) { | 435 for (int t = 0; t < width*height; t++) { |
436 // |data| is RGBA, pixels is ARGB. | 436 // |data| is RGBA, pixels is ARGB. |
437 pixels[t] = | 437 pixels[t] = |
438 ((data->Get(v8::Integer::New(4*t + 3))->Int32Value() & 0xFF) << 24) | | 438 ((data->Get(v8::Integer::New(4*t + 3))->Int32Value() & 0xFF) << 24) | |
439 ((data->Get(v8::Integer::New(4*t + 0))->Int32Value() & 0xFF) << 16) | | 439 ((data->Get(v8::Integer::New(4*t + 0))->Int32Value() & 0xFF) << 16) | |
440 ((data->Get(v8::Integer::New(4*t + 1))->Int32Value() & 0xFF) << 8) | | 440 ((data->Get(v8::Integer::New(4*t + 1))->Int32Value() & 0xFF) << 8) | |
441 ((data->Get(v8::Integer::New(4*t + 2))->Int32Value() & 0xFF) << 0); | 441 ((data->Get(v8::Integer::New(4*t + 2))->Int32Value() & 0xFF) << 0); |
442 } | 442 } |
443 | 443 |
444 // Construct the Value object. | 444 // Construct the Value object. |
445 IPC::Message bitmap_pickle; | 445 IPC::Message bitmap_pickle; |
446 IPC::WriteParam(&bitmap_pickle, bitmap); | 446 IPC::WriteParam(&bitmap_pickle, bitmap); |
447 Value* bitmap_value = BinaryValue::CreateWithCopiedBuffer( | 447 Value* bitmap_value = BinaryValue::CreateWithCopiedBuffer( |
448 static_cast<const char*>(bitmap_pickle.data()), bitmap_pickle.size()); | 448 static_cast<const char*>(bitmap_pickle.data()), bitmap_pickle.size()); |
449 | 449 |
450 return StartRequestCommon(args, bitmap_value); | 450 DictionaryValue* dict = new DictionaryValue(); |
| 451 dict->Set(L"imageData", bitmap_value); |
| 452 dict->SetInteger(L"tabId", tab_id); |
| 453 |
| 454 return StartRequestCommon(args, dict); |
451 } | 455 } |
452 | 456 |
453 static v8::Handle<v8::Value> GetRenderViewId(const v8::Arguments& args) { | 457 static v8::Handle<v8::Value> GetRenderViewId(const v8::Arguments& args) { |
454 RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext(); | 458 RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext(); |
455 if (!renderview) | 459 if (!renderview) |
456 return v8::Undefined(); | 460 return v8::Undefined(); |
457 return v8::Integer::New(renderview->routing_id()); | 461 return v8::Integer::New(renderview->routing_id()); |
458 } | 462 } |
459 }; | 463 }; |
460 | 464 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 return; | 603 return; |
600 | 604 |
601 v8::HandleScope handle_scope; | 605 v8::HandleScope handle_scope; |
602 WebFrame* frame = view->mainFrame(); | 606 WebFrame* frame = view->mainFrame(); |
603 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 607 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
604 v8::Handle<v8::Value> argv[1]; | 608 v8::Handle<v8::Value> argv[1]; |
605 argv[0] = v8::String::New(type_str); | 609 argv[0] = v8::String::New(type_str); |
606 bindings_utils::CallFunctionInContext(context, "setViewType", | 610 bindings_utils::CallFunctionInContext(context, "setViewType", |
607 arraysize(argv), argv); | 611 arraysize(argv), argv); |
608 } | 612 } |
OLD | NEW |