summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcem.kocagil@gmail.com <cem.kocagil@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-30 19:53:29 +0000
committercem.kocagil@gmail.com <cem.kocagil@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-30 19:53:29 +0000
commit7fc838215af759eb66e38be4cf2be1ff50b69e51 (patch)
tree48dbe4947f2f45a83bab177273410926aa4e01bc
parentb14175d1c3ca05c4a07ad73ecbd0572c03000dcf (diff)
downloadchromium_src-7fc838215af759eb66e38be4cf2be1ff50b69e51.zip
chromium_src-7fc838215af759eb66e38be4cf2be1ff50b69e51.tar.gz
chromium_src-7fc838215af759eb66e38be4cf2be1ff50b69e51.tar.bz2
Add JavaScript dialogs functionality to content_shell on Windows
BUG=120155 TEST=JavaScript dialogs should work in content_shell on Windows Review URL: http://codereview.chromium.org/9918013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129904 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/content_shell.gypi4
-rw-r--r--content/shell/resource.h8
-rw-r--r--content/shell/shell.rc70
-rw-r--r--content/shell/shell_javascript_dialog.h9
-rw-r--r--content/shell/shell_javascript_dialog_creator.cc8
-rw-r--r--content/shell/shell_javascript_dialog_creator.h2
-rwxr-xr-xcontent/shell/shell_javascript_dialog_win.cc111
7 files changed, 205 insertions, 7 deletions
diff --git a/content/content_shell.gypi b/content/content_shell.gypi
index 85607fd..d2ee56c 100644
--- a/content/content_shell.gypi
+++ b/content/content_shell.gypi
@@ -82,6 +82,7 @@
'shell/shell_javascript_dialog_creator.cc',
'shell/shell_javascript_dialog_creator.h',
'shell/shell_javascript_dialog_mac.mm',
+ 'shell/shell_javascript_dialog_win.cc',
'shell/shell_javascript_dialog.h',
'shell/shell_main_delegate.cc',
'shell/shell_main_delegate.h',
@@ -261,6 +262,9 @@
],
}],
['OS=="win"', {
+ 'sources': [
+ 'shell/shell.rc',
+ ],
'configurations': {
'Debug_Base': {
'msvs_settings': {
diff --git a/content/shell/resource.h b/content/shell/resource.h
index 291f3f4..849ee86 100644
--- a/content/shell/resource.h
+++ b/content/shell/resource.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -13,10 +13,16 @@
#define IDM_CLOSE_WINDOW 106
#define IDM_NEW_WINDOW 107
#define IDC_CONTENTSHELL 109
+#define IDD_ALERT 130
+#define IDD_CONFIRM 131
+#define IDD_PROMPT 132
#define IDC_NAV_BACK 1001
#define IDC_NAV_FORWARD 1002
#define IDC_NAV_RELOAD 1003
#define IDC_NAV_STOP 1004
+#define IDC_PROMPTEDIT 1005
+#define IDC_DIALOGTEXT 1006
+
#ifndef IDC_STATIC
#define IDC_STATIC -1
#endif
diff --git a/content/shell/shell.rc b/content/shell/shell.rc
index 4e3b2bc..2652573 100644
--- a/content/shell/shell.rc
+++ b/content/shell/shell.rc
@@ -59,6 +59,76 @@ END
#endif // APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_ALERT DIALOGEX 0, 0, 241, 76
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Alert"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ DEFPUSHBUTTON "OK",IDOK,184,55,50,14
+ LTEXT "",IDC_DIALOGTEXT,16,17,210,30
+END
+
+IDD_CONFIRM DIALOGEX 0, 0, 241, 76
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Confirm"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ PUSHBUTTON "Cancel",IDCANCEL,184,55,50,14
+ DEFPUSHBUTTON "OK",IDOK,131,55,50,14
+ LTEXT "",IDC_DIALOGTEXT,16,17,210,30
+END
+
+IDD_PROMPT DIALOGEX 0, 0, 241, 76
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Prompt"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ DEFPUSHBUTTON "OK",IDOK,131,55,50,14
+ LTEXT "",IDC_DIALOGTEXT,16,17,210,18
+ PUSHBUTTON "Cancel",IDCANCEL,184,55,50,14
+ EDITTEXT IDC_PROMPTEDIT,15,33,210,14,ES_AUTOHSCROLL
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO
+BEGIN
+ IDD_ALERT, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 234
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 69
+ END
+
+ IDD_CONFIRM, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 234
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 69
+ END
+
+ IDD_PROMPT, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 234
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 69
+ END
+END
+#endif // APSTUDIO_INVOKED
+
#endif
/////////////////////////////////////////////////////////////////////////////
diff --git a/content/shell/shell_javascript_dialog.h b/content/shell/shell_javascript_dialog.h
index 32d425d..a64ba39 100644
--- a/content/shell/shell_javascript_dialog.h
+++ b/content/shell/shell_javascript_dialog.h
@@ -42,7 +42,14 @@ class ShellJavaScriptDialog {
#if defined(OS_MACOSX)
ShellJavaScriptDialogHelper* helper_; // owned
NSAlert* alert_; // weak, owned by |helper_|.
-#endif // defined(OS_MACOSX)
+#elif defined(OS_WIN)
+ ui::JavascriptMessageType message_type_;
+ HWND dialog_win_;
+ string16 message_text_;
+ string16 default_prompt_text_;
+ static INT_PTR CALLBACK DialogProc(HWND dialog, UINT message, WPARAM wparam,
+ LPARAM lparam);
+#endif
DISALLOW_COPY_AND_ASSIGN(ShellJavaScriptDialog);
};
diff --git a/content/shell/shell_javascript_dialog_creator.cc b/content/shell/shell_javascript_dialog_creator.cc
index d6b100c..b0dc5a1 100644
--- a/content/shell/shell_javascript_dialog_creator.cc
+++ b/content/shell/shell_javascript_dialog_creator.cc
@@ -26,7 +26,7 @@ void ShellJavaScriptDialogCreator::RunJavaScriptDialog(
const string16& default_prompt_text,
const DialogClosedCallback& callback,
bool* did_suppress_message) {
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(OS_WIN)
*did_suppress_message = false;
if (dialog_.get()) {
@@ -56,7 +56,7 @@ void ShellJavaScriptDialogCreator::RunBeforeUnloadDialog(
const string16& message_text,
bool is_reload,
const DialogClosedCallback& callback) {
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(OS_WIN)
if (dialog_.get()) {
// Seriously!?
callback.Run(true, string16());
@@ -81,7 +81,7 @@ void ShellJavaScriptDialogCreator::RunBeforeUnloadDialog(
void ShellJavaScriptDialogCreator::ResetJavaScriptState(
WebContents* web_contents) {
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(OS_WIN)
if (dialog_.get()) {
dialog_->Cancel();
dialog_.reset();
@@ -92,7 +92,7 @@ void ShellJavaScriptDialogCreator::ResetJavaScriptState(
}
void ShellJavaScriptDialogCreator::DialogClosed(ShellJavaScriptDialog* dialog) {
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(OS_WIN)
DCHECK_EQ(dialog, dialog_.get());
dialog_.reset();
#else
diff --git a/content/shell/shell_javascript_dialog_creator.h b/content/shell/shell_javascript_dialog_creator.h
index 88e5db6..7a99837 100644
--- a/content/shell/shell_javascript_dialog_creator.h
+++ b/content/shell/shell_javascript_dialog_creator.h
@@ -42,7 +42,7 @@ class ShellJavaScriptDialogCreator : public JavaScriptDialogCreator {
void DialogClosed(ShellJavaScriptDialog* dialog);
private:
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(OS_WIN)
// The dialog being shown. No queueing.
scoped_ptr<ShellJavaScriptDialog> dialog_;
#else
diff --git a/content/shell/shell_javascript_dialog_win.cc b/content/shell/shell_javascript_dialog_win.cc
new file mode 100755
index 0000000..7195ba5
--- /dev/null
+++ b/content/shell/shell_javascript_dialog_win.cc
@@ -0,0 +1,111 @@
+// Copyright (c) 2012 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 "content/shell/shell_javascript_dialog.h"
+
+#include "base/string_util.h"
+#include "content/shell/resource.h"
+#include "content/shell/shell.h"
+#include "content/shell/shell_javascript_dialog_creator.h"
+
+namespace content {
+
+class ShellJavaScriptDialog;
+
+INT_PTR CALLBACK ShellJavaScriptDialog::DialogProc(HWND dialog, UINT message,
+ WPARAM wparam,
+ LPARAM lparam) {
+ switch (message) {
+ case WM_INITDIALOG: {
+ SetWindowLongPtr(dialog, DWL_USER, static_cast<LONG_PTR>(lparam));
+ ShellJavaScriptDialog* owner =
+ reinterpret_cast<ShellJavaScriptDialog*>(lparam);
+ owner->dialog_win_ = dialog;
+ SetDlgItemText(dialog, IDC_DIALOGTEXT, owner->message_text_.c_str());
+ if (owner->message_type_ == ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT)
+ SetDlgItemText(dialog, IDC_PROMPTEDIT,
+ owner->default_prompt_text_.c_str());
+ break;
+ }
+ case WM_DESTROY: {
+ ShellJavaScriptDialog* owner = reinterpret_cast<ShellJavaScriptDialog*>(
+ GetWindowLongPtr(dialog, DWL_USER));
+ if (owner->dialog_win_) {
+ owner->dialog_win_ = 0;
+ owner->callback_.Run(false, string16());
+ owner->creator_->DialogClosed(owner);
+ }
+ break;
+ }
+ case WM_COMMAND: {
+ ShellJavaScriptDialog* owner = reinterpret_cast<ShellJavaScriptDialog*>(
+ GetWindowLongPtr(dialog, DWL_USER));
+ string16 user_input;
+ bool finish = false;
+ bool result;
+ switch (LOWORD(wparam)) {
+ case IDOK:
+ finish = true;
+ result = true;
+ if (owner->message_type_ == ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT) {
+ size_t length =
+ GetWindowTextLength(GetDlgItem(dialog, IDC_PROMPTEDIT)) + 1;
+ GetDlgItemText(dialog, IDC_PROMPTEDIT,
+ WriteInto(&user_input, length), length);
+ }
+ break;
+ case IDCANCEL:
+ finish = true;
+ result = false;
+ break;
+ }
+ if (finish) {
+ owner->dialog_win_ = 0;
+ owner->callback_.Run(result, user_input);
+ DestroyWindow(dialog);
+ owner->creator_->DialogClosed(owner);
+ }
+ break;
+ }
+ default:
+ return DefWindowProc(dialog, message, wparam, lparam);
+ }
+ return 0;
+}
+
+ShellJavaScriptDialog::ShellJavaScriptDialog(
+ ShellJavaScriptDialogCreator* creator,
+ ui::JavascriptMessageType javascript_message_type,
+ const string16& message_text,
+ const string16& default_prompt_text,
+ const JavaScriptDialogCreator::DialogClosedCallback& callback)
+ : creator_(creator),
+ callback_(callback),
+ message_text_(message_text),
+ default_prompt_text_(default_prompt_text),
+ message_type_(javascript_message_type) {
+ int dialog_type;
+ if (javascript_message_type == ui::JAVASCRIPT_MESSAGE_TYPE_ALERT)
+ dialog_type = IDD_ALERT;
+ else if (javascript_message_type == ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM)
+ dialog_type = IDD_CONFIRM;
+ else // JAVASCRIPT_MESSAGE_TYPE_PROMPT
+ dialog_type = IDD_PROMPT;
+
+ dialog_win_ = CreateDialogParam(GetModuleHandle(0),
+ MAKEINTRESOURCE(dialog_type), 0, DialogProc,
+ reinterpret_cast<LPARAM>(this));
+ ShowWindow(dialog_win_, SW_SHOWNORMAL);
+}
+
+ShellJavaScriptDialog::~ShellJavaScriptDialog() {
+ Cancel();
+}
+
+void ShellJavaScriptDialog::Cancel() {
+ if (dialog_win_)
+ DestroyWindow(dialog_win_);
+}
+
+} // namespace content