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" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 12 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
13 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" | 13 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" |
14 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h" | 14 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h" |
15 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 15 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 16 #include "content/browser/browser_thread_impl.h" |
| 17 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
16 #include "content/browser/renderer_host/render_view_host_impl.h" | 18 #include "content/browser/renderer_host/render_view_host_impl.h" |
17 #include "content/browser/renderer_host/render_widget_host_impl.h" | 19 #include "content/browser/renderer_host/render_widget_host_impl.h" |
18 #include "content/browser/web_contents/web_contents_impl.h" | 20 #include "content/browser/web_contents/web_contents_impl.h" |
19 #include "content/browser/web_contents/web_contents_view_guest.h" | 21 #include "content/browser/web_contents/web_contents_view_guest.h" |
20 #include "content/common/browser_plugin/browser_plugin_constants.h" | 22 #include "content/common/browser_plugin/browser_plugin_constants.h" |
21 #include "content/common/browser_plugin/browser_plugin_messages.h" | 23 #include "content/common/browser_plugin/browser_plugin_messages.h" |
22 #include "content/common/content_constants_internal.h" | 24 #include "content/common/content_constants_internal.h" |
23 #include "content/common/drag_messages.h" | 25 #include "content/common/drag_messages.h" |
24 #include "content/common/gpu/gpu_messages.h" | 26 #include "content/common/gpu/gpu_messages.h" |
25 #include "content/common/view_messages.h" | 27 #include "content/common/view_messages.h" |
26 #include "content/port/browser/render_view_host_delegate_view.h" | 28 #include "content/port/browser/render_view_host_delegate_view.h" |
27 #include "content/public/browser/browser_context.h" | 29 #include "content/public/browser/browser_context.h" |
28 #include "content/public/browser/content_browser_client.h" | 30 #include "content/public/browser/content_browser_client.h" |
29 #include "content/public/browser/geolocation_permission_context.h" | 31 #include "content/public/browser/geolocation_permission_context.h" |
30 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
31 #include "content/public/browser/notification_types.h" | 33 #include "content/public/browser/notification_types.h" |
32 #include "content/public/browser/render_process_host.h" | 34 #include "content/public/browser/render_process_host.h" |
33 #include "content/public/browser/render_widget_host_view.h" | 35 #include "content/public/browser/render_widget_host_view.h" |
34 #include "content/public/browser/resource_request_details.h" | 36 #include "content/public/browser/resource_request_details.h" |
35 #include "content/public/browser/user_metrics.h" | 37 #include "content/public/browser/user_metrics.h" |
36 #include "content/public/browser/web_contents_view.h" | 38 #include "content/public/browser/web_contents_view.h" |
37 #include "content/public/common/media_stream_request.h" | 39 #include "content/public/common/media_stream_request.h" |
38 #include "content/public/common/result_codes.h" | 40 #include "content/public/common/result_codes.h" |
39 #include "net/base/net_errors.h" | 41 #include "net/base/net_errors.h" |
| 42 #include "net/url_request/url_request.h" |
40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
41 #include "ui/surface/transport_dib.h" | 44 #include "ui/surface/transport_dib.h" |
42 #include "webkit/glue/resource_type.h" | 45 #include "webkit/glue/resource_type.h" |
43 #include "webkit/glue/webdropdata.h" | 46 #include "webkit/glue/webdropdata.h" |
44 | 47 |
45 #if defined(OS_MACOSX) | 48 #if defined(OS_MACOSX) |
46 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" | 49 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" |
47 #endif | 50 #endif |
48 | 51 |
49 namespace content { | 52 namespace content { |
(...skipping 20 matching lines...) Expand all Loading... |
70 case NEW_WINDOW: | 73 case NEW_WINDOW: |
71 return "new_window"; | 74 return "new_window"; |
72 case NEW_POPUP: | 75 case NEW_POPUP: |
73 return "new_popup"; | 76 return "new_popup"; |
74 default: | 77 default: |
75 NOTREACHED() << "Unknown Window Open Disposition"; | 78 NOTREACHED() << "Unknown Window Open Disposition"; |
76 return "ignore"; | 79 return "ignore"; |
77 } | 80 } |
78 } | 81 } |
79 | 82 |
| 83 // Called on IO thread. |
| 84 static std::string RetrieveDownloadURLFromRequestId( |
| 85 RenderViewHost* render_view_host, |
| 86 int url_request_id) { |
| 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 88 |
| 89 int render_process_id = render_view_host->GetProcess()->GetID(); |
| 90 GlobalRequestID global_id(render_process_id, url_request_id); |
| 91 net::URLRequest* url_request = |
| 92 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); |
| 93 if (url_request) |
| 94 return url_request->url().possibly_invalid_spec(); |
| 95 return ""; |
| 96 } |
| 97 |
80 } | 98 } |
81 | 99 |
82 class BrowserPluginGuest::EmbedderRenderViewHostObserver | 100 class BrowserPluginGuest::EmbedderRenderViewHostObserver |
83 : public RenderViewHostObserver { | 101 : public RenderViewHostObserver { |
84 public: | 102 public: |
85 explicit EmbedderRenderViewHostObserver(BrowserPluginGuest* guest) | 103 explicit EmbedderRenderViewHostObserver(BrowserPluginGuest* guest) |
86 : RenderViewHostObserver( | 104 : RenderViewHostObserver( |
87 guest->embedder_web_contents()->GetRenderViewHost()), | 105 guest->embedder_web_contents()->GetRenderViewHost()), |
88 browser_plugin_guest_(guest) { | 106 browser_plugin_guest_(guest) { |
89 } | 107 } |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 WebContents* new_contents, | 318 WebContents* new_contents, |
301 WindowOpenDisposition disposition, | 319 WindowOpenDisposition disposition, |
302 const gfx::Rect& initial_pos, | 320 const gfx::Rect& initial_pos, |
303 bool user_gesture, | 321 bool user_gesture, |
304 bool* was_blocked) { | 322 bool* was_blocked) { |
305 *was_blocked = false; | 323 *was_blocked = false; |
306 RequestNewWindowPermission(static_cast<WebContentsImpl*>(new_contents), | 324 RequestNewWindowPermission(static_cast<WebContentsImpl*>(new_contents), |
307 disposition, initial_pos, user_gesture); | 325 disposition, initial_pos, user_gesture); |
308 } | 326 } |
309 | 327 |
310 bool BrowserPluginGuest::CanDownload(RenderViewHost* render_view_host, | 328 void BrowserPluginGuest::CanDownload( |
311 int request_id, | 329 RenderViewHost* render_view_host, |
312 const std::string& request_method) { | 330 int request_id, |
313 // TODO(fsamuel): We disable downloads in guests for now, but we will later | 331 const std::string& request_method, |
314 // expose API to allow embedders to handle them. | 332 const base::Callback<void(bool)>& callback) { |
315 // Note: it seems content_shell ignores this. This should be fixed | 333 if (download_request_callback_map_.size() >= |
316 // for debugging and test purposes. | 334 kNumMaxOutstandingPermissionRequests) { |
317 return false; | 335 // Deny the download request. |
| 336 callback.Run(false); |
| 337 return; |
| 338 } |
| 339 |
| 340 int permission_request_id = next_permission_request_id_++; |
| 341 download_request_callback_map_[permission_request_id] = callback; |
| 342 |
| 343 BrowserThread::PostTaskAndReplyWithResult( |
| 344 BrowserThread::IO, FROM_HERE, |
| 345 base::Bind(&RetrieveDownloadURLFromRequestId, |
| 346 render_view_host, request_id), |
| 347 base::Bind(&BrowserPluginGuest::DidRetrieveDownloadURLFromRequestId, |
| 348 weak_ptr_factory_.GetWeakPtr(), |
| 349 request_method, |
| 350 permission_request_id)); |
318 } | 351 } |
319 | 352 |
320 bool BrowserPluginGuest::HandleContextMenu( | 353 bool BrowserPluginGuest::HandleContextMenu( |
321 const ContextMenuParams& params) { | 354 const ContextMenuParams& params) { |
322 // TODO(fsamuel): We have a do nothing context menu handler for now until | 355 // 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 | 356 // we implement the Apps Context Menu API for Browser Plugin (see |
324 // http://crbug.com/140315). | 357 // http://crbug.com/140315). |
325 return true; | 358 return true; |
326 } | 359 } |
327 | 360 |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 void BrowserPluginGuest::OnStop(int instance_id) { | 971 void BrowserPluginGuest::OnStop(int instance_id) { |
939 GetWebContents()->Stop(); | 972 GetWebContents()->Stop(); |
940 } | 973 } |
941 | 974 |
942 void BrowserPluginGuest::OnRespondPermission( | 975 void BrowserPluginGuest::OnRespondPermission( |
943 int instance_id, | 976 int instance_id, |
944 BrowserPluginPermissionType permission_type, | 977 BrowserPluginPermissionType permission_type, |
945 int request_id, | 978 int request_id, |
946 bool should_allow) { | 979 bool should_allow) { |
947 switch (permission_type) { | 980 switch (permission_type) { |
| 981 case BrowserPluginPermissionTypeDownload: |
| 982 OnRespondPermissionDownload(request_id, should_allow); |
| 983 break; |
948 case BrowserPluginPermissionTypeGeolocation: | 984 case BrowserPluginPermissionTypeGeolocation: |
949 OnRespondPermissionGeolocation(request_id, should_allow); | 985 OnRespondPermissionGeolocation(request_id, should_allow); |
950 break; | 986 break; |
951 case BrowserPluginPermissionTypeMedia: | 987 case BrowserPluginPermissionTypeMedia: |
952 OnRespondPermissionMedia(request_id, should_allow); | 988 OnRespondPermissionMedia(request_id, should_allow); |
953 break; | 989 break; |
954 case BrowserPluginPermissionTypeNewWindow: | 990 case BrowserPluginPermissionTypeNewWindow: |
955 OnRespondPermissionNewWindow(request_id, should_allow); | 991 OnRespondPermissionNewWindow(request_id, should_allow); |
956 break; | 992 break; |
957 default: | 993 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_; | 1186 relay_params.damage_buffer_sequence_id = damage_buffer_sequence_id_; |
1151 relay_params.bitmap_rect = params.bitmap_rect; | 1187 relay_params.bitmap_rect = params.bitmap_rect; |
1152 relay_params.scroll_delta = params.scroll_delta; | 1188 relay_params.scroll_delta = params.scroll_delta; |
1153 relay_params.scroll_rect = params.scroll_rect; | 1189 relay_params.scroll_rect = params.scroll_rect; |
1154 relay_params.copy_rects = params.copy_rects; | 1190 relay_params.copy_rects = params.copy_rects; |
1155 | 1191 |
1156 SendMessageToEmbedder( | 1192 SendMessageToEmbedder( |
1157 new BrowserPluginMsg_UpdateRect(instance_id(), relay_params)); | 1193 new BrowserPluginMsg_UpdateRect(instance_id(), relay_params)); |
1158 } | 1194 } |
1159 | 1195 |
| 1196 void BrowserPluginGuest::OnRespondPermissionDownload(int request_id, |
| 1197 bool should_allow) { |
| 1198 DownloadRequestMap::iterator download_request_iter = |
| 1199 download_request_callback_map_.find(request_id); |
| 1200 if (download_request_iter == download_request_callback_map_.end()) { |
| 1201 LOG(INFO) << "Not a valid request ID."; |
| 1202 return; |
| 1203 } |
| 1204 |
| 1205 const base::Callback<void(bool)>& can_download_callback = |
| 1206 download_request_iter->second; |
| 1207 can_download_callback.Run(should_allow); |
| 1208 } |
| 1209 |
1160 void BrowserPluginGuest::OnRespondPermissionGeolocation( | 1210 void BrowserPluginGuest::OnRespondPermissionGeolocation( |
1161 int request_id, bool should_allow) { | 1211 int request_id, bool should_allow) { |
1162 if (should_allow && embedder_web_contents_) { | 1212 if (should_allow && embedder_web_contents_) { |
1163 // If renderer side embedder decides to allow gelocation, we need to check | 1213 // If renderer side embedder decides to allow gelocation, we need to check |
1164 // if the app/embedder itself has geolocation access. | 1214 // if the app/embedder itself has geolocation access. |
1165 BrowserContext* browser_context = | 1215 BrowserContext* browser_context = |
1166 embedder_web_contents_->GetBrowserContext(); | 1216 embedder_web_contents_->GetBrowserContext(); |
1167 if (browser_context) { | 1217 if (browser_context) { |
1168 GeolocationPermissionContext* geolocation_context = | 1218 GeolocationPermissionContext* geolocation_context = |
1169 browser_context->GetGeolocationPermissionContext(); | 1219 browser_context->GetGeolocationPermissionContext(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 if (!guest) { | 1279 if (!guest) { |
1230 LOG(INFO) << "Guest not found. Instance ID: " << instance_id; | 1280 LOG(INFO) << "Guest not found. Instance ID: " << instance_id; |
1231 return; | 1281 return; |
1232 } | 1282 } |
1233 if (!should_allow) | 1283 if (!should_allow) |
1234 guest->Destroy(); | 1284 guest->Destroy(); |
1235 // If we do not destroy the guest then we allow the new window. | 1285 // If we do not destroy the guest then we allow the new window. |
1236 new_window_request_map_.erase(new_window_request_iter); | 1286 new_window_request_map_.erase(new_window_request_iter); |
1237 } | 1287 } |
1238 | 1288 |
| 1289 void BrowserPluginGuest::DidRetrieveDownloadURLFromRequestId( |
| 1290 const std::string& request_method, |
| 1291 int permission_request_id, |
| 1292 const std::string& url) { |
| 1293 if (url.empty()) { |
| 1294 OnRespondPermissionDownload(permission_request_id, |
| 1295 false /* should_allow */); |
| 1296 return; |
| 1297 } |
| 1298 |
| 1299 base::DictionaryValue request_info; |
| 1300 request_info.Set(browser_plugin::kRequestMethod, |
| 1301 base::Value::CreateStringValue(request_method)); |
| 1302 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); |
| 1303 |
| 1304 SendMessageToEmbedder( |
| 1305 new BrowserPluginMsg_RequestPermission(instance_id(), |
| 1306 BrowserPluginPermissionTypeDownload, permission_request_id, |
| 1307 request_info)); |
| 1308 } |
| 1309 |
1239 } // namespace content | 1310 } // namespace content |
OLD | NEW |