| OLD | NEW |
| (Empty) |
| 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/extension_install_prompt_show_params.h" | |
| 6 | |
| 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" | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 Profile* ProfileForWebContents(content::WebContents* web_contents) { | |
| 15 if (!web_contents) | |
| 16 return nullptr; | |
| 17 return Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
| 18 } | |
| 19 | |
| 20 gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) { | |
| 21 if (!contents) | |
| 22 return nullptr; | |
| 23 | |
| 24 return contents->GetTopLevelNativeWindow(); | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 class ExtensionInstallPromptShowParams::WebContentsDestructionObserver | |
| 30 : public content::WebContentsObserver { | |
| 31 public: | |
| 32 explicit WebContentsDestructionObserver( | |
| 33 ExtensionInstallPromptShowParams* params) | |
| 34 : content::WebContentsObserver(params->GetParentWebContents()), | |
| 35 params_(params) { | |
| 36 } | |
| 37 | |
| 38 virtual ~WebContentsDestructionObserver() { | |
| 39 } | |
| 40 | |
| 41 virtual void WebContentsDestroyed() override { | |
| 42 params_->WebContentsDestroyed(); | |
| 43 } | |
| 44 | |
| 45 private: | |
| 46 // Not owned. | |
| 47 ExtensionInstallPromptShowParams* params_; | |
| 48 | |
| 49 DISALLOW_COPY_AND_ASSIGN(WebContentsDestructionObserver); | |
| 50 }; | |
| 51 | |
| 52 ExtensionInstallPromptShowParams::ExtensionInstallPromptShowParams( | |
| 53 content::WebContents* contents) | |
| 54 : profile_(ProfileForWebContents(contents)), | |
| 55 parent_web_contents_(contents), | |
| 56 parent_web_contents_destroyed_(false), | |
| 57 parent_window_(NativeWindowForWebContents(contents)) { | |
| 58 if (contents) { | |
| 59 web_contents_destruction_observer_.reset( | |
| 60 new WebContentsDestructionObserver(this)); | |
| 61 } | |
| 62 if (parent_window_) | |
| 63 native_window_tracker_ = NativeWindowTracker::Create(parent_window_); | |
| 64 } | |
| 65 | |
| 66 ExtensionInstallPromptShowParams::ExtensionInstallPromptShowParams( | |
| 67 Profile* profile, | |
| 68 gfx::NativeWindow parent_window) | |
| 69 : profile_(profile), | |
| 70 parent_web_contents_(nullptr), | |
| 71 parent_web_contents_destroyed_(false), | |
| 72 parent_window_(parent_window) { | |
| 73 if (parent_window_) | |
| 74 native_window_tracker_ = NativeWindowTracker::Create(parent_window_); | |
| 75 } | |
| 76 | |
| 77 ExtensionInstallPromptShowParams::~ExtensionInstallPromptShowParams() { | |
| 78 } | |
| 79 | |
| 80 content::WebContents* ExtensionInstallPromptShowParams::GetParentWebContents() { | |
| 81 return parent_web_contents_; | |
| 82 } | |
| 83 | |
| 84 gfx::NativeWindow ExtensionInstallPromptShowParams::GetParentWindow() { | |
| 85 return (native_window_tracker_ && | |
| 86 !native_window_tracker_->WasNativeWindowClosed()) | |
| 87 ? parent_window_ | |
| 88 : nullptr; | |
| 89 } | |
| 90 | |
| 91 bool ExtensionInstallPromptShowParams::WasParentDestroyed() { | |
| 92 return parent_web_contents_destroyed_ || | |
| 93 (native_window_tracker_ && | |
| 94 native_window_tracker_->WasNativeWindowClosed()); | |
| 95 } | |
| 96 | |
| 97 void ExtensionInstallPromptShowParams::WebContentsDestroyed() { | |
| 98 parent_web_contents_ = nullptr; | |
| 99 parent_web_contents_destroyed_ = true; | |
| 100 } | |
| OLD | NEW |