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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/browser_plugin/browser_plugin_guest.h" 5 #include "content/browser/browser_plugin/browser_plugin_guest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // If we do not destroy the guest then we allow the new window. 113 // If we do not destroy the guest then we allow the new window.
114 if (!should_allow) 114 if (!should_allow)
115 guest->Destroy(); 115 guest->Destroy();
116 } 116 }
117 117
118 private: 118 private:
119 virtual ~NewWindowRequest() {} 119 virtual ~NewWindowRequest() {}
120 int instance_id_; 120 int instance_id_;
121 }; 121 };
122 122
123 class BrowserPluginGuest::JavaScriptDialogRequest : public PermissionRequest {
124 public:
125 JavaScriptDialogRequest(const base::WeakPtr<BrowserPluginGuest>& guest,
126 const DialogClosedCallback& callback)
127 : PermissionRequest(guest),
128 callback_(callback) {
129 RecordAction(
130 base::UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.JSDialog" ));
131 }
132
133 virtual void RespondImpl(bool should_allow,
134 const std::string& user_input) OVERRIDE {
135 callback_.Run(should_allow, base::UTF8ToUTF16(user_input));
136 }
137
138 private:
139 virtual ~JavaScriptDialogRequest() {}
140 DialogClosedCallback callback_;
141 };
142
143 namespace { 123 namespace {
144 std::string WindowOpenDispositionToString( 124 std::string WindowOpenDispositionToString(
145 WindowOpenDisposition window_open_disposition) { 125 WindowOpenDisposition window_open_disposition) {
146 switch (window_open_disposition) { 126 switch (window_open_disposition) {
147 case IGNORE_ACTION: 127 case IGNORE_ACTION:
148 return "ignore"; 128 return "ignore";
149 case SAVE_TO_DISK: 129 case SAVE_TO_DISK:
150 return "save_to_disk"; 130 return "save_to_disk";
151 case CURRENT_TAB: 131 case CURRENT_TAB:
152 return "current_tab"; 132 return "current_tab";
153 case NEW_BACKGROUND_TAB: 133 case NEW_BACKGROUND_TAB:
154 return "new_background_tab"; 134 return "new_background_tab";
155 case NEW_FOREGROUND_TAB: 135 case NEW_FOREGROUND_TAB:
156 return "new_foreground_tab"; 136 return "new_foreground_tab";
157 case NEW_WINDOW: 137 case NEW_WINDOW:
158 return "new_window"; 138 return "new_window";
159 case NEW_POPUP: 139 case NEW_POPUP:
160 return "new_popup"; 140 return "new_popup";
161 default: 141 default:
162 NOTREACHED() << "Unknown Window Open Disposition"; 142 NOTREACHED() << "Unknown Window Open Disposition";
163 return "ignore"; 143 return "ignore";
164 } 144 }
165 } 145 }
166 146
167 std::string JavaScriptMessageTypeToString(JavaScriptMessageType message_type) {
168 switch (message_type) {
169 case JAVASCRIPT_MESSAGE_TYPE_ALERT:
170 return "alert";
171 case JAVASCRIPT_MESSAGE_TYPE_CONFIRM:
172 return "confirm";
173 case JAVASCRIPT_MESSAGE_TYPE_PROMPT:
174 return "prompt";
175 default:
176 NOTREACHED() << "Unknown JavaScript Message Type.";
177 return "unknown";
178 }
179 }
180
181 // Called on IO thread. 147 // Called on IO thread.
182 static GURL RetrieveDownloadURLFromRequestId( 148 static GURL RetrieveDownloadURLFromRequestId(
183 int render_process_id, 149 int render_process_id,
184 int url_request_id) { 150 int url_request_id) {
185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
186 152
187 GlobalRequestID global_id(render_process_id, url_request_id); 153 GlobalRequestID global_id(render_process_id, url_request_id);
188 net::URLRequest* url_request = 154 net::URLRequest* url_request =
189 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); 155 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id);
190 if (url_request) 156 if (url_request)
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 } 622 }
657 623
658 void BrowserPluginGuest::CloseContents(WebContents* source) { 624 void BrowserPluginGuest::CloseContents(WebContents* source) {
659 if (!delegate_) 625 if (!delegate_)
660 return; 626 return;
661 627
662 delegate_->Close(); 628 delegate_->Close();
663 } 629 }
664 630
665 JavaScriptDialogManager* BrowserPluginGuest::GetJavaScriptDialogManager() { 631 JavaScriptDialogManager* BrowserPluginGuest::GetJavaScriptDialogManager() {
666 return this; 632 if (!delegate_)
633 return NULL;
634 return delegate_->GetJavaScriptDialogManager();
667 } 635 }
668 636
669 ColorChooser* BrowserPluginGuest::OpenColorChooser( 637 ColorChooser* BrowserPluginGuest::OpenColorChooser(
670 WebContents* web_contents, 638 WebContents* web_contents,
671 SkColor color, 639 SkColor color,
672 const std::vector<ColorSuggestion>& suggestions) { 640 const std::vector<ColorSuggestion>& suggestions) {
673 if (!embedder_web_contents_ || !embedder_web_contents_->GetDelegate()) 641 if (!embedder_web_contents_ || !embedder_web_contents_->GetDelegate())
674 return NULL; 642 return NULL;
675 return embedder_web_contents_->GetDelegate()->OpenColorChooser( 643 return embedder_web_contents_->GetDelegate()->OpenColorChooser(
676 web_contents, color, suggestions); 644 web_contents, color, suggestions);
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
1556 delegate_->RequestMediaAccessPermission(request, callback); 1524 delegate_->RequestMediaAccessPermission(request, callback);
1557 } 1525 }
1558 1526
1559 bool BrowserPluginGuest::PreHandleGestureEvent( 1527 bool BrowserPluginGuest::PreHandleGestureEvent(
1560 WebContents* source, const blink::WebGestureEvent& event) { 1528 WebContents* source, const blink::WebGestureEvent& event) {
1561 return event.type == blink::WebGestureEvent::GesturePinchBegin || 1529 return event.type == blink::WebGestureEvent::GesturePinchBegin ||
1562 event.type == blink::WebGestureEvent::GesturePinchUpdate || 1530 event.type == blink::WebGestureEvent::GesturePinchUpdate ||
1563 event.type == blink::WebGestureEvent::GesturePinchEnd; 1531 event.type == blink::WebGestureEvent::GesturePinchEnd;
1564 } 1532 }
1565 1533
1566 void BrowserPluginGuest::RunJavaScriptDialog(
1567 WebContents* web_contents,
1568 const GURL& origin_url,
1569 const std::string& accept_lang,
1570 JavaScriptMessageType javascript_message_type,
1571 const base::string16& message_text,
1572 const base::string16& default_prompt_text,
1573 const DialogClosedCallback& callback,
1574 bool* did_suppress_message) {
1575 base::DictionaryValue request_info;
1576 request_info.Set(
1577 browser_plugin::kDefaultPromptText,
1578 base::Value::CreateStringValue(base::UTF16ToUTF8(default_prompt_text)));
1579 request_info.Set(
1580 browser_plugin::kMessageText,
1581 base::Value::CreateStringValue(base::UTF16ToUTF8(message_text)));
1582 request_info.Set(
1583 browser_plugin::kMessageType,
1584 base::Value::CreateStringValue(
1585 JavaScriptMessageTypeToString(javascript_message_type)));
1586 request_info.Set(
1587 browser_plugin::kURL,
1588 base::Value::CreateStringValue(origin_url.spec()));
1589
1590 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG,
1591 new JavaScriptDialogRequest(weak_ptr_factory_.GetWeakPtr(),
1592 callback),
1593 request_info);
1594 }
1595
1596 void BrowserPluginGuest::RunBeforeUnloadDialog(
1597 WebContents* web_contents,
1598 const base::string16& message_text,
1599 bool is_reload,
1600 const DialogClosedCallback& callback) {
1601 // This is called if the guest has a beforeunload event handler.
1602 // This callback allows navigation to proceed.
1603 callback.Run(true, base::string16());
1604 }
1605
1606 bool BrowserPluginGuest::HandleJavaScriptDialog(
1607 WebContents* web_contents,
1608 bool accept,
1609 const base::string16* prompt_override) {
1610 return false;
1611 }
1612
1613 void BrowserPluginGuest::CancelActiveAndPendingDialogs(
1614 WebContents* web_contents) {
1615 }
1616
1617 void BrowserPluginGuest::WebContentsDestroyed(WebContents* web_contents) {
1618 }
1619
1620 void BrowserPluginGuest::OnUpdateRect( 1534 void BrowserPluginGuest::OnUpdateRect(
1621 const ViewHostMsg_UpdateRect_Params& params) { 1535 const ViewHostMsg_UpdateRect_Params& params) {
1622 BrowserPluginMsg_UpdateRect_Params relay_params; 1536 BrowserPluginMsg_UpdateRect_Params relay_params;
1623 relay_params.view_size = params.view_size; 1537 relay_params.view_size = params.view_size;
1624 relay_params.scale_factor = params.scale_factor; 1538 relay_params.scale_factor = params.scale_factor;
1625 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( 1539 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack(
1626 params.flags); 1540 params.flags);
1627 relay_params.needs_ack = params.needs_ack; 1541 relay_params.needs_ack = params.needs_ack;
1628 1542
1629 bool size_changed = last_seen_view_size_ != params.view_size; 1543 bool size_changed = last_seen_view_size_ != params.view_size;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1715 const GURL& url) { 1629 const GURL& url) {
1716 if (!url.is_valid()) { 1630 if (!url.is_valid()) {
1717 callback.Run(false); 1631 callback.Run(false);
1718 return; 1632 return;
1719 } 1633 }
1720 1634
1721 delegate_->CanDownload(request_method, url, callback); 1635 delegate_->CanDownload(request_method, url, callback);
1722 } 1636 }
1723 1637
1724 } // namespace content 1638 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_plugin/browser_plugin_guest.h ('k') | content/common/browser_plugin/browser_plugin_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698