[Cocoa] More tweaks and refactoring to prepare for ARC
[WebKit.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 "WebViewInternal.h"
37 #import <JavaScriptCore/InitializeThreading.h>
38 #import <WebCore/AlternativeTextUIController.h>
39 #import <WebCore/HistoryItem.h>
40 #import <WebCore/TextIndicatorWindow.h>
41 #import <WebCore/ValidationBubble.h>
42 #import <wtf/MainThread.h>
43 #import <wtf/RunLoop.h>
44
45 #if PLATFORM(IOS)
46 #import "WebGeolocationProviderIOS.h"
47 #endif
48
49 #if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
50 #import "WebMediaPlaybackTargetPicker.h"
51 #endif
52
53 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
54 #import <WebCore/PlaybackSessionInterfaceMac.h>
55 #import <WebCore/PlaybackSessionModelMediaElement.h>
56 #endif
57
58 BOOL applicationIsTerminating = NO;
59 int pluginDatabaseClientCount = 0;
60
61 void LayerFlushController::scheduleLayerFlush()
62 {
63     m_layerFlushScheduler.schedule();
64 }
65
66 void LayerFlushController::invalidate()
67 {
68     m_layerFlushScheduler.invalidate();
69     m_webView = nullptr;
70 }
71
72 LayerFlushController::LayerFlushController(WebView* webView)
73     : m_webView(webView)
74     , m_layerFlushScheduler(this)
75 {
76     ASSERT_ARG(webView, webView);
77 }
78
79 WebViewLayerFlushScheduler::WebViewLayerFlushScheduler(LayerFlushController* flushController)
80     : WebCore::LayerFlushScheduler(flushController)
81     , m_flushController(flushController)
82 {
83 }
84
85 #if PLATFORM(MAC)
86
87 @implementation WebWindowVisibilityObserver
88
89 - (instancetype)initWithView:(WebView *)view
90 {
91     self = [super init];
92     if (!self)
93         return nil;
94
95     _view = view;
96     return self;
97 }
98
99 - (void)startObserving:(NSWindow *)window
100 {
101     // An NSView derived object such as WebView cannot observe these notifications, because NSView itself observes them.
102     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowVisibilityChanged:)
103                                                  name:@"NSWindowDidOrderOffScreenNotification" object:window];
104     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowVisibilityChanged:)
105                                                  name:@"_NSWindowDidBecomeVisible" object:window];
106 }
107
108 - (void)stopObserving:(NSWindow *)window
109 {
110     [[NSNotificationCenter defaultCenter] removeObserver:self name:@"NSWindowDidOrderOffScreenNotification" object:window];
111     [[NSNotificationCenter defaultCenter] removeObserver:self name:@"_NSWindowDidBecomeVisible" object:window];
112 }
113
114 - (void)_windowVisibilityChanged:(NSNotification *)notification
115 {
116     [_view _windowVisibilityChanged:notification];
117 }
118
119 @end
120
121 #endif // PLATFORM(MAC)
122
123 @implementation WebViewPrivate
124
125 + (void)initialize
126 {
127 #if !PLATFORM(IOS)
128     JSC::initializeThreading();
129     WTF::initializeMainThreadToProcessMainThread();
130     RunLoop::initializeMainRunLoop();
131 #endif
132 }
133
134 - (id)init 
135 {
136     self = [super init];
137     if (!self)
138         return nil;
139
140     allowsUndo = YES;
141     usesPageCache = YES;
142     shouldUpdateWhileOffscreen = YES;
143
144     zoomMultiplier = 1;
145     zoomsTextOnly = NO;
146
147 #if PLATFORM(MAC)
148     interactiveFormValidationEnabled = YES;
149 #else
150     interactiveFormValidationEnabled = NO;
151 #endif
152     // The default value should be synchronized with WebCore/page/Settings.cpp.
153     validationMessageTimerMagnification = 50;
154
155 #if ENABLE(DASHBOARD_SUPPORT)
156     dashboardBehaviorAllowWheelScrolling = YES;
157 #endif
158
159 #if PLATFORM(IOS)
160     isStopping = NO;
161     _geolocationProvider = [WebGeolocationProviderIOS sharedGeolocationProvider];
162 #endif
163
164     shouldCloseWithWindow = false;
165
166     pluginDatabaseClientCount++;
167
168 #if USE(DICTATION_ALTERNATIVES)
169     m_alternativeTextUIController = std::make_unique<WebCore::AlternativeTextUIController>();
170 #endif
171
172     return self;
173 }
174
175 - (void)dealloc
176 {    
177     ASSERT(applicationIsTerminating || !page);
178     ASSERT(applicationIsTerminating || !preferences);
179 #if !PLATFORM(IOS)
180     ASSERT(!insertionPasteboard);
181 #endif
182 #if ENABLE(VIDEO)
183     ASSERT(!fullscreenController);
184 #endif
185
186     [applicationNameForUserAgent release];
187 #if !PLATFORM(IOS)
188     [backgroundColor release];
189 #else
190     CGColorRelease(backgroundColor);
191 #endif
192     [inspector release];
193     [currentNodeHighlight release];
194 #if PLATFORM(MAC)
195     [immediateActionController release];
196 #endif
197     [hostWindow release];
198     [policyDelegateForwarder release];
199     [UIDelegateForwarder release];
200     [frameLoadDelegateForwarder release];
201     [editingDelegateForwarder release];
202     [mediaStyle release];
203
204 #if ENABLE(REMOTE_INSPECTOR)
205 #if PLATFORM(IOS)
206     [indicateLayer release];
207 #endif
208 #endif
209
210 #if PLATFORM(IOS)
211     [UIKitDelegateForwarder release];
212     [formDelegateForwarder release];
213     [_caretChangeListeners release];
214     [_fixedPositionContent release];
215 #endif
216
217     [super dealloc];
218 }
219
220 @end