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 #include "chrome/common/extensions/extension_localization_peer.h" | 5 #include "chrome/common/extensions/extension_localization_peer.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/common/extensions/extension_messages.h" | 9 #include "chrome/common/extensions/extension_messages.h" |
10 #include "chrome/common/extensions/message_bundle.h" | 10 #include "chrome/common/extensions/message_bundle.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 response_info_ = info; | 59 response_info_ = info; |
60 } | 60 } |
61 | 61 |
62 void ExtensionLocalizationPeer::OnReceivedData(const char* data, | 62 void ExtensionLocalizationPeer::OnReceivedData(const char* data, |
63 int data_length, | 63 int data_length, |
64 int encoded_data_length) { | 64 int encoded_data_length) { |
65 data_.append(data, data_length); | 65 data_.append(data, data_length); |
66 } | 66 } |
67 | 67 |
68 void ExtensionLocalizationPeer::OnCompletedRequest( | 68 void ExtensionLocalizationPeer::OnCompletedRequest( |
69 const net::URLRequestStatus& status, | 69 int error_code, |
| 70 bool was_ignored_by_handler, |
70 const std::string& security_info, | 71 const std::string& security_info, |
71 const base::TimeTicks& completion_time) { | 72 const base::TimeTicks& completion_time) { |
72 // Make sure we delete ourselves at the end of this call. | 73 // Make sure we delete ourselves at the end of this call. |
73 scoped_ptr<ExtensionLocalizationPeer> this_deleter(this); | 74 scoped_ptr<ExtensionLocalizationPeer> this_deleter(this); |
74 | 75 |
75 // Give sub-classes a chance at altering the data. | 76 // Give sub-classes a chance at altering the data. |
76 if (status.status() != net::URLRequestStatus::SUCCESS) { | 77 if (error_code != net::OK) { |
77 // We failed to load the resource. | 78 // We failed to load the resource. |
78 original_peer_->OnReceivedResponse(response_info_); | 79 original_peer_->OnReceivedResponse(response_info_); |
79 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, | 80 original_peer_->OnCompletedRequest(net::ERR_ABORTED, false, security_info, |
80 net::ERR_ABORTED); | 81 completion_time); |
81 original_peer_->OnCompletedRequest(status, security_info, completion_time); | |
82 return; | 82 return; |
83 } | 83 } |
84 | 84 |
85 ReplaceMessages(); | 85 ReplaceMessages(); |
86 | 86 |
87 original_peer_->OnReceivedResponse(response_info_); | 87 original_peer_->OnReceivedResponse(response_info_); |
88 if (!data_.empty()) | 88 if (!data_.empty()) |
89 original_peer_->OnReceivedData(data_.data(), | 89 original_peer_->OnReceivedData(data_.data(), |
90 static_cast<int>(data_.size()), | 90 static_cast<int>(data_.size()), |
91 -1); | 91 -1); |
92 original_peer_->OnCompletedRequest(status, security_info, completion_time); | 92 original_peer_->OnCompletedRequest(error_code, was_ignored_by_handler, |
| 93 security_info, completion_time); |
93 } | 94 } |
94 | 95 |
95 void ExtensionLocalizationPeer::ReplaceMessages() { | 96 void ExtensionLocalizationPeer::ReplaceMessages() { |
96 if (!message_sender_ || data_.empty()) | 97 if (!message_sender_ || data_.empty()) |
97 return; | 98 return; |
98 | 99 |
99 if (!request_url_.is_valid()) | 100 if (!request_url_.is_valid()) |
100 return; | 101 return; |
101 | 102 |
102 std::string extension_id = request_url_.host(); | 103 std::string extension_id = request_url_.host(); |
(...skipping 12 matching lines...) Expand all Loading... |
115 | 116 |
116 l10n_messages = extensions::GetL10nMessagesMap(extension_id); | 117 l10n_messages = extensions::GetL10nMessagesMap(extension_id); |
117 } | 118 } |
118 | 119 |
119 std::string error; | 120 std::string error; |
120 if (extensions::MessageBundle::ReplaceMessagesWithExternalDictionary( | 121 if (extensions::MessageBundle::ReplaceMessagesWithExternalDictionary( |
121 *l10n_messages, &data_, &error)) { | 122 *l10n_messages, &data_, &error)) { |
122 data_.resize(data_.size()); | 123 data_.resize(data_.size()); |
123 } | 124 } |
124 } | 125 } |
OLD | NEW |