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

Side by Side Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_action.h

Issue 10449069: Support redirects by regular expression in declarative WebRequest API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 6 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 | Annotate | Revision Log
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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTION_H _ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTION_H _
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTION_H _ 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTION_H _
7 #pragma once 7 #pragma once
8 8
9 #include <list> 9 #include <list>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/memory/linked_ptr.h" 14 #include "base/memory/linked_ptr.h"
15 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h" 15 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h"
16 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h " 16 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h "
17 #include "chrome/common/extensions/api/events.h" 17 #include "chrome/common/extensions/api/events.h"
18 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
19 #include "unicode/regex.h"
19 20
20 namespace base { 21 namespace base {
21 class DictionaryValue; 22 class DictionaryValue;
22 class Time; 23 class Time;
23 class Value; 24 class Value;
24 } 25 }
25 26
26 namespace extension_web_request_api_helpers { 27 namespace extension_web_request_api_helpers {
27 struct EventResponseDelta; 28 struct EventResponseDelta;
28 } 29 }
(...skipping 11 matching lines...) Expand all
40 // 41 //
41 // TODO(battre): Add method that corresponds to executing the action. 42 // TODO(battre): Add method that corresponds to executing the action.
42 class WebRequestAction { 43 class WebRequestAction {
43 public: 44 public:
44 // Type identifiers for concrete WebRequestActions. 45 // Type identifiers for concrete WebRequestActions.
45 enum Type { 46 enum Type {
46 ACTION_CANCEL_REQUEST, 47 ACTION_CANCEL_REQUEST,
47 ACTION_REDIRECT_REQUEST, 48 ACTION_REDIRECT_REQUEST,
48 ACTION_REDIRECT_TO_TRANSPARENT_IMAGE, 49 ACTION_REDIRECT_TO_TRANSPARENT_IMAGE,
49 ACTION_REDIRECT_TO_EMPTY_DOCUMENT, 50 ACTION_REDIRECT_TO_EMPTY_DOCUMENT,
51 ACTION_REDIRECT_BY_REGEX_DOCUMENT,
50 ACTION_SET_REQUEST_HEADER, 52 ACTION_SET_REQUEST_HEADER,
51 ACTION_REMOVE_REQUEST_HEADER, 53 ACTION_REMOVE_REQUEST_HEADER,
52 ACTION_ADD_RESPONSE_HEADER, 54 ACTION_ADD_RESPONSE_HEADER,
53 ACTION_REMOVE_RESPONSE_HEADER, 55 ACTION_REMOVE_RESPONSE_HEADER,
54 ACTION_IGNORE_RULES, 56 ACTION_IGNORE_RULES,
55 }; 57 };
56 58
57 WebRequestAction(); 59 WebRequestAction();
58 virtual ~WebRequestAction(); 60 virtual ~WebRequestAction();
59 61
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 net::URLRequest* request, 211 net::URLRequest* request,
210 RequestStages request_stage, 212 RequestStages request_stage,
211 const WebRequestRule::OptionalRequestData& optional_request_data, 213 const WebRequestRule::OptionalRequestData& optional_request_data,
212 const std::string& extension_id, 214 const std::string& extension_id,
213 const base::Time& extension_install_time) const OVERRIDE; 215 const base::Time& extension_install_time) const OVERRIDE;
214 216
215 private: 217 private:
216 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToEmptyDocumentAction); 218 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToEmptyDocumentAction);
217 }; 219 };
218 220
221 // Action that instructs to redirect a network request.
222 class WebRequestRedirectByRegExAction : public WebRequestAction {
223 public:
224 // The |to_pattern| has to be passed in ICU syntax.
225 // TODO(battre): Change this to Perl style when migrated to RE2.
226 explicit WebRequestRedirectByRegExAction(
227 scoped_ptr<icu::RegexPattern> from_pattern,
228 const std::string& to_pattern);
229 virtual ~WebRequestRedirectByRegExAction();
230
231 // Conversion of capture group styles between Perl style ($1, $2, ...) and
232 // RE2 (\1, \2, ...).
233 static std::string PerlToRe2Style(const std::string& perl);
234
235 // Implementation of WebRequestAction:
236 virtual int GetStages() const OVERRIDE;
237 virtual Type GetType() const OVERRIDE;
238 virtual LinkedPtrEventResponseDelta CreateDelta(
239 net::URLRequest* request,
240 RequestStages request_stage,
241 const WebRequestRule::OptionalRequestData& optional_request_data,
242 const std::string& extension_id,
243 const base::Time& extension_install_time) const OVERRIDE;
244
245 private:
246 scoped_ptr<icu::RegexPattern> from_pattern_;
247 icu::UnicodeString to_pattern_;
248
249 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectByRegExAction);
250 };
251
219 // Action that instructs to set a request header. 252 // Action that instructs to set a request header.
220 class WebRequestSetRequestHeaderAction : public WebRequestAction { 253 class WebRequestSetRequestHeaderAction : public WebRequestAction {
221 public: 254 public:
222 WebRequestSetRequestHeaderAction(const std::string& name, 255 WebRequestSetRequestHeaderAction(const std::string& name,
223 const std::string& value); 256 const std::string& value);
224 virtual ~WebRequestSetRequestHeaderAction(); 257 virtual ~WebRequestSetRequestHeaderAction();
225 258
226 // Implementation of WebRequestAction: 259 // Implementation of WebRequestAction:
227 virtual int GetStages() const OVERRIDE; 260 virtual int GetStages() const OVERRIDE;
228 virtual Type GetType() const OVERRIDE; 261 virtual Type GetType() const OVERRIDE;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 int minimum_priority_; 362 int minimum_priority_;
330 DISALLOW_COPY_AND_ASSIGN(WebRequestIgnoreRulesAction); 363 DISALLOW_COPY_AND_ASSIGN(WebRequestIgnoreRulesAction);
331 }; 364 };
332 365
333 // TODO(battre) Implement further actions: 366 // TODO(battre) Implement further actions:
334 // Redirect by RegEx, Cookie manipulations, ... 367 // Redirect by RegEx, Cookie manipulations, ...
335 368
336 } // namespace extensions 369 } // namespace extensions
337 370
338 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTIO N_H_ 371 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTIO N_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698