| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/external_extension_provider_impl.h" | 5 #include "chrome/browser/extensions/external_extension_provider_impl.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 using content::BrowserThread; | 42 using content::BrowserThread; |
| 43 | 43 |
| 44 // Constants for keeping track of extension preferences in a dictionary. | 44 // Constants for keeping track of extension preferences in a dictionary. |
| 45 const char ExternalExtensionProviderImpl::kExternalCrx[] = "external_crx"; | 45 const char ExternalExtensionProviderImpl::kExternalCrx[] = "external_crx"; |
| 46 const char ExternalExtensionProviderImpl::kExternalVersion[] = | 46 const char ExternalExtensionProviderImpl::kExternalVersion[] = |
| 47 "external_version"; | 47 "external_version"; |
| 48 const char ExternalExtensionProviderImpl::kExternalUpdateUrl[] = | 48 const char ExternalExtensionProviderImpl::kExternalUpdateUrl[] = |
| 49 "external_update_url"; | 49 "external_update_url"; |
| 50 const char ExternalExtensionProviderImpl::kSupportedLocales[] = | 50 const char ExternalExtensionProviderImpl::kSupportedLocales[] = |
| 51 "supported_locales"; | 51 "supported_locales"; |
| 52 const char ExternalExtensionProviderImpl::kIsBookmarkApp[] = |
| 53 "is_bookmark_app"; |
| 52 | 54 |
| 53 ExternalExtensionProviderImpl::ExternalExtensionProviderImpl( | 55 ExternalExtensionProviderImpl::ExternalExtensionProviderImpl( |
| 54 VisitorInterface* service, | 56 VisitorInterface* service, |
| 55 ExternalExtensionLoader* loader, | 57 ExternalExtensionLoader* loader, |
| 56 Extension::Location crx_location, | 58 Extension::Location crx_location, |
| 57 Extension::Location download_location, | 59 Extension::Location download_location, |
| 58 int creation_flags) | 60 int creation_flags) |
| 59 : crx_location_(crx_location), | 61 : crx_location_(crx_location), |
| 60 download_location_(download_location), | 62 download_location_(download_location), |
| 61 service_(service), | 63 service_(service), |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 163 |
| 162 if (!locale_supported) { | 164 if (!locale_supported) { |
| 163 unsupported_extensions.insert(extension_id); | 165 unsupported_extensions.insert(extension_id); |
| 164 LOG(INFO) << "Skip installing (or uninstall) external extension: " | 166 LOG(INFO) << "Skip installing (or uninstall) external extension: " |
| 165 << extension_id << " because the extension doesn't support " | 167 << extension_id << " because the extension doesn't support " |
| 166 << "the browser locale."; | 168 << "the browser locale."; |
| 167 continue; | 169 continue; |
| 168 } | 170 } |
| 169 } | 171 } |
| 170 | 172 |
| 173 int creation_flags = creation_flags_; |
| 174 bool is_bookmark_app; |
| 175 if (extension->GetBoolean(kIsBookmarkApp, &is_bookmark_app) && |
| 176 is_bookmark_app) { |
| 177 creation_flags |= Extension::FROM_BOOKMARK; |
| 178 } |
| 179 |
| 171 if (has_external_crx) { | 180 if (has_external_crx) { |
| 172 if (crx_location_ == Extension::INVALID) { | 181 if (crx_location_ == Extension::INVALID) { |
| 173 LOG(WARNING) << "This provider does not support installing external " | 182 LOG(WARNING) << "This provider does not support installing external " |
| 174 << "extensions from crx files."; | 183 << "extensions from crx files."; |
| 175 continue; | 184 continue; |
| 176 } | 185 } |
| 177 if (external_crx.find(FilePath::kParentDirectory) != | 186 if (external_crx.find(FilePath::kParentDirectory) != |
| 178 base::StringPiece::npos) { | 187 base::StringPiece::npos) { |
| 179 LOG(WARNING) << "Path traversal not allowed in path: " | 188 LOG(WARNING) << "Path traversal not allowed in path: " |
| 180 << external_crx.c_str(); | 189 << external_crx.c_str(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 196 | 205 |
| 197 scoped_ptr<Version> version; | 206 scoped_ptr<Version> version; |
| 198 version.reset(Version::GetVersionFromString(external_version)); | 207 version.reset(Version::GetVersionFromString(external_version)); |
| 199 if (!version.get()) { | 208 if (!version.get()) { |
| 200 LOG(WARNING) << "Malformed extension dictionary for extension: " | 209 LOG(WARNING) << "Malformed extension dictionary for extension: " |
| 201 << extension_id.c_str() << ". Invalid version string \"" | 210 << extension_id.c_str() << ". Invalid version string \"" |
| 202 << external_version << "\"."; | 211 << external_version << "\"."; |
| 203 continue; | 212 continue; |
| 204 } | 213 } |
| 205 service_->OnExternalExtensionFileFound(extension_id, version.get(), path, | 214 service_->OnExternalExtensionFileFound(extension_id, version.get(), path, |
| 206 crx_location_, creation_flags_, | 215 crx_location_, creation_flags, |
| 207 auto_acknowledge_); | 216 auto_acknowledge_); |
| 208 } else { // if (has_external_update_url) | 217 } else { // if (has_external_update_url) |
| 209 CHECK(has_external_update_url); // Checking of keys above ensures this. | 218 CHECK(has_external_update_url); // Checking of keys above ensures this. |
| 210 if (download_location_ == Extension::INVALID) { | 219 if (download_location_ == Extension::INVALID) { |
| 211 LOG(WARNING) << "This provider does not support installing external " | 220 LOG(WARNING) << "This provider does not support installing external " |
| 212 << "extensions from update URLs."; | 221 << "extensions from update URLs."; |
| 213 continue; | 222 continue; |
| 214 } | 223 } |
| 215 GURL update_url(external_update_url); | 224 GURL update_url(external_update_url); |
| 216 if (!update_url.is_valid()) { | 225 if (!update_url.is_valid()) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 236 } | 245 } |
| 237 | 246 |
| 238 void ExternalExtensionProviderImpl::ServiceShutdown() { | 247 void ExternalExtensionProviderImpl::ServiceShutdown() { |
| 239 service_ = NULL; | 248 service_ = NULL; |
| 240 } | 249 } |
| 241 | 250 |
| 242 bool ExternalExtensionProviderImpl::IsReady() const { | 251 bool ExternalExtensionProviderImpl::IsReady() const { |
| 243 return ready_; | 252 return ready_; |
| 244 } | 253 } |
| 245 | 254 |
| 246 int ExternalExtensionProviderImpl::GetCreationFlags() const { | |
| 247 return creation_flags_; | |
| 248 } | |
| 249 | |
| 250 bool ExternalExtensionProviderImpl::HasExtension( | 255 bool ExternalExtensionProviderImpl::HasExtension( |
| 251 const std::string& id) const { | 256 const std::string& id) const { |
| 252 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 257 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 253 CHECK(prefs_.get()); | 258 CHECK(prefs_.get()); |
| 254 CHECK(ready_); | 259 CHECK(ready_); |
| 255 return prefs_->HasKey(id); | 260 return prefs_->HasKey(id); |
| 256 } | 261 } |
| 257 | 262 |
| 258 bool ExternalExtensionProviderImpl::GetExtensionDetails( | 263 bool ExternalExtensionProviderImpl::GetExtensionDetails( |
| 259 const std::string& id, Extension::Location* location, | 264 const std::string& id, Extension::Location* location, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 provider_list->push_back( | 377 provider_list->push_back( |
| 373 linked_ptr<ExternalExtensionProviderInterface>( | 378 linked_ptr<ExternalExtensionProviderInterface>( |
| 374 new default_apps::Provider( | 379 new default_apps::Provider( |
| 375 profile, | 380 profile, |
| 376 service, | 381 service, |
| 377 new ExternalPrefExtensionLoader( | 382 new ExternalPrefExtensionLoader( |
| 378 chrome::DIR_DEFAULT_APPS, | 383 chrome::DIR_DEFAULT_APPS, |
| 379 ExternalPrefExtensionLoader::NONE), | 384 ExternalPrefExtensionLoader::NONE), |
| 380 Extension::EXTERNAL_PREF, | 385 Extension::EXTERNAL_PREF, |
| 381 Extension::INVALID, | 386 Extension::INVALID, |
| 382 Extension::FROM_BOOKMARK))); | 387 Extension::FROM_WEBSTORE))); |
| 383 #endif | 388 #endif |
| 384 | 389 |
| 385 #if defined(OS_CHROMEOS) | 390 #if defined(OS_CHROMEOS) |
| 386 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 391 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| 387 policy::BrowserPolicyConnector* connector = | 392 policy::BrowserPolicyConnector* connector = |
| 388 g_browser_process->browser_policy_connector(); | 393 g_browser_process->browser_policy_connector(); |
| 389 if (user_manager && user_manager->IsLoggedInAsDemoUser() && | 394 if (user_manager && user_manager->IsLoggedInAsDemoUser() && |
| 390 connector->GetDeviceMode() == policy::DEVICE_MODE_KIOSK && | 395 connector->GetDeviceMode() == policy::DEVICE_MODE_KIOSK && |
| 391 connector->GetAppPackUpdater()) { | 396 connector->GetAppPackUpdater()) { |
| 392 provider_list->push_back( | 397 provider_list->push_back( |
| 393 linked_ptr<ExternalExtensionProviderInterface>( | 398 linked_ptr<ExternalExtensionProviderInterface>( |
| 394 new ExternalExtensionProviderImpl( | 399 new ExternalExtensionProviderImpl( |
| 395 service, | 400 service, |
| 396 connector->GetAppPackUpdater()->CreateExternalExtensionLoader(), | 401 connector->GetAppPackUpdater()->CreateExternalExtensionLoader(), |
| 397 Extension::EXTERNAL_PREF, | 402 Extension::EXTERNAL_PREF, |
| 398 Extension::INVALID, | 403 Extension::INVALID, |
| 399 Extension::NO_FLAGS))); | 404 Extension::NO_FLAGS))); |
| 400 } | 405 } |
| 401 #endif | 406 #endif |
| 402 } | 407 } |
| OLD | NEW |