OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_process_bindings.h" | 5 #include "chrome/renderer/extensions/extension_process_bindings.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 return page_action_vector; | 429 return page_action_vector; |
430 } | 430 } |
431 | 431 |
432 // Common code for starting an API request to the browser. |value_args| | 432 // Common code for starting an API request to the browser. |value_args| |
433 // contains the request's arguments. | 433 // contains the request's arguments. |
434 // Steals value_args contents for efficiency. | 434 // Steals value_args contents for efficiency. |
435 static v8::Handle<v8::Value> StartRequestCommon( | 435 static v8::Handle<v8::Value> StartRequestCommon( |
436 const v8::Arguments& args, ListValue* value_args) { | 436 const v8::Arguments& args, ListValue* value_args) { |
437 ExtensionImpl* v8_extension = GetFromArguments<ExtensionImpl>(args); | 437 ExtensionImpl* v8_extension = GetFromArguments<ExtensionImpl>(args); |
438 | 438 |
439 const ChromeV8ContextSet& contexts = | |
440 v8_extension->extension_dispatcher()->v8_context_set(); | |
441 ChromeV8Context* current_context = contexts.GetCurrent(); | |
442 if (!current_context) | |
443 return v8::Undefined(); | |
444 | |
439 // Get the current RenderView so that we can send a routed IPC message from | 445 // Get the current RenderView so that we can send a routed IPC message from |
440 // the correct source. | 446 // the correct source. |
441 content::RenderView* renderview = GetCurrentRenderView(); | 447 content::RenderView* renderview = current_context->GetRenderView(); |
442 if (!renderview) | 448 if (!renderview) |
443 return v8::Undefined(); | 449 return v8::Undefined(); |
444 | 450 |
445 std::string name = *v8::String::AsciiValue(args[0]); | 451 std::string name = *v8::String::AsciiValue(args[0]); |
446 const std::set<std::string>& function_names = | 452 const std::set<std::string>& function_names = |
447 v8_extension->extension_dispatcher_->function_names(); | 453 v8_extension->extension_dispatcher_->function_names(); |
448 if (function_names.find(name) == function_names.end()) { | 454 if (function_names.find(name) == function_names.end()) { |
449 NOTREACHED() << "Unexpected function " << name; | 455 NOTREACHED() << "Unexpected function " << name; |
450 return v8::Undefined(); | 456 return v8::Undefined(); |
451 } | 457 } |
452 | 458 |
459 // TODO: add this to ChromeV8Context. | |
Aaron Boodman
2011/10/28 23:29:46
TODO(aa)
Tessa MacDuff
2011/10/29 00:06:54
Done.
| |
453 if (!v8_extension->CheckPermissionForCurrentRenderView(name)) | 460 if (!v8_extension->CheckPermissionForCurrentRenderView(name)) |
454 return v8::Undefined(); | 461 return v8::Undefined(); |
455 | 462 |
456 GURL source_url; | 463 GURL source_url; |
457 WebFrame* webframe = WebFrame::frameForCurrentContext(); | 464 WebFrame* webframe = current_context->web_frame(); |
458 if (webframe) | 465 if (webframe) |
459 source_url = webframe->document().url(); | 466 source_url = webframe->document().url(); |
460 | 467 |
461 int request_id = args[2]->Int32Value(); | 468 int request_id = args[2]->Int32Value(); |
462 bool has_callback = args[3]->BooleanValue(); | 469 bool has_callback = args[3]->BooleanValue(); |
463 bool for_io_thread = args[4]->BooleanValue(); | 470 bool for_io_thread = args[4]->BooleanValue(); |
464 | 471 |
465 v8::Persistent<v8::Context> current_context = | 472 v8::Persistent<v8::Context> persistent_context = |
Aaron Boodman
2011/10/28 23:29:46
Better name is v8_context to distinguish from "nor
Tessa MacDuff
2011/10/29 00:06:54
Done.
| |
466 v8::Persistent<v8::Context>::New(v8::Context::GetCurrent()); | 473 v8::Persistent<v8::Context>::New(v8::Context::GetCurrent()); |
467 DCHECK(!current_context.IsEmpty()); | 474 DCHECK(!persistent_context.IsEmpty()); |
468 g_pending_requests.Get()[request_id].reset(new PendingRequest( | 475 g_pending_requests.Get()[request_id].reset(new PendingRequest( |
469 current_context, name)); | 476 persistent_context, name)); |
470 | 477 |
471 ExtensionHostMsg_Request_Params params; | 478 ExtensionHostMsg_Request_Params params; |
472 params.name = name; | 479 params.name = name; |
473 params.arguments.Swap(value_args); | 480 params.arguments.Swap(value_args); |
474 params.source_url = source_url; | 481 params.source_url = source_url; |
475 params.request_id = request_id; | 482 params.request_id = request_id; |
476 params.has_callback = has_callback; | 483 params.has_callback = has_callback; |
477 params.user_gesture = | 484 params.user_gesture = |
478 webframe ? webframe->isProcessingUserGesture() : false; | 485 webframe ? webframe->isProcessingUserGesture() : false; |
479 if (for_io_thread) { | 486 if (for_io_thread) { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
632 if (!retval.IsEmpty() && !retval->IsUndefined()) { | 639 if (!retval.IsEmpty() && !retval->IsUndefined()) { |
633 std::string error = *v8::String::AsciiValue(retval); | 640 std::string error = *v8::String::AsciiValue(retval); |
634 DCHECK(false) << error; | 641 DCHECK(false) << error; |
635 } | 642 } |
636 #endif | 643 #endif |
637 | 644 |
638 request->second->context.Dispose(); | 645 request->second->context.Dispose(); |
639 request->second->context.Clear(); | 646 request->second->context.Clear(); |
640 g_pending_requests.Get().erase(request); | 647 g_pending_requests.Get().erase(request); |
641 } | 648 } |
OLD | NEW |