Commit 235f2d1d authored by Wez's avatar Wez Committed by Commit Bot

[Fuchsia] Fix FrameImpl to cope with multiple View lifetimes.

Tear-down any existing View-related resources (e.g. Aura window, focus
controller etc) if a CreateView() request is received while a View is
already active for this Frame.

Bug: 920490
Change-Id: Iec4f7d393e33d583bc7dc8caf0bbea5f4ae11f6d
Reviewed-on: https://chromium-review.googlesource.com/c/1423901
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#628554}
parent 2db681ea
This diff is collapsed.
...@@ -50,6 +50,7 @@ class FrameImpl : public chromium::web::Frame, ...@@ -50,6 +50,7 @@ class FrameImpl : public chromium::web::Frame,
zx::unowned_channel GetBindingChannelForTest() const; zx::unowned_channel GetBindingChannelForTest() const;
content::WebContents* web_contents_for_test() { return web_contents_.get(); } content::WebContents* web_contents_for_test() { return web_contents_.get(); }
bool has_view_for_test() { return window_tree_host_ != nullptr; }
// chromium::web::Frame implementation. // chromium::web::Frame implementation.
void CreateView( void CreateView(
...@@ -96,6 +97,15 @@ class FrameImpl : public chromium::web::Frame, ...@@ -96,6 +97,15 @@ class FrameImpl : public chromium::web::Frame,
DISALLOW_COPY_AND_ASSIGN(OriginScopedScript); DISALLOW_COPY_AND_ASSIGN(OriginScopedScript);
}; };
aura::Window* root_window() const { return window_tree_host_->window(); }
// Release the resources associated with the View, if one is active.
void TearDownView();
// Sends |pending_navigation_event_| to the observer if there are any changes
// to be reported.
void MaybeSendNavigationEvent();
// chromium::web::NavigationController implementation. // chromium::web::NavigationController implementation.
void LoadUrl(std::string url, void LoadUrl(std::string url,
std::unique_ptr<chromium::web::LoadUrlParams> params) override; std::unique_ptr<chromium::web::LoadUrlParams> params) override;
...@@ -105,12 +115,6 @@ class FrameImpl : public chromium::web::Frame, ...@@ -105,12 +115,6 @@ class FrameImpl : public chromium::web::Frame,
void Reload(chromium::web::ReloadType type) override; void Reload(chromium::web::ReloadType type) override;
void GetVisibleEntry(GetVisibleEntryCallback callback) override; void GetVisibleEntry(GetVisibleEntryCallback callback) override;
aura::Window* root_window() const { return window_tree_host_->window(); }
// Sends |pending_navigation_event_| to the observer if there are any changes
// to be reported.
void MaybeSendNavigationEvent();
// content::WebContentsDelegate implementation. // content::WebContentsDelegate implementation.
bool ShouldCreateWebContents( bool ShouldCreateWebContents(
content::WebContents* web_contents, content::WebContents* web_contents,
......
...@@ -978,6 +978,46 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, PostMessageBadOriginDropped) { ...@@ -978,6 +978,46 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, PostMessageBadOriginDropped) {
EXPECT_FALSE(unused_message_read.has_value()); EXPECT_FALSE(unused_message_read.has_value());
} }
IN_PROC_BROWSER_TEST_F(FrameImplTest, RecreateView) {
chromium::web::FramePtr frame = CreateFrame();
ASSERT_TRUE(embedded_test_server()->Start());
// Process the Frame creation request, and verify we can get the FrameImpl.
base::RunLoop().RunUntilIdle();
FrameImpl* frame_impl = context_impl()->GetFrameImplForTest(&frame);
ASSERT_TRUE(frame_impl);
EXPECT_FALSE(frame_impl->has_view_for_test());
chromium::web::NavigationControllerPtr controller;
frame->GetNavigationController(controller.NewRequest());
// Verify that the Frame can navigate, prior to the View being created.
const GURL page1_url(embedded_test_server()->GetURL(kPage1Path));
CheckLoadUrl(page1_url.spec(), kPage1Title, nullptr, controller.get());
// Request a View from the Frame, and pump the loop to process the request.
zx::eventpair owner_token, frame_token;
ASSERT_EQ(zx::eventpair::create(0, &owner_token, &frame_token), ZX_OK);
frame->CreateView2(std::move(frame_token), nullptr, nullptr);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(frame_impl->has_view_for_test());
// Verify that the Frame still works, by navigating to Page #2.
const GURL page2_url(embedded_test_server()->GetURL(kPage2Path));
CheckLoadUrl(page2_url.spec(), kPage2Title, nullptr, controller.get());
// Create new View tokens and request a new view.
zx::eventpair owner_token2, frame_token2;
ASSERT_EQ(zx::eventpair::create(0, &owner_token2, &frame_token2), ZX_OK);
frame->CreateView2(std::move(frame_token), nullptr, nullptr);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(frame_impl->has_view_for_test());
// Verify that the Frame still works, by navigating back to Page #1.
CheckLoadUrl(page1_url.spec(), kPage1Title, nullptr, controller.get());
}
class RequestMonitoringFrameImplBrowserTest : public FrameImplTest { class RequestMonitoringFrameImplBrowserTest : public FrameImplTest {
public: public:
RequestMonitoringFrameImplBrowserTest() = default; RequestMonitoringFrameImplBrowserTest() = default;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment