| 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 } | 19 : proceed_beforeunload_default_(true) {} |
| 20 | 20 |
| 21 ShellJavaScriptDialogManager::~ShellJavaScriptDialogManager() { | 21 ShellJavaScriptDialogManager::~ShellJavaScriptDialogManager() { |
| 22 } | 22 } |
| 23 | 23 |
| 24 void ShellJavaScriptDialogManager::RunJavaScriptDialog( | 24 void ShellJavaScriptDialogManager::RunJavaScriptDialog( |
| 25 WebContents* web_contents, | 25 WebContents* web_contents, |
| 26 const GURL& origin_url, | 26 const GURL& origin_url, |
| 27 const std::string& accept_lang, | 27 const std::string& accept_lang, |
| 28 JavaScriptMessageType javascript_message_type, | 28 JavaScriptMessageType javascript_message_type, |
| 29 const base::string16& message_text, | 29 const base::string16& message_text, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 61 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 62 *did_suppress_message = true; | 62 *did_suppress_message = true; |
| 63 return; | 63 return; |
| 64 #endif | 64 #endif |
| 65 } | 65 } |
| 66 | 66 |
| 67 void ShellJavaScriptDialogManager::RunBeforeUnloadDialog( | 67 void ShellJavaScriptDialogManager::RunBeforeUnloadDialog( |
| 68 WebContents* web_contents, | 68 WebContents* web_contents, |
| 69 bool is_reload, | 69 bool is_reload, |
| 70 const DialogClosedCallback& callback) { | 70 const DialogClosedCallback& callback) { |
| 71 // During tests, if the BeforeUnload should not proceed automatically, store |
| 72 // the callback and return. |
| 71 if (!dialog_request_callback_.is_null()) { | 73 if (!dialog_request_callback_.is_null()) { |
| 72 dialog_request_callback_.Run(); | 74 dialog_request_callback_.Run(); |
| 73 callback.Run(true, base::string16()); | 75 if (proceed_beforeunload_default_) |
| 76 callback.Run(true, base::string16()); |
| 77 else |
| 78 before_unload_callback_ = callback; |
| 74 dialog_request_callback_.Reset(); | 79 dialog_request_callback_.Reset(); |
| 75 return; | 80 return; |
| 76 } | 81 } |
| 77 | 82 |
| 78 #if defined(OS_MACOSX) || defined(OS_WIN) | 83 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 79 if (dialog_) { | 84 if (dialog_) { |
| 80 // Seriously!? | 85 // Seriously!? |
| 81 callback.Run(true, base::string16()); | 86 callback.Run(true, base::string16()); |
| 82 return; | 87 return; |
| 83 } | 88 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 106 if (dialog_) { | 111 if (dialog_) { |
| 107 dialog_->Cancel(); | 112 dialog_->Cancel(); |
| 108 dialog_.reset(); | 113 dialog_.reset(); |
| 109 } | 114 } |
| 110 #else | 115 #else |
| 111 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 116 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 112 #endif | 117 #endif |
| 113 } | 118 } |
| 114 | 119 |
| 115 void ShellJavaScriptDialogManager::ResetDialogState(WebContents* web_contents) { | 120 void ShellJavaScriptDialogManager::ResetDialogState(WebContents* web_contents) { |
| 121 if (before_unload_callback_.is_null()) |
| 122 return; |
| 123 before_unload_callback_.Run(false, base::string16()); |
| 124 before_unload_callback_.Reset(); |
| 116 } | 125 } |
| 117 | 126 |
| 118 void ShellJavaScriptDialogManager::DialogClosed(ShellJavaScriptDialog* dialog) { | 127 void ShellJavaScriptDialogManager::DialogClosed(ShellJavaScriptDialog* dialog) { |
| 119 #if defined(OS_MACOSX) || defined(OS_WIN) | 128 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 120 DCHECK_EQ(dialog, dialog_.get()); | 129 DCHECK_EQ(dialog, dialog_.get()); |
| 121 dialog_.reset(); | 130 dialog_.reset(); |
| 122 #else | 131 #else |
| 123 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 132 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 124 #endif | 133 #endif |
| 125 } | 134 } |
| 126 | 135 |
| 127 } // namespace content | 136 } // namespace content |
| OLD | NEW |