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

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

Issue 9414013: Add a webstore API for installing bundles of extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 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/extension_webstore_private_api.h" 5 #include "chrome/browser/extensions/extension_webstore_private_api.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 18 matching lines...) Expand all
29 #include "chrome/common/net/gaia/gaia_constants.h" 29 #include "chrome/common/net/gaia/gaia_constants.h"
30 #include "content/public/browser/gpu_data_manager.h" 30 #include "content/public/browser/gpu_data_manager.h"
31 #include "content/public/browser/notification_details.h" 31 #include "content/public/browser/notification_details.h"
32 #include "content/public/browser/notification_source.h" 32 #include "content/public/browser/notification_source.h"
33 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
34 #include "grit/chromium_strings.h" 34 #include "grit/chromium_strings.h"
35 #include "grit/generated_resources.h" 35 #include "grit/generated_resources.h"
36 #include "ui/base/l10n/l10n_util.h" 36 #include "ui/base/l10n/l10n_util.h"
37 37
38 using content::GpuDataManager; 38 using content::GpuDataManager;
39 using extensions::BundleInstaller;
39 40
40 namespace { 41 namespace {
41 42
42 const char kAppInstallBubbleKey[] = "appInstallBubble"; 43 const char kAppInstallBubbleKey[] = "appInstallBubble";
43 const char kIconDataKey[] = "iconData"; 44 const char kIconDataKey[] = "iconData";
44 const char kIconUrlKey[] = "iconUrl"; 45 const char kIconUrlKey[] = "iconUrl";
45 const char kIdKey[] = "id"; 46 const char kIdKey[] = "id";
46 const char kLocalizedNameKey[] = "localizedName"; 47 const char kLocalizedNameKey[] = "localizedName";
47 const char kLoginKey[] = "login"; 48 const char kLoginKey[] = "login";
48 const char kManifestKey[] = "manifest"; 49 const char kManifestKey[] = "manifest";
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 void WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting( 131 void WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting(
131 WebstoreInstaller::Delegate* delegate) { 132 WebstoreInstaller::Delegate* delegate) {
132 test_webstore_installer_delegate = delegate; 133 test_webstore_installer_delegate = delegate;
133 } 134 }
134 135
135 // static 136 // static
136 void WebstorePrivateApi::SetTrustTestIDsForTesting(bool allow) { 137 void WebstorePrivateApi::SetTrustTestIDsForTesting(bool allow) {
137 trust_test_ids = allow; 138 trust_test_ids = allow;
138 } 139 }
139 140
141 InstallBundleFunction::InstallBundleFunction() {}
142 InstallBundleFunction::~InstallBundleFunction() {}
143
144 bool InstallBundleFunction::RunImpl() {
145 ListValue* extensions = NULL;
146 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &extensions));
147
148 BundleInstaller::ItemList items;
149 if (!ReadBundleInfo(extensions, &items))
150 return false;
151
152 bundle_ = new BundleInstaller(profile(), items);
153
154 AddRef(); // Balanced in OnBundleInstallApproved and OnBundleInstallCanceled.
Yoyo Zhou 2012/02/22 00:20:26 in OnBundleInstallCompleted
jstritar 2012/02/22 15:45:48 Thanks for catching all those... forgot to change
155
156 bundle_->PromptForApproval(this);
157 return true;
158 }
159
160 bool InstallBundleFunction::ReadBundleInfo(ListValue* extensions,
161 BundleInstaller::ItemList* items) {
162 for (size_t i = 0; i < extensions->GetSize(); ++i) {
163 DictionaryValue* details = NULL;
164 EXTENSION_FUNCTION_VALIDATE(extensions->GetDictionary(i, &details));
165
166 BundleInstaller::Item item;
167 EXTENSION_FUNCTION_VALIDATE(details->GetString(
168 kIdKey, &item.id));
169 EXTENSION_FUNCTION_VALIDATE(details->GetString(
170 kManifestKey, &item.manifest));
171 EXTENSION_FUNCTION_VALIDATE(details->GetString(
172 kLocalizedNameKey, &item.localized_name));
173
174 items->push_back(item);
175 }
176
177 return true;
178 }
179
180 void InstallBundleFunction::OnBundleInstallApproved() {
181 bundle_->CompleteInstall(
182 &(dispatcher()->delegate()->GetAssociatedWebContents()->GetController()),
183 GetCurrentBrowser(),
184 this);
185 }
186
187 void InstallBundleFunction::OnBundleInstallCanceled(bool user_initiated) {
188 if (user_initiated)
189 error_ = "user_canceled";
190 else
191 error_ = "unknown_error";
192
193 SendResponse(false);
194
195 Release(); // Balanced in RunImpl().
196 }
197
198 void InstallBundleFunction::OnBundleInstallCompleted() {
199 SendResponse(true);
200
201 Release(); // Balanced in RunImpl().
202 }
203
140 BeginInstallWithManifestFunction::BeginInstallWithManifestFunction() 204 BeginInstallWithManifestFunction::BeginInstallWithManifestFunction()
141 : use_app_installed_bubble_(false) {} 205 : use_app_installed_bubble_(false) {}
142 206
143 BeginInstallWithManifestFunction::~BeginInstallWithManifestFunction() {} 207 BeginInstallWithManifestFunction::~BeginInstallWithManifestFunction() {}
144 208
145 bool BeginInstallWithManifestFunction::RunImpl() { 209 bool BeginInstallWithManifestFunction::RunImpl() {
146 DictionaryValue* details = NULL; 210 DictionaryValue* details = NULL;
147 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); 211 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
148 CHECK(details); 212 CHECK(details);
149 213
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 SendResponse(true); 587 SendResponse(true);
524 } else { 588 } else {
525 // Matched with a Release in OnGpuInfoUpdate. 589 // Matched with a Release in OnGpuInfoUpdate.
526 AddRef(); 590 AddRef();
527 591
528 manager->AddObserver(this); 592 manager->AddObserver(this);
529 manager->RequestCompleteGpuInfoIfNeeded(); 593 manager->RequestCompleteGpuInfoIfNeeded();
530 } 594 }
531 return true; 595 return true;
532 } 596 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698