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

Side by Side Diff: chrome/browser/ui/app_modal_dialogs/message_box_handler.cc

Issue 6257006: Move a bunch of random other files to src/ui/base... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 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/ui/app_modal_dialogs/message_box_handler.h" 5 #include "chrome/browser/ui/app_modal_dialogs/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"
9 #include "app/text_elider.h"
10 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
11 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
12 #include "build/build_config.h" 10 #include "build/build_config.h"
13 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/tab_contents/tab_contents.h" 13 #include "chrome/browser/tab_contents/tab_contents.h"
16 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" 14 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h"
17 #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" 15 #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h"
18 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
19 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
20 #include "gfx/font.h" 18 #include "gfx/font.h"
21 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
22 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
23 #include "grit/chromium_strings.h" 21 #include "grit/chromium_strings.h"
22 #include "ui/base/message_box_flags.h"
23 #include "ui/base/text/text_elider.h"
24 24
25 static std::wstring GetTitle(Profile* profile, 25 static std::wstring GetTitle(Profile* profile,
26 bool is_alert, 26 bool is_alert,
27 const GURL& frame_url) { 27 const GURL& frame_url) {
28 ExtensionService* extensions_service = profile->GetExtensionService(); 28 ExtensionService* extensions_service = profile->GetExtensionService();
29 if (extensions_service) { 29 if (extensions_service) {
30 const Extension* extension = 30 const Extension* extension =
31 extensions_service->GetExtensionByURL(frame_url); 31 extensions_service->GetExtensionByURL(frame_url);
32 if (!extension) 32 if (!extension)
33 extension = extensions_service->GetExtensionByWebExtent(frame_url); 33 extension = extensions_service->GetExtensionByWebExtent(frame_url);
34 34
35 if (extension && (extension->location() == Extension::COMPONENT)) { 35 if (extension && (extension->location() == Extension::COMPONENT)) {
36 return UTF16ToWideHack(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); 36 return UTF16ToWideHack(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
37 } else if (extension && !extension->name().empty()) { 37 } else if (extension && !extension->name().empty()) {
38 return UTF8ToWide(extension->name()); 38 return UTF8ToWide(extension->name());
39 } 39 }
40 } 40 }
41 if (!frame_url.has_host()) { 41 if (!frame_url.has_host()) {
42 return UTF16ToWideHack(l10n_util::GetStringUTF16( 42 return UTF16ToWideHack(l10n_util::GetStringUTF16(
43 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE 43 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE
44 : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE)); 44 : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE));
45 } 45 }
46 46
47 // TODO(brettw) it should be easier than this to do the correct language 47 // TODO(brettw) it should be easier than this to do the correct language
48 // handling without getting the accept language from the profile. 48 // handling without getting the accept language from the profile.
49 string16 base_address = gfx::ElideUrl(frame_url.GetOrigin(), 49 string16 base_address = ui::ElideUrl(frame_url.GetOrigin(),
50 gfx::Font(), 0, 50 gfx::Font(), 0,
51 UTF8ToWide(profile->GetPrefs()->GetString(prefs::kAcceptLanguages))); 51 UTF8ToWide(profile->GetPrefs()->GetString(prefs::kAcceptLanguages)));
52 52
53 // Force URL to have LTR directionality. 53 // Force URL to have LTR directionality.
54 base_address = base::i18n::GetDisplayStringInLTRDirectionality( 54 base_address = base::i18n::GetDisplayStringInLTRDirectionality(
55 base_address); 55 base_address);
56 56
57 return UTF16ToWide(l10n_util::GetStringFUTF16( 57 return UTF16ToWide(l10n_util::GetStringFUTF16(
58 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : 58 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE :
59 IDS_JAVASCRIPT_MESSAGEBOX_TITLE, 59 IDS_JAVASCRIPT_MESSAGEBOX_TITLE,
60 base_address)); 60 base_address));
61 } 61 }
62 62
63 void RunJavascriptMessageBox(Profile* profile, 63 void RunJavascriptMessageBox(Profile* profile,
64 JavaScriptAppModalDialogDelegate* delegate, 64 JavaScriptAppModalDialogDelegate* delegate,
65 const GURL& frame_url, 65 const GURL& frame_url,
66 int dialog_flags, 66 int dialog_flags,
67 const std::wstring& message_text, 67 const std::wstring& message_text,
68 const std::wstring& default_prompt_text, 68 const std::wstring& default_prompt_text,
69 bool display_suppress_checkbox, 69 bool display_suppress_checkbox,
70 IPC::Message* reply_msg) { 70 IPC::Message* reply_msg) {
71 bool is_alert = dialog_flags == MessageBoxFlags::kIsJavascriptAlert; 71 bool is_alert = dialog_flags == ui::MessageBoxFlags::kIsJavascriptAlert;
72 std::wstring title = GetTitle(profile, is_alert, frame_url); 72 std::wstring title = GetTitle(profile, is_alert, frame_url);
73 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( 73 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog(
74 delegate, title, dialog_flags, message_text, default_prompt_text, 74 delegate, title, dialog_flags, message_text, default_prompt_text,
75 display_suppress_checkbox, false, reply_msg)); 75 display_suppress_checkbox, false, reply_msg));
76 } 76 }
77 77
78 void RunBeforeUnloadDialog(TabContents* tab_contents, 78 void RunBeforeUnloadDialog(TabContents* tab_contents,
79 const std::wstring& message_text, 79 const std::wstring& message_text,
80 IPC::Message* reply_msg) { 80 IPC::Message* reply_msg) {
81 std::wstring full_message = message_text + L"\n\n" + UTF16ToWideHack( 81 std::wstring full_message = message_text + L"\n\n" + UTF16ToWideHack(
82 l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER)); 82 l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER));
83 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( 83 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog(
84 tab_contents, 84 tab_contents,
85 UTF16ToWideHack( 85 UTF16ToWideHack(
86 l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE)), 86 l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE)),
87 MessageBoxFlags::kIsJavascriptConfirm, 87 ui::MessageBoxFlags::kIsJavascriptConfirm,
88 message_text, 88 message_text,
89 std::wstring(), 89 std::wstring(),
90 false, 90 false,
91 true, 91 true,
92 reply_msg)); 92 reply_msg));
93 } 93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698