| 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 const std::string& accept_lang, | |
| 28 JavaScriptMessageType javascript_message_type, | 27 JavaScriptMessageType javascript_message_type, |
| 29 const base::string16& message_text, | 28 const base::string16& message_text, |
| 30 const base::string16& default_prompt_text, | 29 const base::string16& default_prompt_text, |
| 31 const DialogClosedCallback& callback, | 30 const DialogClosedCallback& callback, |
| 32 bool* did_suppress_message) { | 31 bool* did_suppress_message) { |
| 33 if (!dialog_request_callback_.is_null()) { | 32 if (!dialog_request_callback_.is_null()) { |
| 34 dialog_request_callback_.Run(); | 33 dialog_request_callback_.Run(); |
| 35 callback.Run(true, base::string16()); | 34 callback.Run(true, base::string16()); |
| 36 dialog_request_callback_.Reset(); | 35 dialog_request_callback_.Reset(); |
| 37 return; | 36 return; |
| 38 } | 37 } |
| 39 | 38 |
| 40 #if defined(OS_MACOSX) || defined(OS_WIN) | 39 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 41 *did_suppress_message = false; | 40 *did_suppress_message = false; |
| 42 | 41 |
| 43 if (dialog_) { | 42 if (dialog_) { |
| 44 // One dialog at a time, please. | 43 // One dialog at a time, please. |
| 45 *did_suppress_message = true; | 44 *did_suppress_message = true; |
| 46 return; | 45 return; |
| 47 } | 46 } |
| 48 | 47 |
| 49 base::string16 new_message_text = | 48 base::string16 new_message_text = |
| 50 url_formatter::FormatUrl(origin_url, accept_lang) + | 49 url_formatter::FormatUrl(origin_url) + |
| 51 base::ASCIIToUTF16("\n\n") + message_text; | 50 base::ASCIIToUTF16("\n\n") + message_text; |
| 52 gfx::NativeWindow parent_window = web_contents->GetTopLevelNativeWindow(); | 51 gfx::NativeWindow parent_window = web_contents->GetTopLevelNativeWindow(); |
| 53 | 52 |
| 54 dialog_.reset(new ShellJavaScriptDialog(this, | 53 dialog_.reset(new ShellJavaScriptDialog(this, |
| 55 parent_window, | 54 parent_window, |
| 56 javascript_message_type, | 55 javascript_message_type, |
| 57 new_message_text, | 56 new_message_text, |
| 58 default_prompt_text, | 57 default_prompt_text, |
| 59 callback)); | 58 callback)); |
| 60 #else | 59 #else |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 void ShellJavaScriptDialogManager::DialogClosed(ShellJavaScriptDialog* dialog) { | 126 void ShellJavaScriptDialogManager::DialogClosed(ShellJavaScriptDialog* dialog) { |
| 128 #if defined(OS_MACOSX) || defined(OS_WIN) | 127 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 129 DCHECK_EQ(dialog, dialog_.get()); | 128 DCHECK_EQ(dialog, dialog_.get()); |
| 130 dialog_.reset(); | 129 dialog_.reset(); |
| 131 #else | 130 #else |
| 132 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 131 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 133 #endif | 132 #endif |
| 134 } | 133 } |
| 135 | 134 |
| 136 } // namespace content | 135 } // namespace content |
| OLD | NEW |