| Index: chrome/renderer/extensions/request_sender.cc
|
| ===================================================================
|
| --- chrome/renderer/extensions/request_sender.cc (revision 184858)
|
| +++ chrome/renderer/extensions/request_sender.cc (working copy)
|
| @@ -7,6 +7,7 @@
|
| #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 "content/public/renderer/render_view.h"
|
| #include "content/public/renderer/v8_value_converter.h"
|
| @@ -21,18 +22,23 @@
|
| // Contains info relevant to a pending API request.
|
| struct PendingRequest {
|
| public :
|
| - PendingRequest(ChromeV8Context* context,
|
| - ChromeV8Context* caller_context,
|
| - const std::string& name)
|
| - : name(name), context(context), caller_context(caller_context) {
|
| + PendingRequest(v8::Persistent<v8::Context> context, const std::string& name,
|
| + const std::string& extension_id)
|
| + : context(context), name(name), extension_id(extension_id) {
|
| }
|
|
|
| + ~PendingRequest() {
|
| + context.Dispose(context->GetIsolate());
|
| + }
|
| +
|
| + v8::Persistent<v8::Context> context;
|
| std::string name;
|
| - ChromeV8Context* context;
|
| - ChromeV8Context* caller_context;
|
| + std::string extension_id;
|
| };
|
|
|
| -RequestSender::RequestSender(Dispatcher* dispatcher) : dispatcher_(dispatcher) {
|
| +RequestSender::RequestSender(Dispatcher* dispatcher,
|
| + ChromeV8ContextSet* context_set)
|
| + : dispatcher_(dispatcher), context_set_(context_set) {
|
| }
|
|
|
| RequestSender::~RequestSender() {
|
| @@ -53,15 +59,18 @@
|
| return result;
|
| }
|
|
|
| -void RequestSender::StartRequest(ChromeV8Context* context,
|
| - const std::string& name,
|
| +void RequestSender::StartRequest(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 = context->GetRenderView();
|
| + content::RenderView* renderview = current_context->GetRenderView();
|
| if (!renderview)
|
| return;
|
|
|
| @@ -73,26 +82,26 @@
|
| }
|
|
|
| // TODO(koz): See if we can make this a CHECK.
|
| - if (!dispatcher_->CheckContextAccessToExtensionAPI(name, context))
|
| + if (!dispatcher_->CheckCurrentContextAccessToExtensionAPI(name))
|
| return;
|
|
|
| GURL source_url;
|
| WebKit::WebSecurityOrigin source_origin;
|
| - WebKit::WebFrame* webframe = context->web_frame();
|
| + WebKit::WebFrame* webframe = current_context->web_frame();
|
| if (webframe) {
|
| source_url = webframe->document().url();
|
| source_origin = webframe->document().securityOrigin();
|
| }
|
|
|
| - std::string extension_id = context->GetExtensionID();
|
| - // Insert the current context into the PendingRequest because that's the
|
| - // context that we call back on.
|
| - InsertRequest(
|
| - request_id,
|
| - new PendingRequest(context,
|
| - dispatcher_->v8_context_set().GetCurrent(),
|
| - name));
|
| + v8::Local<v8::Context> ctx = v8::Context::GetCurrent();
|
| + v8::Persistent<v8::Context> v8_context =
|
| + v8::Persistent<v8::Context>::New(ctx->GetIsolate(), ctx);
|
| + DCHECK(!v8_context.IsEmpty());
|
|
|
| + std::string extension_id = current_context->GetExtensionID();
|
| + InsertRequest(request_id, new PendingRequest(
|
| + v8_context, name, extension_id));
|
| +
|
| ExtensionHostMsg_Request_Params params;
|
| params.name = name;
|
| params.arguments.Swap(value_args);
|
| @@ -119,10 +128,16 @@
|
| linked_ptr<PendingRequest> request = RemoveRequest(request_id);
|
|
|
| if (!request.get()) {
|
| - // This can happen if a context is destroyed while a request is in flight.
|
| + // 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;
|
| return;
|
| }
|
|
|
| + ChromeV8Context* v8_context = context_set_->GetByV8Context(request->context);
|
| + if (!v8_context)
|
| + return; // The frame went away.
|
| +
|
| v8::HandleScope handle_scope;
|
|
|
| scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
|
| @@ -130,15 +145,15 @@
|
| v8::Integer::New(request_id),
|
| v8::String::New(request->name.c_str()),
|
| v8::Boolean::New(success),
|
| - converter->ToV8Value(&responseList, request->context->v8_context()),
|
| + converter->ToV8Value(&responseList, v8_context->v8_context()),
|
| v8::String::New(error.c_str())
|
| };
|
|
|
| v8::Handle<v8::Value> retval;
|
| - CHECK(request->context->CallChromeHiddenMethod("handleResponse",
|
| - arraysize(argv),
|
| - argv,
|
| - &retval));
|
| + CHECK(v8_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()) {
|
| @@ -149,14 +164,4 @@
|
| }
|
| }
|
|
|
| -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
|
|
|