OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 CHROME_FRAME_NPAPI_URL_REQUEST_H_ | 5 #ifndef CHROME_FRAME_NPAPI_URL_REQUEST_H_ |
6 #define CHROME_FRAME_NPAPI_URL_REQUEST_H_ | 6 #define CHROME_FRAME_NPAPI_URL_REQUEST_H_ |
7 | 7 |
| 8 #include <map> |
| 9 |
8 #include "base/platform_thread.h" | 10 #include "base/platform_thread.h" |
9 #include "chrome_frame/plugin_url_request.h" | 11 #include "chrome_frame/plugin_url_request.h" |
10 #include "third_party/WebKit/WebCore/bridge/npapi.h" | 12 #include "third_party/WebKit/WebCore/bridge/npapi.h" |
11 | 13 |
12 class NPAPIUrlRequest : public PluginUrlRequest { | 14 class NPAPIUrlRequest; |
| 15 class NPAPIUrlRequestManager : public PluginUrlRequestManager, |
| 16 public PluginUrlRequestDelegate { |
13 public: | 17 public: |
14 explicit NPAPIUrlRequest(NPP instance); | 18 NPAPIUrlRequestManager(); |
15 ~NPAPIUrlRequest(); | 19 ~NPAPIUrlRequestManager(); |
16 | 20 |
17 virtual bool Start(); | 21 void set_NPPInstance(NPP instance) { |
18 virtual void Stop(); | 22 instance_ = instance; |
19 virtual bool Read(int bytes_to_read); | 23 } |
20 | 24 |
21 // Called from NPAPI | 25 // Notifications from the browser. We find the appropriate NPAPIUrlRequest |
22 bool OnStreamCreated(const char* mime_type, NPStream* stream); | 26 // and forward the call. |
23 void OnStreamDestroyed(NPReason reason); | 27 bool NewStream(NPMIMEType type, NPStream* stream, |
24 int OnWriteReady(); | 28 NPBool seekable, uint16* stream_type); |
25 int OnWrite(void* buffer, int len); | 29 int32 WriteReady(NPStream* stream); |
26 | 30 int32 Write(NPStream* stream, int32 offset, int32 len, void* buffer); |
27 // Thread unsafe implementation of ref counting, since | 31 NPError DestroyStream(NPStream* stream, NPReason reason); |
28 // this will be called on the plugin UI thread only. | 32 void UrlNotify(const char* url, NPReason reason, void* notify_data); |
29 virtual unsigned long API_CALL AddRef(); | |
30 virtual unsigned long API_CALL Release(); | |
31 | 33 |
32 private: | 34 private: |
33 unsigned long ref_count_; | 35 // PluginUrlRequestManager implementation. Called from AutomationClient. |
| 36 virtual bool IsThreadSafe(); |
| 37 virtual void StartRequest(int request_id, |
| 38 const IPC::AutomationURLRequest& request_info); |
| 39 virtual void ReadRequest(int request_id, int bytes_to_read); |
| 40 virtual void EndRequest(int request_id); |
| 41 virtual void StopAll(); |
| 42 |
| 43 // Outstanding requests map. |
| 44 typedef std::map<int, scoped_refptr<NPAPIUrlRequest> > RequestMap; |
| 45 RequestMap request_map_; |
| 46 |
| 47 // PluginUrlRequestDelegate implementation. Forwards back to delegate. |
| 48 virtual void OnResponseStarted(int request_id, const char* mime_type, |
| 49 const char* headers, int size, |
| 50 base::Time last_modified, const std::string& peristent_cookies, |
| 51 const std::string& redirect_url, int redirect_status); |
| 52 virtual void OnReadComplete(int request_id, const void* buffer, int len); |
| 53 virtual void OnResponseEnd(int request_id, const URLRequestStatus& status); |
| 54 |
| 55 static inline NPAPIUrlRequest* RequestFromNotifyData(void* notify_data) { |
| 56 return reinterpret_cast<NPAPIUrlRequest*>(notify_data); |
| 57 } |
| 58 |
34 NPP instance_; | 59 NPP instance_; |
35 NPStream* stream_; | |
36 size_t pending_read_size_; | |
37 URLRequestStatus status_; | |
38 | |
39 PlatformThreadId thread_; | |
40 static int instance_count_; | |
41 DISALLOW_COPY_AND_ASSIGN(NPAPIUrlRequest); | |
42 }; | 60 }; |
43 | 61 |
44 #endif // CHROME_FRAME_NPAPI_URL_REQUEST_H_ | 62 #endif // CHROME_FRAME_NPAPI_URL_REQUEST_H_ |
45 | 63 |
OLD | NEW |