OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/shell/shell_js_dialog_creator.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "content/shell/shell_js_dialog.h" |
| 10 #include "net/base/net_util.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 ShellJavaScriptDialogCreator::ShellJavaScriptDialogCreator() { |
| 15 } |
| 16 |
| 17 ShellJavaScriptDialogCreator::~ShellJavaScriptDialogCreator() { |
| 18 } |
| 19 |
| 20 void ShellJavaScriptDialogCreator::RunJavaScriptDialog( |
| 21 WebContents* web_contents, |
| 22 const GURL& origin_url, |
| 23 const std::string& accept_lang, |
| 24 ui::JavascriptMessageType javascript_message_type, |
| 25 const string16& message_text, |
| 26 const string16& default_prompt_text, |
| 27 const DialogClosedCallback& callback, |
| 28 bool* did_suppress_message) { |
| 29 #if defined(OS_MACOSX) |
| 30 *did_suppress_message = false; |
| 31 |
| 32 if (dialog_.get()) { |
| 33 // One dialog at a time, please. |
| 34 *did_suppress_message = true; |
| 35 return; |
| 36 } |
| 37 |
| 38 string16 new_message_text = net::FormatUrl(origin_url, accept_lang) + |
| 39 ASCIIToUTF16("\n\n") + |
| 40 message_text; |
| 41 |
| 42 dialog_.reset(new ShellJavaScriptDialog(this, |
| 43 javascript_message_type, |
| 44 new_message_text, |
| 45 default_prompt_text, |
| 46 callback)); |
| 47 #else |
| 48 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 49 *did_suppress_message = true; |
| 50 return; |
| 51 #endif |
| 52 } |
| 53 |
| 54 void ShellJavaScriptDialogCreator::RunBeforeUnloadDialog( |
| 55 WebContents* web_contents, |
| 56 const string16& message_text, |
| 57 bool is_reload, |
| 58 const DialogClosedCallback& callback) { |
| 59 #if defined(OS_MACOSX) |
| 60 if (dialog_.get()) { |
| 61 // Seriously!? |
| 62 callback.Run(true, string16()); |
| 63 return; |
| 64 } |
| 65 |
| 66 string16 new_message_text = |
| 67 message_text + |
| 68 ASCIIToUTF16("\n\nIs it OK to leave/reload this page?"); |
| 69 |
| 70 dialog_.reset(new ShellJavaScriptDialog(this, |
| 71 ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM, |
| 72 new_message_text, |
| 73 string16(), // default_prompt_text |
| 74 callback)); |
| 75 #else |
| 76 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
| 77 callback.Run(true, string16()); |
| 78 return; |
| 79 #endif |
| 80 } |
| 81 |
| 82 void ShellJavaScriptDialogCreator::ResetJavaScriptState( |
| 83 WebContents* web_contents) { |
| 84 if (dialog_.get()) { |
| 85 dialog_->Cancel(); |
| 86 dialog_.reset(); |
| 87 } |
| 88 } |
| 89 |
| 90 void ShellJavaScriptDialogCreator::DialogClosed(ShellJavaScriptDialog* dialog) { |
| 91 DCHECK_EQ(dialog, dialog_.get()); |
| 92 dialog_.reset(); |
| 93 } |
| 94 |
| 95 } // namespace content |
OLD | NEW |