From 87a98e428afa9dff6d02ff37d1504411d40fda3d Mon Sep 17 00:00:00 2001 From: lazyboy Date: Tue, 21 Jul 2015 03:12:08 -0700 Subject: Fix nested GuestView's container bounds calculation. This results in incorrect context menu positioning in pdf in webview or webview inside appview. If a guest A is nested within an embedder B, which in turn is nested inside an embedder C, then we used to add offset twice to calculate the bounds of A because BrowserPluginGuest::GetScreenCoordinates would add: 1. offset of C from A and 2. offset of B from A. This CL removes step #2. From logs, it seems to be there from the beginning of appview implementation. BUG=507223 Test=Load a PDF inside and check context menu inside the PDF. Easier to test with the browser sample: https://github.com/GoogleChrome/chrome-app-samples/tree/master/samples/webview-samples/browser You should observe the context menu is shown in the right place instead of it being shifted. Review URL: https://codereview.chromium.org/1237343002 Cr-Commit-Position: refs/heads/master@{#339635} --- .../guest_view/browser/test_guest_view_manager.cc | 32 +++++++++++++++++----- .../guest_view/browser/test_guest_view_manager.h | 14 +++++++--- 2 files changed, 35 insertions(+), 11 deletions(-) (limited to 'components') diff --git a/components/guest_view/browser/test_guest_view_manager.cc b/components/guest_view/browser/test_guest_view_manager.cc index 78458ef..c23399a 100644 --- a/components/guest_view/browser/test_guest_view_manager.cc +++ b/components/guest_view/browser/test_guest_view_manager.cc @@ -15,7 +15,9 @@ TestGuestViewManager::TestGuestViewManager( : GuestViewManager(context, delegate.Pass()), num_embedder_processes_destroyed_(0), num_guests_created_(0), - num_views_garbage_collected_(0) { + expected_num_guests_created_(0), + num_views_garbage_collected_(0), + waiting_for_guests_created_(false) { } TestGuestViewManager::~TestGuestViewManager() { @@ -51,22 +53,28 @@ void TestGuestViewManager::WaitForLastGuestDeleted() { guest_web_contents_watchers_.back()->Wait(); }; -void TestGuestViewManager::WaitForGuestCreated() { - created_message_loop_runner_ = new content::MessageLoopRunner; - created_message_loop_runner_->Run(); -} - content::WebContents* TestGuestViewManager::WaitForSingleGuestCreated() { if (!GetNumGuestsActive()) { // Guests have been created and subsequently destroyed. if (num_guests_created() > 0) return nullptr; - WaitForGuestCreated(); + WaitForNumGuestsCreated(1u); } return GetLastGuestCreated(); } +void TestGuestViewManager::WaitForNumGuestsCreated(size_t count) { + if (count == num_guests_created_) + return; + + waiting_for_guests_created_ = true; + expected_num_guests_created_ = count; + + created_message_loop_runner_ = new content::MessageLoopRunner; + created_message_loop_runner_->Run(); +} + void TestGuestViewManager::WaitForViewGarbageCollected() { gc_message_loop_runner_ = new content::MessageLoopRunner; gc_message_loop_runner_->Run(); @@ -86,11 +94,21 @@ void TestGuestViewManager::AddGuest(int guest_instance_id, new content::WebContentsDestroyedWatcher(guest_web_contents))); ++num_guests_created_; + if (!waiting_for_guests_created_ && + num_guests_created_ != expected_num_guests_created_) { + return; + } if (created_message_loop_runner_.get()) created_message_loop_runner_->Quit(); } +void TestGuestViewManager::GetGuestWebContentsList( + std::vector* guest_web_contents_list) { + for (auto& watcher : guest_web_contents_watchers_) + guest_web_contents_list->push_back(watcher->web_contents()); +} + void TestGuestViewManager::RemoveGuest(int guest_instance_id) { GuestViewManager::RemoveGuest(guest_instance_id); } diff --git a/components/guest_view/browser/test_guest_view_manager.h b/components/guest_view/browser/test_guest_view_manager.h index 76f0cd7..5367737 100644 --- a/components/guest_view/browser/test_guest_view_manager.h +++ b/components/guest_view/browser/test_guest_view_manager.h @@ -25,6 +25,7 @@ class TestGuestViewManager : public GuestViewManager { void WaitForLastGuestDeleted(); content::WebContents* WaitForSingleGuestCreated(); + void WaitForNumGuestsCreated(size_t count); void WaitForSingleViewGarbageCollected(); @@ -56,7 +57,7 @@ class TestGuestViewManager : public GuestViewManager { // Returns the number of guests that have been created since the creation of // this GuestViewManager. - int num_guests_created() const { return num_guests_created_; } + size_t num_guests_created() const { return num_guests_created_; } // Returns the number of GuestViews that have been garbage collected in // JavaScript since the creation of this GuestViewManager. @@ -67,6 +68,11 @@ class TestGuestViewManager : public GuestViewManager { // Returns the last guest instance ID removed from the manager. int last_instance_id_removed() const { return last_instance_id_removed_; } + // Returns the list of guests WebContentses that were created by this + // manager. + void GetGuestWebContentsList( + std::vector* guest_web_contents_list); + private: FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove); @@ -78,16 +84,16 @@ class TestGuestViewManager : public GuestViewManager { void ViewGarbageCollected(int embedder_process_id, int view_instance_id) override; - void WaitForGuestCreated(); - void WaitForViewGarbageCollected(); using GuestViewManager::last_instance_id_removed_; using GuestViewManager::removed_instance_ids_; int num_embedder_processes_destroyed_; - int num_guests_created_; + size_t num_guests_created_; + size_t expected_num_guests_created_; int num_views_garbage_collected_; + bool waiting_for_guests_created_; std::vector> guest_web_contents_watchers_; -- cgit v1.1