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/chromeos/file_manager/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 file_manager
{
14 const char kWebContentsDestroyedError
[] = "WebContents is destroyed.";
17 class AppInstaller::WebContentsObserver
: public content::WebContentsObserver
{
19 WebContentsObserver(content::WebContents
* web_contents
, AppInstaller
* parent
)
20 : content::WebContentsObserver(web_contents
),
25 // content::WebContentsObserver implementation.
26 void WebContentsDestroyed() override
{
27 parent_
->OnWebContentsDestroyed(web_contents());
31 AppInstaller
* parent_
;
33 DISALLOW_IMPLICIT_CONSTRUCTORS(WebContentsObserver
);
36 AppInstaller::AppInstaller(content::WebContents
* web_contents
,
37 const std::string
& item_id
,
39 bool silent_installation
,
40 const Callback
& callback
)
41 : extensions::WebstoreStandaloneInstaller(item_id
, profile
, callback
),
42 silent_installation_(silent_installation
),
44 web_contents_(web_contents
),
45 web_contents_observer_(new WebContentsObserver(web_contents
, this)) {
48 AppInstaller::~AppInstaller() {}
50 bool AppInstaller::CheckRequestorAlive() const {
51 // The tab may have gone away - cancel installation in that case.
52 return web_contents_
!= NULL
;
55 const GURL
& AppInstaller::GetRequestorURL() const {
56 return GURL::EmptyGURL();
59 scoped_refptr
<ExtensionInstallPrompt::Prompt
>
60 AppInstaller::CreateInstallPrompt() const {
61 if (silent_installation_
)
64 scoped_refptr
<ExtensionInstallPrompt::Prompt
> prompt(
65 new ExtensionInstallPrompt::Prompt(
66 ExtensionInstallPrompt::INLINE_INSTALL_PROMPT
));
68 prompt
->SetWebstoreData(localized_user_count(),
75 bool AppInstaller::ShouldShowPostInstallUI() const {
79 bool AppInstaller::ShouldShowAppInstalledBubble() const {
83 content::WebContents
* AppInstaller::GetWebContents() const {
87 bool AppInstaller::CheckInlineInstallPermitted(
88 const base::DictionaryValue
& webstore_data
,
89 std::string
* error
) const {
90 DCHECK(error
!= NULL
);
91 DCHECK(error
->empty());
95 bool AppInstaller::CheckRequestorPermitted(
96 const base::DictionaryValue
& webstore_data
,
97 std::string
* error
) const {
98 DCHECK(error
!= NULL
);
99 DCHECK(error
->empty());
103 void AppInstaller::OnWebContentsDestroyed(
104 content::WebContents
* web_contents
) {
106 kWebContentsDestroyedError
,
107 extensions::webstore_install::OTHER_ERROR
);
111 } // namespace file_manager