summaryrefslogtreecommitdiffstats
path: root/webkit/glue/ftp_directory_listing_response_delegate.h
blob: 1218da9b7956b1b66ce036f5c55ba751a89868c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2009 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.
//
// A delegate class of WebURLLoaderImpl that handles text/vnd.chromium.ftp-dir
// data.

#ifndef WEBKIT_GLUE_FTP_DIRECTORY_LISTING_RESPONSE_DELEGATE_H_
#define WEBKIT_GLUE_FTP_DIRECTORY_LISTING_RESPONSE_DELEGATE_H_

#include <string>

#include "net/ftp/ftp_directory_listing_buffer.h"
#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"

namespace WebKit {
class WebURLLoader;
class WebURLLoaderClient;
}

namespace webkit_glue {

class FtpDirectoryListingResponseDelegate {
 public:
  FtpDirectoryListingResponseDelegate(WebKit::WebURLLoaderClient* client,
                                      WebKit::WebURLLoader* loader,
                                      const WebKit::WebURLResponse& response);

  // Passed through from ResourceHandleInternal
  void OnReceivedData(const char* data, int data_len);
  void OnCompletedRequest();

 private:
  void Init();

  // Converts |filename| to detected server encoding and puts the result
  // in |raw_bytes| (if no conversion is necessary, an empty string is used).
  // Returns true on success.
  bool ConvertToServerEncoding(const string16& filename,
                               std::string* raw_bytes) const;

  // Fetches the listing entries from the buffer and sends them to the client.
  void ProcessReceivedEntries();

  void SendDataToClient(const std::string& data);

  // Pointers to the client and associated loader so we can make callbacks as
  // we parse pieces of data.
  WebKit::WebURLLoaderClient* client_;
  WebKit::WebURLLoader* loader_;

  // The original resource response for this request.  We use this as a
  // starting point for each parts response.
  WebKit::WebURLResponse original_response_;

  // Data buffer also responsible for parsing the listing data.
  net::FtpDirectoryListingBuffer buffer_;

  // True if we updated histogram data (we only want to do it once).
  bool updated_histograms_;

  // True if we got an error when parsing the response.
  bool had_parsing_error_;
};

}  // namespace webkit_glue

#endif  // WEBKIT_GLUE_FTP_DIRECTORY_LISTING_RESPONSE_DELEGATE_H_