Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITIO N_ATTRIBUTE_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITIO N_ATTRIBUTE_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/memory/linked_ptr.h" | |
| 14 #include "tools/json_schema_compiler/any.h" | |
| 15 | |
| 16 namespace net { | |
| 17 class URLRequest; | |
| 18 } | |
| 19 | |
| 20 namespace extensions { | |
| 21 namespace declarative_webrequest { | |
| 22 | |
| 23 // Base class for all condition attributes of the declarative Web Request API | |
| 24 // except for condition attribute to test URLPatterns. | |
| 25 class WebRequestConditionAttribute { | |
| 26 public: | |
| 27 enum Types { | |
| 28 CONDITION_HAS_SCHEME | |
| 29 }; | |
| 30 | |
| 31 WebRequestConditionAttribute(); | |
| 32 virtual ~WebRequestConditionAttribute(); | |
| 33 | |
| 34 // Returns a bit vector representing extensions::RequestStages. The bit vector | |
| 35 // contains a 1 for each request stage during which the condition attribute | |
| 36 // can be tested. | |
| 37 virtual int GetStages() const = 0; | |
| 38 | |
| 39 // Returns whether the condition is fulfilled for this request. | |
| 40 virtual bool IsFulfilled(net::URLRequest* request) = 0; | |
| 41 | |
| 42 virtual Types type() const = 0; | |
| 43 | |
| 44 private: | |
| 45 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttribute); | |
| 46 }; | |
| 47 | |
| 48 typedef std::vector<linked_ptr<WebRequestConditionAttribute> > | |
| 49 WebRequestConditionAttributes; | |
| 50 | |
| 51 class WebRequestConditionAttributeFactory { | |
| 52 public: | |
| 53 // Returns whether conditions of type |instance_type| are handled by this | |
| 54 // factory. | |
| 55 static bool IsHandledByThisFactory(const std::string& instance_type); | |
| 56 | |
| 57 // Creates a WebRequestConditionAttribute for the JSON dictionary | |
| 58 // {|name|: |value|}. Sets |error| and returns NULL if something fails. | |
| 59 // The ownership of |value| remains at the caller. | |
| 60 static scoped_ptr<WebRequestConditionAttribute> Create( | |
| 61 const std::string& name, | |
| 62 const base::Value* value, | |
| 63 std::string* error); | |
| 64 | |
| 65 private: | |
| 66 DISALLOW_IMPLICIT_CONSTRUCTORS(WebRequestConditionAttributeFactory); | |
| 67 }; | |
| 68 | |
| 69 // | |
| 70 // The following are concrete conditions | |
| 71 // | |
| 72 | |
| 73 // Condition that checks whether a URL has a specific scheme. | |
| 74 // TODO(battre): Generalize this to allow checking for multiple schemes. | |
| 75 class WebRequestConditionAttributeHasScheme | |
|
Matt Perry
2012/03/22 23:07:25
I'm still convinced this doesn't belong here. Can
battre
2012/03/26 18:35:51
The reason for having this here was flexibility, i
Matt Perry
2012/03/26 19:11:06
I see. The main thing bothering me here is that th
battre
2012/03/26 20:38:10
We can improve this, but I suggest to do it in two
| |
| 76 : public WebRequestConditionAttribute { | |
| 77 public: | |
| 78 virtual ~WebRequestConditionAttributeHasScheme(); | |
| 79 | |
| 80 static bool IsMatchingType(const std::string& instance_type); | |
| 81 | |
| 82 static scoped_ptr<WebRequestConditionAttribute> Create( | |
| 83 const std::string& name, | |
| 84 const base::Value* value, | |
| 85 std::string* error); | |
| 86 | |
| 87 virtual int GetStages() const OVERRIDE; | |
| 88 virtual bool IsFulfilled(net::URLRequest* request) OVERRIDE; | |
| 89 virtual Types type() const OVERRIDE { return CONDITION_HAS_SCHEME; } | |
| 90 | |
| 91 private: | |
| 92 explicit WebRequestConditionAttributeHasScheme(const std::string& pattern); | |
| 93 std::string pattern_; | |
| 94 | |
| 95 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeHasScheme); | |
| 96 }; | |
| 97 | |
| 98 } // namespace declarative_webrequest | |
| 99 } // namespace extensions | |
| 100 | |
| 101 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_ATTRIBUTE_H_ | |
| OLD | NEW |