Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / extensions / api / webstore_widget_private / app_installer.cc
blobfbdb041bb4e46324b849d5f6a4c590ea8607299f
1 // Copyright 2013 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/api/webstore_widget_private/app_installer.h"
7 #include "chrome/common/extensions/webstore_install_result.h"
8 #include "content/public/browser/web_contents.h"
9 #include "content/public/browser/web_contents_observer.h"
11 namespace {
12 const char kWebContentsDestroyedError[] = "WebContents is destroyed.";
13 } // namespace
15 namespace webstore_widget {
17 class AppInstaller::WebContentsObserver : public content::WebContentsObserver {
18 public:
19 WebContentsObserver(content::WebContents* web_contents, AppInstaller* parent)
20 : content::WebContentsObserver(web_contents), parent_(parent) {}
22 protected:
23 // content::WebContentsObserver implementation.
24 void WebContentsDestroyed() override {
25 parent_->OnWebContentsDestroyed(web_contents());
28 private:
29 AppInstaller* parent_;
31 DISALLOW_IMPLICIT_CONSTRUCTORS(WebContentsObserver);
34 AppInstaller::AppInstaller(content::WebContents* web_contents,
35 const std::string& item_id,
36 Profile* profile,
37 bool silent_installation,
38 const Callback& callback)
39 : extensions::WebstoreStandaloneInstaller(item_id, profile, callback),
40 silent_installation_(silent_installation),
41 callback_(callback),
42 web_contents_(web_contents),
43 web_contents_observer_(new WebContentsObserver(web_contents, this)) {
46 AppInstaller::~AppInstaller() {
49 bool AppInstaller::CheckRequestorAlive() const {
50 // The tab may have gone away - cancel installation in that case.
51 return web_contents_ != NULL;
54 const GURL& AppInstaller::GetRequestorURL() const {
55 return GURL::EmptyGURL();
58 scoped_refptr<ExtensionInstallPrompt::Prompt>
59 AppInstaller::CreateInstallPrompt() const {
60 if (silent_installation_)
61 return NULL;
63 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt(
64 new ExtensionInstallPrompt::Prompt(
65 ExtensionInstallPrompt::INLINE_INSTALL_PROMPT));
67 prompt->SetWebstoreData(localized_user_count(), show_user_count(),
68 average_rating(), rating_count());
69 return prompt;
72 bool AppInstaller::ShouldShowPostInstallUI() const {
73 return false;
76 bool AppInstaller::ShouldShowAppInstalledBubble() const {
77 return false;
80 content::WebContents* AppInstaller::GetWebContents() const {
81 return web_contents_;
84 bool AppInstaller::CheckInlineInstallPermitted(
85 const base::DictionaryValue& webstore_data,
86 std::string* error) const {
87 DCHECK(error != NULL);
88 DCHECK(error->empty());
89 return true;
92 bool AppInstaller::CheckRequestorPermitted(
93 const base::DictionaryValue& webstore_data,
94 std::string* error) const {
95 DCHECK(error != NULL);
96 DCHECK(error->empty());
97 return true;
100 void AppInstaller::OnWebContentsDestroyed(content::WebContents* web_contents) {
101 callback_.Run(false, kWebContentsDestroyedError,
102 extensions::webstore_install::OTHER_ERROR);
103 AbortInstall();
106 } // namespace webstore_widget