| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/jsmessage_box_handler.h" | 5 #include "chrome/browser/message_box_handler.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/message_box_flags.h" | 8 #include "app/message_box_flags.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/app_modal_dialog_queue.h" | 10 #include "chrome/browser/app_modal_dialog_queue.h" |
| 11 #include "chrome/browser/browsing_data_local_storage_helper.h" |
| 12 #include "chrome/browser/cookie_modal_dialog.h" |
| 13 #include "chrome/browser/cookie_prompt_modal_dialog_delegate.h" |
| 11 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/js_modal_dialog.h" |
| 12 #include "chrome/browser/tab_contents/tab_contents.h" | 16 #include "chrome/browser/tab_contents/tab_contents.h" |
| 13 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 14 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 15 | 19 |
| 16 namespace { | 20 namespace { |
| 17 | 21 |
| 18 const size_t kMaxReasonableTextLength = 2048; | 22 const size_t kMaxReasonableTextLength = 2048; |
| 19 | 23 |
| 20 // In some platforms, the underlying processing of humongous strings takes too | 24 // In some platforms, the underlying processing of humongous strings takes too |
| 21 // long and thus make the UI thread unresponsive. | 25 // long and thus make the UI thread unresponsive. |
| 22 std::wstring MakeTextSafe(const std::wstring& text) { | 26 std::wstring MakeTextSafe(const std::wstring& text) { |
| 23 if (text.size() > kMaxReasonableTextLength) | 27 if (text.size() > kMaxReasonableTextLength) |
| 24 return text.substr(0, kMaxReasonableTextLength) + L"\x2026"; | 28 return text.substr(0, kMaxReasonableTextLength) + L"\x2026"; |
| 25 return text; | 29 return text; |
| 26 } | 30 } |
| 27 | 31 |
| 28 } // namespace | 32 } // namespace |
| 29 | 33 |
| 30 void RunJavascriptMessageBox(JavaScriptMessageBoxClient* client, | 34 void RunJavascriptMessageBox(JavaScriptMessageBoxClient* client, |
| 31 const GURL& frame_url, | 35 const GURL& frame_url, |
| 32 int dialog_flags, | 36 int dialog_flags, |
| 33 const std::wstring& message_text, | 37 const std::wstring& message_text, |
| 34 const std::wstring& default_prompt_text, | 38 const std::wstring& default_prompt_text, |
| 35 bool display_suppress_checkbox, | 39 bool display_suppress_checkbox, |
| 36 IPC::Message* reply_msg) { | 40 IPC::Message* reply_msg) { |
| 37 std::wstring title = client->GetMessageBoxTitle(frame_url, | 41 std::wstring title = client->GetMessageBoxTitle(frame_url, |
| 38 (dialog_flags == MessageBoxFlags::kIsJavascriptAlert)); | 42 (dialog_flags == MessageBoxFlags::kIsJavascriptAlert)); |
| 39 Singleton<AppModalDialogQueue>()->AddDialog( | 43 Singleton<AppModalDialogQueue>()->AddDialog( |
| 40 new AppModalDialog(client, title, | 44 new JavaScriptAppModalDialog(client, title, dialog_flags, |
| 41 dialog_flags, MakeTextSafe(message_text), | 45 MakeTextSafe(message_text), default_prompt_text, |
| 42 default_prompt_text, display_suppress_checkbox, | 46 display_suppress_checkbox, false, reply_msg)); |
| 43 false, reply_msg)); | |
| 44 } | 47 } |
| 45 | 48 |
| 46 void RunBeforeUnloadDialog(TabContents* tab_contents, | 49 void RunBeforeUnloadDialog(TabContents* tab_contents, |
| 47 const std::wstring& message_text, | 50 const std::wstring& message_text, |
| 48 IPC::Message* reply_msg) { | 51 IPC::Message* reply_msg) { |
| 49 std::wstring full_message = | 52 std::wstring full_message = |
| 50 message_text + L"\n\n" + | 53 message_text + L"\n\n" + |
| 51 l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER); | 54 l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER); |
| 52 Singleton<AppModalDialogQueue>()->AddDialog(new AppModalDialog( | 55 Singleton<AppModalDialogQueue>()->AddDialog(new JavaScriptAppModalDialog( |
| 53 tab_contents, l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE), | 56 tab_contents, l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE), |
| 54 MessageBoxFlags::kIsJavascriptConfirm, MakeTextSafe(message_text), | 57 MessageBoxFlags::kIsJavascriptConfirm, MakeTextSafe(message_text), |
| 55 std::wstring(), false, true, reply_msg)); | 58 std::wstring(), false, true, reply_msg)); |
| 56 } | 59 } |
| 60 |
| 61 #if defined(OS_WIN) |
| 62 void RunCookiePrompt(TabContents* tab_contents, |
| 63 const GURL& url, |
| 64 const std::string& cookie_line, |
| 65 CookiePromptModalDialogDelegate* delegate) { |
| 66 Singleton<AppModalDialogQueue>()->AddDialog( |
| 67 new CookiePromptModalDialog(tab_contents, url, cookie_line, delegate)); |
| 68 } |
| 69 |
| 70 |
| 71 void RunLocalStoragePrompt( |
| 72 TabContents* tab_contents, |
| 73 const BrowsingDataLocalStorageHelper::LocalStorageInfo& local_storage_info, |
| 74 CookiePromptModalDialogDelegate* delegate) { |
| 75 Singleton<AppModalDialogQueue>()->AddDialog( |
| 76 new CookiePromptModalDialog(tab_contents, local_storage_info, delegate)); |
| 77 } |
| 78 #endif |
| 79 |
| OLD | NEW |