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

Side by Side Diff: extensions/common/extension_set.cc

Issue 102103005: Move c/c/e/extension_set to top-level extensions/ (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed unused includes, added includes where missing Created 7 years 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 #include "chrome/common/extensions/extension_set.h" 5 #include "extensions/common/extension_set.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "chrome/common/url_constants.h"
11 #include "extensions/common/constants.h" 10 #include "extensions/common/constants.h"
12 #include "extensions/common/extension.h" 11 #include "extensions/common/extension.h"
13 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" 12 #include "extensions/common/manifest_handlers/sandboxed_page_info.h"
14 13
15 using extensions::Extension; 14 namespace extensions {
16 15
17 ExtensionSet::const_iterator::const_iterator() {} 16 ExtensionSet::const_iterator::const_iterator() {}
18 17
19 ExtensionSet::const_iterator::const_iterator(const const_iterator& other) 18 ExtensionSet::const_iterator::const_iterator(const const_iterator& other)
20 : it_(other.it_) { 19 : it_(other.it_) {
21 } 20 }
22 21
23 ExtensionSet::const_iterator::const_iterator(ExtensionMap::const_iterator it) 22 ExtensionSet::const_iterator::const_iterator(ExtensionMap::const_iterator it)
24 : it_(it) { 23 : it_(it) {
25 } 24 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 if (was_present && !modification_callback_.is_null()) 65 if (was_present && !modification_callback_.is_null())
67 modification_callback_.Run(GetIDs()); 66 modification_callback_.Run(GetIDs());
68 return was_present; 67 return was_present;
69 } 68 }
70 69
71 void ExtensionSet::Clear() { 70 void ExtensionSet::Clear() {
72 extensions_.clear(); 71 extensions_.clear();
73 } 72 }
74 73
75 std::string ExtensionSet::GetExtensionOrAppIDByURL(const GURL& url) const { 74 std::string ExtensionSet::GetExtensionOrAppIDByURL(const GURL& url) const {
76 if (url.SchemeIs(extensions::kExtensionScheme)) 75 if (url.SchemeIs(kExtensionScheme))
77 return url.host(); 76 return url.host();
78 77
79 const Extension* extension = GetExtensionOrAppByURL(url); 78 const Extension* extension = GetExtensionOrAppByURL(url);
80 if (!extension) 79 if (!extension)
81 return std::string(); 80 return std::string();
82 81
83 return extension->id(); 82 return extension->id();
84 } 83 }
85 84
86 const Extension* ExtensionSet::GetExtensionOrAppByURL(const GURL& url) const { 85 const Extension* ExtensionSet::GetExtensionOrAppByURL(const GURL& url) const {
87 if (url.SchemeIs(extensions::kExtensionScheme)) 86 if (url.SchemeIs(kExtensionScheme))
88 return GetByID(url.host()); 87 return GetByID(url.host());
89 88
90 return GetHostedAppByURL(url); 89 return GetHostedAppByURL(url);
91 } 90 }
92 91
93 const Extension* ExtensionSet::GetHostedAppByURL(const GURL& url) const { 92 const Extension* ExtensionSet::GetHostedAppByURL(const GURL& url) const {
94 for (ExtensionMap::const_iterator iter = extensions_.begin(); 93 for (ExtensionMap::const_iterator iter = extensions_.begin();
95 iter != extensions_.end(); ++iter) { 94 iter != extensions_.end(); ++iter) {
96 if (iter->second->web_extent().MatchesURL(url)) 95 if (iter->second->web_extent().MatchesURL(url))
97 return iter->second.get(); 96 return iter->second.get();
98 } 97 }
99 98
100 return NULL; 99 return NULL;
101 } 100 }
102 101
103 const Extension* ExtensionSet::GetHostedAppByOverlappingWebExtent( 102 const Extension* ExtensionSet::GetHostedAppByOverlappingWebExtent(
104 const extensions::URLPatternSet& extent) const { 103 const URLPatternSet& extent) const {
105 for (ExtensionMap::const_iterator iter = extensions_.begin(); 104 for (ExtensionMap::const_iterator iter = extensions_.begin();
106 iter != extensions_.end(); ++iter) { 105 iter != extensions_.end(); ++iter) {
107 if (iter->second->web_extent().OverlapsWith(extent)) 106 if (iter->second->web_extent().OverlapsWith(extent))
108 return iter->second.get(); 107 return iter->second.get();
109 } 108 }
110 109
111 return NULL; 110 return NULL;
112 } 111 }
113 112
114 bool ExtensionSet::InSameExtent(const GURL& old_url, 113 bool ExtensionSet::InSameExtent(const GURL& old_url,
115 const GURL& new_url) const { 114 const GURL& new_url) const {
116 return GetExtensionOrAppByURL(old_url) == 115 return GetExtensionOrAppByURL(old_url) ==
117 GetExtensionOrAppByURL(new_url); 116 GetExtensionOrAppByURL(new_url);
118 } 117 }
119 118
120 const Extension* ExtensionSet::GetByID(const std::string& id) const { 119 const Extension* ExtensionSet::GetByID(const std::string& id) const {
121 ExtensionMap::const_iterator i = extensions_.find(id); 120 ExtensionMap::const_iterator i = extensions_.find(id);
122 if (i != extensions_.end()) 121 if (i != extensions_.end())
123 return i->second.get(); 122 return i->second.get();
124 else 123 else
125 return NULL; 124 return NULL;
126 } 125 }
127 126
128 extensions::ExtensionIdSet ExtensionSet::GetIDs() const { 127 ExtensionIdSet ExtensionSet::GetIDs() const {
129 extensions::ExtensionIdSet ids; 128 ExtensionIdSet ids;
130 for (ExtensionMap::const_iterator it = extensions_.begin(); 129 for (ExtensionMap::const_iterator it = extensions_.begin();
131 it != extensions_.end(); ++it) { 130 it != extensions_.end(); ++it) {
132 ids.insert(it->first); 131 ids.insert(it->first);
133 } 132 }
134 return ids; 133 return ids;
135 } 134 }
136 135
137 bool ExtensionSet::ExtensionBindingsAllowed(const GURL& url) const { 136 bool ExtensionSet::ExtensionBindingsAllowed(const GURL& url) const {
138 if (url.SchemeIs(extensions::kExtensionScheme)) 137 if (url.SchemeIs(kExtensionScheme))
139 return true; 138 return true;
140 139
141 ExtensionMap::const_iterator i = extensions_.begin(); 140 for (ExtensionMap::const_iterator it = extensions_.begin();
142 for (; i != extensions_.end(); ++i) { 141 it != extensions_.end(); ++it) {
143 if (i->second->location() == extensions::Manifest::COMPONENT && 142 if (it->second->location() == Manifest::COMPONENT &&
144 i->second->web_extent().MatchesURL(url)) 143 it->second->web_extent().MatchesURL(url))
145 return true; 144 return true;
146 } 145 }
147 146
148 return false; 147 return false;
149 } 148 }
149
150 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698