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

Side by Side Diff: chrome/browser/extensions/api/webstore_private/webstore_private_api.cc

Issue 885443010: WebstorePrivate extension API cleanup, part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@testext_permission_prompt
Patch Set: ALL the functions! Created 5 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
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/api/webstore_private/webstore_private_api.h" 5 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/command_line.h"
9 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
10 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
11 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
12 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "base/values.h" 13 #include "base/values.h"
17 #include "base/version.h" 14 #include "base/version.h"
18 #include "chrome/browser/about_flags.h"
19 #include "chrome/browser/apps/ephemeral_app_launcher.h" 15 #include "chrome/browser/apps/ephemeral_app_launcher.h"
20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/chrome_notification_types.h"
22 #include "chrome/browser/extensions/crx_installer.h" 16 #include "chrome/browser/extensions/crx_installer.h"
23 #include "chrome/browser/extensions/extension_install_ui_util.h" 17 #include "chrome/browser/extensions/extension_install_ui_util.h"
24 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
25 #include "chrome/browser/extensions/install_tracker.h" 19 #include "chrome/browser/extensions/install_tracker.h"
26 #include "chrome/browser/extensions/webstore_installer.h"
27 #include "chrome/browser/gpu/gpu_feature_checker.h" 20 #include "chrome/browser/gpu/gpu_feature_checker.h"
28 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/signin/signin_manager_factory.h" 22 #include "chrome/browser/signin/signin_manager_factory.h"
30 #include "chrome/browser/sync/profile_sync_service.h"
31 #include "chrome/browser/sync/profile_sync_service_factory.h"
32 #include "chrome/browser/ui/app_list/app_list_service.h" 23 #include "chrome/browser/ui/app_list/app_list_service.h"
33 #include "chrome/browser/ui/app_list/app_list_util.h" 24 #include "chrome/browser/ui/app_list/app_list_util.h"
34 #include "chrome/common/extensions/extension_constants.h" 25 #include "chrome/common/extensions/extension_constants.h"
35 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
36 #include "components/crx_file/id_util.h" 27 #include "components/crx_file/id_util.h"
37 #include "components/signin/core/browser/signin_manager.h" 28 #include "components/signin/core/browser/signin_manager.h"
38 #include "content/public/browser/gpu_data_manager.h"
39 #include "content/public/browser/notification_details.h"
40 #include "content/public/browser/notification_source.h"
41 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
42 #include "extensions/browser/extension_function_dispatcher.h" 30 #include "extensions/browser/extension_function_dispatcher.h"
43 #include "extensions/browser/extension_prefs.h"
44 #include "extensions/browser/extension_registry.h" 31 #include "extensions/browser/extension_registry.h"
45 #include "extensions/browser/extension_system.h" 32 #include "extensions/browser/extension_system.h"
46 #include "extensions/browser/extension_util.h" 33 #include "extensions/browser/extension_util.h"
47 #include "extensions/common/error_utils.h"
48 #include "extensions/common/extension.h" 34 #include "extensions/common/extension.h"
49 #include "ui/base/l10n/l10n_util.h"
50
51 using content::GpuDataManager;
52 35
53 namespace extensions { 36 namespace extensions {
54 37
55 namespace BeginInstallWithManifest3 = 38 namespace BeginInstallWithManifest3 =
56 api::webstore_private::BeginInstallWithManifest3; 39 api::webstore_private::BeginInstallWithManifest3;
40 namespace CompleteInstall = api::webstore_private::CompleteInstall;
41 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin;
57 namespace GetEphemeralAppsEnabled = 42 namespace GetEphemeralAppsEnabled =
58 api::webstore_private::GetEphemeralAppsEnabled; 43 api::webstore_private::GetEphemeralAppsEnabled;
59 namespace CompleteInstall = api::webstore_private::CompleteInstall;
60 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin;
61 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; 44 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled;
62 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; 45 namespace GetStoreLogin = api::webstore_private::GetStoreLogin;
63 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; 46 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus;
64 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; 47 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode;
65 namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp; 48 namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp;
66 namespace LaunchEphemeralAppResult = LaunchEphemeralApp::Results; 49 namespace LaunchEphemeralAppResult = LaunchEphemeralApp::Results;
67 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; 50 namespace SetStoreLogin = api::webstore_private::SetStoreLogin;
68 51
69 namespace { 52 namespace {
70 53
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 141 }
159 142
160 // static 143 // static
161 scoped_ptr<WebstoreInstaller::Approval> 144 scoped_ptr<WebstoreInstaller::Approval>
162 WebstorePrivateApi::PopApprovalForTesting( 145 WebstorePrivateApi::PopApprovalForTesting(
163 Profile* profile, const std::string& extension_id) { 146 Profile* profile, const std::string& extension_id) {
164 return g_pending_approvals.Get().PopApproval(profile, extension_id); 147 return g_pending_approvals.Get().PopApproval(profile, extension_id);
165 } 148 }
166 149
167 WebstorePrivateBeginInstallWithManifest3Function:: 150 WebstorePrivateBeginInstallWithManifest3Function::
168 WebstorePrivateBeginInstallWithManifest3Function() { 151 WebstorePrivateBeginInstallWithManifest3Function() : chrome_details_(this) {
169 } 152 }
170 153
171 WebstorePrivateBeginInstallWithManifest3Function:: 154 WebstorePrivateBeginInstallWithManifest3Function::
172 ~WebstorePrivateBeginInstallWithManifest3Function() { 155 ~WebstorePrivateBeginInstallWithManifest3Function() {
173 } 156 }
174 157
175 bool WebstorePrivateBeginInstallWithManifest3Function::RunAsync() { 158 ExtensionFunction::ResponseAction
159 WebstorePrivateBeginInstallWithManifest3Function::Run() {
176 params_ = BeginInstallWithManifest3::Params::Create(*args_); 160 params_ = BeginInstallWithManifest3::Params::Create(*args_);
177 EXTENSION_FUNCTION_VALIDATE(params_); 161 EXTENSION_FUNCTION_VALIDATE(params_);
178 162
179 if (!crx_file::id_util::IdIsValid(params_->details.id)) { 163 if (!crx_file::id_util::IdIsValid(params_->details.id))
180 SetResultCode(INVALID_ID); 164 return RespondNow(BuildResponseForError(INVALID_ID, kInvalidIdError));
181 error_ = kInvalidIdError;
182 return false;
183 }
184 165
185 if (params_->details.icon_data && params_->details.icon_url) { 166 if (params_->details.icon_data && params_->details.icon_url) {
186 SetResultCode(ICON_ERROR); 167 return RespondNow(BuildResponseForError(ICON_ERROR,
187 error_ = kCannotSpecifyIconDataAndUrlError; 168 kCannotSpecifyIconDataAndUrlError));
188 return false;
189 } 169 }
190 170
191 GURL icon_url; 171 GURL icon_url;
192 if (params_->details.icon_url) { 172 if (params_->details.icon_url) {
193 std::string tmp_url; 173 std::string tmp_url;
194 icon_url = source_url().Resolve(*params_->details.icon_url); 174 icon_url = source_url().Resolve(*params_->details.icon_url);
195 if (!icon_url.is_valid()) { 175 if (!icon_url.is_valid()) {
196 SetResultCode(INVALID_ICON_URL); 176 return RespondNow(BuildResponseForError(INVALID_ICON_URL,
197 error_ = kInvalidIconUrlError; 177 kInvalidIconUrlError));
198 return false;
199 } 178 }
200 } 179 }
201 180
202 if (params_->details.authuser) { 181 if (params_->details.authuser) {
203 authuser_ = *params_->details.authuser; 182 authuser_ = *params_->details.authuser;
204 } 183 }
205 184
206 std::string icon_data = params_->details.icon_data ? 185 std::string icon_data = params_->details.icon_data ?
207 *params_->details.icon_data : std::string(); 186 *params_->details.icon_data : std::string();
208 187
209 Profile* profile = GetProfile(); 188 InstallTracker* tracker = InstallTracker::Get(browser_context());
210 InstallTracker* tracker = InstallTracker::Get(profile);
211 DCHECK(tracker); 189 DCHECK(tracker);
212 if (util::IsExtensionInstalledPermanently(params_->details.id, profile) || 190 if (util::IsExtensionInstalledPermanently(params_->details.id,
191 browser_context()) ||
213 tracker->GetActiveInstall(params_->details.id)) { 192 tracker->GetActiveInstall(params_->details.id)) {
214 SetResultCode(ALREADY_INSTALLED); 193 return RespondNow(BuildResponseForError(ALREADY_INSTALLED,
215 error_ = kAlreadyInstalledError; 194 kAlreadyInstalledError));
216 return false;
217 } 195 }
218 ActiveInstallData install_data(params_->details.id); 196 ActiveInstallData install_data(params_->details.id);
219 scoped_active_install_.reset(new ScopedActiveInstall(tracker, install_data)); 197 scoped_active_install_.reset(new ScopedActiveInstall(tracker, install_data));
220 198
221 net::URLRequestContextGetter* context_getter = NULL; 199 net::URLRequestContextGetter* context_getter = NULL;
222 if (!icon_url.is_empty()) 200 if (!icon_url.is_empty())
223 context_getter = GetProfile()->GetRequestContext(); 201 context_getter = browser_context()->GetRequestContext();
224 202
225 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( 203 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper(
226 this, params_->details.id, params_->details.manifest, icon_data, icon_url, 204 this, params_->details.id, params_->details.manifest, icon_data, icon_url,
227 context_getter); 205 context_getter);
228 206
229 // The helper will call us back via OnWebstoreParseSuccess or 207 // The helper will call us back via OnWebstoreParseSuccess or
230 // OnWebstoreParseFailure. 208 // OnWebstoreParseFailure.
231 helper->Start(); 209 helper->Start();
232 210
233 // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure. 211 // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure.
234 AddRef(); 212 AddRef();
235 213
236 // The response is sent asynchronously in OnWebstoreParseSuccess/ 214 // The response is sent asynchronously in OnWebstoreParseSuccess/
237 // OnWebstoreParseFailure. 215 // OnWebstoreParseFailure.
238 return true; 216 return RespondLater();
239 }
240
241 const char* WebstorePrivateBeginInstallWithManifest3Function::
242 ResultCodeToString(ResultCode code) {
243 switch (code) {
244 case ERROR_NONE:
245 return "";
246 case UNKNOWN_ERROR:
247 return "unknown_error";
248 case USER_CANCELLED:
249 return "user_cancelled";
250 case MANIFEST_ERROR:
251 return "manifest_error";
252 case ICON_ERROR:
253 return "icon_error";
254 case INVALID_ID:
255 return "invalid_id";
256 case PERMISSION_DENIED:
257 return "permission_denied";
258 case INVALID_ICON_URL:
259 return "invalid_icon_url";
260 case ALREADY_INSTALLED:
261 return "already_installed";
262 }
263 NOTREACHED();
264 return "";
265 }
266
267 void WebstorePrivateBeginInstallWithManifest3Function::SetResultCode(
268 ResultCode code) {
269 results_ = BeginInstallWithManifest3::Results::Create(
270 ResultCodeToString(code));
271 } 217 }
272 218
273 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseSuccess( 219 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseSuccess(
274 const std::string& id, 220 const std::string& id,
275 const SkBitmap& icon, 221 const SkBitmap& icon,
276 base::DictionaryValue* parsed_manifest) { 222 base::DictionaryValue* parsed_manifest) {
277 CHECK_EQ(params_->details.id, id); 223 CHECK_EQ(params_->details.id, id);
278 CHECK(parsed_manifest); 224 CHECK(parsed_manifest);
279 icon_ = icon; 225 icon_ = icon;
280 parsed_manifest_.reset(parsed_manifest); 226 parsed_manifest_.reset(parsed_manifest);
(...skipping 29 matching lines...) Expand all
310 // Control flow finishes up in InstallUIProceed or InstallUIAbort. 256 // Control flow finishes up in InstallUIProceed or InstallUIAbort.
311 } 257 }
312 258
313 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseFailure( 259 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseFailure(
314 const std::string& id, 260 const std::string& id,
315 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, 261 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code,
316 const std::string& error_message) { 262 const std::string& error_message) {
317 CHECK_EQ(params_->details.id, id); 263 CHECK_EQ(params_->details.id, id);
318 264
319 // Map from WebstoreInstallHelper's result codes to ours. 265 // Map from WebstoreInstallHelper's result codes to ours.
266 ResultCode code = ERROR_NONE;
320 switch (result_code) { 267 switch (result_code) {
321 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: 268 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR:
322 SetResultCode(UNKNOWN_ERROR); 269 code = UNKNOWN_ERROR;
323 break; 270 break;
324 case WebstoreInstallHelper::Delegate::ICON_ERROR: 271 case WebstoreInstallHelper::Delegate::ICON_ERROR:
325 SetResultCode(ICON_ERROR); 272 code = ICON_ERROR;
326 break; 273 break;
327 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: 274 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR:
328 SetResultCode(MANIFEST_ERROR); 275 code = MANIFEST_ERROR;
329 break; 276 break;
330 default:
331 CHECK(false);
332 } 277 }
333 error_ = error_message; 278 DCHECK_NE(code, ERROR_NONE);
334 SendResponse(false); 279 Respond(BuildResponseForError(code, error_message));
335 280
336 // Matches the AddRef in RunAsync(). 281 // Matches the AddRef in Run().
337 Release(); 282 Release();
338 } 283 }
339 284
340 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIProceed() { 285 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIProceed() {
341 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in 286 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in
342 // the future we may also want to add time-based expiration, where a whitelist 287 // the future we may also want to add time-based expiration, where a whitelist
343 // entry is only valid for some number of minutes. 288 // entry is only valid for some number of minutes.
344 scoped_ptr<WebstoreInstaller::Approval> approval( 289 scoped_ptr<WebstoreInstaller::Approval> approval(
345 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( 290 WebstoreInstaller::Approval::CreateWithNoInstallPrompt(
346 GetProfile(), params_->details.id, parsed_manifest_.Pass(), false)); 291 chrome_details_.GetProfile(),
292 params_->details.id,
293 parsed_manifest_.Pass(),
294 false));
347 approval->use_app_installed_bubble = params_->details.app_install_bubble; 295 approval->use_app_installed_bubble = params_->details.app_install_bubble;
348 approval->enable_launcher = params_->details.enable_launcher; 296 approval->enable_launcher = params_->details.enable_launcher;
349 // If we are enabling the launcher, we should not show the app list in order 297 // If we are enabling the launcher, we should not show the app list in order
350 // to train the user to open it themselves at least once. 298 // to train the user to open it themselves at least once.
351 approval->skip_post_install_ui = params_->details.enable_launcher; 299 approval->skip_post_install_ui = params_->details.enable_launcher;
352 approval->dummy_extension = dummy_extension_; 300 approval->dummy_extension = dummy_extension_;
353 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_); 301 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_);
354 approval->authuser = authuser_; 302 approval->authuser = authuser_;
355 g_pending_approvals.Get().PushApproval(approval.Pass()); 303 g_pending_approvals.Get().PushApproval(approval.Pass());
356 304
357 DCHECK(scoped_active_install_.get()); 305 DCHECK(scoped_active_install_.get());
358 scoped_active_install_->CancelDeregister(); 306 scoped_active_install_->CancelDeregister();
359 307
360 SetResultCode(ERROR_NONE); 308 Respond(BuildResponseForSuccess());
361 SendResponse(true);
362 309
363 // The Permissions_Install histogram is recorded from the ExtensionService 310 // The Permissions_Install histogram is recorded from the ExtensionService
364 // for all extension installs, so we only need to record the web store 311 // for all extension installs, so we only need to record the web store
365 // specific histogram here. 312 // specific histogram here.
366 ExtensionService::RecordPermissionMessagesHistogram( 313 ExtensionService::RecordPermissionMessagesHistogram(
367 dummy_extension_.get(), "Extensions.Permissions_WebStoreInstall2"); 314 dummy_extension_.get(), "Extensions.Permissions_WebStoreInstall2");
368 315
369 // Matches the AddRef in RunAsync(). 316 // Matches the AddRef in Run().
370 Release(); 317 Release();
371 } 318 }
372 319
373 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIAbort( 320 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIAbort(
374 bool user_initiated) { 321 bool user_initiated) {
375 error_ = kUserCancelledError; 322 Respond(BuildResponseForError(USER_CANCELLED, kUserCancelledError));
376 SetResultCode(USER_CANCELLED);
377 SendResponse(false);
378 323
379 // The web store install histograms are a subset of the install histograms. 324 // The web store install histograms are a subset of the install histograms.
380 // We need to record both histograms here since CrxInstaller::InstallUIAbort 325 // We need to record both histograms here since CrxInstaller::InstallUIAbort
381 // is never called for web store install cancellations. 326 // is never called for web store install cancellations.
382 std::string histogram_name = 327 std::string histogram_name =
383 user_initiated ? "Extensions.Permissions_WebStoreInstallCancel2" 328 user_initiated ? "Extensions.Permissions_WebStoreInstallCancel2"
384 : "Extensions.Permissions_WebStoreInstallAbort2"; 329 : "Extensions.Permissions_WebStoreInstallAbort2";
385 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), 330 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(),
386 histogram_name.c_str()); 331 histogram_name.c_str());
387 332
388 histogram_name = user_initiated ? "Extensions.Permissions_InstallCancel2" 333 histogram_name = user_initiated ? "Extensions.Permissions_InstallCancel2"
389 : "Extensions.Permissions_InstallAbort2"; 334 : "Extensions.Permissions_InstallAbort2";
390 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), 335 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(),
391 histogram_name.c_str()); 336 histogram_name.c_str());
392 337
393 // Matches the AddRef in RunAsync(). 338 // Matches the AddRef in Run().
394 Release(); 339 Release();
395 } 340 }
396 341
342 const char* WebstorePrivateBeginInstallWithManifest3Function::
343 ResultCodeToString(ResultCode code) const {
344 switch (code) {
345 case ERROR_NONE:
346 return "";
347 case UNKNOWN_ERROR:
348 return "unknown_error";
349 case USER_CANCELLED:
350 return "user_cancelled";
351 case MANIFEST_ERROR:
352 return "manifest_error";
353 case ICON_ERROR:
354 return "icon_error";
355 case INVALID_ID:
356 return "invalid_id";
357 case PERMISSION_DENIED:
358 return "permission_denied";
359 case INVALID_ICON_URL:
360 return "invalid_icon_url";
361 case ALREADY_INSTALLED:
362 return "already_installed";
363 }
364 NOTREACHED();
365 return "";
366 }
367
368 ExtensionFunction::ResponseValue
369 WebstorePrivateBeginInstallWithManifest3Function::BuildResponseForSuccess() {
370 return ArgumentList(
371 BeginInstallWithManifest3::Results::Create(
372 ResultCodeToString(ERROR_NONE)));
373 }
374
375 ExtensionFunction::ResponseValue
376 WebstorePrivateBeginInstallWithManifest3Function::BuildResponseForError(
377 ResultCode code, const std::string& error) {
378 return ErrorWithArguments(
379 BeginInstallWithManifest3::Results::Create(ResultCodeToString(code)),
380 error);
381 }
382
397 WebstorePrivateCompleteInstallFunction:: 383 WebstorePrivateCompleteInstallFunction::
398 WebstorePrivateCompleteInstallFunction() {} 384 WebstorePrivateCompleteInstallFunction() : chrome_details_(this) {}
399 385
400 WebstorePrivateCompleteInstallFunction:: 386 WebstorePrivateCompleteInstallFunction::
401 ~WebstorePrivateCompleteInstallFunction() {} 387 ~WebstorePrivateCompleteInstallFunction() {}
402 388
403 bool WebstorePrivateCompleteInstallFunction::RunAsync() { 389 ExtensionFunction::ResponseAction
390 WebstorePrivateCompleteInstallFunction::Run() {
404 scoped_ptr<CompleteInstall::Params> params( 391 scoped_ptr<CompleteInstall::Params> params(
405 CompleteInstall::Params::Create(*args_)); 392 CompleteInstall::Params::Create(*args_));
406 EXTENSION_FUNCTION_VALIDATE(params); 393 EXTENSION_FUNCTION_VALIDATE(params);
407 if (!crx_file::id_util::IdIsValid(params->expected_id)) { 394 if (!crx_file::id_util::IdIsValid(params->expected_id))
408 error_ = kInvalidIdError; 395 return RespondNow(Error(kInvalidIdError));
409 return false;
410 }
411 396
412 approval_ = g_pending_approvals.Get() 397 approval_ =
413 .PopApproval(GetProfile(), params->expected_id) 398 g_pending_approvals.Get().PopApproval(chrome_details_.GetProfile(),
414 .Pass(); 399 params->expected_id).Pass();
415 if (!approval_) { 400 if (!approval_) {
416 error_ = ErrorUtils::FormatErrorMessage( 401 return RespondNow(Error(kNoPreviousBeginInstallWithManifestError,
417 kNoPreviousBeginInstallWithManifestError, params->expected_id); 402 params->expected_id));
418 return false;
419 } 403 }
420 404
421 scoped_active_install_.reset(new ScopedActiveInstall( 405 scoped_active_install_.reset(new ScopedActiveInstall(
422 InstallTracker::Get(GetProfile()), params->expected_id)); 406 InstallTracker::Get(browser_context()), params->expected_id));
423 407
424 AppListService* app_list_service = AppListService::Get( 408 AppListService* app_list_service = AppListService::Get(
425 GetHostDesktopTypeForWebContents(GetAssociatedWebContents())); 409 GetHostDesktopTypeForWebContents(GetAssociatedWebContents()));
426 410
427 if (approval_->enable_launcher) { 411 if (approval_->enable_launcher) {
428 app_list_service->EnableAppList(GetProfile(), 412 app_list_service->EnableAppList(chrome_details_.GetProfile(),
429 AppListService::ENABLE_FOR_APP_INSTALL); 413 AppListService::ENABLE_FOR_APP_INSTALL);
430 } 414 }
431 415
432 if (IsAppLauncherEnabled() && approval_->manifest->is_app()) { 416 if (IsAppLauncherEnabled() && approval_->manifest->is_app()) {
433 // Show the app list to show download is progressing. Don't show the app 417 // Show the app list to show download is progressing. Don't show the app
434 // list on first app install so users can be trained to open it themselves. 418 // list on first app install so users can be trained to open it themselves.
435 app_list_service->ShowForAppInstall( 419 app_list_service->ShowForAppInstall(
436 GetProfile(), params->expected_id, approval_->enable_launcher); 420 chrome_details_.GetProfile(),
421 params->expected_id,
422 approval_->enable_launcher);
437 } 423 }
438 424
439 // If the target extension has already been installed ephemerally and is 425 // If the target extension has already been installed ephemerally and is
440 // up to date, it can be promoted to a regular installed extension and 426 // up to date, it can be promoted to a regular installed extension and
441 // downloading from the Web Store is not necessary. 427 // downloading from the Web Store is not necessary.
442 const Extension* extension = ExtensionRegistry::Get(GetProfile())-> 428 const Extension* extension = ExtensionRegistry::Get(browser_context())->
443 GetExtensionById(params->expected_id, ExtensionRegistry::EVERYTHING); 429 GetExtensionById(params->expected_id, ExtensionRegistry::EVERYTHING);
444 if (extension && approval_->dummy_extension.get() && 430 if (extension && approval_->dummy_extension.get() &&
445 util::IsEphemeralApp(extension->id(), GetProfile()) && 431 util::IsEphemeralApp(extension->id(), browser_context()) &&
446 extension->version()->CompareTo(*approval_->dummy_extension->version()) >= 432 extension->version()->CompareTo(*approval_->dummy_extension->version()) >=
447 0) { 433 0) {
448 install_ui::ShowPostInstallUIForApproval( 434 install_ui::ShowPostInstallUIForApproval(
449 GetProfile(), *approval_, extension); 435 browser_context(), *approval_, extension);
450 436
451 ExtensionService* extension_service = 437 ExtensionService* extension_service =
452 ExtensionSystem::Get(GetProfile())->extension_service(); 438 ExtensionSystem::Get(browser_context())->extension_service();
453 extension_service->PromoteEphemeralApp(extension, false); 439 extension_service->PromoteEphemeralApp(extension, false);
454 OnInstallSuccess(extension->id()); 440 OnInstallSuccess(extension->id());
455 return true; 441 VLOG(1) << "Install success, sending response";
442 return RespondNow(NoArguments());
456 } 443 }
457 444
458 // Balanced in OnExtensionInstallSuccess() or OnExtensionInstallFailure(). 445 // Balanced in OnExtensionInstallSuccess() or OnExtensionInstallFailure().
459 AddRef(); 446 AddRef();
460 447
461 // The extension will install through the normal extension install flow, but 448 // The extension will install through the normal extension install flow, but
462 // the whitelist entry will bypass the normal permissions install dialog. 449 // the whitelist entry will bypass the normal permissions install dialog.
463 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( 450 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller(
464 GetProfile(), 451 chrome_details_.GetProfile(),
465 this, 452 this,
466 dispatcher()->delegate()->GetAssociatedWebContents(), 453 dispatcher()->delegate()->GetAssociatedWebContents(),
Marc Treib 2015/02/06 15:13:45 Could this just be chrome_details_.GetAssociatedWe
not at google - send to devlin 2015/02/06 18:14:52 I expect so. You can get rid of the Dispatcher dep
Marc Treib 2015/02/09 09:22:34 Done.
467 params->expected_id, 454 params->expected_id,
468 approval_.Pass(), 455 approval_.Pass(),
469 WebstoreInstaller::INSTALL_SOURCE_OTHER); 456 WebstoreInstaller::INSTALL_SOURCE_OTHER);
470 installer->Start(); 457 installer->Start();
471 458
472 return true; 459 return RespondLater();
473 } 460 }
474 461
475 void WebstorePrivateCompleteInstallFunction::OnExtensionInstallSuccess( 462 void WebstorePrivateCompleteInstallFunction::OnExtensionInstallSuccess(
476 const std::string& id) { 463 const std::string& id) {
477 OnInstallSuccess(id); 464 OnInstallSuccess(id);
465 VLOG(1) << "Install success, sending response";
466 Respond(NoArguments());
467
478 RecordWebstoreExtensionInstallResult(true); 468 RecordWebstoreExtensionInstallResult(true);
479 469
480 // Matches the AddRef in RunAsync(). 470 // Matches the AddRef in Run().
481 Release(); 471 Release();
482 } 472 }
483 473
484 void WebstorePrivateCompleteInstallFunction::OnExtensionInstallFailure( 474 void WebstorePrivateCompleteInstallFunction::OnExtensionInstallFailure(
485 const std::string& id, 475 const std::string& id,
486 const std::string& error, 476 const std::string& error,
487 WebstoreInstaller::FailureReason reason) { 477 WebstoreInstaller::FailureReason reason) {
488 if (test_webstore_installer_delegate) { 478 if (test_webstore_installer_delegate) {
489 test_webstore_installer_delegate->OnExtensionInstallFailure( 479 test_webstore_installer_delegate->OnExtensionInstallFailure(
490 id, error, reason); 480 id, error, reason);
491 } 481 }
492 482
493 error_ = error;
494 VLOG(1) << "Install failed, sending response"; 483 VLOG(1) << "Install failed, sending response";
495 SendResponse(false); 484 Respond(Error(error));
496 485
497 RecordWebstoreExtensionInstallResult(false); 486 RecordWebstoreExtensionInstallResult(false);
498 487
499 // Matches the AddRef in RunAsync(). 488 // Matches the AddRef in Run().
500 Release(); 489 Release();
501 } 490 }
502 491
503 void WebstorePrivateCompleteInstallFunction::OnInstallSuccess( 492 void WebstorePrivateCompleteInstallFunction::OnInstallSuccess(
504 const std::string& id) { 493 const std::string& id) {
505 if (test_webstore_installer_delegate) 494 if (test_webstore_installer_delegate)
506 test_webstore_installer_delegate->OnExtensionInstallSuccess(id); 495 test_webstore_installer_delegate->OnExtensionInstallSuccess(id);
507
508 VLOG(1) << "Install success, sending response";
509 SendResponse(true);
510 } 496 }
511 497
512 WebstorePrivateEnableAppLauncherFunction:: 498 WebstorePrivateEnableAppLauncherFunction::
513 WebstorePrivateEnableAppLauncherFunction() {} 499 WebstorePrivateEnableAppLauncherFunction() : chrome_details_(this) {}
514 500
515 WebstorePrivateEnableAppLauncherFunction:: 501 WebstorePrivateEnableAppLauncherFunction::
516 ~WebstorePrivateEnableAppLauncherFunction() {} 502 ~WebstorePrivateEnableAppLauncherFunction() {}
517 503
518 bool WebstorePrivateEnableAppLauncherFunction::RunSync() { 504 ExtensionFunction::ResponseAction
505 WebstorePrivateEnableAppLauncherFunction::Run() {
519 AppListService* app_list_service = AppListService::Get( 506 AppListService* app_list_service = AppListService::Get(
520 GetHostDesktopTypeForWebContents(GetAssociatedWebContents())); 507 GetHostDesktopTypeForWebContents(
521 app_list_service->EnableAppList(GetProfile(), 508 chrome_details_.GetAssociatedWebContents()));
509 app_list_service->EnableAppList(chrome_details_.GetProfile(),
522 AppListService::ENABLE_VIA_WEBSTORE_LINK); 510 AppListService::ENABLE_VIA_WEBSTORE_LINK);
523 return true; 511 return RespondNow(NoArguments());
524 } 512 }
525 513
526 bool WebstorePrivateGetBrowserLoginFunction::RunSync() { 514 WebstorePrivateGetBrowserLoginFunction::
515 WebstorePrivateGetBrowserLoginFunction() : chrome_details_(this) {}
516
517 WebstorePrivateGetBrowserLoginFunction::
518 ~WebstorePrivateGetBrowserLoginFunction() {}
519
520 ExtensionFunction::ResponseAction
521 WebstorePrivateGetBrowserLoginFunction::Run() {
527 GetBrowserLogin::Results::Info info; 522 GetBrowserLogin::Results::Info info;
528 info.login = 523 info.login = SigninManagerFactory::GetForProfile(
529 SigninManagerFactory::GetForProfile(GetProfile()->GetOriginalProfile()) 524 chrome_details_.GetProfile()->GetOriginalProfile())
530 ->GetAuthenticatedUsername(); 525 ->GetAuthenticatedUsername();
531 results_ = GetBrowserLogin::Results::Create(info); 526 return RespondNow(ArgumentList(GetBrowserLogin::Results::Create(info)));
532 return true;
533 } 527 }
534 528
535 bool WebstorePrivateGetStoreLoginFunction::RunSync() { 529 WebstorePrivateGetStoreLoginFunction::
536 results_ = GetStoreLogin::Results::Create(GetWebstoreLogin(GetProfile())); 530 WebstorePrivateGetStoreLoginFunction() : chrome_details_(this) {}
537 return true; 531
532 WebstorePrivateGetStoreLoginFunction::
533 ~WebstorePrivateGetStoreLoginFunction() {}
534
535 ExtensionFunction::ResponseAction WebstorePrivateGetStoreLoginFunction::Run() {
536 return RespondNow(ArgumentList(GetStoreLogin::Results::Create(
537 GetWebstoreLogin(chrome_details_.GetProfile()))));
538 } 538 }
539 539
540 bool WebstorePrivateSetStoreLoginFunction::RunSync() { 540 WebstorePrivateSetStoreLoginFunction::
541 WebstorePrivateSetStoreLoginFunction() : chrome_details_(this) {}
542
543 WebstorePrivateSetStoreLoginFunction::
544 ~WebstorePrivateSetStoreLoginFunction() {}
545
546 ExtensionFunction::ResponseAction WebstorePrivateSetStoreLoginFunction::Run() {
541 scoped_ptr<SetStoreLogin::Params> params( 547 scoped_ptr<SetStoreLogin::Params> params(
542 SetStoreLogin::Params::Create(*args_)); 548 SetStoreLogin::Params::Create(*args_));
543 EXTENSION_FUNCTION_VALIDATE(params); 549 EXTENSION_FUNCTION_VALIDATE(params);
544 SetWebstoreLogin(GetProfile(), params->login); 550 SetWebstoreLogin(chrome_details_.GetProfile(), params->login);
545 return true; 551 return RespondNow(NoArguments());
546 } 552 }
547 553
548 WebstorePrivateGetWebGLStatusFunction::WebstorePrivateGetWebGLStatusFunction() { 554 WebstorePrivateGetWebGLStatusFunction::WebstorePrivateGetWebGLStatusFunction()
549 feature_checker_ = new GPUFeatureChecker( 555 : feature_checker_(new GPUFeatureChecker(
550 gpu::GPU_FEATURE_TYPE_WEBGL, 556 gpu::GPU_FEATURE_TYPE_WEBGL,
551 base::Bind(&WebstorePrivateGetWebGLStatusFunction::OnFeatureCheck, 557 base::Bind(&WebstorePrivateGetWebGLStatusFunction::OnFeatureCheck,
552 base::Unretained(this))); 558 base::Unretained(this)))) {
553 } 559 }
554 560
555 WebstorePrivateGetWebGLStatusFunction:: 561 WebstorePrivateGetWebGLStatusFunction::
556 ~WebstorePrivateGetWebGLStatusFunction() {} 562 ~WebstorePrivateGetWebGLStatusFunction() {}
557 563
558 void WebstorePrivateGetWebGLStatusFunction::CreateResult(bool webgl_allowed) { 564 ExtensionFunction::ResponseAction WebstorePrivateGetWebGLStatusFunction::Run() {
559 results_ = GetWebGLStatus::Results::Create(GetWebGLStatus::Results:: 565 feature_checker_->CheckGPUFeatureAvailability();
560 ParseWebgl_status(webgl_allowed ? "webgl_allowed" : "webgl_blocked")); 566 return RespondLater();
561 } 567 }
562 568
563 bool WebstorePrivateGetWebGLStatusFunction::RunAsync() { 569 void WebstorePrivateGetWebGLStatusFunction::OnFeatureCheck(
564 feature_checker_->CheckGPUFeatureAvailability(); 570 bool feature_allowed) {
565 return true; 571 Respond(ArgumentList(GetWebGLStatus::Results::Create(
572 GetWebGLStatus::Results::ParseWebgl_status(
573 feature_allowed ? "webgl_allowed" : "webgl_blocked"))));
566 } 574 }
567 575
568 void WebstorePrivateGetWebGLStatusFunction:: 576 WebstorePrivateGetIsLauncherEnabledFunction::
569 OnFeatureCheck(bool feature_allowed) { 577 WebstorePrivateGetIsLauncherEnabledFunction() {}
570 CreateResult(feature_allowed); 578
571 SendResponse(true); 579 WebstorePrivateGetIsLauncherEnabledFunction::
580 ~WebstorePrivateGetIsLauncherEnabledFunction() {}
581
582 ExtensionFunction::ResponseAction
583 WebstorePrivateGetIsLauncherEnabledFunction::Run() {
584 return RespondNow(ArgumentList(
585 GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled())));
572 } 586 }
573 587
574 bool WebstorePrivateGetIsLauncherEnabledFunction::RunSync() { 588 WebstorePrivateIsInIncognitoModeFunction::
575 results_ = GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled()); 589 WebstorePrivateIsInIncognitoModeFunction() : chrome_details_(this) {}
576 return true;
577 }
578 590
579 bool WebstorePrivateIsInIncognitoModeFunction::RunSync() { 591 WebstorePrivateIsInIncognitoModeFunction::
580 results_ = IsInIncognitoMode::Results::Create( 592 ~WebstorePrivateIsInIncognitoModeFunction() {}
581 GetProfile() != GetProfile()->GetOriginalProfile()); 593
582 return true; 594 ExtensionFunction::ResponseAction
595 WebstorePrivateIsInIncognitoModeFunction::Run() {
596 Profile* profile = chrome_details_.GetProfile();
597 return RespondNow(ArgumentList(IsInIncognitoMode::Results::Create(
598 profile != profile->GetOriginalProfile())));
583 } 599 }
584 600
585 WebstorePrivateLaunchEphemeralAppFunction:: 601 WebstorePrivateLaunchEphemeralAppFunction::
586 WebstorePrivateLaunchEphemeralAppFunction() {} 602 WebstorePrivateLaunchEphemeralAppFunction() : chrome_details_(this) {}
587 603
588 WebstorePrivateLaunchEphemeralAppFunction:: 604 WebstorePrivateLaunchEphemeralAppFunction::
589 ~WebstorePrivateLaunchEphemeralAppFunction() {} 605 ~WebstorePrivateLaunchEphemeralAppFunction() {}
590 606
591 bool WebstorePrivateLaunchEphemeralAppFunction::RunAsync() { 607 ExtensionFunction::ResponseAction
608 WebstorePrivateLaunchEphemeralAppFunction::Run() {
592 // Check whether the browser window still exists. 609 // Check whether the browser window still exists.
593 content::WebContents* web_contents = GetAssociatedWebContents(); 610 content::WebContents* web_contents =
594 if (!web_contents) { 611 chrome_details_.GetAssociatedWebContents();
595 error_ = "aborted"; 612 if (!web_contents)
596 return false; 613 return RespondNow(Error("aborted"));
597 }
598 614
599 if (!user_gesture()) { 615 if (!user_gesture()) {
600 SetResult(LaunchEphemeralAppResult::RESULT_USER_GESTURE_REQUIRED, 616 return RespondNow(BuildResponse(
601 "User gesture is required"); 617 LaunchEphemeralAppResult::RESULT_USER_GESTURE_REQUIRED,
602 return false; 618 "User gesture is required"));
603 } 619 }
604 620
605 scoped_ptr<LaunchEphemeralApp::Params> params( 621 scoped_ptr<LaunchEphemeralApp::Params> params(
606 LaunchEphemeralApp::Params::Create(*args_)); 622 LaunchEphemeralApp::Params::Create(*args_));
607 EXTENSION_FUNCTION_VALIDATE(params); 623 EXTENSION_FUNCTION_VALIDATE(params);
608 624
609 AddRef(); // Balanced in OnLaunchComplete() 625 AddRef(); // Balanced in OnLaunchComplete()
610 626
611 scoped_refptr<EphemeralAppLauncher> launcher = 627 scoped_refptr<EphemeralAppLauncher> launcher =
612 EphemeralAppLauncher::CreateForWebContents( 628 EphemeralAppLauncher::CreateForWebContents(
613 params->id, 629 params->id,
614 web_contents, 630 web_contents,
615 base::Bind( 631 base::Bind(
616 &WebstorePrivateLaunchEphemeralAppFunction::OnLaunchComplete, 632 &WebstorePrivateLaunchEphemeralAppFunction::OnLaunchComplete,
617 base::Unretained(this))); 633 base::Unretained(this)));
618 launcher->Start(); 634 launcher->Start();
619 return true; 635
636 return RespondLater();
620 } 637 }
621 638
622 void WebstorePrivateLaunchEphemeralAppFunction::OnLaunchComplete( 639 void WebstorePrivateLaunchEphemeralAppFunction::OnLaunchComplete(
623 webstore_install::Result result, const std::string& error) { 640 webstore_install::Result result, const std::string& error) {
624 // Translate between the EphemeralAppLauncher's error codes and the API 641 // Translate between the EphemeralAppLauncher's error codes and the API
625 // error codes. 642 // error codes.
626 LaunchEphemeralAppResult::Result api_result = 643 LaunchEphemeralAppResult::Result api_result =
627 LaunchEphemeralAppResult::RESULT_UNKNOWN_ERROR; 644 LaunchEphemeralAppResult::RESULT_UNKNOWN_ERROR;
628 switch (result) { 645 switch (result) {
629 case webstore_install::SUCCESS: 646 case webstore_install::SUCCESS:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 break; 678 break;
662 case webstore_install::LAUNCH_UNSUPPORTED_EXTENSION_TYPE: 679 case webstore_install::LAUNCH_UNSUPPORTED_EXTENSION_TYPE:
663 api_result = LaunchEphemeralAppResult::RESULT_UNSUPPORTED_EXTENSION_TYPE; 680 api_result = LaunchEphemeralAppResult::RESULT_UNSUPPORTED_EXTENSION_TYPE;
664 break; 681 break;
665 case webstore_install::INSTALL_IN_PROGRESS: 682 case webstore_install::INSTALL_IN_PROGRESS:
666 api_result = LaunchEphemeralAppResult::RESULT_INSTALL_IN_PROGRESS; 683 api_result = LaunchEphemeralAppResult::RESULT_INSTALL_IN_PROGRESS;
667 break; 684 break;
668 case webstore_install::LAUNCH_IN_PROGRESS: 685 case webstore_install::LAUNCH_IN_PROGRESS:
669 api_result = LaunchEphemeralAppResult::RESULT_LAUNCH_IN_PROGRESS; 686 api_result = LaunchEphemeralAppResult::RESULT_LAUNCH_IN_PROGRESS;
670 break; 687 break;
671 default:
672 NOTREACHED();
673 break;
674 } 688 }
675 689
676 SetResult(api_result, error); 690 Respond(BuildResponse(api_result, error));
677 Release(); // Matches AddRef() in RunAsync() 691 Release(); // Matches AddRef() in Run()
678 } 692 }
679 693
680 void WebstorePrivateLaunchEphemeralAppFunction::SetResult( 694 ExtensionFunction::ResponseValue
695 WebstorePrivateLaunchEphemeralAppFunction::BuildResponse(
681 LaunchEphemeralAppResult::Result result, const std::string& error) { 696 LaunchEphemeralAppResult::Result result, const std::string& error) {
682 if (result != LaunchEphemeralAppResult::RESULT_SUCCESS) { 697 if (result != LaunchEphemeralAppResult::RESULT_SUCCESS) {
698 std::string error_message;
683 if (error.empty()) { 699 if (error.empty()) {
684 error_ = base::StringPrintf( 700 error_message = base::StringPrintf(
685 "[%s]", LaunchEphemeralAppResult::ToString(result).c_str()); 701 "[%s]", LaunchEphemeralAppResult::ToString(result).c_str());
686 } else { 702 } else {
687 error_ = base::StringPrintf( 703 error_message = base::StringPrintf(
688 "[%s]: %s", 704 "[%s]: %s",
689 LaunchEphemeralAppResult::ToString(result).c_str(), 705 LaunchEphemeralAppResult::ToString(result).c_str(),
690 error.c_str()); 706 error.c_str());
691 } 707 }
708 return ErrorWithArguments(LaunchEphemeralAppResult::Create(result),
709 error_message);
692 } 710 }
693 711 return ArgumentList(LaunchEphemeralAppResult::Create(result));
694 results_ = LaunchEphemeralAppResult::Create(result);
695 SendResponse(result == LaunchEphemeralAppResult::RESULT_SUCCESS);
696 } 712 }
697 713
698 WebstorePrivateGetEphemeralAppsEnabledFunction:: 714 WebstorePrivateGetEphemeralAppsEnabledFunction::
699 WebstorePrivateGetEphemeralAppsEnabledFunction() {} 715 WebstorePrivateGetEphemeralAppsEnabledFunction() {}
700 716
701 WebstorePrivateGetEphemeralAppsEnabledFunction:: 717 WebstorePrivateGetEphemeralAppsEnabledFunction::
702 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} 718 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {}
703 719
704 bool WebstorePrivateGetEphemeralAppsEnabledFunction::RunSync() { 720 ExtensionFunction::ResponseAction
705 results_ = GetEphemeralAppsEnabled::Results::Create( 721 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() {
706 EphemeralAppLauncher::IsFeatureEnabledInWebstore()); 722 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create(
707 return true; 723 EphemeralAppLauncher::IsFeatureEnabledInWebstore())));
708 } 724 }
709 725
710 } // namespace extensions 726 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698