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

Side by Side Diff: chrome/browser/jsmessage_box_handler_win.cc

Issue 56205: NULL check web_contents_ to prevent a crash. (Closed)
Patch Set: Created 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/jsmessage_box_handler_win.h" 5 #include "chrome/browser/jsmessage_box_handler_win.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "chrome/browser/app_modal_dialog_queue.h" 8 #include "chrome/browser/app_modal_dialog_queue.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profile.h" 10 #include "chrome/browser/profile.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 if (dialog_flags_ & MessageBox::kFlagHasOKButton) 77 if (dialog_flags_ & MessageBox::kFlagHasOKButton)
78 dialog_buttons = DIALOGBUTTON_OK; 78 dialog_buttons = DIALOGBUTTON_OK;
79 79
80 if (dialog_flags_ & MessageBox::kFlagHasCancelButton) 80 if (dialog_flags_ & MessageBox::kFlagHasCancelButton)
81 dialog_buttons |= DIALOGBUTTON_CANCEL; 81 dialog_buttons |= DIALOGBUTTON_CANCEL;
82 82
83 return dialog_buttons; 83 return dialog_buttons;
84 } 84 }
85 85
86 std::wstring JavascriptMessageBoxHandler::GetWindowTitle() const { 86 std::wstring JavascriptMessageBoxHandler::GetWindowTitle() const {
87 if (!frame_url_.has_host()) 87 if (!frame_url_.has_host() || !web_contents_)
88 return l10n_util::GetString(IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE); 88 return l10n_util::GetString(IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE);
89 89
90 // We really only want the scheme, hostname, and port. 90 // We really only want the scheme, hostname, and port.
91 GURL::Replacements replacements; 91 GURL::Replacements replacements;
92 replacements.ClearUsername(); 92 replacements.ClearUsername();
93 replacements.ClearPassword(); 93 replacements.ClearPassword();
94 replacements.ClearPath(); 94 replacements.ClearPath();
95 replacements.ClearQuery(); 95 replacements.ClearQuery();
96 replacements.ClearRef(); 96 replacements.ClearRef();
97 GURL clean_url = frame_url_.ReplaceComponents(replacements); 97 GURL clean_url = frame_url_.ReplaceComponents(replacements);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 return message_box_view_->text_box(); 182 return message_box_view_->text_box();
183 return views::AppModalDialogDelegate::GetInitiallyFocusedView(); 183 return views::AppModalDialogDelegate::GetInitiallyFocusedView();
184 } 184 }
185 185
186 /////////////////////////////////////////////////////////////////////////////// 186 ///////////////////////////////////////////////////////////////////////////////
187 // JavascriptMessageBoxHandler, private: 187 // JavascriptMessageBoxHandler, private:
188 188
189 void JavascriptMessageBoxHandler::Observe(NotificationType type, 189 void JavascriptMessageBoxHandler::Observe(NotificationType type,
190 const NotificationSource& source, 190 const NotificationSource& source,
191 const NotificationDetails& details) { 191 const NotificationDetails& details) {
192 bool web_contents_gone = false;
193 if (!web_contents_) 192 if (!web_contents_)
194 return; 193 return;
195 194
195 bool web_contents_gone = false;
196
196 if (type == NotificationType::NAV_ENTRY_COMMITTED && 197 if (type == NotificationType::NAV_ENTRY_COMMITTED &&
197 Source<NavigationController>(source).ptr() == web_contents_->controller()) 198 Source<NavigationController>(source).ptr() == web_contents_->controller())
198 web_contents_gone = true; 199 web_contents_gone = true;
199 200
200 if (type == NotificationType::TAB_CONTENTS_DESTROYED && 201 if (type == NotificationType::TAB_CONTENTS_DESTROYED &&
201 Source<TabContents>(source).ptr() == 202 Source<TabContents>(source).ptr() ==
202 static_cast<TabContents*>(web_contents_)) 203 static_cast<TabContents*>(web_contents_))
203 web_contents_gone = true; 204 web_contents_gone = true;
204 205
205 if (web_contents_gone) { 206 if (web_contents_gone) {
206 web_contents_ = NULL; 207 web_contents_ = NULL;
207 208
208 // If the dialog is visible close it. 209 // If the dialog is visible close it.
209 if (dialog_) 210 if (dialog_)
210 dialog_->Close(); 211 dialog_->Close();
211 } 212 }
212 } 213 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698