| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser/extensions/extension_info_map.h" | 5 #include "chrome/browser/extensions/extension_info_map.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser_thread.h" | 7 #include "chrome/browser/browser_thread.h" |
| 8 #include "chrome/common/extensions/extension.h" |
| 8 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
| 9 | 10 |
| 10 namespace { | 11 namespace { |
| 11 | 12 |
| 12 static void CheckOnValidThread() { | 13 static void CheckOnValidThread() { |
| 13 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 14 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 14 } | 15 } |
| 15 | 16 |
| 16 } // namespace | 17 } // namespace |
| 17 | 18 |
| 18 ExtensionInfoMap::ExtensionInfoMap() { | 19 ExtensionInfoMap::ExtensionInfoMap() { |
| 19 } | 20 } |
| 20 | 21 |
| 21 ExtensionInfoMap::~ExtensionInfoMap() { | 22 ExtensionInfoMap::~ExtensionInfoMap() { |
| 22 } | 23 } |
| 23 | 24 |
| 24 void ExtensionInfoMap::AddExtension(const Extension::StaticData* data) { | 25 void ExtensionInfoMap::AddExtension(const Extension* extension) { |
| 25 CheckOnValidThread(); | 26 CheckOnValidThread(); |
| 26 extension_info_[data->id] = data; | 27 extension_info_[extension->id()] = extension; |
| 27 | 28 |
| 28 // Our map has already added a reference. Balance the reference given at the | 29 // Our map has already added a reference. Balance the reference given at the |
| 29 // call-site. | 30 // call-site. |
| 30 data->Release(); | 31 extension->Release(); |
| 31 } | 32 } |
| 32 | 33 |
| 33 void ExtensionInfoMap::RemoveExtension(const std::string& id) { | 34 void ExtensionInfoMap::RemoveExtension(const std::string& id) { |
| 34 CheckOnValidThread(); | 35 CheckOnValidThread(); |
| 35 Map::iterator iter = extension_info_.find(id); | 36 Map::iterator iter = extension_info_.find(id); |
| 36 if (iter != extension_info_.end()) { | 37 if (iter != extension_info_.end()) { |
| 37 extension_info_.erase(iter); | 38 extension_info_.erase(iter); |
| 38 } else { | 39 } else { |
| 39 // NOTE: This can currently happen if we receive multiple unload | 40 // NOTE: This can currently happen if we receive multiple unload |
| 40 // notifications, e.g. setting incognito-enabled state for a | 41 // notifications, e.g. setting incognito-enabled state for a |
| 41 // disabled extension (e.g., via sync). See | 42 // disabled extension (e.g., via sync). See |
| 42 // http://code.google.com/p/chromium/issues/detail?id=50582 . | 43 // http://code.google.com/p/chromium/issues/detail?id=50582 . |
| 43 NOTREACHED() << id; | 44 NOTREACHED() << id; |
| 44 } | 45 } |
| 45 } | 46 } |
| 46 | 47 |
| 47 | 48 |
| 48 std::string ExtensionInfoMap::GetNameForExtension(const std::string& id) const { | 49 std::string ExtensionInfoMap::GetNameForExtension(const std::string& id) const { |
| 49 Map::const_iterator iter = extension_info_.find(id); | 50 Map::const_iterator iter = extension_info_.find(id); |
| 50 if (iter != extension_info_.end()) | 51 if (iter != extension_info_.end()) |
| 51 return iter->second->name; | 52 return iter->second->name(); |
| 52 else | 53 else |
| 53 return std::string(); | 54 return std::string(); |
| 54 } | 55 } |
| 55 | 56 |
| 56 FilePath ExtensionInfoMap::GetPathForExtension(const std::string& id) const { | 57 FilePath ExtensionInfoMap::GetPathForExtension(const std::string& id) const { |
| 57 Map::const_iterator iter = extension_info_.find(id); | 58 Map::const_iterator iter = extension_info_.find(id); |
| 58 if (iter != extension_info_.end()) | 59 if (iter != extension_info_.end()) |
| 59 return iter->second->path; | 60 return iter->second->path(); |
| 60 else | 61 else |
| 61 return FilePath(); | 62 return FilePath(); |
| 62 } | 63 } |
| 63 | 64 |
| 64 bool ExtensionInfoMap::ExtensionHasWebExtent(const std::string& id) const { | 65 bool ExtensionInfoMap::ExtensionHasWebExtent(const std::string& id) const { |
| 65 Map::const_iterator iter = extension_info_.find(id); | 66 Map::const_iterator iter = extension_info_.find(id); |
| 66 return iter != extension_info_.end() && !iter->second->extent.is_empty(); | 67 return iter != extension_info_.end() && |
| 68 !iter->second->web_extent().is_empty(); |
| 67 } | 69 } |
| 68 | 70 |
| 69 bool ExtensionInfoMap::ExtensionCanLoadInIncognito( | 71 bool ExtensionInfoMap::ExtensionCanLoadInIncognito( |
| 70 const std::string& id) const { | 72 const std::string& id) const { |
| 71 Map::const_iterator iter = extension_info_.find(id); | 73 Map::const_iterator iter = extension_info_.find(id); |
| 72 // Only split-mode extensions can load in incognito profiles. | 74 // Only split-mode extensions can load in incognito profiles. |
| 73 return iter != extension_info_.end() && iter->second->incognito_split_mode; | 75 return iter != extension_info_.end() && iter->second->incognito_split_mode(); |
| 74 } | 76 } |
| 75 | 77 |
| 76 std::string ExtensionInfoMap::GetDefaultLocaleForExtension( | 78 std::string ExtensionInfoMap::GetDefaultLocaleForExtension( |
| 77 const std::string& id) const { | 79 const std::string& id) const { |
| 78 Map::const_iterator iter = extension_info_.find(id); | 80 Map::const_iterator iter = extension_info_.find(id); |
| 79 std::string result; | 81 std::string result; |
| 80 if (iter != extension_info_.end()) | 82 if (iter != extension_info_.end()) |
| 81 result = iter->second->default_locale; | 83 result = iter->second->default_locale(); |
| 82 | 84 |
| 83 return result; | 85 return result; |
| 84 } | 86 } |
| 85 | 87 |
| 86 ExtensionExtent ExtensionInfoMap::GetEffectiveHostPermissionsForExtension( | 88 ExtensionExtent ExtensionInfoMap::GetEffectiveHostPermissionsForExtension( |
| 87 const std::string& id) const { | 89 const std::string& id) const { |
| 88 Map::const_iterator iter = extension_info_.find(id); | 90 Map::const_iterator iter = extension_info_.find(id); |
| 89 ExtensionExtent result; | 91 ExtensionExtent result; |
| 90 if (iter != extension_info_.end()) | 92 if (iter != extension_info_.end()) |
| 91 result = iter->second->effective_host_permissions; | 93 result = iter->second->GetEffectiveHostPermissions(); |
| 92 | 94 |
| 93 return result; | 95 return result; |
| 94 } | 96 } |
| 95 | 97 |
| 96 bool ExtensionInfoMap::CheckURLAccessToExtensionPermission( | 98 bool ExtensionInfoMap::CheckURLAccessToExtensionPermission( |
| 97 const GURL& url, | 99 const GURL& url, |
| 98 const char* permission_name) const { | 100 const char* permission_name) const { |
| 99 Map::const_iterator info; | 101 Map::const_iterator info; |
| 100 if (url.SchemeIs(chrome::kExtensionScheme)) { | 102 if (url.SchemeIs(chrome::kExtensionScheme)) { |
| 101 // If the url is an extension scheme, we just look it up by extension id. | 103 // If the url is an extension scheme, we just look it up by extension id. |
| 102 std::string id = url.host(); | 104 std::string id = url.host(); |
| 103 info = extension_info_.find(id); | 105 info = extension_info_.find(id); |
| 104 } else { | 106 } else { |
| 105 // Otherwise, we scan for a matching extent. Overlapping extents are | 107 // Otherwise, we scan for a matching extent. Overlapping extents are |
| 106 // disallowed, so only one will match. | 108 // disallowed, so only one will match. |
| 107 info = extension_info_.begin(); | 109 info = extension_info_.begin(); |
| 108 while (info != extension_info_.end() && | 110 while (info != extension_info_.end() && |
| 109 !info->second->extent.ContainsURL(url)) | 111 !info->second->web_extent().ContainsURL(url)) |
| 110 ++info; | 112 ++info; |
| 111 } | 113 } |
| 112 | 114 |
| 113 if (info == extension_info_.end()) | 115 if (info == extension_info_.end()) |
| 114 return false; | 116 return false; |
| 115 | 117 |
| 116 const std::set<std::string>& api_permissions = info->second->api_permissions; | 118 return info->second->api_permissions().count(permission_name) != 0; |
| 117 return api_permissions.count(permission_name) != 0; | |
| 118 } | 119 } |
| 119 | 120 |
| 120 bool ExtensionInfoMap::URLIsForExtensionIcon(const GURL& url) const { | 121 bool ExtensionInfoMap::URLIsForExtensionIcon(const GURL& url) const { |
| 121 DCHECK(url.SchemeIs(chrome::kExtensionScheme)); | 122 DCHECK(url.SchemeIs(chrome::kExtensionScheme)); |
| 122 | 123 |
| 123 Map::const_iterator iter = extension_info_.find(url.host()); | 124 Map::const_iterator iter = extension_info_.find(url.host()); |
| 124 if (iter == extension_info_.end()) | 125 if (iter == extension_info_.end()) |
| 125 return false; | 126 return false; |
| 126 | 127 |
| 127 std::string path = url.path(); | 128 std::string path = url.path(); |
| 128 DCHECK(path.length() > 0 && path[0] == '/'); | 129 DCHECK(path.length() > 0 && path[0] == '/'); |
| 129 path = path.substr(1); | 130 path = path.substr(1); |
| 130 return iter->second->icons.ContainsPath(path); | 131 return iter->second->icons().ContainsPath(path); |
| 131 } | 132 } |
| OLD | NEW |