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 length_received) { |
| 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()), -1); |
89 original_peer_->OnCompletedRequest(status, security_info, completion_time); | 91 original_peer_->OnCompletedRequest(status, security_info, completion_time); |
90 } | 92 } |
91 | 93 |
92 void ExtensionLocalizationPeer::ReplaceMessages() { | 94 void ExtensionLocalizationPeer::ReplaceMessages() { |
93 if (!message_sender_ || data_.empty()) | 95 if (!message_sender_ || data_.empty()) |
94 return; | 96 return; |
95 | 97 |
96 if (!request_url_.is_valid()) | 98 if (!request_url_.is_valid()) |
97 return; | 99 return; |
98 | 100 |
(...skipping 12 matching lines...) Expand all Loading... |
111 | 113 |
112 l10n_messages = GetL10nMessagesMap(extension_id); | 114 l10n_messages = GetL10nMessagesMap(extension_id); |
113 } | 115 } |
114 | 116 |
115 std::string error; | 117 std::string error; |
116 if (ExtensionMessageBundle::ReplaceMessagesWithExternalDictionary( | 118 if (ExtensionMessageBundle::ReplaceMessagesWithExternalDictionary( |
117 *l10n_messages, &data_, &error)) { | 119 *l10n_messages, &data_, &error)) { |
118 data_.resize(data_.size()); | 120 data_.resize(data_.size()); |
119 } | 121 } |
120 } | 122 } |
OLD | NEW |