Chromium Code Reviews| 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" | |
| 13 #include "base/utf_string_conversions.h" | |
| 12 #include "base/values.h" | 14 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/crx_installer.h" | 15 #include "chrome/browser/extensions/crx_installer.h" |
| 14 #include "chrome/browser/extensions/extension_install_dialog.h" | 16 #include "chrome/browser/extensions/extension_install_dialog.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 19 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
| 21 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 0, | 75 0, |
| 74 IDS_EXTENSION_BUNDLE_INSTALL_PROMPT_HEADING_EXTENSIONS, | 76 IDS_EXTENSION_BUNDLE_INSTALL_PROMPT_HEADING_EXTENSIONS, |
| 75 IDS_EXTENSION_BUNDLE_INSTALL_PROMPT_HEADING_APPS, | 77 IDS_EXTENSION_BUNDLE_INSTALL_PROMPT_HEADING_APPS, |
| 76 IDS_EXTENSION_BUNDLE_INSTALL_PROMPT_HEADING_EXTENSION_APPS | 78 IDS_EXTENSION_BUNDLE_INSTALL_PROMPT_HEADING_EXTENSION_APPS |
| 77 }, | 79 }, |
| 78 { | 80 { |
| 79 0, | 81 0, |
| 80 IDS_EXTENSION_BUNDLE_INSTALLED_HEADING_EXTENSIONS, | 82 IDS_EXTENSION_BUNDLE_INSTALLED_HEADING_EXTENSIONS, |
| 81 IDS_EXTENSION_BUNDLE_INSTALLED_HEADING_APPS, | 83 IDS_EXTENSION_BUNDLE_INSTALLED_HEADING_APPS, |
| 82 IDS_EXTENSION_BUNDLE_INSTALLED_HEADING_EXTENSION_APPS | 84 IDS_EXTENSION_BUNDLE_INSTALLED_HEADING_EXTENSION_APPS |
| 83 }, | 85 } |
| 84 { IDS_EXTENSION_BUNDLE_ERROR_HEADING, 0, 0, 0 } | |
| 85 }; | 86 }; |
| 86 | 87 |
| 87 } // namespace | 88 } // namespace |
| 88 | 89 |
| 89 // static | 90 // static |
| 90 void BundleInstaller::SetAutoApproveForTesting(bool auto_approve) { | 91 void BundleInstaller::SetAutoApproveForTesting(bool auto_approve) { |
| 91 CHECK(CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)); | 92 CHECK(CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)); |
| 92 g_auto_approve_for_test = auto_approve ? PROCEED : ABORT; | 93 g_auto_approve_for_test = auto_approve ? PROCEED : ABORT; |
| 93 } | 94 } |
| 94 | 95 |
| 95 BundleInstaller::Item::Item() : state(STATE_PENDING) {} | 96 BundleInstaller::Item::Item() : state(STATE_PENDING) {} |
| 96 | 97 |
| 98 string16 BundleInstaller::Item::GetNameForDisplay() { | |
| 99 string16 name = UTF8ToUTF16(localized_name); | |
| 100 base::i18n::AdjustStringForLocaleDirection(&name); | |
| 101 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PERMISSION_LINE, name); | |
| 102 } | |
| 103 | |
| 97 BundleInstaller::BundleInstaller(Profile* profile, | 104 BundleInstaller::BundleInstaller(Profile* profile, |
| 98 const BundleInstaller::ItemList& items) | 105 const BundleInstaller::ItemList& items) |
| 99 : approved_(false), | 106 : approved_(false), |
| 100 browser_(NULL), | 107 browser_(NULL), |
| 101 profile_(profile), | 108 profile_(profile), |
| 102 delegate_(NULL) { | 109 delegate_(NULL) { |
| 103 BrowserList::AddObserver(this); | 110 BrowserList::AddObserver(this); |
| 104 for (size_t i = 0; i < items.size(); ++i) { | 111 for (size_t i = 0; i < items.size(); ++i) { |
| 105 items_[items[i].id] = items[i]; | 112 items_[items[i].id] = items[i]; |
| 106 items_[items[i].id].state = Item::STATE_PENDING; | 113 items_[items[i].id].state = Item::STATE_PENDING; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 profile_, | 162 profile_, |
| 156 this, | 163 this, |
| 157 controller, | 164 controller, |
| 158 i->first, | 165 i->first, |
| 159 WebstoreInstaller::FLAG_NONE); | 166 WebstoreInstaller::FLAG_NONE); |
| 160 installer->Start(); | 167 installer->Start(); |
| 161 } | 168 } |
| 162 } | 169 } |
| 163 | 170 |
| 164 string16 BundleInstaller::GetHeadingTextFor(Item::State state) const { | 171 string16 BundleInstaller::GetHeadingTextFor(Item::State state) const { |
| 165 size_t total = 0; | 172 if (state == Item::STATE_FAILED) { |
| 166 size_t apps = 0; | 173 if (GetItemsWithState(state).size()) |
| 174 return l10n_util::GetStringUTF16(IDS_EXTENSION_BUNDLE_ERROR_HEADING); | |
| 175 return string16(); | |
| 176 } | |
| 167 | 177 |
| 168 // For STATE_FAILED, we can't tell if the items were apps or extensions | 178 size_t total = GetItemsWithState(state).size(); |
| 169 // so we always show the same message. | 179 size_t apps = std::count_if( |
|
Yoyo Zhou
2012/02/28 00:42:39
Why remove this comment?
jstritar
2012/03/05 18:05:08
Re-added.
| |
| 170 if (state == Item::STATE_INSTALLED || state == Item::STATE_PENDING) { | 180 dummy_extensions_.begin(), dummy_extensions_.end(), &IsAppPredicate); |
| 171 total = GetItemsWithState(state).size(); | |
| 172 apps = std::count_if( | |
| 173 dummy_extensions_.begin(), dummy_extensions_.end(), &IsAppPredicate); | |
| 174 } | |
| 175 | 181 |
| 176 bool has_apps = apps > 0; | 182 bool has_apps = apps > 0; |
| 177 bool has_extensions = apps < total; | 183 bool has_extensions = apps < total; |
| 178 size_t index = (has_extensions << 0) + (has_apps << 1); | 184 size_t index = (has_extensions << 0) + (has_apps << 1); |
| 179 | 185 |
| 180 CHECK_LT(static_cast<size_t>(state), arraysize(kHeadingIds)); | 186 CHECK_LT(static_cast<size_t>(state), arraysize(kHeadingIds)); |
| 181 CHECK_LT(index, arraysize(kHeadingIds[state])); | 187 CHECK_LT(index, arraysize(kHeadingIds[state])); |
| 182 | 188 |
| 183 int msg_id = kHeadingIds[state][index]; | 189 int msg_id = kHeadingIds[state][index]; |
| 184 if (!msg_id) | 190 if (!msg_id) |
| 185 return string16(); | 191 return string16(); |
| 186 | 192 |
| 187 return l10n_util::GetStringUTF16(msg_id); | 193 return l10n_util::GetStringUTF16(msg_id); |
| 188 } | 194 } |
| 189 | 195 |
| 190 #if !defined(TOOLKIT_GTK) | 196 #if defined(TOOLKIT_VIEWS) |
|
Yoyo Zhou
2012/02/28 00:42:39
I trust you know what to do with the merge conflic
jstritar
2012/03/05 18:05:08
The other CL landed, so I removed this entire bloc
| |
| 191 // static | 197 // static |
| 192 void BundleInstaller::ShowInstalledBubble( | 198 void BundleInstaller::ShowInstalledBubble( |
| 193 const BundleInstaller* bundle, Browser* browser) { | 199 const BundleInstaller* bundle, Browser* browser) { |
| 194 // TODO(jstritar): provide platform specific implementations. | 200 // TODO(jstritar): provide platform specific implementations. |
| 195 } | 201 } |
| 196 #endif | 202 #endif |
| 197 | 203 |
| 198 void BundleInstaller::ParseManifests() { | 204 void BundleInstaller::ParseManifests() { |
| 199 if (items_.empty()) { | 205 if (items_.empty()) { |
| 200 ReportCanceled(false); | 206 ReportCanceled(false); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 void BundleInstaller::OnExtensionInstallSuccess(const std::string& id) { | 328 void BundleInstaller::OnExtensionInstallSuccess(const std::string& id) { |
| 323 items_[id].state = Item::STATE_INSTALLED; | 329 items_[id].state = Item::STATE_INSTALLED; |
| 324 | 330 |
| 325 ShowInstalledBubbleIfDone(); | 331 ShowInstalledBubbleIfDone(); |
| 326 } | 332 } |
| 327 | 333 |
| 328 void BundleInstaller::OnExtensionInstallFailure(const std::string& id, | 334 void BundleInstaller::OnExtensionInstallFailure(const std::string& id, |
| 329 const std::string& error) { | 335 const std::string& error) { |
| 330 items_[id].state = Item::STATE_FAILED; | 336 items_[id].state = Item::STATE_FAILED; |
| 331 | 337 |
| 332 std::remove_if(dummy_extensions_.begin(), dummy_extensions_.end(), | 338 ExtensionList::iterator i = std::find_if( |
| 333 MatchIdFunctor(id)); | 339 dummy_extensions_.begin(), dummy_extensions_.end(), MatchIdFunctor(id)); |
| 340 CHECK(dummy_extensions_.end() != i); | |
| 341 dummy_extensions_.erase(i); | |
| 334 | 342 |
| 335 ShowInstalledBubbleIfDone(); | 343 ShowInstalledBubbleIfDone(); |
| 336 } | 344 } |
| 337 | 345 |
| 338 void BundleInstaller::OnBrowserAdded(const Browser* browser) { | 346 void BundleInstaller::OnBrowserAdded(const Browser* browser) { |
| 339 } | 347 } |
| 340 | 348 |
| 341 void BundleInstaller::OnBrowserRemoved(const Browser* browser) { | 349 void BundleInstaller::OnBrowserRemoved(const Browser* browser) { |
| 342 if (browser_ == browser) | 350 if (browser_ == browser) |
| 343 browser_ = NULL; | 351 browser_ = NULL; |
| 344 } | 352 } |
| 345 | 353 |
| 346 void BundleInstaller::OnBrowserSetLastActive(const Browser* browser) { | 354 void BundleInstaller::OnBrowserSetLastActive(const Browser* browser) { |
| 347 } | 355 } |
| 348 | 356 |
| 349 } // namespace extensions | 357 } // namespace extensions |
| OLD | NEW |