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

Side by Side Diff: chrome/browser/extensions/api/declarative/rules_registry.h

Issue 28273006: <webview>: Implement declarativeWebRequest API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests Created 7 years, 1 month 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
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_RULES_REGISTRY_H__ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__ 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/linked_ptr.h" 11 #include "base/memory/linked_ptr.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "chrome/common/extensions/api/events.h" 13 #include "chrome/common/extensions/api/events.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 15
16 namespace base { 16 namespace base {
17 class DictionaryValue; 17 class DictionaryValue;
18 } 18 }
19 19
20 namespace extensions { 20 namespace extensions {
21 21
22 class RulesRegistry;
23
24 // Interface for rule registries. 22 // Interface for rule registries.
25 // 23 //
26 // All functions except GetOwnerThread() and the destructor are only called on 24 // All functions except GetOwnerThread() and the destructor are only called on
27 // the thread indicated by GetOwnerThread(). 25 // the thread indicated by GetOwnerThread().
28 class RulesRegistry : public base::RefCountedThreadSafe<RulesRegistry> { 26 class RulesRegistry : public base::RefCountedThreadSafe<RulesRegistry> {
29 public: 27 public:
30 typedef extensions::api::events::Rule Rule; 28 typedef extensions::api::events::Rule Rule;
29 typedef std::pair<int, int> WebViewKey;
31 30
32 RulesRegistry(content::BrowserThread::ID owner_thread, 31 RulesRegistry(content::BrowserThread::ID owner_thread,
33 const std::string& event_name) 32 const std::string& event_name,
34 : owner_thread_(owner_thread), event_name_(event_name) {} 33 const WebViewKey& webview_key);
35 34
36 // Registers |rules|, owned by |extension_id| to this RulesRegistry. 35 // Registers |rules|, owned by |extension_id| to this RulesRegistry.
37 // If a concrete RuleRegistry does not support some of the rules, 36 // If a concrete RuleRegistry does not support some of the rules,
38 // it may ignore them. 37 // it may ignore them.
39 // 38 //
40 // |rules| is a list of Rule instances following the definition of the 39 // |rules| is a list of Rule instances following the definition of the
41 // declarative extension APIs. It is guaranteed that each rule in |rules| has 40 // declarative extension APIs. It is guaranteed that each rule in |rules| has
42 // a unique name within the scope of |extension_id| that has not been 41 // a unique name within the scope of |extension_id| that has not been
43 // registered before, unless it has been removed again. 42 // registered before, unless it has been removed again.
44 // The ownership of rules remains with the caller. 43 // The ownership of rules remains with the caller.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // and all rules of this extension need to be removed. 88 // and all rules of this extension need to be removed.
90 virtual void OnExtensionUnloaded(const std::string& extension_id) = 0; 89 virtual void OnExtensionUnloaded(const std::string& extension_id) = 0;
91 90
92 // Returns the ID of the thread on which the rules registry lives. 91 // Returns the ID of the thread on which the rules registry lives.
93 // It is safe to call this function from any thread. 92 // It is safe to call this function from any thread.
94 content::BrowserThread::ID owner_thread() const { return owner_thread_; } 93 content::BrowserThread::ID owner_thread() const { return owner_thread_; }
95 94
96 // The name of the event with which rules are registered. 95 // The name of the event with which rules are registered.
97 const std::string& event_name() const { return event_name_; } 96 const std::string& event_name() const { return event_name_; }
98 97
98 // The key that identifies the webview (or tabs) in which these rules apply.
99 const WebViewKey& webview_key() const {
100 return webview_key_;
101 }
102
99 protected: 103 protected:
100 virtual ~RulesRegistry() {} 104 virtual ~RulesRegistry();
101 105
102 private: 106 private:
103 friend class base::RefCountedThreadSafe<RulesRegistry>; 107 friend class base::RefCountedThreadSafe<RulesRegistry>;
104 108
105 // The ID of the thread on which the rules registry lives. 109 // The ID of the thread on which the rules registry lives.
106 const content::BrowserThread::ID owner_thread_; 110 const content::BrowserThread::ID owner_thread_;
107 111
108 // The name of the event with which rules are registered. 112 // The name of the event with which rules are registered.
109 const std::string event_name_; 113 const std::string event_name_;
110 114
115 // The key that identifies the context in which these rules apply.
116 WebViewKey webview_key_;
117
111 DISALLOW_COPY_AND_ASSIGN(RulesRegistry); 118 DISALLOW_COPY_AND_ASSIGN(RulesRegistry);
112 }; 119 };
113 120
114 } // namespace extensions 121 } // namespace extensions
115 122
116 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__ 123 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698