| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/app_modal/javascript_dialog_manager.h" | 5 #include "components/app_modal/javascript_dialog_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 if (accept) { | 234 if (accept) { |
| 235 if (prompt_override) | 235 if (prompt_override) |
| 236 dialog->SetOverridePromptText(*prompt_override); | 236 dialog->SetOverridePromptText(*prompt_override); |
| 237 dialog->native_dialog()->AcceptAppModalDialog(); | 237 dialog->native_dialog()->AcceptAppModalDialog(); |
| 238 } else { | 238 } else { |
| 239 dialog->native_dialog()->CancelAppModalDialog(); | 239 dialog->native_dialog()->CancelAppModalDialog(); |
| 240 } | 240 } |
| 241 return true; | 241 return true; |
| 242 } | 242 } |
| 243 | 243 |
| 244 void JavaScriptDialogManager::ResetDialogState( | |
| 245 content::WebContents* web_contents) { | |
| 246 CancelActiveAndPendingDialogs(web_contents); | |
| 247 javascript_dialog_extra_data_.erase(web_contents); | |
| 248 } | |
| 249 | |
| 250 base::string16 JavaScriptDialogManager::GetTitle( | 244 base::string16 JavaScriptDialogManager::GetTitle( |
| 251 content::WebContents* web_contents, | 245 content::WebContents* web_contents, |
| 252 const GURL& origin_url, | 246 const GURL& origin_url, |
| 253 bool is_alert) { | 247 bool is_alert) { |
| 254 // For extensions, show the extension name, but only if the origin of | 248 // For extensions, show the extension name, but only if the origin of |
| 255 // the alert matches the top-level WebContents. | 249 // the alert matches the top-level WebContents. |
| 256 std::string name; | 250 std::string name; |
| 257 if (extensions_client_->GetExtensionName(web_contents, origin_url, &name)) | 251 if (extensions_client_->GetExtensionName(web_contents, origin_url, &name)) |
| 258 return base::UTF8ToUTF16(name); | 252 return base::UTF8ToUTF16(name); |
| 259 | 253 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 274 is_same_origin_as_main_frame ? IDS_JAVASCRIPT_MESSAGEBOX_TITLE | 268 is_same_origin_as_main_frame ? IDS_JAVASCRIPT_MESSAGEBOX_TITLE |
| 275 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE_IFRAME, | 269 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE_IFRAME, |
| 276 base::i18n::GetDisplayStringInLTRDirectionality(url_string)); | 270 base::i18n::GetDisplayStringInLTRDirectionality(url_string)); |
| 277 } | 271 } |
| 278 return l10n_util::GetStringUTF16( | 272 return l10n_util::GetStringUTF16( |
| 279 is_same_origin_as_main_frame | 273 is_same_origin_as_main_frame |
| 280 ? IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL | 274 ? IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL |
| 281 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL_IFRAME); | 275 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL_IFRAME); |
| 282 } | 276 } |
| 283 | 277 |
| 284 void JavaScriptDialogManager::CancelActiveAndPendingDialogs( | 278 void JavaScriptDialogManager::CancelDialogs(content::WebContents* web_contents, |
| 285 content::WebContents* web_contents) { | 279 bool suppress_callbacks, |
| 280 bool reset_state) { |
| 286 AppModalDialogQueue* queue = AppModalDialogQueue::GetInstance(); | 281 AppModalDialogQueue* queue = AppModalDialogQueue::GetInstance(); |
| 287 AppModalDialog* active_dialog = queue->active_dialog(); | 282 AppModalDialog* active_dialog = queue->active_dialog(); |
| 288 for (AppModalDialogQueue::iterator i = queue->begin(); | 283 for (AppModalDialogQueue::iterator i = queue->begin(); |
| 289 i != queue->end(); ++i) { | 284 i != queue->end(); ++i) { |
| 290 // Invalidating the active dialog might trigger showing a not-yet | 285 // Invalidating the active dialog might trigger showing a not-yet |
| 291 // invalidated dialog, so invalidate the active dialog last. | 286 // invalidated dialog, so invalidate the active dialog last. |
| 292 if ((*i) == active_dialog) | 287 if ((*i) == active_dialog) |
| 293 continue; | 288 continue; |
| 294 if ((*i)->web_contents() == web_contents) | 289 if ((*i)->web_contents() == web_contents) |
| 295 (*i)->Invalidate(); | 290 (*i)->Invalidate(suppress_callbacks); |
| 296 } | 291 } |
| 297 if (active_dialog && active_dialog->web_contents() == web_contents) | 292 if (active_dialog && active_dialog->web_contents() == web_contents) |
| 298 active_dialog->Invalidate(); | 293 active_dialog->Invalidate(suppress_callbacks); |
| 294 |
| 295 if (reset_state) |
| 296 javascript_dialog_extra_data_.erase(web_contents); |
| 299 } | 297 } |
| 300 | 298 |
| 301 void JavaScriptDialogManager::OnBeforeUnloadDialogClosed( | 299 void JavaScriptDialogManager::OnBeforeUnloadDialogClosed( |
| 302 content::WebContents* web_contents, | 300 content::WebContents* web_contents, |
| 303 DialogClosedCallback callback, | 301 DialogClosedCallback callback, |
| 304 bool success, | 302 bool success, |
| 305 const base::string16& user_input) { | 303 const base::string16& user_input) { |
| 306 enum class StayVsLeave { | 304 enum class StayVsLeave { |
| 307 STAY = 0, | 305 STAY = 0, |
| 308 LEAVE = 1, | 306 LEAVE = 1, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 325 // lazy background page after the dialog closes. (Dialogs are closed before | 323 // lazy background page after the dialog closes. (Dialogs are closed before |
| 326 // their WebContents is destroyed so |web_contents| is still valid here.) | 324 // their WebContents is destroyed so |web_contents| is still valid here.) |
| 327 extensions_client_->OnDialogClosed(web_contents); | 325 extensions_client_->OnDialogClosed(web_contents); |
| 328 | 326 |
| 329 last_close_time_ = base::TimeTicks::Now(); | 327 last_close_time_ = base::TimeTicks::Now(); |
| 330 | 328 |
| 331 callback.Run(success, user_input); | 329 callback.Run(success, user_input); |
| 332 } | 330 } |
| 333 | 331 |
| 334 } // namespace app_modal | 332 } // namespace app_modal |
| OLD | NEW |