summaryrefslogtreecommitdiffstats
path: root/content/shell/browser/shell_javascript_dialog_win.cc
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-20 11:30:41 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-20 11:30:41 +0000
commitde7d61ff0d16a335b4c5199bc638205df91700a5 (patch)
treebcd14deb2b6b242e2fc5e20bc136f177c2aa7c18 /content/shell/browser/shell_javascript_dialog_win.cc
parent8162d4474a101a16cc729c94e979cb3216e2aa9d (diff)
downloadchromium_src-de7d61ff0d16a335b4c5199bc638205df91700a5.zip
chromium_src-de7d61ff0d16a335b4c5199bc638205df91700a5.tar.gz
chromium_src-de7d61ff0d16a335b4c5199bc638205df91700a5.tar.bz2
[content shell] move browser process stuff into browser/ subdir
BUG=180021 R=marja@chromium.org TBR=joi@chromium.org,ben@chromium.org Review URL: https://chromiumcodereview.appspot.com/23316003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218441 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/shell/browser/shell_javascript_dialog_win.cc')
-rw-r--r--content/shell/browser/shell_javascript_dialog_win.cc113
1 files changed, 113 insertions, 0 deletions
diff --git a/content/shell/browser/shell_javascript_dialog_win.cc b/content/shell/browser/shell_javascript_dialog_win.cc
new file mode 100644
index 0000000..a59639e
--- /dev/null
+++ b/content/shell/browser/shell_javascript_dialog_win.cc
@@ -0,0 +1,113 @@
+// Copyright 2013 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/browser/shell_javascript_dialog.h"
+
+#include "base/strings/string_util.h"
+#include "content/shell/app/resource.h"
+#include "content/shell/browser/shell.h"
+#include "content/shell/browser/shell_javascript_dialog_manager.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, DWLP_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_ == 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, DWLP_USER));
+ if (owner->dialog_win_) {
+ owner->dialog_win_ = 0;
+ owner->callback_.Run(false, string16());
+ owner->manager_->DialogClosed(owner);
+ }
+ break;
+ }
+ case WM_COMMAND: {
+ ShellJavaScriptDialog* owner = reinterpret_cast<ShellJavaScriptDialog*>(
+ GetWindowLongPtr(dialog, DWLP_USER));
+ string16 user_input;
+ bool finish = false;
+ bool result;
+ switch (LOWORD(wparam)) {
+ case IDOK:
+ finish = true;
+ result = true;
+ if (owner->message_type_ == JAVASCRIPT_MESSAGE_TYPE_PROMPT) {
+ int 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->manager_->DialogClosed(owner);
+ }
+ break;
+ }
+ default:
+ return DefWindowProc(dialog, message, wparam, lparam);
+ }
+ return 0;
+}
+
+ShellJavaScriptDialog::ShellJavaScriptDialog(
+ ShellJavaScriptDialogManager* manager,
+ gfx::NativeWindow parent_window,
+ JavaScriptMessageType message_type,
+ const string16& message_text,
+ const string16& default_prompt_text,
+ const JavaScriptDialogManager::DialogClosedCallback& callback)
+ : manager_(manager),
+ callback_(callback),
+ message_text_(message_text),
+ default_prompt_text_(default_prompt_text),
+ message_type_(message_type) {
+ int dialog_type;
+ if (message_type == JAVASCRIPT_MESSAGE_TYPE_ALERT)
+ dialog_type = IDD_ALERT;
+ else if (message_type == 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