[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> |
[email protected] | 7ae8074 | 2010-03-25 22:02:27 | [diff] [blame] | 9 | #include <string> |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 10 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 11 | #include "base/platform_thread.h" |
| 12 | #include "chrome_frame/plugin_url_request.h" |
[email protected] | c96c3c9 | 2010-05-01 02:08:38 | [diff] [blame] | 13 | #include "third_party/npapi/bindings/npapi.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 14 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 15 | class NPAPIUrlRequest; |
| 16 | class NPAPIUrlRequestManager : public PluginUrlRequestManager, |
| 17 | public PluginUrlRequestDelegate { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 18 | public: |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 19 | NPAPIUrlRequestManager(); |
| 20 | ~NPAPIUrlRequestManager(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 21 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 22 | void set_NPPInstance(NPP instance) { |
| 23 | instance_ = instance; |
| 24 | } |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 25 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 26 | // Notifications from the browser. We find the appropriate NPAPIUrlRequest |
| 27 | // and forward the call. |
[email protected] | 0d9d4513 | 2010-02-02 00:04:28 | [diff] [blame] | 28 | NPError NewStream(NPMIMEType type, NPStream* stream, |
| 29 | NPBool seekable, uint16* stream_type); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 30 | int32 WriteReady(NPStream* stream); |
| 31 | int32 Write(NPStream* stream, int32 offset, int32 len, void* buffer); |
| 32 | NPError DestroyStream(NPStream* stream, NPReason reason); |
| 33 | void UrlNotify(const char* url, NPReason reason, void* notify_data); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 34 | |
| 35 | private: |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 36 | // PluginUrlRequestManager implementation. Called from AutomationClient. |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 37 | virtual PluginUrlRequestManager::ThreadSafeFlags GetThreadSafeFlags(); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 38 | virtual void StartRequest(int request_id, |
[email protected] | 0ce4640 | 2010-04-08 16:53:57 | [diff] [blame] | 39 | const IPC::AutomationURLRequest& request_info); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 40 | virtual void ReadRequest(int request_id, int bytes_to_read); |
| 41 | virtual void EndRequest(int request_id); |
[email protected] | 7ae8074 | 2010-03-25 22:02:27 | [diff] [blame] | 42 | virtual void DownloadRequestInHost(int request_id) { |
| 43 | // Not yet implemented. |
| 44 | } |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 45 | virtual void StopAll(); |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 46 | virtual void SetCookiesForUrl(const GURL& url, const std::string& cookie); |
| 47 | virtual void GetCookiesForUrl(const GURL& url, int cookie_id); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 48 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 49 | // Outstanding requests map. |
| 50 | typedef std::map<int, scoped_refptr<NPAPIUrlRequest> > RequestMap; |
| 51 | RequestMap request_map_; |
| 52 | |
[email protected] | 0d9d4513 | 2010-02-02 00:04:28 | [diff] [blame] | 53 | scoped_refptr<NPAPIUrlRequest> LookupRequest(int request_id); |
| 54 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 55 | // PluginUrlRequestDelegate implementation. Forwards back to delegate. |
| 56 | virtual void OnResponseStarted(int request_id, const char* mime_type, |
[email protected] | 70daf0b | 2010-03-02 19:13:00 | [diff] [blame] | 57 | const char* headers, int size, base::Time last_modified, |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 58 | const std::string& redirect_url, int redirect_status); |
[email protected] | 0ce4640 | 2010-04-08 16:53:57 | [diff] [blame] | 59 | virtual void OnReadComplete(int request_id, const std::string& data); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 60 | virtual void OnResponseEnd(int request_id, const URLRequestStatus& status); |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 61 | virtual void OnCookiesRetrieved(bool success, const GURL& url, |
| 62 | const std::string& cookie_string, int cookie_id); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 63 | |
| 64 | static inline NPAPIUrlRequest* RequestFromNotifyData(void* notify_data) { |
| 65 | return reinterpret_cast<NPAPIUrlRequest*>(notify_data); |
| 66 | } |
| 67 | |
| 68 | NPP instance_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | #endif // CHROME_FRAME_NPAPI_URL_REQUEST_H_ |
| 72 | |