| 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/bundle_installer.h" | 5 #include "chrome/browser/extensions/bundle_installer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/extensions/crx_installer.h" | 15 #include "chrome/browser/extensions/crx_installer.h" |
| 16 #include "chrome/browser/extensions/permissions_updater.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
| 19 #include "chrome/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
| 23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 24 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
| 25 #include "extensions/common/permissions/permission_set.h" | 26 #include "extensions/common/permissions/permission_set.h" |
| 26 #include "extensions/common/permissions/permissions_data.h" | 27 #include "extensions/common/permissions/permissions_data.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 28 | 29 |
| 29 namespace extensions { | 30 namespace extensions { |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 enum AutoApproveForTest { | 34 enum AutoApproveForTest { |
| 34 DO_NOT_SKIP = 0, | 35 DO_NOT_SKIP = 0, |
| 35 PROCEED, | 36 PROCEED, |
| 36 ABORT | 37 ABORT |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 AutoApproveForTest g_auto_approve_for_test = DO_NOT_SKIP; | 40 AutoApproveForTest g_auto_approve_for_test = DO_NOT_SKIP; |
| 40 | 41 |
| 41 // Creates a dummy extension and sets the manifest's name to the item's | 42 // Creates a dummy extension and sets the manifest's name to the item's |
| 42 // localized name. | 43 // localized name. |
| 43 scoped_refptr<Extension> CreateDummyExtension(const BundleInstaller::Item& item, | 44 scoped_refptr<Extension> CreateDummyExtension(const BundleInstaller::Item& item, |
| 44 base::DictionaryValue* manifest) { | 45 base::DictionaryValue* manifest, |
| 46 Profile* profile) { |
| 45 // We require localized names so we can have nice error messages when we can't | 47 // We require localized names so we can have nice error messages when we can't |
| 46 // parse an extension manifest. | 48 // parse an extension manifest. |
| 47 CHECK(!item.localized_name.empty()); | 49 CHECK(!item.localized_name.empty()); |
| 48 | 50 |
| 49 std::string error; | 51 std::string error; |
| 50 return Extension::Create(base::FilePath(), | 52 scoped_refptr<Extension> extension = Extension::Create(base::FilePath(), |
| 51 Manifest::INTERNAL, | 53 Manifest::INTERNAL, |
| 52 *manifest, | 54 *manifest, |
| 53 Extension::NO_FLAGS, | 55 Extension::NO_FLAGS, |
| 54 item.id, | 56 item.id, |
| 55 &error); | 57 &error); |
| 58 // Initialize permissions so that withheld permissions don't end up in the |
| 59 // install prompt. |
| 60 PermissionsUpdater(profile).InitializePermissions( |
| 61 extension.get(), PermissionsUpdater::INIT_FLAG_TRANSIENT); |
| 62 return extension; |
| 56 } | 63 } |
| 57 | 64 |
| 58 bool IsAppPredicate(scoped_refptr<const Extension> extension) { | 65 bool IsAppPredicate(scoped_refptr<const Extension> extension) { |
| 59 return extension->is_app(); | 66 return extension->is_app(); |
| 60 } | 67 } |
| 61 | 68 |
| 62 struct MatchIdFunctor { | 69 struct MatchIdFunctor { |
| 63 explicit MatchIdFunctor(const std::string& id) : id(id) {} | 70 explicit MatchIdFunctor(const std::string& id) : id(id) {} |
| 64 bool operator()(scoped_refptr<const Extension> extension) { | 71 bool operator()(scoped_refptr<const Extension> extension) { |
| 65 return extension->id() == id; | 72 return extension->id() == id; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 if (browser_) | 295 if (browser_) |
| 289 ShowInstalledBubble(this, browser_); | 296 ShowInstalledBubble(this, browser_); |
| 290 | 297 |
| 291 ReportComplete(); | 298 ReportComplete(); |
| 292 } | 299 } |
| 293 | 300 |
| 294 void BundleInstaller::OnWebstoreParseSuccess( | 301 void BundleInstaller::OnWebstoreParseSuccess( |
| 295 const std::string& id, | 302 const std::string& id, |
| 296 const SkBitmap& icon, | 303 const SkBitmap& icon, |
| 297 base::DictionaryValue* manifest) { | 304 base::DictionaryValue* manifest) { |
| 298 dummy_extensions_.push_back(CreateDummyExtension(items_[id], manifest)); | 305 dummy_extensions_.push_back( |
| 306 CreateDummyExtension(items_[id], manifest, profile_)); |
| 299 parsed_manifests_[id] = linked_ptr<base::DictionaryValue>(manifest); | 307 parsed_manifests_[id] = linked_ptr<base::DictionaryValue>(manifest); |
| 300 | 308 |
| 301 ShowPromptIfDoneParsing(); | 309 ShowPromptIfDoneParsing(); |
| 302 } | 310 } |
| 303 | 311 |
| 304 void BundleInstaller::OnWebstoreParseFailure( | 312 void BundleInstaller::OnWebstoreParseFailure( |
| 305 const std::string& id, | 313 const std::string& id, |
| 306 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, | 314 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, |
| 307 const std::string& error_message) { | 315 const std::string& error_message) { |
| 308 items_[id].state = Item::STATE_FAILED; | 316 items_[id].state = Item::STATE_FAILED; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 void BundleInstaller::OnBrowserAdded(Browser* browser) {} | 353 void BundleInstaller::OnBrowserAdded(Browser* browser) {} |
| 346 | 354 |
| 347 void BundleInstaller::OnBrowserRemoved(Browser* browser) { | 355 void BundleInstaller::OnBrowserRemoved(Browser* browser) { |
| 348 if (browser_ == browser) | 356 if (browser_ == browser) |
| 349 browser_ = NULL; | 357 browser_ = NULL; |
| 350 } | 358 } |
| 351 | 359 |
| 352 void BundleInstaller::OnBrowserSetLastActive(Browser* browser) {} | 360 void BundleInstaller::OnBrowserSetLastActive(Browser* browser) {} |
| 353 | 361 |
| 354 } // namespace extensions | 362 } // namespace extensions |
| OLD | NEW |