diff options
author | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-05 22:32:14 +0000 |
---|---|---|
committer | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-05 22:32:14 +0000 |
commit | 12f74a94c21e19c74208dacf1dc5ef46f8a27f53 (patch) | |
tree | d10fe102066ab8b0a437b18ffc70aa228d02ba4e /chrome/browser/js_modal_dialog.h | |
parent | 225c8f507421a2eff2ed7a900104431d04ed7e5e (diff) | |
download | chromium_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/js_modal_dialog.h')
-rw-r--r-- | chrome/browser/js_modal_dialog.h | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/chrome/browser/js_modal_dialog.h b/chrome/browser/js_modal_dialog.h new file mode 100644 index 0000000..1ec75ac --- /dev/null +++ b/chrome/browser/js_modal_dialog.h @@ -0,0 +1,102 @@ +// Copyright (c) 2009 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_JS_MODAL_DIALOG_H_ +#define CHROME_BROWSER_JS_MODAL_DIALOG_H_ + +#include <string> + +#include "build/build_config.h" +#include "chrome/browser/app_modal_dialog.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" +#include "net/base/cookie_monster.h" + +class ExtensionHost; +class JavaScriptMessageBoxClient; + +// 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, + const std::wstring& title, + int dialog_flags, + const std::wstring& message_text, + const std::wstring& default_prompt_text, + bool display_suppress_checkbox, + bool is_before_unload_dialog, + IPC::Message* reply_msg); + virtual ~JavaScriptAppModalDialog(); + + // AppModalDialog overrides. +#if defined(OS_LINUX) || defined(OS_MACOSX) + virtual void CreateAndShowDialog(); +#endif +#if defined(OS_LINUX) + virtual void HandleDialogResponse(GtkDialog* dialog, gint response_id); +#endif + virtual int GetDialogButtons(); + virtual void AcceptWindow(); + virtual void CancelWindow(); + + ///////////////////////////////////////////////////////////////////////////// + // Getters so NativeDialog can get information about the message box. + JavaScriptMessageBoxClient* client() { + return client_; + } + int dialog_flags() { + return dialog_flags_; + } + bool is_before_unload_dialog() { + return is_before_unload_dialog_; + } + + // Callbacks from NativeDialog when the user accepts or cancels the dialog. + void OnCancel(); + void OnAccept(const std::wstring& prompt_text, bool suppress_js_messages); + void OnClose(); + + protected: + // AppModalDialog overrides. + virtual void Cleanup(); + virtual NativeDialog CreateNativeDialog(); + + private: + // NotificationObserver implementation. + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + // Initializes for notifications to listen. + void InitNotifications(); + + NotificationRegistrar registrar_; + + // An implementation of the client interface to provide supporting methods + // and receive results. + JavaScriptMessageBoxClient* client_; + + // 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. + ExtensionHost* extension_host_; + + // Information about the message box is held in the following variables. + int dialog_flags_; + std::wstring message_text_; + std::wstring default_prompt_text_; + bool display_suppress_checkbox_; + bool is_before_unload_dialog_; + IPC::Message* reply_msg_; + + DISALLOW_COPY_AND_ASSIGN(JavaScriptAppModalDialog); +}; + +#endif // CHROME_BROWSER_JS_MODAL_DIALOG_H_ + |