| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 virtual void RespondImpl(bool should_allow, | 133 virtual void RespondImpl(bool should_allow, |
| 134 const std::string& user_input) OVERRIDE { | 134 const std::string& user_input) OVERRIDE { |
| 135 callback_.Run(should_allow, base::UTF8ToUTF16(user_input)); | 135 callback_.Run(should_allow, base::UTF8ToUTF16(user_input)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 virtual ~JavaScriptDialogRequest() {} | 139 virtual ~JavaScriptDialogRequest() {} |
| 140 DialogClosedCallback callback_; | 140 DialogClosedCallback callback_; |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 class BrowserPluginGuest::PointerLockRequest : public PermissionRequest { | |
| 144 public: | |
| 145 explicit PointerLockRequest(const base::WeakPtr<BrowserPluginGuest>& guest) | |
| 146 : PermissionRequest(guest) { | |
| 147 RecordAction( | |
| 148 base::UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.PointerLo
ck")); | |
| 149 } | |
| 150 | |
| 151 virtual void RespondImpl(bool should_allow, | |
| 152 const std::string& user_input) OVERRIDE { | |
| 153 guest_->SendMessageToEmbedder( | |
| 154 new BrowserPluginMsg_SetMouseLock(guest_->instance_id(), should_allow)); | |
| 155 } | |
| 156 | |
| 157 private: | |
| 158 virtual ~PointerLockRequest() {} | |
| 159 }; | |
| 160 | |
| 161 namespace { | 143 namespace { |
| 162 std::string WindowOpenDispositionToString( | 144 std::string WindowOpenDispositionToString( |
| 163 WindowOpenDisposition window_open_disposition) { | 145 WindowOpenDisposition window_open_disposition) { |
| 164 switch (window_open_disposition) { | 146 switch (window_open_disposition) { |
| 165 case IGNORE_ACTION: | 147 case IGNORE_ACTION: |
| 166 return "ignore"; | 148 return "ignore"; |
| 167 case SAVE_TO_DISK: | 149 case SAVE_TO_DISK: |
| 168 return "save_to_disk"; | 150 return "save_to_disk"; |
| 169 case CURRENT_TAB: | 151 case CURRENT_TAB: |
| 170 return "current_tab"; | 152 return "current_tab"; |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 // See http://crbug.com/229882. | 706 // See http://crbug.com/229882. |
| 725 embedder_web_contents_->GetDelegate()->HandleKeyboardEvent( | 707 embedder_web_contents_->GetDelegate()->HandleKeyboardEvent( |
| 726 web_contents(), event); | 708 web_contents(), event); |
| 727 } | 709 } |
| 728 | 710 |
| 729 void BrowserPluginGuest::SetZoom(double zoom_factor) { | 711 void BrowserPluginGuest::SetZoom(double zoom_factor) { |
| 730 if (delegate_) | 712 if (delegate_) |
| 731 delegate_->SetZoom(zoom_factor); | 713 delegate_->SetZoom(zoom_factor); |
| 732 } | 714 } |
| 733 | 715 |
| 716 void BrowserPluginGuest::PointerLockPermissionResponse(bool allow) { |
| 717 SendMessageToEmbedder( |
| 718 new BrowserPluginMsg_SetMouseLock(instance_id(), allow)); |
| 719 } |
| 720 |
| 734 void BrowserPluginGuest::FindReply(WebContents* contents, | 721 void BrowserPluginGuest::FindReply(WebContents* contents, |
| 735 int request_id, | 722 int request_id, |
| 736 int number_of_matches, | 723 int number_of_matches, |
| 737 const gfx::Rect& selection_rect, | 724 const gfx::Rect& selection_rect, |
| 738 int active_match_ordinal, | 725 int active_match_ordinal, |
| 739 bool final_update) { | 726 bool final_update) { |
| 740 if (!delegate_) | 727 if (!delegate_) |
| 741 return; | 728 return; |
| 742 | 729 |
| 743 // |selection_rect| is updated to incorporate embedder coordinates. | 730 // |selection_rect| is updated to incorporate embedder coordinates. |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 | 1265 |
| 1279 void BrowserPluginGuest::OnLockMouse(bool user_gesture, | 1266 void BrowserPluginGuest::OnLockMouse(bool user_gesture, |
| 1280 bool last_unlocked_by_target, | 1267 bool last_unlocked_by_target, |
| 1281 bool privileged) { | 1268 bool privileged) { |
| 1282 if (pending_lock_request_) { | 1269 if (pending_lock_request_) { |
| 1283 // Immediately reject the lock because only one pointerLock may be active | 1270 // Immediately reject the lock because only one pointerLock may be active |
| 1284 // at a time. | 1271 // at a time. |
| 1285 Send(new ViewMsg_LockMouse_ACK(routing_id(), false)); | 1272 Send(new ViewMsg_LockMouse_ACK(routing_id(), false)); |
| 1286 return; | 1273 return; |
| 1287 } | 1274 } |
| 1275 |
| 1276 if (!delegate_) |
| 1277 return; |
| 1278 |
| 1288 pending_lock_request_ = true; | 1279 pending_lock_request_ = true; |
| 1289 base::DictionaryValue request_info; | |
| 1290 request_info.Set(browser_plugin::kUserGesture, | |
| 1291 base::Value::CreateBooleanValue(user_gesture)); | |
| 1292 request_info.Set(browser_plugin::kLastUnlockedBySelf, | |
| 1293 base::Value::CreateBooleanValue(last_unlocked_by_target)); | |
| 1294 request_info.Set(browser_plugin::kURL, | |
| 1295 base::Value::CreateStringValue( | |
| 1296 web_contents()->GetLastCommittedURL().spec())); | |
| 1297 | 1280 |
| 1298 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK, | 1281 delegate_->RequestPointerLockPermission( |
| 1299 new PointerLockRequest(weak_ptr_factory_.GetWeakPtr()), | 1282 user_gesture, |
| 1300 request_info); | 1283 last_unlocked_by_target, |
| 1284 base::Bind(&BrowserPluginGuest::PointerLockPermissionResponse, |
| 1285 weak_ptr_factory_.GetWeakPtr())); |
| 1301 } | 1286 } |
| 1302 | 1287 |
| 1303 void BrowserPluginGuest::OnLockMouseAck(int instance_id, bool succeeded) { | 1288 void BrowserPluginGuest::OnLockMouseAck(int instance_id, bool succeeded) { |
| 1304 Send(new ViewMsg_LockMouse_ACK(routing_id(), succeeded)); | 1289 Send(new ViewMsg_LockMouse_ACK(routing_id(), succeeded)); |
| 1305 pending_lock_request_ = false; | 1290 pending_lock_request_ = false; |
| 1306 if (succeeded) | 1291 if (succeeded) |
| 1307 mouse_locked_ = true; | 1292 mouse_locked_ = true; |
| 1308 } | 1293 } |
| 1309 | 1294 |
| 1310 void BrowserPluginGuest::OnNavigateGuest( | 1295 void BrowserPluginGuest::OnNavigateGuest( |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1730 const GURL& url) { | 1715 const GURL& url) { |
| 1731 if (!url.is_valid()) { | 1716 if (!url.is_valid()) { |
| 1732 callback.Run(false); | 1717 callback.Run(false); |
| 1733 return; | 1718 return; |
| 1734 } | 1719 } |
| 1735 | 1720 |
| 1736 delegate_->CanDownload(request_method, url, callback); | 1721 delegate_->CanDownload(request_method, url, callback); |
| 1737 } | 1722 } |
| 1738 | 1723 |
| 1739 } // namespace content | 1724 } // namespace content |
| OLD | NEW |