diff options
author | pam@chromium.org <pam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-05 18:22:35 +0000 |
---|---|---|
committer | pam@chromium.org <pam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-05 18:22:35 +0000 |
commit | e1d0303ebea1caddb079d71b63f39463d3944bad (patch) | |
tree | 9c9c1abb6d608889aa20d14c34036eb99ffe2c58 /chrome/browser/tab_contents/tab_contents.cc | |
parent | d6b401bed87fa50d1fc0993c04ee7ee992dd6627 (diff) | |
download | chromium_src-e1d0303ebea1caddb079d71b63f39463d3944bad.zip chromium_src-e1d0303ebea1caddb079d71b63f39463d3944bad.tar.gz chromium_src-e1d0303ebea1caddb079d71b63f39463d3944bad.tar.bz2 |
Implement window.alert() and its cousins for extensions.
BUG=12126
TEST=put a window.prompt() in a background page, a browser action, and a page action.
Make sure it gets the result back correctly. Also make sure it still works when
called from a web page.
Review URL: http://codereview.chromium.org/341089
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31110 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents/tab_contents.cc')
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 70 |
1 files changed, 54 insertions, 16 deletions
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index e72df68..831b13c 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -4,6 +4,7 @@ #include "chrome/browser/tab_contents/tab_contents.h" +#include "app/gfx/text_elider.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/file_version_info.h" @@ -1114,21 +1115,6 @@ void TabContents::GetPageLanguage() { render_view_host()->GetPageLanguage(); } -void TabContents::OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg, - bool success, - const std::wstring& prompt) { - last_javascript_message_dismissal_ = base::TimeTicks::Now(); - if (is_showing_before_unload_dialog_ && !success) { - // If a beforeunload dialog is canceled, we need to stop the throbber from - // spinning, since we forced it to start spinning in Navigate. - DidStopLoading(); - - tab_close_start_time_ = base::TimeTicks(); - } - is_showing_before_unload_dialog_ = false; - render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt); -} - void TabContents::OnSavePage() { // If we can not save the page, try to download it. if (!SavePackage::IsSavableContents(contents_mime_type())) { @@ -2333,7 +2319,7 @@ void TabContents::RunJavaScriptMessage( } else { // If we are suppressing messages, just reply as is if the user immediately // pressed "Cancel". - OnJavaScriptMessageBoxClosed(reply_msg, false, std::wstring()); + OnMessageBoxClosed(reply_msg, false, std::wstring()); } } @@ -2648,6 +2634,58 @@ void TabContents::Observe(NotificationType type, } } +std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url, + bool is_alert) { + if (!frame_url.has_host()) + return l10n_util::GetString( + is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE + : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE); + + // We really only want the scheme, hostname, and port. + GURL::Replacements replacements; + replacements.ClearUsername(); + replacements.ClearPassword(); + replacements.ClearPath(); + replacements.ClearQuery(); + replacements.ClearRef(); + GURL clean_url = frame_url.ReplaceComponents(replacements); + + // TODO(brettw) it should be easier than this to do the correct language + // handling without getting the accept language from the profile. + std::wstring base_address = gfx::ElideUrl(clean_url, gfx::Font(), 0, + profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)); + // Force URL to have LTR directionality. + if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) + l10n_util::WrapStringWithLTRFormatting(&base_address); + + return l10n_util::GetStringF( + is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE, + base_address); +} + +gfx::NativeWindow TabContents::GetMessageBoxRootWindow() { + return view_->GetTopLevelNativeWindow(); +} + +void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg, + bool success, + const std::wstring& prompt) { + last_javascript_message_dismissal_ = base::TimeTicks::Now(); + if (is_showing_before_unload_dialog_ && !success) { + // If a beforeunload dialog is canceled, we need to stop the throbber from + // spinning, since we forced it to start spinning in Navigate. + DidStopLoading(); + + tab_close_start_time_ = base::TimeTicks(); + } + is_showing_before_unload_dialog_ = false; + render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt); +} + +void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) { + set_suppress_javascript_messages(suppress_message_boxes); +} + void TabContents::set_encoding(const std::string& encoding) { encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); } |