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

Side by Side Diff: chrome/browser/extensions/api/web_request/upload_data_presenter.h

Issue 10694055: Add read-only access to POST data for webRequest's onBeforeRequest (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Corrected the multipart parser + parsedForm->formData Created 8 years, 4 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_UPLOAD_DATA_PRESENTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_UPLOAD_DATA_PRESENTER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/memory/scoped_ptr.h"
12 // Need to include this, because UploadData::Element cannot be forward declared.
13 #include "net/base/upload_data.h"
14
15 namespace base {
16 class DictionaryValue;
17 class ListValue;
18 class Value;
19 }
20
21 namespace extensions {
22 class FormDataParser;
23 }
24
25 namespace net {
26 class URLRequest;
27 }
28
29 namespace extensions {
30
31 // UploadDataPresenter is an interface for objects capable to be consume
battre 2012/08/16 19:18:03 -be
vabr (Chromium) 2012/08/17 18:29:57 Done.
32 // a series of UploadData::Element and represent this data as a base:Value.
33 //
34 // Workflow for objects implementing this interface:
35 // 1. Call object->FeedNext(element) for each element from the request's body.
36 // 2. Check if object->Succeeded().
37 // 3. If that check passed then retrieve object->Result().
38 class UploadDataPresenter {
39 public:
40 virtual ~UploadDataPresenter();
41 virtual void FeedNext(const net::UploadData::Element& element) = 0;
42 virtual bool Succeeded() = 0;
43 virtual scoped_ptr<base::Value> Result() = 0;
44
45 protected:
46 UploadDataPresenter() {}
47
48 private:
49 DISALLOW_COPY_AND_ASSIGN(UploadDataPresenter);
50 };
51
52 // This class checks that chunked transfer encoding (defined in RFC 2616)
53 // is not used. If it is, an error string is generated.
54 class ChunkedErrorPresenter : public UploadDataPresenter {
55 public:
56 explicit ChunkedErrorPresenter(const net::URLRequest* request);
57 virtual ~ChunkedErrorPresenter();
58
59 // Tests the headers of |request| for transfer encoding.
60 static bool TransferEncodingChunked(const net::URLRequest* request);
battre 2012/08/16 19:18:03 Put a verb ("Is") to the beginning of method name?
vabr (Chromium) 2012/08/17 18:29:57 Done.
61
62 // Implementation of UploadDataPresenter.
63 virtual void FeedNext(const net::UploadData::Element& element) OVERRIDE;
64 virtual bool Succeeded() OVERRIDE;
65 virtual scoped_ptr<base::Value> Result() OVERRIDE;
66
67 private:
68 bool chunks_found_;
69 };
70
71 class RawDataPresenter : public UploadDataPresenter {
battre 2012/08/16 19:18:03 Can you please add a high level description for th
vabr (Chromium) 2012/08/17 18:29:57 Done.
72 public:
73 RawDataPresenter();
74 virtual ~RawDataPresenter();
75
76 // Implementation of UploadDataPresenter.
77 virtual void FeedNext(const net::UploadData::Element& element) OVERRIDE;
78 virtual bool Succeeded() OVERRIDE;
79 virtual scoped_ptr<base::Value> Result() OVERRIDE;
80
81 private:
82 // Clears resources and the success flag.
83 void Abort();
84
85 void FeedNextBytes(const std::vector<char>& bytes);
86 void FeedNextFile(const std::string& filename);
87 FRIEND_TEST_ALL_PREFIXES(WebRequestUploadDataPresenterTest, RawData);
88
89 bool success_;
90 scoped_ptr<base::ListValue> list_;
91 };
92
93 class ParsedDataPresenter : public UploadDataPresenter {
battre 2012/08/16 19:18:03 Can you please add a high level description for th
vabr (Chromium) 2012/08/17 18:29:57 Done.
94 public:
95 explicit ParsedDataPresenter(const net::URLRequest* request);
96 virtual ~ParsedDataPresenter();
97
98 // Implementation of UploadDataPresenter.
99 virtual void FeedNext(const net::UploadData::Element& element) OVERRIDE;
100 virtual bool Succeeded() OVERRIDE;
101 virtual scoped_ptr<base::Value> Result() OVERRIDE;
102
103 private:
104 // Clears resources and the success flag.
105 void Abort();
106 scoped_ptr<FormDataParser> parser_;
107 bool success_;
108 scoped_ptr<base::DictionaryValue> dictionary_;
109 };
110
111 } // namespace extensions
112
113 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_UPLOAD_DATA_PRESENTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698