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

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 16 matching lines...) Expand all
27 #include "chrome/common/extensions/extension_error_utils.h" 27 #include "chrome/common/extensions/extension_error_utils.h"
28 #include "chrome/common/extensions/extension_l10n_util.h" 28 #include "chrome/common/extensions/extension_l10n_util.h"
29 #include "chrome/common/net/gaia/gaia_constants.h" 29 #include "chrome/common/net/gaia/gaia_constants.h"
30 #include "content/public/browser/notification_details.h" 30 #include "content/public/browser/notification_details.h"
31 #include "content/public/browser/notification_source.h" 31 #include "content/public/browser/notification_source.h"
32 #include "content/public/browser/web_contents.h" 32 #include "content/public/browser/web_contents.h"
33 #include "grit/chromium_strings.h" 33 #include "grit/chromium_strings.h"
34 #include "grit/generated_resources.h" 34 #include "grit/generated_resources.h"
35 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
36 36
37 using webstore::BundleInstaller;
38 using webstore::Item;
39 using webstore::ItemList;
40
37 namespace { 41 namespace {
38 42
39 const char kAppInstallBubbleKey[] = "appInstallBubble"; 43 const char kAppInstallBubbleKey[] = "appInstallBubble";
40 const char kIconDataKey[] = "iconData"; 44 const char kIconDataKey[] = "iconData";
41 const char kIconUrlKey[] = "iconUrl"; 45 const char kIconUrlKey[] = "iconUrl";
42 const char kIdKey[] = "id"; 46 const char kIdKey[] = "id";
43 const char kLocalizedNameKey[] = "localizedName"; 47 const char kLocalizedNameKey[] = "localizedName";
44 const char kLoginKey[] = "login"; 48 const char kLoginKey[] = "login";
45 const char kManifestKey[] = "manifest"; 49 const char kManifestKey[] = "manifest";
46 const char kTokenKey[] = "token"; 50 const char kTokenKey[] = "token";
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 void WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting( 131 void WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting(
128 WebstoreInstaller::Delegate* delegate) { 132 WebstoreInstaller::Delegate* delegate) {
129 test_webstore_installer_delegate = delegate; 133 test_webstore_installer_delegate = delegate;
130 } 134 }
131 135
132 // static 136 // static
133 void WebstorePrivateApi::SetTrustTestIDsForTesting(bool allow) { 137 void WebstorePrivateApi::SetTrustTestIDsForTesting(bool allow) {
134 trust_test_ids = allow; 138 trust_test_ids = allow;
135 } 139 }
136 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 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.
155
156 bundle_->PromptForApproval(this);
157 return true;
158 }
159
160 bool InstallBundleFunction::ReadBundleInfo(ListValue* extensions,
161 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 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 this);
184 }
185
186 void InstallBundleFunction::OnBundleInstallCanceled(bool user_initiated) {
187 if (user_initiated)
188 error_ = "user_canceled";
189 else
190 error_ = "unknown_error";
191
192 SendResponse(false);
193
194 Release(); // Balanced in RunImpl().
195 }
196
197 void InstallBundleFunction::OnBundleInstallCompleted() {
198 SendResponse(true);
199
200 Release(); // Balanced in RunImpl().
201 }
202
137 BeginInstallWithManifestFunction::BeginInstallWithManifestFunction() 203 BeginInstallWithManifestFunction::BeginInstallWithManifestFunction()
138 : use_app_installed_bubble_(false) {} 204 : use_app_installed_bubble_(false) {}
139 205
140 BeginInstallWithManifestFunction::~BeginInstallWithManifestFunction() {} 206 BeginInstallWithManifestFunction::~BeginInstallWithManifestFunction() {}
141 207
142 bool BeginInstallWithManifestFunction::RunImpl() { 208 bool BeginInstallWithManifestFunction::RunImpl() {
143 DictionaryValue* details = NULL; 209 DictionaryValue* details = NULL;
144 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); 210 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
145 CHECK(details); 211 CHECK(details);
146 212
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 SendResponse(true); 586 SendResponse(true);
521 } else { 587 } else {
522 // Matched with a Release in OnGpuInfoUpdate. 588 // Matched with a Release in OnGpuInfoUpdate.
523 AddRef(); 589 AddRef();
524 590
525 manager->AddObserver(this); 591 manager->AddObserver(this);
526 manager->RequestCompleteGpuInfoIfNeeded(); 592 manager->RequestCompleteGpuInfoIfNeeded();
527 } 593 }
528 return true; 594 return true;
529 } 595 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698