| OLD | NEW |
| 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/public/test/browser_test_utils.h" | 5 #include "content/public/test/browser_test_utils.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 return false; | 1526 return false; |
| 1527 } | 1527 } |
| 1528 | 1528 |
| 1529 bool RequestFrame(WebContents* web_contents) { | 1529 bool RequestFrame(WebContents* web_contents) { |
| 1530 DCHECK(web_contents); | 1530 DCHECK(web_contents); |
| 1531 return RenderWidgetHostImpl::From( | 1531 return RenderWidgetHostImpl::From( |
| 1532 web_contents->GetRenderViewHost()->GetWidget()) | 1532 web_contents->GetRenderViewHost()->GetWidget()) |
| 1533 ->ScheduleComposite(); | 1533 ->ScheduleComposite(); |
| 1534 } | 1534 } |
| 1535 | 1535 |
| 1536 FrameWatcher::FrameWatcher() : MessageFilter(), frames_to_wait_(0) {} | 1536 FrameWatcher::FrameWatcher() = default; |
| 1537 | 1537 |
| 1538 FrameWatcher::~FrameWatcher() { | 1538 FrameWatcher::FrameWatcher(WebContents* web_contents) |
| 1539 } | 1539 : WebContentsObserver(web_contents) {} |
| 1540 | 1540 |
| 1541 void FrameWatcher::ReceivedFrameSwap(cc::CompositorFrameMetadata metadata) { | 1541 FrameWatcher::~FrameWatcher() = default; |
| 1542 --frames_to_wait_; | |
| 1543 last_metadata_ = std::move(metadata); | |
| 1544 if (frames_to_wait_ == 0) | |
| 1545 quit_.Run(); | |
| 1546 } | |
| 1547 | |
| 1548 bool FrameWatcher::OnMessageReceived(const IPC::Message& message) { | |
| 1549 if (message.type() == ViewHostMsg_SwapCompositorFrame::ID) { | |
| 1550 ViewHostMsg_SwapCompositorFrame::Param param; | |
| 1551 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) | |
| 1552 return false; | |
| 1553 cc::CompositorFrame frame(std::move(std::get<2>(param))); | |
| 1554 | |
| 1555 BrowserThread::PostTask( | |
| 1556 BrowserThread::UI, FROM_HERE, | |
| 1557 base::Bind(&FrameWatcher::ReceivedFrameSwap, this, | |
| 1558 base::Passed(std::move(frame.metadata)))); | |
| 1559 } | |
| 1560 return false; | |
| 1561 } | |
| 1562 | |
| 1563 void FrameWatcher::AttachTo(WebContents* web_contents) { | |
| 1564 DCHECK(web_contents); | |
| 1565 RenderWidgetHostImpl* widget_host = RenderWidgetHostImpl::From( | |
| 1566 web_contents->GetRenderViewHost()->GetWidget()); | |
| 1567 widget_host->GetProcess()->GetChannel()->AddFilter(this); | |
| 1568 } | |
| 1569 | 1542 |
| 1570 void FrameWatcher::WaitFrames(int frames_to_wait) { | 1543 void FrameWatcher::WaitFrames(int frames_to_wait) { |
| 1544 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1571 if (frames_to_wait <= 0) | 1545 if (frames_to_wait <= 0) |
| 1572 return; | 1546 return; |
| 1573 base::RunLoop run_loop; | 1547 base::RunLoop run_loop; |
| 1574 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); | 1548 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); |
| 1575 base::AutoReset<int> reset_frames_to_wait(&frames_to_wait_, frames_to_wait); | 1549 base::AutoReset<int> reset_frames_to_wait(&frames_to_wait_, frames_to_wait); |
| 1576 run_loop.Run(); | 1550 run_loop.Run(); |
| 1577 } | 1551 } |
| 1578 | 1552 |
| 1579 const cc::CompositorFrameMetadata& FrameWatcher::LastMetadata() { | 1553 const cc::CompositorFrameMetadata& FrameWatcher::LastMetadata() { |
| 1580 return last_metadata_; | 1554 return RenderWidgetHostImpl::From( |
| 1555 web_contents()->GetRenderViewHost()->GetWidget()) |
| 1556 ->last_frame_metadata(); |
| 1557 } |
| 1558 |
| 1559 void FrameWatcher::DidReceiveCompositorFrame() { |
| 1560 --frames_to_wait_; |
| 1561 if (frames_to_wait_ == 0) |
| 1562 quit_.Run(); |
| 1581 } | 1563 } |
| 1582 | 1564 |
| 1583 MainThreadFrameObserver::MainThreadFrameObserver( | 1565 MainThreadFrameObserver::MainThreadFrameObserver( |
| 1584 RenderWidgetHost* render_widget_host) | 1566 RenderWidgetHost* render_widget_host) |
| 1585 : render_widget_host_(render_widget_host), | 1567 : render_widget_host_(render_widget_host), |
| 1586 routing_id_(render_widget_host_->GetProcess()->GetNextRoutingID()) { | 1568 routing_id_(render_widget_host_->GetProcess()->GetNextRoutingID()) { |
| 1587 // TODO(lfg): We should look into adding a way to observe RenderWidgetHost | 1569 // TODO(lfg): We should look into adding a way to observe RenderWidgetHost |
| 1588 // messages similarly to what WebContentsObserver can do with RFH and RVW. | 1570 // messages similarly to what WebContentsObserver can do with RFH and RVW. |
| 1589 render_widget_host_->GetProcess()->AddRoute(routing_id_, this); | 1571 render_widget_host_->GetProcess()->AddRoute(routing_id_, this); |
| 1590 } | 1572 } |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1981 bool user_gesture, | 1963 bool user_gesture, |
| 1982 bool last_unlocked_by_target, | 1964 bool last_unlocked_by_target, |
| 1983 bool privileged) { | 1965 bool privileged) { |
| 1984 IPC::IpcSecurityTestUtil::PwnMessageReceived( | 1966 IPC::IpcSecurityTestUtil::PwnMessageReceived( |
| 1985 process->GetChannel(), | 1967 process->GetChannel(), |
| 1986 ViewHostMsg_LockMouse(routing_id, user_gesture, last_unlocked_by_target, | 1968 ViewHostMsg_LockMouse(routing_id, user_gesture, last_unlocked_by_target, |
| 1987 privileged)); | 1969 privileged)); |
| 1988 } | 1970 } |
| 1989 | 1971 |
| 1990 } // namespace content | 1972 } // namespace content |
| OLD | NEW |