Commit 031945ba authored by Ehsan Karamad's avatar Ehsan Karamad Committed by Commit Bot

[ MimeHandlerView ] DidLoad should affect frame container once

MimeHandlerViewContainerManager::DidLoad is used to notify the renderer that
PostMessageSupport can be active and forward messages. The current logic
activates the first PostMessageSupport with a matching URL. This should be the
first PostMessageSupport that is *not* active and has a matching URL.

TBR=wjmaclean@chromium.org

Bug: 957373
Change-Id: Ic2925b593081ec5ac83d6950a1f57243d2b41e45
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1608820Reviewed-by: default avatarEhsan Karamad <ekaramad@chromium.org>
Reviewed-by: default avatarJames MacLean <wjmaclean@chromium.org>
Commit-Queue: Ehsan Karamad <ekaramad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659036}
parent 6026a8c5
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "components/app_modal/native_app_modal_dialog.h" #include "components/app_modal/native_app_modal_dialog.h"
#include "components/guest_view/browser/test_guest_view_manager.h" #include "components/guest_view/browser/test_guest_view_manager.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
...@@ -574,3 +575,41 @@ IN_PROC_BROWSER_TEST_F(MimeHandlerViewBrowserPluginSpecificTest, ...@@ -574,3 +575,41 @@ IN_PROC_BROWSER_TEST_F(MimeHandlerViewBrowserPluginSpecificTest,
} }
EXPECT_EQ(GetMouseCaptureWidget(embedder_web_contents), guest_widget); EXPECT_EQ(GetMouseCaptureWidget(embedder_web_contents), guest_widget);
} }
// Helper class to wait for document load event in the main frame.
class DocumentLoadComplete : public content::WebContentsObserver {
public:
explicit DocumentLoadComplete(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {}
~DocumentLoadComplete() override {}
void DocumentOnLoadCompletedInMainFrame() override {
did_load_ = true;
run_loop_.Quit();
}
void Wait() {
if (!did_load_)
run_loop_.Run();
}
private:
bool did_load_ = false;
base::RunLoop run_loop_;
};
IN_PROC_BROWSER_TEST_P(MimeHandlerViewCrossProcessTest,
ActivatePostMessageSupportOnce) {
RunTest("test_embedded.html");
// Attach a second <embed>.
ASSERT_TRUE(content::ExecJs(GetEmbedderWebContents(),
"const e = document.createElement('embed');"
"e.src = './testEmbedded.csv'; e.type='text/csv';"
"document.body.appendChild(e);"));
DocumentLoadComplete(GetGuestViewManager()->WaitForNextGuestCreated()).Wait();
// After load, an IPC has been sent to the renderer to update routing IDs for
// the guest frame and the content frame (and activate the
// PostMessageSupport). Run some JS to Ensure no DCHECKs have fired in the
// embedder process.
ASSERT_TRUE(content::ExecJs(GetEmbedderWebContents(), "foo = 0;"));
}
\ No newline at end of file
...@@ -154,6 +154,8 @@ void MimeHandlerViewContainerManager::DidLoad(int32_t element_instance_id, ...@@ -154,6 +154,8 @@ void MimeHandlerViewContainerManager::DidLoad(int32_t element_instance_id,
return; return;
} }
for (auto& frame_container : frame_containers_) { for (auto& frame_container : frame_containers_) {
if (frame_container->post_message_support()->is_active())
continue;
if (frame_container->resource_url() != resource_url) if (frame_container->resource_url() != resource_url)
continue; continue;
// To ensure the postMessages will be sent to the right target frame, we // To ensure the postMessages will be sent to the right target frame, we
......
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