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
WebstoreInstallWithPrompt(const std::string & webstore_item_id,Profile * profile,const Callback & callback)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 dummy_web_contents_(
23 WebContents::Create(WebContents::CreateParams(profile))),
24 parent_window_(NULL) {
25 set_install_source(WebstoreInstaller::INSTALL_SOURCE_OTHER);
26 }
27
WebstoreInstallWithPrompt(const std::string & webstore_item_id,Profile * profile,gfx::NativeWindow parent_window,const Callback & callback)28 WebstoreInstallWithPrompt::WebstoreInstallWithPrompt(
29 const std::string& webstore_item_id,
30 Profile* profile,
31 gfx::NativeWindow parent_window,
32 const Callback& callback)
33 : WebstoreStandaloneInstaller(webstore_item_id, profile, callback),
34 dummy_web_contents_(
35 WebContents::Create(WebContents::CreateParams(profile))),
36 parent_window_(parent_window) {
37 DCHECK(parent_window);
38 set_install_source(WebstoreInstaller::INSTALL_SOURCE_OTHER);
39 }
40
~WebstoreInstallWithPrompt()41 WebstoreInstallWithPrompt::~WebstoreInstallWithPrompt() {
42 }
43
CheckRequestorAlive() const44 bool WebstoreInstallWithPrompt::CheckRequestorAlive() const {
45 // Assume the requestor is always alive.
46 return true;
47 }
48
GetRequestorURL() const49 const GURL& WebstoreInstallWithPrompt::GetRequestorURL() const {
50 return dummy_requestor_url_;
51 }
52
53 scoped_refptr<ExtensionInstallPrompt::Prompt>
CreateInstallPrompt() const54 WebstoreInstallWithPrompt::CreateInstallPrompt() const {
55 return new ExtensionInstallPrompt::Prompt(
56 ExtensionInstallPrompt::INSTALL_PROMPT);
57 }
58
59 scoped_ptr<ExtensionInstallPrompt>
CreateInstallUI()60 WebstoreInstallWithPrompt::CreateInstallUI() {
61 // Create an ExtensionInstallPrompt. If the parent window is NULL, the dialog
62 // will be placed in the middle of the screen.
63 return make_scoped_ptr(
64 new ExtensionInstallPrompt(profile(), parent_window_, this));
65 }
66
ShouldShowPostInstallUI() const67 bool WebstoreInstallWithPrompt::ShouldShowPostInstallUI() const {
68 return false;
69 }
70
ShouldShowAppInstalledBubble() const71 bool WebstoreInstallWithPrompt::ShouldShowAppInstalledBubble() const {
72 return false;
73 }
74
GetWebContents() const75 WebContents* WebstoreInstallWithPrompt::GetWebContents() const {
76 return dummy_web_contents_.get();
77 }
78
CheckInlineInstallPermitted(const base::DictionaryValue & webstore_data,std::string * error) const79 bool WebstoreInstallWithPrompt::CheckInlineInstallPermitted(
80 const base::DictionaryValue& webstore_data,
81 std::string* error) const {
82 // Assume the requestor is trusted.
83 *error = std::string();
84 return true;
85 }
86
CheckRequestorPermitted(const base::DictionaryValue & webstore_data,std::string * error) const87 bool WebstoreInstallWithPrompt::CheckRequestorPermitted(
88 const base::DictionaryValue& webstore_data,
89 std::string* error) const {
90 // Assume the requestor is trusted.
91 *error = std::string();
92 return true;
93 }
94
OpenURL(const content::OpenURLParams & params)95 content::WebContents* WebstoreInstallWithPrompt::OpenURL(
96 const content::OpenURLParams& params) {
97 chrome::ScopedTabbedBrowserDisplayer displayer(profile(),
98 chrome::GetActiveDesktop());
99 return displayer.browser()->OpenURL(params);
100 }
101
102 } // namespace extensions
103