Home | History | Annotate | Download | only in extensions
      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 
     13 using content::WebContents;
     14 
     15 namespace extensions {
     16 
     17 WebstoreInstallWithPrompt::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 
     29 WebstoreInstallWithPrompt::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 
     43 WebstoreInstallWithPrompt::~WebstoreInstallWithPrompt() {
     44 }
     45 
     46 bool WebstoreInstallWithPrompt::CheckRequestorAlive() const {
     47   // Assume the requestor is always alive.
     48   return true;
     49 }
     50 
     51 const GURL& WebstoreInstallWithPrompt::GetRequestorURL() const {
     52   return dummy_requestor_url_;
     53 }
     54 
     55 scoped_refptr<ExtensionInstallPrompt::Prompt>
     56 WebstoreInstallWithPrompt::CreateInstallPrompt() const {
     57   return new ExtensionInstallPrompt::Prompt(
     58       ExtensionInstallPrompt::INSTALL_PROMPT);
     59 }
     60 
     61 scoped_ptr<ExtensionInstallPrompt>
     62 WebstoreInstallWithPrompt::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 
     69 bool WebstoreInstallWithPrompt::ShouldShowPostInstallUI() const {
     70   return show_post_install_ui_;
     71 }
     72 
     73 bool WebstoreInstallWithPrompt::ShouldShowAppInstalledBubble() const {
     74   return false;
     75 }
     76 
     77 WebContents* WebstoreInstallWithPrompt::GetWebContents() const {
     78   return dummy_web_contents_.get();
     79 }
     80 
     81 bool 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 
     89 bool 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 
     97 content::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