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

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

Issue 288113005: <webview>: Cleanup Pointer Lock & Simplify HandleKeyboardEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unnecessary braces Created 6 years, 7 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
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/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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 RequestNewWindowPermission(params.disposition, gfx::Rect(), 334 RequestNewWindowPermission(params.disposition, gfx::Rect(),
335 params.user_gesture, new_guest->GetWebContents()); 335 params.user_gesture, new_guest->GetWebContents());
336 336
337 return new_guest; 337 return new_guest;
338 } 338 }
339 339
340 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { 340 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() {
341 return weak_ptr_factory_.GetWeakPtr(); 341 return weak_ptr_factory_.GetWeakPtr();
342 } 342 }
343 343
344 bool BrowserPluginGuest::LockMouse(bool allowed) {
345 if (!attached() || (mouse_locked_ == allowed))
346 return false;
347
348 return embedder_web_contents()->GotResponseToLockMouseRequest(allowed);
349 }
350
344 void BrowserPluginGuest::EmbedderDestroyed() { 351 void BrowserPluginGuest::EmbedderDestroyed() {
345 embedder_web_contents_ = NULL; 352 embedder_web_contents_ = NULL;
346 if (delegate_) 353 if (delegate_)
347 delegate_->EmbedderDestroyed(); 354 delegate_->EmbedderDestroyed();
348 Destroy(); 355 Destroy();
349 } 356 }
350 357
351 void BrowserPluginGuest::Destroy() { 358 void BrowserPluginGuest::Destroy() {
352 is_in_destruction_ = true; 359 is_in_destruction_ = true;
353 if (!attached() && GetOpener()) 360 if (!attached() && GetOpener())
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 return delegate_->HandleContextMenu(context_menu_params); 655 return delegate_->HandleContextMenu(context_menu_params);
649 } 656 }
650 657
651 // Will be handled by WebContentsViewGuest. 658 // Will be handled by WebContentsViewGuest.
652 return false; 659 return false;
653 } 660 }
654 661
655 void BrowserPluginGuest::HandleKeyboardEvent( 662 void BrowserPluginGuest::HandleKeyboardEvent(
656 WebContents* source, 663 WebContents* source,
657 const NativeWebKeyboardEvent& event) { 664 const NativeWebKeyboardEvent& event) {
658 if (!attached()) 665 if (!delegate_)
659 return; 666 return;
660 667
661 if (UnlockMouseIfNecessary(event)) 668 delegate_->HandleKeyboardEvent(event);
662 return;
663
664 if (delegate_ && delegate_->HandleKeyboardEvent(event))
665 return;
666
667 if (!embedder_web_contents_->GetDelegate())
668 return;
669
670 // Send the unhandled keyboard events back to the embedder to reprocess them.
671 // TODO(fsamuel): This introduces the possibility of out-of-order keyboard
672 // events because the guest may be arbitrarily delayed when responding to
673 // keyboard events. In that time, the embedder may have received and processed
674 // additional key events. This needs to be fixed as soon as possible.
675 // See http://crbug.com/229882.
676 embedder_web_contents_->GetDelegate()->HandleKeyboardEvent(
677 web_contents(), event);
678 } 669 }
679 670
680 void BrowserPluginGuest::SetZoom(double zoom_factor) { 671 void BrowserPluginGuest::SetZoom(double zoom_factor) {
681 if (delegate_) 672 if (delegate_)
682 delegate_->SetZoom(zoom_factor); 673 delegate_->SetZoom(zoom_factor);
683 } 674 }
684 675
685 void BrowserPluginGuest::PointerLockPermissionResponse(bool allow) { 676 void BrowserPluginGuest::PointerLockPermissionResponse(bool allow) {
686 SendMessageToEmbedder( 677 SendMessageToEmbedder(
687 new BrowserPluginMsg_SetMouseLock(instance_id(), allow)); 678 new BrowserPluginMsg_SetMouseLock(instance_id(), allow));
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 request_info.Set(browser_plugin::kWindowOpenDisposition, 807 request_info.Set(browser_plugin::kWindowOpenDisposition,
817 base::Value::CreateStringValue( 808 base::Value::CreateStringValue(
818 WindowOpenDispositionToString(disposition))); 809 WindowOpenDispositionToString(disposition)));
819 810
820 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW, 811 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW,
821 new NewWindowRequest(weak_ptr_factory_.GetWeakPtr(), 812 new NewWindowRequest(weak_ptr_factory_.GetWeakPtr(),
822 guest->instance_id()), 813 guest->instance_id()),
823 request_info); 814 request_info);
824 } 815 }
825 816
826 bool BrowserPluginGuest::UnlockMouseIfNecessary(
827 const NativeWebKeyboardEvent& event) {
828 if (!mouse_locked_)
829 return false;
830
831 embedder_web_contents()->GotResponseToLockMouseRequest(false);
832 return true;
833 }
834
835 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { 817 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) {
836 if (!attached()) { 818 if (!attached()) {
837 // Some pages such as data URLs, javascript URLs, and about:blank 819 // Some pages such as data URLs, javascript URLs, and about:blank
838 // do not load external resources and so they load prior to attachment. 820 // do not load external resources and so they load prior to attachment.
839 // As a result, we must save all these IPCs until attachment and then 821 // As a result, we must save all these IPCs until attachment and then
840 // forward them so that the embedder gets a chance to see and process 822 // forward them so that the embedder gets a chance to see and process
841 // the load events. 823 // the load events.
842 pending_messages_.push(msg); 824 pending_messages_.push(msg);
843 return; 825 return;
844 } 826 }
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 void BrowserPluginGuest::OnImeCompositionRangeChanged( 1499 void BrowserPluginGuest::OnImeCompositionRangeChanged(
1518 const gfx::Range& range, 1500 const gfx::Range& range,
1519 const std::vector<gfx::Rect>& character_bounds) { 1501 const std::vector<gfx::Rect>& character_bounds) {
1520 static_cast<RenderWidgetHostViewBase*>( 1502 static_cast<RenderWidgetHostViewBase*>(
1521 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( 1503 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged(
1522 range, character_bounds); 1504 range, character_bounds);
1523 } 1505 }
1524 #endif 1506 #endif
1525 1507
1526 } // namespace content 1508 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_plugin/browser_plugin_guest.h ('k') | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698