diff options
Diffstat (limited to 'chrome/browser/ui/app_modal_dialogs/message_box_handler.cc')
-rw-r--r-- | chrome/browser/ui/app_modal_dialogs/message_box_handler.cc | 85 |
1 files changed, 34 insertions, 51 deletions
diff --git a/chrome/browser/ui/app_modal_dialogs/message_box_handler.cc b/chrome/browser/ui/app_modal_dialogs/message_box_handler.cc index 875024a..09870d4 100644 --- a/chrome/browser/ui/app_modal_dialogs/message_box_handler.cc +++ b/chrome/browser/ui/app_modal_dialogs/message_box_handler.cc @@ -8,35 +8,28 @@ #include "base/compiler_specific.h" #include "base/memory/singleton.h" -#include "base/time.h" #include "base/utf_string_conversions.h" #include "base/i18n/rtl.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" #include "chrome/common/chrome_constants.h" -#include "chrome/common/pref_names.h" #include "content/browser/javascript_dialogs.h" #include "grit/generated_resources.h" -#include "grit/chromium_strings.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/message_box_flags.h" -#include "ui/base/text/text_elider.h" -#include "ui/gfx/font.h" class ChromeJavaScriptDialogCreator : public content::JavaScriptDialogCreator { public: static ChromeJavaScriptDialogCreator* GetInstance(); virtual void RunJavaScriptDialog(content::JavaScriptDialogDelegate* delegate, - const GURL& frame_url, + TitleType title_type, + const string16& title, int dialog_flags, const string16& message_text, const string16& default_prompt_text, IPC::Message* reply_message, - bool* did_suppress_message, - Profile* profile) OVERRIDE; + bool* did_suppress_message) OVERRIDE; virtual void RunBeforeUnloadDialog( content::JavaScriptDialogDelegate* delegate, @@ -52,9 +45,9 @@ class ChromeJavaScriptDialogCreator : public content::JavaScriptDialogCreator { friend struct DefaultSingletonTraits<ChromeJavaScriptDialogCreator>; - string16 GetTitle(Profile* profile, - bool is_alert, - const GURL& frame_url); + string16 GetTitle(TitleType title_type, + const string16& title, + bool is_alert); // Mapping between the JavaScriptDialogDelegates and their extra data. The key // is a void* because the pointer is just a cookie and is never dereferenced. @@ -78,13 +71,13 @@ ChromeJavaScriptDialogCreator* ChromeJavaScriptDialogCreator::GetInstance() { void ChromeJavaScriptDialogCreator::RunJavaScriptDialog( content::JavaScriptDialogDelegate* delegate, - const GURL& frame_url, + TitleType title_type, + const string16& title, int dialog_flags, const string16& message_text, const string16& default_prompt_text, IPC::Message* reply_message, - bool* did_suppress_message, - Profile* profile) { + bool* did_suppress_message) { *did_suppress_message = false; ChromeJavaScriptDialogExtraData* extra_data = @@ -107,12 +100,12 @@ void ChromeJavaScriptDialogCreator::RunJavaScriptDialog( } bool is_alert = dialog_flags == ui::MessageBoxFlags::kIsJavascriptAlert; - string16 title = GetTitle(profile, is_alert, frame_url); + string16 dialog_title = GetTitle(title_type, title, is_alert); AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( delegate, extra_data, - title, + dialog_title, dialog_flags, message_text, default_prompt_text, @@ -148,41 +141,31 @@ void ChromeJavaScriptDialogCreator::ResetJavaScriptState( javascript_dialog_extra_data_.erase(delegate); } -string16 ChromeJavaScriptDialogCreator::GetTitle(Profile* profile, - bool is_alert, - const GURL& frame_url) { - ExtensionService* extensions_service = profile->GetExtensionService(); - if (extensions_service) { - const Extension* extension = - extensions_service->GetExtensionByURL(frame_url); - if (!extension) - extension = extensions_service->GetExtensionByWebExtent(frame_url); - - if (extension && (extension->location() == Extension::COMPONENT)) { - return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); - } else if (extension && !extension->name().empty()) { - return UTF8ToUTF16(extension->name()); +string16 ChromeJavaScriptDialogCreator::GetTitle(TitleType title_type, + const string16& title, + bool is_alert) { + switch (title_type) { + case DIALOG_TITLE_NONE: { + return l10n_util::GetStringUTF16( + is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE + : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE); + break; + } + case DIALOG_TITLE_PLAIN_STRING: { + return title; + break; + } + case DIALOG_TITLE_FORMATTED_URL: { + // Force URL to have LTR directionality. + return l10n_util::GetStringFUTF16( + is_alert ? IDS_JAVASCRIPT_ALERT_TITLE + : IDS_JAVASCRIPT_MESSAGEBOX_TITLE, + base::i18n::GetDisplayStringInLTRDirectionality(title)); + break; } } - if (!frame_url.has_host()) { - return l10n_util::GetStringUTF16( - is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE - : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE); - } - - // TODO(brettw) it should be easier than this to do the correct language - // handling without getting the accept language from the profile. - string16 base_address = ui::ElideUrl(frame_url.GetOrigin(), - gfx::Font(), 0, profile->GetPrefs()->GetString(prefs::kAcceptLanguages)); - - // Force URL to have LTR directionality. - base_address = base::i18n::GetDisplayStringInLTRDirectionality( - base_address); - - return l10n_util::GetStringFUTF16( - is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : - IDS_JAVASCRIPT_MESSAGEBOX_TITLE, - base_address); + NOTREACHED(); + return string16(); } //------------------------------------------------------------------------------ |