1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/shell/browser/shell_javascript_dialog_manager.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/shell/browser/blink_test_controller.h"
12 #include "content/shell/browser/shell_javascript_dialog.h"
13 #include "content/shell/common/shell_switches.h"
14 #include "net/base/net_util.h"
18 ShellJavaScriptDialogManager::ShellJavaScriptDialogManager() {
21 ShellJavaScriptDialogManager::~ShellJavaScriptDialogManager() {
24 void ShellJavaScriptDialogManager::RunJavaScriptDialog(
25 WebContents
* web_contents
,
26 const GURL
& origin_url
,
27 const std::string
& accept_lang
,
28 JavaScriptMessageType javascript_message_type
,
29 const base::string16
& message_text
,
30 const base::string16
& default_prompt_text
,
31 const DialogClosedCallback
& callback
,
32 bool* did_suppress_message
) {
33 if (!dialog_request_callback_
.is_null()) {
34 dialog_request_callback_
.Run();
35 callback
.Run(true, base::string16());
36 dialog_request_callback_
.Reset();
40 #if defined(OS_MACOSX) || defined(OS_WIN)
41 *did_suppress_message
= false;
44 // One dialog at a time, please.
45 *did_suppress_message
= true;
49 base::string16 new_message_text
= net::FormatUrl(origin_url
, accept_lang
) +
50 base::ASCIIToUTF16("\n\n") +
52 gfx::NativeWindow parent_window
= web_contents
->GetTopLevelNativeWindow();
54 dialog_
.reset(new ShellJavaScriptDialog(this,
56 javascript_message_type
,
61 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if
62 *did_suppress_message
= true;
67 void ShellJavaScriptDialogManager::RunBeforeUnloadDialog(
68 WebContents
* web_contents
,
69 const base::string16
& message_text
,
71 const DialogClosedCallback
& callback
) {
72 if (!dialog_request_callback_
.is_null()) {
73 dialog_request_callback_
.Run();
74 callback
.Run(true, base::string16());
75 dialog_request_callback_
.Reset();
79 #if defined(OS_MACOSX) || defined(OS_WIN)
82 callback
.Run(true, base::string16());
86 base::string16 new_message_text
=
88 base::ASCIIToUTF16("\n\nIs it OK to leave/reload this page?");
90 gfx::NativeWindow parent_window
= web_contents
->GetTopLevelNativeWindow();
92 dialog_
.reset(new ShellJavaScriptDialog(this,
94 JAVASCRIPT_MESSAGE_TYPE_CONFIRM
,
96 base::string16(), // default
99 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if
100 callback
.Run(true, base::string16());
105 void ShellJavaScriptDialogManager::CancelActiveAndPendingDialogs(
106 WebContents
* web_contents
) {
107 #if defined(OS_MACOSX) || defined(OS_WIN)
113 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if
117 void ShellJavaScriptDialogManager::ResetDialogState(WebContents
* web_contents
) {
120 void ShellJavaScriptDialogManager::DialogClosed(ShellJavaScriptDialog
* dialog
) {
121 #if defined(OS_MACOSX) || defined(OS_WIN)
122 DCHECK_EQ(dialog
, dialog_
.get());
125 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if
129 } // namespace content