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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.cc

Issue 13037003: permissionrequest API for guest Download. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync @tott Created 7 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 | Annotate | Revision Log
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.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
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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 WebContents* new_contents, 320 WebContents* new_contents,
303 WindowOpenDisposition disposition, 321 WindowOpenDisposition disposition,
304 const gfx::Rect& initial_pos, 322 const gfx::Rect& initial_pos,
305 bool user_gesture, 323 bool user_gesture,
306 bool* was_blocked) { 324 bool* was_blocked) {
307 *was_blocked = false; 325 *was_blocked = false;
308 RequestNewWindowPermission(static_cast<WebContentsImpl*>(new_contents), 326 RequestNewWindowPermission(static_cast<WebContentsImpl*>(new_contents),
309 disposition, initial_pos, user_gesture); 327 disposition, initial_pos, user_gesture);
310 } 328 }
311 329
312 bool BrowserPluginGuest::CanDownload(RenderViewHost* render_view_host, 330 void BrowserPluginGuest::CanDownload(
313 int request_id, 331 RenderViewHost* render_view_host,
314 const std::string& request_method) { 332 int request_id,
315 // TODO(fsamuel): We disable downloads in guests for now, but we will later 333 const std::string& request_method,
316 // expose API to allow embedders to handle them. 334 const base::Callback<void(bool)>& callback) {
317 // Note: it seems content_shell ignores this. This should be fixed 335 if (download_request_callback_map_.size() >=
318 // for debugging and test purposes. 336 kNumMaxOutstandingPermissionRequests) {
319 return false; 337 // Deny the download request.
338 callback.Run(false);
339 return;
340 }
341
342 // TODO(lazyboy): Remove download specific map
343 // |download_request_callback_map_| once we have generalized request items for
344 // all permission types.
345 int permission_request_id = next_permission_request_id_++;
346 download_request_callback_map_[permission_request_id] = callback;
347
348 BrowserThread::PostTaskAndReplyWithResult(
349 BrowserThread::IO, FROM_HERE,
350 base::Bind(&RetrieveDownloadURLFromRequestId,
351 render_view_host, request_id),
352 base::Bind(&BrowserPluginGuest::DidRetrieveDownloadURLFromRequestId,
353 weak_ptr_factory_.GetWeakPtr(),
354 request_method,
355 permission_request_id));
320 } 356 }
321 357
322 bool BrowserPluginGuest::HandleContextMenu( 358 bool BrowserPluginGuest::HandleContextMenu(
323 const ContextMenuParams& params) { 359 const ContextMenuParams& params) {
324 // TODO(fsamuel): We have a do nothing context menu handler for now until 360 // TODO(fsamuel): We have a do nothing context menu handler for now until
325 // we implement the Apps Context Menu API for Browser Plugin (see 361 // we implement the Apps Context Menu API for Browser Plugin (see
326 // http://crbug.com/140315). 362 // http://crbug.com/140315).
327 return true; 363 return true;
328 } 364 }
329 365
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 void BrowserPluginGuest::OnStop(int instance_id) { 987 void BrowserPluginGuest::OnStop(int instance_id) {
952 GetWebContents()->Stop(); 988 GetWebContents()->Stop();
953 } 989 }
954 990
955 void BrowserPluginGuest::OnRespondPermission( 991 void BrowserPluginGuest::OnRespondPermission(
956 int instance_id, 992 int instance_id,
957 BrowserPluginPermissionType permission_type, 993 BrowserPluginPermissionType permission_type,
958 int request_id, 994 int request_id,
959 bool should_allow) { 995 bool should_allow) {
960 switch (permission_type) { 996 switch (permission_type) {
997 case BrowserPluginPermissionTypeDownload:
998 OnRespondPermissionDownload(request_id, should_allow);
999 break;
961 case BrowserPluginPermissionTypeGeolocation: 1000 case BrowserPluginPermissionTypeGeolocation:
962 OnRespondPermissionGeolocation(request_id, should_allow); 1001 OnRespondPermissionGeolocation(request_id, should_allow);
963 break; 1002 break;
964 case BrowserPluginPermissionTypeMedia: 1003 case BrowserPluginPermissionTypeMedia:
965 OnRespondPermissionMedia(request_id, should_allow); 1004 OnRespondPermissionMedia(request_id, should_allow);
966 break; 1005 break;
967 case BrowserPluginPermissionTypeNewWindow: 1006 case BrowserPluginPermissionTypeNewWindow:
968 OnRespondPermissionNewWindow(request_id, should_allow); 1007 OnRespondPermissionNewWindow(request_id, should_allow);
969 break; 1008 break;
970 default: 1009 default:
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 relay_params.damage_buffer_sequence_id = damage_buffer_sequence_id_; 1202 relay_params.damage_buffer_sequence_id = damage_buffer_sequence_id_;
1164 relay_params.bitmap_rect = params.bitmap_rect; 1203 relay_params.bitmap_rect = params.bitmap_rect;
1165 relay_params.scroll_delta = params.scroll_delta; 1204 relay_params.scroll_delta = params.scroll_delta;
1166 relay_params.scroll_rect = params.scroll_rect; 1205 relay_params.scroll_rect = params.scroll_rect;
1167 relay_params.copy_rects = params.copy_rects; 1206 relay_params.copy_rects = params.copy_rects;
1168 1207
1169 SendMessageToEmbedder( 1208 SendMessageToEmbedder(
1170 new BrowserPluginMsg_UpdateRect(instance_id(), relay_params)); 1209 new BrowserPluginMsg_UpdateRect(instance_id(), relay_params));
1171 } 1210 }
1172 1211
1212 void BrowserPluginGuest::OnRespondPermissionDownload(int request_id,
1213 bool should_allow) {
1214 DownloadRequestMap::iterator download_request_iter =
1215 download_request_callback_map_.find(request_id);
1216 if (download_request_iter == download_request_callback_map_.end()) {
1217 LOG(INFO) << "Not a valid request ID.";
1218 return;
1219 }
1220
1221 const base::Callback<void(bool)>& can_download_callback =
1222 download_request_iter->second;
1223 can_download_callback.Run(should_allow);
1224 }
1225
1173 void BrowserPluginGuest::OnRespondPermissionGeolocation( 1226 void BrowserPluginGuest::OnRespondPermissionGeolocation(
1174 int request_id, bool should_allow) { 1227 int request_id, bool should_allow) {
1175 if (should_allow && embedder_web_contents_) { 1228 if (should_allow && embedder_web_contents_) {
1176 // If renderer side embedder decides to allow gelocation, we need to check 1229 // If renderer side embedder decides to allow gelocation, we need to check
1177 // if the app/embedder itself has geolocation access. 1230 // if the app/embedder itself has geolocation access.
1178 BrowserContext* browser_context = 1231 BrowserContext* browser_context =
1179 embedder_web_contents_->GetBrowserContext(); 1232 embedder_web_contents_->GetBrowserContext();
1180 if (browser_context) { 1233 if (browser_context) {
1181 GeolocationPermissionContext* geolocation_context = 1234 GeolocationPermissionContext* geolocation_context =
1182 browser_context->GetGeolocationPermissionContext(); 1235 browser_context->GetGeolocationPermissionContext();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 if (!guest) { 1295 if (!guest) {
1243 LOG(INFO) << "Guest not found. Instance ID: " << instance_id; 1296 LOG(INFO) << "Guest not found. Instance ID: " << instance_id;
1244 return; 1297 return;
1245 } 1298 }
1246 if (!should_allow) 1299 if (!should_allow)
1247 guest->Destroy(); 1300 guest->Destroy();
1248 // If we do not destroy the guest then we allow the new window. 1301 // If we do not destroy the guest then we allow the new window.
1249 new_window_request_map_.erase(new_window_request_iter); 1302 new_window_request_map_.erase(new_window_request_iter);
1250 } 1303 }
1251 1304
1305 void BrowserPluginGuest::DidRetrieveDownloadURLFromRequestId(
1306 const std::string& request_method,
1307 int permission_request_id,
1308 const std::string& url) {
1309 if (url.empty()) {
1310 OnRespondPermissionDownload(permission_request_id,
1311 false /* should_allow */);
1312 return;
1313 }
1314
1315 base::DictionaryValue request_info;
1316 request_info.Set(browser_plugin::kRequestMethod,
1317 base::Value::CreateStringValue(request_method));
1318 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url));
1319
1320 SendMessageToEmbedder(
1321 new BrowserPluginMsg_RequestPermission(instance_id(),
1322 BrowserPluginPermissionTypeDownload, permission_request_id,
1323 request_info));
1324 }
1325
1252 } // namespace content 1326 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_plugin/browser_plugin_guest.h ('k') | content/browser/browser_plugin/browser_plugin_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698