Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef EXTENSIONS_RENDERER_REQUEST_SENDER_H_ | 5 #ifndef EXTENSIONS_RENDERER_REQUEST_SENDER_H_ |
| 6 #define EXTENSIONS_RENDERER_REQUEST_SENDER_H_ | 6 #define EXTENSIONS_RENDERER_REQUEST_SENDER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
| 13 #include "v8/include/v8.h" | 13 #include "v8/include/v8.h" |
| 14 | 14 |
| 15 struct ExtensionHostMsg_Request_Params; | |
|
Devlin
2016/04/13 19:46:32
put top-level namespace forward declarations in on
lazyboy
2016/04/14 02:07:53
Done.
| |
| 16 | |
| 15 namespace base { | 17 namespace base { |
| 16 class ListValue; | 18 class ListValue; |
| 17 } | 19 } |
| 18 | 20 |
| 21 namespace content { | |
| 22 class RenderFrame; | |
| 23 } | |
| 24 | |
| 19 namespace extensions { | 25 namespace extensions { |
| 20 class Dispatcher; | 26 class Dispatcher; |
| 21 class ScriptContext; | 27 class ScriptContext; |
| 22 | 28 |
| 23 struct PendingRequest; | 29 struct PendingRequest; |
| 24 | 30 |
| 25 // Responsible for sending requests for named extension API functions to the | 31 // Responsible for sending requests for named extension API functions to the |
| 26 // extension host and routing the responses back to the caller. | 32 // extension host and routing the responses back to the caller. |
| 27 class RequestSender { | 33 class RequestSender { |
| 28 public: | 34 public: |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 51 | 57 |
| 52 private: | 58 private: |
| 53 RequestSender* const request_sender_; | 59 RequestSender* const request_sender_; |
| 54 const int tab_id_; | 60 const int tab_id_; |
| 55 const int previous_tab_id_; | 61 const int previous_tab_id_; |
| 56 | 62 |
| 57 DISALLOW_COPY_AND_ASSIGN(ScopedTabID); | 63 DISALLOW_COPY_AND_ASSIGN(ScopedTabID); |
| 58 }; | 64 }; |
| 59 | 65 |
| 60 explicit RequestSender(Dispatcher* dispatcher); | 66 explicit RequestSender(Dispatcher* dispatcher); |
| 61 ~RequestSender(); | 67 virtual ~RequestSender(); |
| 62 | 68 |
| 63 // In order to avoid collision, all |request_id|s passed into StartRequest() | 69 // In order to avoid collision, all |request_id|s passed into StartRequest() |
| 64 // should be generated by this method. | 70 // should be generated by this method. |
| 65 int GetNextRequestId() const; | 71 int GetNextRequestId() const; |
| 66 | 72 |
| 67 // Makes a call to the API function |name| that is to be handled by the | 73 // Makes a call to the API function |name| that is to be handled by the |
| 68 // extension host. The response to this request will be received in | 74 // extension host. The response to this request will be received in |
| 69 // HandleResponse(). | 75 // HandleResponse(). |
| 70 // TODO(koz): Remove |request_id| and generate that internally. | 76 // TODO(koz): Remove |request_id| and generate that internally. |
| 71 // There are multiple of these per render view though, so we'll | 77 // There are multiple of these per render view though, so we'll |
| 72 // need to vend the IDs centrally. | 78 // need to vend the IDs centrally. |
| 73 void StartRequest(Source* source, | 79 void StartRequest(Source* source, |
| 74 const std::string& name, | 80 const std::string& name, |
| 75 int request_id, | 81 int request_id, |
| 76 bool has_callback, | 82 bool has_callback, |
| 77 bool for_io_thread, | 83 bool for_io_thread, |
| 78 base::ListValue* value_args); | 84 base::ListValue* value_args); |
| 79 | 85 |
| 86 virtual void SendRequest(content::RenderFrame* render_frame, | |
| 87 bool for_io_thread, | |
| 88 ExtensionHostMsg_Request_Params& params); | |
| 89 | |
| 80 // Handles responses from the extension host to calls made by StartRequest(). | 90 // Handles responses from the extension host to calls made by StartRequest(). |
| 81 void HandleResponse(int request_id, | 91 void HandleResponse(int request_id, |
| 82 bool success, | 92 bool success, |
| 83 const base::ListValue& response, | 93 const base::ListValue& response, |
| 84 const std::string& error); | 94 const std::string& error); |
| 85 | 95 |
| 86 // Notifies this that a request source is no longer valid. | 96 // Notifies this that a request source is no longer valid. |
| 87 // TODO(kalman): Do this in a generic/safe way. | 97 // TODO(kalman): Do this in a generic/safe way. |
| 88 void InvalidateSource(Source* source); | 98 void InvalidateSource(Source* source); |
| 89 | 99 |
| 90 private: | 100 private: |
| 91 friend class ScopedTabID; | 101 friend class ScopedTabID; |
| 92 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; | 102 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; |
| 93 | 103 |
| 94 void InsertRequest(int request_id, PendingRequest* pending_request); | 104 void InsertRequest(int request_id, PendingRequest* pending_request); |
| 95 linked_ptr<PendingRequest> RemoveRequest(int request_id); | 105 linked_ptr<PendingRequest> RemoveRequest(int request_id); |
| 96 | 106 |
| 97 Dispatcher* dispatcher_; | 107 Dispatcher* dispatcher_; |
| 98 PendingRequestMap pending_requests_; | 108 PendingRequestMap pending_requests_; |
| 99 | 109 |
| 100 int source_tab_id_; // Id of the tab sending the request, or -1 if no tab. | 110 int source_tab_id_; // Id of the tab sending the request, or -1 if no tab. |
| 101 | 111 |
| 102 DISALLOW_COPY_AND_ASSIGN(RequestSender); | 112 DISALLOW_COPY_AND_ASSIGN(RequestSender); |
| 103 }; | 113 }; |
| 104 | 114 |
| 105 } // namespace extensions | 115 } // namespace extensions |
| 106 | 116 |
| 107 #endif // EXTENSIONS_RENDERER_REQUEST_SENDER_H_ | 117 #endif // EXTENSIONS_RENDERER_REQUEST_SENDER_H_ |
| OLD | NEW |