| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_BROWSER_LOADER_MIME_SNIFFING_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_MIME_SNIFFING_RESOURCE_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_MIME_SNIFFING_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_LOADER_MIME_SNIFFING_RESOURCE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 STATE_REPLAYING_RESPONSE_RECEIVED, | 73 STATE_REPLAYING_RESPONSE_RECEIVED, |
| 74 | 74 |
| 75 // In this state, the MimeSniffingResourceHandler is just a blind | 75 // In this state, the MimeSniffingResourceHandler is just a blind |
| 76 // pass-through | 76 // pass-through |
| 77 // ResourceHandler. | 77 // ResourceHandler. |
| 78 STATE_STREAMING, | 78 STATE_STREAMING, |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 // ResourceHandler implementation: | 81 // ResourceHandler implementation: |
| 82 void SetController(ResourceController* controller) override; | 82 void SetController(ResourceController* controller) override; |
| 83 bool OnWillStart(const GURL&, bool* defer) override; | 83 void OnWillStart(const GURL&, bool* defer_or_cancel) override; |
| 84 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; | 84 void OnResponseStarted(ResourceResponse* response, |
| 85 bool* defer_or_cancel) override; |
| 85 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 86 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 86 int* buf_size, | 87 int* buf_size, |
| 87 int min_size) override; | 88 int min_size) override; |
| 88 bool OnReadCompleted(int bytes_read, bool* defer) override; | 89 void OnReadCompleted(int bytes_read, bool* defer_or_cancel) override; |
| 89 void OnResponseCompleted(const net::URLRequestStatus& status, | 90 void OnResponseCompleted(const net::URLRequestStatus& status, |
| 90 bool* defer) override; | 91 bool* defer) override; |
| 91 | 92 |
| 92 // ResourceController implementation: | 93 // ResourceController implementation: |
| 93 void Resume() override; | 94 void Resume() override; |
| 94 void Cancel() override; | 95 void Cancel() override; |
| 95 void CancelAndIgnore() override; | 96 void CancelAndIgnore() override; |
| 96 void CancelWithError(int error_code) override; | 97 void CancelWithError(int error_code) override; |
| 97 | 98 |
| 98 // -------------------------------------------------------------------------- | 99 // -------------------------------------------------------------------------- |
| 99 // The following methods replay the buffered data to the downstream | 100 // The following methods replay the buffered data to the downstream |
| 100 // ResourceHandlers. They return false if the request should be cancelled, | 101 // ResourceHandlers. Each of them will set |defer_or_cancel| to true if the |
| 101 // true otherwise. Each of them will set |defer| to true if the request will | 102 // request should not synchronously continue (It was canceled, or will be |
| 102 // proceed to the next stage asynchronously. | 103 // continued/canceled asynchronously. |
| 103 | 104 |
| 104 // Used to advance through the states of the state machine. | 105 // Used to advance through the states of the state machine. |
| 105 void AdvanceState(); | 106 void AdvanceState(); |
| 106 bool ProcessState(bool* defer); | 107 void ProcessState(bool* defer_or_cancel); |
| 107 | 108 |
| 108 // Intercepts the request as a stream/download if needed. | 109 // Intercepts the request as a stream/download if needed. |
| 109 bool MaybeIntercept(bool* defer); | 110 void MaybeIntercept(bool* defer_or_cancel); |
| 110 | 111 |
| 111 // Replays OnResponseStarted on the downstream handlers. | 112 // Replays OnResponseStarted on the downstream handlers. |
| 112 bool ReplayResponseReceived(bool* defer); | 113 void ReplayResponseReceived(bool* defer_or_cancel); |
| 113 | 114 |
| 114 // Replays OnReadCompleted on the downstreams handlers. | 115 // Replays OnReadCompleted on the downstreams handlers. |
| 115 bool ReplayReadCompleted(bool* defer); | 116 void ReplayReadCompleted(bool* defer_or_cancel); |
| 116 | 117 |
| 117 // -------------------------------------------------------------------------- | 118 // -------------------------------------------------------------------------- |
| 118 | 119 |
| 119 // Whether the response body should be sniffed in order to determine the MIME | 120 // Whether the response body should be sniffed in order to determine the MIME |
| 120 // type of the response. | 121 // type of the response. |
| 121 bool ShouldSniffContent(); | 122 bool ShouldSniffContent(); |
| 122 | 123 |
| 123 // Checks whether this request should be intercepted as a stream or a | 124 // Checks whether this request should be intercepted as a stream or a |
| 124 // download. If this is the case, sets up the new ResourceHandler that will be | 125 // download. If this is the case, sets up the new ResourceHandler that will be |
| 125 // used for interception. Returns false if teh request should be cancelled, | 126 // used for interception. |defer_or_cancel| is set to true if the request will |
| 126 // true otherwise. |defer| is set to true if the interception check needs to | 127 // be resumed asynchronously, or was canceled. |
| 127 // finish asynchronously. | 128 void MaybeStartInterception(bool* defer_or_cancel); |
| 128 bool MaybeStartInterception(bool* defer); | |
| 129 | 129 |
| 130 // Determines whether a plugin will handle the current request. Returns false | 130 // Determines whether a plugin will handle the current request. |
| 131 // if there is an error and the request should be cancelled and true | 131 // |defer_or_cancel| is set to true if plugin data is stale and needs to be |
| 132 // otherwise. |defer| is set to true if plugin data is stale and needs to be | 132 // refreshed before the request can be handled, or if the request was |
| 133 // refreshed before the request can be handled (in this case the function | 133 // canceled. If the request is directed to a plugin, |handled_by_plugin| is |
| 134 // still returns true). If the request is directed to a plugin, | 134 // set to true. |
| 135 // |handled_by_plugin| is set to true. | 135 void CheckForPluginHandler(bool* defer_or_cancel, bool* handled_by_plugin); |
| 136 bool CheckForPluginHandler(bool* defer, bool* handled_by_plugin); | |
| 137 | 136 |
| 138 // Whether this request is allowed to be intercepted as a download or a | 137 // Whether this request is allowed to be intercepted as a download or a |
| 139 // stream. | 138 // stream. |
| 140 bool CanBeIntercepted(); | 139 bool CanBeIntercepted(); |
| 141 | 140 |
| 142 // Whether the response we received is not provisional. | 141 // Whether the response we received is not provisional. |
| 143 bool CheckResponseIsNotProvisional(); | 142 bool CheckResponseIsNotProvisional(); |
| 144 | 143 |
| 145 bool MustDownload(); | 144 bool MustDownload(); |
| 146 | 145 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 170 RequestContextType request_context_type_; | 169 RequestContextType request_context_type_; |
| 171 | 170 |
| 172 base::WeakPtrFactory<MimeSniffingResourceHandler> weak_ptr_factory_; | 171 base::WeakPtrFactory<MimeSniffingResourceHandler> weak_ptr_factory_; |
| 173 | 172 |
| 174 DISALLOW_COPY_AND_ASSIGN(MimeSniffingResourceHandler); | 173 DISALLOW_COPY_AND_ASSIGN(MimeSniffingResourceHandler); |
| 175 }; | 174 }; |
| 176 | 175 |
| 177 } // namespace content | 176 } // namespace content |
| 178 | 177 |
| 179 #endif // CONTENT_BROWSER_LOADER_MIME_SNIFFING_RESOURCE_HANDLER_H_ | 178 #endif // CONTENT_BROWSER_LOADER_MIME_SNIFFING_RESOURCE_HANDLER_H_ |
| OLD | NEW |