blob: 29b4e99dff5f409ef5fb1f33fcc63cc7ea034c1f [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) {
30}
31
32WebstoreReinstaller::~WebstoreReinstaller() {
33}
34
35void WebstoreReinstaller::BeginReinstall() {
36 WebstoreStandaloneInstaller::BeginInstall();
37}
38
39bool WebstoreReinstaller::CheckRequestorAlive() const {
40 return web_contents() != NULL;
41}
42
43const GURL& WebstoreReinstaller::GetRequestorURL() const {
44 return GURL::EmptyGURL();
45}
46
dchengc963c7142016-04-08 03:55:2247std::unique_ptr<ExtensionInstallPrompt::Prompt>
rdevlin.cronin5f6b69d2014-09-20 01:23:3548WebstoreReinstaller::CreateInstallPrompt() const {
dchengc963c7142016-04-08 03:55:2249 std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt(
rdevlin.cronin5f6b69d2014-09-20 01:23:3550 new ExtensionInstallPrompt::Prompt(
51 ExtensionInstallPrompt::REPAIR_PROMPT));
52 prompt->SetWebstoreData(localized_user_count(),
53 show_user_count(),
54 average_rating(),
55 rating_count());
dcheng1fc00f12015-12-26 22:18:0356 return prompt;
rdevlin.cronin5f6b69d2014-09-20 01:23:3557}
58
59bool WebstoreReinstaller::ShouldShowPostInstallUI() const {
60 return false;
61}
62
63bool WebstoreReinstaller::ShouldShowAppInstalledBubble() const {
64 return false;
65}
66
67content::WebContents* WebstoreReinstaller::GetWebContents() const {
68 return web_contents();
69}
70
71bool WebstoreReinstaller::CheckInlineInstallPermitted(
72 const base::DictionaryValue& webstore_data,
73 std::string* error) const {
74 return true;
75}
76
77bool WebstoreReinstaller::CheckRequestorPermitted(
78 const base::DictionaryValue& webstore_data,
79 std::string* error) const {
80 return true;
81}
82
83void WebstoreReinstaller::WebContentsDestroyed() {
84 // Run the callback now, because AbortInstall() doesn't do it.
85 RunCallback(false, kTabClosed, webstore_install::ABORTED);
86 AbortInstall();
87}
88
rdevlin.cronin41593052016-01-08 01:40:1289void WebstoreReinstaller::OnInstallPromptDone(
90 ExtensionInstallPrompt::Result result) {
91 if (result != ExtensionInstallPrompt::Result::ACCEPTED) {
92 WebstoreStandaloneInstaller::OnInstallPromptDone(result);
93 return;
94 }
95
rdevlin.cronin5f6b69d2014-09-20 01:23:3596 if (!ExtensionSystem::Get(profile())->extension_service()->UninstallExtension(
97 id(),
98 UNINSTALL_REASON_REINSTALL,
99 base::Bind(&WebstoreReinstaller::OnDeletionDone, this),
100 NULL)) {
101 // Run the callback now, because AbortInstall() doesn't do it.
102 RunCallback(
103 false, kCouldNotUninstallExtension, webstore_install::OTHER_ERROR);
104 AbortInstall();
105 }
106}
107
108void WebstoreReinstaller::OnDeletionDone() {
rdevlin.cronin41593052016-01-08 01:40:12109 WebstoreStandaloneInstaller::OnInstallPromptDone(
110 ExtensionInstallPrompt::Result::ACCEPTED);
rdevlin.cronin5f6b69d2014-09-20 01:23:35111}
112
113} // namespace extensions