Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: chrome/browser/extensions/bundle_installer.cc

Issue 9460045: Add Mac interface for installing bundles of extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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;
166 size_t apps = 0;
167
168 // For STATE_FAILED, we can't tell if the items were apps or extensions 172 // For STATE_FAILED, we can't tell if the items were apps or extensions
169 // so we always show the same message. 173 // so we always show the same message.
170 if (state == Item::STATE_INSTALLED || state == Item::STATE_PENDING) { 174 if (state == Item::STATE_FAILED) {
171 total = GetItemsWithState(state).size(); 175 if (GetItemsWithState(state).size())
172 apps = std::count_if( 176 return l10n_util::GetStringUTF16(IDS_EXTENSION_BUNDLE_ERROR_HEADING);
173 dummy_extensions_.begin(), dummy_extensions_.end(), &IsAppPredicate); 177 return string16();
174 } 178 }
175 179
180 size_t total = GetItemsWithState(state).size();
181 size_t apps = std::count_if(
182 dummy_extensions_.begin(), dummy_extensions_.end(), &IsAppPredicate);
183
176 bool has_apps = apps > 0; 184 bool has_apps = apps > 0;
177 bool has_extensions = apps < total; 185 bool has_extensions = apps < total;
178 size_t index = (has_extensions << 0) + (has_apps << 1); 186 size_t index = (has_extensions << 0) + (has_apps << 1);
179 187
180 CHECK_LT(static_cast<size_t>(state), arraysize(kHeadingIds)); 188 CHECK_LT(static_cast<size_t>(state), arraysize(kHeadingIds));
181 CHECK_LT(index, arraysize(kHeadingIds[state])); 189 CHECK_LT(index, arraysize(kHeadingIds[state]));
182 190
183 int msg_id = kHeadingIds[state][index]; 191 int msg_id = kHeadingIds[state][index];
184 if (!msg_id) 192 if (!msg_id)
185 return string16(); 193 return string16();
186 194
187 return l10n_util::GetStringUTF16(msg_id); 195 return l10n_util::GetStringUTF16(msg_id);
188 } 196 }
189 197
190 #if defined(OS_MACOSX)
191 // static
192 void BundleInstaller::ShowInstalledBubble(
193 const BundleInstaller* bundle, Browser* browser) {
194 // TODO(jstritar): provide platform specific implementations.
195 }
196 #endif
197
198 void BundleInstaller::ParseManifests() { 198 void BundleInstaller::ParseManifests() {
199 if (items_.empty()) { 199 if (items_.empty()) {
200 ReportCanceled(false); 200 ReportCanceled(false);
201 return; 201 return;
202 } 202 }
203 203
204 for (ItemMap::iterator i = items_.begin(); i != items_.end(); ++i) { 204 for (ItemMap::iterator i = items_.begin(); i != items_.end(); ++i) {
205 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( 205 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper(
206 this, i->first, i->second.manifest, "", GURL(), NULL); 206 this, i->first, i->second.manifest, "", GURL(), NULL);
207 helper->Start(); 207 helper->Start();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 void BundleInstaller::OnExtensionInstallSuccess(const std::string& id) { 322 void BundleInstaller::OnExtensionInstallSuccess(const std::string& id) {
323 items_[id].state = Item::STATE_INSTALLED; 323 items_[id].state = Item::STATE_INSTALLED;
324 324
325 ShowInstalledBubbleIfDone(); 325 ShowInstalledBubbleIfDone();
326 } 326 }
327 327
328 void BundleInstaller::OnExtensionInstallFailure(const std::string& id, 328 void BundleInstaller::OnExtensionInstallFailure(const std::string& id,
329 const std::string& error) { 329 const std::string& error) {
330 items_[id].state = Item::STATE_FAILED; 330 items_[id].state = Item::STATE_FAILED;
331 331
332 std::remove_if(dummy_extensions_.begin(), dummy_extensions_.end(), 332 ExtensionList::iterator i = std::find_if(
333 MatchIdFunctor(id)); 333 dummy_extensions_.begin(), dummy_extensions_.end(), MatchIdFunctor(id));
334 CHECK(dummy_extensions_.end() != i);
335 dummy_extensions_.erase(i);
334 336
335 ShowInstalledBubbleIfDone(); 337 ShowInstalledBubbleIfDone();
336 } 338 }
337 339
338 void BundleInstaller::OnBrowserAdded(const Browser* browser) { 340 void BundleInstaller::OnBrowserAdded(const Browser* browser) {
339 } 341 }
340 342
341 void BundleInstaller::OnBrowserRemoved(const Browser* browser) { 343 void BundleInstaller::OnBrowserRemoved(const Browser* browser) {
342 if (browser_ == browser) 344 if (browser_ == browser)
343 browser_ = NULL; 345 browser_ = NULL;
344 } 346 }
345 347
346 void BundleInstaller::OnBrowserSetLastActive(const Browser* browser) { 348 void BundleInstaller::OnBrowserSetLastActive(const Browser* browser) {
347 } 349 }
348 350
349 } // namespace extensions 351 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/bundle_installer.h ('k') | chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698