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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 #ifndef WEBKIT_CHILD_MULTIPART_RESPONSE_DELEGATE_H_ | 49 #ifndef WEBKIT_CHILD_MULTIPART_RESPONSE_DELEGATE_H_ |
50 #define WEBKIT_CHILD_MULTIPART_RESPONSE_DELEGATE_H_ | 50 #define WEBKIT_CHILD_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/public/platform/WebURLResponse.h" | 55 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
56 #include "webkit/child/webkit_child_export.h" | 56 #include "webkit/child/webkit_child_export.h" |
57 | 57 |
58 namespace WebKit { | 58 namespace blink { |
59 class WebURLLoader; | 59 class WebURLLoader; |
60 class WebURLLoaderClient; | 60 class WebURLLoaderClient; |
61 } | 61 } |
62 | 62 |
63 namespace webkit_glue { | 63 namespace webkit_glue { |
64 | 64 |
65 // Used by unit tests to access private members. | 65 // Used by unit tests to access private members. |
66 class MultipartResponseDelegateTester; | 66 class MultipartResponseDelegateTester; |
67 | 67 |
68 class WEBKIT_CHILD_EXPORT MultipartResponseDelegate { | 68 class WEBKIT_CHILD_EXPORT MultipartResponseDelegate { |
69 public: | 69 public: |
70 MultipartResponseDelegate(WebKit::WebURLLoaderClient* client, | 70 MultipartResponseDelegate(blink::WebURLLoaderClient* client, |
71 WebKit::WebURLLoader* loader, | 71 blink::WebURLLoader* loader, |
72 const WebKit::WebURLResponse& response, | 72 const blink::WebURLResponse& response, |
73 const std::string& boundary); | 73 const std::string& boundary); |
74 | 74 |
75 // Passed through from ResourceHandleInternal | 75 // Passed through from ResourceHandleInternal |
76 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); |
77 void OnCompletedRequest(); | 77 void OnCompletedRequest(); |
78 | 78 |
79 // 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. |
80 void Cancel() { | 80 void Cancel() { |
81 client_ = NULL; | 81 client_ = NULL; |
82 loader_ = NULL; | 82 loader_ = NULL; |
83 } | 83 } |
84 | 84 |
85 // Returns the multi part boundary string from the Content-type header | 85 // Returns the multi part boundary string from the Content-type header |
86 // in the response. | 86 // in the response. |
87 // Returns true on success. | 87 // Returns true on success. |
88 static bool ReadMultipartBoundary(const WebKit::WebURLResponse& response, | 88 static bool ReadMultipartBoundary(const blink::WebURLResponse& response, |
89 std::string* multipart_boundary); | 89 std::string* multipart_boundary); |
90 | 90 |
91 // Returns the lower and higher content ranges from an individual multipart | 91 // Returns the lower and higher content ranges from an individual multipart |
92 // in a multipart response. | 92 // in a multipart response. |
93 // Returns true on success. | 93 // Returns true on success. |
94 static bool ReadContentRanges( | 94 static bool ReadContentRanges( |
95 const WebKit::WebURLResponse& response, | 95 const blink::WebURLResponse& response, |
96 int64* content_range_lower_bound, | 96 int64* content_range_lower_bound, |
97 int64* content_range_upper_bound, | 97 int64* content_range_upper_bound, |
98 int64* content_range_instance_size); | 98 int64* content_range_instance_size); |
99 | 99 |
100 private: | 100 private: |
101 friend class MultipartResponseDelegateTester; // For unittests. | 101 friend class MultipartResponseDelegateTester; // For unittests. |
102 | 102 |
103 // 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 |
104 // we parse pieces of data. | 104 // we parse pieces of data. |
105 WebKit::WebURLLoaderClient* client_; | 105 blink::WebURLLoaderClient* client_; |
106 WebKit::WebURLLoader* loader_; | 106 blink::WebURLLoader* loader_; |
107 | 107 |
108 // 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 |
109 // starting point for each parts response. | 109 // starting point for each parts response. |
110 WebKit::WebURLResponse original_response_; | 110 blink::WebURLResponse original_response_; |
111 | 111 |
112 // Checks to see if data[pos] character is a line break; handles crlf, lflf, | 112 // Checks to see if data[pos] character is a line break; handles crlf, lflf, |
113 // lf, or cr. Returns the number of characters to skip over (0, 1 or 2). | 113 // lf, or cr. Returns the number of characters to skip over (0, 1 or 2). |
114 int PushOverLine(const std::string& data, size_t pos); | 114 int PushOverLine(const std::string& data, size_t pos); |
115 | 115 |
116 // Tries to parse http headers from the start of data_. Returns true if it | 116 // Tries to parse http headers from the start of data_. Returns true if it |
117 // succeeds and sends a didReceiveResponse to m_client. Returns false if | 117 // succeeds and sends a didReceiveResponse to m_client. Returns false if |
118 // the header is incomplete (in which case we just wait for more data). | 118 // the header is incomplete (in which case we just wait for more data). |
119 bool ParseHeaders(); | 119 bool ParseHeaders(); |
120 | 120 |
(...skipping 23 matching lines...) Expand all Loading... |
144 | 144 |
145 // true after we've sent our first response to the WebURLLoaderClient. | 145 // true after we've sent our first response to the WebURLLoaderClient. |
146 bool has_sent_first_response_; | 146 bool has_sent_first_response_; |
147 | 147 |
148 DISALLOW_COPY_AND_ASSIGN(MultipartResponseDelegate); | 148 DISALLOW_COPY_AND_ASSIGN(MultipartResponseDelegate); |
149 }; | 149 }; |
150 | 150 |
151 } // namespace webkit_glue | 151 } // namespace webkit_glue |
152 | 152 |
153 #endif // WEBKIT_CHILD_MULTIPART_RESPONSE_DELEGATE_H_ | 153 #endif // WEBKIT_CHILD_MULTIPART_RESPONSE_DELEGATE_H_ |
OLD | NEW |