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; |
| 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 // Sends the IPC to extension host for the API function that is described |
| 87 // in |params|. |
| 88 virtual void SendRequest(content::RenderFrame* render_frame, |
| 89 bool for_io_thread, |
| 90 ExtensionHostMsg_Request_Params& params); |
| 91 |
80 // Handles responses from the extension host to calls made by StartRequest(). | 92 // Handles responses from the extension host to calls made by StartRequest(). |
81 void HandleResponse(int request_id, | 93 void HandleResponse(int request_id, |
82 bool success, | 94 bool success, |
83 const base::ListValue& response, | 95 const base::ListValue& response, |
84 const std::string& error); | 96 const std::string& error); |
85 | 97 |
86 // Notifies this that a request source is no longer valid. | 98 // Notifies this that a request source is no longer valid. |
87 // TODO(kalman): Do this in a generic/safe way. | 99 // TODO(kalman): Do this in a generic/safe way. |
88 void InvalidateSource(Source* source); | 100 void InvalidateSource(Source* source); |
89 | 101 |
90 private: | 102 private: |
91 friend class ScopedTabID; | 103 friend class ScopedTabID; |
92 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; | 104 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; |
93 | 105 |
94 void InsertRequest(int request_id, PendingRequest* pending_request); | 106 void InsertRequest(int request_id, PendingRequest* pending_request); |
95 linked_ptr<PendingRequest> RemoveRequest(int request_id); | 107 linked_ptr<PendingRequest> RemoveRequest(int request_id); |
96 | 108 |
97 Dispatcher* dispatcher_; | 109 Dispatcher* dispatcher_; |
98 PendingRequestMap pending_requests_; | 110 PendingRequestMap pending_requests_; |
99 | 111 |
100 int source_tab_id_; // Id of the tab sending the request, or -1 if no tab. | 112 int source_tab_id_; // Id of the tab sending the request, or -1 if no tab. |
101 | 113 |
102 DISALLOW_COPY_AND_ASSIGN(RequestSender); | 114 DISALLOW_COPY_AND_ASSIGN(RequestSender); |
103 }; | 115 }; |
104 | 116 |
105 } // namespace extensions | 117 } // namespace extensions |
106 | 118 |
107 #endif // EXTENSIONS_RENDERER_REQUEST_SENDER_H_ | 119 #endif // EXTENSIONS_RENDERER_REQUEST_SENDER_H_ |
OLD | NEW |