1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/webstore_reinstaller.h"
7 #include "base/memory/ref_counted.h"
8 #include "chrome/browser/extensions/extension_install_prompt.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/web_contents.h"
12 #include "extensions/browser/extension_system.h"
14 namespace extensions
{
17 const char kCouldNotUninstallExtension
[] = "Failed to uninstall the extension.";
18 const char kTabClosed
[] = "Tab was closed.";
21 WebstoreReinstaller::WebstoreReinstaller(
22 content::WebContents
* web_contents
,
23 const std::string
& extension_id
,
24 const WebstoreStandaloneInstaller::Callback
& callback
)
25 : WebstoreStandaloneInstaller(
27 Profile::FromBrowserContext(web_contents
->GetBrowserContext()),
29 content::WebContentsObserver(web_contents
) {
32 WebstoreReinstaller::~WebstoreReinstaller() {
35 void WebstoreReinstaller::BeginReinstall() {
36 WebstoreStandaloneInstaller::BeginInstall();
39 bool WebstoreReinstaller::CheckRequestorAlive() const {
40 return web_contents() != NULL
;
43 const GURL
& WebstoreReinstaller::GetRequestorURL() const {
44 return GURL::EmptyGURL();
47 scoped_refptr
<ExtensionInstallPrompt::Prompt
>
48 WebstoreReinstaller::CreateInstallPrompt() const {
49 scoped_refptr
<ExtensionInstallPrompt::Prompt
> prompt(
50 new ExtensionInstallPrompt::Prompt(
51 ExtensionInstallPrompt::REPAIR_PROMPT
));
52 prompt
->SetWebstoreData(localized_user_count(),
59 bool WebstoreReinstaller::ShouldShowPostInstallUI() const {
63 bool WebstoreReinstaller::ShouldShowAppInstalledBubble() const {
67 content::WebContents
* WebstoreReinstaller::GetWebContents() const {
68 return web_contents();
71 bool WebstoreReinstaller::CheckInlineInstallPermitted(
72 const base::DictionaryValue
& webstore_data
,
73 std::string
* error
) const {
77 bool WebstoreReinstaller::CheckRequestorPermitted(
78 const base::DictionaryValue
& webstore_data
,
79 std::string
* error
) const {
83 void WebstoreReinstaller::WebContentsDestroyed() {
84 // Run the callback now, because AbortInstall() doesn't do it.
85 RunCallback(false, kTabClosed
, webstore_install::ABORTED
);
89 void WebstoreReinstaller::InstallUIProceed() {
90 if (!ExtensionSystem::Get(profile())->extension_service()->UninstallExtension(
92 UNINSTALL_REASON_REINSTALL
,
93 base::Bind(&WebstoreReinstaller::OnDeletionDone
, this),
95 // Run the callback now, because AbortInstall() doesn't do it.
97 false, kCouldNotUninstallExtension
, webstore_install::OTHER_ERROR
);
102 void WebstoreReinstaller::OnDeletionDone() {
103 WebstoreStandaloneInstaller::InstallUIProceed();
106 } // namespace extensions