| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/shell/browser/shell_javascript_dialog_manager.h" | 5 #include "content/shell/browser/shell_javascript_dialog_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "components/url_formatter/url_formatter.h" | 11 #include "components/url_formatter/url_formatter.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/shell/browser/shell_javascript_dialog.h" | 13 #include "content/shell/browser/shell_javascript_dialog.h" |
| 14 #include "content/shell/common/shell_switches.h" | 14 #include "content/shell/common/shell_switches.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 ShellJavaScriptDialogManager::ShellJavaScriptDialogManager() | 18 ShellJavaScriptDialogManager::ShellJavaScriptDialogManager() {} |
| 19 : should_proceed_on_beforeunload_(true) {} | |
| 20 | 19 |
| 21 ShellJavaScriptDialogManager::~ShellJavaScriptDialogManager() { | 20 ShellJavaScriptDialogManager::~ShellJavaScriptDialogManager() {} |
| 22 } | |
| 23 | 21 |
| 24 void ShellJavaScriptDialogManager::RunJavaScriptDialog( | 22 void ShellJavaScriptDialogManager::RunJavaScriptDialog( |
| 25 WebContents* web_contents, | 23 WebContents* web_contents, |
| 26 const GURL& origin_url, | 24 const GURL& origin_url, |
| 27 JavaScriptDialogType dialog_type, | 25 JavaScriptDialogType dialog_type, |
| 28 const base::string16& message_text, | 26 const base::string16& message_text, |
| 29 const base::string16& default_prompt_text, | 27 const base::string16& default_prompt_text, |
| 30 const DialogClosedCallback& callback, | 28 const DialogClosedCallback& callback, |
| 31 bool* did_suppress_message) { | 29 bool* did_suppress_message) { |
| 32 if (!dialog_request_callback_.is_null()) { | 30 if (!dialog_request_callback_.is_null()) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 57 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 55 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 58 *did_suppress_message = true; | 56 *did_suppress_message = true; |
| 59 return; | 57 return; |
| 60 #endif | 58 #endif |
| 61 } | 59 } |
| 62 | 60 |
| 63 void ShellJavaScriptDialogManager::RunBeforeUnloadDialog( | 61 void ShellJavaScriptDialogManager::RunBeforeUnloadDialog( |
| 64 WebContents* web_contents, | 62 WebContents* web_contents, |
| 65 bool is_reload, | 63 bool is_reload, |
| 66 const DialogClosedCallback& callback) { | 64 const DialogClosedCallback& callback) { |
| 67 // During tests, if the BeforeUnload should not proceed automatically, store | |
| 68 // the callback and return. | |
| 69 if (!dialog_request_callback_.is_null()) { | 65 if (!dialog_request_callback_.is_null()) { |
| 70 dialog_request_callback_.Run(); | 66 dialog_request_callback_.Run(); |
| 71 if (should_proceed_on_beforeunload_) | 67 callback.Run(true, base::string16()); |
| 72 callback.Run(true, base::string16()); | |
| 73 else | |
| 74 before_unload_callback_ = callback; | |
| 75 dialog_request_callback_.Reset(); | 68 dialog_request_callback_.Reset(); |
| 76 return; | 69 return; |
| 77 } | 70 } |
| 78 | 71 |
| 79 #if defined(OS_MACOSX) || defined(OS_WIN) | 72 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 80 if (dialog_) { | 73 if (dialog_) { |
| 81 // Seriously!? | 74 // Seriously!? |
| 82 callback.Run(true, base::string16()); | 75 callback.Run(true, base::string16()); |
| 83 return; | 76 return; |
| 84 } | 77 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 102 void ShellJavaScriptDialogManager::CancelDialogs(WebContents* web_contents, | 95 void ShellJavaScriptDialogManager::CancelDialogs(WebContents* web_contents, |
| 103 bool reset_state) { | 96 bool reset_state) { |
| 104 #if defined(OS_MACOSX) || defined(OS_WIN) | 97 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 105 if (dialog_) { | 98 if (dialog_) { |
| 106 dialog_->Cancel(); | 99 dialog_->Cancel(); |
| 107 dialog_.reset(); | 100 dialog_.reset(); |
| 108 } | 101 } |
| 109 #else | 102 #else |
| 110 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 103 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 111 #endif | 104 #endif |
| 112 | |
| 113 if (before_unload_callback_.is_null()) | |
| 114 return; | |
| 115 | |
| 116 if (reset_state) { | |
| 117 before_unload_callback_.Run(false, base::string16()); | |
| 118 before_unload_callback_.Reset(); | |
| 119 } | |
| 120 } | 105 } |
| 121 | 106 |
| 122 void ShellJavaScriptDialogManager::DialogClosed(ShellJavaScriptDialog* dialog) { | 107 void ShellJavaScriptDialogManager::DialogClosed(ShellJavaScriptDialog* dialog) { |
| 123 #if defined(OS_MACOSX) || defined(OS_WIN) | 108 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 124 DCHECK_EQ(dialog, dialog_.get()); | 109 DCHECK_EQ(dialog, dialog_.get()); |
| 125 dialog_.reset(); | 110 dialog_.reset(); |
| 126 #else | 111 #else |
| 127 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 112 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 128 #endif | 113 #endif |
| 129 } | 114 } |
| 130 | 115 |
| 131 } // namespace content | 116 } // namespace content |
| OLD | NEW |