| 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 "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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 if (was_present && !modification_callback_.is_null()) | 63 if (was_present && !modification_callback_.is_null()) |
| 65 modification_callback_.Run(GetIDs()); | 64 modification_callback_.Run(GetIDs()); |
| 66 return was_present; | 65 return was_present; |
| 67 } | 66 } |
| 68 | 67 |
| 69 void ExtensionSet::Clear() { | 68 void ExtensionSet::Clear() { |
| 70 extensions_.clear(); | 69 extensions_.clear(); |
| 71 } | 70 } |
| 72 | 71 |
| 73 std::string ExtensionSet::GetExtensionOrAppIDByURL(const GURL& url) const { | 72 std::string ExtensionSet::GetExtensionOrAppIDByURL(const GURL& url) const { |
| 74 if (url.SchemeIs(extensions::kExtensionScheme)) | 73 if (url.SchemeIs(kExtensionScheme)) |
| 75 return url.host(); | 74 return url.host(); |
| 76 | 75 |
| 77 const Extension* extension = GetExtensionOrAppByURL(url); | 76 const Extension* extension = GetExtensionOrAppByURL(url); |
| 78 if (!extension) | 77 if (!extension) |
| 79 return std::string(); | 78 return std::string(); |
| 80 | 79 |
| 81 return extension->id(); | 80 return extension->id(); |
| 82 } | 81 } |
| 83 | 82 |
| 84 const Extension* ExtensionSet::GetExtensionOrAppByURL(const GURL& url) const { | 83 const Extension* ExtensionSet::GetExtensionOrAppByURL(const GURL& url) const { |
| 85 if (url.SchemeIs(extensions::kExtensionScheme)) | 84 if (url.SchemeIs(kExtensionScheme)) |
| 86 return GetByID(url.host()); | 85 return GetByID(url.host()); |
| 87 | 86 |
| 88 return GetHostedAppByURL(url); | 87 return GetHostedAppByURL(url); |
| 89 } | 88 } |
| 90 | 89 |
| 91 const Extension* ExtensionSet::GetHostedAppByURL(const GURL& url) const { | 90 const Extension* ExtensionSet::GetHostedAppByURL(const GURL& url) const { |
| 92 for (ExtensionMap::const_iterator iter = extensions_.begin(); | 91 for (ExtensionMap::const_iterator iter = extensions_.begin(); |
| 93 iter != extensions_.end(); ++iter) { | 92 iter != extensions_.end(); ++iter) { |
| 94 if (iter->second->web_extent().MatchesURL(url)) | 93 if (iter->second->web_extent().MatchesURL(url)) |
| 95 return iter->second.get(); | 94 return iter->second.get(); |
| 96 } | 95 } |
| 97 | 96 |
| 98 return NULL; | 97 return NULL; |
| 99 } | 98 } |
| 100 | 99 |
| 101 const Extension* ExtensionSet::GetHostedAppByOverlappingWebExtent( | 100 const Extension* ExtensionSet::GetHostedAppByOverlappingWebExtent( |
| 102 const extensions::URLPatternSet& extent) const { | 101 const URLPatternSet& extent) const { |
| 103 for (ExtensionMap::const_iterator iter = extensions_.begin(); | 102 for (ExtensionMap::const_iterator iter = extensions_.begin(); |
| 104 iter != extensions_.end(); ++iter) { | 103 iter != extensions_.end(); ++iter) { |
| 105 if (iter->second->web_extent().OverlapsWith(extent)) | 104 if (iter->second->web_extent().OverlapsWith(extent)) |
| 106 return iter->second.get(); | 105 return iter->second.get(); |
| 107 } | 106 } |
| 108 | 107 |
| 109 return NULL; | 108 return NULL; |
| 110 } | 109 } |
| 111 | 110 |
| 112 bool ExtensionSet::InSameExtent(const GURL& old_url, | 111 bool ExtensionSet::InSameExtent(const GURL& old_url, |
| 113 const GURL& new_url) const { | 112 const GURL& new_url) const { |
| 114 return GetExtensionOrAppByURL(old_url) == | 113 return GetExtensionOrAppByURL(old_url) == |
| 115 GetExtensionOrAppByURL(new_url); | 114 GetExtensionOrAppByURL(new_url); |
| 116 } | 115 } |
| 117 | 116 |
| 118 const Extension* ExtensionSet::GetByID(const std::string& id) const { | 117 const Extension* ExtensionSet::GetByID(const std::string& id) const { |
| 119 ExtensionMap::const_iterator i = extensions_.find(id); | 118 ExtensionMap::const_iterator i = extensions_.find(id); |
| 120 if (i != extensions_.end()) | 119 if (i != extensions_.end()) |
| 121 return i->second.get(); | 120 return i->second.get(); |
| 122 else | 121 else |
| 123 return NULL; | 122 return NULL; |
| 124 } | 123 } |
| 125 | 124 |
| 126 extensions::ExtensionIdSet ExtensionSet::GetIDs() const { | 125 ExtensionIdSet ExtensionSet::GetIDs() const { |
| 127 extensions::ExtensionIdSet ids; | 126 ExtensionIdSet ids; |
| 128 for (ExtensionMap::const_iterator it = extensions_.begin(); | 127 for (ExtensionMap::const_iterator it = extensions_.begin(); |
| 129 it != extensions_.end(); ++it) { | 128 it != extensions_.end(); ++it) { |
| 130 ids.insert(it->first); | 129 ids.insert(it->first); |
| 131 } | 130 } |
| 132 return ids; | 131 return ids; |
| 133 } | 132 } |
| 134 | 133 |
| 135 bool ExtensionSet::ExtensionBindingsAllowed(const GURL& url) const { | 134 bool ExtensionSet::ExtensionBindingsAllowed(const GURL& url) const { |
| 136 if (url.SchemeIs(extensions::kExtensionScheme)) | 135 if (url.SchemeIs(kExtensionScheme)) |
| 137 return true; | 136 return true; |
| 138 | 137 |
| 139 ExtensionMap::const_iterator i = extensions_.begin(); | 138 for (ExtensionMap::const_iterator it = extensions_.begin(); |
| 140 for (; i != extensions_.end(); ++i) { | 139 it != extensions_.end(); ++it) { |
| 141 if (i->second->location() == extensions::Manifest::COMPONENT && | 140 if (it->second->location() == Manifest::COMPONENT && |
| 142 i->second->web_extent().MatchesURL(url)) | 141 it->second->web_extent().MatchesURL(url)) |
| 143 return true; | 142 return true; |
| 144 } | 143 } |
| 145 | 144 |
| 146 return false; | 145 return false; |
| 147 } | 146 } |
| 147 |
| 148 } // namespace extensions |
| OLD | NEW |