| 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_creator.h" | 5 #include "content/shell/shell_javascript_dialog_creator.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" |
| 11 #include "content/public/browser/web_contents_view.h" |
| 11 #include "content/shell/layout_test_controller_host.h" | 12 #include "content/shell/layout_test_controller_host.h" |
| 12 #include "content/shell/shell_javascript_dialog.h" | 13 #include "content/shell/shell_javascript_dialog.h" |
| 13 #include "content/shell/shell_switches.h" | 14 #include "content/shell/shell_switches.h" |
| 14 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 ShellJavaScriptDialogCreator::ShellJavaScriptDialogCreator() { | 19 ShellJavaScriptDialogCreator::ShellJavaScriptDialogCreator() { |
| 19 } | 20 } |
| 20 | 21 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 44 return; | 45 return; |
| 45 } | 46 } |
| 46 | 47 |
| 47 if (!dialog_request_callback_.is_null()) { | 48 if (!dialog_request_callback_.is_null()) { |
| 48 dialog_request_callback_.Run(); | 49 dialog_request_callback_.Run(); |
| 49 callback.Run(true, string16()); | 50 callback.Run(true, string16()); |
| 50 dialog_request_callback_.Reset(); | 51 dialog_request_callback_.Reset(); |
| 51 return; | 52 return; |
| 52 } | 53 } |
| 53 | 54 |
| 54 #if defined(OS_MACOSX) || defined(OS_WIN) | 55 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) |
| 55 *did_suppress_message = false; | 56 *did_suppress_message = false; |
| 56 | 57 |
| 57 if (dialog_.get()) { | 58 if (dialog_.get()) { |
| 58 // One dialog at a time, please. | 59 // One dialog at a time, please. |
| 59 *did_suppress_message = true; | 60 *did_suppress_message = true; |
| 60 return; | 61 return; |
| 61 } | 62 } |
| 62 | 63 |
| 63 string16 new_message_text = net::FormatUrl(origin_url, accept_lang) + | 64 string16 new_message_text = net::FormatUrl(origin_url, accept_lang) + |
| 64 ASCIIToUTF16("\n\n") + | 65 ASCIIToUTF16("\n\n") + |
| 65 message_text; | 66 message_text; |
| 67 gfx::NativeWindow parent_window = |
| 68 web_contents->GetView()->GetTopLevelNativeWindow(); |
| 66 | 69 |
| 67 dialog_.reset(new ShellJavaScriptDialog(this, | 70 dialog_.reset(new ShellJavaScriptDialog(this, |
| 71 parent_window, |
| 68 javascript_message_type, | 72 javascript_message_type, |
| 69 new_message_text, | 73 new_message_text, |
| 70 default_prompt_text, | 74 default_prompt_text, |
| 71 callback)); | 75 callback)); |
| 72 #else | 76 #else |
| 73 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 77 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 74 *did_suppress_message = true; | 78 *did_suppress_message = true; |
| 75 return; | 79 return; |
| 76 #endif | 80 #endif |
| 77 } | 81 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 92 return; | 96 return; |
| 93 } | 97 } |
| 94 | 98 |
| 95 if (!dialog_request_callback_.is_null()) { | 99 if (!dialog_request_callback_.is_null()) { |
| 96 dialog_request_callback_.Run(); | 100 dialog_request_callback_.Run(); |
| 97 callback.Run(true, string16()); | 101 callback.Run(true, string16()); |
| 98 dialog_request_callback_.Reset(); | 102 dialog_request_callback_.Reset(); |
| 99 return; | 103 return; |
| 100 } | 104 } |
| 101 | 105 |
| 102 #if defined(OS_MACOSX) || defined(OS_WIN) | 106 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) |
| 103 if (dialog_.get()) { | 107 if (dialog_.get()) { |
| 104 // Seriously!? | 108 // Seriously!? |
| 105 callback.Run(true, string16()); | 109 callback.Run(true, string16()); |
| 106 return; | 110 return; |
| 107 } | 111 } |
| 108 | 112 |
| 109 string16 new_message_text = | 113 string16 new_message_text = |
| 110 message_text + | 114 message_text + |
| 111 ASCIIToUTF16("\n\nIs it OK to leave/reload this page?"); | 115 ASCIIToUTF16("\n\nIs it OK to leave/reload this page?"); |
| 112 | 116 |
| 117 gfx::NativeWindow parent_window = |
| 118 web_contents->GetView()->GetTopLevelNativeWindow(); |
| 119 |
| 113 dialog_.reset(new ShellJavaScriptDialog(this, | 120 dialog_.reset(new ShellJavaScriptDialog(this, |
| 121 parent_window, |
| 114 JAVASCRIPT_MESSAGE_TYPE_CONFIRM, | 122 JAVASCRIPT_MESSAGE_TYPE_CONFIRM, |
| 115 new_message_text, | 123 new_message_text, |
| 116 string16(), // default_prompt_text | 124 string16(), // default_prompt_text |
| 117 callback)); | 125 callback)); |
| 118 #else | 126 #else |
| 119 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 127 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 120 callback.Run(true, string16()); | 128 callback.Run(true, string16()); |
| 121 return; | 129 return; |
| 122 #endif | 130 #endif |
| 123 } | 131 } |
| 124 | 132 |
| 125 void ShellJavaScriptDialogCreator::ResetJavaScriptState( | 133 void ShellJavaScriptDialogCreator::ResetJavaScriptState( |
| 126 WebContents* web_contents) { | 134 WebContents* web_contents) { |
| 127 #if defined(OS_MACOSX) || defined(OS_WIN) | 135 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) |
| 128 if (dialog_.get()) { | 136 if (dialog_.get()) { |
| 129 dialog_->Cancel(); | 137 dialog_->Cancel(); |
| 130 dialog_.reset(); | 138 dialog_.reset(); |
| 131 } | 139 } |
| 132 #else | 140 #else |
| 133 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 141 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 134 #endif | 142 #endif |
| 135 } | 143 } |
| 136 | 144 |
| 137 void ShellJavaScriptDialogCreator::DialogClosed(ShellJavaScriptDialog* dialog) { | 145 void ShellJavaScriptDialogCreator::DialogClosed(ShellJavaScriptDialog* dialog) { |
| 138 #if defined(OS_MACOSX) || defined(OS_WIN) | 146 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) |
| 139 DCHECK_EQ(dialog, dialog_.get()); | 147 DCHECK_EQ(dialog, dialog_.get()); |
| 140 dialog_.reset(); | 148 dialog_.reset(); |
| 141 #else | 149 #else |
| 142 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 150 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 143 #endif | 151 #endif |
| 144 } | 152 } |
| 145 | 153 |
| 146 } // namespace content | 154 } // namespace content |
| OLD | NEW |