Remove ColorSpaceDeviceRGB and most users of the obsolete deviceRGB colorspace
[WebKit-https.git] / Source / WebKitLegacy / mac / WebView / WebViewData.mm
1 /*
2  * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3  * Copyright (C) 2006 David Smith (catfish.man@gmail.com)
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  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer. 
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution. 
14  * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission. 
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #import "WebViewData.h"
31
32 #import "WebKitLogging.h"
33 #import "WebPreferenceKeysPrivate.h"
34 #import "WebSelectionServiceController.h"
35 #import "WebViewGroup.h"
36 #import <WebCore/AlternativeTextUIController.h>
37 #import <WebCore/HistoryItem.h>
38 #import <WebCore/TextIndicatorWindow.h>
39 #import <WebCore/ValidationBubble.h>
40 #import <runtime/InitializeThreading.h>
41 #import <wtf/MainThread.h>
42 #import <wtf/RunLoop.h>
43
44 #if PLATFORM(IOS)
45 #import "WebGeolocationProviderIOS.h"
46 #endif
47
48 #if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
49 #import "WebMediaPlaybackTargetPicker.h"
50 #endif
51
52 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
53 #import <WebCore/PlaybackSessionInterfaceMac.h>
54 #import <WebCore/PlaybackSessionModelMediaElement.h>
55 #endif
56
57 BOOL applicationIsTerminating = NO;
58 int pluginDatabaseClientCount = 0;
59
60 void LayerFlushController::scheduleLayerFlush()
61 {
62     m_layerFlushScheduler.schedule();
63 }
64
65 void LayerFlushController::invalidate()
66 {
67     m_layerFlushScheduler.invalidate();
68     m_webView = nullptr;
69 }
70
71 LayerFlushController::LayerFlushController(WebView* webView)
72     : m_webView(webView)
73     , m_layerFlushScheduler(this)
74 {
75     ASSERT_ARG(webView, webView);
76 }
77
78 WebViewLayerFlushScheduler::WebViewLayerFlushScheduler(LayerFlushController* flushController)
79     : WebCore::LayerFlushScheduler(flushController)
80     , m_flushController(flushController)
81 {
82 }
83
84 #if PLATFORM(MAC)
85
86 @implementation WebWindowVisibilityObserver
87
88 - (instancetype)initWithView:(WebView *)view
89 {
90     self = [super init];
91     if (!self)
92         return nil;
93
94     _view = view;
95     return self;
96 }
97
98 - (void)startObserving:(NSWindow *)window
99 {
100     // An NSView derived object such as WebView cannot observe these notifications, because NSView itself observes them.
101     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowVisibilityChanged:)
102                                                  name:@"NSWindowDidOrderOffScreenNotification" object:window];
103     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowVisibilityChanged:)
104                                                  name:@"_NSWindowDidBecomeVisible" object:window];
105 }
106
107 - (void)stopObserving:(NSWindow *)window
108 {
109     [[NSNotificationCenter defaultCenter] removeObserver:self name:@"NSWindowDidOrderOffScreenNotification" object:window];
110     [[NSNotificationCenter defaultCenter] removeObserver:self name:@"_NSWindowDidBecomeVisible" object:window];
111 }
112
113 - (void)_windowVisibilityChanged:(NSNotification *)notification
114 {
115     [_view _windowVisibilityChanged:notification];
116 }
117
118 @end
119
120 #endif // PLATFORM(MAC)
121
122 @implementation WebViewPrivate
123
124 + (void)initialize
125 {
126 #if !PLATFORM(IOS)
127     JSC::initializeThreading();
128     WTF::initializeMainThreadToProcessMainThread();
129     RunLoop::initializeMainRunLoop();
130 #endif
131 }
132
133 - (id)init 
134 {
135     self = [super init];
136     if (!self)
137         return nil;
138
139     allowsUndo = YES;
140     usesPageCache = YES;
141     shouldUpdateWhileOffscreen = YES;
142
143     zoomMultiplier = 1;
144     zoomsTextOnly = NO;
145
146 #if PLATFORM(MAC)
147     interactiveFormValidationEnabled = YES;
148 #else
149     interactiveFormValidationEnabled = NO;
150 #endif
151     // The default value should be synchronized with WebCore/page/Settings.cpp.
152     validationMessageTimerMagnification = 50;
153
154 #if ENABLE(DASHBOARD_SUPPORT)
155     dashboardBehaviorAllowWheelScrolling = YES;
156 #endif
157
158 #if PLATFORM(IOS)
159     isStopping = NO;
160     _geolocationProvider = [WebGeolocationProviderIOS sharedGeolocationProvider];
161 #endif
162
163     shouldCloseWithWindow = false;
164
165     pluginDatabaseClientCount++;
166
167 #if USE(DICTATION_ALTERNATIVES)
168     m_alternativeTextUIController = std::make_unique<WebCore::AlternativeTextUIController>();
169 #endif
170
171     return self;
172 }
173
174 - (void)dealloc
175 {    
176     ASSERT(applicationIsTerminating || !page);
177     ASSERT(applicationIsTerminating || !preferences);
178 #if !PLATFORM(IOS)
179     ASSERT(!insertionPasteboard);
180 #endif
181 #if ENABLE(VIDEO)
182     ASSERT(!fullscreenController);
183 #endif
184
185     [applicationNameForUserAgent release];
186 #if !PLATFORM(IOS)
187     [backgroundColor release];
188 #else
189     CGColorRelease(backgroundColor);
190 #endif
191     [inspector release];
192     [currentNodeHighlight release];
193 #if PLATFORM(MAC)
194     [immediateActionController release];
195 #endif
196     [hostWindow release];
197     [policyDelegateForwarder release];
198     [UIDelegateForwarder release];
199     [frameLoadDelegateForwarder release];
200     [editingDelegateForwarder release];
201     [mediaStyle release];
202
203 #if ENABLE(REMOTE_INSPECTOR)
204 #if PLATFORM(IOS)
205     [indicateLayer release];
206 #endif
207 #endif
208
209 #if PLATFORM(IOS)
210     [UIKitDelegateForwarder release];
211     [formDelegateForwarder release];
212     [_caretChangeListeners release];
213     [_fixedPositionContent release];
214 #endif
215
216     [super dealloc];
217 }
218
219 @end