OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009 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 "chrome/browser/jsmessage_box_handler.h" | |
6 | |
7 #include "app/l10n_util.h" | |
8 #include "app/message_box_flags.h" | |
9 #include "build/build_config.h" | |
10 #include "chrome/browser/app_modal_dialog_queue.h" | |
11 #include "chrome/browser/browser_process.h" | |
12 #include "chrome/browser/tab_contents/tab_contents.h" | |
13 #include "googleurl/src/gurl.h" | |
14 #include "grit/generated_resources.h" | |
15 | |
16 namespace { | |
17 | |
18 const size_t kMaxReasonableTextLength = 2048; | |
19 | |
20 // In some platforms, the underlying processing of humongous strings takes too | |
21 // long and thus make the UI thread unresponsive. | |
22 std::wstring MakeTextSafe(const std::wstring& text) { | |
23 if (text.size() > kMaxReasonableTextLength) | |
24 return text.substr(0, kMaxReasonableTextLength) + L"\x2026"; | |
25 return text; | |
26 } | |
27 | |
28 } // namespace | |
29 | |
30 void RunJavascriptMessageBox(JavaScriptMessageBoxClient* client, | |
31 const GURL& frame_url, | |
32 int dialog_flags, | |
33 const std::wstring& message_text, | |
34 const std::wstring& default_prompt_text, | |
35 bool display_suppress_checkbox, | |
36 IPC::Message* reply_msg) { | |
37 std::wstring title = client->GetMessageBoxTitle(frame_url, | |
38 (dialog_flags == MessageBoxFlags::kIsJavascriptAlert)); | |
39 Singleton<AppModalDialogQueue>()->AddDialog( | |
40 new AppModalDialog(client, title, | |
41 dialog_flags, MakeTextSafe(message_text), | |
42 default_prompt_text, display_suppress_checkbox, | |
43 false, reply_msg)); | |
44 } | |
45 | |
46 void RunBeforeUnloadDialog(TabContents* tab_contents, | |
47 const std::wstring& message_text, | |
48 IPC::Message* reply_msg) { | |
49 std::wstring full_message = | |
50 message_text + L"\n\n" + | |
51 l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER); | |
52 Singleton<AppModalDialogQueue>()->AddDialog(new AppModalDialog( | |
53 tab_contents, l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE), | |
54 MessageBoxFlags::kIsJavascriptConfirm, MakeTextSafe(message_text), | |
55 std::wstring(), false, true, reply_msg)); | |
56 } | |
OLD | NEW |