summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authorzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 22:32:14 +0000
committerzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 22:32:14 +0000
commit12f74a94c21e19c74208dacf1dc5ef46f8a27f53 (patch)
treed10fe102066ab8b0a437b18ffc70aa228d02ba4e /chrome/browser/views
parent225c8f507421a2eff2ed7a900104431d04ed7e5e (diff)
downloadchromium_src-12f74a94c21e19c74208dacf1dc5ef46f8a27f53.zip
chromium_src-12f74a94c21e19c74208dacf1dc5ef46f8a27f53.tar.gz
chromium_src-12f74a94c21e19c74208dacf1dc5ef46f8a27f53.tar.bz2
Refactored out JS specific part of modal dialog stack into its own class, exposed cookie/storage prompt as a modal dialog.
BUG=32719 TEST=none, requires Darin to hook this with his code. Review URL: http://codereview.chromium.org/560030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38268 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/cookie_info_view.cc35
-rw-r--r--chrome/browser/views/cookie_info_view.h4
-rw-r--r--chrome/browser/views/cookie_prompt_view.cc132
-rw-r--r--chrome/browser/views/cookie_prompt_view.h81
-rw-r--r--chrome/browser/views/jsmessage_box_dialog.cc57
-rw-r--r--chrome/browser/views/jsmessage_box_dialog.h29
-rw-r--r--chrome/browser/views/modal_dialog_delegate.cc37
-rw-r--r--chrome/browser/views/modal_dialog_delegate.h32
8 files changed, 237 insertions, 170 deletions
diff --git a/chrome/browser/views/cookie_info_view.cc b/chrome/browser/views/cookie_info_view.cc
index a0cfb3e..da51988 100644
--- a/chrome/browser/views/cookie_info_view.cc
+++ b/chrome/browser/views/cookie_info_view.cc
@@ -89,6 +89,41 @@ void CookieInfoView::SetCookie(
Layout();
}
+void CookieInfoView::SetCookieString(
+ const std::string& domain,
+ const net::CookieMonster::ParsedCookie& cookie) {
+ name_value_field_->SetText(UTF8ToWide(cookie.Name()));
+ content_value_field_->SetText(UTF8ToWide(cookie.Value()));
+ domain_value_field_->SetText(UTF8ToWide(domain));
+ path_value_field_->SetText(UTF8ToWide(cookie.Path()));
+ created_value_field_->SetText(
+ base::TimeFormatFriendlyDateAndTime(base::Time::Now()));
+
+ std::wstring expire_text = cookie.HasExpires() ?
+ base::TimeFormatFriendlyDateAndTime(
+ net::CookieMonster::ParseCookieTime(cookie.Expires())) :
+ l10n_util::GetString(IDS_COOKIES_COOKIE_EXPIRES_SESSION);
+
+ if (editable_expiration_date_) {
+ expire_combo_values_.clear();
+ if (cookie.HasExpires())
+ expire_combo_values_.push_back(expire_text);
+ expire_combo_values_.push_back(
+ l10n_util::GetString(IDS_COOKIES_COOKIE_EXPIRES_SESSION));
+ expires_value_combobox_->ModelChanged();
+ expires_value_combobox_->SetSelectedItem(0);
+ expires_value_combobox_->SetEnabled(true);
+ } else {
+ expires_value_field_->SetText(expire_text);
+ }
+
+ send_for_value_field_->SetText(cookie.IsSecure() ?
+ l10n_util::GetString(IDS_COOKIES_COOKIE_SENDFOR_SECURE) :
+ l10n_util::GetString(IDS_COOKIES_COOKIE_SENDFOR_ANY));
+ EnableCookieDisplay(true);
+ Layout();
+}
+
void CookieInfoView::ClearCookieDisplay() {
std::wstring no_cookie_string =
diff --git a/chrome/browser/views/cookie_info_view.h b/chrome/browser/views/cookie_info_view.h
index 5846146..b0be231 100644
--- a/chrome/browser/views/cookie_info_view.h
+++ b/chrome/browser/views/cookie_info_view.h
@@ -47,6 +47,10 @@ class CookieInfoView : public views::View,
void SetCookie(const std::string& domain,
const net::CookieMonster::CanonicalCookie& cookie_node);
+ // Update the display from the specified cookie string.
+ void SetCookieString(const std::string& domain,
+ const net::CookieMonster::ParsedCookie& cookie);
+
// Clears the cookie display to indicate that no or multiple cookies are
// selected.
void ClearCookieDisplay();
diff --git a/chrome/browser/views/cookie_prompt_view.cc b/chrome/browser/views/cookie_prompt_view.cc
index b65d221..d08fb49 100644
--- a/chrome/browser/views/cookie_prompt_view.cc
+++ b/chrome/browser/views/cookie_prompt_view.cc
@@ -12,6 +12,7 @@
#include "base/i18n/time_formatting.h"
#include "base/message_loop.h"
#include "base/string_util.h"
+#include "chrome/browser/cookie_modal_dialog.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/views/cookie_info_view.h"
#include "chrome/browser/views/local_storage_info_view.h"
@@ -30,100 +31,94 @@
static const int kCookiePromptViewInsetSize = 5;
///////////////////////////////////////////////////////////////////////////////
-// CookiesPromptView, public:
-
-// static
-void CookiesPromptView::ShowCookiePromptWindow(
- gfx::NativeWindow parent,
- Profile* profile,
- const std::string& domain,
- const net::CookieMonster::CanonicalCookie& cookie,
- CookiesPromptViewDelegate* delegate) {
- CookiesPromptView* cookies_view = new CookiesPromptView(profile, delegate);
- cookies_view->SetCookie(domain, cookie);
- views::Window::CreateChromeWindow(parent,
- gfx::Rect(),
- cookies_view)->Show();
-}
-
-// static
-void CookiesPromptView::ShowLocalStoragePromptWindow(
- gfx::NativeWindow parent,
- Profile* profile,
- const std::string& domain,
- const BrowsingDataLocalStorageHelper::LocalStorageInfo& local_storage_info,
- CookiesPromptViewDelegate* delegate) {
- CookiesPromptView* cookies_view = new CookiesPromptView(profile, delegate);
- cookies_view->SetLocalStorage(domain, local_storage_info);
- views::Window::CreateChromeWindow(parent,
- gfx::Rect(),
- cookies_view)->Show();
-}
-
-
-CookiesPromptView::~CookiesPromptView() {
-}
-
-void CookiesPromptView::SetCookie(
- const std::string& domain,
- const net::CookieMonster::CanonicalCookie& cookie) {
+// CookiePromptView, public:
+
+CookiePromptView::CookiePromptView(
+ CookiePromptModalDialog* parent,
+ gfx::NativeWindow root_window,
+ Profile* profile,
+ const GURL& url,
+ const std::string& cookie_line,
+ CookiePromptModalDialogDelegate* delegate)
+ : parent_(parent),
+ root_window_(root_window),
+ profile_(profile),
+ delegate_(delegate) {
cookie_ui_ = true;
- InitializeViewResources(domain);
- cookie_ = cookie;
+ net::CookieMonster::ParsedCookie cookie(cookie_line);
+ InitializeViewResources(cookie.HasDomain() ? cookie.Domain() : url.host());
}
-void CookiesPromptView::SetLocalStorage(
- const std::string& domain,
- const BrowsingDataLocalStorageHelper::LocalStorageInfo storage_info) {
+CookiePromptView::CookiePromptView(
+ CookiePromptModalDialog* parent,
+ gfx::NativeWindow root_window,
+ Profile* profile,
+ const BrowsingDataLocalStorageHelper::LocalStorageInfo& storage_info,
+ CookiePromptModalDialogDelegate* delegate)
+ : parent_(parent),
+ root_window_(root_window),
+ profile_(profile),
+ local_storage_info_(storage_info),
+ delegate_(delegate) {
cookie_ui_ = false;
- InitializeViewResources(domain);
- local_storage_info_ = storage_info;
+ InitializeViewResources(storage_info.host);
+}
+
+CookiePromptView::~CookiePromptView() {
}
///////////////////////////////////////////////////////////////////////////////
-// CookiesPromptView, views::View overrides:
+// CookiePromptView, views::View overrides:
-gfx::Size CookiesPromptView::GetPreferredSize() {
+gfx::Size CookiePromptView::GetPreferredSize() {
gfx::Size client_size = views::View::GetPreferredSize();
return gfx::Size(client_size.width(),
client_size.height() + GetExtendedViewHeight());
}
-void CookiesPromptView::ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child) {
+void CookiePromptView::ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child) {
if (is_add && child == this)
Init();
}
///////////////////////////////////////////////////////////////////////////////
-// CookiesPromptView, views::DialogDelegate implementation:
+// CookiePromptView, ModalDialogDelegate implementation:
+
+gfx::NativeWindow CookiePromptView::GetDialogRootWindow() {
+ return root_window_;
+}
-std::wstring CookiesPromptView::GetWindowTitle() const {
+///////////////////////////////////////////////////////////////////////////////
+// CookiePromptView, views::DialogDelegate implementation:
+
+std::wstring CookiePromptView::GetWindowTitle() const {
return title_;
}
-void CookiesPromptView::WindowClosing() {
+void CookiePromptView::WindowClosing() {
if (!signaled_ && delegate_)
delegate_->BlockSiteData(false);
+ parent_->CompleteDialog();
}
-views::View* CookiesPromptView::GetContentsView() {
+views::View* CookiePromptView::GetContentsView() {
return this;
}
// CookieInfoViewDelegate overrides:
-void CookiesPromptView::ModifyExpireDate(bool session_expire) {
+void CookiePromptView::ModifyExpireDate(bool session_expire) {
session_expire_ = session_expire;
}
///////////////////////////////////////////////////////////////////////////////
-// CookiesPromptView, views::ButtonListener implementation:
+// CookiePromptView, views::ButtonListener implementation:
-void CookiesPromptView::ButtonPressed(views::Button* sender,
- const views::Event& event) {
+void CookiePromptView::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
if (sender == allow_button_) {
if (delegate_) {
delegate_->AllowSiteData(remember_radio_->checked(), session_expire_);
@@ -140,8 +135,8 @@ void CookiesPromptView::ButtonPressed(views::Button* sender,
}
///////////////////////////////////////////////////////////////////////////////
-// CookiesPromptView, views::LinkController implementation:
-void CookiesPromptView::LinkActivated(views::Link* source, int event_flags) {
+// CookiePromptView, views::LinkController implementation:
+void CookiePromptView::LinkActivated(views::Link* source, int event_flags) {
if (source == show_cookie_link_)
ToggleDetailsViewExpand();
else if (source == manage_cookies_link_)
@@ -151,10 +146,10 @@ void CookiesPromptView::LinkActivated(views::Link* source, int event_flags) {
}
///////////////////////////////////////////////////////////////////////////////
-// CookiesPromptView, private:
+// CookiePromptView, private:
-CookiesPromptView::CookiesPromptView(Profile* profile,
- CookiesPromptViewDelegate* delegate)
+CookiePromptView::CookiePromptView(Profile* profile,
+ CookiePromptModalDialogDelegate* delegate)
: remember_radio_(NULL),
ask_radio_(NULL),
allow_button_(NULL),
@@ -169,7 +164,7 @@ CookiesPromptView::CookiesPromptView(Profile* profile,
profile_(profile) {
}
-void CookiesPromptView::Init() {
+void CookiePromptView::Init() {
views::Label* description_label = new views::Label(l10n_util::GetStringF(
cookie_ui_ ? IDS_COOKIE_ALERT_LABEL : IDS_DATA_ALERT_LABEL,
display_domain_));
@@ -267,7 +262,8 @@ void CookiesPromptView::Init() {
cookie_info_view->set_delegate(this);
layout->AddView(cookie_info_view, 1, 1, GridLayout::FILL,
GridLayout::CENTER);
- cookie_info_view->SetCookie(domain_, cookie_);
+
+ cookie_info_view->SetCookieString(domain_, cookie_line_);
info_view_ = cookie_info_view;
} else {
LocalStorageInfoView* local_storage_info_view = new LocalStorageInfoView();
@@ -282,13 +278,13 @@ void CookiesPromptView::Init() {
ask_radio_->SetChecked(true);
}
-int CookiesPromptView::GetExtendedViewHeight() {
+int CookiePromptView::GetExtendedViewHeight() {
DCHECK(info_view_);
return expanded_view_ ?
kRelatedControlVerticalSpacing : -info_view_->GetPreferredSize().height();
}
-void CookiesPromptView::ToggleDetailsViewExpand() {
+void CookiePromptView::ToggleDetailsViewExpand() {
expanded_view_ = !expanded_view_;
views::Window* parent = GetWindow();
gfx::Size non_client_size = parent->GetNonClientView()->GetPreferredSize();
@@ -300,11 +296,11 @@ void CookiesPromptView::ToggleDetailsViewExpand() {
Layout();
}
-void CookiesPromptView::InitializeViewResources(const std::string& domain) {
+void CookiePromptView::InitializeViewResources(const std::string& domain) {
domain_ = domain;
std::string display_domain = domain;
if (!domain.empty() && domain[0] == '.')
- display_domain = display_domain.substr(1);
+ display_domain = display_domain.substr(1);
display_domain_ = UTF8ToWide(display_domain);
title_ = l10n_util::GetStringF(
cookie_ui_ ? IDS_COOKIE_ALERT_TITLE : IDS_DATA_ALERT_TITLE,
diff --git a/chrome/browser/views/cookie_prompt_view.h b/chrome/browser/views/cookie_prompt_view.h
index 1dc5e9d..756687e 100644
--- a/chrome/browser/views/cookie_prompt_view.h
+++ b/chrome/browser/views/cookie_prompt_view.h
@@ -9,8 +9,10 @@
#include "base/task.h"
#include "chrome/browser/browsing_data_local_storage_helper.h"
+#include "chrome/browser/cookie_prompt_modal_dialog_delegate.h"
#include "chrome/browser/views/cookie_info_view.h"
-#include "net/base/cookie_monster.h"
+#include "chrome/browser/views/modal_dialog_delegate.h"
+#include "googleurl/src/gurl.h"
#include "views/controls/button/button.h"
#include "views/controls/link.h"
#include "views/view.h"
@@ -23,56 +25,36 @@ class RadioButton;
}
class CookieInfoView;
+class CookiePromptModalDialog;
class LocalStorageInfoView;
class Profile;
class Timer;
-class CookiesPromptViewDelegate {
- public:
- // Allow site data to be set. If |remember| is true, record this decision
- // for this host.
- virtual void AllowSiteData(bool remember, bool session_expire) = 0;
-
- // Block site data from being stored. If |remember| is true, record this
- // decision for this host.
- virtual void BlockSiteData(bool remember) = 0;
-
- protected:
- virtual ~CookiesPromptViewDelegate() {}
-};
-
// Cookie alert dialog UI.
-class CookiesPromptView : public views::View,
- public views::DialogDelegate,
+class CookiePromptView : public views::View,
+ public ModalDialogDelegate,
public views::ButtonListener,
public views::LinkController,
public CookieInfoViewDelegate {
public:
// Show the Cookies Window, creating one if necessary.
- static void ShowCookiePromptWindow(
- gfx::NativeWindow parent,
+ CookiePromptView(
+ CookiePromptModalDialog* parent,
+ gfx::NativeWindow root_window,
Profile* profile,
- const std::string& domain,
- const net::CookieMonster::CanonicalCookie& cookie,
- CookiesPromptViewDelegate* delegate);
+ const GURL& url,
+ const std::string& cookie_line,
+ CookiePromptModalDialogDelegate* delegate);
- static void CookiesPromptView::ShowLocalStoragePromptWindow(
- gfx::NativeWindow parent,
+ CookiePromptView(
+ CookiePromptModalDialog* parent,
+ gfx::NativeWindow root_window,
Profile* profile,
- const std::string& domain,
const BrowsingDataLocalStorageHelper::LocalStorageInfo&
local_storage_info,
- CookiesPromptViewDelegate* delegate);
-
- virtual ~CookiesPromptView();
-
- // Initializes component for displaying cookie information.
- void SetCookie(const std::string& domain,
- const net::CookieMonster::CanonicalCookie& cookie_node);
+ CookiePromptModalDialogDelegate* delegate);
- // Initializes component for displaying locale storage information.
- void SetLocalStorage(const std::string& domain,
- const BrowsingDataLocalStorageHelper::LocalStorageInfo);
+ virtual ~CookiePromptView();
protected:
// views::View overrides.
@@ -81,11 +63,15 @@ class CookiesPromptView : public views::View,
views::View* parent,
views::View* child);
+ // ModalDialogDelegate overrides.
+ virtual gfx::NativeWindow GetDialogRootWindow();
+
// views::DialogDelegate overrides.
virtual bool CanResize() const { return false; }
virtual std::wstring GetWindowTitle() const;
virtual void WindowClosing();
virtual views::View* GetContentsView();
+ virtual bool IsModal() const { return true; }
// views::ButtonListener overrides.
virtual void ButtonPressed(views::Button* sender, const views::Event& event);
@@ -103,8 +89,8 @@ class CookiesPromptView : public views::View,
private:
// Use the static factory method to show.
- explicit CookiesPromptView(Profile* profile,
- CookiesPromptViewDelegate* delegate);
+ explicit CookiePromptView(Profile* profile,
+ CookiePromptModalDialogDelegate* delegate);
// Initialize the dialog layout.
void Init();
@@ -141,24 +127,29 @@ class CookiesPromptView : public views::View,
// Whether we're showing cookie UI as opposed to other site data.
bool cookie_ui_;
- CookiesPromptViewDelegate* delegate_;
+ // A pointer to the AppModalDialog that owns us.
+ CookiePromptModalDialog* parent_;
+
+ gfx::NativeWindow root_window_;
- // Cookie domain.
+ // The Profile for which Cookies are displayed.
+ Profile* profile_;
+
+ // Cookie / local storage domain.
std::string domain_;
- // Cookie domain formatted for displaying (removed leading '.').
+ // Domain name formatted for displaying (removed leading '.').
std::wstring display_domain_;
- // Displayed cookie. Only used when |cookie_ui_| is true.
- net::CookieMonster::CanonicalCookie cookie_;
+ // Displayed cookie. Only used when |cookie_ui_| is true.
+ std::string cookie_line_;
// Displayed local storage info. Only used when |cookie_ui_| is false.
BrowsingDataLocalStorageHelper::LocalStorageInfo local_storage_info_;
- // The Profile for which Cookies are displayed.
- Profile* profile_;
+ CookiePromptModalDialogDelegate* delegate_;
- DISALLOW_COPY_AND_ASSIGN(CookiesPromptView);
+ DISALLOW_COPY_AND_ASSIGN(CookiePromptView);
};
#endif // CHROME_BROWSER_VIEWS_COOKIE_PROMPT_VIEW_H_
diff --git a/chrome/browser/views/jsmessage_box_dialog.cc b/chrome/browser/views/jsmessage_box_dialog.cc
index b83242f..9e78f1d 100644
--- a/chrome/browser/views/jsmessage_box_dialog.cc
+++ b/chrome/browser/views/jsmessage_box_dialog.cc
@@ -13,13 +13,12 @@
#include "views/controls/message_box_view.h"
#include "views/window/window.h"
-JavascriptMessageBoxDialog::JavascriptMessageBoxDialog(
- AppModalDialog* parent,
+JavaScriptMessageBoxDialog::JavaScriptMessageBoxDialog(
+ JavaScriptAppModalDialog* parent,
const std::wstring& message_text,
const std::wstring& default_prompt_text,
bool display_suppress_checkbox)
: parent_(parent),
- dialog_(NULL),
message_box_view_(new MessageBoxView(
parent->dialog_flags() | MessageBoxFlags::kAutoDetectAlignment,
message_text, default_prompt_text)) {
@@ -33,39 +32,17 @@ JavascriptMessageBoxDialog::JavascriptMessageBoxDialog(
}
}
-JavascriptMessageBoxDialog::~JavascriptMessageBoxDialog() {
+JavaScriptMessageBoxDialog::~JavaScriptMessageBoxDialog() {
}
-void JavascriptMessageBoxDialog::ShowModalDialog() {
- gfx::NativeWindow root_hwnd = client()->GetMessageBoxRootWindow();
- // GetMessageBoxRootWindow() will be NULL if there's no selected tab (e.g.,
- // during shutdown), in which case we simply skip showing this dialog.
- if (!root_hwnd) {
- Cancel();
- } else {
- dialog_ = views::Window::CreateChromeWindow(root_hwnd, gfx::Rect(), this);
- dialog_->Show();
- }
-}
-
-void JavascriptMessageBoxDialog::ActivateModalDialog() {
- // Ensure that the dialog is visible and at the top of the z-order. These
- // conditions may not be true if the dialog was opened on a different virtual
- // desktop to the one the browser window is on.
- dialog_->Show();
- dialog_->Activate();
-}
-
-void JavascriptMessageBoxDialog::CloseModalDialog() {
- // If the dialog is visible close it.
- if (dialog_)
- dialog_->Close();
+gfx::NativeWindow JavaScriptMessageBoxDialog::GetDialogRootWindow() {
+ return client()->GetMessageBoxRootWindow();
}
//////////////////////////////////////////////////////////////////////////////
-// JavascriptMessageBoxDialog, views::DialogDelegate implementation:
+// JavaScriptMessageBoxDialog, views::DialogDelegate implementation:
-int JavascriptMessageBoxDialog::GetDialogButtons() const {
+int JavaScriptMessageBoxDialog::GetDialogButtons() const {
int dialog_buttons = 0;
if (parent_->dialog_flags() & MessageBoxFlags::kFlagHasOKButton)
dialog_buttons = MessageBoxFlags::DIALOGBUTTON_OK;
@@ -76,36 +53,36 @@ int JavascriptMessageBoxDialog::GetDialogButtons() const {
return dialog_buttons;
}
-std::wstring JavascriptMessageBoxDialog::GetWindowTitle() const {
+std::wstring JavaScriptMessageBoxDialog::GetWindowTitle() const {
return parent_->title();
}
-void JavascriptMessageBoxDialog::WindowClosing() {
+void JavaScriptMessageBoxDialog::WindowClosing() {
dialog_ = NULL;
}
-void JavascriptMessageBoxDialog::DeleteDelegate() {
+void JavaScriptMessageBoxDialog::DeleteDelegate() {
delete parent_;
delete this;
}
-bool JavascriptMessageBoxDialog::Cancel() {
+bool JavaScriptMessageBoxDialog::Cancel() {
parent_->OnCancel();
return true;
}
-bool JavascriptMessageBoxDialog::Accept() {
+bool JavaScriptMessageBoxDialog::Accept() {
parent_->OnAccept(message_box_view_->GetInputText(),
message_box_view_->IsCheckBoxSelected());
return true;
}
-void JavascriptMessageBoxDialog::OnClose() {
+void JavaScriptMessageBoxDialog::OnClose() {
parent_->OnClose();
}
-std::wstring JavascriptMessageBoxDialog::GetDialogButtonLabel(
+std::wstring JavaScriptMessageBoxDialog::GetDialogButtonLabel(
MessageBoxFlags::DialogButton button) const {
if (parent_->is_before_unload_dialog()) {
if (button == MessageBoxFlags::DIALOGBUTTON_OK) {
@@ -119,13 +96,13 @@ std::wstring JavascriptMessageBoxDialog::GetDialogButtonLabel(
}
///////////////////////////////////////////////////////////////////////////////
-// JavascriptMessageBoxDialog, views::WindowDelegate implementation:
+// JavaScriptMessageBoxDialog, views::WindowDelegate implementation:
-views::View* JavascriptMessageBoxDialog::GetContentsView() {
+views::View* JavaScriptMessageBoxDialog::GetContentsView() {
return message_box_view_;
}
-views::View* JavascriptMessageBoxDialog::GetInitiallyFocusedView() {
+views::View* JavaScriptMessageBoxDialog::GetInitiallyFocusedView() {
if (message_box_view_->text_box())
return message_box_view_->text_box();
return views::DialogDelegate::GetInitiallyFocusedView();
diff --git a/chrome/browser/views/jsmessage_box_dialog.h b/chrome/browser/views/jsmessage_box_dialog.h
index 92a2635..62fcf51 100644
--- a/chrome/browser/views/jsmessage_box_dialog.h
+++ b/chrome/browser/views/jsmessage_box_dialog.h
@@ -5,30 +5,28 @@
#ifndef CHROME_BROWSER_VIEWS_JSMESSAGE_BOX_DIALOG_H_
#define CHROME_BROWSER_VIEWS_JSMESSAGE_BOX_DIALOG_H_
+#include "chrome/browser/js_modal_dialog.h"
+
#include <string>
-#include "chrome/browser/app_modal_dialog.h"
-#include "views/window/dialog_delegate.h"
+#include "app/message_box_flags.h"
+#include "chrome/browser/jsmessage_box_client.h"
+#include "chrome/browser/views/modal_dialog_delegate.h"
class MessageBoxView;
class JavaScriptMessageBoxClient;
-namespace views {
-class Window;
-}
-class JavascriptMessageBoxDialog : public views::DialogDelegate {
+class JavaScriptMessageBoxDialog : public ModalDialogDelegate {
public:
- JavascriptMessageBoxDialog(AppModalDialog* parent,
+ JavaScriptMessageBoxDialog(JavaScriptAppModalDialog* parent,
const std::wstring& message_text,
const std::wstring& default_prompt_text,
bool display_suppress_checkbox);
- virtual ~JavascriptMessageBoxDialog();
+ virtual ~JavaScriptMessageBoxDialog();
- // Methods called from AppModalDialog.
- void ShowModalDialog();
- void ActivateModalDialog();
- void CloseModalDialog();
+ // ModalDialogDelegate overrides.
+ virtual gfx::NativeWindow GetDialogRootWindow();
// views::DialogDelegate Methods:
virtual int GetDialogButtons() const;
@@ -52,15 +50,12 @@ class JavascriptMessageBoxDialog : public views::DialogDelegate {
}
// A pointer to the AppModalDialog that owns us.
- AppModalDialog* parent_;
+ JavaScriptAppModalDialog* parent_;
// The message box view whose commands we handle.
MessageBoxView* message_box_view_;
- // The dialog if it is currently visible.
- views::Window* dialog_;
-
- DISALLOW_COPY_AND_ASSIGN(JavascriptMessageBoxDialog);
+ DISALLOW_COPY_AND_ASSIGN(JavaScriptMessageBoxDialog);
};
#endif // CHROME_BROWSER_VIEWS_JSMESSAGE_BOX_DIALOG_H_
diff --git a/chrome/browser/views/modal_dialog_delegate.cc b/chrome/browser/views/modal_dialog_delegate.cc
new file mode 100644
index 0000000..586b9f6
--- /dev/null
+++ b/chrome/browser/views/modal_dialog_delegate.cc
@@ -0,0 +1,37 @@
+// Copyright (c) 2006-2008 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/views/modal_dialog_delegate.h"
+
+#include "views/window/window.h"
+
+void ModalDialogDelegate::ShowModalDialog() {
+ gfx::NativeWindow root_hwnd = GetDialogRootWindow();
+ // GetMessageBoxRootWindow() will be NULL if there's no selected tab (e.g.,
+ // during shutdown), in which case we simply skip showing this dialog.
+ if (!root_hwnd) {
+ Cancel();
+ } else {
+ dialog_ = views::Window::CreateChromeWindow(root_hwnd, gfx::Rect(), this);
+ dialog_->Show();
+ }
+}
+
+void ModalDialogDelegate::ActivateModalDialog() {
+ // Ensure that the dialog is visible and at the top of the z-order. These
+ // conditions may not be true if the dialog was opened on a different virtual
+ // desktop to the one the browser window is on.
+ dialog_->Show();
+ dialog_->Activate();
+}
+
+void ModalDialogDelegate::CloseModalDialog() {
+ // If the dialog is visible close it.
+ if (dialog_)
+ dialog_->Close();
+}
+
+ModalDialogDelegate::ModalDialogDelegate() : dialog_(NULL) {
+}
+
diff --git a/chrome/browser/views/modal_dialog_delegate.h b/chrome/browser/views/modal_dialog_delegate.h
new file mode 100644
index 0000000..4fe2c1d
--- /dev/null
+++ b/chrome/browser/views/modal_dialog_delegate.h
@@ -0,0 +1,32 @@
+// Copyright (c) 2006-2008 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.
+
+#ifndef CHROME_BROWSER_VIEWS_MODAL_DIALOG_DELEGATE_H_
+#define CHROME_BROWSER_VIEWS_MODAL_DIALOG_DELEGATE_H_
+
+#include <string>
+
+#include "views/window/dialog_delegate.h"
+
+namespace views {
+class Window;
+}
+
+class ModalDialogDelegate : public views::DialogDelegate {
+ public:
+ virtual ~ModalDialogDelegate() {}
+ // Methods called from AppModalDialog.
+ virtual gfx::NativeWindow GetDialogRootWindow() = 0;
+ virtual void ShowModalDialog();
+ virtual void ActivateModalDialog();
+ virtual void CloseModalDialog();
+ protected:
+ ModalDialogDelegate();
+
+ // The dialog if it is currently visible.
+ views::Window* dialog_;
+};
+
+#endif // CHROME_BROWSER_VIEWS_MODAL_DIALOG_DELEGATE_H_
+