| OLD | NEW |
| 1 // Copyright (c) 2011 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 // A delegate class of WebURLLoaderImpl that handles multipart/x-mixed-replace | 5 // A delegate class of WebURLLoaderImpl that handles multipart/x-mixed-replace |
| 6 // data. We special case multipart/x-mixed-replace because WebCore expects a | 6 // data. We special case multipart/x-mixed-replace because WebCore expects a |
| 7 // separate didReceiveResponse for each new message part. | 7 // separate didReceiveResponse for each new message part. |
| 8 // | 8 // |
| 9 // Most of the logic and edge case handling are based on the Mozilla's | 9 // Most of the logic and edge case handling are based on the Mozilla's |
| 10 // implementation in netwerk/streamconv/converters/nsMultiMixedConv.cpp. | 10 // implementation in netwerk/streamconv/converters/nsMultiMixedConv.cpp. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 * | 46 * |
| 47 * ***** END LICENSE BLOCK ***** */ | 47 * ***** END LICENSE BLOCK ***** */ |
| 48 | 48 |
| 49 #ifndef WEBKIT_GLUE_MULTIPART_RESPONSE_DELEGATE_H_ | 49 #ifndef WEBKIT_GLUE_MULTIPART_RESPONSE_DELEGATE_H_ |
| 50 #define WEBKIT_GLUE_MULTIPART_RESPONSE_DELEGATE_H_ | 50 #define WEBKIT_GLUE_MULTIPART_RESPONSE_DELEGATE_H_ |
| 51 | 51 |
| 52 #include <string> | 52 #include <string> |
| 53 | 53 |
| 54 #include "base/basictypes.h" | 54 #include "base/basictypes.h" |
| 55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
| 56 #include "webkit/glue/webkit_glue_export.h" |
| 56 | 57 |
| 57 namespace WebKit { | 58 namespace WebKit { |
| 58 class WebURLLoader; | 59 class WebURLLoader; |
| 59 class WebURLLoaderClient; | 60 class WebURLLoaderClient; |
| 60 } | 61 } |
| 61 | 62 |
| 62 namespace webkit_glue { | 63 namespace webkit_glue { |
| 63 | 64 |
| 64 // Used by unit tests to access private members. | 65 // Used by unit tests to access private members. |
| 65 class MultipartResponseDelegateTester; | 66 class MultipartResponseDelegateTester; |
| 66 | 67 |
| 67 class MultipartResponseDelegate { | 68 class WEBKIT_GLUE_EXPORT MultipartResponseDelegate { |
| 68 public: | 69 public: |
| 69 MultipartResponseDelegate(WebKit::WebURLLoaderClient* client, | 70 MultipartResponseDelegate(WebKit::WebURLLoaderClient* client, |
| 70 WebKit::WebURLLoader* loader, | 71 WebKit::WebURLLoader* loader, |
| 71 const WebKit::WebURLResponse& response, | 72 const WebKit::WebURLResponse& response, |
| 72 const std::string& boundary); | 73 const std::string& boundary); |
| 73 | 74 |
| 74 // Passed through from ResourceHandleInternal | 75 // Passed through from ResourceHandleInternal |
| 75 void OnReceivedData(const char* data, int data_len, int encoded_data_length); | 76 void OnReceivedData(const char* data, int data_len, int encoded_data_length); |
| 76 void OnCompletedRequest(); | 77 void OnCompletedRequest(); |
| 77 | 78 |
| 78 // The request has been canceled, so stop making calls to the client. | 79 // The request has been canceled, so stop making calls to the client. |
| 79 void Cancel() { | 80 void Cancel() { |
| 80 client_ = NULL; | 81 client_ = NULL; |
| 81 loader_ = NULL; | 82 loader_ = NULL; |
| 82 } | 83 } |
| 83 | 84 |
| 84 // Returns the multi part boundary string from the Content-type header | 85 // Returns the multi part boundary string from the Content-type header |
| 85 // in the response. | 86 // in the response. |
| 86 // Returns true on success. | 87 // Returns true on success. |
| 87 static bool ReadMultipartBoundary(const WebKit::WebURLResponse& response, | 88 static bool ReadMultipartBoundary(const WebKit::WebURLResponse& response, |
| 88 std::string* multipart_boundary); | 89 std::string* multipart_boundary); |
| 89 | 90 |
| 90 // Returns the lower and higher content ranges from an individual multipart | 91 // Returns the lower and higher content ranges from an individual multipart |
| 91 // in a multipart response. | 92 // in a multipart response. |
| 92 // Returns true on success. | 93 // Returns true on success. |
| 93 static bool ReadContentRanges(const WebKit::WebURLResponse& response, | 94 static bool ReadContentRanges( |
| 94 int64* content_range_lower_bound, | 95 const WebKit::WebURLResponse& response, |
| 95 int64* content_range_upper_bound, | 96 int64* content_range_lower_bound, |
| 96 int64* content_range_instance_size); | 97 int64* content_range_upper_bound, |
| 98 int64* content_range_instance_size); |
| 97 | 99 |
| 98 private: | 100 private: |
| 99 friend class MultipartResponseDelegateTester; // For unittests. | 101 friend class MultipartResponseDelegateTester; // For unittests. |
| 100 | 102 |
| 101 // Pointers to the client and associated loader so we can make callbacks as | 103 // Pointers to the client and associated loader so we can make callbacks as |
| 102 // we parse pieces of data. | 104 // we parse pieces of data. |
| 103 WebKit::WebURLLoaderClient* client_; | 105 WebKit::WebURLLoaderClient* client_; |
| 104 WebKit::WebURLLoader* loader_; | 106 WebKit::WebURLLoader* loader_; |
| 105 | 107 |
| 106 // The original resource response for this request. We use this as a | 108 // The original resource response for this request. We use this as a |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 144 |
| 143 // true after we've sent our first response to the WebURLLoaderClient. | 145 // true after we've sent our first response to the WebURLLoaderClient. |
| 144 bool has_sent_first_response_; | 146 bool has_sent_first_response_; |
| 145 | 147 |
| 146 DISALLOW_COPY_AND_ASSIGN(MultipartResponseDelegate); | 148 DISALLOW_COPY_AND_ASSIGN(MultipartResponseDelegate); |
| 147 }; | 149 }; |
| 148 | 150 |
| 149 } // namespace webkit_glue | 151 } // namespace webkit_glue |
| 150 | 152 |
| 151 #endif | 153 #endif |
| OLD | NEW |