Index: chrome_frame/npapi_url_request.h |
=================================================================== |
--- chrome_frame/npapi_url_request.h (revision 37418) |
+++ chrome_frame/npapi_url_request.h (working copy) |
@@ -5,40 +5,58 @@ |
#ifndef CHROME_FRAME_NPAPI_URL_REQUEST_H_ |
#define CHROME_FRAME_NPAPI_URL_REQUEST_H_ |
+#include <map> |
+ |
#include "base/platform_thread.h" |
#include "chrome_frame/plugin_url_request.h" |
#include "third_party/WebKit/WebCore/bridge/npapi.h" |
-class NPAPIUrlRequest : public PluginUrlRequest { |
+class NPAPIUrlRequest; |
+class NPAPIUrlRequestManager : public PluginUrlRequestManager, |
+ public PluginUrlRequestDelegate { |
public: |
- explicit NPAPIUrlRequest(NPP instance); |
- ~NPAPIUrlRequest(); |
+ NPAPIUrlRequestManager(); |
+ ~NPAPIUrlRequestManager(); |
- virtual bool Start(); |
- virtual void Stop(); |
- virtual bool Read(int bytes_to_read); |
+ void set_NPPInstance(NPP instance) { |
+ instance_ = instance; |
+ } |
- // Called from NPAPI |
- bool OnStreamCreated(const char* mime_type, NPStream* stream); |
- void OnStreamDestroyed(NPReason reason); |
- int OnWriteReady(); |
- int OnWrite(void* buffer, int len); |
+ // Notifications from the browser. We find the appropriate NPAPIUrlRequest |
+ // and forward the call. |
+ bool NewStream(NPMIMEType type, NPStream* stream, |
+ NPBool seekable, uint16* stream_type); |
+ int32 WriteReady(NPStream* stream); |
+ int32 Write(NPStream* stream, int32 offset, int32 len, void* buffer); |
+ NPError DestroyStream(NPStream* stream, NPReason reason); |
+ void UrlNotify(const char* url, NPReason reason, void* notify_data); |
- // Thread unsafe implementation of ref counting, since |
- // this will be called on the plugin UI thread only. |
- virtual unsigned long API_CALL AddRef(); |
- virtual unsigned long API_CALL Release(); |
+ private: |
+ // PluginUrlRequestManager implementation. Called from AutomationClient. |
+ virtual bool IsThreadSafe(); |
+ virtual void StartRequest(int request_id, |
+ const IPC::AutomationURLRequest& request_info); |
+ virtual void ReadRequest(int request_id, int bytes_to_read); |
+ virtual void EndRequest(int request_id); |
+ virtual void StopAll(); |
- private: |
- unsigned long ref_count_; |
+ // Outstanding requests map. |
+ typedef std::map<int, scoped_refptr<NPAPIUrlRequest> > RequestMap; |
+ RequestMap request_map_; |
+ |
+ // PluginUrlRequestDelegate implementation. Forwards back to delegate. |
+ virtual void OnResponseStarted(int request_id, const char* mime_type, |
+ const char* headers, int size, |
+ base::Time last_modified, const std::string& peristent_cookies, |
+ const std::string& redirect_url, int redirect_status); |
+ virtual void OnReadComplete(int request_id, const void* buffer, int len); |
+ virtual void OnResponseEnd(int request_id, const URLRequestStatus& status); |
+ |
+ static inline NPAPIUrlRequest* RequestFromNotifyData(void* notify_data) { |
+ return reinterpret_cast<NPAPIUrlRequest*>(notify_data); |
+ } |
+ |
NPP instance_; |
- NPStream* stream_; |
- size_t pending_read_size_; |
- URLRequestStatus status_; |
- |
- PlatformThreadId thread_; |
- static int instance_count_; |
- DISALLOW_COPY_AND_ASSIGN(NPAPIUrlRequest); |
}; |
#endif // CHROME_FRAME_NPAPI_URL_REQUEST_H_ |