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

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

Issue 10012004: Implemented proper support for checking schemes and requested resource types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renamed 'scheme' to 'schemes' Created 8 years, 8 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_CONDITIO N_ATTRIBUTE_H_ 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_ 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITIO N_ATTRIBUTE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/memory/linked_ptr.h" 13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_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/common/extensions/api/experimental.declarative.h" 16 #include "chrome/common/extensions/api/experimental.declarative.h"
17 #include "webkit/glue/resource_type.h"
17 18
18 namespace base { 19 namespace base {
19 class Value; 20 class Value;
20 } 21 }
21 22
22 namespace net { 23 namespace net {
23 class URLRequest; 24 class URLRequest;
24 } 25 }
25 26
26 namespace extensions { 27 namespace extensions {
27 28
28 // Base class for all condition attributes of the declarative Web Request API 29 // Base class for all condition attributes of the declarative Web Request API
29 // except for condition attribute to test URLPatterns. 30 // except for condition attribute to test URLPatterns.
30 class WebRequestConditionAttribute { 31 class WebRequestConditionAttribute {
31 public: 32 public:
32 enum Type { 33 enum Type {
33 CONDITION_HAS_SCHEME 34 CONDITION_RESOURCE_TYPE
34 }; 35 };
35 36
36 WebRequestConditionAttribute(); 37 WebRequestConditionAttribute();
37 virtual ~WebRequestConditionAttribute(); 38 virtual ~WebRequestConditionAttribute();
38 39
39 // Factory method that creates a WebRequestConditionAttribute for the JSON 40 // Factory method that creates a WebRequestConditionAttribute for the JSON
40 // dictionary {|name|: |value|} passed by the extension API. Sets |error| and 41 // dictionary {|name|: |value|} passed by the extension API. Sets |error| and
41 // returns NULL if something fails. 42 // returns NULL if something fails.
42 // The ownership of |value| remains at the caller. 43 // The ownership of |value| remains at the caller.
43 static scoped_ptr<WebRequestConditionAttribute> Create( 44 static scoped_ptr<WebRequestConditionAttribute> Create(
(...skipping 20 matching lines...) Expand all
64 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttribute); 65 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttribute);
65 }; 66 };
66 67
67 typedef std::vector<linked_ptr<WebRequestConditionAttribute> > 68 typedef std::vector<linked_ptr<WebRequestConditionAttribute> >
68 WebRequestConditionAttributes; 69 WebRequestConditionAttributes;
69 70
70 // 71 //
71 // The following are concrete condition attributes. 72 // The following are concrete condition attributes.
72 // 73 //
73 74
74 // Condition that checks whether a URL has a specific scheme. 75 // Condition that checks whether a request is for a specific resource type.
75 // TODO(battre): Generalize this to allow checking for multiple schemes. 76 class WebRequestConditionAttributeResourceType
76 // TODO(battre): Alternatively, move the scheme check into the URLMatcher.
77 class WebRequestConditionAttributeHasScheme
78 : public WebRequestConditionAttribute { 77 : public WebRequestConditionAttribute {
79 public: 78 public:
80 virtual ~WebRequestConditionAttributeHasScheme(); 79 virtual ~WebRequestConditionAttributeResourceType();
81 80
82 static bool IsMatchingType(const std::string& instance_type); 81 static bool IsMatchingType(const std::string& instance_type);
83 82
84 // Factory method, see WebRequestConditionAttribute::Create. 83 // Factory method, see WebRequestConditionAttribute::Create.
85 static scoped_ptr<WebRequestConditionAttribute> Create( 84 static scoped_ptr<WebRequestConditionAttribute> Create(
86 const std::string& name, 85 const std::string& name,
87 const base::Value* value, 86 const base::Value* value,
88 std::string* error); 87 std::string* error);
89 88
90 // Implementation of WebRequestConditionAttribute: 89 // Implementation of WebRequestConditionAttribute:
91 virtual int GetStages() const OVERRIDE; 90 virtual int GetStages() const OVERRIDE;
92 virtual bool IsFulfilled(net::URLRequest* request, 91 virtual bool IsFulfilled(net::URLRequest* request,
93 RequestStages request_stage) OVERRIDE; 92 RequestStages request_stage) OVERRIDE;
94 virtual Type GetType() const OVERRIDE; 93 virtual Type GetType() const OVERRIDE;
95 94
96 private: 95 private:
97 explicit WebRequestConditionAttributeHasScheme(const std::string& pattern); 96 explicit WebRequestConditionAttributeResourceType(
97 const std::vector<ResourceType::Type>& types);
98 98
99 std::string pattern_; 99 std::vector<ResourceType::Type> types_;
100 100
101 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeHasScheme); 101 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeResourceType);
102 }; 102 };
103 103
104 } // namespace extensions 104 } // namespace extensions
105 105
106 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_ATTRIBUTE_H_ 106 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_ATTRIBUTE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698