Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: chrome/browser/extensions/extension_install_prompt_show_params.cc

Issue 662073002: Fix crash when user closes window prior to the "Confirm Install" prompt showing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/install_prompt_navigator
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_deletion_observer.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 NULL;
17 return Profile::FromBrowserContext(web_contents->GetBrowserContext());
18 }
19
20 gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) {
21 if (!contents)
22 return NULL;
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_deletion_observer_ =
64 NativeWindowDeletionObserver::Create(parent_window_);
65 }
66 }
67
68 ExtensionInstallPromptShowParams::ExtensionInstallPromptShowParams(
69 Profile* profile,
70 gfx::NativeWindow parent_window)
71 : profile_(profile),
72 parent_web_contents_(NULL),
73 parent_web_contents_destroyed_(false),
74 parent_window_(parent_window) {
75 if (parent_window_) {
76 native_window_deletion_observer_ =
77 NativeWindowDeletionObserver::Create(parent_window_);
78 }
79 }
80
81 ExtensionInstallPromptShowParams::~ExtensionInstallPromptShowParams() {
82 }
83
84 content::WebContents* ExtensionInstallPromptShowParams::GetParentWebContents() {
85 return parent_web_contents_;
86 }
87
88 gfx::NativeWindow ExtensionInstallPromptShowParams::GetParentWindow() {
89 return (native_window_deletion_observer_ &&
90 native_window_deletion_observer_->IsNativeWindowAlive())
91 ? parent_window_
92 : NULL;
93 }
94
95 bool ExtensionInstallPromptShowParams::WasParentDestroyed() {
96 return parent_web_contents_destroyed_ ||
97 (native_window_deletion_observer_ &&
98 !native_window_deletion_observer_->IsNativeWindowAlive());
99 }
100
101 void ExtensionInstallPromptShowParams::WebContentsDestroyed() {
102 parent_web_contents_ = NULL;
103 parent_web_contents_destroyed_ = true;
104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698