1// 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_install_with_prompt.h" 6 7#include "chrome/browser/extensions/webstore_installer.h" 8#include "chrome/browser/profiles/profile.h" 9#include "chrome/browser/ui/browser.h" 10#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 11#include "content/public/browser/web_contents.h" 12 13using content::WebContents; 14 15namespace extensions { 16 17WebstoreInstallWithPrompt::WebstoreInstallWithPrompt( 18 const std::string& webstore_item_id, 19 Profile* profile, 20 const Callback& callback) 21 : WebstoreStandaloneInstaller(webstore_item_id, profile, callback), 22 show_post_install_ui_(true), 23 dummy_web_contents_( 24 WebContents::Create(WebContents::CreateParams(profile))), 25 parent_window_(NULL) { 26 set_install_source(WebstoreInstaller::INSTALL_SOURCE_OTHER); 27} 28 29WebstoreInstallWithPrompt::WebstoreInstallWithPrompt( 30 const std::string& webstore_item_id, 31 Profile* profile, 32 gfx::NativeWindow parent_window, 33 const Callback& callback) 34 : WebstoreStandaloneInstaller(webstore_item_id, profile, callback), 35 show_post_install_ui_(true), 36 dummy_web_contents_( 37 WebContents::Create(WebContents::CreateParams(profile))), 38 parent_window_(parent_window) { 39 DCHECK(parent_window); 40 set_install_source(WebstoreInstaller::INSTALL_SOURCE_OTHER); 41} 42 43WebstoreInstallWithPrompt::~WebstoreInstallWithPrompt() { 44} 45 46bool WebstoreInstallWithPrompt::CheckRequestorAlive() const { 47 // Assume the requestor is always alive. 48 return true; 49} 50 51const GURL& WebstoreInstallWithPrompt::GetRequestorURL() const { 52 return dummy_requestor_url_; 53} 54 55scoped_refptr<ExtensionInstallPrompt::Prompt> 56WebstoreInstallWithPrompt::CreateInstallPrompt() const { 57 return new ExtensionInstallPrompt::Prompt( 58 ExtensionInstallPrompt::INSTALL_PROMPT); 59} 60 61scoped_ptr<ExtensionInstallPrompt> 62WebstoreInstallWithPrompt::CreateInstallUI() { 63 // Create an ExtensionInstallPrompt. If the parent window is NULL, the dialog 64 // will be placed in the middle of the screen. 65 return make_scoped_ptr( 66 new ExtensionInstallPrompt(profile(), parent_window_, this)); 67} 68 69bool WebstoreInstallWithPrompt::ShouldShowPostInstallUI() const { 70 return show_post_install_ui_; 71} 72 73bool WebstoreInstallWithPrompt::ShouldShowAppInstalledBubble() const { 74 return false; 75} 76 77WebContents* WebstoreInstallWithPrompt::GetWebContents() const { 78 return dummy_web_contents_.get(); 79} 80 81bool WebstoreInstallWithPrompt::CheckInlineInstallPermitted( 82 const base::DictionaryValue& webstore_data, 83 std::string* error) const { 84 // Assume the requestor is trusted. 85 *error = std::string(); 86 return true; 87} 88 89bool WebstoreInstallWithPrompt::CheckRequestorPermitted( 90 const base::DictionaryValue& webstore_data, 91 std::string* error) const { 92 // Assume the requestor is trusted. 93 *error = std::string(); 94 return true; 95} 96 97content::WebContents* WebstoreInstallWithPrompt::OpenURL( 98 const content::OpenURLParams& params) { 99 chrome::ScopedTabbedBrowserDisplayer displayer(profile(), 100 chrome::GetActiveDesktop()); 101 return displayer.browser()->OpenURL(params); 102} 103 104} // namespace extensions 105