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

Side by Side Diff: chrome/browser/ui/webui/constrained_web_dialog_delegate_base.cc

Issue 2798583002: WebUI: prevent WebContent to hold invalid pointer. (Closed)
Patch Set: Remove reference to |this| when the WebContent is no more owned. Created 3 years, 8 months 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h" 5 #include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/renderer_preferences_util.h" 10 #include "chrome/browser/renderer_preferences_util.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 web_contents_->SetDelegate(this); 42 web_contents_->SetDelegate(this);
43 } 43 }
44 content::RendererPreferences* prefs = 44 content::RendererPreferences* prefs =
45 web_contents_->GetMutableRendererPrefs(); 45 web_contents_->GetMutableRendererPrefs();
46 renderer_preferences_util::UpdateFromSystemSettings( 46 renderer_preferences_util::UpdateFromSystemSettings(
47 prefs, Profile::FromBrowserContext(browser_context), web_contents_.get()); 47 prefs, Profile::FromBrowserContext(browser_context), web_contents_.get());
48 48
49 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); 49 web_contents_->GetRenderViewHost()->SyncRendererPrefs();
50 50
51 // Set |this| as a delegate so the ConstrainedWebDialogUI can retrieve it. 51 // Set |this| as a delegate so the ConstrainedWebDialogUI can retrieve it.
52 ConstrainedWebDialogUI::SetConstrainedDelegate(web_contents_.get(), this); 52 ConstrainedWebDialogUI::SetConstrainedDelegate(web_contents_.get(), this);
arthursonzogni 2017/04/04 14:32:15 FYI: the |this| pointer is given to the WebContent
53 53
54 web_contents_->GetController().LoadURL(delegate->GetDialogContentURL(), 54 web_contents_->GetController().LoadURL(delegate->GetDialogContentURL(),
55 content::Referrer(), 55 content::Referrer(),
56 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 56 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
57 std::string()); 57 std::string());
58 } 58 }
59 59
60 ConstrainedWebDialogDelegateBase::~ConstrainedWebDialogDelegateBase() { 60 ConstrainedWebDialogDelegateBase::~ConstrainedWebDialogDelegateBase() {
61 if (release_contents_on_close_) 61 if (release_contents_on_close_)
62 ignore_result(web_contents_.release()); 62 ignore_result(web_contents_.release());
Avi (use Gerrit) 2017/04/04 14:49:46 (read the other comment first) This if() block se
arthursonzogni 2017/04/04 15:17:52 Yes, that is what I have done in the first patch.
Lei Zhang 2017/04/06 08:27:55 Can you check to see what thread it's being called
63 } 63 }
64 64
65 const WebDialogDelegate* 65 const WebDialogDelegate*
66 ConstrainedWebDialogDelegateBase::GetWebDialogDelegate() const { 66 ConstrainedWebDialogDelegateBase::GetWebDialogDelegate() const {
67 return web_dialog_delegate_.get(); 67 return web_dialog_delegate_.get();
68 } 68 }
69 69
70 WebDialogDelegate* 70 WebDialogDelegate*
71 ConstrainedWebDialogDelegateBase::GetWebDialogDelegate() { 71 ConstrainedWebDialogDelegateBase::GetWebDialogDelegate() {
72 return web_dialog_delegate_.get(); 72 return web_dialog_delegate_.get();
73 } 73 }
74 74
75 void ConstrainedWebDialogDelegateBase::OnDialogCloseFromWebUI() { 75 void ConstrainedWebDialogDelegateBase::OnDialogCloseFromWebUI() {
76 closed_via_webui_ = true; 76 closed_via_webui_ = true;
77 CloseContents(web_contents_.get()); 77 CloseContents(web_contents_.get());
78 } 78 }
79 79
80 bool ConstrainedWebDialogDelegateBase::closed_via_webui() const { 80 bool ConstrainedWebDialogDelegateBase::closed_via_webui() const {
81 return closed_via_webui_; 81 return closed_via_webui_;
82 } 82 }
83 83
84 void ConstrainedWebDialogDelegateBase::ReleaseWebContentsOnDialogClose() { 84 void ConstrainedWebDialogDelegateBase::ReleaseWebContentsOnDialogClose() {
85 // Remove reference to |this| in the WebContent since the lifetime of the
86 // WebContent may exceed the one of this object.
87 ConstrainedWebDialogUI::ClearConstrainedDelegate(web_contents_.get());
Avi (use Gerrit) 2017/04/04 14:49:46 This doesn't look right. // If called, on dialo
arthursonzogni 2017/04/04 15:17:52 I can't. [See the answer above]. Clearing the poin
Lei Zhang 2017/04/06 09:12:54 Please double check my work: Starting from PrintP
85 release_contents_on_close_ = true; 88 release_contents_on_close_ = true;
86 } 89 }
87 90
88 gfx::NativeWindow ConstrainedWebDialogDelegateBase::GetNativeDialog() { 91 gfx::NativeWindow ConstrainedWebDialogDelegateBase::GetNativeDialog() {
89 NOTREACHED(); 92 NOTREACHED();
90 return NULL; 93 return NULL;
91 } 94 }
92 95
93 WebContents* ConstrainedWebDialogDelegateBase::GetWebContents() { 96 WebContents* ConstrainedWebDialogDelegateBase::GetWebContents() {
94 return web_contents_.get(); 97 return web_contents_.get();
(...skipping 16 matching lines...) Expand all
111 114
112 gfx::Size ConstrainedWebDialogDelegateBase::GetPreferredSize() const { 115 gfx::Size ConstrainedWebDialogDelegateBase::GetPreferredSize() const {
113 NOTREACHED(); 116 NOTREACHED();
114 return gfx::Size(); 117 return gfx::Size();
115 } 118 }
116 119
117 void ConstrainedWebDialogDelegateBase::ResizeToGivenSize( 120 void ConstrainedWebDialogDelegateBase::ResizeToGivenSize(
118 const gfx::Size size) { 121 const gfx::Size size) {
119 NOTREACHED(); 122 NOTREACHED();
120 } 123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698