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

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

Issue 855513002: Add/resurrect support for bundles of WebStore items. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@testext_bundle
Patch Set: fix BitmapFetcher destruction Created 5 years, 8 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/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
11 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "base/version.h" 15 #include "base/version.h"
15 #include "chrome/browser/apps/ephemeral_app_launcher.h" 16 #include "chrome/browser/apps/ephemeral_app_launcher.h"
17 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h"
16 #include "chrome/browser/extensions/crx_installer.h" 18 #include "chrome/browser/extensions/crx_installer.h"
17 #include "chrome/browser/extensions/extension_install_ui_util.h" 19 #include "chrome/browser/extensions/extension_install_ui_util.h"
18 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
19 #include "chrome/browser/extensions/install_tracker.h" 21 #include "chrome/browser/extensions/install_tracker.h"
20 #include "chrome/browser/gpu/gpu_feature_checker.h" 22 #include "chrome/browser/gpu/gpu_feature_checker.h"
21 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/signin/signin_manager_factory.h" 24 #include "chrome/browser/signin/signin_manager_factory.h"
23 #include "chrome/browser/ui/app_list/app_list_service.h" 25 #include "chrome/browser/ui/app_list/app_list_service.h"
24 #include "chrome/browser/ui/app_list/app_list_util.h" 26 #include "chrome/browser/ui/app_list/app_list_util.h"
25 #include "chrome/common/extensions/extension_constants.h" 27 #include "chrome/common/extensions/extension_constants.h"
26 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
27 #include "components/crx_file/id_util.h" 29 #include "components/crx_file/id_util.h"
28 #include "components/signin/core/browser/signin_manager.h" 30 #include "components/signin/core/browser/signin_manager.h"
29 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
30 #include "extensions/browser/extension_registry.h" 32 #include "extensions/browser/extension_registry.h"
31 #include "extensions/browser/extension_system.h" 33 #include "extensions/browser/extension_system.h"
32 #include "extensions/browser/extension_util.h" 34 #include "extensions/browser/extension_util.h"
33 #include "extensions/common/extension.h" 35 #include "extensions/common/extension.h"
36 #include "net/base/load_flags.h"
37 #include "net/url_request/url_request.h"
38 #include "url/gurl.h"
34 39
35 namespace extensions { 40 namespace extensions {
36 41
37 namespace BeginInstallWithManifest3 = 42 namespace BeginInstallWithManifest3 =
38 api::webstore_private::BeginInstallWithManifest3; 43 api::webstore_private::BeginInstallWithManifest3;
39 namespace CompleteInstall = api::webstore_private::CompleteInstall; 44 namespace CompleteInstall = api::webstore_private::CompleteInstall;
40 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; 45 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin;
41 namespace GetEphemeralAppsEnabled = 46 namespace GetEphemeralAppsEnabled =
42 api::webstore_private::GetEphemeralAppsEnabled; 47 api::webstore_private::GetEphemeralAppsEnabled;
43 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; 48 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled;
44 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; 49 namespace GetStoreLogin = api::webstore_private::GetStoreLogin;
45 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; 50 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus;
51 namespace InstallBundle = api::webstore_private::InstallBundle;
46 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; 52 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode;
47 namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp; 53 namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp;
48 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; 54 namespace SetStoreLogin = api::webstore_private::SetStoreLogin;
49 namespace ShowPermissionPromptForDelegatedInstall = 55 namespace ShowPermissionPromptForDelegatedInstall =
50 api::webstore_private::ShowPermissionPromptForDelegatedInstall; 56 api::webstore_private::ShowPermissionPromptForDelegatedInstall;
51 57
52 namespace { 58 namespace {
53 59
54 // Holds the Approvals between the time we prompt and start the installs. 60 // Holds the Approvals between the time we prompt and start the installs.
55 class PendingApprovals { 61 class PendingApprovals {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 NOTREACHED(); 154 NOTREACHED();
149 return api::webstore_private::RESULT_NONE; 155 return api::webstore_private::RESULT_NONE;
150 } 156 }
151 157
152 static base::LazyInstance<PendingApprovals> g_pending_approvals = 158 static base::LazyInstance<PendingApprovals> g_pending_approvals =
153 LAZY_INSTANCE_INITIALIZER; 159 LAZY_INSTANCE_INITIALIZER;
154 160
155 // A preference set by the web store to indicate login information for 161 // A preference set by the web store to indicate login information for
156 // purchased apps. 162 // purchased apps.
157 const char kWebstoreLogin[] = "extensions.webstore_login"; 163 const char kWebstoreLogin[] = "extensions.webstore_login";
164
165 // Error messages that can be returned by the API.
158 const char kAlreadyInstalledError[] = "This item is already installed"; 166 const char kAlreadyInstalledError[] = "This item is already installed";
159 const char kCannotSpecifyIconDataAndUrlError[] = 167 const char kCannotSpecifyIconDataAndUrlError[] =
160 "You cannot specify both icon data and an icon url"; 168 "You cannot specify both icon data and an icon url";
169 const char kInvalidBundleError[] = "Invalid bundle";
161 const char kInvalidIconUrlError[] = "Invalid icon url"; 170 const char kInvalidIconUrlError[] = "Invalid icon url";
162 const char kInvalidIdError[] = "Invalid id"; 171 const char kInvalidIdError[] = "Invalid id";
163 const char kInvalidManifestError[] = "Invalid manifest"; 172 const char kInvalidManifestError[] = "Invalid manifest";
164 const char kNoPreviousBeginInstallWithManifestError[] = 173 const char kNoPreviousBeginInstallWithManifestError[] =
165 "* does not match a previous call to beginInstallWithManifest3"; 174 "* does not match a previous call to beginInstallWithManifest3";
166 const char kUserCancelledError[] = "User cancelled install"; 175 const char kUserCancelledError[] = "User cancelled install";
167 176
168 WebstoreInstaller::Delegate* test_webstore_installer_delegate = NULL; 177 WebstoreInstaller::Delegate* test_webstore_installer_delegate = nullptr;
169 178
170 // We allow the web store to set a string containing login information when a 179 // We allow the web store to set a string containing login information when a
171 // purchase is made, so that when a user logs into sync with a different 180 // purchase is made, so that when a user logs into sync with a different
172 // account we can recognize the situation. The Get function returns the login if 181 // account we can recognize the situation. The Get function returns the login if
173 // there was previously stored data, or an empty string otherwise. The Set will 182 // there was previously stored data, or an empty string otherwise. The Set will
174 // overwrite any previous login. 183 // overwrite any previous login.
175 std::string GetWebstoreLogin(Profile* profile) { 184 std::string GetWebstoreLogin(Profile* profile) {
176 if (profile->GetPrefs()->HasPrefPath(kWebstoreLogin)) 185 if (profile->GetPrefs()->HasPrefPath(kWebstoreLogin))
177 return profile->GetPrefs()->GetString(kWebstoreLogin); 186 return profile->GetPrefs()->GetString(kWebstoreLogin);
178 return std::string(); 187 return std::string();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 return RespondNow(BuildResponse( 268 return RespondNow(BuildResponse(
260 api::webstore_private::RESULT_INVALID_ICON_URL, 269 api::webstore_private::RESULT_INVALID_ICON_URL,
261 kInvalidIconUrlError)); 270 kInvalidIconUrlError));
262 } 271 }
263 } 272 }
264 273
265 ExtensionFunction::ResponseValue response = RunExtraForResponse(); 274 ExtensionFunction::ResponseValue response = RunExtraForResponse();
266 if (response) 275 if (response)
267 return RespondNow(response.Pass()); 276 return RespondNow(response.Pass());
268 277
269 net::URLRequestContextGetter* context_getter = NULL; 278 net::URLRequestContextGetter* context_getter = nullptr;
270 if (!icon_url.is_empty()) 279 if (!icon_url.is_empty())
271 context_getter = browser_context()->GetRequestContext(); 280 context_getter = browser_context()->GetRequestContext();
272 281
273 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( 282 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper(
274 this, params_->details.id, params_->details.manifest, icon_url, 283 this, params_->details.id, params_->details.manifest, icon_url,
275 context_getter); 284 context_getter);
276 285
277 // The helper will call us back via OnWebstoreParseSuccess or 286 // The helper will call us back via OnWebstoreParseSuccess or
278 // OnWebstoreParseFailure. 287 // OnWebstoreParseFailure.
279 helper->Start(); 288 helper->Start();
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 install_prompt->ConfirmPermissionsForDelegatedInstall( 588 install_prompt->ConfirmPermissionsForDelegatedInstall(
580 this, dummy_extension().get(), params().details.delegated_user, &icon()); 589 this, dummy_extension().get(), params().details.delegated_user, &icon());
581 } 590 }
582 591
583 scoped_ptr<base::ListValue> 592 scoped_ptr<base::ListValue>
584 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction::CreateResults( 593 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction::CreateResults(
585 api::webstore_private::Result result) const { 594 api::webstore_private::Result result) const {
586 return ShowPermissionPromptForDelegatedInstall::Results::Create(result); 595 return ShowPermissionPromptForDelegatedInstall::Results::Create(result);
587 } 596 }
588 597
598 WebstorePrivateInstallBundleFunction::WebstorePrivateInstallBundleFunction()
599 : chrome_details_(this) {
600 }
601
602 WebstorePrivateInstallBundleFunction::~WebstorePrivateInstallBundleFunction() {
603 }
604
605 ExtensionFunction::ResponseAction WebstorePrivateInstallBundleFunction::Run() {
606 params_ = InstallBundle::Params::Create(*args_);
607 EXTENSION_FUNCTION_VALIDATE(params_);
608
609 if (params_->contents.empty())
610 return RespondNow(Error(kInvalidBundleError));
611
612 if (params_->details.icon_url) {
613 GURL icon_url = source_url().Resolve(*params_->details.icon_url);
614 if (!icon_url.is_valid())
615 return RespondNow(Error(kInvalidIconUrlError));
616
617 // The bitmap fetcher will call us back via OnFetchComplete.
618 icon_fetcher_.reset(new chrome::BitmapFetcher(icon_url, this));
619 icon_fetcher_->Start(
620 browser_context()->GetRequestContext(), std::string(),
621 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE,
622 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES);
623 } else {
624 base::MessageLoopProxy::current()->PostTask(
625 FROM_HERE,
626 base::Bind(&WebstorePrivateInstallBundleFunction::OnFetchComplete,
627 this, GURL(), nullptr));
628 }
629
630 AddRef(); // Balanced in OnFetchComplete.
631
632 // The response is sent asynchronously in OnFetchComplete, OnInstallApproval,
633 // or OnInstallComplete.
634 return RespondLater();
635 }
636
637 void WebstorePrivateInstallBundleFunction::OnFetchComplete(
638 const GURL& url, const SkBitmap* bitmap) {
639 InstallTracker* tracker = InstallTracker::Get(browser_context());
640 DCHECK(tracker);
641
642 std::string authuser;
643 if (params_->details.authuser)
644 authuser = *params_->details.authuser;
645
646 BundleInstaller::ItemList items;
647 for (const auto& entry : params_->contents) {
648 // Skip already-installed items.
649 if (util::IsExtensionInstalledPermanently(entry->id, browser_context()) ||
650 tracker->GetActiveInstall(entry->id)) {
651 continue;
652 }
653 BundleInstaller::Item item;
654 item.id = entry->id;
655 item.manifest = entry->manifest;
656 item.localized_name = entry->localized_name;
657 if (entry->icon_url)
658 item.icon_url = source_url().Resolve(*entry->icon_url);
659 items.push_back(item);
660 }
661 if (items.empty()) {
662 Respond(Error(kAlreadyInstalledError));
663 Release(); // Matches the AddRef in Run.
664 return;
665 }
666 bundle_.reset(new BundleInstaller(chrome_details_.GetCurrentBrowser(),
667 params_->details.localized_name,
668 bitmap ? *bitmap : SkBitmap(), authuser,
669 items));
670
671 // The bundle installer will call us back via OnInstallApproval.
672 bundle_->PromptForApproval(
673 base::Bind(&WebstorePrivateInstallBundleFunction::OnInstallApproval,
674 this));
675
676 Release(); // Matches the AddRef in Run.
677 }
678
679 void WebstorePrivateInstallBundleFunction::OnInstallApproval(
680 BundleInstaller::ApprovalState state) {
681 if (state != BundleInstaller::APPROVED) {
682 Respond(Error(state == BundleInstaller::USER_CANCELED
683 ? kUserCancelledError
684 : kInvalidBundleError));
685 return;
686 }
687
688 // The bundle installer will call us back via OnInstallComplete.
689 bundle_->CompleteInstall(
690 chrome_details_.GetAssociatedWebContents(),
691 base::Bind(&WebstorePrivateInstallBundleFunction::OnInstallComplete,
692 this));
693 }
694
695 void WebstorePrivateInstallBundleFunction::OnInstallComplete() {
696 Respond(NoArguments());
697 }
698
589 WebstorePrivateEnableAppLauncherFunction:: 699 WebstorePrivateEnableAppLauncherFunction::
590 WebstorePrivateEnableAppLauncherFunction() : chrome_details_(this) {} 700 WebstorePrivateEnableAppLauncherFunction() : chrome_details_(this) {}
591 701
592 WebstorePrivateEnableAppLauncherFunction:: 702 WebstorePrivateEnableAppLauncherFunction::
593 ~WebstorePrivateEnableAppLauncherFunction() {} 703 ~WebstorePrivateEnableAppLauncherFunction() {}
594 704
595 ExtensionFunction::ResponseAction 705 ExtensionFunction::ResponseAction
596 WebstorePrivateEnableAppLauncherFunction::Run() { 706 WebstorePrivateEnableAppLauncherFunction::Run() {
597 AppListService* app_list_service = AppListService::Get( 707 AppListService* app_list_service = AppListService::Get(
598 GetHostDesktopTypeForWebContents( 708 GetHostDesktopTypeForWebContents(
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 WebstorePrivateGetEphemeralAppsEnabledFunction:: 869 WebstorePrivateGetEphemeralAppsEnabledFunction::
760 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} 870 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {}
761 871
762 ExtensionFunction::ResponseAction 872 ExtensionFunction::ResponseAction
763 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() { 873 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() {
764 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create( 874 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create(
765 EphemeralAppLauncher::IsFeatureEnabled()))); 875 EphemeralAppLauncher::IsFeatureEnabled())));
766 } 876 }
767 877
768 } // namespace extensions 878 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698