| Index: chrome/browser/guest_view/web_view/javascript_dialog_helper.cc
|
| diff --git a/chrome/browser/guest_view/web_view/javascript_dialog_helper.cc b/chrome/browser/guest_view/web_view/javascript_dialog_helper.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6fe90b1b4f45c78269151998d03e549e4372210a
|
| --- /dev/null
|
| +++ b/chrome/browser/guest_view/web_view/javascript_dialog_helper.cc
|
| @@ -0,0 +1,106 @@
|
| +// 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/guest_view/web_view/javascript_dialog_helper.h"
|
| +
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "base/values.h"
|
| +#include "chrome/browser/guest_view/web_view/web_view_constants.h"
|
| +#include "chrome/browser/guest_view/web_view/web_view_guest.h"
|
| +#include "chrome/browser/guest_view/web_view/web_view_permission_helper.h"
|
| +#include "chrome/browser/guest_view/web_view/web_view_permission_types.h"
|
| +#include "extensions/browser/guest_view/guest_view_constants.h"
|
| +
|
| +namespace extensions {
|
| +
|
| +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)
|
| + : web_view_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,
|
| + new base::StringValue(base::UTF16ToUTF8(default_prompt_text)));
|
| + request_info.Set(webview::kMessageText,
|
| + new base::StringValue(base::UTF16ToUTF8(message_text)));
|
| + request_info.Set(webview::kMessageType,
|
| + new base::StringValue(
|
| + JavaScriptMessageTypeToString(javascript_message_type)));
|
| + request_info.Set(guestview::kUrl, new base::StringValue(origin_url.spec()));
|
| + WebViewPermissionHelper* web_view_permission_helper =
|
| + WebViewPermissionHelper::FromWebContents(web_contents);
|
| + web_view_permission_helper->RequestPermission(
|
| + 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 && web_view_guest_->attached(),
|
| + base::UTF8ToUTF16(user_input));
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|