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( |
44 base::DictionaryValue* manifest) { | 45 const BundleInstaller::Item& item, |
| 46 base::DictionaryValue* manifest, |
| 47 content::BrowserContext* browser_context) { |
45 // We require localized names so we can have nice error messages when we can't | 48 // We require localized names so we can have nice error messages when we can't |
46 // parse an extension manifest. | 49 // parse an extension manifest. |
47 CHECK(!item.localized_name.empty()); | 50 CHECK(!item.localized_name.empty()); |
48 | 51 |
49 std::string error; | 52 std::string error; |
50 return Extension::Create(base::FilePath(), | 53 scoped_refptr<Extension> extension = Extension::Create(base::FilePath(), |
51 Manifest::INTERNAL, | 54 Manifest::INTERNAL, |
52 *manifest, | 55 *manifest, |
53 Extension::NO_FLAGS, | 56 Extension::NO_FLAGS, |
54 item.id, | 57 item.id, |
55 &error); | 58 &error); |
| 59 // Initialize permissions so that withheld permissions don't end up in the |
| 60 // install prompt. |
| 61 PermissionsUpdater(browser_context).InitializePermissions( |
| 62 extension.get(), PermissionsUpdater::INIT_FLAG_TRANSIENT); |
| 63 return extension; |
56 } | 64 } |
57 | 65 |
58 bool IsAppPredicate(scoped_refptr<const Extension> extension) { | 66 bool IsAppPredicate(scoped_refptr<const Extension> extension) { |
59 return extension->is_app(); | 67 return extension->is_app(); |
60 } | 68 } |
61 | 69 |
62 struct MatchIdFunctor { | 70 struct MatchIdFunctor { |
63 explicit MatchIdFunctor(const std::string& id) : id(id) {} | 71 explicit MatchIdFunctor(const std::string& id) : id(id) {} |
64 bool operator()(scoped_refptr<const Extension> extension) { | 72 bool operator()(scoped_refptr<const Extension> extension) { |
65 return extension->id() == id; | 73 return extension->id() == id; |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 if (browser_) | 296 if (browser_) |
289 ShowInstalledBubble(this, browser_); | 297 ShowInstalledBubble(this, browser_); |
290 | 298 |
291 ReportComplete(); | 299 ReportComplete(); |
292 } | 300 } |
293 | 301 |
294 void BundleInstaller::OnWebstoreParseSuccess( | 302 void BundleInstaller::OnWebstoreParseSuccess( |
295 const std::string& id, | 303 const std::string& id, |
296 const SkBitmap& icon, | 304 const SkBitmap& icon, |
297 base::DictionaryValue* manifest) { | 305 base::DictionaryValue* manifest) { |
298 dummy_extensions_.push_back(CreateDummyExtension(items_[id], manifest)); | 306 dummy_extensions_.push_back( |
| 307 CreateDummyExtension(items_[id], manifest, profile_)); |
299 parsed_manifests_[id] = linked_ptr<base::DictionaryValue>(manifest); | 308 parsed_manifests_[id] = linked_ptr<base::DictionaryValue>(manifest); |
300 | 309 |
301 ShowPromptIfDoneParsing(); | 310 ShowPromptIfDoneParsing(); |
302 } | 311 } |
303 | 312 |
304 void BundleInstaller::OnWebstoreParseFailure( | 313 void BundleInstaller::OnWebstoreParseFailure( |
305 const std::string& id, | 314 const std::string& id, |
306 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, | 315 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, |
307 const std::string& error_message) { | 316 const std::string& error_message) { |
308 items_[id].state = Item::STATE_FAILED; | 317 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) {} | 354 void BundleInstaller::OnBrowserAdded(Browser* browser) {} |
346 | 355 |
347 void BundleInstaller::OnBrowserRemoved(Browser* browser) { | 356 void BundleInstaller::OnBrowserRemoved(Browser* browser) { |
348 if (browser_ == browser) | 357 if (browser_ == browser) |
349 browser_ = NULL; | 358 browser_ = NULL; |
350 } | 359 } |
351 | 360 |
352 void BundleInstaller::OnBrowserSetLastActive(Browser* browser) {} | 361 void BundleInstaller::OnBrowserSetLastActive(Browser* browser) {} |
353 | 362 |
354 } // namespace extensions | 363 } // namespace extensions |
OLD | NEW |