Add a webstorePrivate API to show a permission prompt for delegated bundle installs
[chromium-blink-merge.git] / chrome / browser / extensions / webstore_install_with_prompt.cc
blobb0ddf40c83e50028f37afeda352784af4e914cf2
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 "content/public/browser/web_contents.h"
11 using content::WebContents;
13 namespace extensions {
15 WebstoreInstallWithPrompt::WebstoreInstallWithPrompt(
16 const std::string& webstore_item_id,
17 Profile* profile,
18 const Callback& callback)
19 : WebstoreStandaloneInstaller(webstore_item_id, profile, callback),
20 show_post_install_ui_(true),
21 dummy_web_contents_(
22 WebContents::Create(WebContents::CreateParams(profile))),
23 parent_window_(NULL) {
24 set_install_source(WebstoreInstaller::INSTALL_SOURCE_OTHER);
27 WebstoreInstallWithPrompt::WebstoreInstallWithPrompt(
28 const std::string& webstore_item_id,
29 Profile* profile,
30 gfx::NativeWindow parent_window,
31 const Callback& callback)
32 : WebstoreStandaloneInstaller(webstore_item_id, profile, callback),
33 show_post_install_ui_(true),
34 dummy_web_contents_(
35 WebContents::Create(WebContents::CreateParams(profile))),
36 parent_window_(parent_window) {
37 if (parent_window_)
38 parent_window_tracker_ = NativeWindowTracker::Create(parent_window);
39 set_install_source(WebstoreInstaller::INSTALL_SOURCE_OTHER);
42 WebstoreInstallWithPrompt::~WebstoreInstallWithPrompt() {
45 bool WebstoreInstallWithPrompt::CheckRequestorAlive() const {
46 if (!parent_window_) {
47 // Assume the requestor is always alive if |parent_window_| is null.
48 return true;
50 return !parent_window_tracker_->WasNativeWindowClosed();
53 const GURL& WebstoreInstallWithPrompt::GetRequestorURL() const {
54 return dummy_requestor_url_;
57 scoped_refptr<ExtensionInstallPrompt::Prompt>
58 WebstoreInstallWithPrompt::CreateInstallPrompt() const {
59 return new ExtensionInstallPrompt::Prompt(
60 ExtensionInstallPrompt::INSTALL_PROMPT);
63 scoped_ptr<ExtensionInstallPrompt>
64 WebstoreInstallWithPrompt::CreateInstallUI() {
65 // Create an ExtensionInstallPrompt. If the parent window is NULL, the dialog
66 // will be placed in the middle of the screen.
67 return make_scoped_ptr(new ExtensionInstallPrompt(profile(), parent_window_));
70 bool WebstoreInstallWithPrompt::ShouldShowPostInstallUI() const {
71 return show_post_install_ui_;
74 bool WebstoreInstallWithPrompt::ShouldShowAppInstalledBubble() const {
75 return false;
78 WebContents* WebstoreInstallWithPrompt::GetWebContents() const {
79 return dummy_web_contents_.get();
82 bool WebstoreInstallWithPrompt::CheckInlineInstallPermitted(
83 const base::DictionaryValue& webstore_data,
84 std::string* error) const {
85 // Assume the requestor is trusted.
86 *error = std::string();
87 return true;
90 bool WebstoreInstallWithPrompt::CheckRequestorPermitted(
91 const base::DictionaryValue& webstore_data,
92 std::string* error) const {
93 // Assume the requestor is trusted.
94 *error = std::string();
95 return true;
98 } // namespace extensions