| 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 #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_message_bundle.h" | 9 #include "chrome/common/extensions/extension_message_bundle.h" |
| 10 #include "chrome/common/extensions/extension_messages.h" | 10 #include "chrome/common/extensions/extension_messages.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 GURL* new_first_party_for_cookies) { | 52 GURL* new_first_party_for_cookies) { |
| 53 NOTREACHED(); | 53 NOTREACHED(); |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void ExtensionLocalizationPeer::OnReceivedResponse( | 57 void ExtensionLocalizationPeer::OnReceivedResponse( |
| 58 const webkit_glue::ResourceResponseInfo& info) { | 58 const webkit_glue::ResourceResponseInfo& info) { |
| 59 response_info_ = info; | 59 response_info_ = info; |
| 60 } | 60 } |
| 61 | 61 |
| 62 void ExtensionLocalizationPeer::OnReceivedData(const char* data, int len) { | 62 void ExtensionLocalizationPeer::OnReceivedData(const char* data, |
| 63 data_.append(data, len); | 63 int data_length, |
| 64 int raw_data_length) { |
| 65 data_.append(data, data_length); |
| 64 } | 66 } |
| 65 | 67 |
| 66 void ExtensionLocalizationPeer::OnCompletedRequest( | 68 void ExtensionLocalizationPeer::OnCompletedRequest( |
| 67 const net::URLRequestStatus& status, | 69 const net::URLRequestStatus& status, |
| 68 const std::string& security_info, | 70 const std::string& security_info, |
| 69 const base::Time& completion_time) { | 71 const base::Time& completion_time) { |
| 70 // Make sure we delete ourselves at the end of this call. | 72 // Make sure we delete ourselves at the end of this call. |
| 71 scoped_ptr<ExtensionLocalizationPeer> this_deleter(this); | 73 scoped_ptr<ExtensionLocalizationPeer> this_deleter(this); |
| 72 | 74 |
| 73 // Give sub-classes a chance at altering the data. | 75 // Give sub-classes a chance at altering the data. |
| 74 if (status.status() != net::URLRequestStatus::SUCCESS) { | 76 if (status.status() != net::URLRequestStatus::SUCCESS) { |
| 75 // We failed to load the resource. | 77 // We failed to load the resource. |
| 76 original_peer_->OnReceivedResponse(response_info_); | 78 original_peer_->OnReceivedResponse(response_info_); |
| 77 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, | 79 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, |
| 78 net::ERR_ABORTED); | 80 net::ERR_ABORTED); |
| 79 original_peer_->OnCompletedRequest(status, security_info, completion_time); | 81 original_peer_->OnCompletedRequest(status, security_info, completion_time); |
| 80 return; | 82 return; |
| 81 } | 83 } |
| 82 | 84 |
| 83 ReplaceMessages(); | 85 ReplaceMessages(); |
| 84 | 86 |
| 85 original_peer_->OnReceivedResponse(response_info_); | 87 original_peer_->OnReceivedResponse(response_info_); |
| 86 if (!data_.empty()) | 88 if (!data_.empty()) |
| 87 original_peer_->OnReceivedData(data_.data(), | 89 original_peer_->OnReceivedData(data_.data(), |
| 88 static_cast<int>(data_.size())); | 90 static_cast<int>(data_.size()), |
| 91 -1); |
| 89 original_peer_->OnCompletedRequest(status, security_info, completion_time); | 92 original_peer_->OnCompletedRequest(status, security_info, completion_time); |
| 90 } | 93 } |
| 91 | 94 |
| 92 void ExtensionLocalizationPeer::ReplaceMessages() { | 95 void ExtensionLocalizationPeer::ReplaceMessages() { |
| 93 if (!message_sender_ || data_.empty()) | 96 if (!message_sender_ || data_.empty()) |
| 94 return; | 97 return; |
| 95 | 98 |
| 96 if (!request_url_.is_valid()) | 99 if (!request_url_.is_valid()) |
| 97 return; | 100 return; |
| 98 | 101 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 111 | 114 |
| 112 l10n_messages = GetL10nMessagesMap(extension_id); | 115 l10n_messages = GetL10nMessagesMap(extension_id); |
| 113 } | 116 } |
| 114 | 117 |
| 115 std::string error; | 118 std::string error; |
| 116 if (ExtensionMessageBundle::ReplaceMessagesWithExternalDictionary( | 119 if (ExtensionMessageBundle::ReplaceMessagesWithExternalDictionary( |
| 117 *l10n_messages, &data_, &error)) { | 120 *l10n_messages, &data_, &error)) { |
| 118 data_.resize(data_.size()); | 121 data_.resize(data_.size()); |
| 119 } | 122 } |
| 120 } | 123 } |
| OLD | NEW |