Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/renderer/extensions/extension_localization_peer.cc

Issue 1103813002: Make WebURLLoader capable of retaining received buffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "chrome/renderer/extensions/extension_localization_peer.h" 5 #include "chrome/renderer/extensions/extension_localization_peer.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "chrome/common/url_constants.h" 9 #include "chrome/common/url_constants.h"
10 #include "extensions/common/constants.h" 10 #include "extensions/common/constants.h"
11 #include "extensions/common/extension_messages.h" 11 #include "extensions/common/extension_messages.h"
12 #include "extensions/common/message_bundle.h" 12 #include "extensions/common/message_bundle.h"
13 #include "ipc/ipc_sender.h" 13 #include "ipc/ipc_sender.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/http/http_response_headers.h" 15 #include "net/http/http_response_headers.h"
16 16
17 namespace {
18
19 class StringData final : public content::RequestPeer::ReceivedData {
20 public:
21 explicit StringData(const std::string& data) : data_(data) {}
22 void Append(const char* data, int length) { data_.append(data, length); }
23
24 const char* payload() const override { return data_.data(); }
25 int length() const override { return data_.size(); }
26 int encoded_length() const override { return -1; }
27
28 private:
29 std::string data_;
30
31 DISALLOW_COPY_AND_ASSIGN(StringData);
32 };
33
34 } // namespace
35
17 ExtensionLocalizationPeer::ExtensionLocalizationPeer( 36 ExtensionLocalizationPeer::ExtensionLocalizationPeer(
18 content::RequestPeer* peer, 37 content::RequestPeer* peer,
19 IPC::Sender* message_sender, 38 IPC::Sender* message_sender,
20 const GURL& request_url) 39 const GURL& request_url)
21 : original_peer_(peer), 40 : original_peer_(peer),
22 message_sender_(message_sender), 41 message_sender_(message_sender),
23 request_url_(request_url) { 42 request_url_(request_url) {
24 } 43 }
25 44
26 ExtensionLocalizationPeer::~ExtensionLocalizationPeer() { 45 ExtensionLocalizationPeer::~ExtensionLocalizationPeer() {
(...skipping 23 matching lines...) Expand all
50 const content::ResourceResponseInfo& info) { 69 const content::ResourceResponseInfo& info) {
51 NOTREACHED(); 70 NOTREACHED();
52 return false; 71 return false;
53 } 72 }
54 73
55 void ExtensionLocalizationPeer::OnReceivedResponse( 74 void ExtensionLocalizationPeer::OnReceivedResponse(
56 const content::ResourceResponseInfo& info) { 75 const content::ResourceResponseInfo& info) {
57 response_info_ = info; 76 response_info_ = info;
58 } 77 }
59 78
60 void ExtensionLocalizationPeer::OnReceivedData(const char* data, 79 void ExtensionLocalizationPeer::OnReceivedData(scoped_ptr<ReceivedData> data) {
61 int data_length, 80 data_.append(data->payload(), data->length());
62 int encoded_data_length) {
63 data_.append(data, data_length);
64 } 81 }
65 82
66 void ExtensionLocalizationPeer::OnCompletedRequest( 83 void ExtensionLocalizationPeer::OnCompletedRequest(
67 int error_code, 84 int error_code,
68 bool was_ignored_by_handler, 85 bool was_ignored_by_handler,
69 bool stale_copy_in_cache, 86 bool stale_copy_in_cache,
70 const std::string& security_info, 87 const std::string& security_info,
71 const base::TimeTicks& completion_time, 88 const base::TimeTicks& completion_time,
72 int64 total_transfer_size) { 89 int64 total_transfer_size) {
73 // Make sure we delete ourselves at the end of this call. 90 // Make sure we delete ourselves at the end of this call.
74 scoped_ptr<ExtensionLocalizationPeer> this_deleter(this); 91 scoped_ptr<ExtensionLocalizationPeer> this_deleter(this);
75 92
76 // Give sub-classes a chance at altering the data. 93 // Give sub-classes a chance at altering the data.
77 if (error_code != net::OK) { 94 if (error_code != net::OK) {
78 // We failed to load the resource. 95 // We failed to load the resource.
79 original_peer_->OnReceivedResponse(response_info_); 96 original_peer_->OnReceivedResponse(response_info_);
80 original_peer_->OnCompletedRequest(net::ERR_ABORTED, false, 97 original_peer_->OnCompletedRequest(net::ERR_ABORTED, false,
81 stale_copy_in_cache, security_info, 98 stale_copy_in_cache, security_info,
82 completion_time, 99 completion_time,
83 total_transfer_size); 100 total_transfer_size);
84 return; 101 return;
85 } 102 }
86 103
87 ReplaceMessages(); 104 ReplaceMessages();
88 105
89 original_peer_->OnReceivedResponse(response_info_); 106 original_peer_->OnReceivedResponse(response_info_);
90 if (!data_.empty()) 107 if (!data_.empty())
91 original_peer_->OnReceivedData(data_.data(), 108 original_peer_->OnReceivedData(make_scoped_ptr(new StringData(data_)));
92 static_cast<int>(data_.size()),
93 -1);
94 original_peer_->OnCompletedRequest(error_code, was_ignored_by_handler, 109 original_peer_->OnCompletedRequest(error_code, was_ignored_by_handler,
95 stale_copy_in_cache, 110 stale_copy_in_cache,
96 security_info, completion_time, 111 security_info, completion_time,
97 total_transfer_size); 112 total_transfer_size);
98 } 113 }
99 114
100 void ExtensionLocalizationPeer::ReplaceMessages() { 115 void ExtensionLocalizationPeer::ReplaceMessages() {
101 if (!message_sender_ || data_.empty()) 116 if (!message_sender_ || data_.empty())
102 return; 117 return;
103 118
(...skipping 16 matching lines...) Expand all
120 135
121 l10n_messages = extensions::GetL10nMessagesMap(extension_id); 136 l10n_messages = extensions::GetL10nMessagesMap(extension_id);
122 } 137 }
123 138
124 std::string error; 139 std::string error;
125 if (extensions::MessageBundle::ReplaceMessagesWithExternalDictionary( 140 if (extensions::MessageBundle::ReplaceMessagesWithExternalDictionary(
126 *l10n_messages, &data_, &error)) { 141 *l10n_messages, &data_, &error)) {
127 data_.resize(data_.size()); 142 data_.resize(data_.size());
128 } 143 }
129 } 144 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698