Index: content/browser/browser_plugin/browser_plugin_guest.cc |
diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc |
index 973408fbd476f1fa1a1d651c24368d9a7ca8a06c..20215f20c5bda8b458d635dcb814138ac33cf163 100644 |
--- a/content/browser/browser_plugin/browser_plugin_guest.cc |
+++ b/content/browser/browser_plugin/browser_plugin_guest.cc |
@@ -310,13 +310,36 @@ void BrowserPluginGuest::AddNewContents(WebContents* source, |
bool BrowserPluginGuest::CanDownload(RenderViewHost* render_view_host, |
int request_id, |
const std::string& request_method) { |
- // TODO(fsamuel): We disable downloads in guests for now, but we will later |
- // expose API to allow embedders to handle them. |
- // Note: it seems content_shell ignores this. This should be fixed |
- // for debugging and test purposes. |
+ // We can only decide whether a guest can download or not through async API, |
+ // see CanDownloadAsync(). |
+ NOTREACHED(); |
return false; |
} |
+void BrowserPluginGuest::CanDownloadAsync( |
+ RenderViewHost* render_view_host, |
+ int download_request_id, |
+ const std::string& request_method, |
+ const base::Callback<void(bool)>& callback) { |
+ if (download_request_callback_map_.size() >= |
+ kNumMaxOutstandingPermissionRequests) { |
+ // Deny the download request. |
+ callback.Run(false); |
+ return; |
+ } |
+ |
+ int request_id = next_permission_request_id_++; |
+ download_request_callback_map_[request_id] = callback; |
+ |
+ base::DictionaryValue request_info; |
+ request_info.Set(browser_plugin::kRequestMethod, |
+ base::Value::CreateStringValue(request_method)); |
+ |
+ SendMessageToEmbedder( |
+ new BrowserPluginMsg_RequestPermission(instance_id(), |
+ BrowserPluginPermissionTypeDownload, request_id, request_info)); |
+} |
+ |
bool BrowserPluginGuest::HandleContextMenu( |
const ContextMenuParams& params) { |
// TODO(fsamuel): We have a do nothing context menu handler for now until |
@@ -945,6 +968,9 @@ void BrowserPluginGuest::OnRespondPermission( |
int request_id, |
bool should_allow) { |
switch (permission_type) { |
+ case BrowserPluginPermissionTypeDownload: |
+ OnRespondPermissionDownload(request_id, should_allow); |
+ break; |
case BrowserPluginPermissionTypeGeolocation: |
OnRespondPermissionGeolocation(request_id, should_allow); |
break; |
@@ -1157,6 +1183,20 @@ void BrowserPluginGuest::OnUpdateRect( |
new BrowserPluginMsg_UpdateRect(instance_id(), relay_params)); |
} |
+void BrowserPluginGuest::OnRespondPermissionDownload(int request_id, |
+ bool should_allow) { |
+ DownloadRequestMap::iterator download_request_iter = |
+ download_request_callback_map_.find(request_id); |
+ if (download_request_iter == download_request_callback_map_.end()) { |
+ LOG(INFO) << "Not a valid request ID."; |
+ return; |
+ } |
+ |
+ const base::Callback<void(bool)>& can_download_callback = |
+ download_request_iter->second; |
+ can_download_callback.Run(should_allow); |
+} |
+ |
void BrowserPluginGuest::OnRespondPermissionGeolocation( |
int request_id, bool should_allow) { |
if (should_allow && embedder_web_contents_) { |