blob: 48d5a98f930629fbfbd4327cf8c44625229363bc [file] [log] [blame]
rdevlin.cronin5f6b69d2014-09-20 01:23:351// 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.
4
5#include "chrome/browser/extensions/webstore_reinstaller.h"
6
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"
13
14namespace extensions {
15
16namespace {
17const char kCouldNotUninstallExtension[] = "Failed to uninstall the extension.";
18const char kTabClosed[] = "Tab was closed.";
19}
20
21WebstoreReinstaller::WebstoreReinstaller(
22 content::WebContents* web_contents,
23 const std::string& extension_id,
24 const WebstoreStandaloneInstaller::Callback& callback)
25 : WebstoreStandaloneInstaller(
26 extension_id,
27 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
28 callback),
29 content::WebContentsObserver(web_contents) {
Minh X. Nguyen45479012017-08-18 21:35:3630 DCHECK(
31 ExtensionPrefs::Get(web_contents->GetBrowserContext())
32 ->HasDisableReason(extension_id, disable_reason::DISABLE_CORRUPTED));
rdevlin.cronin5f6b69d2014-09-20 01:23:3533}
34
35WebstoreReinstaller::~WebstoreReinstaller() {
36}
37
38void WebstoreReinstaller::BeginReinstall() {
39 WebstoreStandaloneInstaller::BeginInstall();
40}
41
42bool WebstoreReinstaller::CheckRequestorAlive() const {
43 return web_contents() != NULL;
44}
45
46const GURL& WebstoreReinstaller::GetRequestorURL() const {
47 return GURL::EmptyGURL();
48}
49
dchengc963c7142016-04-08 03:55:2250std::unique_ptr<ExtensionInstallPrompt::Prompt>
rdevlin.cronin5f6b69d2014-09-20 01:23:3551WebstoreReinstaller::CreateInstallPrompt() const {
dchengc963c7142016-04-08 03:55:2252 std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt(
rdevlin.cronin5f6b69d2014-09-20 01:23:3553 new ExtensionInstallPrompt::Prompt(
54 ExtensionInstallPrompt::REPAIR_PROMPT));
55 prompt->SetWebstoreData(localized_user_count(),
56 show_user_count(),
57 average_rating(),
58 rating_count());
dcheng1fc00f12015-12-26 22:18:0359 return prompt;
rdevlin.cronin5f6b69d2014-09-20 01:23:3560}
61
62bool WebstoreReinstaller::ShouldShowPostInstallUI() const {
63 return false;
64}
65
66bool WebstoreReinstaller::ShouldShowAppInstalledBubble() const {
67 return false;
68}
69
70content::WebContents* WebstoreReinstaller::GetWebContents() const {
71 return web_contents();
72}
73
74bool WebstoreReinstaller::CheckInlineInstallPermitted(
75 const base::DictionaryValue& webstore_data,
76 std::string* error) const {
77 return true;
78}
79
80bool WebstoreReinstaller::CheckRequestorPermitted(
81 const base::DictionaryValue& webstore_data,
82 std::string* error) const {
83 return true;
84}
85
86void WebstoreReinstaller::WebContentsDestroyed() {
87 // Run the callback now, because AbortInstall() doesn't do it.
88 RunCallback(false, kTabClosed, webstore_install::ABORTED);
89 AbortInstall();
90}
91
rdevlin.cronin41593052016-01-08 01:40:1292void WebstoreReinstaller::OnInstallPromptDone(
93 ExtensionInstallPrompt::Result result) {
94 if (result != ExtensionInstallPrompt::Result::ACCEPTED) {
95 WebstoreStandaloneInstaller::OnInstallPromptDone(result);
96 return;
97 }
98
rdevlin.cronin5f6b69d2014-09-20 01:23:3599 if (!ExtensionSystem::Get(profile())->extension_service()->UninstallExtension(
100 id(),
101 UNINSTALL_REASON_REINSTALL,
102 base::Bind(&WebstoreReinstaller::OnDeletionDone, this),
103 NULL)) {
104 // Run the callback now, because AbortInstall() doesn't do it.
105 RunCallback(
106 false, kCouldNotUninstallExtension, webstore_install::OTHER_ERROR);
107 AbortInstall();
108 }
109}
110
111void WebstoreReinstaller::OnDeletionDone() {
rdevlin.cronin41593052016-01-08 01:40:12112 WebstoreStandaloneInstaller::OnInstallPromptDone(
113 ExtensionInstallPrompt::Result::ACCEPTED);
rdevlin.cronin5f6b69d2014-09-20 01:23:35114}
115
116} // namespace extensions