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"
14 Profile
* ProfileForWebContents(content::WebContents
* web_contents
) {
17 return Profile::FromBrowserContext(web_contents
->GetBrowserContext());
20 gfx::NativeWindow
NativeWindowForWebContents(content::WebContents
* contents
) {
24 return contents
->GetTopLevelNativeWindow();
29 class ExtensionInstallPromptShowParams::WebContentsDestructionObserver
30 : public content::WebContentsObserver
{
32 explicit WebContentsDestructionObserver(
33 ExtensionInstallPromptShowParams
* params
)
34 : content::WebContentsObserver(params
->GetParentWebContents()),
38 ~WebContentsDestructionObserver() override
{}
40 void WebContentsDestroyed() override
{ params_
->WebContentsDestroyed(); }
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
)) {
56 web_contents_destruction_observer_
.reset(
57 new WebContentsDestructionObserver(this));
60 native_window_tracker_
= NativeWindowTracker::Create(parent_window_
);
63 ExtensionInstallPromptShowParams::ExtensionInstallPromptShowParams(
65 gfx::NativeWindow parent_window
)
67 parent_web_contents_(nullptr),
68 parent_web_contents_destroyed_(false),
69 parent_window_(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())
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;