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

Side by Side Diff: chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.cc

Issue 25434002: Don't leave renderer process frozen when canceling JavaScript dialogs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial patch Created 7 years, 2 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 | Annotate | Revision Log
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/app_modal_dialogs/javascript_app_modal_dialog.h" 5 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/browser_shutdown.h" 8 #include "chrome/browser/browser_shutdown.h"
9 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" 9 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h"
10 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 ExtraDataMap* extra_data_map, 62 ExtraDataMap* extra_data_map,
63 const string16& title, 63 const string16& title,
64 content::JavaScriptMessageType javascript_message_type, 64 content::JavaScriptMessageType javascript_message_type,
65 const string16& message_text, 65 const string16& message_text,
66 const string16& default_prompt_text, 66 const string16& default_prompt_text,
67 bool display_suppress_checkbox, 67 bool display_suppress_checkbox,
68 bool is_before_unload_dialog, 68 bool is_before_unload_dialog,
69 bool is_reload, 69 bool is_reload,
70 const JavaScriptDialogManager::DialogClosedCallback& callback) 70 const JavaScriptDialogManager::DialogClosedCallback& callback)
71 : AppModalDialog(web_contents, title), 71 : AppModalDialog(web_contents, title),
72 WebContentsObserver(web_contents),
73 render_view_host_(web_contents->GetRenderViewHost()),
72 extra_data_map_(extra_data_map), 74 extra_data_map_(extra_data_map),
73 javascript_message_type_(javascript_message_type), 75 javascript_message_type_(javascript_message_type),
74 display_suppress_checkbox_(display_suppress_checkbox), 76 display_suppress_checkbox_(display_suppress_checkbox),
75 is_before_unload_dialog_(is_before_unload_dialog), 77 is_before_unload_dialog_(is_before_unload_dialog),
76 is_reload_(is_reload), 78 is_reload_(is_reload),
77 callback_(callback), 79 callback_(callback),
78 use_override_prompt_text_(false) { 80 use_override_prompt_text_(false) {
79 EnforceMaxTextSize(message_text, &message_text_); 81 EnforceMaxTextSize(message_text, &message_text_);
80 EnforceMaxPromptSize(default_prompt_text, &default_prompt_text_); 82 EnforceMaxPromptSize(default_prompt_text, &default_prompt_text_);
81 } 83 }
82 84
83 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() { 85 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() {
84 } 86 }
85 87
86 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() { 88 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() {
87 gfx::NativeWindow parent_window = 89 gfx::NativeWindow parent_window =
88 web_contents()->GetView()->GetTopLevelNativeWindow(); 90 AppModalDialog::web_contents()->GetView()->GetTopLevelNativeWindow();
89 91
90 #if defined(USE_AURA) 92 #if defined(USE_AURA)
91 if (!parent_window->GetRootWindow()) { 93 if (!parent_window->GetRootWindow()) {
92 // When we are part of a WebContents that isn't actually being displayed on 94 // When we are part of a WebContents that isn't actually being displayed on
93 // the screen, we can't actually attach to it. 95 // the screen, we can't actually attach to it.
94 parent_window = NULL; 96 parent_window = NULL;
95 } 97 }
96 #endif // defined(USE_AURA) 98 #endif // defined(USE_AURA)
97 99
98 return NativeAppModalDialog::CreateNativeJavaScriptPrompt(this, 100 return NativeAppModalDialog::CreateNativeJavaScriptPrompt(this,
99 parent_window); 101 parent_window);
100 } 102 }
101 103
102 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() { 104 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() {
103 return true; 105 return true;
104 } 106 }
105 107
106 void JavaScriptAppModalDialog::Invalidate() { 108 void JavaScriptAppModalDialog::Invalidate() {
107 if (!IsValid()) 109 if (!IsValid())
108 return; 110 return;
109 111
110 AppModalDialog::Invalidate(); 112 AppModalDialog::Invalidate();
111 callback_.Reset(); 113 if (!callback_.is_null()) {
114 callback_.Run(false, string16());
115 callback_.Reset();
116 }
112 if (native_dialog()) 117 if (native_dialog())
113 CloseModalDialog(); 118 CloseModalDialog();
114 } 119 }
115 120
121 void JavaScriptAppModalDialog::RenderViewDeleted(
Avi (use Gerrit) 2013/10/01 03:20:18 This really, really makes me sad. The old JavaScri
Charlie Reis 2013/10/01 16:39:29 That part was optional. The new WebContents metho
122 content::RenderViewHost* render_view_host) {
123 // Don't try to run the callback after the RenderViewHost has been deleted.
124 if (render_view_host_ == render_view_host) {
125 render_view_host_ = NULL;
126 callback_.Reset();
127 }
128 }
129
116 void JavaScriptAppModalDialog::OnCancel(bool suppress_js_messages) { 130 void JavaScriptAppModalDialog::OnCancel(bool suppress_js_messages) {
117 // If we are shutting down and this is an onbeforeunload dialog, cancel the 131 // If we are shutting down and this is an onbeforeunload dialog, cancel the
118 // shutdown. 132 // shutdown.
119 // TODO(sammc): Remove this when kEnableBatchedShutdown becomes mandatory. 133 // TODO(sammc): Remove this when kEnableBatchedShutdown becomes mandatory.
120 if (is_before_unload_dialog_ && 134 if (is_before_unload_dialog_ &&
121 !CommandLine::ForCurrentProcess()->HasSwitch( 135 !CommandLine::ForCurrentProcess()->HasSwitch(
122 switches::kEnableBatchedShutdown)) { 136 switches::kEnableBatchedShutdown)) {
123 browser_shutdown::SetTryingToQuit(false); 137 browser_shutdown::SetTryingToQuit(false);
124 } 138 }
125 139
(...skipping 28 matching lines...) Expand all
154 override_prompt_text_ = override_prompt_text; 168 override_prompt_text_ = override_prompt_text;
155 use_override_prompt_text_ = true; 169 use_override_prompt_text_ = true;
156 } 170 }
157 171
158 void JavaScriptAppModalDialog::NotifyDelegate(bool success, 172 void JavaScriptAppModalDialog::NotifyDelegate(bool success,
159 const string16& user_input, 173 const string16& user_input,
160 bool suppress_js_messages) { 174 bool suppress_js_messages) {
161 if (!IsValid()) 175 if (!IsValid())
162 return; 176 return;
163 177
164 callback_.Run(success, user_input); 178 if (!callback_.is_null()) {
179 callback_.Run(success, user_input);
180 callback_.Reset();
181 }
165 182
166 // The callback_ above may delete web_contents_, thus removing the extra 183 // The callback_ above may delete web_contents_, thus removing the extra
167 // data from the map owned by ChromeJavaScriptDialogManager. Make sure 184 // data from the map owned by ChromeJavaScriptDialogManager. Make sure
168 // to only use the data if still present. http://crbug.com/236476 185 // to only use the data if still present. http://crbug.com/236476
169 ExtraDataMap::iterator extra_data = extra_data_map_->find(web_contents()); 186 ExtraDataMap::iterator extra_data = extra_data_map_->find(
187 AppModalDialog::web_contents());
170 if (extra_data != extra_data_map_->end()) { 188 if (extra_data != extra_data_map_->end()) {
171 extra_data->second.last_javascript_message_dismissal_ = 189 extra_data->second.last_javascript_message_dismissal_ =
172 base::TimeTicks::Now(); 190 base::TimeTicks::Now();
173 extra_data->second.suppress_javascript_messages_ = suppress_js_messages; 191 extra_data->second.suppress_javascript_messages_ = suppress_js_messages;
174 } 192 }
175 193
176 // On Views, we can end up coming through this code path twice :(. 194 // On Views, we can end up coming through this code path twice :(.
177 // See crbug.com/63732. 195 // See crbug.com/63732.
178 AppModalDialog::Invalidate(); 196 AppModalDialog::Invalidate();
179 } 197 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h ('k') | chrome/browser/ui/browser_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698