| 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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 return browser_plugin::kInvalidPermissionRequestID; | 402 return browser_plugin::kInvalidPermissionRequestID; |
| 459 } | 403 } |
| 460 | 404 |
| 461 int request_id = ++next_permission_request_id_; | 405 int request_id = ++next_permission_request_id_; |
| 462 permission_request_map_[request_id] = request; | 406 permission_request_map_[request_id] = request; |
| 463 | 407 |
| 464 BrowserPluginGuestDelegate::PermissionResponseCallback callback = | 408 BrowserPluginGuestDelegate::PermissionResponseCallback callback = |
| 465 base::Bind(&BrowserPluginGuest::RespondToPermissionRequest, | 409 base::Bind(&BrowserPluginGuest::RespondToPermissionRequest, |
| 466 AsWeakPtr(), | 410 AsWeakPtr(), |
| 467 request_id); | 411 request_id); |
| 468 // If BrowserPluginGuestDelegate hasn't handled the permission then we simply | 412 delegate_->RequestPermission( |
| 469 // perform the default action (which is one of allow or reject) immediately. | 413 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 | 414 |
| 476 return request_id; | 415 return request_id; |
| 477 } | 416 } |
| 478 | 417 |
| 479 BrowserPluginGuest* BrowserPluginGuest::CreateNewGuestWindow( | 418 BrowserPluginGuest* BrowserPluginGuest::CreateNewGuestWindow( |
| 480 const OpenURLParams& params) { | 419 const OpenURLParams& params) { |
| 481 BrowserPluginGuestManager* guest_manager = | 420 BrowserPluginGuestManager* guest_manager = |
| 482 GetWebContents()->GetBrowserPluginGuestManager(); | 421 GetWebContents()->GetBrowserPluginGuestManager(); |
| 483 | 422 |
| 484 // Allocate a new instance ID for the new guest. | 423 // Allocate a new instance ID for the new guest. |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 990 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
| 1052 GetWebContents()->GetRenderViewHost()); | 991 GetWebContents()->GetRenderViewHost()); |
| 1053 guest_rvh->DragSourceSystemDragEnded(); | 992 guest_rvh->DragSourceSystemDragEnded(); |
| 1054 } | 993 } |
| 1055 | 994 |
| 1056 void BrowserPluginGuest::SetDelegate(BrowserPluginGuestDelegate* delegate) { | 995 void BrowserPluginGuest::SetDelegate(BrowserPluginGuestDelegate* delegate) { |
| 1057 DCHECK(!delegate_); | 996 DCHECK(!delegate_); |
| 1058 delegate_.reset(delegate); | 997 delegate_.reset(delegate); |
| 1059 } | 998 } |
| 1060 | 999 |
| 1061 void BrowserPluginGuest::AskEmbedderForGeolocationPermission( | |
| 1062 int bridge_id, | |
| 1063 const GURL& requesting_frame, | |
| 1064 bool user_gesture, | |
| 1065 const GeolocationCallback& callback) { | |
| 1066 base::DictionaryValue request_info; | |
| 1067 request_info.Set(browser_plugin::kURL, | |
| 1068 base::Value::CreateStringValue(requesting_frame.spec())); | |
| 1069 | |
| 1070 int request_id = | |
| 1071 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_GEOLOCATION, | |
| 1072 new GeolocationRequest(weak_ptr_factory_.GetWeakPtr(), | |
| 1073 callback, | |
| 1074 bridge_id, | |
| 1075 user_gesture), | |
| 1076 request_info); | |
| 1077 | |
| 1078 DCHECK(bridge_id_to_request_id_map_.find(bridge_id) == | |
| 1079 bridge_id_to_request_id_map_.end()); | |
| 1080 bridge_id_to_request_id_map_[bridge_id] = request_id; | |
| 1081 } | |
| 1082 | |
| 1083 int BrowserPluginGuest::RemoveBridgeID(int bridge_id) { | |
| 1084 std::map<int, int>::iterator bridge_itr = | |
| 1085 bridge_id_to_request_id_map_.find(bridge_id); | |
| 1086 if (bridge_itr == bridge_id_to_request_id_map_.end()) | |
| 1087 return browser_plugin::kInvalidPermissionRequestID; | |
| 1088 | |
| 1089 int request_id = bridge_itr->second; | |
| 1090 bridge_id_to_request_id_map_.erase(bridge_itr); | |
| 1091 return request_id; | |
| 1092 } | |
| 1093 | |
| 1094 void BrowserPluginGuest::CancelGeolocationRequest(int bridge_id) { | |
| 1095 int request_id = RemoveBridgeID(bridge_id); | |
| 1096 RequestMap::iterator request_itr = permission_request_map_.find(request_id); | |
| 1097 if (request_itr == permission_request_map_.end()) | |
| 1098 return; | |
| 1099 permission_request_map_.erase(request_itr); | |
| 1100 } | |
| 1101 | |
| 1102 void BrowserPluginGuest::SetGeolocationPermission(GeolocationCallback callback, | |
| 1103 int bridge_id, | |
| 1104 bool allowed) { | |
| 1105 callback.Run(allowed); | |
| 1106 RemoveBridgeID(bridge_id); | |
| 1107 } | |
| 1108 | |
| 1109 void BrowserPluginGuest::SendQueuedMessages() { | 1000 void BrowserPluginGuest::SendQueuedMessages() { |
| 1110 if (!attached()) | 1001 if (!attached()) |
| 1111 return; | 1002 return; |
| 1112 | 1003 |
| 1113 while (!pending_messages_.empty()) { | 1004 while (!pending_messages_.empty()) { |
| 1114 IPC::Message* message = pending_messages_.front(); | 1005 IPC::Message* message = pending_messages_.front(); |
| 1115 pending_messages_.pop(); | 1006 pending_messages_.pop(); |
| 1116 SendMessageToEmbedder(message); | 1007 SendMessageToEmbedder(message); |
| 1117 } | 1008 } |
| 1118 } | 1009 } |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1932 base::Value::CreateStringValue(request_method)); | 1823 base::Value::CreateStringValue(request_method)); |
| 1933 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); | 1824 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); |
| 1934 | 1825 |
| 1935 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, | 1826 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, |
| 1936 new DownloadRequest(weak_ptr_factory_.GetWeakPtr(), | 1827 new DownloadRequest(weak_ptr_factory_.GetWeakPtr(), |
| 1937 callback), | 1828 callback), |
| 1938 request_info); | 1829 request_info); |
| 1939 } | 1830 } |
| 1940 | 1831 |
| 1941 } // namespace content | 1832 } // namespace content |
| OLD | NEW |