| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/test_runner/composite_async_then.h" |
| 6 |
| 7 #include "base/callback.h" |
| 8 #include "base/trace_event/trace_event.h" |
| 9 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.h" |
| 10 #include "third_party/WebKit/public/web/WebPagePopup.h" |
| 11 #include "third_party/WebKit/public/web/WebWidget.h" |
| 12 |
| 13 namespace test_runner { |
| 14 |
| 15 namespace { |
| 16 |
| 17 class CompositeCallback : public blink::WebCompositeAndReadbackAsyncCallback { |
| 18 public: |
| 19 CompositeCallback(const base::Closure& callback) |
| 20 : callback_(callback), wait_for_popup_(false) {} |
| 21 virtual ~CompositeCallback() {} |
| 22 |
| 23 void set_wait_for_popup(bool wait) { wait_for_popup_ = wait; } |
| 24 |
| 25 // WebCompositeAndReadbackAsyncCallback implementation. |
| 26 bool needsBitmap() const override; |
| 27 void didCompositeAndReadback(const SkBitmap& bitmap) override; |
| 28 |
| 29 private: |
| 30 base::Closure callback_; |
| 31 bool wait_for_popup_; |
| 32 }; |
| 33 |
| 34 bool CompositeCallback::needsBitmap() const { |
| 35 return false; |
| 36 } |
| 37 |
| 38 void CompositeCallback::didCompositeAndReadback(const SkBitmap& bitmap) { |
| 39 TRACE_EVENT0("shell", "LayoutAndPaintCallback::didComposite"); |
| 40 if (wait_for_popup_) { |
| 41 wait_for_popup_ = false; |
| 42 return; |
| 43 } |
| 44 |
| 45 if (!callback_.is_null()) |
| 46 callback_.Run(); |
| 47 delete this; |
| 48 } |
| 49 |
| 50 } // namespace |
| 51 |
| 52 void CompositeAsyncThen(blink::WebWidget* web_widget, |
| 53 const base::Closure& callback) { |
| 54 TRACE_EVENT0("shell", "CompositeAsyncThen"); |
| 55 |
| 56 CompositeCallback* composite_callback = |
| 57 new CompositeCallback(callback); |
| 58 web_widget->compositeAndReadbackAsync(composite_callback); |
| 59 if (blink::WebPagePopup* popup = web_widget->pagePopup()) { |
| 60 composite_callback->set_wait_for_popup(true); |
| 61 popup->compositeAndReadbackAsync(composite_callback); |
| 62 } |
| 63 } |
| 64 |
| 65 } // namespace test_runner |
| OLD | NEW |