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. 4 5 #include "chrome/browser/chromeos/file_manager/app_installer.h" 6 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" 10 11 namespace file_manager { 12 13 namespace { 14 const char kWebContentsDestroyedError[] = "WebContents is destroyed."; 15 } // namespace 16 17 class AppInstaller::WebContentsObserver : public content::WebContentsObserver { 18 public: 19 WebContentsObserver(content::WebContents* web_contents, AppInstaller* parent) 20 : content::WebContentsObserver(web_contents), 21 parent_(parent) { 22 } 23 24 protected: 25 // content::WebContentsObserver implementation. 26 virtual void WebContentsDestroyed() OVERRIDE { 27 parent_->OnWebContentsDestroyed(web_contents()); 28 } 29 30 private: 31 AppInstaller* parent_; 32 33 DISALLOW_IMPLICIT_CONSTRUCTORS(WebContentsObserver); 34 }; 35 36 AppInstaller::AppInstaller(content::WebContents* web_contents, 37 const std::string& item_id, 38 Profile* profile, 39 bool silent_installation, 40 const Callback& callback) 41 : extensions::WebstoreStandaloneInstaller(item_id, profile, callback), 42 silent_installation_(silent_installation), 43 callback_(callback), 44 web_contents_(web_contents), 45 web_contents_observer_(new WebContentsObserver(web_contents, this)) { 46 } 47 48 AppInstaller::~AppInstaller() {} 49 50 bool AppInstaller::CheckRequestorAlive() const { 51 // The tab may have gone away - cancel installation in that case. 52 return web_contents_ != NULL; 53 } 54 55 const GURL& AppInstaller::GetRequestorURL() const { 56 return GURL::EmptyGURL(); 57 } 58 59 scoped_refptr<ExtensionInstallPrompt::Prompt> 60 AppInstaller::CreateInstallPrompt() const { 61 if (silent_installation_) 62 return NULL; 63 64 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt( 65 new ExtensionInstallPrompt::Prompt( 66 ExtensionInstallPrompt::INLINE_INSTALL_PROMPT)); 67 68 prompt->SetWebstoreData(localized_user_count(), 69 show_user_count(), 70 average_rating(), 71 rating_count()); 72 return prompt; 73 } 74 75 bool AppInstaller::ShouldShowPostInstallUI() const { 76 return false; 77 } 78 79 bool AppInstaller::ShouldShowAppInstalledBubble() const { 80 return false; 81 } 82 83 content::WebContents* AppInstaller::GetWebContents() const { 84 return web_contents_; 85 } 86 87 bool AppInstaller::CheckInlineInstallPermitted( 88 const base::DictionaryValue& webstore_data, 89 std::string* error) const { 90 DCHECK(error != NULL); 91 DCHECK(error->empty()); 92 return true; 93 } 94 95 bool AppInstaller::CheckRequestorPermitted( 96 const base::DictionaryValue& webstore_data, 97 std::string* error) const { 98 DCHECK(error != NULL); 99 DCHECK(error->empty()); 100 return true; 101 } 102 103 void AppInstaller::OnWebContentsDestroyed( 104 content::WebContents* web_contents) { 105 callback_.Run(false, 106 kWebContentsDestroyedError, 107 extensions::webstore_install::OTHER_ERROR); 108 AbortInstall(); 109 } 110 111 } // namespace file_manager 112