| Index: chrome/renderer/extensions/request_sender.cc
|
| diff --git a/chrome/renderer/extensions/request_sender.cc b/chrome/renderer/extensions/request_sender.cc
|
| index 0c54e17dd61598530b846697ccdf63651b842a5f..e59be5a3d542d4b191ab2ab18e0b2b4f3f774b64 100644
|
| --- a/chrome/renderer/extensions/request_sender.cc
|
| +++ b/chrome/renderer/extensions/request_sender.cc
|
| @@ -7,7 +7,6 @@
|
| #include "base/values.h"
|
| #include "chrome/common/extensions/extension_messages.h"
|
| #include "chrome/renderer/extensions/chrome_v8_context.h"
|
| -#include "chrome/renderer/extensions/chrome_v8_context_set.h"
|
| #include "chrome/renderer/extensions/dispatcher.h"
|
| #include "chrome/renderer/extensions/scoped_persistent.h"
|
| #include "content/public/renderer/render_view.h"
|
| @@ -24,20 +23,15 @@ namespace extensions {
|
| // Contains info relevant to a pending API request.
|
| struct PendingRequest {
|
| public :
|
| - PendingRequest(v8::Handle<v8::Context> context,
|
| - const std::string& name,
|
| - const std::string& extension_id)
|
| - : context(context), name(name), extension_id(extension_id) {
|
| + PendingRequest(const std::string& name, ChromeV8Context* context)
|
| + : name(name), context(context) {
|
| }
|
|
|
| - ScopedPersistent<v8::Context> context;
|
| std::string name;
|
| - std::string extension_id;
|
| + ChromeV8Context* context;
|
| };
|
|
|
| -RequestSender::RequestSender(Dispatcher* dispatcher,
|
| - ChromeV8ContextSet* context_set)
|
| - : dispatcher_(dispatcher), context_set_(context_set) {
|
| +RequestSender::RequestSender(Dispatcher* dispatcher) : dispatcher_(dispatcher) {
|
| }
|
|
|
| RequestSender::~RequestSender() {
|
| @@ -58,18 +52,15 @@ linked_ptr<PendingRequest> RequestSender::RemoveRequest(int request_id) {
|
| return result;
|
| }
|
|
|
| -void RequestSender::StartRequest(const std::string& name,
|
| +void RequestSender::StartRequest(ChromeV8Context* context,
|
| + const std::string& name,
|
| int request_id,
|
| bool has_callback,
|
| bool for_io_thread,
|
| base::ListValue* value_args) {
|
| - ChromeV8Context* current_context = context_set_->GetCurrent();
|
| - if (!current_context)
|
| - return;
|
| -
|
| // Get the current RenderView so that we can send a routed IPC message from
|
| // the correct source.
|
| - content::RenderView* renderview = current_context->GetRenderView();
|
| + content::RenderView* renderview = context->GetRenderView();
|
| if (!renderview)
|
| return;
|
|
|
| @@ -81,25 +72,23 @@ void RequestSender::StartRequest(const std::string& name,
|
| }
|
|
|
| // TODO(koz): See if we can make this a CHECK.
|
| - if (!dispatcher_->CheckCurrentContextAccessToExtensionAPI(name))
|
| + if (!dispatcher_->CheckContextAccessToExtensionAPI(name, context))
|
| return;
|
|
|
| GURL source_url;
|
| WebKit::WebSecurityOrigin source_origin;
|
| - WebKit::WebFrame* webframe = current_context->web_frame();
|
| + WebKit::WebFrame* webframe = context->web_frame();
|
| if (webframe) {
|
| source_url = webframe->document().url();
|
| source_origin = webframe->document().securityOrigin();
|
| }
|
|
|
| - std::string extension_id = current_context->GetExtensionID();
|
| - InsertRequest(request_id, new PendingRequest(
|
| - v8::Context::GetCurrent(), name, extension_id));
|
| + InsertRequest(request_id, new PendingRequest(name, context));
|
|
|
| ExtensionHostMsg_Request_Params params;
|
| params.name = name;
|
| params.arguments.Swap(value_args);
|
| - params.extension_id = extension_id;
|
| + params.extension_id = context->GetExtensionID();
|
| params.source_url = source_url;
|
| params.source_origin = source_origin.toString();
|
| params.request_id = request_id;
|
| @@ -122,17 +111,10 @@ void RequestSender::HandleResponse(int request_id,
|
| linked_ptr<PendingRequest> request = RemoveRequest(request_id);
|
|
|
| if (!request.get()) {
|
| - // This should not be able to happen since we only remove requests when
|
| - // they are handled.
|
| - LOG(ERROR) << "Could not find specified request id: " << request_id;
|
| + // This can happen if a context is destroyed while a request is in flight.
|
| return;
|
| }
|
|
|
| - ChromeV8Context* v8_context =
|
| - context_set_->GetByV8Context(request->context.get());
|
| - if (!v8_context)
|
| - return; // The frame went away.
|
| -
|
| v8::HandleScope handle_scope;
|
|
|
| scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
|
| @@ -140,15 +122,15 @@ void RequestSender::HandleResponse(int request_id,
|
| v8::Integer::New(request_id),
|
| v8::String::New(request->name.c_str()),
|
| v8::Boolean::New(success),
|
| - converter->ToV8Value(&responseList, v8_context->v8_context()),
|
| + converter->ToV8Value(&responseList, request->context->v8_context()),
|
| v8::String::New(error.c_str())
|
| };
|
|
|
| v8::Handle<v8::Value> retval;
|
| - CHECK(v8_context->CallChromeHiddenMethod("handleResponse",
|
| - arraysize(argv),
|
| - argv,
|
| - &retval));
|
| + CHECK(request->context->CallChromeHiddenMethod("handleResponse",
|
| + arraysize(argv),
|
| + argv,
|
| + &retval));
|
| // In debug, the js will validate the callback parameters and return a
|
| // string if a validation error has occured.
|
| if (DCHECK_IS_ON()) {
|
| @@ -159,4 +141,14 @@ void RequestSender::HandleResponse(int request_id,
|
| }
|
| }
|
|
|
| +void RequestSender::InvalidateContext(ChromeV8Context* context) {
|
| + for (PendingRequestMap::iterator it = pending_requests_.begin();
|
| + it != pending_requests_.end();) {
|
| + if (it->second->context == context)
|
| + pending_requests_.erase(it++);
|
| + else
|
| + ++it;
|
| + }
|
| +}
|
| +
|
| } // namespace extensions
|
|
|