summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-03 18:02:07 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-03 18:02:07 +0000
commit3ab9cb81731759c6e11f8c5296c1b75a7d2dadf1 (patch)
tree9344ece34a634b18d3e226c738471159d32484a6 /chrome/browser/ui
parenteadd4e31649b1a9da5d47864ff26ccd06b45edba (diff)
downloadchromium_src-3ab9cb81731759c6e11f8c5296c1b75a7d2dadf1.zip
chromium_src-3ab9cb81731759c6e11f8c5296c1b75a7d2dadf1.tar.gz
chromium_src-3ab9cb81731759c6e11f8c5296c1b75a7d2dadf1.tar.bz2
Remove JS dialog dependency from content.
BUG=71097 TEST=all types of javascript dialogs work, onbeforeunload dialogs work too Review URL: http://codereview.chromium.org/7096016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87806 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r--chrome/browser/ui/app_modal_dialogs/app_modal_dialog.cc2
-rw-r--r--chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h7
-rw-r--r--chrome/browser/ui/app_modal_dialogs/js_modal_dialog.cc44
-rw-r--r--chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h62
-rw-r--r--chrome/browser/ui/app_modal_dialogs/message_box_handler.cc188
-rw-r--r--chrome/browser/ui/app_modal_dialogs/message_box_handler.h37
-rw-r--r--chrome/browser/ui/blocked_content/blocked_content_container.cc6
-rw-r--r--chrome/browser/ui/blocked_content/blocked_content_container.h3
-rw-r--r--chrome/browser/ui/browser.cc5
-rw-r--r--chrome/browser/ui/browser.h2
-rw-r--r--chrome/browser/ui/cocoa/js_modal_dialog_cocoa.mm10
-rw-r--r--chrome/browser/ui/gtk/js_modal_dialog_gtk.cc12
-rw-r--r--chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc6
-rw-r--r--chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h2
-rw-r--r--chrome/browser/ui/views/html_dialog_view_browsertest.cc2
-rw-r--r--chrome/browser/ui/views/js_modal_dialog_views.cc7
-rw-r--r--chrome/browser/ui/views/ssl_client_certificate_selector_win.cc2
-rw-r--r--chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.cc1
-rw-r--r--chrome/browser/ui/views/tabs/dragged_tab_controller.cc6
-rw-r--r--chrome/browser/ui/views/tabs/dragged_tab_controller.h2
-rw-r--r--chrome/browser/ui/web_applications/web_app_ui.cc1
-rw-r--r--chrome/browser/ui/webui/flags_ui.cc1
-rw-r--r--chrome/browser/ui/webui/flash_ui.cc1
-rw-r--r--chrome/browser/ui/webui/options/advanced_options_handler.cc2
-rw-r--r--chrome/browser/ui/webui/textfields_ui.cc1
-rw-r--r--chrome/browser/ui/webui/web_ui_browsertest.cc1
26 files changed, 260 insertions, 153 deletions
diff --git a/chrome/browser/ui/app_modal_dialogs/app_modal_dialog.cc b/chrome/browser/ui/app_modal_dialogs/app_modal_dialog.cc
index 51f1755..257def3 100644
--- a/chrome/browser/ui/app_modal_dialogs/app_modal_dialog.cc
+++ b/chrome/browser/ui/app_modal_dialogs/app_modal_dialog.cc
@@ -11,7 +11,7 @@
#include "content/common/notification_type.h"
AppModalDialog::AppModalDialog(TabContents* tab_contents,
- const std::wstring& title)
+ const string16& title)
: skip_this_dialog_(false),
tab_contents_(tab_contents),
native_dialog_(NULL),
diff --git a/chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h b/chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h
index 39b358a..8d09d48 100644
--- a/chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h
+++ b/chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h
@@ -9,6 +9,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/string16.h"
#include "build/build_config.h"
class NativeAppModalDialog;
@@ -20,7 +21,7 @@ class AppModalDialog {
// A union of data necessary to determine the type of message box to
// show. |tab_contents| parameter is optional, if provided that tab will be
// activated before the modal dialog is displayed.
- AppModalDialog(TabContents* tab_contents, const std::wstring& title);
+ AppModalDialog(TabContents* tab_contents, const string16& title);
virtual ~AppModalDialog();
// Called by the AppModalDialogQueue to show this dialog.
@@ -37,7 +38,7 @@ class AppModalDialog {
void CompleteDialog();
// Dialog window title.
- std::wstring title() const { return title_; }
+ string16 title() const { return title_; }
NativeAppModalDialog* native_dialog() const { return native_dialog_; }
@@ -76,7 +77,7 @@ class AppModalDialog {
private:
// Information about the message box is held in the following variables.
- std::wstring title_;
+ string16 title_;
DISALLOW_COPY_AND_ASSIGN(AppModalDialog);
};
diff --git a/chrome/browser/ui/app_modal_dialogs/js_modal_dialog.cc b/chrome/browser/ui/app_modal_dialogs/js_modal_dialog.cc
index 84ae2cc..2714272 100644
--- a/chrome/browser/ui/app_modal_dialogs/js_modal_dialog.cc
+++ b/chrome/browser/ui/app_modal_dialogs/js_modal_dialog.cc
@@ -48,28 +48,31 @@ void EnforceMaxPromptSize(const string16& in_string, string16* out_string) {
} // namespace
+ChromeJavaScriptDialogExtraData::ChromeJavaScriptDialogExtraData()
+ : suppress_javascript_messages_(false) {
+}
+
JavaScriptAppModalDialog::JavaScriptAppModalDialog(
- JavaScriptAppModalDialogDelegate* delegate,
- const std::wstring& title,
+ content::JavaScriptDialogDelegate* delegate,
+ ChromeJavaScriptDialogExtraData* extra_data,
+ const string16& title,
int dialog_flags,
- const std::wstring& message_text,
- const std::wstring& default_prompt_text,
+ const string16& message_text,
+ const string16& default_prompt_text,
bool display_suppress_checkbox,
bool is_before_unload_dialog,
IPC::Message* reply_msg)
: AppModalDialog(delegate->AsTabContents(), title),
delegate_(delegate),
+ extra_data_(extra_data),
extension_host_(delegate->AsExtensionHost()),
dialog_flags_(dialog_flags),
display_suppress_checkbox_(display_suppress_checkbox),
is_before_unload_dialog_(is_before_unload_dialog),
reply_msg_(reply_msg),
use_override_prompt_text_(false) {
- string16 elided_text;
- EnforceMaxTextSize(WideToUTF16(message_text), &elided_text);
- message_text_ = UTF16ToWide(elided_text);
- EnforceMaxPromptSize(WideToUTF16Hack(default_prompt_text),
- &default_prompt_text_);
+ EnforceMaxTextSize(message_text, &message_text_);
+ EnforceMaxPromptSize(default_prompt_text, &default_prompt_text_);
DCHECK((tab_contents_ != NULL) != (extension_host_ != NULL));
InitNotifications();
@@ -79,9 +82,7 @@ JavaScriptAppModalDialog::~JavaScriptAppModalDialog() {
}
NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() {
- gfx::NativeWindow parent_window = tab_contents_ ?
- tab_contents_->GetMessageBoxRootWindow() :
- extension_host_->GetMessageBoxRootWindow();
+ gfx::NativeWindow parent_window = delegate_->GetDialogRootWindow();
return NativeAppModalDialog::CreateNativeJavaScriptPrompt(this,
parent_window);
}
@@ -142,22 +143,22 @@ void JavaScriptAppModalDialog::OnCancel(bool suppress_js_messages) {
// is a temporary workaround.
CompleteDialog();
- NotifyDelegate(false, L"", suppress_js_messages);
+ NotifyDelegate(false, string16(), suppress_js_messages);
}
-void JavaScriptAppModalDialog::OnAccept(const std::wstring& prompt_text,
+void JavaScriptAppModalDialog::OnAccept(const string16& prompt_text,
bool suppress_js_messages) {
- std::wstring prompt_text_to_use = prompt_text;
+ string16 prompt_text_to_use = prompt_text;
// This is only for testing.
if (use_override_prompt_text_)
- prompt_text_to_use = UTF16ToWideHack(override_prompt_text_);
+ prompt_text_to_use = override_prompt_text_;
CompleteDialog();
NotifyDelegate(true, prompt_text_to_use, suppress_js_messages);
}
void JavaScriptAppModalDialog::OnClose() {
- NotifyDelegate(false, L"", false);
+ NotifyDelegate(false, string16(), false);
}
void JavaScriptAppModalDialog::SetOverridePromptText(
@@ -167,14 +168,15 @@ void JavaScriptAppModalDialog::SetOverridePromptText(
}
void JavaScriptAppModalDialog::NotifyDelegate(bool success,
- const std::wstring& prompt_text,
+ const string16& user_input,
bool suppress_js_messages) {
if (skip_this_dialog_)
return;
- delegate_->OnMessageBoxClosed(reply_msg_, success, prompt_text);
- if (suppress_js_messages)
- delegate_->SetSuppressMessageBoxes(true);
+ delegate_->OnDialogClosed(reply_msg_, success, user_input);
+
+ extra_data_->last_javascript_message_dismissal_ = base::TimeTicks::Now();
+ extra_data_->suppress_javascript_messages_ = suppress_js_messages;
// On Views, we can end up coming through this code path twice :(.
// See crbug.com/63732.
diff --git a/chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h b/chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h
index 851b039..6a05b8e 100644
--- a/chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h
+++ b/chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h
@@ -8,12 +8,12 @@
#include <string>
-#include "base/utf_string_conversions.h"
+#include "base/time.h"
#include "build/build_config.h"
#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
+#include "content/browser/javascript_dialogs.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
-#include "ui/gfx/native_widget_types.h"
class ExtensionHost;
class NativeAppModalDialog;
@@ -23,28 +23,16 @@ namespace IPC {
class Message;
}
-class JavaScriptAppModalDialogDelegate {
+// Extra data for JavaScript dialogs to add Chrome-only features.
+class ChromeJavaScriptDialogExtraData {
public:
- // AppModalDialog calls this when the dialog is closed.
- virtual void OnMessageBoxClosed(IPC::Message* reply_msg,
- bool success,
- const std::wstring& prompt) = 0;
-
- // Indicates whether additional message boxes should be suppressed.
- virtual void SetSuppressMessageBoxes(bool suppress_message_boxes) = 0;
-
- // Returns the root native window with which the message box is associated.
- virtual gfx::NativeWindow GetMessageBoxRootWindow() = 0;
-
- // Returns the TabContents or ExtensionHost associated with this message
- // box -- in practice, the object implementing this interface. Exactly one
- // of these must be non-NULL; behavior is undefined (read: it'll probably
- // crash) if that is not the case.
- virtual TabContents* AsTabContents() = 0;
- virtual ExtensionHost* AsExtensionHost() = 0;
-
- protected:
- virtual ~JavaScriptAppModalDialogDelegate() {}
+ ChromeJavaScriptDialogExtraData();
+
+ // The time that the last JavaScript dialog was dismissed.
+ base::TimeTicks last_javascript_message_dismissal_;
+
+ // True if the user has decided to block future JavaScript dialogs.
+ bool suppress_javascript_messages_;
};
// A controller + model class for JavaScript alert, confirm, prompt, and
@@ -52,11 +40,12 @@ class JavaScriptAppModalDialogDelegate {
class JavaScriptAppModalDialog : public AppModalDialog,
public NotificationObserver {
public:
- JavaScriptAppModalDialog(JavaScriptAppModalDialogDelegate* delegate,
- const std::wstring& title,
+ JavaScriptAppModalDialog(content::JavaScriptDialogDelegate* delegate,
+ ChromeJavaScriptDialogExtraData* extra_data,
+ const string16& title,
int dialog_flags,
- const std::wstring& message_text,
- const std::wstring& default_prompt_text,
+ const string16& message_text,
+ const string16& default_prompt_text,
bool display_suppress_checkbox,
bool is_before_unload_dialog,
IPC::Message* reply_msg);
@@ -66,11 +55,11 @@ class JavaScriptAppModalDialog : public AppModalDialog,
virtual NativeAppModalDialog* CreateNativeDialog();
virtual bool IsJavaScriptModalDialog();
- JavaScriptAppModalDialogDelegate* delegate() const { return delegate_; }
+ content::JavaScriptDialogDelegate* delegate() const { return delegate_; }
// Callbacks from NativeDialog when the user accepts or cancels the dialog.
void OnCancel(bool suppress_js_messages);
- void OnAccept(const std::wstring& prompt_text, bool suppress_js_messages);
+ void OnAccept(const string16& prompt_text, bool suppress_js_messages);
// NOTE: This is only called under Views, and should be removed. Any critical
// work should be done in OnCancel or OnAccept. See crbug.com/63732 for more.
@@ -82,10 +71,8 @@ class JavaScriptAppModalDialog : public AppModalDialog,
// Accessors
int dialog_flags() const { return dialog_flags_; }
- std::wstring message_text() const { return message_text_; }
- std::wstring default_prompt_text() const {
- return UTF16ToWideHack(default_prompt_text_);
- }
+ string16 message_text() const { return message_text_; }
+ string16 default_prompt_text() const { return default_prompt_text_; }
bool display_suppress_checkbox() const { return display_suppress_checkbox_; }
bool is_before_unload_dialog() const { return is_before_unload_dialog_; }
@@ -99,14 +86,17 @@ class JavaScriptAppModalDialog : public AppModalDialog,
void InitNotifications();
// Notifies the delegate with the result of the dialog.
- void NotifyDelegate(bool success, const std::wstring& prompt_text,
+ void NotifyDelegate(bool success, const string16& prompt_text,
bool suppress_js_messages);
NotificationRegistrar registrar_;
// An implementation of the client interface to provide supporting methods
// and receive results.
- JavaScriptAppModalDialogDelegate* delegate_;
+ content::JavaScriptDialogDelegate* delegate_;
+
+ // The extra Chrome-only data associated with the delegate_.
+ ChromeJavaScriptDialogExtraData* extra_data_;
// The client_ as an ExtensionHost, cached for use during notifications that
// may arrive after the client has entered its destructor (and is thus
@@ -116,7 +106,7 @@ class JavaScriptAppModalDialog : public AppModalDialog,
// Information about the message box is held in the following variables.
int dialog_flags_;
- std::wstring message_text_;
+ string16 message_text_;
string16 default_prompt_text_;
bool display_suppress_checkbox_;
bool is_before_unload_dialog_;
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 0de1b9a..875024a 100644
--- a/chrome/browser/ui/app_modal_dialogs/message_box_handler.cc
+++ b/chrome/browser/ui/app_modal_dialogs/message_box_handler.cc
@@ -1,20 +1,23 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
-#include "base/i18n/rtl.h"
+#include <map>
+
+#include "base/compiler_specific.h"
+#include "base/memory/singleton.h"
+#include "base/time.h"
#include "base/utf_string_conversions.h"
-#include "build/build_config.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 "chrome/common/url_constants.h"
-#include "content/browser/tab_contents/tab_contents.h"
-#include "googleurl/src/gurl.h"
+#include "content/browser/javascript_dialogs.h"
#include "grit/generated_resources.h"
#include "grit/chromium_strings.h"
#include "ui/base/l10n/l10n_util.h"
@@ -22,9 +25,132 @@
#include "ui/base/text/text_elider.h"
#include "ui/gfx/font.h"
-static std::wstring GetTitle(Profile* profile,
- bool is_alert,
- const GURL& frame_url) {
+class ChromeJavaScriptDialogCreator : public content::JavaScriptDialogCreator {
+ public:
+ static ChromeJavaScriptDialogCreator* GetInstance();
+
+ virtual void RunJavaScriptDialog(content::JavaScriptDialogDelegate* delegate,
+ const GURL& frame_url,
+ int dialog_flags,
+ const string16& message_text,
+ const string16& default_prompt_text,
+ IPC::Message* reply_message,
+ bool* did_suppress_message,
+ Profile* profile) OVERRIDE;
+
+ virtual void RunBeforeUnloadDialog(
+ content::JavaScriptDialogDelegate* delegate,
+ const string16& message_text,
+ IPC::Message* reply_message) OVERRIDE;
+
+ virtual void ResetJavaScriptState(
+ content::JavaScriptDialogDelegate* delegate) OVERRIDE;
+
+ private:
+ explicit ChromeJavaScriptDialogCreator();
+ virtual ~ChromeJavaScriptDialogCreator();
+
+ friend struct DefaultSingletonTraits<ChromeJavaScriptDialogCreator>;
+
+ string16 GetTitle(Profile* profile,
+ bool is_alert,
+ const GURL& frame_url);
+
+ // Mapping between the JavaScriptDialogDelegates and their extra data. The key
+ // is a void* because the pointer is just a cookie and is never dereferenced.
+ typedef std::map<void*, ChromeJavaScriptDialogExtraData>
+ JavaScriptDialogExtraDataMap;
+ JavaScriptDialogExtraDataMap javascript_dialog_extra_data_;
+};
+
+//------------------------------------------------------------------------------
+
+ChromeJavaScriptDialogCreator::ChromeJavaScriptDialogCreator() {
+}
+
+ChromeJavaScriptDialogCreator::~ChromeJavaScriptDialogCreator() {
+}
+
+/* static */
+ChromeJavaScriptDialogCreator* ChromeJavaScriptDialogCreator::GetInstance() {
+ return Singleton<ChromeJavaScriptDialogCreator>::get();
+}
+
+void ChromeJavaScriptDialogCreator::RunJavaScriptDialog(
+ content::JavaScriptDialogDelegate* delegate,
+ const GURL& frame_url,
+ int dialog_flags,
+ const string16& message_text,
+ const string16& default_prompt_text,
+ IPC::Message* reply_message,
+ bool* did_suppress_message,
+ Profile* profile) {
+ *did_suppress_message = false;
+
+ ChromeJavaScriptDialogExtraData* extra_data =
+ &javascript_dialog_extra_data_[delegate];
+
+ if (extra_data->suppress_javascript_messages_) {
+ *did_suppress_message = true;
+ return;
+ }
+
+ base::TimeDelta time_since_last_message = base::TimeTicks::Now() -
+ extra_data->last_javascript_message_dismissal_;
+ bool display_suppress_checkbox = false;
+ // Show a checkbox offering to suppress further messages if this message is
+ // being displayed within kJavascriptMessageExpectedDelay of the last one.
+ if (time_since_last_message <
+ base::TimeDelta::FromMilliseconds(
+ chrome::kJavascriptMessageExpectedDelay)) {
+ display_suppress_checkbox = true;
+ }
+
+ bool is_alert = dialog_flags == ui::MessageBoxFlags::kIsJavascriptAlert;
+ string16 title = GetTitle(profile, is_alert, frame_url);
+
+ AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog(
+ delegate,
+ extra_data,
+ title,
+ dialog_flags,
+ message_text,
+ default_prompt_text,
+ display_suppress_checkbox,
+ false, // is_before_unload_dialog
+ reply_message));
+}
+
+void ChromeJavaScriptDialogCreator::RunBeforeUnloadDialog(
+ content::JavaScriptDialogDelegate* delegate,
+ const string16& message_text,
+ IPC::Message* reply_message) {
+ ChromeJavaScriptDialogExtraData* extra_data =
+ &javascript_dialog_extra_data_[delegate];
+
+ string16 full_message = message_text + ASCIIToUTF16("\n\n") +
+ l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER);
+
+ AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog(
+ delegate,
+ extra_data,
+ l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE),
+ ui::MessageBoxFlags::kIsJavascriptConfirm,
+ full_message,
+ string16(), // default_prompt_text
+ false, // display_suppress_checkbox
+ true, // is_before_unload_dialog
+ reply_message));
+}
+
+void ChromeJavaScriptDialogCreator::ResetJavaScriptState(
+ content::JavaScriptDialogDelegate* delegate) {
+ 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 =
@@ -33,15 +159,15 @@ static std::wstring GetTitle(Profile* profile,
extension = extensions_service->GetExtensionByWebExtent(frame_url);
if (extension && (extension->location() == Extension::COMPONENT)) {
- return UTF16ToWideHack(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
+ return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
} else if (extension && !extension->name().empty()) {
- return UTF8ToWide(extension->name());
+ return UTF8ToUTF16(extension->name());
}
}
if (!frame_url.has_host()) {
- return UTF16ToWideHack(l10n_util::GetStringUTF16(
+ return l10n_util::GetStringUTF16(
is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE
- : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE));
+ : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE);
}
// TODO(brettw) it should be easier than this to do the correct language
@@ -53,40 +179,14 @@ static std::wstring GetTitle(Profile* profile,
base_address = base::i18n::GetDisplayStringInLTRDirectionality(
base_address);
- return UTF16ToWide(l10n_util::GetStringFUTF16(
+ return l10n_util::GetStringFUTF16(
is_alert ? IDS_JAVASCRIPT_ALERT_TITLE :
IDS_JAVASCRIPT_MESSAGEBOX_TITLE,
- base_address));
+ base_address);
}
-void RunJavascriptMessageBox(Profile* profile,
- JavaScriptAppModalDialogDelegate* delegate,
- const GURL& frame_url,
- int dialog_flags,
- const std::wstring& message_text,
- const std::wstring& default_prompt_text,
- bool display_suppress_checkbox,
- IPC::Message* reply_msg) {
- bool is_alert = dialog_flags == ui::MessageBoxFlags::kIsJavascriptAlert;
- std::wstring title = GetTitle(profile, is_alert, frame_url);
- AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog(
- delegate, title, dialog_flags, message_text, default_prompt_text,
- display_suppress_checkbox, false, reply_msg));
-}
+//------------------------------------------------------------------------------
-void RunBeforeUnloadDialog(TabContents* tab_contents,
- const std::wstring& message_text,
- IPC::Message* reply_msg) {
- std::wstring full_message = message_text + L"\n\n" + UTF16ToWideHack(
- l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER));
- AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog(
- tab_contents,
- UTF16ToWideHack(
- l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE)),
- ui::MessageBoxFlags::kIsJavascriptConfirm,
- message_text,
- std::wstring(),
- false,
- true,
- reply_msg));
+content::JavaScriptDialogCreator* GetJavaScriptDialogCreatorInstance() {
+ return ChromeJavaScriptDialogCreator::GetInstance();
}
diff --git a/chrome/browser/ui/app_modal_dialogs/message_box_handler.h b/chrome/browser/ui/app_modal_dialogs/message_box_handler.h
index 0acfb14..5d2642a 100644
--- a/chrome/browser/ui/app_modal_dialogs/message_box_handler.h
+++ b/chrome/browser/ui/app_modal_dialogs/message_box_handler.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,36 +6,11 @@
#define CHROME_BROWSER_UI_APP_MODAL_DIALOGS_MESSAGE_BOX_HANDLER_H_
#pragma once
-#include <string>
+namespace content {
+ class JavaScriptDialogCreator;
+}
-#include "ipc/ipc_message.h"
-
-class GURL;
-class JavaScriptAppModalDialogDelegate;
-class TabContents;
-class Profile;
-
-// Creates and runs a Javascript Message Box dialog.
-// The dialog type is specified within |dialog_flags|, the
-// default static display text is in |message_text| and if the dialog box is
-// a user input prompt() box, the default text for the text field is in
-// |default_prompt_text|. The result of the operation is returned using
-// |reply_msg|.
-void RunJavascriptMessageBox(Profile* profile,
- JavaScriptAppModalDialogDelegate* delegate,
- const GURL& frame_url,
- int dialog_flags,
- const std::wstring& message_text,
- const std::wstring& default_prompt_text,
- bool display_suppress_checkbox,
- IPC::Message* reply_msg);
-
-// This will display a modal dialog box with a header and footer asking the
-// the user if they wish to navigate away from a page, with additional text
-// |message_text| between the header and footer. The users response is
-// returned to the renderer using |reply_msg|.
-void RunBeforeUnloadDialog(TabContents* tab_contents,
- const std::wstring& message_text,
- IPC::Message* reply_msg);
+// Returns a JavaScriptDialogCreator that creates real dialogs.
+content::JavaScriptDialogCreator* GetJavaScriptDialogCreatorInstance();
#endif // CHROME_BROWSER_UI_APP_MODAL_DIALOGS_MESSAGE_BOX_HANDLER_H_
diff --git a/chrome/browser/ui/blocked_content/blocked_content_container.cc b/chrome/browser/ui/blocked_content/blocked_content_container.cc
index 09defd8..11204ea 100644
--- a/chrome/browser/ui/blocked_content/blocked_content_container.cc
+++ b/chrome/browser/ui/blocked_content/blocked_content_container.cc
@@ -163,6 +163,12 @@ bool BlockedContentContainer::IsPopup(const TabContents* source) const {
return true;
}
+bool BlockedContentContainer::ShouldSuppressDialogs() {
+ // Suppress JavaScript dialogs when inside a constrained popup window (because
+ // that activates them and breaks them out of the constrained window jail).
+ return true;
+}
+
TabContents* BlockedContentContainer::GetConstrainingContents(
TabContents* source) {
return owner_->tab_contents();
diff --git a/chrome/browser/ui/blocked_content/blocked_content_container.h b/chrome/browser/ui/blocked_content/blocked_content_container.h
index fb41d22..b6ecde9 100644
--- a/chrome/browser/ui/blocked_content/blocked_content_container.h
+++ b/chrome/browser/ui/blocked_content/blocked_content_container.h
@@ -94,6 +94,9 @@ class BlockedContentContainer : public BlockedContentTabHelperDelegate,
// Ignored; BlockedContentContainer doesn't display a URL bar.
virtual void UpdateTargetURL(TabContents* source, const GURL& url) {}
+ // Always returns true.
+ virtual bool ShouldSuppressDialogs();
+
// Maximum number of blocked contents we allow. No page should really need
// this many anyway. If reached it typically means there is a compromised
// renderer.
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index 2a71f6c..e6b402a 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -73,6 +73,7 @@
#include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h"
#include "chrome/browser/tabs/tab_finder.h"
#include "chrome/browser/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
#include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
#include "chrome/browser/ui/browser_dialogs.h"
@@ -3422,6 +3423,10 @@ void Browser::DidNavigateMainFramePostCommit(
}
}
+content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() {
+ return GetJavaScriptDialogCreatorInstance();
+}
+
///////////////////////////////////////////////////////////////////////////////
// Browser, TabContentsWrapperDelegate implementation:
diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h
index f143719..2b41d9e 100644
--- a/chrome/browser/ui/browser.h
+++ b/chrome/browser/ui/browser.h
@@ -851,6 +851,8 @@ class Browser : public TabHandlerDelegate,
virtual void DidNavigateMainFramePostCommit(
TabContents* tab,
const MainFrameCommitDetails& details);
+ virtual content::JavaScriptDialogCreator* GetJavaScriptDialogCreator()
+ OVERRIDE;
// Overridden from TabContentsWrapperDelegate:
virtual void OnDidGetApplicationInfo(TabContentsWrapper* source,
diff --git a/chrome/browser/ui/cocoa/js_modal_dialog_cocoa.mm b/chrome/browser/ui/cocoa/js_modal_dialog_cocoa.mm
index 62825d5..77d8149 100644
--- a/chrome/browser/ui/cocoa/js_modal_dialog_cocoa.mm
+++ b/chrome/browser/ui/cocoa/js_modal_dialog_cocoa.mm
@@ -59,9 +59,9 @@
contextInfo:(void*)contextInfo {
scoped_ptr<JSModalDialogCocoa> native_dialog(
reinterpret_cast<JSModalDialogCocoa*>(contextInfo));
- std::wstring input;
+ string16 input;
if (textField_)
- input = base::SysNSStringToWide([textField_ stringValue]);
+ input = base::SysNSStringToUTF16([textField_ stringValue]);
bool shouldSuppress = false;
if ([alert showsSuppressionButton])
shouldSuppress = [[alert suppressionButton] state] == NSOnState;
@@ -135,12 +135,12 @@ JSModalDialogCocoa::JSModalDialogCocoa(JavaScriptAppModalDialog* dialog)
NSTextField* field = nil;
if (text_field) {
field = [helper_ textField];
- [field setStringValue:base::SysWideToNSString(
+ [field setStringValue:base::SysUTF16ToNSString(
dialog_->default_prompt_text())];
}
[alert_ setDelegate:helper_];
- [alert_ setInformativeText:base::SysWideToNSString(dialog_->message_text())];
- [alert_ setMessageText:base::SysWideToNSString(dialog_->title())];
+ [alert_ setInformativeText:base::SysUTF16ToNSString(dialog_->message_text())];
+ [alert_ setMessageText:base::SysUTF16ToNSString(dialog_->title())];
[alert_ addButtonWithTitle:default_button];
if (!one_button) {
NSButton* other = [alert_ addButtonWithTitle:other_button];
diff --git a/chrome/browser/ui/gtk/js_modal_dialog_gtk.cc b/chrome/browser/ui/gtk/js_modal_dialog_gtk.cc
index dbad866..bb1a71b 100644
--- a/chrome/browser/ui/gtk/js_modal_dialog_gtk.cc
+++ b/chrome/browser/ui/gtk/js_modal_dialog_gtk.cc
@@ -24,12 +24,12 @@ const char kSuppressCheckboxId[] = "chrome_suppress_checkbox";
// If there's a text entry in the dialog, get the text from the first one and
// return it.
-std::wstring GetPromptText(GtkDialog* dialog) {
+string16 GetPromptText(GtkDialog* dialog) {
GtkWidget* widget = static_cast<GtkWidget*>(
g_object_get_data(G_OBJECT(dialog), kPromptTextId));
if (widget)
- return UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(widget)));
- return std::wstring();
+ return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(widget)));
+ return string16();
}
// If there's a toggle button in the dialog, return the toggled state.
@@ -87,12 +87,12 @@ JSModalDialogGtk::JSModalDialogGtk(JavaScriptAppModalDialog* dialog,
gtk_dialog_ = gtk_message_dialog_new(parent_window,
GTK_DIALOG_MODAL, message_type, buttons, "%s",
- WideToUTF8(dialog_->message_text()).c_str());
+ UTF16ToUTF8(dialog_->message_text()).c_str());
g_signal_connect(gtk_dialog_, "delete-event",
G_CALLBACK(gtk_widget_hide_on_delete), NULL);
gtk_util::ApplyMessageDialogQuirks(gtk_dialog_);
gtk_window_set_title(GTK_WINDOW(gtk_dialog_),
- WideToUTF8(dialog_->title()).c_str());
+ UTF16ToUTF8(dialog_->title()).c_str());
// Adjust content area as needed. Set up the prompt text entry or
// suppression check box.
@@ -101,7 +101,7 @@ JSModalDialogGtk::JSModalDialogGtk(JavaScriptAppModalDialog* dialog,
GtkWidget* contents_vbox = GTK_DIALOG(gtk_dialog_)->vbox;
GtkWidget* text_box = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(text_box),
- WideToUTF8(dialog_->default_prompt_text()).c_str());
+ UTF16ToUTF8(dialog_->default_prompt_text()).c_str());
gtk_box_pack_start(GTK_BOX(contents_vbox), text_box, TRUE, TRUE, 0);
g_object_set_data(G_OBJECT(gtk_dialog_), kPromptTextId, text_box);
gtk_entry_set_activates_default(GTK_ENTRY(text_box), TRUE);
diff --git a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc
index 42ad68d..c836bf0 100644
--- a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc
+++ b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc
@@ -10,6 +10,7 @@
#include "base/i18n/rtl.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/gtk/browser_window_gtk.h"
#include "chrome/browser/ui/gtk/gtk_util.h"
@@ -180,6 +181,11 @@ void DraggedTabControllerGtk::UpdateTargetURL(TabContents* source,
// Ignored.
}
+content::JavaScriptDialogCreator*
+DraggedTabControllerGtk::GetJavaScriptDialogCreator() {
+ return GetJavaScriptDialogCreatorInstance();
+}
+
////////////////////////////////////////////////////////////////////////////////
// DraggedTabControllerGtk, NotificationObserver implementation:
diff --git a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h
index f12e0df..5249a18 100644
--- a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h
+++ b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h
@@ -89,6 +89,8 @@ class DraggedTabControllerGtk : public NotificationObserver,
virtual void MoveContents(TabContents* source, const gfx::Rect& pos);
virtual bool IsPopup(const TabContents* source) const;
virtual void UpdateTargetURL(TabContents* source, const GURL& url);
+ virtual content::JavaScriptDialogCreator* GetJavaScriptDialogCreator()
+ OVERRIDE;
// Overridden from NotificationObserver:
virtual void Observe(NotificationType type,
diff --git a/chrome/browser/ui/views/html_dialog_view_browsertest.cc b/chrome/browser/ui/views/html_dialog_view_browsertest.cc
index 1d351c0..8ec8681 100644
--- a/chrome/browser/ui/views/html_dialog_view_browsertest.cc
+++ b/chrome/browser/ui/views/html_dialog_view_browsertest.cc
@@ -131,7 +131,7 @@ IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, MAYBE_SizeWindow) {
new HtmlDialogView(browser()->profile(), delegate);
TabContents* tab_contents = browser()->GetSelectedTabContents();
ASSERT_TRUE(tab_contents != NULL);
- views::Window::CreateChromeWindow(tab_contents->GetMessageBoxRootWindow(),
+ views::Window::CreateChromeWindow(tab_contents->GetDialogRootWindow(),
gfx::Rect(), html_view);
html_view->InitDialog();
html_view->window()->Show();
diff --git a/chrome/browser/ui/views/js_modal_dialog_views.cc b/chrome/browser/ui/views/js_modal_dialog_views.cc
index 6bccb5d..4f3f472 100644
--- a/chrome/browser/ui/views/js_modal_dialog_views.cc
+++ b/chrome/browser/ui/views/js_modal_dialog_views.cc
@@ -23,7 +23,8 @@ JSModalDialogViews::JSModalDialogViews(
: parent_(parent),
message_box_view_(new views::MessageBoxView(
parent->dialog_flags() | ui::MessageBoxFlags::kAutoDetectAlignment,
- parent->message_text(), parent->default_prompt_text())) {
+ UTF16ToWideHack(parent->message_text()),
+ UTF16ToWideHack(parent->default_prompt_text()))) {
DCHECK(message_box_view_);
message_box_view_->AddAccelerator(
@@ -90,7 +91,7 @@ int JSModalDialogViews::GetDialogButtons() const {
}
std::wstring JSModalDialogViews::GetWindowTitle() const {
- return parent_->title();
+ return UTF16ToWideHack(parent_->title());
}
@@ -108,7 +109,7 @@ bool JSModalDialogViews::Cancel() {
}
bool JSModalDialogViews::Accept() {
- parent_->OnAccept(message_box_view_->GetInputText(),
+ parent_->OnAccept(WideToUTF16Hack(message_box_view_->GetInputText()),
message_box_view_->IsCheckBoxSelected());
return true;
}
diff --git a/chrome/browser/ui/views/ssl_client_certificate_selector_win.cc b/chrome/browser/ui/views/ssl_client_certificate_selector_win.cc
index e738d6c..bee7774 100644
--- a/chrome/browser/ui/views/ssl_client_certificate_selector_win.cc
+++ b/chrome/browser/ui/views/ssl_client_certificate_selector_win.cc
@@ -46,7 +46,7 @@ void ShowSSLClientCertificateSelector(
IDS_CLIENT_CERT_DIALOG_TEXT,
ASCIIToUTF16(cert_request_info->host_and_port)));
PCCERT_CONTEXT cert_context = CryptUIDlgSelectCertificateFromStore(
- client_certs, parent->GetMessageBoxRootWindow(),
+ client_certs, parent->GetDialogRootWindow(),
title.c_str(), text.c_str(), 0, 0, NULL);
net::X509Certificate* cert = NULL;
diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.cc
index 2840a8b..dd8fe8c 100644
--- a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.cc
+++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.h"
+#include "base/utf_string_conversions.h"
#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
#include "chrome/browser/tab_contents/web_drag_dest_gtk.h"
#include "chrome/browser/ui/gtk/constrained_window_gtk.h"
diff --git a/chrome/browser/ui/views/tabs/dragged_tab_controller.cc b/chrome/browser/ui/views/tabs/dragged_tab_controller.cc
index 2ffa620..88c5086 100644
--- a/chrome/browser/ui/views/tabs/dragged_tab_controller.cc
+++ b/chrome/browser/ui/views/tabs/dragged_tab_controller.cc
@@ -11,6 +11,7 @@
#include "base/i18n/rtl.h"
#include "chrome/browser/extensions/extension_function_dispatcher.h"
#include "chrome/browser/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/tabs/base_tab.h"
@@ -488,6 +489,11 @@ bool DraggedTabController::ShouldSuppressDialogs() {
return false;
}
+content::JavaScriptDialogCreator*
+DraggedTabController::GetJavaScriptDialogCreator() {
+ return GetJavaScriptDialogCreatorInstance();
+}
+
///////////////////////////////////////////////////////////////////////////////
// DraggedTabController, NotificationObserver implementation:
diff --git a/chrome/browser/ui/views/tabs/dragged_tab_controller.h b/chrome/browser/ui/views/tabs/dragged_tab_controller.h
index 55289b1..9023a2b 100644
--- a/chrome/browser/ui/views/tabs/dragged_tab_controller.h
+++ b/chrome/browser/ui/views/tabs/dragged_tab_controller.h
@@ -148,6 +148,8 @@ class DraggedTabController : public TabContentsDelegate,
const gfx::Rect& pos) OVERRIDE;
virtual void UpdateTargetURL(TabContents* source, const GURL& url) OVERRIDE;
virtual bool ShouldSuppressDialogs() OVERRIDE;
+ virtual content::JavaScriptDialogCreator* GetJavaScriptDialogCreator()
+ OVERRIDE;
// Overridden from NotificationObserver:
virtual void Observe(NotificationType type,
diff --git a/chrome/browser/ui/web_applications/web_app_ui.cc b/chrome/browser/ui/web_applications/web_app_ui.cc
index b125963..b7a68b4 100644
--- a/chrome/browser/ui/web_applications/web_app_ui.cc
+++ b/chrome/browser/ui/web_applications/web_app_ui.cc
@@ -7,6 +7,7 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/task.h"
+#include "base/utf_string_conversions.h"
#include "base/win/windows_version.h"
#include "chrome/browser/extensions/extension_tab_helper.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
diff --git a/chrome/browser/ui/webui/flags_ui.cc b/chrome/browser/ui/webui/flags_ui.cc
index 5ba870d..49dc9a6 100644
--- a/chrome/browser/ui/webui/flags_ui.cc
+++ b/chrome/browser/ui/webui/flags_ui.cc
@@ -7,6 +7,7 @@
#include <string>
#include "base/memory/singleton.h"
+#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/about_flags.h"
#include "chrome/browser/browser_process.h"
diff --git a/chrome/browser/ui/webui/flash_ui.cc b/chrome/browser/ui/webui/flash_ui.cc
index f1dbcce..644fd5a 100644
--- a/chrome/browser/ui/webui/flash_ui.cc
+++ b/chrome/browser/ui/webui/flash_ui.cc
@@ -7,6 +7,7 @@
#include "base/i18n/time_formatting.h"
#include "base/string_number_conversions.h"
#include "base/threading/thread_restrictions.h"
+#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/crash_upload_list.h"
#include "chrome/browser/platform_util.h"
diff --git a/chrome/browser/ui/webui/options/advanced_options_handler.cc b/chrome/browser/ui/webui/options/advanced_options_handler.cc
index c85e197a..d8a6906 100644
--- a/chrome/browser/ui/webui/options/advanced_options_handler.cc
+++ b/chrome/browser/ui/webui/options/advanced_options_handler.cc
@@ -465,7 +465,7 @@ void AdvancedOptionsHandler::ShowCloudPrintSetupDialog(const ListValue* args) {
cloud_print_setup_handler_.reset(new CloudPrintSetupHandler(this));
CloudPrintSetupFlow::OpenDialog(
web_ui_->GetProfile(), cloud_print_setup_handler_->AsWeakPtr(),
- web_ui_->tab_contents()->GetMessageBoxRootWindow());
+ web_ui_->tab_contents()->GetDialogRootWindow());
}
void AdvancedOptionsHandler::HandleDisableCloudPrintProxy(
diff --git a/chrome/browser/ui/webui/textfields_ui.cc b/chrome/browser/ui/webui/textfields_ui.cc
index a87f90d..2f43a0b 100644
--- a/chrome/browser/ui/webui/textfields_ui.cc
+++ b/chrome/browser/ui/webui/textfields_ui.cc
@@ -9,6 +9,7 @@
#include "base/memory/singleton.h"
#include "base/string_piece.h"
+#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/jstemplate_builder.h"
diff --git a/chrome/browser/ui/webui/web_ui_browsertest.cc b/chrome/browser/ui/webui/web_ui_browsertest.cc
index 026c77d..3817612 100644
--- a/chrome/browser/ui/webui/web_ui_browsertest.cc
+++ b/chrome/browser/ui/webui/web_ui_browsertest.cc
@@ -7,6 +7,7 @@
#include <vector>
#include "base/path_service.h"
+#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_paths.h"