OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_win.h" | 5 #include "chrome/browser/jsmessage_box_handler_win.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "chrome/browser/app_modal_dialog_queue.h" | 8 #include "chrome/browser/app_modal_dialog_queue.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
11 #include "chrome/browser/tab_contents/web_contents.h" | 11 #include "chrome/browser/tab_contents/web_contents.h" |
12 #include "chrome/common/gfx/text_elider.h" | 12 #include "chrome/common/gfx/text_elider.h" |
13 #include "chrome/common/l10n_util.h" | 13 #include "chrome/common/l10n_util.h" |
14 #include "chrome/common/notification_service.h" | 14 #include "chrome/common/notification_service.h" |
15 #include "chrome/common/notification_type.h" | 15 #include "chrome/common/notification_type.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "chrome/common/pref_service.h" | 17 #include "chrome/common/pref_service.h" |
18 #include "chrome/views/message_box_view.h" | 18 #include "chrome/views/message_box_view.h" |
19 #include "chrome/views/window.h" | 19 #include "chrome/views/window.h" |
20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
21 | 21 |
22 void RunJavascriptMessageBox(WebContents* web_contents, | 22 void RunJavascriptMessageBox(WebContents* web_contents, |
| 23 const GURL& frame_url, |
23 int dialog_flags, | 24 int dialog_flags, |
24 const std::wstring& message_text, | 25 const std::wstring& message_text, |
25 const std::wstring& default_prompt_text, | 26 const std::wstring& default_prompt_text, |
26 bool display_suppress_checkbox, | 27 bool display_suppress_checkbox, |
27 IPC::Message* reply_msg) { | 28 IPC::Message* reply_msg) { |
28 JavascriptMessageBoxHandler* handler = | 29 JavascriptMessageBoxHandler* handler = |
29 new JavascriptMessageBoxHandler(web_contents, dialog_flags, | 30 new JavascriptMessageBoxHandler(web_contents, frame_url, dialog_flags, |
30 message_text, default_prompt_text, | 31 message_text, default_prompt_text, |
31 display_suppress_checkbox, reply_msg); | 32 display_suppress_checkbox, reply_msg); |
32 AppModalDialogQueue::AddDialog(handler); | 33 AppModalDialogQueue::AddDialog(handler); |
33 } | 34 } |
34 | 35 |
35 JavascriptMessageBoxHandler::JavascriptMessageBoxHandler( | 36 JavascriptMessageBoxHandler::JavascriptMessageBoxHandler( |
36 WebContents* web_contents, | 37 WebContents* web_contents, |
| 38 const GURL& frame_url, |
37 int dialog_flags, | 39 int dialog_flags, |
38 const std::wstring& message_text, | 40 const std::wstring& message_text, |
39 const std::wstring& default_prompt_text, | 41 const std::wstring& default_prompt_text, |
40 bool display_suppress_checkbox, | 42 bool display_suppress_checkbox, |
41 IPC::Message* reply_msg) | 43 IPC::Message* reply_msg) |
42 : web_contents_(web_contents), | 44 : web_contents_(web_contents), |
43 reply_msg_(reply_msg), | 45 frame_url_(frame_url), |
44 dialog_flags_(dialog_flags), | 46 reply_msg_(reply_msg), |
45 dialog_(NULL), | 47 dialog_flags_(dialog_flags), |
46 message_box_view_(new MessageBoxView( | 48 dialog_(NULL), |
47 dialog_flags | MessageBoxView::kAutoDetectAlignment, | 49 message_box_view_(new MessageBoxView( |
48 message_text, default_prompt_text)) { | 50 dialog_flags | MessageBoxView::kAutoDetectAlignment, |
| 51 message_text, default_prompt_text)) { |
49 DCHECK(message_box_view_); | 52 DCHECK(message_box_view_); |
50 DCHECK(reply_msg_); | 53 DCHECK(reply_msg_); |
51 | 54 |
52 if (display_suppress_checkbox) { | 55 if (display_suppress_checkbox) { |
53 message_box_view_->SetCheckBoxLabel( | 56 message_box_view_->SetCheckBoxLabel( |
54 l10n_util::GetString(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION)); | 57 l10n_util::GetString(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION)); |
55 } | 58 } |
56 | 59 |
57 // Make sure we get navigation notifications so we know when our parent | 60 // Make sure we get navigation notifications so we know when our parent |
58 // contents will disappear or navigate to a different page. | 61 // contents will disappear or navigate to a different page. |
(...skipping 14 matching lines...) Expand all Loading... |
73 if (dialog_flags_ & MessageBoxView::kFlagHasOKButton) | 76 if (dialog_flags_ & MessageBoxView::kFlagHasOKButton) |
74 dialog_buttons = DIALOGBUTTON_OK; | 77 dialog_buttons = DIALOGBUTTON_OK; |
75 | 78 |
76 if (dialog_flags_ & MessageBoxView::kFlagHasCancelButton) | 79 if (dialog_flags_ & MessageBoxView::kFlagHasCancelButton) |
77 dialog_buttons |= DIALOGBUTTON_CANCEL; | 80 dialog_buttons |= DIALOGBUTTON_CANCEL; |
78 | 81 |
79 return dialog_buttons; | 82 return dialog_buttons; |
80 } | 83 } |
81 | 84 |
82 std::wstring JavascriptMessageBoxHandler::GetWindowTitle() const { | 85 std::wstring JavascriptMessageBoxHandler::GetWindowTitle() const { |
83 if (!web_contents_) | 86 if (!frame_url_.has_host()) |
84 return std::wstring(); | |
85 | |
86 GURL url = web_contents_->GetURL(); | |
87 if (!url.has_host()) | |
88 return l10n_util::GetString(IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE); | 87 return l10n_util::GetString(IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE); |
89 | 88 |
90 // We really only want the scheme, hostname, and port. | 89 // We really only want the scheme, hostname, and port. |
91 GURL::Replacements replacements; | 90 GURL::Replacements replacements; |
92 replacements.ClearUsername(); | 91 replacements.ClearUsername(); |
93 replacements.ClearPassword(); | 92 replacements.ClearPassword(); |
94 replacements.ClearPath(); | 93 replacements.ClearPath(); |
95 replacements.ClearQuery(); | 94 replacements.ClearQuery(); |
96 replacements.ClearRef(); | 95 replacements.ClearRef(); |
97 GURL clean_url = url.ReplaceComponents(replacements); | 96 GURL clean_url = frame_url_.ReplaceComponents(replacements); |
98 | 97 |
99 // TODO(brettw) it should be easier than this to do the correct language | 98 // TODO(brettw) it should be easier than this to do the correct language |
100 // handling without getting the accept language from the profile. | 99 // handling without getting the accept language from the profile. |
101 std::wstring base_address = gfx::ElideUrl(clean_url, ChromeFont(), 0, | 100 std::wstring base_address = gfx::ElideUrl(clean_url, ChromeFont(), 0, |
102 web_contents_->profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 101 web_contents_->profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
103 // Force URL to have LTR directionality. | 102 // Force URL to have LTR directionality. |
104 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) | 103 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) |
105 l10n_util::WrapStringWithLTRFormatting(&base_address); | 104 l10n_util::WrapStringWithLTRFormatting(&base_address); |
106 return l10n_util::GetStringF(IDS_JAVASCRIPT_MESSAGEBOX_TITLE, base_address); | 105 return l10n_util::GetStringF(IDS_JAVASCRIPT_MESSAGEBOX_TITLE, base_address); |
107 } | 106 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 web_contents_gone = true; | 200 web_contents_gone = true; |
202 | 201 |
203 if (web_contents_gone) { | 202 if (web_contents_gone) { |
204 web_contents_ = NULL; | 203 web_contents_ = NULL; |
205 | 204 |
206 // If the dialog is visible close it. | 205 // If the dialog is visible close it. |
207 if (dialog_) | 206 if (dialog_) |
208 dialog_->Close(); | 207 dialog_->Close(); |
209 } | 208 } |
210 } | 209 } |
OLD | NEW |