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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "content/common/browser_plugin/browser_plugin_messages.h" | 25 #include "content/common/browser_plugin/browser_plugin_messages.h" |
26 #include "content/common/content_constants_internal.h" | 26 #include "content/common/content_constants_internal.h" |
27 #include "content/common/drag_messages.h" | 27 #include "content/common/drag_messages.h" |
28 #include "content/common/gpu/gpu_messages.h" | 28 #include "content/common/gpu/gpu_messages.h" |
29 #include "content/common/input_messages.h" | 29 #include "content/common/input_messages.h" |
30 #include "content/common/view_messages.h" | 30 #include "content/common/view_messages.h" |
31 #include "content/port/browser/render_view_host_delegate_view.h" | 31 #include "content/port/browser/render_view_host_delegate_view.h" |
32 #include "content/port/browser/render_widget_host_view_port.h" | 32 #include "content/port/browser/render_widget_host_view_port.h" |
33 #include "content/public/browser/browser_context.h" | 33 #include "content/public/browser/browser_context.h" |
34 #include "content/public/browser/content_browser_client.h" | 34 #include "content/public/browser/content_browser_client.h" |
35 #include "content/public/browser/geolocation_permission_context.h" | |
36 #include "content/public/browser/navigation_controller.h" | 35 #include "content/public/browser/navigation_controller.h" |
37 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
38 #include "content/public/browser/render_widget_host_view.h" | 37 #include "content/public/browser/render_widget_host_view.h" |
39 #include "content/public/browser/resource_request_details.h" | 38 #include "content/public/browser/resource_request_details.h" |
40 #include "content/public/browser/user_metrics.h" | 39 #include "content/public/browser/user_metrics.h" |
41 #include "content/public/browser/web_contents_observer.h" | 40 #include "content/public/browser/web_contents_observer.h" |
42 #include "content/public/browser/web_contents_view.h" | 41 #include "content/public/browser/web_contents_view.h" |
43 #include "content/public/common/drop_data.h" | 42 #include "content/public/common/drop_data.h" |
44 #include "content/public/common/media_stream_request.h" | 43 #include "content/public/common/media_stream_request.h" |
45 #include "content/public/common/result_codes.h" | 44 #include "content/public/common/result_codes.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 virtual void RespondImpl(bool should_allow, | 100 virtual void RespondImpl(bool should_allow, |
102 const std::string& user_input) OVERRIDE { | 101 const std::string& user_input) OVERRIDE { |
103 callback_.Run(should_allow); | 102 callback_.Run(should_allow); |
104 } | 103 } |
105 | 104 |
106 private: | 105 private: |
107 virtual ~DownloadRequest() {} | 106 virtual ~DownloadRequest() {} |
108 base::Callback<void(bool)> callback_; | 107 base::Callback<void(bool)> callback_; |
109 }; | 108 }; |
110 | 109 |
111 class BrowserPluginGuest::GeolocationRequest : public PermissionRequest { | |
112 public: | |
113 GeolocationRequest(const base::WeakPtr<BrowserPluginGuest>& guest, | |
114 GeolocationCallback callback, | |
115 int bridge_id, | |
116 bool user_gesture) | |
117 : PermissionRequest(guest), | |
118 callback_(callback), | |
119 bridge_id_(bridge_id), | |
120 user_gesture_(user_gesture) { | |
121 RecordAction( | |
122 base::UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.Geolocati
on")); | |
123 } | |
124 | |
125 virtual void RespondImpl(bool should_allow, | |
126 const std::string& user_input) OVERRIDE { | |
127 WebContents* web_contents = guest_->embedder_web_contents(); | |
128 if (should_allow && web_contents) { | |
129 // If renderer side embedder decides to allow gelocation, we need to check | |
130 // if the app/embedder itself has geolocation access. | |
131 BrowserContext* browser_context = web_contents->GetBrowserContext(); | |
132 if (browser_context) { | |
133 GeolocationPermissionContext* geolocation_context = | |
134 browser_context->GetGeolocationPermissionContext(); | |
135 if (geolocation_context) { | |
136 base::Callback<void(bool)> geolocation_callback = base::Bind( | |
137 &BrowserPluginGuest::SetGeolocationPermission, | |
138 guest_, | |
139 callback_, | |
140 bridge_id_); | |
141 geolocation_context->RequestGeolocationPermission( | |
142 web_contents->GetRenderProcessHost()->GetID(), | |
143 web_contents->GetRoutingID(), | |
144 // The geolocation permission request here is not initiated | |
145 // through WebGeolocationPermissionRequest. We are only interested | |
146 // in the fact whether the embedder/app has geolocation | |
147 // permission. Therefore we use an invalid |bridge_id|. | |
148 -1 /* bridge_id */, | |
149 web_contents->GetLastCommittedURL(), | |
150 user_gesture_, | |
151 geolocation_callback); | |
152 return; | |
153 } | |
154 } | |
155 } | |
156 guest_->SetGeolocationPermission(callback_, bridge_id_, false); | |
157 } | |
158 | |
159 private: | |
160 virtual ~GeolocationRequest() {} | |
161 base::Callback<void(bool)> callback_; | |
162 int bridge_id_; | |
163 bool user_gesture_; | |
164 }; | |
165 | |
166 class BrowserPluginGuest::MediaRequest : public PermissionRequest { | 110 class BrowserPluginGuest::MediaRequest : public PermissionRequest { |
167 public: | 111 public: |
168 MediaRequest(const base::WeakPtr<BrowserPluginGuest>& guest, | 112 MediaRequest(const base::WeakPtr<BrowserPluginGuest>& guest, |
169 const MediaStreamRequest& request, | 113 const MediaStreamRequest& request, |
170 const MediaResponseCallback& callback) | 114 const MediaResponseCallback& callback) |
171 : PermissionRequest(guest), | 115 : PermissionRequest(guest), |
172 request_(request), | 116 request_(request), |
173 callback_(callback) { | 117 callback_(callback) { |
174 RecordAction( | 118 RecordAction( |
175 base::UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.Media")); | 119 base::UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.Media")); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 const std::string& user_input) { | 379 const std::string& user_input) { |
436 RequestMap::iterator request_itr = permission_request_map_.find(request_id); | 380 RequestMap::iterator request_itr = permission_request_map_.find(request_id); |
437 if (request_itr == permission_request_map_.end()) { | 381 if (request_itr == permission_request_map_.end()) { |
438 VLOG(0) << "Not a valid request ID."; | 382 VLOG(0) << "Not a valid request ID."; |
439 return; | 383 return; |
440 } | 384 } |
441 request_itr->second->Respond(should_allow, user_input); | 385 request_itr->second->Respond(should_allow, user_input); |
442 permission_request_map_.erase(request_itr); | 386 permission_request_map_.erase(request_itr); |
443 } | 387 } |
444 | 388 |
445 int BrowserPluginGuest::RequestPermission( | 389 void BrowserPluginGuest::RequestPermission( |
446 BrowserPluginPermissionType permission_type, | 390 BrowserPluginPermissionType permission_type, |
447 scoped_refptr<BrowserPluginGuest::PermissionRequest> request, | 391 scoped_refptr<BrowserPluginGuest::PermissionRequest> request, |
448 const base::DictionaryValue& request_info) { | 392 const base::DictionaryValue& request_info) { |
449 if (!delegate_) { | 393 if (!delegate_) { |
450 // Let the stack unwind before we deny the permission request so that | 394 // Let the stack unwind before we deny the permission request so that |
451 // objects held by the permission request are not destroyed immediately | 395 // objects held by the permission request are not destroyed immediately |
452 // after creation. This is to allow those same objects to be accessed again | 396 // after creation. This is to allow those same objects to be accessed again |
453 // in the same scope without fear of use after freeing. | 397 // in the same scope without fear of use after freeing. |
454 base::MessageLoop::current()->PostTask( | 398 base::MessageLoop::current()->PostTask( |
455 FROM_HERE, | 399 FROM_HERE, |
456 base::Bind(&BrowserPluginGuest::PermissionRequest::Respond, | 400 base::Bind(&BrowserPluginGuest::PermissionRequest::Respond, |
457 request, false, "")); | 401 request, false, "")); |
458 return browser_plugin::kInvalidPermissionRequestID; | |
459 } | 402 } |
460 | 403 |
461 int request_id = ++next_permission_request_id_; | 404 int request_id = ++next_permission_request_id_; |
462 permission_request_map_[request_id] = request; | 405 permission_request_map_[request_id] = request; |
463 | 406 |
464 BrowserPluginGuestDelegate::PermissionResponseCallback callback = | 407 BrowserPluginGuestDelegate::PermissionResponseCallback callback = |
465 base::Bind(&BrowserPluginGuest::RespondToPermissionRequest, | 408 base::Bind(&BrowserPluginGuest::RespondToPermissionRequest, |
466 AsWeakPtr(), | 409 AsWeakPtr(), |
467 request_id); | 410 request_id); |
468 // If BrowserPluginGuestDelegate hasn't handled the permission then we simply | 411 delegate_->RequestPermission( |
469 // perform the default action (which is one of allow or reject) immediately. | 412 permission_type, request_info, callback, request->AllowedByDefault()); |
470 if (!delegate_->RequestPermission( | |
471 permission_type, request_info, callback, request->AllowedByDefault())) { | |
472 callback.Run(request->AllowedByDefault(), ""); | |
473 return browser_plugin::kInvalidPermissionRequestID; | |
474 } | |
475 | |
476 return request_id; | |
477 } | 413 } |
478 | 414 |
479 BrowserPluginGuest* BrowserPluginGuest::CreateNewGuestWindow( | 415 BrowserPluginGuest* BrowserPluginGuest::CreateNewGuestWindow( |
480 const OpenURLParams& params) { | 416 const OpenURLParams& params) { |
481 BrowserPluginGuestManager* guest_manager = | 417 BrowserPluginGuestManager* guest_manager = |
482 GetWebContents()->GetBrowserPluginGuestManager(); | 418 GetWebContents()->GetBrowserPluginGuestManager(); |
483 | 419 |
484 // Allocate a new instance ID for the new guest. | 420 // Allocate a new instance ID for the new guest. |
485 int instance_id = guest_manager->get_next_instance_id(); | 421 int instance_id = guest_manager->get_next_instance_id(); |
486 | 422 |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 985 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
1050 GetWebContents()->GetRenderViewHost()); | 986 GetWebContents()->GetRenderViewHost()); |
1051 guest_rvh->DragSourceSystemDragEnded(); | 987 guest_rvh->DragSourceSystemDragEnded(); |
1052 } | 988 } |
1053 | 989 |
1054 void BrowserPluginGuest::SetDelegate(BrowserPluginGuestDelegate* delegate) { | 990 void BrowserPluginGuest::SetDelegate(BrowserPluginGuestDelegate* delegate) { |
1055 DCHECK(!delegate_); | 991 DCHECK(!delegate_); |
1056 delegate_.reset(delegate); | 992 delegate_.reset(delegate); |
1057 } | 993 } |
1058 | 994 |
1059 void BrowserPluginGuest::AskEmbedderForGeolocationPermission( | |
1060 int bridge_id, | |
1061 const GURL& requesting_frame, | |
1062 bool user_gesture, | |
1063 const GeolocationCallback& callback) { | |
1064 base::DictionaryValue request_info; | |
1065 request_info.Set(browser_plugin::kURL, | |
1066 base::Value::CreateStringValue(requesting_frame.spec())); | |
1067 | |
1068 int request_id = | |
1069 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_GEOLOCATION, | |
1070 new GeolocationRequest(weak_ptr_factory_.GetWeakPtr(), | |
1071 callback, | |
1072 bridge_id, | |
1073 user_gesture), | |
1074 request_info); | |
1075 | |
1076 DCHECK(bridge_id_to_request_id_map_.find(bridge_id) == | |
1077 bridge_id_to_request_id_map_.end()); | |
1078 bridge_id_to_request_id_map_[bridge_id] = request_id; | |
1079 } | |
1080 | |
1081 int BrowserPluginGuest::RemoveBridgeID(int bridge_id) { | |
1082 std::map<int, int>::iterator bridge_itr = | |
1083 bridge_id_to_request_id_map_.find(bridge_id); | |
1084 if (bridge_itr == bridge_id_to_request_id_map_.end()) | |
1085 return browser_plugin::kInvalidPermissionRequestID; | |
1086 | |
1087 int request_id = bridge_itr->second; | |
1088 bridge_id_to_request_id_map_.erase(bridge_itr); | |
1089 return request_id; | |
1090 } | |
1091 | |
1092 void BrowserPluginGuest::CancelGeolocationRequest(int bridge_id) { | |
1093 int request_id = RemoveBridgeID(bridge_id); | |
1094 RequestMap::iterator request_itr = permission_request_map_.find(request_id); | |
1095 if (request_itr == permission_request_map_.end()) | |
1096 return; | |
1097 permission_request_map_.erase(request_itr); | |
1098 } | |
1099 | |
1100 void BrowserPluginGuest::SetGeolocationPermission(GeolocationCallback callback, | |
1101 int bridge_id, | |
1102 bool allowed) { | |
1103 callback.Run(allowed); | |
1104 RemoveBridgeID(bridge_id); | |
1105 } | |
1106 | |
1107 void BrowserPluginGuest::SendQueuedMessages() { | 995 void BrowserPluginGuest::SendQueuedMessages() { |
1108 if (!attached()) | 996 if (!attached()) |
1109 return; | 997 return; |
1110 | 998 |
1111 while (!pending_messages_.empty()) { | 999 while (!pending_messages_.empty()) { |
1112 IPC::Message* message = pending_messages_.front(); | 1000 IPC::Message* message = pending_messages_.front(); |
1113 pending_messages_.pop(); | 1001 pending_messages_.pop(); |
1114 SendMessageToEmbedder(message); | 1002 SendMessageToEmbedder(message); |
1115 } | 1003 } |
1116 } | 1004 } |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 base::Value::CreateStringValue(request_method)); | 1788 base::Value::CreateStringValue(request_method)); |
1901 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); | 1789 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); |
1902 | 1790 |
1903 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, | 1791 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, |
1904 new DownloadRequest(weak_ptr_factory_.GetWeakPtr(), | 1792 new DownloadRequest(weak_ptr_factory_.GetWeakPtr(), |
1905 callback), | 1793 callback), |
1906 request_info); | 1794 request_info); |
1907 } | 1795 } |
1908 | 1796 |
1909 } // namespace content | 1797 } // namespace content |
OLD | NEW |