| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/common/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 "extensions/common/constants.h" | 10 #include "extensions/common/constants.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 const Extension* ExtensionSet::GetExtensionOrAppByURL(const GURL& url) const { | 85 const Extension* ExtensionSet::GetExtensionOrAppByURL(const GURL& url) const { |
| 86 if (url.SchemeIs(kExtensionScheme)) | 86 if (url.SchemeIs(kExtensionScheme)) |
| 87 return GetByID(url.host()); | 87 return GetByID(url.host()); |
| 88 | 88 |
| 89 return GetHostedAppByURL(url); | 89 return GetHostedAppByURL(url); |
| 90 } | 90 } |
| 91 | 91 |
| 92 const Extension* ExtensionSet::GetAppByURL(const GURL& url) const { | 92 const Extension* ExtensionSet::GetAppByURL(const GURL& url) const { |
| 93 const Extension* extension = GetExtensionOrAppByURL(url); | 93 const Extension* extension = GetExtensionOrAppByURL(url); |
| 94 return (extension && extension->is_app()) ? extension : NULL; | 94 return (extension && extension->is_app()) ? extension : nullptr; |
| 95 } | 95 } |
| 96 | 96 |
| 97 const Extension* ExtensionSet::GetHostedAppByURL(const GURL& url) const { | 97 const Extension* ExtensionSet::GetHostedAppByURL(const GURL& url) const { |
| 98 for (ExtensionMap::const_iterator iter = extensions_.begin(); | 98 for (ExtensionMap::const_iterator iter = extensions_.begin(); |
| 99 iter != extensions_.end(); ++iter) { | 99 iter != extensions_.end(); ++iter) { |
| 100 if (iter->second->web_extent().MatchesURL(url)) | 100 if (iter->second->web_extent().MatchesURL(url)) |
| 101 return iter->second.get(); | 101 return iter->second.get(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 return NULL; | 104 return nullptr; |
| 105 } | 105 } |
| 106 | 106 |
| 107 const Extension* ExtensionSet::GetHostedAppByOverlappingWebExtent( | 107 const Extension* ExtensionSet::GetHostedAppByOverlappingWebExtent( |
| 108 const URLPatternSet& extent) const { | 108 const URLPatternSet& extent) const { |
| 109 for (ExtensionMap::const_iterator iter = extensions_.begin(); | 109 for (ExtensionMap::const_iterator iter = extensions_.begin(); |
| 110 iter != extensions_.end(); ++iter) { | 110 iter != extensions_.end(); ++iter) { |
| 111 if (iter->second->web_extent().OverlapsWith(extent)) | 111 if (iter->second->web_extent().OverlapsWith(extent)) |
| 112 return iter->second.get(); | 112 return iter->second.get(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 return NULL; | 115 return nullptr; |
| 116 } | 116 } |
| 117 | 117 |
| 118 bool ExtensionSet::InSameExtent(const GURL& old_url, | 118 bool ExtensionSet::InSameExtent(const GURL& old_url, |
| 119 const GURL& new_url) const { | 119 const GURL& new_url) const { |
| 120 return GetExtensionOrAppByURL(old_url) == | 120 return GetExtensionOrAppByURL(old_url) == |
| 121 GetExtensionOrAppByURL(new_url); | 121 GetExtensionOrAppByURL(new_url); |
| 122 } | 122 } |
| 123 | 123 |
| 124 const Extension* ExtensionSet::GetByID(const std::string& id) const { | 124 const Extension* ExtensionSet::GetByID(const std::string& id) const { |
| 125 ExtensionMap::const_iterator i = extensions_.find(id); | 125 ExtensionMap::const_iterator i = extensions_.find(id); |
| 126 if (i != extensions_.end()) | 126 if (i != extensions_.end()) |
| 127 return i->second.get(); | 127 return i->second.get(); |
| 128 else | 128 else |
| 129 return NULL; | 129 return nullptr; |
| 130 } | 130 } |
| 131 | 131 |
| 132 ExtensionIdSet ExtensionSet::GetIDs() const { | 132 ExtensionIdSet ExtensionSet::GetIDs() const { |
| 133 ExtensionIdSet ids; | 133 ExtensionIdSet ids; |
| 134 for (ExtensionMap::const_iterator it = extensions_.begin(); | 134 for (ExtensionMap::const_iterator it = extensions_.begin(); |
| 135 it != extensions_.end(); ++it) { | 135 it != extensions_.end(); ++it) { |
| 136 ids.insert(it->first); | 136 ids.insert(it->first); |
| 137 } | 137 } |
| 138 return ids; | 138 return ids; |
| 139 } | 139 } |
| 140 | 140 |
| 141 bool ExtensionSet::ExtensionBindingsAllowed(const GURL& url) const { | 141 bool ExtensionSet::ExtensionBindingsAllowed(const GURL& url) const { |
| 142 if (url.SchemeIs(kExtensionScheme)) | 142 if (url.SchemeIs(kExtensionScheme)) |
| 143 return true; | 143 return true; |
| 144 | 144 |
| 145 for (ExtensionMap::const_iterator it = extensions_.begin(); | 145 for (ExtensionMap::const_iterator it = extensions_.begin(); |
| 146 it != extensions_.end(); ++it) { | 146 it != extensions_.end(); ++it) { |
| 147 if (it->second->location() == Manifest::COMPONENT && | 147 if (it->second->location() == Manifest::COMPONENT && |
| 148 it->second->web_extent().MatchesURL(url)) | 148 it->second->web_extent().MatchesURL(url)) |
| 149 return true; | 149 return true; |
| 150 } | 150 } |
| 151 | 151 |
| 152 return false; | 152 return false; |
| 153 } | 153 } |
| 154 | 154 |
| 155 } // namespace extensions | 155 } // namespace extensions |
| OLD | NEW |