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

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: prevent ConstrainedWebDialogBase to hold an invalid pointer. 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 16 matching lines...) Expand all
27 WebDialogDelegate* delegate, 27 WebDialogDelegate* delegate,
28 WebDialogWebContentsDelegate* tab_delegate) 28 WebDialogWebContentsDelegate* tab_delegate)
29 : WebDialogWebContentsDelegate(browser_context, 29 : WebDialogWebContentsDelegate(browser_context,
30 new ChromeWebContentsHandler), 30 new ChromeWebContentsHandler),
31 web_dialog_delegate_(delegate), 31 web_dialog_delegate_(delegate),
32 closed_via_webui_(false), 32 closed_via_webui_(false),
33 release_contents_on_close_(false) { 33 release_contents_on_close_(false) {
34 CHECK(delegate); 34 CHECK(delegate);
35 web_contents_.reset( 35 web_contents_.reset(
36 WebContents::Create(WebContents::CreateParams(browser_context))); 36 WebContents::Create(WebContents::CreateParams(browser_context)));
37 WebContentsObserver::Observe(web_contents_.get());
37 zoom::ZoomController::CreateForWebContents(web_contents_.get()); 38 zoom::ZoomController::CreateForWebContents(web_contents_.get());
38 if (tab_delegate) { 39 if (tab_delegate) {
39 override_tab_delegate_.reset(tab_delegate); 40 override_tab_delegate_.reset(tab_delegate);
40 web_contents_->SetDelegate(tab_delegate); 41 web_contents_->SetDelegate(tab_delegate);
41 } else { 42 } else {
42 web_contents_->SetDelegate(this); 43 web_contents_->SetDelegate(this);
43 } 44 }
44 content::RendererPreferences* prefs = 45 content::RendererPreferences* prefs =
45 web_contents_->GetMutableRendererPrefs(); 46 web_contents_->GetMutableRendererPrefs();
46 renderer_preferences_util::UpdateFromSystemSettings( 47 renderer_preferences_util::UpdateFromSystemSettings(
47 prefs, Profile::FromBrowserContext(browser_context), web_contents_.get()); 48 prefs, Profile::FromBrowserContext(browser_context), web_contents_.get());
48 49
49 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); 50 web_contents_->GetRenderViewHost()->SyncRendererPrefs();
50 51
51 // Set |this| as a delegate so the ConstrainedWebDialogUI can retrieve it. 52 // Set |this| as a delegate so the ConstrainedWebDialogUI can retrieve it.
52 ConstrainedWebDialogUI::SetConstrainedDelegate(web_contents_.get(), this); 53 ConstrainedWebDialogUI::SetConstrainedDelegate(web_contents_.get(), this);
53 54
54 web_contents_->GetController().LoadURL(delegate->GetDialogContentURL(), 55 web_contents_->GetController().LoadURL(delegate->GetDialogContentURL(),
55 content::Referrer(), 56 content::Referrer(),
56 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 57 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
57 std::string()); 58 std::string());
58 } 59 }
59 60
60 ConstrainedWebDialogDelegateBase::~ConstrainedWebDialogDelegateBase() { 61 ConstrainedWebDialogDelegateBase::~ConstrainedWebDialogDelegateBase() {
61 if (release_contents_on_close_) 62 if (release_contents_on_close_ && web_contents_) {
63 // Remove reference to |this| in the WebContent since the lifetime of the
64 // WebContent may exceed the one of this object.
65 ConstrainedWebDialogUI::ClearConstrainedDelegate(web_contents_.get());
62 ignore_result(web_contents_.release()); 66 ignore_result(web_contents_.release());
67 }
63 } 68 }
64 69
65 const WebDialogDelegate* 70 const WebDialogDelegate*
66 ConstrainedWebDialogDelegateBase::GetWebDialogDelegate() const { 71 ConstrainedWebDialogDelegateBase::GetWebDialogDelegate() const {
67 return web_dialog_delegate_.get(); 72 return web_dialog_delegate_.get();
68 } 73 }
69 74
70 WebDialogDelegate* 75 WebDialogDelegate*
71 ConstrainedWebDialogDelegateBase::GetWebDialogDelegate() { 76 ConstrainedWebDialogDelegateBase::GetWebDialogDelegate() {
72 return web_dialog_delegate_.get(); 77 return web_dialog_delegate_.get();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 gfx::Size ConstrainedWebDialogDelegateBase::GetMaximumSize() const { 112 gfx::Size ConstrainedWebDialogDelegateBase::GetMaximumSize() const {
108 NOTREACHED(); 113 NOTREACHED();
109 return gfx::Size(); 114 return gfx::Size();
110 } 115 }
111 116
112 gfx::Size ConstrainedWebDialogDelegateBase::GetPreferredSize() const { 117 gfx::Size ConstrainedWebDialogDelegateBase::GetPreferredSize() const {
113 NOTREACHED(); 118 NOTREACHED();
114 return gfx::Size(); 119 return gfx::Size();
115 } 120 }
116 121
122 void ConstrainedWebDialogDelegateBase::WebContentsDestroyed() {
123 web_contents_.release();
Lei Zhang 2017/04/07 00:55:22 This release() makes the ownership of |web_content
124 }
125
117 void ConstrainedWebDialogDelegateBase::ResizeToGivenSize( 126 void ConstrainedWebDialogDelegateBase::ResizeToGivenSize(
118 const gfx::Size size) { 127 const gfx::Size size) {
119 NOTREACHED(); 128 NOTREACHED();
120 } 129 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h ('k') | chrome/browser/ui/webui/constrained_web_dialog_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698