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 "base/memory/scoped_ptr.h" |
| 15 #include "tools/json_schema_compiler/any.h" |
| 16 |
| 17 namespace base{ |
| 18 class Value; |
| 19 } |
| 20 |
| 21 namespace net { |
| 22 class URLRequest; |
| 23 } |
| 24 |
| 25 namespace extensions { |
| 26 |
| 27 // Base class for all condition attributes of the declarative Web Request API |
| 28 // except for condition attribute to test URLPatterns. |
| 29 class WebRequestConditionAttribute { |
| 30 public: |
| 31 enum Type { |
| 32 CONDITION_HAS_SCHEME |
| 33 }; |
| 34 |
| 35 WebRequestConditionAttribute(); |
| 36 virtual ~WebRequestConditionAttribute(); |
| 37 |
| 38 // Factory method that creates a WebRequestConditionAttribute for the JSON |
| 39 // dictionary {|name|: |value|} passed by the extension API. Sets |error| and |
| 40 // returns NULL if something fails. |
| 41 // The ownership of |value| remains at the caller. |
| 42 static scoped_ptr<WebRequestConditionAttribute> Create( |
| 43 const std::string& name, |
| 44 const base::Value* value, |
| 45 std::string* error); |
| 46 |
| 47 // Returns a bit vector representing extensions::RequestStages. The bit vector |
| 48 // contains a 1 for each request stage during which the condition attribute |
| 49 // can be tested. |
| 50 virtual int GetStages() const = 0; |
| 51 |
| 52 // Returns whether the condition is fulfilled for this request. |
| 53 virtual bool IsFulfilled(net::URLRequest* request) = 0; |
| 54 |
| 55 virtual Type GetType() const = 0; |
| 56 |
| 57 // Returns whether condition attributes of type |instance_type| are known |
| 58 // and can be instantiated by Create(). |
| 59 static bool IsKnownType(const std::string& instance_type); |
| 60 |
| 61 private: |
| 62 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttribute); |
| 63 }; |
| 64 |
| 65 typedef std::vector<linked_ptr<WebRequestConditionAttribute> > |
| 66 WebRequestConditionAttributes; |
| 67 |
| 68 // |
| 69 // The following are concrete condition attributes. |
| 70 // |
| 71 |
| 72 // Condition that checks whether a URL has a specific scheme. |
| 73 // TODO(battre): Generalize this to allow checking for multiple schemes. |
| 74 // TODO(battre): Alternatively, move the scheme check into the URLMatcher. |
| 75 class WebRequestConditionAttributeHasScheme |
| 76 : public WebRequestConditionAttribute { |
| 77 public: |
| 78 virtual ~WebRequestConditionAttributeHasScheme(); |
| 79 |
| 80 static bool IsMatchingType(const std::string& instance_type); |
| 81 |
| 82 // Factory method, see WebRequestConditionAttribute::Create. |
| 83 static scoped_ptr<WebRequestConditionAttribute> Create( |
| 84 const std::string& name, |
| 85 const base::Value* value, |
| 86 std::string* error); |
| 87 |
| 88 // Implementation of WebRequestConditionAttribute: |
| 89 virtual int GetStages() const OVERRIDE; |
| 90 virtual bool IsFulfilled(net::URLRequest* request) OVERRIDE; |
| 91 virtual Type GetType() const OVERRIDE; |
| 92 |
| 93 private: |
| 94 explicit WebRequestConditionAttributeHasScheme(const std::string& pattern); |
| 95 |
| 96 std::string pattern_; |
| 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeHasScheme); |
| 99 }; |
| 100 |
| 101 } // namespace extensions |
| 102 |
| 103 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI
TION_ATTRIBUTE_H_ |
OLD | NEW |