OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/shell_javascript_dialog_creator.h" | 5 #include "content/shell/shell_javascript_dialog_creator.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "content/shell/shell_javascript_dialog.h" | 9 #include "content/shell/shell_javascript_dialog.h" |
10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 ShellJavaScriptDialogCreator::ShellJavaScriptDialogCreator() { | 14 ShellJavaScriptDialogCreator::ShellJavaScriptDialogCreator() { |
15 } | 15 } |
16 | 16 |
17 ShellJavaScriptDialogCreator::~ShellJavaScriptDialogCreator() { | 17 ShellJavaScriptDialogCreator::~ShellJavaScriptDialogCreator() { |
18 } | 18 } |
19 | 19 |
20 void ShellJavaScriptDialogCreator::RunJavaScriptDialog( | 20 void ShellJavaScriptDialogCreator::RunJavaScriptDialog( |
21 WebContents* web_contents, | 21 WebContents* web_contents, |
22 const GURL& origin_url, | 22 const GURL& origin_url, |
23 const std::string& accept_lang, | 23 const std::string& accept_lang, |
24 ui::JavascriptMessageType javascript_message_type, | 24 ui::JavascriptMessageType javascript_message_type, |
25 const string16& message_text, | 25 const string16& message_text, |
26 const string16& default_prompt_text, | 26 const string16& default_prompt_text, |
27 const DialogClosedCallback& callback, | 27 const DialogClosedCallback& callback, |
28 bool* did_suppress_message) { | 28 bool* did_suppress_message) { |
29 #if defined(OS_MACOSX) | 29 #if defined(OS_MACOSX) || defined(OS_WIN) |
30 *did_suppress_message = false; | 30 *did_suppress_message = false; |
31 | 31 |
32 if (dialog_.get()) { | 32 if (dialog_.get()) { |
33 // One dialog at a time, please. | 33 // One dialog at a time, please. |
34 *did_suppress_message = true; | 34 *did_suppress_message = true; |
35 return; | 35 return; |
36 } | 36 } |
37 | 37 |
38 string16 new_message_text = net::FormatUrl(origin_url, accept_lang) + | 38 string16 new_message_text = net::FormatUrl(origin_url, accept_lang) + |
39 ASCIIToUTF16("\n\n") + | 39 ASCIIToUTF16("\n\n") + |
40 message_text; | 40 message_text; |
41 | 41 |
42 dialog_.reset(new ShellJavaScriptDialog(this, | 42 dialog_.reset(new ShellJavaScriptDialog(this, |
43 javascript_message_type, | 43 javascript_message_type, |
44 new_message_text, | 44 new_message_text, |
45 default_prompt_text, | 45 default_prompt_text, |
46 callback)); | 46 callback)); |
47 #else | 47 #else |
48 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 48 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
49 *did_suppress_message = true; | 49 *did_suppress_message = true; |
50 return; | 50 return; |
51 #endif | 51 #endif |
52 } | 52 } |
53 | 53 |
54 void ShellJavaScriptDialogCreator::RunBeforeUnloadDialog( | 54 void ShellJavaScriptDialogCreator::RunBeforeUnloadDialog( |
55 WebContents* web_contents, | 55 WebContents* web_contents, |
56 const string16& message_text, | 56 const string16& message_text, |
57 bool is_reload, | 57 bool is_reload, |
58 const DialogClosedCallback& callback) { | 58 const DialogClosedCallback& callback) { |
59 #if defined(OS_MACOSX) | 59 #if defined(OS_MACOSX) || defined(OS_WIN) |
60 if (dialog_.get()) { | 60 if (dialog_.get()) { |
61 // Seriously!? | 61 // Seriously!? |
62 callback.Run(true, string16()); | 62 callback.Run(true, string16()); |
63 return; | 63 return; |
64 } | 64 } |
65 | 65 |
66 string16 new_message_text = | 66 string16 new_message_text = |
67 message_text + | 67 message_text + |
68 ASCIIToUTF16("\n\nIs it OK to leave/reload this page?"); | 68 ASCIIToUTF16("\n\nIs it OK to leave/reload this page?"); |
69 | 69 |
70 dialog_.reset(new ShellJavaScriptDialog(this, | 70 dialog_.reset(new ShellJavaScriptDialog(this, |
71 ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM, | 71 ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM, |
72 new_message_text, | 72 new_message_text, |
73 string16(), // default_prompt_text | 73 string16(), // default_prompt_text |
74 callback)); | 74 callback)); |
75 #else | 75 #else |
76 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 76 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
77 callback.Run(true, string16()); | 77 callback.Run(true, string16()); |
78 return; | 78 return; |
79 #endif | 79 #endif |
80 } | 80 } |
81 | 81 |
82 void ShellJavaScriptDialogCreator::ResetJavaScriptState( | 82 void ShellJavaScriptDialogCreator::ResetJavaScriptState( |
83 WebContents* web_contents) { | 83 WebContents* web_contents) { |
84 #if defined(OS_MACOSX) | 84 #if defined(OS_MACOSX) || defined(OS_WIN) |
85 if (dialog_.get()) { | 85 if (dialog_.get()) { |
86 dialog_->Cancel(); | 86 dialog_->Cancel(); |
87 dialog_.reset(); | 87 dialog_.reset(); |
88 } | 88 } |
89 #else | 89 #else |
90 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 90 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
91 #endif | 91 #endif |
92 } | 92 } |
93 | 93 |
94 void ShellJavaScriptDialogCreator::DialogClosed(ShellJavaScriptDialog* dialog) { | 94 void ShellJavaScriptDialogCreator::DialogClosed(ShellJavaScriptDialog* dialog) { |
95 #if defined(OS_MACOSX) | 95 #if defined(OS_MACOSX) || defined(OS_WIN) |
96 DCHECK_EQ(dialog, dialog_.get()); | 96 DCHECK_EQ(dialog, dialog_.get()); |
97 dialog_.reset(); | 97 dialog_.reset(); |
98 #else | 98 #else |
99 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if | 99 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if |
100 #endif | 100 #endif |
101 } | 101 } |
102 | 102 |
103 } // namespace content | 103 } // namespace content |
OLD | NEW |