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

Side by Side Diff: chrome/common/extensions/extension_set.h

Issue 10375021: Move Extension into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Take 6 Created 8 years, 7 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
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_COMMON_EXTENSIONS_EXTENSION_SET_H_ 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_ 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_
7 #pragma once 7 #pragma once
8 8
9 #include <iterator> 9 #include <iterator>
10 #include <map> 10 #include <map>
(...skipping 23 matching lines...) Expand all
34 const GURL& url() const { return url_; } 34 const GURL& url() const { return url_; }
35 35
36 private: 36 private:
37 WebKit::WebSecurityOrigin origin_; 37 WebKit::WebSecurityOrigin origin_;
38 GURL url_; 38 GURL url_;
39 }; 39 };
40 40
41 // The one true extension container. Extensions are identified by their id. 41 // The one true extension container. Extensions are identified by their id.
42 // Only one extension can be in the set with a given ID. 42 // Only one extension can be in the set with a given ID.
43 class ExtensionSet { 43 class ExtensionSet {
44 public: 44 public:
45 typedef std::pair<FilePath, std::string> ExtensionPathAndDefaultLocale; 45 typedef std::pair<FilePath, std::string> ExtensionPathAndDefaultLocale;
46 typedef std::map<std::string, scoped_refptr<const Extension> > ExtensionMap; 46 typedef std::map<std::string, scoped_refptr<const extensions::Extension> >
47 ExtensionMap;
47 48
48 // Iteration over the values of the map (given that it's an ExtensionSet, 49 // Iteration over the values of the map (given that it's an ExtensionSet,
49 // it should iterate like a set iterator). 50 // it should iterate like a set iterator).
50 class const_iterator : 51 class const_iterator :
51 public std::iterator<std::input_iterator_tag, 52 public std::iterator<std::input_iterator_tag,
52 scoped_refptr<const Extension> > { 53 scoped_refptr<const extensions::Extension> > {
53 public: 54 public:
54 const_iterator() {} 55 const_iterator() {}
55 explicit const_iterator(ExtensionMap::const_iterator it) : 56 explicit const_iterator(ExtensionMap::const_iterator it) :
56 it_(it) {} 57 it_(it) {}
57 const_iterator& operator++() { 58 const_iterator& operator++() {
58 ++it_; 59 ++it_;
59 return *this; 60 return *this;
60 } 61 }
61 const scoped_refptr<const Extension> operator*() { 62 const scoped_refptr<const extensions::Extension> operator*() {
62 return it_->second; 63 return it_->second;
63 } 64 }
64 bool operator!=(const const_iterator& other) { return it_ != other.it_; } 65 bool operator!=(const const_iterator& other) { return it_ != other.it_; }
65 bool operator==(const const_iterator& other) { return it_ == other.it_; } 66 bool operator==(const const_iterator& other) { return it_ == other.it_; }
66 67
67 private: 68 private:
68 ExtensionMap::const_iterator it_; 69 ExtensionMap::const_iterator it_;
69 }; 70 };
70 71
71 ExtensionSet(); 72 ExtensionSet();
72 ~ExtensionSet(); 73 ~ExtensionSet();
73 74
74 size_t size() const; 75 size_t size() const;
75 bool is_empty() const; 76 bool is_empty() const;
76 77
77 // Iteration support. 78 // Iteration support.
78 const_iterator begin() const { return const_iterator(extensions_.begin()); } 79 const_iterator begin() const { return const_iterator(extensions_.begin()); }
79 const_iterator end() const { return const_iterator(extensions_.end()); } 80 const_iterator end() const { return const_iterator(extensions_.end()); }
80 81
81 // Returns true if the set contains the specified extension. 82 // Returns true if the set contains the specified extension.
82 bool Contains(const std::string& id) const; 83 bool Contains(const std::string& id) const;
83 84
84 // Adds the specified extension to the set. The set becomes an owner. Any 85 // Adds the specified extension to the set. The set becomes an owner. Any
85 // previous extension with the same ID is removed. 86 // previous extension with the same ID is removed.
86 void Insert(const scoped_refptr<const Extension>& extension); 87 void Insert(const scoped_refptr<const extensions::Extension>& extension);
87 88
88 // Copies different items from |extensions| to the current set and returns 89 // Copies different items from |extensions| to the current set and returns
89 // whether anything changed. 90 // whether anything changed.
90 bool InsertAll(const ExtensionSet& extensions); 91 bool InsertAll(const ExtensionSet& extensions);
91 92
92 // Removes the specified extension. 93 // Removes the specified extension.
93 void Remove(const std::string& id); 94 void Remove(const std::string& id);
94 95
95 // Removes all extensions. 96 // Removes all extensions.
96 void Clear(); 97 void Clear();
97 98
98 // Returns the extension ID, or empty if none. This includes web URLs that 99 // Returns the extension ID, or empty if none. This includes web URLs that
99 // are part of an extension's web extent. 100 // are part of an extension's web extent.
100 std::string GetExtensionOrAppIDByURL(const ExtensionURLInfo& info) const; 101 std::string GetExtensionOrAppIDByURL(const ExtensionURLInfo& info) const;
101 102
102 // Returns the Extension, or NULL if none. This includes web URLs that are 103 // Returns the Extension, or NULL if none. This includes web URLs that are
103 // part of an extension's web extent. 104 // part of an extension's web extent.
104 // NOTE: This can return NULL if called before UpdateExtensions receives 105 // NOTE: This can return NULL if called before UpdateExtensions receives
105 // bulk extension data (e.g. if called from 106 // bulk extension data (e.g. if called from
106 // EventBindings::HandleContextCreated) 107 // EventBindings::HandleContextCreated)
107 const Extension* GetExtensionOrAppByURL(const ExtensionURLInfo& info) const; 108 const extensions::Extension* GetExtensionOrAppByURL(
109 const ExtensionURLInfo& info) const;
108 110
109 // Returns the hosted app whose web extent contains the URL. 111 // Returns the hosted app whose web extent contains the URL.
110 const Extension* GetHostedAppByURL(const ExtensionURLInfo& info) const; 112 const extensions::Extension* GetHostedAppByURL(
113 const ExtensionURLInfo& info) const;
111 114
112 // Returns a hosted app that contains any URL that overlaps with the given 115 // Returns a hosted app that contains any URL that overlaps with the given
113 // extent, if one exists. 116 // extent, if one exists.
114 const Extension* GetHostedAppByOverlappingWebExtent( 117 const extensions::Extension* GetHostedAppByOverlappingWebExtent(
115 const URLPatternSet& extent) const; 118 const URLPatternSet& extent) const;
116 119
117 // Returns true if |new_url| is in the extent of the same extension as 120 // Returns true if |new_url| is in the extent of the same extension as
118 // |old_url|. Also returns true if neither URL is in an app. 121 // |old_url|. Also returns true if neither URL is in an app.
119 bool InSameExtent(const GURL& old_url, const GURL& new_url) const; 122 bool InSameExtent(const GURL& old_url, const GURL& new_url) const;
120 123
121 // Look up an Extension object by id. 124 // Look up an Extension object by id.
122 const Extension* GetByID(const std::string& id) const; 125 const extensions::Extension* GetByID(const std::string& id) const;
123 126
124 // Returns true if |info| should get extension api bindings and be permitted 127 // Returns true if |info| should get extension api bindings and be permitted
125 // to make api calls. Note that this is independent of what extension 128 // to make api calls. Note that this is independent of what extension
126 // permissions the given extension has been granted. 129 // permissions the given extension has been granted.
127 bool ExtensionBindingsAllowed(const ExtensionURLInfo& info) const; 130 bool ExtensionBindingsAllowed(const ExtensionURLInfo& info) const;
128 131
129 private: 132 private:
130 FRIEND_TEST_ALL_PREFIXES(ExtensionSetTest, ExtensionSet); 133 FRIEND_TEST_ALL_PREFIXES(ExtensionSetTest, ExtensionSet);
131 134
132 ExtensionMap extensions_; 135 ExtensionMap extensions_;
133 136
134 DISALLOW_COPY_AND_ASSIGN(ExtensionSet); 137 DISALLOW_COPY_AND_ASSIGN(ExtensionSet);
135 }; 138 };
136 139
137 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_ 140 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_resource_unittest.cc ('k') | chrome/common/extensions/extension_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698