OLD | NEW |
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.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 bool user_gesture, | 303 bool user_gesture, |
304 bool* was_blocked) { | 304 bool* was_blocked) { |
305 *was_blocked = false; | 305 *was_blocked = false; |
306 RequestNewWindowPermission(static_cast<WebContentsImpl*>(new_contents), | 306 RequestNewWindowPermission(static_cast<WebContentsImpl*>(new_contents), |
307 disposition, initial_pos, user_gesture); | 307 disposition, initial_pos, user_gesture); |
308 } | 308 } |
309 | 309 |
310 bool BrowserPluginGuest::CanDownload(RenderViewHost* render_view_host, | 310 bool BrowserPluginGuest::CanDownload(RenderViewHost* render_view_host, |
311 int request_id, | 311 int request_id, |
312 const std::string& request_method) { | 312 const std::string& request_method) { |
313 // TODO(fsamuel): We disable downloads in guests for now, but we will later | 313 // We can only decide whether a guest can download or not through async API, |
314 // expose API to allow embedders to handle them. | 314 // see CanDownloadAsync(). |
315 // Note: it seems content_shell ignores this. This should be fixed | 315 NOTREACHED(); |
316 // for debugging and test purposes. | |
317 return false; | 316 return false; |
318 } | 317 } |
319 | 318 |
| 319 void BrowserPluginGuest::CanDownloadAsync( |
| 320 RenderViewHost* render_view_host, |
| 321 int download_request_id, |
| 322 const std::string& request_method, |
| 323 const base::Callback<void(bool)>& callback) { |
| 324 if (download_request_callback_map_.size() >= |
| 325 kNumMaxOutstandingPermissionRequests) { |
| 326 // Deny the download request. |
| 327 callback.Run(false); |
| 328 return; |
| 329 } |
| 330 |
| 331 int request_id = next_permission_request_id_++; |
| 332 download_request_callback_map_[request_id] = callback; |
| 333 |
| 334 base::DictionaryValue request_info; |
| 335 request_info.Set(browser_plugin::kRequestMethod, |
| 336 base::Value::CreateStringValue(request_method)); |
| 337 |
| 338 SendMessageToEmbedder( |
| 339 new BrowserPluginMsg_RequestPermission(instance_id(), |
| 340 BrowserPluginPermissionTypeDownload, request_id, request_info)); |
| 341 } |
| 342 |
320 bool BrowserPluginGuest::HandleContextMenu( | 343 bool BrowserPluginGuest::HandleContextMenu( |
321 const ContextMenuParams& params) { | 344 const ContextMenuParams& params) { |
322 // TODO(fsamuel): We have a do nothing context menu handler for now until | 345 // TODO(fsamuel): We have a do nothing context menu handler for now until |
323 // we implement the Apps Context Menu API for Browser Plugin (see | 346 // we implement the Apps Context Menu API for Browser Plugin (see |
324 // http://crbug.com/140315). | 347 // http://crbug.com/140315). |
325 return true; | 348 return true; |
326 } | 349 } |
327 | 350 |
328 void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, | 351 void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, |
329 int64 source_frame_id, | 352 int64 source_frame_id, |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 void BrowserPluginGuest::OnStop(int instance_id) { | 961 void BrowserPluginGuest::OnStop(int instance_id) { |
939 GetWebContents()->Stop(); | 962 GetWebContents()->Stop(); |
940 } | 963 } |
941 | 964 |
942 void BrowserPluginGuest::OnRespondPermission( | 965 void BrowserPluginGuest::OnRespondPermission( |
943 int instance_id, | 966 int instance_id, |
944 BrowserPluginPermissionType permission_type, | 967 BrowserPluginPermissionType permission_type, |
945 int request_id, | 968 int request_id, |
946 bool should_allow) { | 969 bool should_allow) { |
947 switch (permission_type) { | 970 switch (permission_type) { |
| 971 case BrowserPluginPermissionTypeDownload: |
| 972 OnRespondPermissionDownload(request_id, should_allow); |
| 973 break; |
948 case BrowserPluginPermissionTypeGeolocation: | 974 case BrowserPluginPermissionTypeGeolocation: |
949 OnRespondPermissionGeolocation(request_id, should_allow); | 975 OnRespondPermissionGeolocation(request_id, should_allow); |
950 break; | 976 break; |
951 case BrowserPluginPermissionTypeMedia: | 977 case BrowserPluginPermissionTypeMedia: |
952 OnRespondPermissionMedia(request_id, should_allow); | 978 OnRespondPermissionMedia(request_id, should_allow); |
953 break; | 979 break; |
954 case BrowserPluginPermissionTypeNewWindow: | 980 case BrowserPluginPermissionTypeNewWindow: |
955 OnRespondPermissionNewWindow(request_id, should_allow); | 981 OnRespondPermissionNewWindow(request_id, should_allow); |
956 break; | 982 break; |
957 default: | 983 default: |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 relay_params.damage_buffer_sequence_id = damage_buffer_sequence_id_; | 1176 relay_params.damage_buffer_sequence_id = damage_buffer_sequence_id_; |
1151 relay_params.bitmap_rect = params.bitmap_rect; | 1177 relay_params.bitmap_rect = params.bitmap_rect; |
1152 relay_params.scroll_delta = params.scroll_delta; | 1178 relay_params.scroll_delta = params.scroll_delta; |
1153 relay_params.scroll_rect = params.scroll_rect; | 1179 relay_params.scroll_rect = params.scroll_rect; |
1154 relay_params.copy_rects = params.copy_rects; | 1180 relay_params.copy_rects = params.copy_rects; |
1155 | 1181 |
1156 SendMessageToEmbedder( | 1182 SendMessageToEmbedder( |
1157 new BrowserPluginMsg_UpdateRect(instance_id(), relay_params)); | 1183 new BrowserPluginMsg_UpdateRect(instance_id(), relay_params)); |
1158 } | 1184 } |
1159 | 1185 |
| 1186 void BrowserPluginGuest::OnRespondPermissionDownload(int request_id, |
| 1187 bool should_allow) { |
| 1188 DownloadRequestMap::iterator download_request_iter = |
| 1189 download_request_callback_map_.find(request_id); |
| 1190 if (download_request_iter == download_request_callback_map_.end()) { |
| 1191 LOG(INFO) << "Not a valid request ID."; |
| 1192 return; |
| 1193 } |
| 1194 |
| 1195 const base::Callback<void(bool)>& can_download_callback = |
| 1196 download_request_iter->second; |
| 1197 can_download_callback.Run(should_allow); |
| 1198 } |
| 1199 |
1160 void BrowserPluginGuest::OnRespondPermissionGeolocation( | 1200 void BrowserPluginGuest::OnRespondPermissionGeolocation( |
1161 int request_id, bool should_allow) { | 1201 int request_id, bool should_allow) { |
1162 if (should_allow && embedder_web_contents_) { | 1202 if (should_allow && embedder_web_contents_) { |
1163 // If renderer side embedder decides to allow gelocation, we need to check | 1203 // If renderer side embedder decides to allow gelocation, we need to check |
1164 // if the app/embedder itself has geolocation access. | 1204 // if the app/embedder itself has geolocation access. |
1165 BrowserContext* browser_context = | 1205 BrowserContext* browser_context = |
1166 embedder_web_contents_->GetBrowserContext(); | 1206 embedder_web_contents_->GetBrowserContext(); |
1167 if (browser_context) { | 1207 if (browser_context) { |
1168 GeolocationPermissionContext* geolocation_context = | 1208 GeolocationPermissionContext* geolocation_context = |
1169 browser_context->GetGeolocationPermissionContext(); | 1209 browser_context->GetGeolocationPermissionContext(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 LOG(INFO) << "Guest not found. Instance ID: " << instance_id; | 1270 LOG(INFO) << "Guest not found. Instance ID: " << instance_id; |
1231 return; | 1271 return; |
1232 } | 1272 } |
1233 if (!should_allow) | 1273 if (!should_allow) |
1234 guest->Destroy(); | 1274 guest->Destroy(); |
1235 // If we do not destroy the guest then we allow the new window. | 1275 // If we do not destroy the guest then we allow the new window. |
1236 new_window_request_map_.erase(new_window_request_iter); | 1276 new_window_request_map_.erase(new_window_request_iter); |
1237 } | 1277 } |
1238 | 1278 |
1239 } // namespace content | 1279 } // namespace content |
OLD | NEW |