OLD | NEW |
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 <utility> |
| 8 |
7 #include "base/macros.h" | 9 #include "base/macros.h" |
8 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
10 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
11 #include "extensions/common/constants.h" | 13 #include "extensions/common/constants.h" |
12 #include "extensions/common/extension_messages.h" | 14 #include "extensions/common/extension_messages.h" |
13 #include "extensions/common/message_bundle.h" | 15 #include "extensions/common/message_bundle.h" |
14 #include "ipc/ipc_sender.h" | 16 #include "ipc/ipc_sender.h" |
15 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
16 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 response_info_, nullptr, net::ERR_ABORTED, false, stale_copy_in_cache, | 101 response_info_, nullptr, net::ERR_ABORTED, false, stale_copy_in_cache, |
100 security_info, completion_time, total_transfer_size); | 102 security_info, completion_time, total_transfer_size); |
101 return; | 103 return; |
102 } | 104 } |
103 | 105 |
104 ReplaceMessages(); | 106 ReplaceMessages(); |
105 | 107 |
106 scoped_ptr<StringData> data_to_pass(data_.empty() ? nullptr | 108 scoped_ptr<StringData> data_to_pass(data_.empty() ? nullptr |
107 : new StringData(data_)); | 109 : new StringData(data_)); |
108 original_peer_->OnReceivedCompletedResponse( | 110 original_peer_->OnReceivedCompletedResponse( |
109 response_info_, data_to_pass.Pass(), error_code, was_ignored_by_handler, | 111 response_info_, std::move(data_to_pass), error_code, |
110 stale_copy_in_cache, security_info, completion_time, total_transfer_size); | 112 was_ignored_by_handler, stale_copy_in_cache, security_info, |
| 113 completion_time, total_transfer_size); |
111 } | 114 } |
112 | 115 |
113 void ExtensionLocalizationPeer::OnReceivedCompletedResponse( | 116 void ExtensionLocalizationPeer::OnReceivedCompletedResponse( |
114 const content::ResourceResponseInfo& info, | 117 const content::ResourceResponseInfo& info, |
115 scoped_ptr<ReceivedData> data, | 118 scoped_ptr<ReceivedData> data, |
116 int error_code, | 119 int error_code, |
117 bool was_ignored_by_handler, | 120 bool was_ignored_by_handler, |
118 bool stale_copy_in_cache, | 121 bool stale_copy_in_cache, |
119 const std::string& security_info, | 122 const std::string& security_info, |
120 const base::TimeTicks& completion_time, | 123 const base::TimeTicks& completion_time, |
121 int64_t total_transfer_size) { | 124 int64_t total_transfer_size) { |
122 // Make sure we delete ourselves at the end of this call. | 125 // Make sure we delete ourselves at the end of this call. |
123 scoped_ptr<ExtensionLocalizationPeer> this_deleter(this); | 126 scoped_ptr<ExtensionLocalizationPeer> this_deleter(this); |
124 original_peer_->OnReceivedCompletedResponse( | 127 original_peer_->OnReceivedCompletedResponse( |
125 info, data.Pass(), error_code, was_ignored_by_handler, | 128 info, std::move(data), error_code, was_ignored_by_handler, |
126 stale_copy_in_cache, security_info, completion_time, total_transfer_size); | 129 stale_copy_in_cache, security_info, completion_time, total_transfer_size); |
127 } | 130 } |
128 | 131 |
129 void ExtensionLocalizationPeer::ReplaceMessages() { | 132 void ExtensionLocalizationPeer::ReplaceMessages() { |
130 if (!message_sender_ || data_.empty()) | 133 if (!message_sender_ || data_.empty()) |
131 return; | 134 return; |
132 | 135 |
133 if (!request_url_.is_valid()) | 136 if (!request_url_.is_valid()) |
134 return; | 137 return; |
135 | 138 |
(...skipping 13 matching lines...) Expand all Loading... |
149 | 152 |
150 l10n_messages = extensions::GetL10nMessagesMap(extension_id); | 153 l10n_messages = extensions::GetL10nMessagesMap(extension_id); |
151 } | 154 } |
152 | 155 |
153 std::string error; | 156 std::string error; |
154 if (extensions::MessageBundle::ReplaceMessagesWithExternalDictionary( | 157 if (extensions::MessageBundle::ReplaceMessagesWithExternalDictionary( |
155 *l10n_messages, &data_, &error)) { | 158 *l10n_messages, &data_, &error)) { |
156 data_.resize(data_.size()); | 159 data_.resize(data_.size()); |
157 } | 160 } |
158 } | 161 } |
OLD | NEW |