summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-02 19:20:13 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-02 19:20:13 +0000
commit1db06851c0de18c6049a88379750f5651cc92a75 (patch)
treeb73c3fc45a07f77ab55fc3de83c4e035b5ba2387
parent7fef9717afc4570883a9207fb8ea70f295685488 (diff)
downloadchromium_src-1db06851c0de18c6049a88379750f5651cc92a75.zip
chromium_src-1db06851c0de18c6049a88379750f5651cc92a75.tar.gz
chromium_src-1db06851c0de18c6049a88379750f5651cc92a75.tar.bz2
Add a Delegate to JavaScriptAppModalDialog.
Done a couples of things here: - Renamed JavaScriptMessageBoxClient to JavaScriptMessageBoxDelegate (since this is a common pattern in chrome and helps the reader to find out where the message box goes). - Moved that class into js_modal_dialog.h file. - Deleted jsmessage_box_client.h It is a following to http://codereview.chromium.org/3384036. BUG=54988 TEST=trybots Review URL: http://codereview.chromium.org/3576003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61309 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extension_host.h8
-rw-r--r--chrome/browser/js_modal_dialog.cc20
-rw-r--r--chrome/browser/js_modal_dialog.h51
-rw-r--r--chrome/browser/jsmessage_box_client.h49
-rw-r--r--chrome/browser/message_box_handler.cc4
-rw-r--r--chrome/browser/message_box_handler.h4
-rw-r--r--chrome/browser/tab_contents/background_contents.h8
-rw-r--r--chrome/browser/tab_contents/tab_contents.h8
-rw-r--r--chrome/browser/views/js_modal_dialog_views.h5
-rw-r--r--chrome/chrome_browser.gypi1
10 files changed, 63 insertions, 95 deletions
diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h
index fda120a..fe208c8 100644
--- a/chrome/browser/extensions/extension_host.h
+++ b/chrome/browser/extensions/extension_host.h
@@ -12,7 +12,7 @@
#include "base/perftimer.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/extensions/extension_function_dispatcher.h"
-#include "chrome/browser/jsmessage_box_client.h"
+#include "chrome/browser/js_modal_dialog.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
#if defined(TOOLKIT_VIEWS)
@@ -40,7 +40,7 @@ class ExtensionHost : public RenderViewHostDelegate,
public RenderViewHostDelegate::View,
public ExtensionFunctionDispatcher::Delegate,
public NotificationObserver,
- public JavaScriptMessageBoxClient {
+ public JavaScriptAppModalDialogDelegate {
public:
class ProcessCreationQueue;
@@ -180,12 +180,12 @@ class ExtensionHost : public RenderViewHostDelegate,
const NotificationSource& source,
const NotificationDetails& details);
- // JavaScriptMessageBoxClient
- virtual gfx::NativeWindow GetMessageBoxRootWindow();
+ // Overridden from JavaScriptAppModalDialogDelegate:
virtual void OnMessageBoxClosed(IPC::Message* reply_msg,
bool success,
const std::wstring& prompt);
virtual void SetSuppressMessageBoxes(bool suppress_message_boxes) {}
+ virtual gfx::NativeWindow GetMessageBoxRootWindow();
virtual TabContents* AsTabContents() { return NULL; }
virtual ExtensionHost* AsExtensionHost() { return this; }
diff --git a/chrome/browser/js_modal_dialog.cc b/chrome/browser/js_modal_dialog.cc
index 8f79da2..604cd9f 100644
--- a/chrome/browser/js_modal_dialog.cc
+++ b/chrome/browser/js_modal_dialog.cc
@@ -22,7 +22,7 @@ const int kDefaultPromptTextSize = 2000;
} // namespace
JavaScriptAppModalDialog::JavaScriptAppModalDialog(
- JavaScriptMessageBoxClient* client,
+ JavaScriptAppModalDialogDelegate* delegate,
const std::wstring& title,
int dialog_flags,
const std::wstring& message_text,
@@ -30,9 +30,9 @@ JavaScriptAppModalDialog::JavaScriptAppModalDialog(
bool display_suppress_checkbox,
bool is_before_unload_dialog,
IPC::Message* reply_msg)
- : AppModalDialog(client->AsTabContents(), title),
- client_(client),
- extension_host_(client->AsExtensionHost()),
+ : AppModalDialog(delegate->AsTabContents(), title),
+ delegate_(delegate),
+ extension_host_(delegate->AsExtensionHost()),
dialog_flags_(dialog_flags),
display_suppress_checkbox_(display_suppress_checkbox),
is_before_unload_dialog_(is_before_unload_dialog),
@@ -71,9 +71,9 @@ void JavaScriptAppModalDialog::Observe(NotificationType type,
// If we reach here, we know the notification is relevant to us, either
// because we're only observing applicable sources or because we passed the
// check above. Both of those indicate that we should ignore this dialog.
- // Also clear the client, since it's now invalid.
+ // Also clear the delegate, since it's now invalid.
skip_this_dialog_ = true;
- client_ = NULL;
+ delegate_ = NULL;
if (native_dialog_)
CloseModalDialog();
}
@@ -111,7 +111,7 @@ void JavaScriptAppModalDialog::OnCancel() {
CompleteDialog();
if (!skip_this_dialog_) {
- client_->OnMessageBoxClosed(reply_msg_, false, std::wstring());
+ delegate_->OnMessageBoxClosed(reply_msg_, false, std::wstring());
}
Cleanup();
@@ -122,9 +122,9 @@ void JavaScriptAppModalDialog::OnAccept(const std::wstring& prompt_text,
CompleteDialog();
if (!skip_this_dialog_) {
- client_->OnMessageBoxClosed(reply_msg_, true, prompt_text);
+ delegate_->OnMessageBoxClosed(reply_msg_, true, prompt_text);
if (suppress_js_messages)
- client_->SetSuppressMessageBoxes(true);
+ delegate_->SetSuppressMessageBoxes(true);
}
Cleanup();
@@ -136,7 +136,7 @@ void JavaScriptAppModalDialog::OnClose() {
void JavaScriptAppModalDialog::Cleanup() {
if (skip_this_dialog_) {
- // We can't use the client_, because we might be in the process of
+ // We can't use the |delegate_|, because we might be in the process of
// destroying it.
if (tab_contents_)
tab_contents_->OnMessageBoxClosed(reply_msg_, false, L"");
diff --git a/chrome/browser/js_modal_dialog.h b/chrome/browser/js_modal_dialog.h
index b2cccff..eef7540 100644
--- a/chrome/browser/js_modal_dialog.h
+++ b/chrome/browser/js_modal_dialog.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -12,23 +12,46 @@
#include "chrome/browser/app_modal_dialog.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
+#include "gfx/native_widget_types.h"
class ExtensionHost;
-class JavaScriptMessageBoxClient;
class NativeAppModalDialog;
+class TabContents;
namespace IPC {
class Message;
}
-// A controller+model class for JavaScript alert, confirm, prompt, and
+class JavaScriptAppModalDialogDelegate {
+ 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() {}
+};
+
+// A controller + model class for JavaScript alert, confirm, prompt, and
// onbeforeunload dialog boxes.
class JavaScriptAppModalDialog : public AppModalDialog,
public NotificationObserver {
public:
- // A union of data necessary to determine the type of message box to
- // show. |dialog_flags| is a MessageBox flag.
- JavaScriptAppModalDialog(JavaScriptMessageBoxClient* client,
+ JavaScriptAppModalDialog(JavaScriptAppModalDialogDelegate* delegate,
const std::wstring& title,
int dialog_flags,
const std::wstring& message_text,
@@ -38,12 +61,10 @@ class JavaScriptAppModalDialog : public AppModalDialog,
IPC::Message* reply_msg);
virtual ~JavaScriptAppModalDialog();
- // AppModalDialog overrides.
+ // Overridden from AppModalDialog:
virtual NativeAppModalDialog* CreateNativeDialog();
- /////////////////////////////////////////////////////////////////////////////
- // Getters so NativeDialog can get information about the message box.
- JavaScriptMessageBoxClient* client() const { return client_; }
+ JavaScriptAppModalDialogDelegate* delegate() const { return delegate_; }
// Callbacks from NativeDialog when the user accepts or cancels the dialog.
void OnCancel();
@@ -58,11 +79,11 @@ class JavaScriptAppModalDialog : public AppModalDialog,
bool is_before_unload_dialog() const { return is_before_unload_dialog_; }
protected:
- // AppModalDialog overrides.
+ // Overridden from AppModalDialog:
virtual void Cleanup();
private:
- // NotificationObserver implementation.
+ // Overridden from NotificationObserver:
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);
@@ -76,12 +97,12 @@ class JavaScriptAppModalDialog : public AppModalDialog,
// An implementation of the client interface to provide supporting methods
// and receive results.
- JavaScriptMessageBoxClient* client_;
+ JavaScriptAppModalDialogDelegate* delegate_;
// The client_ as an ExtensionHost, cached for use during notifications that
// may arrive after the client has entered its destructor (and is thus
- // treated as a base JavaScriptMessageBoxClient). This will be NULL if the
- // client is not an ExtensionHost.
+ // treated as a base Delegate). This will be NULL if the |delegate_| is not an
+ // ExtensionHost.
ExtensionHost* extension_host_;
// Information about the message box is held in the following variables.
diff --git a/chrome/browser/jsmessage_box_client.h b/chrome/browser/jsmessage_box_client.h
deleted file mode 100644
index 011a281..0000000
--- a/chrome/browser/jsmessage_box_client.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright (c) 2010 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_JSMESSAGE_BOX_CLIENT_H_
-#define CHROME_BROWSER_JSMESSAGE_BOX_CLIENT_H_
-#pragma once
-
-// JavaScriptMessageBoxClient
-//
-// An interface implemented by an object that receives results from JavaScript
-// message boxes (alert, confirm, and prompt).
-//
-
-#include <string>
-
-#include "gfx/native_widget_types.h"
-
-class ExtensionHost;
-class GURL;
-class TabContents;
-namespace IPC {
-class Message;
-}
-
-class JavaScriptMessageBoxClient {
- public:
- virtual ~JavaScriptMessageBoxClient() {}
-
- // Returns the root native window with which the message box is associated.
- virtual gfx::NativeWindow GetMessageBoxRootWindow() = 0;
-
- // 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 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;
-};
-
-#endif // CHROME_BROWSER_JSMESSAGE_BOX_CLIENT_H_
diff --git a/chrome/browser/message_box_handler.cc b/chrome/browser/message_box_handler.cc
index 7389cc7..1f5831a 100644
--- a/chrome/browser/message_box_handler.cc
+++ b/chrome/browser/message_box_handler.cc
@@ -62,7 +62,7 @@ static std::wstring GetTitle(Profile* profile,
}
void RunJavascriptMessageBox(Profile* profile,
- JavaScriptMessageBoxClient* client,
+ JavaScriptAppModalDialogDelegate* delegate,
const GURL& frame_url,
int dialog_flags,
const std::wstring& message_text,
@@ -72,7 +72,7 @@ void RunJavascriptMessageBox(Profile* profile,
bool is_alert = dialog_flags == MessageBoxFlags::kIsJavascriptAlert;
std::wstring title = GetTitle(profile, is_alert, frame_url);
Singleton<AppModalDialogQueue>()->AddDialog(new JavaScriptAppModalDialog(
- client, title, dialog_flags, message_text, default_prompt_text,
+ delegate, title, dialog_flags, message_text, default_prompt_text,
display_suppress_checkbox, false, reply_msg));
}
diff --git a/chrome/browser/message_box_handler.h b/chrome/browser/message_box_handler.h
index fcb9cc9..ea35df7 100644
--- a/chrome/browser/message_box_handler.h
+++ b/chrome/browser/message_box_handler.h
@@ -10,6 +10,7 @@
#include "base/string16.h"
#include "chrome/browser/browsing_data_local_storage_helper.h"
+#include "chrome/browser/js_modal_dialog.h"
#include "googleurl/src/gurl.h"
#include "ipc/ipc_message.h"
#include "net/base/cookie_monster.h"
@@ -17,7 +18,6 @@
class CookiePromptModalDialogDelegate;
class GURL;
class HostContentSettingsMap;
-class JavaScriptMessageBoxClient;
class TabContents;
class Profile;
@@ -28,7 +28,7 @@ class Profile;
// |default_prompt_text|. The result of the operation is returned using
// |reply_msg|.
void RunJavascriptMessageBox(Profile* profile,
- JavaScriptMessageBoxClient* client,
+ JavaScriptAppModalDialogDelegate* delegate,
const GURL& frame_url,
int dialog_flags,
const std::wstring& message_text,
diff --git a/chrome/browser/tab_contents/background_contents.h b/chrome/browser/tab_contents/background_contents.h
index 6743291..f4cf75b 100644
--- a/chrome/browser/tab_contents/background_contents.h
+++ b/chrome/browser/tab_contents/background_contents.h
@@ -8,7 +8,7 @@
#include <string>
-#include "chrome/browser/jsmessage_box_client.h"
+#include "chrome/browser/js_modal_dialog.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
#include "chrome/common/extensions/extension_constants.h"
@@ -32,7 +32,7 @@ class Rect;
class BackgroundContents : public RenderViewHostDelegate,
public RenderViewHostDelegate::View,
public NotificationObserver,
- public JavaScriptMessageBoxClient {
+ public JavaScriptAppModalDialogDelegate {
public:
class Delegate {
public:
@@ -122,12 +122,12 @@ class BackgroundContents : public RenderViewHostDelegate,
const NotificationSource& source,
const NotificationDetails& details);
- // JavaScriptMessageBoxClient
- virtual gfx::NativeWindow GetMessageBoxRootWindow();
+ // Overridden from JavaScriptAppModalDialogDelegate:
virtual void OnMessageBoxClosed(IPC::Message* reply_msg,
bool success,
const std::wstring& prompt);
virtual void SetSuppressMessageBoxes(bool suppress_message_boxes) {}
+ virtual gfx::NativeWindow GetMessageBoxRootWindow();
virtual TabContents* AsTabContents() { return NULL; }
virtual ExtensionHost* AsExtensionHost() { return NULL; }
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index bf0a890..b556c62 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -23,7 +23,7 @@
#include "chrome/browser/fav_icon_helper.h"
#include "chrome/browser/find_bar_controller.h"
#include "chrome/browser/find_notification_details.h"
-#include "chrome/browser/jsmessage_box_client.h"
+#include "chrome/browser/js_modal_dialog.h"
#include "chrome/browser/prefs/pref_change_registrar.h"
#include "chrome/browser/password_manager/password_manager_delegate.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
@@ -100,7 +100,7 @@ class TabContents : public PageNavigator,
public RenderViewHostDelegate::BrowserIntegration,
public RenderViewHostDelegate::Resource,
public RenderViewHostManager::Delegate,
- public JavaScriptMessageBoxClient,
+ public JavaScriptAppModalDialogDelegate,
public ImageLoadingTracker::Observer,
public PasswordManagerDelegate,
public TabSpecificContentSettings::Delegate {
@@ -663,12 +663,12 @@ class TabContents : public PageNavigator,
}
bool closed_by_user_gesture() const { return closed_by_user_gesture_; }
- // JavaScriptMessageBoxClient ------------------------------------------------
- virtual gfx::NativeWindow GetMessageBoxRootWindow();
+ // Overridden from JavaScriptAppModalDialogDelegate:
virtual void OnMessageBoxClosed(IPC::Message* reply_msg,
bool success,
const std::wstring& prompt);
virtual void SetSuppressMessageBoxes(bool suppress_message_boxes);
+ virtual gfx::NativeWindow GetMessageBoxRootWindow();
virtual TabContents* AsTabContents();
virtual ExtensionHost* AsExtensionHost();
diff --git a/chrome/browser/views/js_modal_dialog_views.h b/chrome/browser/views/js_modal_dialog_views.h
index a101f51..00d1bb7 100644
--- a/chrome/browser/views/js_modal_dialog_views.h
+++ b/chrome/browser/views/js_modal_dialog_views.h
@@ -11,14 +11,13 @@
#include <string>
#include "app/message_box_flags.h"
-#include "chrome/browser/jsmessage_box_client.h"
#include "chrome/browser/native_app_modal_dialog.h"
#include "views/window/dialog_delegate.h"
class MessageBoxView;
class JSModalDialogViews : public NativeAppModalDialog,
- public views::DialogDelegate {
+ public views::DialogDelegate {
public:
explicit JSModalDialogViews(JavaScriptAppModalDialog* parent);
virtual ~JSModalDialogViews();
@@ -49,8 +48,6 @@ class JSModalDialogViews : public NativeAppModalDialog,
virtual void OnClose();
private:
- JavaScriptMessageBoxClient* client() const { return parent_->client(); }
-
// A pointer to the AppModalDialog that owns us.
JavaScriptAppModalDialog* parent_;
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index bfbecc1..da1cb11 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2058,7 +2058,6 @@
'browser/jumplist_win.h',
'browser/js_modal_dialog.cc',
'browser/js_modal_dialog.h',
- 'browser/jsmessage_box_client.h',
'browser/keychain_mac.cc',
'browser/keychain_mac.h',
'browser/labs.cc',