| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/extensions_service.h" | 5 #include "chrome/browser/extensions/extensions_service.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/scoped_handle.h" | 8 #include "base/scoped_handle.h" |
| 9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/third_party/nss/blapi.h" | 11 #include "base/third_party/nss/blapi.h" |
| 12 #include "base/third_party/nss/sha256.h" | 12 #include "base/third_party/nss/sha256.h" |
| 13 #include "base/thread.h" | 13 #include "base/thread.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "net/base/file_stream.h" | 15 #include "net/base/file_stream.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/browsing_instance.h" | 17 #include "chrome/browser/browsing_instance.h" |
| 18 #include "chrome/browser/extensions/extension.h" | 18 #include "chrome/browser/extensions/extension.h" |
| 19 #include "chrome/browser/extensions/extension_browser_event_router.h" | 19 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 20 #include "chrome/browser/extensions/extension_error_reporter.h" | 20 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 21 #include "chrome/browser/extensions/extension_host.h" |
| 22 #include "chrome/browser/extensions/extension_view.h" |
| 21 #include "chrome/browser/extensions/user_script_master.h" | 23 #include "chrome/browser/extensions/user_script_master.h" |
| 22 #include "chrome/browser/extensions/extension_view.h" | |
| 23 #include "chrome/browser/plugin_service.h" | 24 #include "chrome/browser/plugin_service.h" |
| 24 #include "chrome/browser/profile.h" | 25 #include "chrome/browser/profile.h" |
| 25 #include "chrome/browser/tab_contents/site_instance.h" | 26 #include "chrome/browser/tab_contents/site_instance.h" |
| 26 #include "chrome/common/json_value_serializer.h" | 27 #include "chrome/common/json_value_serializer.h" |
| 27 #include "chrome/common/notification_service.h" | 28 #include "chrome/common/notification_service.h" |
| 28 #include "chrome/common/unzip.h" | 29 #include "chrome/common/unzip.h" |
| 29 | 30 |
| 31 #include "chrome/browser/browser_list.h" |
| 32 |
| 30 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
| 31 #include "base/registry.h" | 34 #include "base/registry.h" |
| 32 #endif | 35 #endif |
| 33 | 36 |
| 34 // ExtensionsService | 37 // ExtensionsService |
| 35 | 38 |
| 36 const char* ExtensionsService::kInstallDirectoryName = "Extensions"; | 39 const char* ExtensionsService::kInstallDirectoryName = "Extensions"; |
| 37 const char* ExtensionsService::kCurrentVersionFileName = "Current Version"; | 40 const char* ExtensionsService::kCurrentVersionFileName = "Current Version"; |
| 38 const char* ExtensionsServiceBackend::kTempExtensionName = "TEMP_INSTALL"; | 41 const char* ExtensionsServiceBackend::kTempExtensionName = "TEMP_INSTALL"; |
| 39 | 42 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 ExtensionsService::ExtensionsService(Profile* profile, | 78 ExtensionsService::ExtensionsService(Profile* profile, |
| 76 UserScriptMaster* user_script_master) | 79 UserScriptMaster* user_script_master) |
| 77 : message_loop_(MessageLoop::current()), | 80 : message_loop_(MessageLoop::current()), |
| 78 install_directory_(profile->GetPath().AppendASCII(kInstallDirectoryName)), | 81 install_directory_(profile->GetPath().AppendASCII(kInstallDirectoryName)), |
| 79 backend_(new ExtensionsServiceBackend(install_directory_)), | 82 backend_(new ExtensionsServiceBackend(install_directory_)), |
| 80 user_script_master_(user_script_master), | 83 user_script_master_(user_script_master), |
| 81 browsing_instance_(new BrowsingInstance(profile)) { | 84 browsing_instance_(new BrowsingInstance(profile)) { |
| 82 } | 85 } |
| 83 | 86 |
| 84 ExtensionsService::~ExtensionsService() { | 87 ExtensionsService::~ExtensionsService() { |
| 88 for (ExtensionHostList::iterator iter = background_hosts_.begin(); |
| 89 iter != background_hosts_.end(); ++iter) { |
| 90 delete *iter; |
| 91 } |
| 92 |
| 85 for (ExtensionList::iterator iter = extensions_.begin(); | 93 for (ExtensionList::iterator iter = extensions_.begin(); |
| 86 iter != extensions_.end(); ++iter) { | 94 iter != extensions_.end(); ++iter) { |
| 87 delete *iter; | 95 delete *iter; |
| 88 } | 96 } |
| 89 } | 97 } |
| 90 | 98 |
| 91 bool ExtensionsService::Init() { | 99 bool ExtensionsService::Init() { |
| 92 // Start up the extension event routers. | 100 // Start up the extension event routers. |
| 93 ExtensionBrowserEventRouter::GetInstance()->Init(); | 101 ExtensionBrowserEventRouter::GetInstance()->Init(); |
| 94 | 102 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 PluginService::GetInstance()->AddExtraPluginDir( | 164 PluginService::GetInstance()->AddExtraPluginDir( |
| 157 (*extension)->plugins_dir()); | 165 (*extension)->plugins_dir()); |
| 158 } | 166 } |
| 159 | 167 |
| 160 // Tell UserScriptMaster about any scripts in the loaded extensions. | 168 // Tell UserScriptMaster about any scripts in the loaded extensions. |
| 161 const UserScriptList& scripts = (*extension)->content_scripts(); | 169 const UserScriptList& scripts = (*extension)->content_scripts(); |
| 162 for (UserScriptList::const_iterator script = scripts.begin(); | 170 for (UserScriptList::const_iterator script = scripts.begin(); |
| 163 script != scripts.end(); ++script) { | 171 script != scripts.end(); ++script) { |
| 164 user_script_master_->AddLoneScript(*script); | 172 user_script_master_->AddLoneScript(*script); |
| 165 } | 173 } |
| 174 |
| 175 // Start the process for the master page, if it exists. |
| 176 if ((*extension)->background_url().is_valid()) { |
| 177 CreateBackgroundHost(*extension, (*extension)->background_url()); |
| 178 } |
| 166 } | 179 } |
| 167 | 180 |
| 168 // Since user scripts may have changed, tell UserScriptMaster to kick off | 181 // Since user scripts may have changed, tell UserScriptMaster to kick off |
| 169 // a scan. | 182 // a scan. |
| 170 user_script_master_->StartScan(); | 183 user_script_master_->StartScan(); |
| 171 | 184 |
| 172 NotificationService::current()->Notify( | 185 NotificationService::current()->Notify( |
| 173 NotificationType::EXTENSIONS_LOADED, | 186 NotificationType::EXTENSIONS_LOADED, |
| 174 NotificationService::AllSources(), | 187 NotificationService::AllSources(), |
| 175 Details<ExtensionList>(new_extensions)); | 188 Details<ExtensionList>(new_extensions)); |
| 176 | 189 |
| 177 delete new_extensions; | 190 delete new_extensions; |
| 178 } | 191 } |
| 179 | 192 |
| 180 void ExtensionsService::OnExtensionInstalled(FilePath path, bool update) { | 193 void ExtensionsService::OnExtensionInstalled(FilePath path, bool update) { |
| 181 NotificationService::current()->Notify( | 194 NotificationService::current()->Notify( |
| 182 NotificationType::EXTENSION_INSTALLED, | 195 NotificationType::EXTENSION_INSTALLED, |
| 183 NotificationService::AllSources(), | 196 NotificationService::AllSources(), |
| 184 Details<FilePath>(&path)); | 197 Details<FilePath>(&path)); |
| 185 | 198 |
| 186 // TODO(erikkay): Update UI if appropriate. | 199 // TODO(erikkay): Update UI if appropriate. |
| 187 } | 200 } |
| 188 | 201 |
| 189 ExtensionView* ExtensionsService::CreateView(Extension* extension, | 202 ExtensionView* ExtensionsService::CreateView(Extension* extension, |
| 190 const GURL& url, | 203 const GURL& url, |
| 191 Browser* browser) { | 204 Browser* browser) { |
| 192 return new ExtensionView(extension, url, GetSiteInstanceForURL(url), browser); | 205 return new ExtensionView( |
| 206 new ExtensionHost(extension, GetSiteInstanceForURL(url)), browser, url); |
| 207 } |
| 208 |
| 209 void ExtensionsService::CreateBackgroundHost(Extension* extension, |
| 210 const GURL& url) { |
| 211 ExtensionHost* host = |
| 212 new ExtensionHost(extension, GetSiteInstanceForURL(url)); |
| 213 host->CreateRenderView(url, NULL); // create a RenderViewHost with no view |
| 214 background_hosts_.push_back(host); |
| 193 } | 215 } |
| 194 | 216 |
| 195 SiteInstance* ExtensionsService::GetSiteInstanceForURL(const GURL& url) { | 217 SiteInstance* ExtensionsService::GetSiteInstanceForURL(const GURL& url) { |
| 196 return browsing_instance_->GetSiteInstanceForURL(url); | 218 return browsing_instance_->GetSiteInstanceForURL(url); |
| 197 } | 219 } |
| 198 | 220 |
| 199 | 221 |
| 200 // ExtensionsServicesBackend | 222 // ExtensionsServicesBackend |
| 201 | 223 |
| 202 void ExtensionsServiceBackend::LoadExtensionsFromInstallDirectory( | 224 void ExtensionsServiceBackend::LoadExtensionsFromInstallDirectory( |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 | 876 |
| 855 bool ExtensionsServiceBackend::ShouldInstall(const std::string& id, | 877 bool ExtensionsServiceBackend::ShouldInstall(const std::string& id, |
| 856 const std::string& version) { | 878 const std::string& version) { |
| 857 FilePath dir(install_directory_.AppendASCII(id.c_str())); | 879 FilePath dir(install_directory_.AppendASCII(id.c_str())); |
| 858 std::string current_version; | 880 std::string current_version; |
| 859 if (ReadCurrentVersion(dir, ¤t_version)) { | 881 if (ReadCurrentVersion(dir, ¤t_version)) { |
| 860 return !CheckCurrentVersion(version, current_version, dir); | 882 return !CheckCurrentVersion(version, current_version, dir); |
| 861 } | 883 } |
| 862 return true; | 884 return true; |
| 863 } | 885 } |
| OLD | NEW |