Add a webstorePrivate API to show a permission prompt for delegated bundle installs
[chromium-blink-merge.git] / chrome / browser / extensions / extension_install_prompt_show_params.cc
blob953ed36114f289efbb3ea1e76f616efd2882318e
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/extension_install_prompt_show_params.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/native_window_tracker.h"
9 #include "content/public/browser/web_contents.h"
10 #include "content/public/browser/web_contents_observer.h"
12 namespace {
14 Profile* ProfileForWebContents(content::WebContents* web_contents) {
15 if (!web_contents)
16 return nullptr;
17 return Profile::FromBrowserContext(web_contents->GetBrowserContext());
20 gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) {
21 if (!contents)
22 return nullptr;
24 return contents->GetTopLevelNativeWindow();
27 } // namespace
29 class ExtensionInstallPromptShowParams::WebContentsDestructionObserver
30 : public content::WebContentsObserver {
31 public:
32 explicit WebContentsDestructionObserver(
33 ExtensionInstallPromptShowParams* params)
34 : content::WebContentsObserver(params->GetParentWebContents()),
35 params_(params) {
38 ~WebContentsDestructionObserver() override {}
40 void WebContentsDestroyed() override { params_->WebContentsDestroyed(); }
42 private:
43 // Not owned.
44 ExtensionInstallPromptShowParams* params_;
46 DISALLOW_COPY_AND_ASSIGN(WebContentsDestructionObserver);
49 ExtensionInstallPromptShowParams::ExtensionInstallPromptShowParams(
50 content::WebContents* contents)
51 : profile_(ProfileForWebContents(contents)),
52 parent_web_contents_(contents),
53 parent_web_contents_destroyed_(false),
54 parent_window_(NativeWindowForWebContents(contents)) {
55 if (contents) {
56 web_contents_destruction_observer_.reset(
57 new WebContentsDestructionObserver(this));
59 if (parent_window_)
60 native_window_tracker_ = NativeWindowTracker::Create(parent_window_);
63 ExtensionInstallPromptShowParams::ExtensionInstallPromptShowParams(
64 Profile* profile,
65 gfx::NativeWindow parent_window)
66 : profile_(profile),
67 parent_web_contents_(nullptr),
68 parent_web_contents_destroyed_(false),
69 parent_window_(parent_window) {
70 if (parent_window_)
71 native_window_tracker_ = NativeWindowTracker::Create(parent_window_);
74 ExtensionInstallPromptShowParams::~ExtensionInstallPromptShowParams() {
77 content::WebContents* ExtensionInstallPromptShowParams::GetParentWebContents() {
78 return parent_web_contents_;
81 gfx::NativeWindow ExtensionInstallPromptShowParams::GetParentWindow() {
82 return (native_window_tracker_ &&
83 !native_window_tracker_->WasNativeWindowClosed())
84 ? parent_window_
85 : nullptr;
88 bool ExtensionInstallPromptShowParams::WasParentDestroyed() {
89 return parent_web_contents_destroyed_ ||
90 (native_window_tracker_ &&
91 native_window_tracker_->WasNativeWindowClosed());
94 void ExtensionInstallPromptShowParams::WebContentsDestroyed() {
95 parent_web_contents_ = nullptr;
96 parent_web_contents_destroyed_ = true;