[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_FRAME_NPAPI_URL_REQUEST_H_ |
| 6 | #define CHROME_FRAME_NPAPI_URL_REQUEST_H_ |
| 7 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 8 | #include <map> |
| 9 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 10 | #include "base/platform_thread.h" |
| 11 | #include "chrome_frame/plugin_url_request.h" |
| 12 | #include "third_party/WebKit/WebCore/bridge/npapi.h" |
| 13 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 14 | class NPAPIUrlRequest; |
| 15 | class NPAPIUrlRequestManager : public PluginUrlRequestManager, |
| 16 | public PluginUrlRequestDelegate { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 17 | public: |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 18 | NPAPIUrlRequestManager(); |
| 19 | ~NPAPIUrlRequestManager(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 20 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 21 | void set_NPPInstance(NPP instance) { |
| 22 | instance_ = instance; |
| 23 | } |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 24 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 25 | // Notifications from the browser. We find the appropriate NPAPIUrlRequest |
| 26 | // and forward the call. |
[email protected] | 0d9d4513 | 2010-02-02 00:04:28 | [diff] [blame] | 27 | NPError NewStream(NPMIMEType type, NPStream* stream, |
| 28 | NPBool seekable, uint16* stream_type); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 29 | int32 WriteReady(NPStream* stream); |
| 30 | int32 Write(NPStream* stream, int32 offset, int32 len, void* buffer); |
| 31 | NPError DestroyStream(NPStream* stream, NPReason reason); |
| 32 | void UrlNotify(const char* url, NPReason reason, void* notify_data); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 33 | |
| 34 | private: |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 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(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 42 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 43 | // Outstanding requests map. |
| 44 | typedef std::map<int, scoped_refptr<NPAPIUrlRequest> > RequestMap; |
| 45 | RequestMap request_map_; |
| 46 | |
[email protected] | 0d9d4513 | 2010-02-02 00:04:28 | [diff] [blame] | 47 | scoped_refptr<NPAPIUrlRequest> LookupRequest(int request_id); |
| 48 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 49 | // PluginUrlRequestDelegate implementation. Forwards back to delegate. |
| 50 | virtual void OnResponseStarted(int request_id, const char* mime_type, |
[email protected] | 70daf0b | 2010-03-02 19:13:00 | [diff] [blame^] | 51 | const char* headers, int size, base::Time last_modified, |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 52 | const std::string& redirect_url, int redirect_status); |
| 53 | virtual void OnReadComplete(int request_id, const void* buffer, int len); |
| 54 | virtual void OnResponseEnd(int request_id, const URLRequestStatus& status); |
| 55 | |
| 56 | static inline NPAPIUrlRequest* RequestFromNotifyData(void* notify_data) { |
| 57 | return reinterpret_cast<NPAPIUrlRequest*>(notify_data); |
| 58 | } |
| 59 | |
| 60 | NPP instance_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | #endif // CHROME_FRAME_NPAPI_URL_REQUEST_H_ |
| 64 | |