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

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

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

Powered by Google App Engine
This is Rietveld 408576698