Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3216)

Unified Diff: content/shell/shell_js_dialog_creator.cc

Issue 9836127: Content shell: Javascript dialogs, first pass, just Mac for now. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/shell/shell_js_dialog_creator.cc
diff --git a/content/shell/shell_js_dialog_creator.cc b/content/shell/shell_js_dialog_creator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c2d9d28ab17bec79fe1f8ab8032824445b2878ab
--- /dev/null
+++ b/content/shell/shell_js_dialog_creator.cc
@@ -0,0 +1,95 @@
+// 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_js_dialog_creator.h"
+
+#include "base/logging.h"
+#include "base/utf_string_conversions.h"
+#include "content/shell/shell_js_dialog.h"
+#include "net/base/net_util.h"
+
+namespace content {
+
+ShellJavaScriptDialogCreator::ShellJavaScriptDialogCreator() {
+}
+
+ShellJavaScriptDialogCreator::~ShellJavaScriptDialogCreator() {
+}
+
+void ShellJavaScriptDialogCreator::RunJavaScriptDialog(
+ WebContents* web_contents,
+ const GURL& origin_url,
+ const std::string& accept_lang,
+ ui::JavascriptMessageType javascript_message_type,
+ const string16& message_text,
+ const string16& default_prompt_text,
+ const DialogClosedCallback& callback,
+ bool* did_suppress_message) {
+#if defined(OS_MACOSX)
+ *did_suppress_message = false;
+
+ if (dialog_.get()) {
+ // One dialog at a time, please.
+ *did_suppress_message = true;
+ return;
+ }
+
+ string16 new_message_text = net::FormatUrl(origin_url, accept_lang) +
+ ASCIIToUTF16("\n\n") +
+ message_text;
+
+ dialog_.reset(new ShellJavaScriptDialog(this,
+ javascript_message_type,
+ new_message_text,
+ default_prompt_text,
+ callback));
+#else
+ // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if
+ *did_suppress_message = true;
+ return;
+#endif
+}
+
+void ShellJavaScriptDialogCreator::RunBeforeUnloadDialog(
+ WebContents* web_contents,
+ const string16& message_text,
+ bool is_reload,
+ const DialogClosedCallback& callback) {
+#if defined(OS_MACOSX)
+ if (dialog_.get()) {
+ // Seriously!?
+ callback.Run(true, string16());
+ return;
+ }
+
+ string16 new_message_text =
+ message_text +
+ ASCIIToUTF16("\n\nIs it OK to leave/reload this page?");
+
+ dialog_.reset(new ShellJavaScriptDialog(this,
+ ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
+ new_message_text,
+ string16(), // default_prompt_text
+ callback));
+#else
+ // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if
+ callback.Run(true, string16());
+ return;
+#endif
+}
+
+void ShellJavaScriptDialogCreator::ResetJavaScriptState(
+ WebContents* web_contents) {
+ if (dialog_.get()) {
+ dialog_->Cancel();
+ dialog_.reset();
+ }
+}
+
+void ShellJavaScriptDialogCreator::DialogClosed(ShellJavaScriptDialog* dialog) {
+ DCHECK_EQ(dialog, dialog_.get());
+ dialog_.reset();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698