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

Side by Side Diff: content/child/ftp_directory_listing_response_delegate.cc

Issue 2792533003: Separate the parent directory link in FTP listings. (Closed)
Patch Set: Fix comment not converted by Blink mass reformatting Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | net/base/dir_header.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/child/ftp_directory_listing_response_delegate.h" 5 #include "content/child/ftp_directory_listing_response_delegate.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 namespace content { 59 namespace content {
60 60
61 FtpDirectoryListingResponseDelegate::FtpDirectoryListingResponseDelegate( 61 FtpDirectoryListingResponseDelegate::FtpDirectoryListingResponseDelegate(
62 WebURLLoaderClient* client, 62 WebURLLoaderClient* client,
63 WebURLLoader* loader, 63 WebURLLoader* loader,
64 const WebURLResponse& response) 64 const WebURLResponse& response)
65 : client_(client), 65 : client_(client),
66 loader_(loader) { 66 loader_(loader) {
67 if (response.GetExtraData()) { 67 if (response.GetExtraData()) {
68 // extraData can be NULL during tests. 68 // |extra_data| can be NULL during tests.
69 WebURLResponseExtraDataImpl* extra_data = 69 WebURLResponseExtraDataImpl* extra_data =
70 static_cast<WebURLResponseExtraDataImpl*>(response.GetExtraData()); 70 static_cast<WebURLResponseExtraDataImpl*>(response.GetExtraData());
71 extra_data->set_is_ftp_directory_listing(true); 71 extra_data->set_is_ftp_directory_listing(true);
72 } 72 }
73 Init(response.Url()); 73 Init(response.Url());
74 } 74 }
75 75
76 void FtpDirectoryListingResponseDelegate::Cancel() { 76 void FtpDirectoryListingResponseDelegate::Cancel() {
77 client_ = NULL; 77 client_ = nullptr;
78 loader_ = NULL; 78 loader_ = nullptr;
79 } 79 }
80 80
81 void FtpDirectoryListingResponseDelegate::OnReceivedData(const char* data, 81 void FtpDirectoryListingResponseDelegate::OnReceivedData(const char* data,
82 int data_len) { 82 int data_len) {
83 buffer_.append(data, data_len); 83 buffer_.append(data, data_len);
84 } 84 }
85 85
86 void FtpDirectoryListingResponseDelegate::OnCompletedRequest() { 86 void FtpDirectoryListingResponseDelegate::OnCompletedRequest() {
87 std::vector<FtpDirectoryListingEntry> entries; 87 std::vector<FtpDirectoryListingEntry> entries;
88 int rv = -1; 88 int rv = net::ERR_NOT_IMPLEMENTED;
89 #if !BUILDFLAG(DISABLE_FTP_SUPPORT) 89 #if !BUILDFLAG(DISABLE_FTP_SUPPORT)
90 rv = net::ParseFtpDirectoryListing(buffer_, base::Time::Now(), &entries); 90 rv = net::ParseFtpDirectoryListing(buffer_, base::Time::Now(), &entries);
91 #endif 91 #endif
92 if (rv != net::OK) { 92 if (rv != net::OK) {
93 SendDataToClient("<script>onListingParsingError();</script>\n"); 93 SendDataToClient("<script>onListingParsingError();</script>\n");
94 return; 94 return;
95 } 95 }
96 for (size_t i = 0; i < entries.size(); i++) { 96 for (const FtpDirectoryListingEntry& entry : entries) {
97 const FtpDirectoryListingEntry& entry = entries[i];
98
99 // Skip the current and parent directory entries in the listing. Our header 97 // Skip the current and parent directory entries in the listing. Our header
100 // always includes them. 98 // always includes them.
101 if (base::EqualsASCII(entry.name, ".") || 99 if (base::EqualsASCII(entry.name, ".") ||
102 base::EqualsASCII(entry.name, "..")) 100 base::EqualsASCII(entry.name, ".."))
103 continue; 101 continue;
104 102
105 bool is_directory = (entry.type == FtpDirectoryListingEntry::DIRECTORY); 103 bool is_directory = (entry.type == FtpDirectoryListingEntry::DIRECTORY);
106 int64_t size = entry.size; 104 int64_t size =
107 if (entry.type != FtpDirectoryListingEntry::FILE) 105 entry.type == FtpDirectoryListingEntry::FILE ? entry.size : 0;
108 size = 0;
109 SendDataToClient(net::GetDirectoryListingEntry( 106 SendDataToClient(net::GetDirectoryListingEntry(
110 entry.name, entry.raw_name, is_directory, size, entry.last_modified)); 107 entry.name, entry.raw_name, is_directory, size, entry.last_modified));
111 } 108 }
112 } 109 }
113 110
114 void FtpDirectoryListingResponseDelegate::Init(const GURL& response_url) { 111 void FtpDirectoryListingResponseDelegate::Init(const GURL& response_url) {
115 net::UnescapeRule::Type unescape_rules = 112 net::UnescapeRule::Type unescape_rules =
116 net::UnescapeRule::SPACES | 113 net::UnescapeRule::SPACES |
117 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS; 114 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS;
118 std::string unescaped_path = net::UnescapeURLComponent(response_url.path(), 115 std::string unescaped_path = net::UnescapeURLComponent(response_url.path(),
119 unescape_rules); 116 unescape_rules);
120 SendDataToClient(net::GetDirectoryListingHeader( 117 SendDataToClient(net::GetDirectoryListingHeader(
121 ConvertPathToUTF16(unescaped_path))); 118 ConvertPathToUTF16(unescaped_path)));
122 119
123 // If this isn't top level directory (i.e. the path isn't "/",) 120 // If this isn't top level directory (i.e. the path isn't "/",)
124 // add a link to the parent directory. 121 // add a link to the parent directory.
125 if (response_url.path().length() > 1) { 122 if (response_url.path().length() > 1) {
126 SendDataToClient(net::GetDirectoryListingEntry( 123 SendDataToClient("<script>onHasParentDirectory();</script>\n");
127 base::ASCIIToUTF16(".."), std::string(), false, 0, base::Time()));
128 } 124 }
129 } 125 }
130 126
131 void FtpDirectoryListingResponseDelegate::SendDataToClient( 127 void FtpDirectoryListingResponseDelegate::SendDataToClient(
132 const std::string& data) { 128 const std::string& data) {
133 if (client_) { 129 if (client_) {
134 client_->DidReceiveData(data.data(), data.length()); 130 client_->DidReceiveData(data.data(), data.length());
135 } 131 }
136 } 132 }
137 133
138 } // namespace content 134 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | net/base/dir_header.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698