| 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..cfd9b5563bd6d916c8f55933f2ba1c71a7bcfaef 100644
|
| --- a/content/browser/browser_plugin/browser_plugin_guest.cc
|
| +++ b/content/browser/browser_plugin/browser_plugin_guest.cc
|
| @@ -307,14 +307,29 @@ void BrowserPluginGuest::AddNewContents(WebContents* source,
|
| disposition, initial_pos, user_gesture);
|
| }
|
|
|
| -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.
|
| - return false;
|
| +void BrowserPluginGuest::CanDownload(
|
| + RenderViewHost* render_view_host,
|
| + int 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 download_request_id = next_permission_request_id_++;
|
| + download_request_callback_map_[download_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, download_request_id,
|
| + request_info));
|
| }
|
|
|
| bool BrowserPluginGuest::HandleContextMenu(
|
| @@ -945,6 +960,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 +1175,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_) {
|
|
|