Chromium Code Reviews| Index: chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h | 
| diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..8a41b48f6ace86db07cadd0f0a5ef432223ed923 | 
| --- /dev/null | 
| +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h | 
| @@ -0,0 +1,101 @@ | 
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_ATTRIBUTE_H_ | 
| +#define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_ATTRIBUTE_H_ | 
| +#pragma once | 
| + | 
| +#include <string> | 
| +#include <vector> | 
| + | 
| +#include "base/basictypes.h" | 
| +#include "base/memory/linked_ptr.h" | 
| +#include "tools/json_schema_compiler/any.h" | 
| + | 
| +namespace net { | 
| +class URLRequest; | 
| +} | 
| + | 
| +namespace extensions { | 
| +namespace declarative_webrequest { | 
| + | 
| +// Base class for all condition attributes of the declarative Web Request API | 
| +// except for condition attribute to test URLPatterns. | 
| +class WebRequestConditionAttribute { | 
| + public: | 
| + enum Types { | 
| + CONDITION_HAS_SCHEME | 
| + }; | 
| + | 
| + WebRequestConditionAttribute(); | 
| + virtual ~WebRequestConditionAttribute(); | 
| + | 
| + // Returns a bit vector representing extensions::RequestStages. The bit vector | 
| + // contains a 1 for each request stage during which the condition attribute | 
| + // can be tested. | 
| + virtual int GetStages() const = 0; | 
| + | 
| + // Returns whether the condition is fulfilled for this request. | 
| + virtual bool IsFulfilled(net::URLRequest* request) = 0; | 
| + | 
| + virtual Types type() const = 0; | 
| + | 
| + private: | 
| + DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttribute); | 
| +}; | 
| + | 
| +typedef std::vector<linked_ptr<WebRequestConditionAttribute> > | 
| + WebRequestConditionAttributes; | 
| + | 
| +class WebRequestConditionAttributeFactory { | 
| + public: | 
| + // Returns whether conditions of type |instance_type| are handled by this | 
| + // factory. | 
| + static bool IsHandledByThisFactory(const std::string& instance_type); | 
| + | 
| + // Creates a WebRequestConditionAttribute for the JSON dictionary | 
| + // {|name|: |value|}. Sets |error| and returns NULL if something fails. | 
| + // The ownership of |value| remains at the caller. | 
| + static scoped_ptr<WebRequestConditionAttribute> Create( | 
| + const std::string& name, | 
| + const base::Value* value, | 
| + std::string* error); | 
| + | 
| + private: | 
| + DISALLOW_IMPLICIT_CONSTRUCTORS(WebRequestConditionAttributeFactory); | 
| +}; | 
| + | 
| +// | 
| +// The following are concrete conditions | 
| +// | 
| + | 
| +// Condition that checks whether a URL has a specific scheme. | 
| +// TODO(battre): Generalize this to allow checking for multiple schemes. | 
| +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
 
 | 
| + : public WebRequestConditionAttribute { | 
| + public: | 
| + virtual ~WebRequestConditionAttributeHasScheme(); | 
| + | 
| + static bool IsMatchingType(const std::string& instance_type); | 
| + | 
| + static scoped_ptr<WebRequestConditionAttribute> Create( | 
| + const std::string& name, | 
| + const base::Value* value, | 
| + std::string* error); | 
| + | 
| + virtual int GetStages() const OVERRIDE; | 
| + virtual bool IsFulfilled(net::URLRequest* request) OVERRIDE; | 
| + virtual Types type() const OVERRIDE { return CONDITION_HAS_SCHEME; } | 
| + | 
| + private: | 
| + explicit WebRequestConditionAttributeHasScheme(const std::string& pattern); | 
| + std::string pattern_; | 
| + | 
| + DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeHasScheme); | 
| +}; | 
| + | 
| +} // namespace declarative_webrequest | 
| +} // namespace extensions | 
| + | 
| +#endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_ATTRIBUTE_H_ |