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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 const char* kExtensionDeps[] = { | 59 const char* kExtensionDeps[] = { |
60 "extensions/event.js", | 60 "extensions/event.js", |
61 "extensions/json_schema.js", | 61 "extensions/json_schema.js", |
62 "extensions/renderer_extension_bindings.js", | 62 "extensions/renderer_extension_bindings.js", |
63 "extensions/apitest.js" | 63 "extensions/apitest.js" |
64 }; | 64 }; |
65 | 65 |
66 // Contains info relevant to a pending API request. | 66 // Contains info relevant to a pending API request. |
67 struct PendingRequest { | 67 struct PendingRequest { |
68 public : | 68 public : |
69 PendingRequest(v8::Persistent<v8::Context> context, const std::string& name) | 69 PendingRequest(v8::Persistent<v8::Context> context, const std::string& name, |
70 : context(context), name(name) { | 70 const std::string& extension_id) |
| 71 : context(context), name(name), extension_id(extension_id) { |
71 } | 72 } |
72 v8::Persistent<v8::Context> context; | 73 v8::Persistent<v8::Context> context; |
73 std::string name; | 74 std::string name; |
| 75 std::string extension_id; |
74 }; | 76 }; |
75 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; | 77 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; |
76 | 78 |
77 base::LazyInstance<PendingRequestMap> g_pending_requests( | 79 base::LazyInstance<PendingRequestMap> g_pending_requests( |
78 base::LINKER_INITIALIZED); | 80 base::LINKER_INITIALIZED); |
79 | 81 |
80 // A RenderViewVisitor class that iterates through the set of available | 82 // A RenderViewVisitor class that iterates through the set of available |
81 // views, looking for a view of the given type, in the given browser window | 83 // views, looking for a view of the given type, in the given browser window |
82 // and within the given extension. | 84 // and within the given extension. |
83 // Used to accumulate the list of views associated with an extension. | 85 // Used to accumulate the list of views associated with an extension. |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 source_url = webframe->document().url(); | 468 source_url = webframe->document().url(); |
467 | 469 |
468 int request_id = args[2]->Int32Value(); | 470 int request_id = args[2]->Int32Value(); |
469 bool has_callback = args[3]->BooleanValue(); | 471 bool has_callback = args[3]->BooleanValue(); |
470 bool for_io_thread = args[4]->BooleanValue(); | 472 bool for_io_thread = args[4]->BooleanValue(); |
471 | 473 |
472 v8::Persistent<v8::Context> v8_context = | 474 v8::Persistent<v8::Context> v8_context = |
473 v8::Persistent<v8::Context>::New(v8::Context::GetCurrent()); | 475 v8::Persistent<v8::Context>::New(v8::Context::GetCurrent()); |
474 DCHECK(!v8_context.IsEmpty()); | 476 DCHECK(!v8_context.IsEmpty()); |
475 g_pending_requests.Get()[request_id].reset(new PendingRequest( | 477 g_pending_requests.Get()[request_id].reset(new PendingRequest( |
476 v8_context, name)); | 478 v8_context, name, current_context->extension_id())); |
477 | 479 |
478 ExtensionHostMsg_Request_Params params; | 480 ExtensionHostMsg_Request_Params params; |
479 params.name = name; | 481 params.name = name; |
480 params.arguments.Swap(value_args); | 482 params.arguments.Swap(value_args); |
481 params.source_url = source_url; | 483 params.source_url = source_url; |
482 params.request_id = request_id; | 484 params.request_id = request_id; |
483 params.has_callback = has_callback; | 485 params.has_callback = has_callback; |
484 params.user_gesture = | 486 params.user_gesture = |
485 webframe ? webframe->isProcessingUserGesture() : false; | 487 webframe ? webframe->isProcessingUserGesture() : false; |
486 if (for_io_thread) { | 488 if (for_io_thread) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 static_cast<ExtensionImpl*>(extension)->extension_dispatcher()); | 600 static_cast<ExtensionImpl*>(extension)->extension_dispatcher()); |
599 return extension; | 601 return extension; |
600 } | 602 } |
601 | 603 |
602 // static | 604 // static |
603 void ExtensionProcessBindings::HandleResponse( | 605 void ExtensionProcessBindings::HandleResponse( |
604 const ChromeV8ContextSet& contexts, | 606 const ChromeV8ContextSet& contexts, |
605 int request_id, | 607 int request_id, |
606 bool success, | 608 bool success, |
607 const std::string& response, | 609 const std::string& response, |
608 const std::string& error) { | 610 const std::string& error, |
| 611 std::string* extension_id) { |
609 PendingRequestMap::iterator request = | 612 PendingRequestMap::iterator request = |
610 g_pending_requests.Get().find(request_id); | 613 g_pending_requests.Get().find(request_id); |
611 if (request == g_pending_requests.Get().end()) { | 614 if (request == g_pending_requests.Get().end()) { |
612 // This should not be able to happen since we only remove requests when they | 615 // This should not be able to happen since we only remove requests when they |
613 // are handled. | 616 // are handled. |
614 LOG(ERROR) << "Could not find specified request id: " << request_id; | 617 LOG(ERROR) << "Could not find specified request id: " << request_id; |
615 return; | 618 return; |
616 } | 619 } |
617 | 620 |
618 ChromeV8Context* v8_context = | 621 ChromeV8Context* v8_context = |
(...skipping 16 matching lines...) Expand all Loading... |
635 &retval)); | 638 &retval)); |
636 // In debug, the js will validate the callback parameters and return a | 639 // In debug, the js will validate the callback parameters and return a |
637 // string if a validation error has occured. | 640 // string if a validation error has occured. |
638 #ifndef NDEBUG | 641 #ifndef NDEBUG |
639 if (!retval.IsEmpty() && !retval->IsUndefined()) { | 642 if (!retval.IsEmpty() && !retval->IsUndefined()) { |
640 std::string error = *v8::String::AsciiValue(retval); | 643 std::string error = *v8::String::AsciiValue(retval); |
641 DCHECK(false) << error; | 644 DCHECK(false) << error; |
642 } | 645 } |
643 #endif | 646 #endif |
644 | 647 |
| 648 // Save the extension id before erasing the request. |
| 649 *extension_id = request->second->extension_id; |
| 650 |
645 request->second->context.Dispose(); | 651 request->second->context.Dispose(); |
646 request->second->context.Clear(); | 652 request->second->context.Clear(); |
647 g_pending_requests.Get().erase(request); | 653 g_pending_requests.Get().erase(request); |
648 } | 654 } |
| 655 |
| 656 // static |
| 657 bool ExtensionProcessBindings::HasPendingRequests( |
| 658 const std::string& extension_id) { |
| 659 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin(); |
| 660 it != g_pending_requests.Get().end(); ++it) { |
| 661 if (it->second->extension_id == extension_id) |
| 662 return true; |
| 663 } |
| 664 return false; |
| 665 } |
OLD | NEW |