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

Unified Diff: chrome/browser/guestview/webview/javascript_dialog_helper.cc

Issue 239143007: <webview>: Move JavaScript Dialog API to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_pointer_lock_to_chrome
Patch Set: Addressed nits Created 6 years, 8 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: chrome/browser/guestview/webview/javascript_dialog_helper.cc
diff --git a/chrome/browser/guestview/webview/javascript_dialog_helper.cc b/chrome/browser/guestview/webview/javascript_dialog_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8173f062dfb0d6e768daeed78cf337cfa8bafb33
--- /dev/null
+++ b/chrome/browser/guestview/webview/javascript_dialog_helper.cc
@@ -0,0 +1,104 @@
+// Copyright 2014 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 "chrome/browser/guestview/webview/javascript_dialog_helper.h"
+
+#include "base/strings/utf_string_conversions.h"
+#include "base/values.h"
+#include "chrome/browser/guestview/guestview_constants.h"
+#include "chrome/browser/guestview/webview/webview_constants.h"
+#include "chrome/browser/guestview/webview/webview_guest.h"
+#include "chrome/browser/guestview/webview/webview_permission_types.h"
+
+namespace {
+
+std::string JavaScriptMessageTypeToString(
+ content::JavaScriptMessageType message_type) {
+ switch (message_type) {
+ case content::JAVASCRIPT_MESSAGE_TYPE_ALERT:
+ return "alert";
+ case content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM:
+ return "confirm";
+ case content::JAVASCRIPT_MESSAGE_TYPE_PROMPT:
+ return "prompt";
+ default:
+ NOTREACHED() << "Unknown JavaScript Message Type.";
+ return "unknown";
+ }
+}
+
+} // namespace
+
+JavaScriptDialogHelper::JavaScriptDialogHelper(WebViewGuest* guest)
+ : webview_guest_(guest) {
+}
+
+JavaScriptDialogHelper::~JavaScriptDialogHelper() {
+}
+
+void JavaScriptDialogHelper::RunJavaScriptDialog(
+ content::WebContents* web_contents,
+ const GURL& origin_url,
+ const std::string& accept_lang,
+ content::JavaScriptMessageType javascript_message_type,
+ const base::string16& message_text,
+ const base::string16& default_prompt_text,
+ const DialogClosedCallback& callback,
+ bool* did_suppress_message) {
+ base::DictionaryValue request_info;
+ request_info.Set(
+ webview::kDefaultPromptText,
+ base::Value::CreateStringValue(base::UTF16ToUTF8(default_prompt_text)));
+ request_info.Set(
+ webview::kMessageText,
+ base::Value::CreateStringValue(base::UTF16ToUTF8(message_text)));
+ request_info.Set(
+ webview::kMessageType,
+ base::Value::CreateStringValue(
+ JavaScriptMessageTypeToString(javascript_message_type)));
+ request_info.Set(
+ guestview::kUrl,
+ base::Value::CreateStringValue(origin_url.spec()));
+ webview_guest_->RequestPermission(
+ static_cast<BrowserPluginPermissionType>(
+ WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG),
+ request_info,
+ base::Bind(&JavaScriptDialogHelper::OnPermissionResponse,
+ base::Unretained(this),
+ callback),
+ false /* allowed_by_default */);
+}
+
+void JavaScriptDialogHelper::RunBeforeUnloadDialog(
+ content::WebContents* web_contents,
+ const base::string16& message_text,
+ bool is_reload,
+ const DialogClosedCallback& callback) {
+ // This is called if the guest has a beforeunload event handler.
+ // This callback allows navigation to proceed.
+ callback.Run(true, base::string16());
+}
+
+bool JavaScriptDialogHelper::HandleJavaScriptDialog(
+ content::WebContents* web_contents,
+ bool accept,
+ const base::string16* prompt_override) {
+ return false;
+}
+
+void JavaScriptDialogHelper::CancelActiveAndPendingDialogs(
+ content::WebContents* web_contents) {
+}
+
+void JavaScriptDialogHelper::WebContentsDestroyed(
+ content::WebContents* web_contents) {
+}
+
+void JavaScriptDialogHelper::OnPermissionResponse(
+ const DialogClosedCallback& callback,
+ bool allow,
+ const std::string& user_input) {
+ callback.Run(allow && webview_guest_->attached(),
+ base::UTF8ToUTF16(user_input));
+}
« no previous file with comments | « chrome/browser/guestview/webview/javascript_dialog_helper.h ('k') | chrome/browser/guestview/webview/webview_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698