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.
5 #include "chrome/browser/extensions/webstore_install_with_prompt.h"
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"
13 using content::WebContents
;
15 namespace extensions
{
17 WebstoreInstallWithPrompt::WebstoreInstallWithPrompt(
18 const std::string
& webstore_item_id
,
20 const Callback
& callback
)
21 : WebstoreStandaloneInstaller(webstore_item_id
, profile
, callback
),
22 show_post_install_ui_(true),
24 WebContents::Create(WebContents::CreateParams(profile
))),
25 parent_window_(NULL
) {
26 set_install_source(WebstoreInstaller::INSTALL_SOURCE_OTHER
);
29 WebstoreInstallWithPrompt::WebstoreInstallWithPrompt(
30 const std::string
& webstore_item_id
,
32 gfx::NativeWindow parent_window
,
33 const Callback
& callback
)
34 : WebstoreStandaloneInstaller(webstore_item_id
, profile
, callback
),
35 show_post_install_ui_(true),
37 WebContents::Create(WebContents::CreateParams(profile
))),
38 parent_window_(parent_window
) {
39 DCHECK(parent_window
);
40 set_install_source(WebstoreInstaller::INSTALL_SOURCE_OTHER
);
43 WebstoreInstallWithPrompt::~WebstoreInstallWithPrompt() {
46 bool WebstoreInstallWithPrompt::CheckRequestorAlive() const {
47 // Assume the requestor is always alive.
51 const GURL
& WebstoreInstallWithPrompt::GetRequestorURL() const {
52 return dummy_requestor_url_
;
55 scoped_refptr
<ExtensionInstallPrompt::Prompt
>
56 WebstoreInstallWithPrompt::CreateInstallPrompt() const {
57 return new ExtensionInstallPrompt::Prompt(
58 ExtensionInstallPrompt::INSTALL_PROMPT
);
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));
69 bool WebstoreInstallWithPrompt::ShouldShowPostInstallUI() const {
70 return show_post_install_ui_
;
73 bool WebstoreInstallWithPrompt::ShouldShowAppInstalledBubble() const {
77 WebContents
* WebstoreInstallWithPrompt::GetWebContents() const {
78 return dummy_web_contents_
.get();
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();
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();
97 content::WebContents
* WebstoreInstallWithPrompt::OpenURL(
98 const content::OpenURLParams
& params
) {
99 chrome::ScopedTabbedBrowserDisplayer
displayer(profile(),
100 chrome::GetActiveDesktop());
101 return displayer
.browser()->OpenURL(params
);
104 } // namespace extensions