| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/guest_view/web_view/javascript_dialog_helper.h" | 5 #include "chrome/browser/guest_view/web_view/javascript_dialog_helper.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/guest_view/guest_view_constants.h" | 9 #include "chrome/browser/guest_view/guest_view_constants.h" |
| 10 #include "chrome/browser/guest_view/web_view/web_view_constants.h" | 10 #include "chrome/browser/guest_view/web_view/web_view_constants.h" |
| 11 #include "chrome/browser/guest_view/web_view/web_view_guest.h" | 11 #include "chrome/browser/guest_view/web_view/web_view_guest.h" |
| 12 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" |
| 12 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" | 13 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 std::string JavaScriptMessageTypeToString( | 17 std::string JavaScriptMessageTypeToString( |
| 17 content::JavaScriptMessageType message_type) { | 18 content::JavaScriptMessageType message_type) { |
| 18 switch (message_type) { | 19 switch (message_type) { |
| 19 case content::JAVASCRIPT_MESSAGE_TYPE_ALERT: | 20 case content::JAVASCRIPT_MESSAGE_TYPE_ALERT: |
| 20 return "alert"; | 21 return "alert"; |
| 21 case content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM: | 22 case content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM: |
| 22 return "confirm"; | 23 return "confirm"; |
| 23 case content::JAVASCRIPT_MESSAGE_TYPE_PROMPT: | 24 case content::JAVASCRIPT_MESSAGE_TYPE_PROMPT: |
| 24 return "prompt"; | 25 return "prompt"; |
| 25 default: | 26 default: |
| 26 NOTREACHED() << "Unknown JavaScript Message Type."; | 27 NOTREACHED() << "Unknown JavaScript Message Type."; |
| 27 return "unknown"; | 28 return "unknown"; |
| 28 } | 29 } |
| 29 } | 30 } |
| 30 | 31 |
| 31 } // namespace | 32 } // namespace |
| 32 | 33 |
| 33 JavaScriptDialogHelper::JavaScriptDialogHelper(WebViewGuest* guest) | 34 JavaScriptDialogHelper::JavaScriptDialogHelper(WebViewGuest* guest) |
| 34 : webview_guest_(guest) { | 35 : web_view_guest_(guest) { |
| 35 } | 36 } |
| 36 | 37 |
| 37 JavaScriptDialogHelper::~JavaScriptDialogHelper() { | 38 JavaScriptDialogHelper::~JavaScriptDialogHelper() { |
| 38 } | 39 } |
| 39 | 40 |
| 40 void JavaScriptDialogHelper::RunJavaScriptDialog( | 41 void JavaScriptDialogHelper::RunJavaScriptDialog( |
| 41 content::WebContents* web_contents, | 42 content::WebContents* web_contents, |
| 42 const GURL& origin_url, | 43 const GURL& origin_url, |
| 43 const std::string& accept_lang, | 44 const std::string& accept_lang, |
| 44 content::JavaScriptMessageType javascript_message_type, | 45 content::JavaScriptMessageType javascript_message_type, |
| 45 const base::string16& message_text, | 46 const base::string16& message_text, |
| 46 const base::string16& default_prompt_text, | 47 const base::string16& default_prompt_text, |
| 47 const DialogClosedCallback& callback, | 48 const DialogClosedCallback& callback, |
| 48 bool* did_suppress_message) { | 49 bool* did_suppress_message) { |
| 49 base::DictionaryValue request_info; | 50 base::DictionaryValue request_info; |
| 50 request_info.Set( | 51 request_info.Set( |
| 51 webview::kDefaultPromptText, | 52 webview::kDefaultPromptText, |
| 52 base::Value::CreateStringValue(base::UTF16ToUTF8(default_prompt_text))); | 53 base::Value::CreateStringValue(base::UTF16ToUTF8(default_prompt_text))); |
| 53 request_info.Set( | 54 request_info.Set( |
| 54 webview::kMessageText, | 55 webview::kMessageText, |
| 55 base::Value::CreateStringValue(base::UTF16ToUTF8(message_text))); | 56 base::Value::CreateStringValue(base::UTF16ToUTF8(message_text))); |
| 56 request_info.Set( | 57 request_info.Set( |
| 57 webview::kMessageType, | 58 webview::kMessageType, |
| 58 base::Value::CreateStringValue( | 59 base::Value::CreateStringValue( |
| 59 JavaScriptMessageTypeToString(javascript_message_type))); | 60 JavaScriptMessageTypeToString(javascript_message_type))); |
| 60 request_info.Set( | 61 request_info.Set( |
| 61 guestview::kUrl, | 62 guestview::kUrl, |
| 62 base::Value::CreateStringValue(origin_url.spec())); | 63 base::Value::CreateStringValue(origin_url.spec())); |
| 63 webview_guest_->RequestPermission( | 64 WebViewPermissionHelper* web_view_permission_helper = |
| 65 WebViewPermissionHelper::FromWebContents(web_contents); |
| 66 web_view_permission_helper->RequestPermission( |
| 64 WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG, | 67 WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG, |
| 65 request_info, | 68 request_info, |
| 66 base::Bind(&JavaScriptDialogHelper::OnPermissionResponse, | 69 base::Bind(&JavaScriptDialogHelper::OnPermissionResponse, |
| 67 base::Unretained(this), | 70 base::Unretained(this), |
| 68 callback), | 71 callback), |
| 69 false /* allowed_by_default */); | 72 false /* allowed_by_default */); |
| 70 } | 73 } |
| 71 | 74 |
| 72 void JavaScriptDialogHelper::RunBeforeUnloadDialog( | 75 void JavaScriptDialogHelper::RunBeforeUnloadDialog( |
| 73 content::WebContents* web_contents, | 76 content::WebContents* web_contents, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 91 } | 94 } |
| 92 | 95 |
| 93 void JavaScriptDialogHelper::WebContentsDestroyed( | 96 void JavaScriptDialogHelper::WebContentsDestroyed( |
| 94 content::WebContents* web_contents) { | 97 content::WebContents* web_contents) { |
| 95 } | 98 } |
| 96 | 99 |
| 97 void JavaScriptDialogHelper::OnPermissionResponse( | 100 void JavaScriptDialogHelper::OnPermissionResponse( |
| 98 const DialogClosedCallback& callback, | 101 const DialogClosedCallback& callback, |
| 99 bool allow, | 102 bool allow, |
| 100 const std::string& user_input) { | 103 const std::string& user_input) { |
| 101 callback.Run(allow && webview_guest_->attached(), | 104 callback.Run(allow && web_view_guest_->attached(), |
| 102 base::UTF8ToUTF16(user_input)); | 105 base::UTF8ToUTF16(user_input)); |
| 103 } | 106 } |
| OLD | NEW |