| 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) {} | 19 : should_proceed_on_beforeunload_(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 JavaScriptMessageType javascript_message_type, | 27 JavaScriptDialogType dialog_type, |
| 28 const base::string16& message_text, | 28 const base::string16& message_text, |
| 29 const base::string16& default_prompt_text, | 29 const base::string16& default_prompt_text, |
| 30 const DialogClosedCallback& callback, | 30 const DialogClosedCallback& callback, |
| 31 bool* did_suppress_message) { | 31 bool* did_suppress_message) { |
| 32 if (!dialog_request_callback_.is_null()) { | 32 if (!dialog_request_callback_.is_null()) { |
| 33 dialog_request_callback_.Run(); | 33 dialog_request_callback_.Run(); |
| 34 callback.Run(true, base::string16()); | 34 callback.Run(true, base::string16()); |
| 35 dialog_request_callback_.Reset(); | 35 dialog_request_callback_.Reset(); |
| 36 return; | 36 return; |
| 37 } | 37 } |
| 38 | 38 |
| 39 #if defined(OS_MACOSX) || defined(OS_WIN) | 39 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 40 *did_suppress_message = false; | 40 *did_suppress_message = false; |
| 41 | 41 |
| 42 if (dialog_) { | 42 if (dialog_) { |
| 43 // One dialog at a time, please. | 43 // One dialog at a time, please. |
| 44 *did_suppress_message = true; | 44 *did_suppress_message = true; |
| 45 return; | 45 return; |
| 46 } | 46 } |
| 47 | 47 |
| 48 base::string16 new_message_text = | 48 base::string16 new_message_text = |
| 49 url_formatter::FormatUrl(origin_url) + | 49 url_formatter::FormatUrl(origin_url) + |
| 50 base::ASCIIToUTF16("\n\n") + message_text; | 50 base::ASCIIToUTF16("\n\n") + message_text; |
| 51 gfx::NativeWindow parent_window = web_contents->GetTopLevelNativeWindow(); | 51 gfx::NativeWindow parent_window = web_contents->GetTopLevelNativeWindow(); |
| 52 | 52 |
| 53 dialog_.reset(new ShellJavaScriptDialog(this, | 53 dialog_.reset(new ShellJavaScriptDialog(this, parent_window, dialog_type, |
| 54 parent_window, | 54 new_message_text, default_prompt_text, |
| 55 javascript_message_type, | |
| 56 new_message_text, | |
| 57 default_prompt_text, | |
| 58 callback)); | 55 callback)); |
| 59 #else | 56 #else |
| 60 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 57 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 61 *did_suppress_message = true; | 58 *did_suppress_message = true; |
| 62 return; | 59 return; |
| 63 #endif | 60 #endif |
| 64 } | 61 } |
| 65 | 62 |
| 66 void ShellJavaScriptDialogManager::RunBeforeUnloadDialog( | 63 void ShellJavaScriptDialogManager::RunBeforeUnloadDialog( |
| 67 WebContents* web_contents, | 64 WebContents* web_contents, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 84 // Seriously!? | 81 // Seriously!? |
| 85 callback.Run(true, base::string16()); | 82 callback.Run(true, base::string16()); |
| 86 return; | 83 return; |
| 87 } | 84 } |
| 88 | 85 |
| 89 base::string16 message_text = | 86 base::string16 message_text = |
| 90 base::ASCIIToUTF16("Is it OK to leave/reload this page?"); | 87 base::ASCIIToUTF16("Is it OK to leave/reload this page?"); |
| 91 | 88 |
| 92 gfx::NativeWindow parent_window = web_contents->GetTopLevelNativeWindow(); | 89 gfx::NativeWindow parent_window = web_contents->GetTopLevelNativeWindow(); |
| 93 | 90 |
| 94 dialog_.reset(new ShellJavaScriptDialog(this, | 91 dialog_.reset(new ShellJavaScriptDialog( |
| 95 parent_window, | 92 this, parent_window, JAVASCRIPT_DIALOG_TYPE_CONFIRM, message_text, |
| 96 JAVASCRIPT_MESSAGE_TYPE_CONFIRM, | 93 base::string16(), // default |
| 97 message_text, | 94 callback)); |
| 98 base::string16(), // default | |
| 99 callback)); | |
| 100 #else | 95 #else |
| 101 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 96 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 102 callback.Run(true, base::string16()); | 97 callback.Run(true, base::string16()); |
| 103 return; | 98 return; |
| 104 #endif | 99 #endif |
| 105 } | 100 } |
| 106 | 101 |
| 107 void ShellJavaScriptDialogManager::CancelDialogs(WebContents* web_contents, | 102 void ShellJavaScriptDialogManager::CancelDialogs(WebContents* web_contents, |
| 108 bool reset_state) { | 103 bool reset_state) { |
| 109 #if defined(OS_MACOSX) || defined(OS_WIN) | 104 #if defined(OS_MACOSX) || defined(OS_WIN) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 127 void ShellJavaScriptDialogManager::DialogClosed(ShellJavaScriptDialog* dialog) { | 122 void ShellJavaScriptDialogManager::DialogClosed(ShellJavaScriptDialog* dialog) { |
| 128 #if defined(OS_MACOSX) || defined(OS_WIN) | 123 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 129 DCHECK_EQ(dialog, dialog_.get()); | 124 DCHECK_EQ(dialog, dialog_.get()); |
| 130 dialog_.reset(); | 125 dialog_.reset(); |
| 131 #else | 126 #else |
| 132 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 127 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 133 #endif | 128 #endif |
| 134 } | 129 } |
| 135 | 130 |
| 136 } // namespace content | 131 } // namespace content |
| OLD | NEW |