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"
12 const char kWebContentsDestroyedError
[] = "WebContents is destroyed.";
15 namespace webstore_widget
{
17 class AppInstaller::WebContentsObserver
: public content::WebContentsObserver
{
19 WebContentsObserver(content::WebContents
* web_contents
, AppInstaller
* parent
)
20 : content::WebContentsObserver(web_contents
), parent_(parent
) {}
23 // content::WebContentsObserver implementation.
24 void WebContentsDestroyed() override
{
25 parent_
->OnWebContentsDestroyed(web_contents());
29 AppInstaller
* parent_
;
31 DISALLOW_IMPLICIT_CONSTRUCTORS(WebContentsObserver
);
34 AppInstaller::AppInstaller(content::WebContents
* web_contents
,
35 const std::string
& item_id
,
37 bool silent_installation
,
38 const Callback
& callback
)
39 : extensions::WebstoreStandaloneInstaller(item_id
, profile
, callback
),
40 silent_installation_(silent_installation
),
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_
)
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());
72 bool AppInstaller::ShouldShowPostInstallUI() const {
76 bool AppInstaller::ShouldShowAppInstalledBubble() const {
80 content::WebContents
* AppInstaller::GetWebContents() const {
84 bool AppInstaller::CheckInlineInstallPermitted(
85 const base::DictionaryValue
& webstore_data
,
86 std::string
* error
) const {
87 DCHECK(error
!= NULL
);
88 DCHECK(error
->empty());
92 bool AppInstaller::CheckRequestorPermitted(
93 const base::DictionaryValue
& webstore_data
,
94 std::string
* error
) const {
95 DCHECK(error
!= NULL
);
96 DCHECK(error
->empty());
100 void AppInstaller::OnWebContentsDestroyed(content::WebContents
* web_contents
) {
101 callback_
.Run(false, kWebContentsDestroyedError
,
102 extensions::webstore_install::OTHER_ERROR
);
106 } // namespace webstore_widget