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

Side by Side Diff: chrome/browser/extensions/api/web_request/web_request_api.cc

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: Deleting a forgotten comment Created 8 years, 5 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/browser/extensions/api/web_request/web_request_api.h" 5 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 26 matching lines...) Expand all
37 #include "chrome/common/extensions/url_pattern.h" 37 #include "chrome/common/extensions/url_pattern.h"
38 #include "chrome/common/url_constants.h" 38 #include "chrome/common/url_constants.h"
39 #include "content/public/browser/browser_message_filter.h" 39 #include "content/public/browser/browser_message_filter.h"
40 #include "content/public/browser/browser_thread.h" 40 #include "content/public/browser/browser_thread.h"
41 #include "content/public/browser/render_process_host.h" 41 #include "content/public/browser/render_process_host.h"
42 #include "content/public/browser/resource_request_info.h" 42 #include "content/public/browser/resource_request_info.h"
43 #include "googleurl/src/gurl.h" 43 #include "googleurl/src/gurl.h"
44 #include "grit/generated_resources.h" 44 #include "grit/generated_resources.h"
45 #include "net/base/auth.h" 45 #include "net/base/auth.h"
46 #include "net/base/net_errors.h" 46 #include "net/base/net_errors.h"
47 #include "net/base/upload_data.h"
47 #include "net/http/http_response_headers.h" 48 #include "net/http/http_response_headers.h"
48 #include "net/url_request/url_request.h" 49 #include "net/url_request/url_request.h"
49 #include "ui/base/l10n/l10n_util.h" 50 #include "ui/base/l10n/l10n_util.h"
50 51
51 using content::BrowserMessageFilter; 52 using content::BrowserMessageFilter;
52 using content::BrowserThread; 53 using content::BrowserThread;
53 using content::ResourceRequestInfo; 54 using content::ResourceRequestInfo;
54 using extensions::Extension; 55 using extensions::Extension;
55 56
56 namespace helpers = extension_web_request_api_helpers; 57 namespace helpers = extension_web_request_api_helpers;
57 namespace keys = extension_web_request_api_constants; 58 namespace keys = extension_web_request_api_constants;
58 59
59 namespace { 60 namespace {
60 61
61 // List of all the webRequest events. 62 // List of all the webRequest events.
62 static const char* const kWebRequestEvents[] = { 63 static const char* const kWebRequestEvents[] = {
63 keys::kOnBeforeRedirect, 64 keys::kOnBeforeRedirect,
64 keys::kOnBeforeRequest, 65 keys::kOnBeforeRequest,
65 keys::kOnBeforeSendHeaders, 66 keys::kOnBeforeSendHeaders,
66 keys::kOnCompleted, 67 keys::kOnCompleted,
67 keys::kOnErrorOccurred, 68 keys::kOnErrorOccurred,
68 keys::kOnSendHeaders, 69 keys::kOnSendHeaders,
69 keys::kOnAuthRequired, 70 keys::kOnAuthRequired,
70 keys::kOnResponseStarted, 71 keys::kOnResponseStarted,
71 keys::kOnHeadersReceived, 72 keys::kOnHeadersReceived,
72 }; 73 };
73 74
74 #define ARRAYEND(array) (array + arraysize(array)) 75 #define ARRAYEND(array) (array + arraysize(array))
75 76
77 const char kContentDisposition[] = "Content-Disposition:";
78
76 // Returns the frame ID as it will be passed to the extension: 79 // Returns the frame ID as it will be passed to the extension:
77 // 0 if the navigation happens in the main frame, or the frame ID 80 // 0 if the navigation happens in the main frame, or the frame ID
78 // modulo 32 bits otherwise. 81 // modulo 32 bits otherwise.
79 // Keep this in sync with the GetFrameId() function in 82 // Keep this in sync with the GetFrameId() function in
80 // extension_webnavigation_api.cc. 83 // extension_webnavigation_api.cc.
81 int GetFrameId(bool is_main_frame, int64 frame_id) { 84 int GetFrameId(bool is_main_frame, int64 frame_id) {
82 return is_main_frame ? 0 : static_cast<int>(frame_id); 85 return is_main_frame ? 0 : static_cast<int>(frame_id);
83 } 86 }
84 87
85 bool IsWebRequestEvent(const std::string& event_name) { 88 bool IsWebRequestEvent(const std::string& event_name) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 base::Uint64ToString(request->identifier())); 165 base::Uint64ToString(request->identifier()));
163 out->SetString(keys::kUrlKey, request->url().spec()); 166 out->SetString(keys::kUrlKey, request->url().spec());
164 out->SetString(keys::kMethodKey, request->method()); 167 out->SetString(keys::kMethodKey, request->method());
165 out->SetInteger(keys::kFrameIdKey, frame_id_for_extension); 168 out->SetInteger(keys::kFrameIdKey, frame_id_for_extension);
166 out->SetInteger(keys::kParentFrameIdKey, parent_frame_id_for_extension); 169 out->SetInteger(keys::kParentFrameIdKey, parent_frame_id_for_extension);
167 out->SetInteger(keys::kTabIdKey, tab_id); 170 out->SetInteger(keys::kTabIdKey, tab_id);
168 out->SetString(keys::kTypeKey, helpers::ResourceTypeToString(resource_type)); 171 out->SetString(keys::kTypeKey, helpers::ResourceTypeToString(resource_type));
169 out->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000); 172 out->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000);
170 } 173 }
171 174
175 // Interface for parsers for the POST data.
176 class PostDataParser {
battre 2012/07/11 10:59:50 could you move all of this new code to c/b/e/api/w
vabr (Chromium) 2012/07/12 15:13:11 Done, except for ExtractRequestInfoPost which I fe
177 public:
178 struct Result {
179 base::StringPiece key;
180 base::StringPiece val;
181 };
182 // Sets the |length| bytes at |source| as the data to be parsed.
183 // Returns true on success.
battre 2012/07/11 10:59:50 There is no |length| anymore.
vabr (Chromium) 2012/07/12 15:13:11 Done.
184 virtual bool SetSource(const std::vector<char>& source) = 0;
battre 2012/07/11 10:59:50 I think you should pass a const std::vector<char>*
battre 2012/07/11 10:59:50 What do you think of making SetSource part of the
vabr (Chromium) 2012/07/12 15:13:11 That would not work, as SetSource is called multip
vabr (Chromium) 2012/07/12 15:13:11 Done.
185 // Returns the next key-value pair as |result|. After SetSource has succeeded,
186 // this allows to iterate over all pairs in the source.
187 // Returns true as long as a new pair was successfully found.
188 virtual bool GetNextPair(Result* result) = 0;
189 // Returns true if there was some data, it was well formed and all was read.
190 virtual bool AllDataReadOK() = 0;
191
192 protected:
193 PostDataParser() {}
battre 2012/07/11 10:59:50 You need to declare a virtual destructor.
vabr (Chromium) 2012/07/12 15:13:11 Done.
194
195 private:
196 DISALLOW_COPY_AND_ASSIGN(PostDataParser);
197 };
198
199 class PostDataParserUrlEncoded : public PostDataParser {
battre 2012/07/11 10:59:50 Can you add a reference to the RFC according to wh
vabr (Chromium) 2012/07/12 15:13:11 This is not covered in a RFC, but it is described
200 public:
201 PostDataParserUrlEncoded() : source_(NULL) {}
202 ~PostDataParserUrlEncoded() {}
battre 2012/07/11 10:59:50 virtual
vabr (Chromium) 2012/07/12 15:13:11 Done.
203 // Implementation of PostDataParser.
204 virtual bool SetSource(const std::vector<char>& source) OVERRIDE;
205 virtual bool GetNextPair(Result* result) OVERRIDE;
206 virtual bool AllDataReadOK() OVERRIDE;
207
208 private:
209 // We parse the first |length_| bytes from |source_|.
battre 2012/07/11 10:59:50 There is no |length_| anymore.
vabr (Chromium) 2012/07/12 15:13:11 Done.
210 const std::vector<char>* source_;
211 std::vector<char>::const_iterator offset_;
212 DISALLOW_COPY_AND_ASSIGN(PostDataParserUrlEncoded);
213 };
214
215 bool PostDataParserUrlEncoded::AllDataReadOK() {
battre 2012/07/11 10:59:50 nit: the function order should match the function
vabr (Chromium) 2012/07/12 15:13:11 Done, converted all to alphabetical order.
216 return source_ != NULL && offset_ == source_->end();
217 }
218
219 bool PostDataParserUrlEncoded::SetSource(const std::vector<char>& source) {
220 if (source_ != NULL)
221 return false;
222 source_ = &source;
223 offset_ = source_->begin();
224 return true;
225 }
226
227 bool PostDataParserUrlEncoded::GetNextPair(Result* result) {
228 if (source_ == NULL)
229 return false;
230 if (offset_ == source_->end())
231 return false;
232 std::vector<char>::const_iterator seek = offset_;
233 // (*) Now we have |seek| >= |offset_| until the end of this function:
234 while (seek != source_->end() && *seek != '=')
235 ++seek;
236 if (seek == source_->end()) {
237 // This means the data is malformed.
238 offset_ = seek;
239 return false;
240 }
241 result->key.set(&(*offset_), seek - offset_); // Safe, see (*).
242 offset_ = ++seek;
243 while (seek != source_->end() && *seek != '&')
244 ++seek;
245 result->val.set(&(*offset_), seek - offset_); // Safe, see (*).
246 offset_ = seek == source_->end() ? seek : seek+1;
battre 2012/07/11 10:59:50 nit: spaces around + opt: I think I would put pare
vabr (Chromium) 2012/07/12 15:13:11 Done.
247 return true;
248 }
249
250 class PostDataParserMultipart : public PostDataParser {
battre 2012/07/11 10:59:50 Can you mention the RFC according to which this pa
vabr (Chromium) 2012/07/12 15:13:11 Done. Yes.
251 public:
252 explicit PostDataParserMultipart(const std::string& boundary)
253 : source_(NULL),
254 boundary_(boundary),
255 state_(kInit) {}
256 ~PostDataParserMultipart() {}
battre 2012/07/11 10:59:50 virtual
vabr (Chromium) 2012/07/12 15:13:11 Done.
257 // Implementation of PostDataParser.
258 virtual bool SetSource(const std::vector<char>& source) OVERRIDE;
259 virtual bool GetNextPair(Result* result) OVERRIDE;
260 virtual bool AllDataReadOK() OVERRIDE;
261
262 private:
263 // Note on implementation:
264 // This parser reads the source line by line. There are four types of lines:
265 // (BOUND) "Boundary" line, separating entries.
266 // (FBOUND) Final "boundary" line, ends the data.
267 // (DISP) "Content-Disposition" line, containing the "key" for |result|.
268 // (EMPTY) empty lines
269 // (OTHER) other non-empty lines
270 enum Lines {kBound, kFBound, kDisp, kEmpty, kOther};
battre 2012/07/11 10:59:50 Can you expand these names? We prefer to have no a
vabr (Chromium) 2012/07/12 15:13:11 Done.
271 // The parser uses the following 7-state automaton to check for structure:
272 // kInit --BOUND--> kFirst, kInit --not(BOUND)--> kError
273 // kFirst --DISP--> kSkip, kFirst --not(DISP)--> kHead
274 // kHead --DISP--> kSkip, kHead --not(DISP)-->kHead
275 // kSkip --EMPTY-->kBody, kSkip --not(EMPTY)--> kSkip
276 // kBody --BOUND--> kFirst, kBody --FBOUND--> kFinal,
277 // kBody --not(BOUND)--> kBody
278 enum States {kInit, kFirst, kHead, kSkip, kBody, kFinal, kError};
279 // Read one more line from |source_|, update line pointers.
280 bool GetNextLine();
281 // Determine the |line_type_| of the current line_.
282 void GetLineType();
283 // One-step of the automaton, based on |state_| and |line_type_|.
284 // This calls GetNextLine() and returns it return value.
285 bool DoStep();
286 // Extracts "key" and possibly "val" from a DISP line. Returns success.
287 bool ParseHead(Result* result);
288 // We parse the first |length_| bytes from |source_|.
289 const char* source_;
290 size_t length_;
291 // Offset of the current and next line from |source_|:
292 // [line_]...line... [line_end_]EOL [next_line_]...line...
293 size_t line_;
294 size_t line_end_;
295 size_t next_line_;
296 const std::string boundary_;
297 States state_;
298 Lines line_type_;
299 DISALLOW_COPY_AND_ASSIGN(PostDataParserMultipart);
300 };
301
302 bool PostDataParserMultipart::AllDataReadOK() {
303 return source_ != NULL && next_line_ >= length_ && state_ == kFinal;
304 }
305
306 bool PostDataParserMultipart::SetSource(const std::vector<char>& source) {
307 if (state_ == kError)
308 return false;
309 if (source_ != NULL && next_line_ < length_)
310 return false;
311 source_ = &(source[0]);
312 length_ = source.size();
313 next_line_ = 0;
314 return true;
315 }
316
317 bool PostDataParserMultipart::GetNextPair(Result* result) {
318 if (state_ == kError)
319 return false;
320 while (state_ != kSkip) {
321 if (!DoStep())
322 return false;
323 }
324 bool name_parsed = ParseHead(result);
325 while (state_ != kBody) {
326 if (!DoStep())
327 return false;
328 }
329 size_t val_start;
330 size_t val_end;
331 // There may not be more to read from |source_| if the current result comes
332 // from a "file" input element. But then |result->val.data()| != NULL already.
333 if (!DoStep())
334 return result->val.data() != NULL;
335 val_start = line_;
336 while (state_ != kFirst && state_ != kFinal) {
337 val_end = line_end_;
338 if (!DoStep()) break;
339 }
340 if (name_parsed && result->val.data() == NULL) {
341 // This pair is from non-file form item, |val| is on subsequent lines.
342 result->val.set(source_ + val_start, val_end - val_start);
343 }
344 return name_parsed;
345 }
346
347 // Contract: only to be called from GetNextLine().
348 void PostDataParserMultipart::GetLineType() {
349 const char* line = source_ + line_;
350 const size_t line_length = line_end_ - line_;
battre 2012/07/11 10:59:50 How about this? StringPiece line = (source_ + lin
vabr (Chromium) 2012/07/12 15:13:11 Done.
351 const bool boundary_test = line[0] == '-' && line[1] == '-' &&
352 strncmp(boundary_.c_str(), line+2, boundary_.size()) == 0;
353 if (boundary_test && line_length == boundary_.size() + 2)
354 line_type_ = kBound;
355 else if (boundary_test && line_length == boundary_.size() + 4 &&
356 line[line_length-2] == '-' && line[line_length-1] == '-')
357 line_type_ = kFBound;
358 else if (strncmp(line, kContentDisposition, strlen(kContentDisposition)) == 0)
359 line_type_ = kDisp;
360 else if (line_ == line_end_)
361 line_type_ = kEmpty;
362 else
363 line_type_ = kOther;
364 }
365
366 // Contract: only to be called from DoStep().
367 bool PostDataParserMultipart::GetNextLine() {
368 if (source_ == NULL || state_ == kError)
369 return false;
370 if (next_line_ >= length_)
371 return false;
372 size_t seek = line_ = next_line_;
battre 2012/07/11 10:59:50 could please you split variable declarations and a
vabr (Chromium) 2012/07/12 15:13:11 Done.
373 while (seek < length_ && *(source_ + seek) != '\r')
374 ++seek;
375 line_end_ = seek;
376 GetLineType();
377 if (seek < length_ && *(source_ + seek + 1) != '\n')
battre 2012/07/11 10:59:50 should this be if (seek + 1 < length_ ...) ?
vabr (Chromium) 2012/07/12 15:13:11 No, it should equal to the first part of the condi
378 return false;
379 next_line_ = seek + 2;
380 return true;
381 }
382
383 bool PostDataParserMultipart::DoStep() {
384 if (!GetNextLine())
385 return false;
386 switch (state_) {
387 case kInit:
388 if (line_type_ == kBound)
389 state_ = kFirst;
390 else
391 state_ = kError;
392 break;
393 case kFirst:
394 if (line_type_ == kDisp)
395 state_ = kSkip;
396 else
397 state_ = kHead;
398 break;
399 case kHead:
400 if (line_type_ == kDisp)
401 state_ = kSkip;
402 break;
403 case kSkip:
404 if (line_type_ == kEmpty)
405 state_ = kBody;
406 break;
407 case kBody:
408 if (line_type_ == kBound)
409 state_ = kFirst;
410 else if (line_type_ == kFBound)
411 state_ = kFinal;
412 break;
413 case kFinal:
414 if (line_type_ != kEmpty)
415 state_ = kError;
416 case kError:
417 break;
418 }
419 return true;
420 }
421
422 // Contract: line_type_ == kDisp.
423 bool PostDataParserMultipart::ParseHead(Result* result) {
battre 2012/07/11 10:59:50 You can verify the contract via DCHECK_EQ(kDisp, l
vabr (Chromium) 2012/07/12 15:13:11 Done.
424 std::string line(source_ + line_, line_end_-line_);
battre 2012/07/11 10:59:50 nit: space around -
vabr (Chromium) 2012/07/12 15:13:11 Done.
425 size_t key_offset = line.find(" name=\"") + 7;
battre 2012/07/11 10:59:50 what happens if find returns std::string::npos?
vabr (Chromium) 2012/07/12 15:13:11 Corrected to: 1. Check against npos. 2. Increment
426 if (key_offset == std::string::npos)
battre 2012/07/11 10:59:50 won't be the case because of the +7
vabr (Chromium) 2012/07/12 15:13:11 Solved, see above.
427 return false;
428 result->key.set(source_ + line_ + key_offset,
429 line.find('"', key_offset) - key_offset);
430 size_t val_offset = line.find(" filename=\"");
431 if (val_offset == std::string::npos) {
432 result->val.set(NULL);
433 } else {
434 val_offset += 11;
435 result->val.set(source_ + line_ + val_offset,
436 line.find('"', val_offset) - val_offset);
437 }
438 return true;
439 }
440
441 // Helps to choose the right POST data parser and takes care of its lifetime.
442 class PostDataParserProxy : public PostDataParser {
battre 2012/07/11 10:59:50 Would it not be simpler to write a scoped_ptr<Post
vabr (Chromium) 2012/07/12 15:13:11 Done.
443 public:
444 PostDataParserProxy() : parser_(NULL) {}
445 ~PostDataParserProxy() {
446 if (parser_ != NULL)
447 delete parser_;
battre 2012/07/11 10:59:50 The better way to do this is using a scoped_ptr
vabr (Chromium) 2012/07/12 15:13:11 Done via replacing the whole parser-proxy thing wi
448 }
449 // Chooses the parser based on content-type of the request. True == success.
450 bool Init(net::URLRequest* request);
451 virtual bool SetSource(const std::vector<char>& source) OVERRIDE;
452 virtual bool GetNextPair(Result* result) OVERRIDE;
453 virtual bool AllDataReadOK() OVERRIDE;
454
455 private:
456 PostDataParser* parser_;
457 DISALLOW_COPY_AND_ASSIGN(PostDataParserProxy);
458 };
459
460 bool PostDataParserProxy::AllDataReadOK() {
461 return parser_ != NULL ? parser_->AllDataReadOK() : false;
462 }
463
464 bool PostDataParserProxy::Init(net::URLRequest* request) {
465 std::string value;
466 const bool found = request->extra_request_headers().GetHeader(
467 "Content-Type", &value);
468 std::string content_type = value.substr(0, value.find(';'));
469 if (!found || content_type == "application/x-www-form-urlencoded") {
470 parser_ = new PostDataParserUrlEncoded();
471 } else if (content_type == "text/plain") {
472 // Unable to parse, may be ambiguous.
473 } else if (content_type == "multipart/form-data") {
474 size_t offset = value.find("boundary=");
475 offset += 9; // 9 == length of "boundary="
476 std::string boundary = value.substr(offset, value.find(';', offset));
477 parser_ = new PostDataParserMultipart(boundary);
478 } else {
479 return false;
480 }
481 return parser_ != NULL;
482 }
483
484 bool PostDataParserProxy::SetSource(const std::vector<char>& source) {
485 return parser_ != NULL ? parser_->SetSource(source) : false;
486 }
487
488 bool PostDataParserProxy::GetNextPair(Result* result) {
489 if (parser_ != NULL)
490 return parser_->GetNextPair(result);
491 else
492 return false;
493 }
494
495 // Takes |dictionary| of <string, list of strings> pairs, and gets the list
496 // for |key|, creating it if necessary.
497 ListValue* GetOrCreateList(DictionaryValue* dictionary,
498 const std::string& key) {
499 ListValue* list = NULL;
500 if (!dictionary->GetList(key, &list)) {
501 list = new ListValue();
502 dictionary->Set(key, list);
503 }
504 return list;
505 }
506
507 // Extracts the POST data from |request| and writes the data into |out|.
508 // This can be expensive, so it's separated from ExtractRequestInfo().
509 // Contract: request->method() == "POST"
510 void ExtractRequestInfoPost(net::URLRequest* request, DictionaryValue* out) {
511 const std::vector<net::UploadData::Element>* elements =
512 request->get_upload()->elements();
513 PostDataParserProxy parser;
514 parser.Init(request);
515 scoped_ptr<DictionaryValue> post_data(new DictionaryValue());
516 std::vector<net::UploadData::Element>::const_iterator element;
517 for (element = elements->begin(); element != elements->end(); ++element) {
518 if (element->type() != net::UploadData::TYPE_BYTES) continue;
519 if (!parser.SetSource(element->bytes())) continue;
520 PostDataParser::Result result;
521 while (parser.GetNextPair(&result)) {
522 GetOrCreateList(post_data.get(), result.key.as_string())->Append(
523 new StringValue(result.val.as_string()));
524 }
525 }
526 if (parser.AllDataReadOK())
527 out->Set(keys::kPostDataKey, post_data.release());
528 }
529
172 // Converts a HttpHeaders dictionary to a |name|, |value| pair. Returns 530 // Converts a HttpHeaders dictionary to a |name|, |value| pair. Returns
173 // true if successful. 531 // true if successful.
174 bool FromHeaderDictionary(const DictionaryValue* header_value, 532 bool FromHeaderDictionary(const DictionaryValue* header_value,
175 std::string* name, 533 std::string* name,
176 std::string* value) { 534 std::string* value) {
177 if (!header_value->GetString(keys::kHeaderNameKey, name)) 535 if (!header_value->GetString(keys::kHeaderNameKey, name))
178 return false; 536 return false;
179 537
180 // We require either a "value" or a "binaryValue" entry. 538 // We require either a "value" or a "binaryValue" entry.
181 if (!(header_value->HasKey(keys::kHeaderValueKey) ^ 539 if (!(header_value->HasKey(keys::kHeaderValueKey) ^
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 return false; 767 return false;
410 768
411 if (str == "requestHeaders") 769 if (str == "requestHeaders")
412 *extra_info_spec |= REQUEST_HEADERS; 770 *extra_info_spec |= REQUEST_HEADERS;
413 else if (str == "responseHeaders") 771 else if (str == "responseHeaders")
414 *extra_info_spec |= RESPONSE_HEADERS; 772 *extra_info_spec |= RESPONSE_HEADERS;
415 else if (str == "blocking") 773 else if (str == "blocking")
416 *extra_info_spec |= BLOCKING; 774 *extra_info_spec |= BLOCKING;
417 else if (str == "asyncBlocking") 775 else if (str == "asyncBlocking")
418 *extra_info_spec |= ASYNC_BLOCKING; 776 *extra_info_spec |= ASYNC_BLOCKING;
777 else if (str == "requestPostData")
778 *extra_info_spec |= REQUEST_POST_DATA;
419 else 779 else
420 return false; 780 return false;
421 781
422 // BLOCKING and ASYNC_BLOCKING are mutually exclusive. 782 // BLOCKING and ASYNC_BLOCKING are mutually exclusive.
423 if ((*extra_info_spec & BLOCKING) && (*extra_info_spec & ASYNC_BLOCKING)) 783 if ((*extra_info_spec & BLOCKING) && (*extra_info_spec & ASYNC_BLOCKING))
424 return false; 784 return false;
425 } 785 }
426 return true; 786 return true;
427 } 787 }
428 788
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 853
494 int extra_info_spec = 0; 854 int extra_info_spec = 0;
495 std::vector<const EventListener*> listeners = 855 std::vector<const EventListener*> listeners =
496 GetMatchingListeners(profile, extension_info_map, keys::kOnBeforeRequest, 856 GetMatchingListeners(profile, extension_info_map, keys::kOnBeforeRequest,
497 request, &extra_info_spec); 857 request, &extra_info_spec);
498 if (!listeners.empty() && 858 if (!listeners.empty() &&
499 !GetAndSetSignaled(request->identifier(), kOnBeforeRequest)) { 859 !GetAndSetSignaled(request->identifier(), kOnBeforeRequest)) {
500 ListValue args; 860 ListValue args;
501 DictionaryValue* dict = new DictionaryValue(); 861 DictionaryValue* dict = new DictionaryValue();
502 ExtractRequestInfo(request, dict); 862 ExtractRequestInfo(request, dict);
863 if (extra_info_spec & ExtraInfoSpec::REQUEST_POST_DATA &&
864 request->method() == "POST")
865 ExtractRequestInfoPost(request, dict);
503 args.Append(dict); 866 args.Append(dict);
504 867
505 initialize_blocked_requests |= 868 initialize_blocked_requests |=
506 DispatchEvent(profile, request, listeners, args); 869 DispatchEvent(profile, request, listeners, args);
507 } 870 }
508 871
509 if (!initialize_blocked_requests) 872 if (!initialize_blocked_requests)
510 return net::OK; // Nobody saw a reason for modifying the request. 873 return net::OK; // Nobody saw a reason for modifying the request.
511 874
512 blocked_requests_[request->identifier()].event = kOnBeforeRequest; 875 blocked_requests_[request->identifier()].event = kOnBeforeRequest;
(...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 } else if ((*it)->name().find("AdBlock") != std::string::npos) { 2131 } else if ((*it)->name().find("AdBlock") != std::string::npos) {
1769 adblock = true; 2132 adblock = true;
1770 } else { 2133 } else {
1771 other = true; 2134 other = true;
1772 } 2135 }
1773 } 2136 }
1774 } 2137 }
1775 2138
1776 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); 2139 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other));
1777 } 2140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698