| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/url_constants.h" | 8 #include "chrome/common/url_constants.h" |
| 9 | 9 |
| 10 using WebKit::WebSecurityOrigin; | 10 using WebKit::WebSecurityOrigin; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // but in some rare cases involving sandboxing, the two will be different. | 67 // but in some rare cases involving sandboxing, the two will be different. |
| 68 // We catch those cases by checking whether the document's origin is unique. | 68 // We catch those cases by checking whether the document's origin is unique. |
| 69 // If that's not the case, then we conclude that the document's security | 69 // If that's not the case, then we conclude that the document's security |
| 70 // context is well-described by its URL and proceed to use only the URL. | 70 // context is well-described by its URL and proceed to use only the URL. |
| 71 if (!info.origin().isNull() && info.origin().isUnique()) | 71 if (!info.origin().isNull() && info.origin().isUnique()) |
| 72 return NULL; | 72 return NULL; |
| 73 | 73 |
| 74 if (info.url().SchemeIs(chrome::kExtensionScheme)) | 74 if (info.url().SchemeIs(chrome::kExtensionScheme)) |
| 75 return GetByID(info.url().host()); | 75 return GetByID(info.url().host()); |
| 76 | 76 |
| 77 ExtensionMap::const_iterator i = extensions_.begin(); | 77 return GetByWebExtent(info); |
| 78 for (; i != extensions_.end(); ++i) { | 78 } |
| 79 if (i->second->web_extent().MatchesURL(info.url())) | 79 |
| 80 return i->second.get(); | 80 const Extension* ExtensionSet::GetByWebExtent( |
| 81 const ExtensionURLInfo& info) const { |
| 82 for (ExtensionMap::const_iterator iter = extensions_.begin(); |
| 83 iter != extensions_.end(); ++iter) { |
| 84 if (iter->second->web_extent().MatchesURL(info.url())) |
| 85 return iter->second.get(); |
| 81 } | 86 } |
| 82 | 87 |
| 83 return NULL; | 88 return NULL; |
| 89 } |
| 90 |
| 91 const Extension* ExtensionSet::GetByOverlappingWebExtent( |
| 92 const URLPatternSet& extent) const { |
| 93 for (ExtensionMap::const_iterator iter = extensions_.begin(); |
| 94 iter != extensions_.end(); ++iter) { |
| 95 if (iter->second->web_extent().OverlapsWith(extent)) |
| 96 return iter->second.get(); |
| 97 } |
| 98 |
| 99 return NULL; |
| 84 } | 100 } |
| 85 | 101 |
| 86 bool ExtensionSet::InSameExtent(const GURL& old_url, | 102 bool ExtensionSet::InSameExtent(const GURL& old_url, |
| 87 const GURL& new_url) const { | 103 const GURL& new_url) const { |
| 88 return GetByURL(ExtensionURLInfo(old_url)) == | 104 return GetByURL(ExtensionURLInfo(old_url)) == |
| 89 GetByURL(ExtensionURLInfo(new_url)); | 105 GetByURL(ExtensionURLInfo(new_url)); |
| 90 } | 106 } |
| 91 | 107 |
| 92 const Extension* ExtensionSet::GetByID(const std::string& id) const { | 108 const Extension* ExtensionSet::GetByID(const std::string& id) const { |
| 93 ExtensionMap::const_iterator i = extensions_.find(id); | 109 ExtensionMap::const_iterator i = extensions_.find(id); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 107 | 123 |
| 108 ExtensionMap::const_iterator i = extensions_.begin(); | 124 ExtensionMap::const_iterator i = extensions_.begin(); |
| 109 for (; i != extensions_.end(); ++i) { | 125 for (; i != extensions_.end(); ++i) { |
| 110 if (i->second->location() == Extension::COMPONENT && | 126 if (i->second->location() == Extension::COMPONENT && |
| 111 i->second->web_extent().MatchesURL(info.url())) | 127 i->second->web_extent().MatchesURL(info.url())) |
| 112 return true; | 128 return true; |
| 113 } | 129 } |
| 114 | 130 |
| 115 return false; | 131 return false; |
| 116 } | 132 } |
| OLD | NEW |