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

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

Issue 10826120: Migrate WebRequestRedirectByRegExAction to use RE2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | 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 7
8 #include <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/linked_ptr.h" 13 #include "base/memory/linked_ptr.h"
14 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h" 14 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h"
15 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h " 15 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h "
16 #include "chrome/common/extensions/api/events.h" 16 #include "chrome/common/extensions/api/events.h"
17 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
18 #include "unicode/regex.h"
19 18
20 class WebRequestPermission; 19 class WebRequestPermission;
21 20
22 namespace base { 21 namespace base {
23 class DictionaryValue; 22 class DictionaryValue;
24 class Time; 23 class Time;
25 class Value; 24 class Value;
26 } 25 }
27 26
28 namespace extension_web_request_api_helpers { 27 namespace extension_web_request_api_helpers {
29 struct EventResponseDelta; 28 struct EventResponseDelta;
30 } 29 }
31 30
32 namespace extensions { 31 namespace extensions {
33 class Extension; 32 class Extension;
34 } 33 }
35 34
36 namespace net { 35 namespace net {
37 class URLRequest; 36 class URLRequest;
38 } 37 }
39 38
39 namespace re2 {
40 class RE2;
41 }
42
40 namespace extensions { 43 namespace extensions {
41 44
42 typedef linked_ptr<extension_web_request_api_helpers::EventResponseDelta> 45 typedef linked_ptr<extension_web_request_api_helpers::EventResponseDelta>
43 LinkedPtrEventResponseDelta; 46 LinkedPtrEventResponseDelta;
44 47
45 // Base class for all WebRequestActions of the declarative Web Request API. 48 // Base class for all WebRequestActions of the declarative Web Request API.
46 // 49 //
47 class WebRequestAction { 50 class WebRequestAction {
48 public: 51 public:
49 // Type identifiers for concrete WebRequestActions. 52 // Type identifiers for concrete WebRequestActions.
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 const std::string& extension_id, 242 const std::string& extension_id,
240 const base::Time& extension_install_time) const OVERRIDE; 243 const base::Time& extension_install_time) const OVERRIDE;
241 244
242 private: 245 private:
243 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToEmptyDocumentAction); 246 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToEmptyDocumentAction);
244 }; 247 };
245 248
246 // Action that instructs to redirect a network request. 249 // Action that instructs to redirect a network request.
247 class WebRequestRedirectByRegExAction : public WebRequestAction { 250 class WebRequestRedirectByRegExAction : public WebRequestAction {
248 public: 251 public:
249 // The |to_pattern| has to be passed in ICU syntax. 252 // The |to_pattern| has to be passed in RE2 syntax with the exception that
250 // TODO(battre): Change this to Perl style when migrated to RE2. 253 // capture groups are referenced in Perl style ($1, $2, ...).
251 explicit WebRequestRedirectByRegExAction( 254 WebRequestRedirectByRegExAction(scoped_ptr<re2::RE2> from_pattern,
252 scoped_ptr<icu::RegexPattern> from_pattern, 255 const std::string& to_pattern);
253 const std::string& to_pattern);
254 virtual ~WebRequestRedirectByRegExAction(); 256 virtual ~WebRequestRedirectByRegExAction();
255 257
256 // Conversion of capture group styles between Perl style ($1, $2, ...) and 258 // Conversion of capture group styles between Perl style ($1, $2, ...) and
257 // RE2 (\1, \2, ...). 259 // RE2 (\1, \2, ...).
258 static std::string PerlToRe2Style(const std::string& perl); 260 static std::string PerlToRe2Style(const std::string& perl);
259 261
260 // Implementation of WebRequestAction: 262 // Implementation of WebRequestAction:
261 virtual int GetStages() const OVERRIDE; 263 virtual int GetStages() const OVERRIDE;
262 virtual Type GetType() const OVERRIDE; 264 virtual Type GetType() const OVERRIDE;
263 virtual LinkedPtrEventResponseDelta CreateDelta( 265 virtual LinkedPtrEventResponseDelta CreateDelta(
264 net::URLRequest* request, 266 net::URLRequest* request,
265 RequestStages request_stage, 267 RequestStages request_stage,
266 const WebRequestRule::OptionalRequestData& optional_request_data, 268 const WebRequestRule::OptionalRequestData& optional_request_data,
267 const std::string& extension_id, 269 const std::string& extension_id,
268 const base::Time& extension_install_time) const OVERRIDE; 270 const base::Time& extension_install_time) const OVERRIDE;
269 271
270 private: 272 private:
271 scoped_ptr<icu::RegexPattern> from_pattern_; 273 scoped_ptr<re2::RE2> from_pattern_;
272 icu::UnicodeString to_pattern_; 274 std::string to_pattern_;
273 275
274 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectByRegExAction); 276 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectByRegExAction);
275 }; 277 };
276 278
277 // Action that instructs to set a request header. 279 // Action that instructs to set a request header.
278 class WebRequestSetRequestHeaderAction : public WebRequestAction { 280 class WebRequestSetRequestHeaderAction : public WebRequestAction {
279 public: 281 public:
280 WebRequestSetRequestHeaderAction(const std::string& name, 282 WebRequestSetRequestHeaderAction(const std::string& name,
281 const std::string& value); 283 const std::string& value);
282 virtual ~WebRequestSetRequestHeaderAction(); 284 virtual ~WebRequestSetRequestHeaderAction();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 int minimum_priority_; 390 int minimum_priority_;
389 DISALLOW_COPY_AND_ASSIGN(WebRequestIgnoreRulesAction); 391 DISALLOW_COPY_AND_ASSIGN(WebRequestIgnoreRulesAction);
390 }; 392 };
391 393
392 // TODO(battre) Implement further actions: 394 // TODO(battre) Implement further actions:
393 // Redirect by RegEx, Cookie manipulations, ... 395 // Redirect by RegEx, Cookie manipulations, ...
394 396
395 } // namespace extensions 397 } // namespace extensions
396 398
397 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTIO N_H_ 399 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTIO N_H_
OLDNEW
« no previous file with comments | « chrome/browser/DEPS ('k') | chrome/browser/extensions/api/declarative_webrequest/webrequest_action.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698