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.url()); |
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(const GURL& url) const { |
| 81 for (ExtensionMap::const_iterator iter = extensions_.begin(); |
| 82 iter != extensions_.end(); ++iter) { |
| 83 if (iter->second->web_extent().MatchesURL(url)) |
| 84 return iter->second.get(); |
81 } | 85 } |
82 | 86 |
83 return NULL; | 87 return NULL; |
| 88 } |
| 89 |
| 90 const Extension* ExtensionSet::GetByOverlappingWebExtent( |
| 91 const URLPatternSet& extent) const { |
| 92 for (ExtensionMap::const_iterator iter = extensions_.begin(); |
| 93 iter != extensions_.end(); ++iter) { |
| 94 if (iter->second->web_extent().OverlapsWith(extent)) |
| 95 return iter->second.get(); |
| 96 } |
| 97 |
| 98 return NULL; |
84 } | 99 } |
85 | 100 |
86 bool ExtensionSet::InSameExtent(const GURL& old_url, | 101 bool ExtensionSet::InSameExtent(const GURL& old_url, |
87 const GURL& new_url) const { | 102 const GURL& new_url) const { |
88 return GetByURL(ExtensionURLInfo(old_url)) == | 103 return GetByURL(ExtensionURLInfo(old_url)) == |
89 GetByURL(ExtensionURLInfo(new_url)); | 104 GetByURL(ExtensionURLInfo(new_url)); |
90 } | 105 } |
91 | 106 |
92 const Extension* ExtensionSet::GetByID(const std::string& id) const { | 107 const Extension* ExtensionSet::GetByID(const std::string& id) const { |
93 ExtensionMap::const_iterator i = extensions_.find(id); | 108 ExtensionMap::const_iterator i = extensions_.find(id); |
(...skipping 13 matching lines...) Expand all Loading... |
107 | 122 |
108 ExtensionMap::const_iterator i = extensions_.begin(); | 123 ExtensionMap::const_iterator i = extensions_.begin(); |
109 for (; i != extensions_.end(); ++i) { | 124 for (; i != extensions_.end(); ++i) { |
110 if (i->second->location() == Extension::COMPONENT && | 125 if (i->second->location() == Extension::COMPONENT && |
111 i->second->web_extent().MatchesURL(info.url())) | 126 i->second->web_extent().MatchesURL(info.url())) |
112 return true; | 127 return true; |
113 } | 128 } |
114 | 129 |
115 return false; | 130 return false; |
116 } | 131 } |
OLD | NEW |