Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: chrome/browser/jsmessage_box_handler.cc

Issue 63033: Refactor AppModalDialogQueue and move JS Alert boxes into a MVC. (Closed)
Patch Set: whitespace Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/jsmessage_box_handler.h ('k') | chrome/browser/jsmessage_box_handler_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "build/build_config.h"
8 #include "chrome/browser/app_modal_dialog_queue.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profile.h"
11 #include "chrome/browser/tab_contents/web_contents.h"
12 #include "chrome/common/gfx/text_elider.h"
13 #include "chrome/common/l10n_util.h"
14 #include "chrome/common/message_box_flags.h"
15 #include "chrome/common/pref_names.h"
16 #include "chrome/common/pref_service.h"
17 #include "googleurl/src/gurl.h"
18 #include "grit/generated_resources.h"
19
20 namespace {
21
22 std::wstring GetWindowTitle(WebContents* web_contents, const GURL& frame_url) {
23 if (!frame_url.has_host())
24 return l10n_util::GetString(IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE);
25
26 // We really only want the scheme, hostname, and port.
27 GURL::Replacements replacements;
28 replacements.ClearUsername();
29 replacements.ClearPassword();
30 replacements.ClearPath();
31 replacements.ClearQuery();
32 replacements.ClearRef();
33 GURL clean_url = frame_url.ReplaceComponents(replacements);
34
35 // TODO(brettw) it should be easier than this to do the correct language
36 // handling without getting the accept language from the profile.
37 std::wstring base_address = gfx::ElideUrl(clean_url, ChromeFont(), 0,
38 web_contents->profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
39 // Force URL to have LTR directionality.
40 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
41 l10n_util::WrapStringWithLTRFormatting(&base_address);
42 return l10n_util::GetStringF(IDS_JAVASCRIPT_MESSAGEBOX_TITLE, base_address);
43 }
44
45 }
46
47 void RunJavascriptMessageBox(WebContents* web_contents,
48 const GURL& frame_url,
49 int dialog_flags,
50 const std::wstring& message_text,
51 const std::wstring& default_prompt_text,
52 bool display_suppress_checkbox,
53 IPC::Message* reply_msg) {
54 std::wstring title = GetWindowTitle(web_contents, frame_url);
55
56 #if defined(OS_WIN)
57 AppModalDialogQueue::AddDialog(new AppModalDialog(web_contents, title,
58 dialog_flags, message_text, default_prompt_text,
59 display_suppress_checkbox, false, reply_msg));
60 #else
61 NOTIMPLEMENTED();
62 #endif
63 }
64
65 void RunBeforeUnloadDialog(WebContents* web_contents,
66 const std::wstring& message_text,
67 IPC::Message* reply_msg) {
68 std::wstring full_message =
69 message_text + L"\n\n" +
70 l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER);
71 #if defined(OS_WIN)
72 AppModalDialogQueue::AddDialog(new AppModalDialog(
73 web_contents, l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE),
74 MessageBox::kIsJavascriptConfirm, message_text, std::wstring(), false,
75 true, reply_msg));
76 #else
77 NOTIMPLEMENTED();
78 #endif
79 }
OLDNEW
« no previous file with comments | « chrome/browser/jsmessage_box_handler.h ('k') | chrome/browser/jsmessage_box_handler_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698