Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 WEBKIT_PLUGINS_PPAPI_PPB_URL_LOADER_IMPL_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_URL_LOADER_IMPL_H_ |
| 6 #define WEBKIT_PLUGINS_PPAPI_PPB_URL_LOADER_IMPL_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_PPB_URL_LOADER_IMPL_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/ref_counted.h" | |
| 10 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 11 #include "ppapi/c/pp_completion_callback.h" | 12 #include "ppapi/c/pp_completion_callback.h" |
| 12 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" | 13 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" |
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoaderClient.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoaderClient.h" |
| 15 #include "webkit/plugins/ppapi/callbacks.h" | |
| 14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 16 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 15 #include "webkit/plugins/ppapi/resource.h" | 17 #include "webkit/plugins/ppapi/resource.h" |
| 16 | 18 |
| 17 struct PPB_URLLoader; | 19 struct PPB_URLLoader; |
| 18 struct PPB_URLLoaderTrusted; | 20 struct PPB_URLLoaderTrusted; |
| 19 | 21 |
| 20 namespace WebKit { | 22 namespace WebKit { |
| 21 class WebFrame; | 23 class WebFrame; |
| 22 class WebURL; | 24 class WebURL; |
| 23 } | 25 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 double finish_time); | 84 double finish_time); |
| 83 virtual void didFail(WebKit::WebURLLoader* loader, | 85 virtual void didFail(WebKit::WebURLLoader* loader, |
| 84 const WebKit::WebURLError& error); | 86 const WebKit::WebURLError& error); |
| 85 | 87 |
| 86 // PluginInstance::Observer implementation. | 88 // PluginInstance::Observer implementation. |
| 87 virtual void InstanceDestroyed(PluginInstance* instance); | 89 virtual void InstanceDestroyed(PluginInstance* instance); |
| 88 | 90 |
| 89 PPB_URLResponseInfo_Impl* response_info() const { return response_info_; } | 91 PPB_URLResponseInfo_Impl* response_info() const { return response_info_; } |
| 90 | 92 |
| 91 private: | 93 private: |
| 94 // Check that |callback| is valid (only non-blocking operation is supported) | |
| 95 // and that no callback is already pending. Returns |PP_OK| if okay, else | |
| 96 // |PP_ERROR_...| to be returned to the plugin. | |
| 97 int32_t ValidateCallback(PP_CompletionCallback callback); | |
| 98 | |
| 99 // Sets up |callback| as the pending callback. This should only be called once | |
| 100 // it is certain that |PP_ERROR_WOULDBLOCK| will be returned. | |
| 101 void RegisterCallback(PP_CompletionCallback callback); | |
| 102 | |
| 92 void RunCallback(int32_t result); | 103 void RunCallback(int32_t result); |
| 104 | |
| 93 size_t FillUserBuffer(); | 105 size_t FillUserBuffer(); |
| 94 | 106 |
| 95 // Converts a WebURLResponse to a URLResponseInfo and saves it. | 107 // Converts a WebURLResponse to a URLResponseInfo and saves it. |
| 96 void SaveResponse(const WebKit::WebURLResponse& response); | 108 void SaveResponse(const WebKit::WebURLResponse& response); |
| 97 | 109 |
| 98 int32_t CanRequest(const WebKit::WebFrame* frame, const WebKit::WebURL& url); | 110 int32_t CanRequest(const WebKit::WebFrame* frame, const WebKit::WebURL& url); |
| 99 | 111 |
| 100 // Calls the status_callback_ (if any) with the current upload and download | 112 // Calls the status_callback_ (if any) with the current upload and download |
| 101 // progress. Call this function if you update any of these values to | 113 // progress. Call this function if you update any of these values to |
| 102 // synchronize an out-of-process plugin's state. | 114 // synchronize an out-of-process plugin's state. |
| 103 void UpdateStatus(); | 115 void UpdateStatus(); |
| 104 | 116 |
| 105 // Returns true if the plugin has requested we record download or upload | 117 // Returns true if the plugin has requested we record download or upload |
| 106 // progress. When false, we don't need to update the counters. We go out of | 118 // progress. When false, we don't need to update the counters. We go out of |
| 107 // our way not to allow access to this information unless it's requested, | 119 // our way not to allow access to this information unless it's requested, |
| 108 // even when it would be easier just to return it and not check, so that | 120 // even when it would be easier just to return it and not check, so that |
| 109 // plugins don't depend on access without setting the flag. | 121 // plugins don't depend on access without setting the flag. |
| 110 bool RecordDownloadProgress() const; | 122 bool RecordDownloadProgress() const; |
| 111 bool RecordUploadProgress() const; | 123 bool RecordUploadProgress() const; |
| 112 | 124 |
| 113 // This will be NULL if the instance has been deleted but this PPB_URLLoader_I mpl was | 125 // This will be NULL if the instance has been deleted but this |
| 114 // somehow leaked. In general, you should not need to check this for NULL. | 126 // PPB_URLLoader_Impl was somehow leaked. In general, you should not need to |
| 115 // However, if you see a NULL pointer crash, that means somebody is holding | 127 // check this for NULL. However, if you see a NULL pointer crash, that means |
| 116 // a reference to this object longer than the PluginInstance's lifetime. | 128 // somebody is holding a reference to this object longer than the |
| 129 // PluginInstance's lifetime. | |
| 117 PluginInstance* instance_; | 130 PluginInstance* instance_; |
| 118 | 131 |
| 119 // If true, then the plugin instance is a full-frame plugin and we're just | 132 // If true, then the plugin instance is a full-frame plugin and we're just |
| 120 // wrapping the main document's loader (i.e. loader_ is null). | 133 // wrapping the main document's loader (i.e. loader_ is null). |
| 121 bool main_document_loader_; | 134 bool main_document_loader_; |
| 122 scoped_ptr<WebKit::WebURLLoader> loader_; | 135 scoped_ptr<WebKit::WebURLLoader> loader_; |
| 123 scoped_refptr<PPB_URLRequestInfo_Impl> request_info_; | 136 scoped_refptr<PPB_URLRequestInfo_Impl> request_info_; |
| 124 scoped_refptr<PPB_URLResponseInfo_Impl> response_info_; | 137 scoped_refptr<PPB_URLResponseInfo_Impl> response_info_; |
| 125 PP_CompletionCallback pending_callback_; | 138 scoped_refptr<TrackedCompletionCallback> pending_callback_; |
| 126 std::deque<char> buffer_; | 139 std::deque<char> buffer_; |
| 127 int64_t bytes_sent_; | 140 int64_t bytes_sent_; |
| 128 int64_t total_bytes_to_be_sent_; | 141 int64_t total_bytes_to_be_sent_; |
| 129 int64_t bytes_received_; | 142 int64_t bytes_received_; |
| 130 int64_t total_bytes_to_be_received_; | 143 int64_t total_bytes_to_be_received_; |
| 131 char* user_buffer_; | 144 char* user_buffer_; |
| 132 size_t user_buffer_size_; | 145 size_t user_buffer_size_; |
| 133 int32_t done_status_; | 146 int32_t done_status_; |
| 134 | 147 |
| 135 bool has_universal_access_; | 148 bool has_universal_access_; |
| 136 | 149 |
| 150 // TODO(viettrungluu): does the status callback need to be tracked? (and have | |
|
brettw
2011/01/13 03:08:30
Extra tracking here shouldn't be necessary. This j
| |
| 151 // semantics with respect to resource deletion verified?) | |
| 137 PP_URLLoaderTrusted_StatusCallback status_callback_; | 152 PP_URLLoaderTrusted_StatusCallback status_callback_; |
| 138 | 153 |
| 139 DISALLOW_COPY_AND_ASSIGN(PPB_URLLoader_Impl); | 154 DISALLOW_COPY_AND_ASSIGN(PPB_URLLoader_Impl); |
| 140 }; | 155 }; |
| 141 | 156 |
| 142 } // namespace ppapi | 157 } // namespace ppapi |
| 143 } // namespace webkit | 158 } // namespace webkit |
| 144 | 159 |
| 145 #endif // WEBKIT_PLUGINS_PPAPI_PPB_URL_LOADER_IMPL_H_ | 160 #endif // WEBKIT_PLUGINS_PPAPI_PPB_URL_LOADER_IMPL_H_ |
| OLD | NEW |