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

Side by Side Diff: content/browser/site_per_process_browsertest.cc

Issue 2506183002: Make window.open() IPCs be frame-based (Closed)
Patch Set: Rebase. Created 3 years, 11 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/site_per_process_browsertest.h" 5 #include "content/browser/site_per_process_browsertest.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 7525 matching lines...) Expand 10 before | Expand all | Expand 10 after
7536 EXPECT_EQ(0, child_count); 7536 EXPECT_EQ(0, child_count);
7537 7537
7538 EXPECT_EQ( 7538 EXPECT_EQ(
7539 " Site A ------------ proxies for B\n" 7539 " Site A ------------ proxies for B\n"
7540 " +--Site B ------- proxies for A\n" 7540 " +--Site B ------- proxies for A\n"
7541 "Where A = http://a.com/\n" 7541 "Where A = http://a.com/\n"
7542 " B = http://b.com/", 7542 " B = http://b.com/",
7543 DepictFrameTree(root)); 7543 DepictFrameTree(root));
7544 } 7544 }
7545 7545
7546 // Helper filter class to wait for a ShowView or ShowWidget message, record the 7546 // Helper filter class to wait for a ShowCreatedWindow or ShowWidget message,
7547 // routing ID from the message, and then drop the message. 7547 // record the routing ID from the message, and then drop the message.
7548 const uint32_t kMessageClasses[] = {ViewMsgStart, FrameMsgStart};
7548 class PendingWidgetMessageFilter : public BrowserMessageFilter { 7549 class PendingWidgetMessageFilter : public BrowserMessageFilter {
7549 public: 7550 public:
7550 PendingWidgetMessageFilter() 7551 PendingWidgetMessageFilter()
7551 : BrowserMessageFilter(ViewMsgStart), 7552 : BrowserMessageFilter(kMessageClasses, arraysize(kMessageClasses)),
7552 routing_id_(MSG_ROUTING_NONE), 7553 routing_id_(MSG_ROUTING_NONE),
7553 message_loop_runner_(new MessageLoopRunner) {} 7554 message_loop_runner_(new MessageLoopRunner) {}
7554 7555
7555 bool OnMessageReceived(const IPC::Message& message) override { 7556 bool OnMessageReceived(const IPC::Message& message) override {
7556 bool handled = true; 7557 bool handled = true;
7557 IPC_BEGIN_MESSAGE_MAP(PendingWidgetMessageFilter, message) 7558 IPC_BEGIN_MESSAGE_MAP(PendingWidgetMessageFilter, message)
7558 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowView, OnShowView) 7559 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowCreatedWindow, OnShowCreatedWindow)
7559 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) 7560 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget)
7560 IPC_MESSAGE_UNHANDLED(handled = false) 7561 IPC_MESSAGE_UNHANDLED(handled = false)
7561 IPC_END_MESSAGE_MAP() 7562 IPC_END_MESSAGE_MAP()
7562 return handled; 7563 return handled;
7563 } 7564 }
7564 7565
7565 void Wait() { 7566 void Wait() {
7566 message_loop_runner_->Run(); 7567 message_loop_runner_->Run();
7567 } 7568 }
7568 7569
7569 int routing_id() { return routing_id_; } 7570 int routing_id() { return routing_id_; }
7570 7571
7571 private: 7572 private:
7572 ~PendingWidgetMessageFilter() override {} 7573 ~PendingWidgetMessageFilter() override {}
7573 7574
7574 void OnShowView(int routing_id, 7575 void OnShowCreatedWindow(int pending_widget_routing_id,
7575 WindowOpenDisposition disposition, 7576 WindowOpenDisposition disposition,
7576 const gfx::Rect& initial_rect, 7577 const gfx::Rect& initial_rect,
7577 bool user_gesture) { 7578 bool user_gesture) {
7578 content::BrowserThread::PostTask( 7579 content::BrowserThread::PostTask(
7579 content::BrowserThread::UI, FROM_HERE, 7580 content::BrowserThread::UI, FROM_HERE,
7580 base::Bind(&PendingWidgetMessageFilter::OnReceivedRoutingIDOnUI, this, 7581 base::Bind(&PendingWidgetMessageFilter::OnReceivedRoutingIDOnUI, this,
7581 routing_id)); 7582 pending_widget_routing_id));
7582 } 7583 }
7583 7584
7584 void OnShowWidget(int routing_id, const gfx::Rect& initial_rect) { 7585 void OnShowWidget(int routing_id, const gfx::Rect& initial_rect) {
7585 content::BrowserThread::PostTask( 7586 content::BrowserThread::PostTask(
7586 content::BrowserThread::UI, FROM_HERE, 7587 content::BrowserThread::UI, FROM_HERE,
7587 base::Bind(&PendingWidgetMessageFilter::OnReceivedRoutingIDOnUI, this, 7588 base::Bind(&PendingWidgetMessageFilter::OnReceivedRoutingIDOnUI, this,
7588 routing_id)); 7589 routing_id));
7589 } 7590 }
7590 7591
7591 void OnReceivedRoutingIDOnUI(int routing_id) { 7592 void OnReceivedRoutingIDOnUI(int widget_routing_id) {
7592 routing_id_ = routing_id; 7593 routing_id_ = widget_routing_id;
7593 message_loop_runner_->Quit(); 7594 message_loop_runner_->Quit();
7594 } 7595 }
7595 7596
7596 int routing_id_; 7597 int routing_id_;
7597 scoped_refptr<MessageLoopRunner> message_loop_runner_; 7598 scoped_refptr<MessageLoopRunner> message_loop_runner_;
7598 7599
7599 DISALLOW_COPY_AND_ASSIGN(PendingWidgetMessageFilter); 7600 DISALLOW_COPY_AND_ASSIGN(PendingWidgetMessageFilter);
7600 }; 7601 };
7601 7602
7602 // Test for https://crbug.com/612276. Simultaneously open two new windows from 7603 // Test for https://crbug.com/612276. Simultaneously open two new windows from
(...skipping 11 matching lines...) Expand all
7614 "a.com", "/cross_site_iframe_factory.html?a(b,c)")); 7615 "a.com", "/cross_site_iframe_factory.html?a(b,c)"));
7615 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 7616 EXPECT_TRUE(NavigateToURL(shell(), main_url));
7616 7617
7617 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); 7618 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
7618 FrameTreeNode* child1 = root->child_at(0); 7619 FrameTreeNode* child1 = root->child_at(0);
7619 FrameTreeNode* child2 = root->child_at(1); 7620 FrameTreeNode* child2 = root->child_at(1);
7620 RenderProcessHost* process1 = child1->current_frame_host()->GetProcess(); 7621 RenderProcessHost* process1 = child1->current_frame_host()->GetProcess();
7621 RenderProcessHost* process2 = child2->current_frame_host()->GetProcess(); 7622 RenderProcessHost* process2 = child2->current_frame_host()->GetProcess();
7622 7623
7623 // Call window.open simultaneously in both subframes to create two popups. 7624 // Call window.open simultaneously in both subframes to create two popups.
7624 // Wait for and then drop both ViewHostMsg_ShowView messages. This will 7625 // Wait for and then drop both FrameHostMsg_ShowCreatedWindow messages. This
7625 // ensure that both CreateNewWindow calls happen before either 7626 // will ensure that both CreateNewWindow calls happen before either
7626 // ShowCreatedWindow call. 7627 // ShowCreatedWindow call.
7627 scoped_refptr<PendingWidgetMessageFilter> filter1 = 7628 scoped_refptr<PendingWidgetMessageFilter> filter1 =
7628 new PendingWidgetMessageFilter(); 7629 new PendingWidgetMessageFilter();
7629 process1->AddFilter(filter1.get()); 7630 process1->AddFilter(filter1.get());
7630 EXPECT_TRUE(ExecuteScript(child1, "window.open();")); 7631 EXPECT_TRUE(ExecuteScript(child1, "window.open();"));
7631 filter1->Wait(); 7632 filter1->Wait();
7632 7633
7633 scoped_refptr<PendingWidgetMessageFilter> filter2 = 7634 scoped_refptr<PendingWidgetMessageFilter> filter2 =
7634 new PendingWidgetMessageFilter(); 7635 new PendingWidgetMessageFilter();
7635 process2->AddFilter(filter2.get()); 7636 process2->AddFilter(filter2.get());
7636 EXPECT_TRUE(ExecuteScript(child2, "window.open();")); 7637 EXPECT_TRUE(ExecuteScript(child2, "window.open();"));
7637 filter2->Wait(); 7638 filter2->Wait();
7638 7639
7639 // At this point, we should have two pending WebContents. 7640 // At this point, we should have two pending WebContents.
7640 EXPECT_TRUE(base::ContainsKey( 7641 EXPECT_TRUE(base::ContainsKey(
7641 web_contents()->pending_contents_, 7642 web_contents()->pending_contents_,
7642 std::make_pair(process1->GetID(), filter1->routing_id()))); 7643 std::make_pair(process1->GetID(), filter1->routing_id())));
7643 EXPECT_TRUE(base::ContainsKey( 7644 EXPECT_TRUE(base::ContainsKey(
7644 web_contents()->pending_contents_, 7645 web_contents()->pending_contents_,
7645 std::make_pair(process2->GetID(), filter2->routing_id()))); 7646 std::make_pair(process2->GetID(), filter2->routing_id())));
7646 7647
7647 // Both subframes were set up in the same way, so the next routing ID for the 7648 // Both subframes were set up in the same way, so the next routing ID for the
7648 // new popup windows should match up (this led to the collision in the 7649 // new popup windows should match up (this led to the collision in the
7649 // pending contents map in the original bug). 7650 // pending contents map in the original bug).
7650 EXPECT_EQ(filter1->routing_id(), filter2->routing_id()); 7651 EXPECT_EQ(filter1->routing_id(), filter2->routing_id());
7651 7652
7652 // Now, simulate that both ShowView messages arrive by showing both of the 7653 // Now, simulate that both FrameHostMsg_ShowCreatedWindow messages arrive by
7653 // pending WebContents. 7654 // showing both of the pending WebContents.
7654 web_contents()->ShowCreatedWindow(process1->GetID(), filter1->routing_id(), 7655 web_contents()->ShowCreatedWindow(process1->GetID(), filter1->routing_id(),
7655 WindowOpenDisposition::NEW_FOREGROUND_TAB, 7656 WindowOpenDisposition::NEW_FOREGROUND_TAB,
7656 gfx::Rect(), true); 7657 gfx::Rect(), true);
7657 web_contents()->ShowCreatedWindow(process2->GetID(), filter2->routing_id(), 7658 web_contents()->ShowCreatedWindow(process2->GetID(), filter2->routing_id(),
7658 WindowOpenDisposition::NEW_FOREGROUND_TAB, 7659 WindowOpenDisposition::NEW_FOREGROUND_TAB,
7659 gfx::Rect(), true); 7660 gfx::Rect(), true);
7660 7661
7661 // Verify that both shells were properly created. 7662 // Verify that both shells were properly created.
7662 EXPECT_EQ(3u, Shell::windows().size()); 7663 EXPECT_EQ(3u, Shell::windows().size());
7663 } 7664 }
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after
8990 rfh->OnSwappedOut(); 8991 rfh->OnSwappedOut();
8991 8992
8992 // Wait for the new a.com navigation to finish. 8993 // Wait for the new a.com navigation to finish.
8993 back_observer.Wait(); 8994 back_observer.Wait();
8994 8995
8995 // The RVH for a.com should've been reused, and it should be active. 8996 // The RVH for a.com should've been reused, and it should be active.
8996 EXPECT_TRUE(rvh->is_active()); 8997 EXPECT_TRUE(rvh->is_active());
8997 } 8998 }
8998 8999
8999 } // namespace content 9000 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/security_exploit_browsertest.cc ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698