1/*
2 * Copyright (C) 2010-2018 Apple Inc. All rights reserved.
3 * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#pragma once
28
29#include "DrawingAreaInfo.h"
30#include "GenericCallback.h"
31#include "MessageReceiver.h"
32#include "MessageSender.h"
33#include <WebCore/FloatRect.h>
34#include <WebCore/IntRect.h>
35#include <WebCore/IntSize.h>
36#include <stdint.h>
37#include <wtf/Noncopyable.h>
38#include <wtf/RunLoop.h>
39#include <wtf/TypeCasts.h>
40
41#if PLATFORM(COCOA)
42namespace WTF {
43class MachSendRight;
44}
45#endif
46
47namespace WebKit {
48
49class LayerTreeContext;
50class UpdateInfo;
51class WebPageProxy;
52class WebProcessProxy;
53
54class DrawingAreaProxy : public IPC::MessageReceiver, protected IPC::MessageSender {
55 WTF_MAKE_NONCOPYABLE(DrawingAreaProxy);
56
57public:
58 virtual ~DrawingAreaProxy();
59
60 DrawingAreaType type() const { return m_type; }
61 DrawingAreaIdentifier identifier() const { return m_identifier; }
62
63 virtual void deviceScaleFactorDidChange() = 0;
64
65 // FIXME: These should be pure virtual.
66 virtual void setBackingStoreIsDiscardable(bool) { }
67
68 virtual void waitForBackingStoreUpdateOnNextPaint() { }
69
70 const WebCore::IntSize& size() const { return m_size; }
71 bool setSize(const WebCore::IntSize&, const WebCore::IntSize& scrollOffset = { });
72
73 // The timeout we use when waiting for a DidUpdateGeometry message.
74 static constexpr Seconds didUpdateBackingStoreStateTimeout() { return Seconds::fromMilliseconds(500); }
75
76 virtual void colorSpaceDidChange() { }
77 virtual void viewLayoutSizeDidChange() { }
78
79 virtual void adjustTransientZoom(double, WebCore::FloatPoint) { }
80 virtual void commitTransientZoom(double, WebCore::FloatPoint) { }
81
82#if PLATFORM(MAC)
83 virtual void setViewExposedRect(Optional<WebCore::FloatRect>);
84 Optional<WebCore::FloatRect> viewExposedRect() const { return m_viewExposedRect; }
85 void viewExposedRectChangedTimerFired();
86#endif
87
88 virtual void updateDebugIndicator() { }
89
90 virtual void waitForDidUpdateActivityState(ActivityStateChangeID) { }
91
92 virtual void dispatchAfterEnsuringDrawing(WTF::Function<void (CallbackBase::Error)>&&) { ASSERT_NOT_REACHED(); }
93
94 // Hide the content until the currently pending update arrives.
95 virtual void hideContentUntilPendingUpdate() { ASSERT_NOT_REACHED(); }
96
97 // Hide the content until any update arrives.
98 virtual void hideContentUntilAnyUpdate() { ASSERT_NOT_REACHED(); }
99
100 virtual bool hasVisibleContent() const { return true; }
101
102 virtual void willSendUpdateGeometry() { }
103
104 virtual void prepareForAppSuspension() { }
105
106#if PLATFORM(COCOA)
107 virtual WTF::MachSendRight createFence();
108#endif
109
110 virtual void dispatchPresentationCallbacksAfterFlushingLayers(const Vector<CallbackID>&) { }
111
112 WebPageProxy& page() const { return m_webPageProxy; }
113 WebProcessProxy& process() { return m_process.get(); }
114 const WebProcessProxy& process() const { return m_process.get(); }
115
116protected:
117 DrawingAreaProxy(DrawingAreaType, WebPageProxy&, WebProcessProxy&);
118
119 DrawingAreaType m_type;
120 DrawingAreaIdentifier m_identifier;
121 WebPageProxy& m_webPageProxy;
122 Ref<WebProcessProxy> m_process;
123
124 WebCore::IntSize m_size;
125 WebCore::IntSize m_scrollOffset;
126
127 // IPC::MessageReceiver
128 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
129
130private:
131 virtual void sizeDidChange() = 0;
132
133 IPC::Connection* messageSenderConnection() const final;
134 uint64_t messageSenderDestinationID() const final { return m_identifier.toUInt64(); }
135 bool sendMessage(std::unique_ptr<IPC::Encoder>, OptionSet<IPC::SendOption>) final;
136
137 // Message handlers.
138 // FIXME: These should be pure virtual.
139 virtual void update(uint64_t /* backingStoreStateID */, const UpdateInfo&) { }
140 virtual void didUpdateBackingStoreState(uint64_t /* backingStoreStateID */, const UpdateInfo&, const LayerTreeContext&) { }
141 virtual void enterAcceleratedCompositingMode(uint64_t /* backingStoreStateID */, const LayerTreeContext&) { }
142 virtual void exitAcceleratedCompositingMode(uint64_t /* backingStoreStateID */, const UpdateInfo&) { }
143 virtual void updateAcceleratedCompositingMode(uint64_t /* backingStoreStateID */, const LayerTreeContext&) { }
144#if PLATFORM(COCOA)
145 virtual void didUpdateGeometry() { }
146
147#if PLATFORM(MAC)
148 RunLoop::Timer<DrawingAreaProxy> m_viewExposedRectChangedTimer;
149 Optional<WebCore::FloatRect> m_viewExposedRect;
150 Optional<WebCore::FloatRect> m_lastSentViewExposedRect;
151#endif // PLATFORM(MAC)
152#endif
153};
154
155} // namespace WebKit
156
157#define SPECIALIZE_TYPE_TRAITS_DRAWING_AREA_PROXY(ToValueTypeName, ProxyType) \
158SPECIALIZE_TYPE_TRAITS_BEGIN(WebKit::ToValueTypeName) \
159 static bool isType(const WebKit::DrawingAreaProxy& proxy) { return proxy.type() == WebKit::ProxyType; } \
160SPECIALIZE_TYPE_TRAITS_END()
161
162