| OLD | NEW |
| 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 "chrome/common/extensions/extension_set.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/common/extensions/extension.h" | 8 #include "chrome/common/extensions/extension.h" |
| 9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
| 10 #include "extensions/common/constants.h" | 10 #include "extensions/common/constants.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 bool ExtensionSet::InsertAll(const ExtensionSet& extensions) { | 57 bool ExtensionSet::InsertAll(const ExtensionSet& extensions) { |
| 58 size_t before = size(); | 58 size_t before = size(); |
| 59 for (ExtensionSet::const_iterator iter = extensions.begin(); | 59 for (ExtensionSet::const_iterator iter = extensions.begin(); |
| 60 iter != extensions.end(); ++iter) { | 60 iter != extensions.end(); ++iter) { |
| 61 Insert(*iter); | 61 Insert(*iter); |
| 62 } | 62 } |
| 63 return size() != before; | 63 return size() != before; |
| 64 } | 64 } |
| 65 | 65 |
| 66 void ExtensionSet::Remove(const std::string& id) { | 66 bool ExtensionSet::Remove(const std::string& id) { |
| 67 extensions_.erase(id); | 67 return extensions_.erase(id) > 0; |
| 68 } | 68 } |
| 69 | 69 |
| 70 void ExtensionSet::Clear() { | 70 void ExtensionSet::Clear() { |
| 71 extensions_.clear(); | 71 extensions_.clear(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 std::string ExtensionSet::GetExtensionOrAppIDByURL( | 74 std::string ExtensionSet::GetExtensionOrAppIDByURL( |
| 75 const ExtensionURLInfo& info) const { | 75 const ExtensionURLInfo& info) const { |
| 76 DCHECK(!info.origin().isNull()); | 76 DCHECK(!info.origin().isNull()); |
| 77 | 77 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } | 130 } |
| 131 | 131 |
| 132 const Extension* ExtensionSet::GetByID(const std::string& id) const { | 132 const Extension* ExtensionSet::GetByID(const std::string& id) const { |
| 133 ExtensionMap::const_iterator i = extensions_.find(id); | 133 ExtensionMap::const_iterator i = extensions_.find(id); |
| 134 if (i != extensions_.end()) | 134 if (i != extensions_.end()) |
| 135 return i->second.get(); | 135 return i->second.get(); |
| 136 else | 136 else |
| 137 return NULL; | 137 return NULL; |
| 138 } | 138 } |
| 139 | 139 |
| 140 std::set<std::string> ExtensionSet::GetIDs() const { |
| 141 std::set<std::string> ids; |
| 142 for (ExtensionMap::const_iterator it = extensions_.begin(); |
| 143 it != extensions_.end(); ++it) { |
| 144 ids.insert(it->first); |
| 145 } |
| 146 return ids; |
| 147 } |
| 148 |
| 140 bool ExtensionSet::ExtensionBindingsAllowed( | 149 bool ExtensionSet::ExtensionBindingsAllowed( |
| 141 const ExtensionURLInfo& info) const { | 150 const ExtensionURLInfo& info) const { |
| 142 if (info.origin().isUnique() || IsSandboxedPage(info)) | 151 if (info.origin().isUnique() || IsSandboxedPage(info)) |
| 143 return false; | 152 return false; |
| 144 | 153 |
| 145 if (info.url().SchemeIs(extensions::kExtensionScheme)) | 154 if (info.url().SchemeIs(extensions::kExtensionScheme)) |
| 146 return true; | 155 return true; |
| 147 | 156 |
| 148 ExtensionMap::const_iterator i = extensions_.begin(); | 157 ExtensionMap::const_iterator i = extensions_.begin(); |
| 149 for (; i != extensions_.end(); ++i) { | 158 for (; i != extensions_.end(); ++i) { |
| 150 if (i->second->location() == Extension::COMPONENT && | 159 if (i->second->location() == Extension::COMPONENT && |
| 151 i->second->web_extent().MatchesURL(info.url())) | 160 i->second->web_extent().MatchesURL(info.url())) |
| 152 return true; | 161 return true; |
| 153 } | 162 } |
| 154 | 163 |
| 155 return false; | 164 return false; |
| 156 } | 165 } |
| 157 | 166 |
| 158 bool ExtensionSet::IsSandboxedPage(const ExtensionURLInfo& info) const { | 167 bool ExtensionSet::IsSandboxedPage(const ExtensionURLInfo& info) const { |
| 159 if (info.url().SchemeIs(extensions::kExtensionScheme)) { | 168 if (info.url().SchemeIs(extensions::kExtensionScheme)) { |
| 160 const Extension* extension = GetByID(info.url().host()); | 169 const Extension* extension = GetByID(info.url().host()); |
| 161 if (extension) { | 170 if (extension) { |
| 162 return extension->IsSandboxedPage(info.url().path()); | 171 return extension->IsSandboxedPage(info.url().path()); |
| 163 } | 172 } |
| 164 } | 173 } |
| 165 return false; | 174 return false; |
| 166 } | 175 } |
| OLD | NEW |