| OLD | NEW |
| 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 "content/shell/shell_javascript_dialog_manager.h" | 5 #include "content/shell/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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 if (!dialog_request_callback_.is_null()) { | 39 if (!dialog_request_callback_.is_null()) { |
| 40 dialog_request_callback_.Run(); | 40 dialog_request_callback_.Run(); |
| 41 callback.Run(true, string16()); | 41 callback.Run(true, string16()); |
| 42 dialog_request_callback_.Reset(); | 42 dialog_request_callback_.Reset(); |
| 43 return; | 43 return; |
| 44 } | 44 } |
| 45 | 45 |
| 46 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(TOOLKIT_GTK) | 46 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(TOOLKIT_GTK) |
| 47 *did_suppress_message = false; | 47 *did_suppress_message = false; |
| 48 | 48 |
| 49 if (dialog_.get()) { | 49 if (dialog_) { |
| 50 // One dialog at a time, please. | 50 // One dialog at a time, please. |
| 51 *did_suppress_message = true; | 51 *did_suppress_message = true; |
| 52 return; | 52 return; |
| 53 } | 53 } |
| 54 | 54 |
| 55 string16 new_message_text = net::FormatUrl(origin_url, accept_lang) + | 55 string16 new_message_text = net::FormatUrl(origin_url, accept_lang) + |
| 56 ASCIIToUTF16("\n\n") + | 56 ASCIIToUTF16("\n\n") + |
| 57 message_text; | 57 message_text; |
| 58 gfx::NativeWindow parent_window = | 58 gfx::NativeWindow parent_window = |
| 59 web_contents->GetView()->GetTopLevelNativeWindow(); | 59 web_contents->GetView()->GetTopLevelNativeWindow(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 82 } | 82 } |
| 83 | 83 |
| 84 if (!dialog_request_callback_.is_null()) { | 84 if (!dialog_request_callback_.is_null()) { |
| 85 dialog_request_callback_.Run(); | 85 dialog_request_callback_.Run(); |
| 86 callback.Run(true, string16()); | 86 callback.Run(true, string16()); |
| 87 dialog_request_callback_.Reset(); | 87 dialog_request_callback_.Reset(); |
| 88 return; | 88 return; |
| 89 } | 89 } |
| 90 | 90 |
| 91 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(TOOLKIT_GTK) | 91 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(TOOLKIT_GTK) |
| 92 if (dialog_.get()) { | 92 if (dialog_) { |
| 93 // Seriously!? | 93 // Seriously!? |
| 94 callback.Run(true, string16()); | 94 callback.Run(true, string16()); |
| 95 return; | 95 return; |
| 96 } | 96 } |
| 97 | 97 |
| 98 string16 new_message_text = | 98 string16 new_message_text = |
| 99 message_text + | 99 message_text + |
| 100 ASCIIToUTF16("\n\nIs it OK to leave/reload this page?"); | 100 ASCIIToUTF16("\n\nIs it OK to leave/reload this page?"); |
| 101 | 101 |
| 102 gfx::NativeWindow parent_window = | 102 gfx::NativeWindow parent_window = |
| 103 web_contents->GetView()->GetTopLevelNativeWindow(); | 103 web_contents->GetView()->GetTopLevelNativeWindow(); |
| 104 | 104 |
| 105 dialog_.reset(new ShellJavaScriptDialog(this, | 105 dialog_.reset(new ShellJavaScriptDialog(this, |
| 106 parent_window, | 106 parent_window, |
| 107 JAVASCRIPT_MESSAGE_TYPE_CONFIRM, | 107 JAVASCRIPT_MESSAGE_TYPE_CONFIRM, |
| 108 new_message_text, | 108 new_message_text, |
| 109 string16(), // default_prompt_text | 109 string16(), // default_prompt_text |
| 110 callback)); | 110 callback)); |
| 111 #else | 111 #else |
| 112 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 112 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 113 callback.Run(true, string16()); | 113 callback.Run(true, string16()); |
| 114 return; | 114 return; |
| 115 #endif | 115 #endif |
| 116 } | 116 } |
| 117 | 117 |
| 118 void ShellJavaScriptDialogManager::ResetJavaScriptState( | 118 void ShellJavaScriptDialogManager::ResetJavaScriptState( |
| 119 WebContents* web_contents) { | 119 WebContents* web_contents) { |
| 120 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(TOOLKIT_GTK) | 120 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(TOOLKIT_GTK) |
| 121 if (dialog_.get()) { | 121 if (dialog_) { |
| 122 dialog_->Cancel(); | 122 dialog_->Cancel(); |
| 123 dialog_.reset(); | 123 dialog_.reset(); |
| 124 } | 124 } |
| 125 #else | 125 #else |
| 126 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 126 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 127 #endif | 127 #endif |
| 128 } | 128 } |
| 129 | 129 |
| 130 void ShellJavaScriptDialogManager::DialogClosed(ShellJavaScriptDialog* dialog) { | 130 void ShellJavaScriptDialogManager::DialogClosed(ShellJavaScriptDialog* dialog) { |
| 131 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(TOOLKIT_GTK) | 131 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(TOOLKIT_GTK) |
| 132 DCHECK_EQ(dialog, dialog_.get()); | 132 DCHECK_EQ(dialog, dialog_.get()); |
| 133 dialog_.reset(); | 133 dialog_.reset(); |
| 134 #else | 134 #else |
| 135 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 135 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 136 #endif | 136 #endif |
| 137 } | 137 } |
| 138 | 138 |
| 139 } // namespace content | 139 } // namespace content |
| OLD | NEW |