Chromium Code Reviews| 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..1211fd37b093a7e6be8a0e5ca7bb10711fcdf015 |
| --- /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, |
|
lazyboy
2014/04/16 14:41:44
indent. I see all the params in this file unindent
Fady Samuel
2014/04/16 18:34:39
Done.
|
| + 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)); |
| +} |