Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Unified Diff: webkit/glue/ftp_directory_listing_response_delegate.cc

Issue 6670085: FTP: Detect the character encoding only after the entire listing is received. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test coverage Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/glue/ftp_directory_listing_response_delegate.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/ftp_directory_listing_response_delegate.cc
diff --git a/webkit/glue/ftp_directory_listing_response_delegate.cc b/webkit/glue/ftp_directory_listing_response_delegate.cc
index 0a2542bd4c360c7d5b3bf1ff74324f8839e73b9d..a94d299806def9d161a4a886705c9124c163613a 100644
--- a/webkit/glue/ftp_directory_listing_response_delegate.cc
+++ b/webkit/glue/ftp_directory_listing_response_delegate.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -17,7 +17,6 @@
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
#include "net/ftp/ftp_directory_listing_parser.h"
-#include "net/ftp/ftp_server_type_histograms.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h"
@@ -60,37 +59,40 @@ FtpDirectoryListingResponseDelegate::FtpDirectoryListingResponseDelegate(
WebURLLoader* loader,
const WebURLResponse& response)
: client_(client),
- loader_(loader),
- original_response_(response),
- buffer_(base::Time::Now()),
- updated_histograms_(false),
- had_parsing_error_(false) {
- Init();
+ loader_(loader) {
+ Init(response.url());
}
void FtpDirectoryListingResponseDelegate::OnReceivedData(const char* data,
int data_len) {
- if (had_parsing_error_)
- return;
-
- if (buffer_.ConsumeData(data, data_len) == net::OK)
- ProcessReceivedEntries();
- else
- had_parsing_error_ = true;
+ buffer_.append(data, data_len);
}
void FtpDirectoryListingResponseDelegate::OnCompletedRequest() {
- if (!had_parsing_error_ && buffer_.ProcessRemainingData() == net::OK)
- ProcessReceivedEntries();
- else
- had_parsing_error_ = true;
-
- if (had_parsing_error_)
+ std::vector<FtpDirectoryListingEntry> entries;
+ int rv = net::ParseFtpDirectoryListing(buffer_, base::Time::Now(), &entries);
+ if (rv != net::OK) {
SendDataToClient("<script>onListingParsingError();</script>\n");
+ return;
+ }
+ for (size_t i = 0; i < entries.size(); i++) {
+ FtpDirectoryListingEntry entry = entries[i];
+
+ // Skip the current and parent directory entries in the listing. Our header
+ // always includes them.
+ if (EqualsASCII(entry.name, ".") || EqualsASCII(entry.name, ".."))
+ continue;
+
+ bool is_directory = (entry.type == FtpDirectoryListingEntry::DIRECTORY);
+ int64 size = entry.size;
+ if (entry.type != FtpDirectoryListingEntry::FILE)
+ size = 0;
+ SendDataToClient(net::GetDirectoryListingEntry(
+ entry.name, entry.raw_name, is_directory, size, entry.last_modified));
+ }
}
-void FtpDirectoryListingResponseDelegate::Init() {
- GURL response_url(original_response_.url());
+void FtpDirectoryListingResponseDelegate::Init(const GURL& response_url) {
UnescapeRule::Type unescape_rules = UnescapeRule::SPACES |
UnescapeRule::URL_SPECIAL_CHARS;
std::string unescaped_path = UnescapeURLComponent(response_url.path(),
@@ -106,51 +108,6 @@ void FtpDirectoryListingResponseDelegate::Init() {
}
}
-bool FtpDirectoryListingResponseDelegate::ConvertToServerEncoding(
- const string16& filename, std::string* raw_bytes) const {
- if (buffer_.encoding().empty()) {
- *raw_bytes = std::string();
- return true;
- }
-
- return base::UTF16ToCodepage(filename, buffer_.encoding().c_str(),
- base::OnStringConversionError::FAIL,
- raw_bytes);
-}
-
-void FtpDirectoryListingResponseDelegate::ProcessReceivedEntries() {
- if (!updated_histograms_ && buffer_.EntryAvailable()) {
- // Only log the server type if we got enough data to reliably detect it.
- net::UpdateFtpServerTypeHistograms(buffer_.GetServerType());
- updated_histograms_ = true;
- }
-
- while (buffer_.EntryAvailable()) {
- FtpDirectoryListingEntry entry = buffer_.PopEntry();
-
- // Skip the current and parent directory entries in the listing. Our header
- // always includes them.
- if (EqualsASCII(entry.name, ".") || EqualsASCII(entry.name, ".."))
- continue;
-
- bool is_directory = (entry.type == FtpDirectoryListingEntry::DIRECTORY);
- int64 size = entry.size;
- if (entry.type != FtpDirectoryListingEntry::FILE)
- size = 0;
- std::string raw_bytes;
- if (ConvertToServerEncoding(entry.name, &raw_bytes)) {
- SendDataToClient(net::GetDirectoryListingEntry(
- entry.name, raw_bytes, is_directory, size, entry.last_modified));
- } else {
- // Consider an encoding problem a non-fatal error. The server's support
- // for non-ASCII characters might be buggy. Display an error message,
- // but keep trying to display the rest of the listing (most file names
- // are ASCII anyway, we could be just unlucky with this one).
- had_parsing_error_ = true;
- }
- }
-}
-
void FtpDirectoryListingResponseDelegate::SendDataToClient(
const std::string& data) {
client_->didReceiveData(loader_, data.data(), data.length());
« no previous file with comments | « webkit/glue/ftp_directory_listing_response_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698