| 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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 return v8::Undefined(); | 451 return v8::Undefined(); |
| 452 | 452 |
| 453 std::string name = *v8::String::AsciiValue(args[0]); | 453 std::string name = *v8::String::AsciiValue(args[0]); |
| 454 const std::set<std::string>& function_names = | 454 const std::set<std::string>& function_names = |
| 455 v8_extension->extension_dispatcher_->function_names(); | 455 v8_extension->extension_dispatcher_->function_names(); |
| 456 if (function_names.find(name) == function_names.end()) { | 456 if (function_names.find(name) == function_names.end()) { |
| 457 NOTREACHED() << "Unexpected function " << name; | 457 NOTREACHED() << "Unexpected function " << name; |
| 458 return v8::Undefined(); | 458 return v8::Undefined(); |
| 459 } | 459 } |
| 460 | 460 |
| 461 // TODO(aa): add this to ChromeV8Context. | 461 if (!v8_extension->CheckCurrentContextAccessToExtensionAPI(name)) |
| 462 if (!v8_extension->CheckPermissionForCurrentRenderView(name)) | |
| 463 return v8::Undefined(); | 462 return v8::Undefined(); |
| 464 | 463 |
| 465 GURL source_url; | 464 GURL source_url; |
| 466 WebFrame* webframe = current_context->web_frame(); | 465 WebFrame* webframe = current_context->web_frame(); |
| 467 if (webframe) | 466 if (webframe) |
| 468 source_url = webframe->document().url(); | 467 source_url = webframe->document().url(); |
| 469 | 468 |
| 470 int request_id = args[2]->Int32Value(); | 469 int request_id = args[2]->Int32Value(); |
| 471 bool has_callback = args[3]->BooleanValue(); | 470 bool has_callback = args[3]->BooleanValue(); |
| 472 bool for_io_thread = args[4]->BooleanValue(); | 471 bool for_io_thread = args[4]->BooleanValue(); |
| 473 | 472 |
| 474 v8::Persistent<v8::Context> v8_context = | 473 v8::Persistent<v8::Context> v8_context = |
| 475 v8::Persistent<v8::Context>::New(v8::Context::GetCurrent()); | 474 v8::Persistent<v8::Context>::New(v8::Context::GetCurrent()); |
| 476 DCHECK(!v8_context.IsEmpty()); | 475 DCHECK(!v8_context.IsEmpty()); |
| 477 g_pending_requests.Get()[request_id].reset(new PendingRequest( | 476 g_pending_requests.Get()[request_id].reset(new PendingRequest( |
| 478 v8_context, name, current_context->extension_id())); | 477 v8_context, name, current_context->extension_id())); |
| 479 | 478 |
| 480 ExtensionHostMsg_Request_Params params; | 479 ExtensionHostMsg_Request_Params params; |
| 481 params.name = name; | 480 params.name = name; |
| 482 params.arguments.Swap(value_args); | 481 params.arguments.Swap(value_args); |
| 482 params.extension_id = current_context->extension_id(); |
| 483 params.source_url = source_url; | 483 params.source_url = source_url; |
| 484 params.request_id = request_id; | 484 params.request_id = request_id; |
| 485 params.has_callback = has_callback; | 485 params.has_callback = has_callback; |
| 486 params.user_gesture = | 486 params.user_gesture = |
| 487 webframe ? webframe->isProcessingUserGesture() : false; | 487 webframe ? webframe->isProcessingUserGesture() : false; |
| 488 if (for_io_thread) { | 488 if (for_io_thread) { |
| 489 renderview->Send(new ExtensionHostMsg_RequestForIOThread( | 489 renderview->Send(new ExtensionHostMsg_RequestForIOThread( |
| 490 renderview->GetRoutingId(), params)); | 490 renderview->GetRoutingId(), params)); |
| 491 } else { | 491 } else { |
| 492 renderview->Send(new ExtensionHostMsg_Request( | 492 renderview->Send(new ExtensionHostMsg_Request( |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 // static | 656 // static |
| 657 bool ExtensionProcessBindings::HasPendingRequests( | 657 bool ExtensionProcessBindings::HasPendingRequests( |
| 658 const std::string& extension_id) { | 658 const std::string& extension_id) { |
| 659 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin(); | 659 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin(); |
| 660 it != g_pending_requests.Get().end(); ++it) { | 660 it != g_pending_requests.Get().end(); ++it) { |
| 661 if (it->second->extension_id == extension_id) | 661 if (it->second->extension_id == extension_id) |
| 662 return true; | 662 return true; |
| 663 } | 663 } |
| 664 return false; | 664 return false; |
| 665 } | 665 } |
| OLD | NEW |