| 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 30 matching lines...) Expand all Loading... |
| 41 } | 41 } |
| 42 | 42 |
| 43 void ExtensionLocalizationPeer::OnUploadProgress( | 43 void ExtensionLocalizationPeer::OnUploadProgress( |
| 44 uint64 position, uint64 size) { | 44 uint64 position, uint64 size) { |
| 45 NOTREACHED(); | 45 NOTREACHED(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool ExtensionLocalizationPeer::OnReceivedRedirect( | 48 bool ExtensionLocalizationPeer::OnReceivedRedirect( |
| 49 const GURL& new_url, | 49 const GURL& new_url, |
| 50 const webkit_glue::ResourceResponseInfo& info, | 50 const webkit_glue::ResourceResponseInfo& info, |
| 51 const base::TimeTicks& start_time, |
| 52 const base::TimeTicks& end_time, |
| 51 bool* has_new_first_party_for_cookies, | 53 bool* has_new_first_party_for_cookies, |
| 52 GURL* new_first_party_for_cookies) { | 54 GURL* new_first_party_for_cookies) { |
| 53 NOTREACHED(); | 55 NOTREACHED(); |
| 54 return false; | 56 return false; |
| 55 } | 57 } |
| 56 | 58 |
| 57 void ExtensionLocalizationPeer::OnReceivedResponse( | 59 void ExtensionLocalizationPeer::OnReceivedResponse( |
| 58 const webkit_glue::ResourceResponseInfo& info) { | 60 const webkit_glue::ResourceResponseInfo& info, |
| 61 const base::TimeTicks& start_time, |
| 62 const base::TimeTicks& end_time) { |
| 59 response_info_ = info; | 63 response_info_ = info; |
| 64 start_time_ = start_time; |
| 65 end_time_ = end_time; |
| 60 } | 66 } |
| 61 | 67 |
| 62 void ExtensionLocalizationPeer::OnReceivedData(const char* data, | 68 void ExtensionLocalizationPeer::OnReceivedData(const char* data, |
| 63 int data_length, | 69 int data_length, |
| 64 int encoded_data_length) { | 70 int encoded_data_length) { |
| 65 data_.append(data, data_length); | 71 data_.append(data, data_length); |
| 66 } | 72 } |
| 67 | 73 |
| 68 void ExtensionLocalizationPeer::OnCompletedRequest( | 74 void ExtensionLocalizationPeer::OnCompletedRequest( |
| 69 const net::URLRequestStatus& status, | 75 const net::URLRequestStatus& status, |
| 70 const std::string& security_info, | 76 const std::string& security_info, |
| 71 const base::Time& completion_time) { | 77 const base::TimeTicks& completion_time) { |
| 72 // Make sure we delete ourselves at the end of this call. | 78 // Make sure we delete ourselves at the end of this call. |
| 73 scoped_ptr<ExtensionLocalizationPeer> this_deleter(this); | 79 scoped_ptr<ExtensionLocalizationPeer> this_deleter(this); |
| 74 | 80 |
| 75 // Give sub-classes a chance at altering the data. | 81 // Give sub-classes a chance at altering the data. |
| 76 if (status.status() != net::URLRequestStatus::SUCCESS) { | 82 if (status.status() != net::URLRequestStatus::SUCCESS) { |
| 77 // We failed to load the resource. | 83 // We failed to load the resource. |
| 78 original_peer_->OnReceivedResponse(response_info_); | 84 original_peer_->OnReceivedResponse(response_info_, start_time_, end_time_); |
| 79 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, | 85 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, |
| 80 net::ERR_ABORTED); | 86 net::ERR_ABORTED); |
| 81 original_peer_->OnCompletedRequest(status, security_info, completion_time); | 87 original_peer_->OnCompletedRequest(status, security_info, completion_time); |
| 82 return; | 88 return; |
| 83 } | 89 } |
| 84 | 90 |
| 85 ReplaceMessages(); | 91 ReplaceMessages(); |
| 86 | 92 |
| 87 original_peer_->OnReceivedResponse(response_info_); | 93 original_peer_->OnReceivedResponse(response_info_, start_time_, end_time_); |
| 88 if (!data_.empty()) | 94 if (!data_.empty()) |
| 89 original_peer_->OnReceivedData(data_.data(), | 95 original_peer_->OnReceivedData(data_.data(), |
| 90 static_cast<int>(data_.size()), | 96 static_cast<int>(data_.size()), |
| 91 -1); | 97 -1); |
| 92 original_peer_->OnCompletedRequest(status, security_info, completion_time); | 98 original_peer_->OnCompletedRequest(status, security_info, completion_time); |
| 93 } | 99 } |
| 94 | 100 |
| 95 void ExtensionLocalizationPeer::ReplaceMessages() { | 101 void ExtensionLocalizationPeer::ReplaceMessages() { |
| 96 if (!message_sender_ || data_.empty()) | 102 if (!message_sender_ || data_.empty()) |
| 97 return; | 103 return; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 114 | 120 |
| 115 l10n_messages = GetL10nMessagesMap(extension_id); | 121 l10n_messages = GetL10nMessagesMap(extension_id); |
| 116 } | 122 } |
| 117 | 123 |
| 118 std::string error; | 124 std::string error; |
| 119 if (ExtensionMessageBundle::ReplaceMessagesWithExternalDictionary( | 125 if (ExtensionMessageBundle::ReplaceMessagesWithExternalDictionary( |
| 120 *l10n_messages, &data_, &error)) { | 126 *l10n_messages, &data_, &error)) { |
| 121 data_.resize(data_.size()); | 127 data_.resize(data_.size()); |
| 122 } | 128 } |
| 123 } | 129 } |
| OLD | NEW |