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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 | 43 |
44 void ExtensionSet::Remove(const std::string& id) { | 44 void ExtensionSet::Remove(const std::string& id) { |
45 extensions_.erase(id); | 45 extensions_.erase(id); |
46 } | 46 } |
47 | 47 |
48 void ExtensionSet::Clear() { | 48 void ExtensionSet::Clear() { |
49 extensions_.clear(); | 49 extensions_.clear(); |
50 } | 50 } |
51 | 51 |
52 std::string ExtensionSet::GetIDByURL(const ExtensionURLInfo& info) const { | 52 std::string ExtensionSet::GetExtensionOrAppIDByURL( |
| 53 const ExtensionURLInfo& info) const { |
53 DCHECK(!info.origin().isNull()); | 54 DCHECK(!info.origin().isNull()); |
54 | 55 |
55 if (info.url().SchemeIs(chrome::kExtensionScheme)) | 56 if (info.url().SchemeIs(chrome::kExtensionScheme)) |
56 return info.origin().isUnique() ? "" : info.url().host(); | 57 return info.origin().isUnique() ? "" : info.url().host(); |
57 | 58 |
58 const Extension* extension = GetByURL(info); | 59 const Extension* extension = GetExtensionOrAppByURL(info); |
59 if (!extension) | 60 if (!extension) |
60 return ""; | 61 return ""; |
61 | 62 |
62 return extension->id(); | 63 return extension->id(); |
63 } | 64 } |
64 | 65 |
65 const Extension* ExtensionSet::GetByURL(const ExtensionURLInfo& info) const { | 66 const Extension* ExtensionSet::GetExtensionOrAppByURL( |
| 67 const ExtensionURLInfo& info) const { |
66 // In the common case, the document's origin will correspond to its URL, | 68 // In the common case, the document's origin will correspond to its URL, |
67 // but in some rare cases involving sandboxing, the two will be different. | 69 // 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. | 70 // 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 | 71 // 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. | 72 // context is well-described by its URL and proceed to use only the URL. |
71 if (!info.origin().isNull() && info.origin().isUnique()) | 73 if (!info.origin().isNull() && info.origin().isUnique()) |
72 return NULL; | 74 return NULL; |
73 | 75 |
74 if (info.url().SchemeIs(chrome::kExtensionScheme)) | 76 if (info.url().SchemeIs(chrome::kExtensionScheme)) |
75 return GetByID(info.url().host()); | 77 return GetByID(info.url().host()); |
76 | 78 |
77 ExtensionMap::const_iterator i = extensions_.begin(); | 79 return GetHostedAppByURL(info); |
78 for (; i != extensions_.end(); ++i) { | 80 } |
79 if (i->second->web_extent().MatchesURL(info.url())) | 81 |
80 return i->second.get(); | 82 const Extension* ExtensionSet::GetHostedAppByURL( |
| 83 const ExtensionURLInfo& info) const { |
| 84 for (ExtensionMap::const_iterator iter = extensions_.begin(); |
| 85 iter != extensions_.end(); ++iter) { |
| 86 if (iter->second->web_extent().MatchesURL(info.url())) |
| 87 return iter->second.get(); |
81 } | 88 } |
82 | 89 |
83 return NULL; | 90 return NULL; |
| 91 } |
| 92 |
| 93 const Extension* ExtensionSet::GetHostedAppByOverlappingWebExtent( |
| 94 const URLPatternSet& extent) const { |
| 95 for (ExtensionMap::const_iterator iter = extensions_.begin(); |
| 96 iter != extensions_.end(); ++iter) { |
| 97 if (iter->second->web_extent().OverlapsWith(extent)) |
| 98 return iter->second.get(); |
| 99 } |
| 100 |
| 101 return NULL; |
84 } | 102 } |
85 | 103 |
86 bool ExtensionSet::InSameExtent(const GURL& old_url, | 104 bool ExtensionSet::InSameExtent(const GURL& old_url, |
87 const GURL& new_url) const { | 105 const GURL& new_url) const { |
88 return GetByURL(ExtensionURLInfo(old_url)) == | 106 return GetExtensionOrAppByURL(ExtensionURLInfo(old_url)) == |
89 GetByURL(ExtensionURLInfo(new_url)); | 107 GetExtensionOrAppByURL(ExtensionURLInfo(new_url)); |
90 } | 108 } |
91 | 109 |
92 const Extension* ExtensionSet::GetByID(const std::string& id) const { | 110 const Extension* ExtensionSet::GetByID(const std::string& id) const { |
93 ExtensionMap::const_iterator i = extensions_.find(id); | 111 ExtensionMap::const_iterator i = extensions_.find(id); |
94 if (i != extensions_.end()) | 112 if (i != extensions_.end()) |
95 return i->second.get(); | 113 return i->second.get(); |
96 else | 114 else |
97 return NULL; | 115 return NULL; |
98 } | 116 } |
99 | 117 |
100 bool ExtensionSet::ExtensionBindingsAllowed( | 118 bool ExtensionSet::ExtensionBindingsAllowed( |
101 const ExtensionURLInfo& info) const { | 119 const ExtensionURLInfo& info) const { |
102 if (info.origin().isUnique()) | 120 if (info.origin().isUnique()) |
103 return false; | 121 return false; |
104 | 122 |
105 if (info.url().SchemeIs(chrome::kExtensionScheme)) | 123 if (info.url().SchemeIs(chrome::kExtensionScheme)) |
106 return true; | 124 return true; |
107 | 125 |
108 ExtensionMap::const_iterator i = extensions_.begin(); | 126 ExtensionMap::const_iterator i = extensions_.begin(); |
109 for (; i != extensions_.end(); ++i) { | 127 for (; i != extensions_.end(); ++i) { |
110 if (i->second->location() == Extension::COMPONENT && | 128 if (i->second->location() == Extension::COMPONENT && |
111 i->second->web_extent().MatchesURL(info.url())) | 129 i->second->web_extent().MatchesURL(info.url())) |
112 return true; | 130 return true; |
113 } | 131 } |
114 | 132 |
115 return false; | 133 return false; |
116 } | 134 } |
OLD | NEW |