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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/guestview/webview/javascript_dialog_helper.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "base/values.h"
9 #include "chrome/browser/guestview/guestview_constants.h"
10 #include "chrome/browser/guestview/webview/webview_constants.h"
11 #include "chrome/browser/guestview/webview/webview_guest.h"
12 #include "chrome/browser/guestview/webview/webview_permission_types.h"
13
14 namespace {
15
16 std::string JavaScriptMessageTypeToString(
17 content::JavaScriptMessageType message_type) {
18 switch (message_type) {
19 case content::JAVASCRIPT_MESSAGE_TYPE_ALERT:
20 return "alert";
21 case content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM:
22 return "confirm";
23 case content::JAVASCRIPT_MESSAGE_TYPE_PROMPT:
24 return "prompt";
25 default:
26 NOTREACHED() << "Unknown JavaScript Message Type.";
27 return "unknown";
28 }
29 }
30
31 } // namespace
32
33 JavaScriptDialogHelper::JavaScriptDialogHelper(WebViewGuest* guest)
34 : webview_guest_(guest) {
35 }
36
37 JavaScriptDialogHelper::~JavaScriptDialogHelper() {
38 }
39
40 void JavaScriptDialogHelper::RunJavaScriptDialog(
41 content::WebContents* web_contents,
42 const GURL& origin_url,
43 const std::string& accept_lang,
44 content::JavaScriptMessageType javascript_message_type,
45 const base::string16& message_text,
46 const base::string16& default_prompt_text,
47 const DialogClosedCallback& callback,
48 bool* did_suppress_message) {
49 base::DictionaryValue request_info;
50 request_info.Set(
51 webview::kDefaultPromptText,
52 base::Value::CreateStringValue(base::UTF16ToUTF8(default_prompt_text)));
53 request_info.Set(
54 webview::kMessageText,
55 base::Value::CreateStringValue(base::UTF16ToUTF8(message_text)));
56 request_info.Set(
57 webview::kMessageType,
58 base::Value::CreateStringValue(
59 JavaScriptMessageTypeToString(javascript_message_type)));
60 request_info.Set(
61 guestview::kUrl,
62 base::Value::CreateStringValue(origin_url.spec()));
63 webview_guest_->RequestPermission(
64 static_cast<BrowserPluginPermissionType>(
65 WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG),
66 request_info,
67 base::Bind(&JavaScriptDialogHelper::OnPermissionResponse,
68 base::Unretained(this),
69 callback),
70 false /* allowed_by_default */);
71 }
72
73 void JavaScriptDialogHelper::RunBeforeUnloadDialog(
74 content::WebContents* web_contents,
75 const base::string16& message_text,
76 bool is_reload,
77 const DialogClosedCallback& callback) {
78 // This is called if the guest has a beforeunload event handler.
79 // This callback allows navigation to proceed.
80 callback.Run(true, base::string16());
81 }
82
83 bool JavaScriptDialogHelper::HandleJavaScriptDialog(
84 content::WebContents* web_contents,
85 bool accept,
86 const base::string16* prompt_override) {
87 return false;
88 }
89
90 void JavaScriptDialogHelper::CancelActiveAndPendingDialogs(
91 content::WebContents* web_contents) {
92 }
93
94 void JavaScriptDialogHelper::WebContentsDestroyed(
95 content::WebContents* web_contents) {
96 }
97
98 void JavaScriptDialogHelper::OnPermissionResponse(
99 const DialogClosedCallback& callback,
100 bool allow,
101 const std::string& user_input) {
102 callback.Run(allow && webview_guest_->attached(),
103 base::UTF8ToUTF16(user_input));
104 }
OLDNEW
« 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