| 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 #ifndef CHROME_RENDERER_SECURITY_FILTER_PEER_H_ | 5 #ifndef CHROME_RENDERER_SECURITY_FILTER_PEER_H_ |
| 6 #define CHROME_RENDERER_SECURITY_FILTER_PEER_H_ | 6 #define CHROME_RENDERER_SECURITY_FILTER_PEER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 protected: | 44 protected: |
| 45 explicit SecurityFilterPeer(std::unique_ptr<content::RequestPeer> peer); | 45 explicit SecurityFilterPeer(std::unique_ptr<content::RequestPeer> peer); |
| 46 | 46 |
| 47 std::unique_ptr<content::RequestPeer> original_peer_; | 47 std::unique_ptr<content::RequestPeer> original_peer_; |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 DISALLOW_COPY_AND_ASSIGN(SecurityFilterPeer); | 50 DISALLOW_COPY_AND_ASSIGN(SecurityFilterPeer); |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 // The BufferedPeer reads all the data of the request into an internal buffer. | |
| 54 // Subclasses should implement DataReady() to process the data as necessary. | |
| 55 class BufferedPeer : public SecurityFilterPeer { | |
| 56 public: | |
| 57 BufferedPeer(std::unique_ptr<content::RequestPeer> peer, | |
| 58 const std::string& mime_type); | |
| 59 ~BufferedPeer() override; | |
| 60 | |
| 61 // content::RequestPeer Implementation. | |
| 62 void OnReceivedResponse(const content::ResourceResponseInfo& info) override; | |
| 63 void OnReceivedData(std::unique_ptr<ReceivedData> data) override; | |
| 64 void OnCompletedRequest(int error_code, | |
| 65 bool was_ignored_by_handler, | |
| 66 bool stale_copy_in_cache, | |
| 67 const base::TimeTicks& completion_time, | |
| 68 int64_t total_transfer_size, | |
| 69 int64_t encoded_body_size) override; | |
| 70 | |
| 71 protected: | |
| 72 // Invoked when the entire request has been processed before the data is sent | |
| 73 // to the original peer, giving an opportunity to subclasses to process the | |
| 74 // data in data_. If this method returns true, the data is fed to the | |
| 75 // original peer, if it returns false, an error is sent instead. | |
| 76 virtual bool DataReady() = 0; | |
| 77 | |
| 78 content::ResourceResponseInfo response_info_; | |
| 79 std::string data_; | |
| 80 | |
| 81 private: | |
| 82 std::string mime_type_; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(BufferedPeer); | |
| 85 }; | |
| 86 | |
| 87 // The ReplaceContentPeer cancels the request and serves the provided data as | 53 // The ReplaceContentPeer cancels the request and serves the provided data as |
| 88 // content instead. | 54 // content instead. |
| 89 // TODO(jcampan): For now the resource is still being fetched, but ignored, as | 55 // TODO(jcampan): For now the resource is still being fetched, but ignored, as |
| 90 // once we have provided the replacement content, the associated pending request | 56 // once we have provided the replacement content, the associated pending request |
| 91 // in ResourceDispatcher is removed and further OnReceived* notifications are | 57 // in ResourceDispatcher is removed and further OnReceived* notifications are |
| 92 // ignored. | 58 // ignored. |
| 93 class ReplaceContentPeer : public SecurityFilterPeer { | 59 class ReplaceContentPeer : public SecurityFilterPeer { |
| 94 public: | 60 public: |
| 95 ReplaceContentPeer(std::unique_ptr<content::RequestPeer> peer, | 61 ReplaceContentPeer(std::unique_ptr<content::RequestPeer> peer, |
| 96 const std::string& mime_type, | 62 const std::string& mime_type, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 109 | 75 |
| 110 private: | 76 private: |
| 111 content::ResourceResponseInfo response_info_; | 77 content::ResourceResponseInfo response_info_; |
| 112 std::string mime_type_; | 78 std::string mime_type_; |
| 113 std::string data_; | 79 std::string data_; |
| 114 | 80 |
| 115 DISALLOW_COPY_AND_ASSIGN(ReplaceContentPeer); | 81 DISALLOW_COPY_AND_ASSIGN(ReplaceContentPeer); |
| 116 }; | 82 }; |
| 117 | 83 |
| 118 #endif // CHROME_RENDERER_SECURITY_FILTER_PEER_H_ | 84 #endif // CHROME_RENDERER_SECURITY_FILTER_PEER_H_ |
| OLD | NEW |