blob: 5a2a27de808e22dfe80d84c62beca0c9b2b2d1d3 [file] [log] [blame]
[email protected]de7d61ff2013-08-20 11:30:411// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]7fc83822012-03-30 19:53:292// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]de7d61ff2013-08-20 11:30:415#include "content/shell/browser/shell_javascript_dialog.h"
[email protected]7fc83822012-03-30 19:53:296
Avi Drissmane04d3992017-10-05 15:11:367#include <utility>
8
[email protected]21aa99682013-06-11 07:17:019#include "base/strings/string_util.h"
Jan Wilken Dörrie86069892021-02-23 17:09:1310#include "base/strings/utf_string_conversions.h"
[email protected]993951d2013-05-08 21:37:0211#include "content/shell/app/resource.h"
[email protected]de7d61ff2013-08-20 11:30:4112#include "content/shell/browser/shell.h"
13#include "content/shell/browser/shell_javascript_dialog_manager.h"
[email protected]7fc83822012-03-30 19:53:2914
Bruce Dawsonbdea9d662021-06-23 17:34:1515#include <windows.h>
16
[email protected]7fc83822012-03-30 19:53:2917namespace content {
18
19class ShellJavaScriptDialog;
20
[email protected]be2510c02012-05-28 14:52:1421INT_PTR CALLBACK ShellJavaScriptDialog::DialogProc(HWND dialog,
22 UINT message,
[email protected]7fc83822012-03-30 19:53:2923 WPARAM wparam,
24 LPARAM lparam) {
25 switch (message) {
26 case WM_INITDIALOG: {
[email protected]3bed5302013-02-15 19:31:4127 SetWindowLongPtr(dialog, DWLP_USER, static_cast<LONG_PTR>(lparam));
[email protected]7fc83822012-03-30 19:53:2928 ShellJavaScriptDialog* owner =
29 reinterpret_cast<ShellJavaScriptDialog*>(lparam);
30 owner->dialog_win_ = dialog;
Jan Wilken Dörrie86069892021-02-23 17:09:1331 SetDlgItemText(dialog, IDC_DIALOGTEXT,
32 base::as_wcstr(owner->message_text_));
avi777ff452017-02-09 19:04:4833 if (owner->dialog_type_ == JAVASCRIPT_DIALOG_TYPE_PROMPT)
[email protected]7fc83822012-03-30 19:53:2934 SetDlgItemText(dialog, IDC_PROMPTEDIT,
Jan Wilken Dörrie86069892021-02-23 17:09:1335 base::as_wcstr(owner->default_prompt_text_));
[email protected]7fc83822012-03-30 19:53:2936 break;
37 }
38 case WM_DESTROY: {
39 ShellJavaScriptDialog* owner = reinterpret_cast<ShellJavaScriptDialog*>(
[email protected]3bed5302013-02-15 19:31:4140 GetWindowLongPtr(dialog, DWLP_USER));
[email protected]7fc83822012-03-30 19:53:2941 if (owner->dialog_win_) {
42 owner->dialog_win_ = 0;
Jan Wilken Dörrieaace0cfef2021-03-11 22:01:5843 std::move(owner->callback_).Run(false, std::u16string());
[email protected]71a88bb2013-02-01 22:05:1544 owner->manager_->DialogClosed(owner);
[email protected]7fc83822012-03-30 19:53:2945 }
46 break;
47 }
48 case WM_COMMAND: {
49 ShellJavaScriptDialog* owner = reinterpret_cast<ShellJavaScriptDialog*>(
[email protected]3bed5302013-02-15 19:31:4150 GetWindowLongPtr(dialog, DWLP_USER));
Jan Wilken Dörrie86069892021-02-23 17:09:1351 std::wstring user_input;
[email protected]7fc83822012-03-30 19:53:2952 bool finish = false;
tzikb7d06d52016-02-20 08:21:2853 bool result = false;
[email protected]7fc83822012-03-30 19:53:2954 switch (LOWORD(wparam)) {
55 case IDOK:
56 finish = true;
57 result = true;
avi777ff452017-02-09 19:04:4858 if (owner->dialog_type_ == JAVASCRIPT_DIALOG_TYPE_PROMPT) {
[email protected]3bed5302013-02-15 19:31:4159 int length =
[email protected]7fc83822012-03-30 19:53:2960 GetWindowTextLength(GetDlgItem(dialog, IDC_PROMPTEDIT)) + 1;
61 GetDlgItemText(dialog, IDC_PROMPTEDIT,
Brett Wilsone3c4d1a2015-07-07 23:38:0962 base::WriteInto(&user_input, length), length);
[email protected]7fc83822012-03-30 19:53:2963 }
64 break;
65 case IDCANCEL:
66 finish = true;
67 result = false;
68 break;
69 }
70 if (finish) {
71 owner->dialog_win_ = 0;
Jan Wilken Dörrie