2 * Copyright (c) 2010, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef PlatformSupport_h
32 #define PlatformSupport_h
38 #include "FileSystem.h"
39 #include "ImageSource.h"
41 #include "PassRefPtr.h"
42 #include "PasteboardPrivate.h"
43 #include "PluginData.h"
45 #include <wtf/Forward.h>
46 #include <wtf/HashSet.h>
47 #include <wtf/Vector.h>
49 typedef struct NPObject NPObject;
50 typedef struct _NPP NPP_t;
54 typedef struct CGFont* CGFontRef;
55 typedef uintptr_t ATSFontContainerRef;
64 typedef struct HFONT__* HFONT;
75 class GeolocationServiceBridge;
76 class GeolocationServiceChromium;
77 class GraphicsContext;
79 class IDBFactoryBackendInterface;
83 class SerializedScriptValue;
88 struct FontRenderStyle;
90 // PlatformSupport an interface to the embedding layer that lets the embedder
91 // supply implementations for Platform functionality that WebCore cannot access
92 // directly (for example, because WebCore is in a sandbox).
94 class PlatformSupport {
96 // Cache --------------------------------------------------------------
97 static void cacheMetadata(const KURL&, double responseTime, const Vector<char>&);
99 // Clipboard ----------------------------------------------------------
100 static uint64_t clipboardSequenceNumber(PasteboardPrivate::ClipboardBuffer);
102 static bool clipboardIsFormatAvailable(PasteboardPrivate::ClipboardFormat, PasteboardPrivate::ClipboardBuffer);
103 static HashSet<String> clipboardReadAvailableTypes(PasteboardPrivate::ClipboardBuffer, bool* containsFilenames);
105 static String clipboardReadPlainText(PasteboardPrivate::ClipboardBuffer);
106 static void clipboardReadHTML(PasteboardPrivate::ClipboardBuffer, String*, KURL*, unsigned* fragmentStart, unsigned* fragmentEnd);
107 static PassRefPtr<SharedBuffer> clipboardReadImage(PasteboardPrivate::ClipboardBuffer);
109 // Only the clipboardRead functions take a buffer argument because
110 // Chromium currently uses a different technique to write to alternate
111 // clipboard buffers.
112 static void clipboardWriteSelection(const String&, const KURL&, const String&, bool);
113 static void clipboardWritePlainText(const String&);
114 static void clipboardWriteURL(const KURL&, const String&);
115 static void clipboardWriteImage(NativeImagePtr, const KURL&, const String&);
116 static void clipboardWriteDataObject(Clipboard*);
118 // Cookies ------------------------------------------------------------
119 static void setCookies(const Document*, const KURL&, const String& value);
120 static String cookies(const Document*, const KURL&);
121 static String cookieRequestHeaderFieldValue(const Document*, const KURL&);
122 static bool rawCookies(const Document*, const KURL&, Vector<Cookie>&);
123 static void deleteCookie(const Document*, const KURL&, const String& cookieName);
124 static bool cookiesEnabled(const Document*);
126 // DNS ----------------------------------------------------------------
127 static void prefetchDNS(const String& hostname);
129 // File ---------------------------------------------------------------
130 static void revealFolderInOS(const String&);
131 static bool fileExists(const String&);
132 static bool deleteFile(const String&);
133 static bool deleteEmptyDirectory(const String&);
134 static bool getFileSize(const String&, long long& result);
135 static bool getFileModificationTime(const String&, time_t& result);
136 static String directoryName(const String& path);
137 static String pathByAppendingComponent(const String& path, const String& component);
138 static bool makeAllDirectories(const String& path);
139 static String getAbsolutePath(const String&);
140 static bool isDirectory(const String&);
141 static KURL filePathToURL(const String&);
142 static PlatformFileHandle openFile(const String& path, FileOpenMode);
143 static void closeFile(PlatformFileHandle&);
144 static long long seekFile(PlatformFileHandle, long long offset, FileSeekOrigin);
145 static bool truncateFile(PlatformFileHandle, long long offset);
146 static int readFromFile(PlatformFileHandle, char* data, int length);
147 static int writeToFile(PlatformFileHandle, const char* data, int length);
149 // Font ---------------------------------------------------------------
151 static bool ensureFontLoaded(HFONT);
154 static bool loadFont(NSFont* srcFont, CGFontRef*, uint32_t* fontID);
156 static void getRenderStyleForStrike(const char* family, int sizeAndStyle, FontRenderStyle* result);
162 static void getFontFamilyForCharacters(const UChar*, size_t numCharacters, const char* preferredLocale, FontFamily*);
165 // Forms --------------------------------------------------------------
166 static void notifyFormStateChanged(const Document*);
168 // Databases ----------------------------------------------------------
169 // Returns a handle to the DB file and ooptionally a handle to its containing directory
170 static PlatformFileHandle databaseOpenFile(const String& vfsFleName, int desiredFlags);
171 // Returns a SQLite code (SQLITE_OK = 0, on success)
172 static int databaseDeleteFile(const String& vfsFileName, bool syncDir = false);
173 // Returns the attributes of the DB file
174 static long databaseGetFileAttributes(const String& vfsFileName);
175 // Returns the size of the DB file
176 static long long databaseGetFileSize(const String& vfsFileName);
177 // Returns the space available for the origin
178 static long long databaseGetSpaceAvailableForOrigin(const String& originIdentifier);
180 // IndexedDB ----------------------------------------------------------
181 static PassRefPtr<IDBFactoryBackendInterface> idbFactory();
182 // Extracts keyPath from values and returns the corresponding keys.
183 static void createIDBKeysFromSerializedValuesAndKeyPath(const Vector<RefPtr<SerializedScriptValue> >& values, const String& keyPath, Vector<RefPtr<IDBKey> >& keys);
184 // Injects key via keyPath into value. Returns true on success.
185 static PassRefPtr<SerializedScriptValue> injectIDBKeyIntoSerializedValue(PassRefPtr<IDBKey>, PassRefPtr<SerializedScriptValue>, const String& keyPath);
187 // Gamepad -----------------------------------------------------------
188 static void sampleGamepads(GamepadList* into);
190 // JavaScript ---------------------------------------------------------
191 static void notifyJSOutOfMemory(Frame*);
192 static bool allowScriptDespiteSettings(const KURL& documentURL);
194 // Keygen -------------------------------------------------------------
195 static String signedPublicKeyAndChallengeString(unsigned keySizeIndex, const String& challenge, const KURL&);
197 // Language -----------------------------------------------------------
198 static String computedDefaultLanguage();
200 // LayoutTestMode -----------------------------------------------------
201 static bool layoutTestMode();
203 // Memory -------------------------------------------------------------
204 // Returns the current space allocated for the pagefile, in MB.
205 // That is committed size for Windows and virtual memory size for POSIX
206 static int memoryUsageMB();
207 // Same as above, but always returns actual value, without any caches.
208 static int actualMemoryUsageMB();
209 // If memory usage is below this threshold, do not bother forcing GC.
210 static int lowMemoryUsageMB();
211 // If memory usage is above this threshold, force GC more aggressively.
212 static int highMemoryUsageMB();
213 // Delta of memory usage growth (vs. last actualMemoryUsageMB()) to force GC when memory usage is high.
214 static int highUsageDeltaMB();
216 // MimeType -----------------------------------------------------------
217 static bool isSupportedImageMIMEType(const String& mimeType);
218 static bool isSupportedJavaScriptMIMEType(const String& mimeType);
219 static bool isSupportedNonImageMIMEType(const String& mimeType);
220 static String mimeTypeForExtension(const String& fileExtension);
221 static String wellKnownMimeTypeForExtension(const String& fileExtension);
222 static String mimeTypeFromFile(const String& filePath);
223 static String preferredExtensionForMIMEType(const String& mimeType);
225 // Plugin -------------------------------------------------------------
226 static bool plugins(bool refresh, Vector<PluginInfo>*);
227 static NPObject* pluginScriptableObject(Widget*);
228 static bool popupsAllowed(NPP);
230 // Resources ----------------------------------------------------------
231 static PassRefPtr<Image> loadPlatformImageResource(const char* name);
233 #if ENABLE(WEB_AUDIO)
234 static PassOwnPtr<AudioBus> loadPlatformAudioResource(const char* name, double sampleRate);
235 static PassOwnPtr<AudioBus> decodeAudioFileData(const char* data, size_t, double sampleRate);
238 // Sandbox ------------------------------------------------------------
239 static bool sandboxEnabled();
241 // Screen -------------------------------------------------------------
242 static int screenDepth(Widget*);
243 static int screenDepthPerComponent(Widget*);
244 static bool screenIsMonochrome(Widget*);
245 static IntRect screenRect(Widget*);
246 static IntRect screenAvailableRect(Widget*);
247 static double screenRefreshRate(Widget*);
249 // SharedTimers -------------------------------------------------------
250 static void setSharedTimerFiredFunction(void (*func)());
251 static void setSharedTimerFireInterval(double);
252 static void stopSharedTimer();
254 // StatsCounters ------------------------------------------------------
255 static void decrementStatsCounter(const char* name);
256 static void incrementStatsCounter(const char* name);
257 static void histogramCustomCounts(const char* name, int sample, int min, int max, int bucketCount);
258 static void histogramEnumeration(const char* name, int sample, int boundaryValue);
260 // Sudden Termination
261 static void suddenTerminationChanged(bool enabled);
263 // Theming ------------------------------------------------------------
265 static void paintButton(
266 GraphicsContext*, int part, int state, int classicState, const IntRect&);
267 static void paintMenuList(
268 GraphicsContext*, int part, int state, int classicState, const IntRect&);
269 static void paintScrollbarArrow(
270 GraphicsContext*, int state, int classicState, const IntRect&);
271 static void paintScrollbarThumb(
272 GraphicsContext*, int part, int state, int classicState, const IntRect&);
273 static void paintScrollbarTrack(
274 GraphicsContext*, int part, int state, int classicState, const IntRect&, const IntRect& alignRect);
275 static void paintSpinButton(
276 GraphicsContext*, int part, int state, int classicState, const IntRect&);
277 static void paintTextField(
278 GraphicsContext*, int part, int state, int classicState, const IntRect&, const Color&, bool fillContentArea, bool drawEdges);
279 static void paintTrackbar(
280 GraphicsContext*, int part, int state, int classicState, const IntRect&);
281 static void paintProgressBar(
282 GraphicsContext*, const IntRect& barRect, const IntRect& valueRect, bool determinate, double animatedSeconds);
284 enum ThemePaintState {
291 enum ThemePaintSize {
296 enum ThemePaintScrollbarOrientation {
297 ScrollbarOrientationHorizontal,
298 ScrollbarOrientationVertical,
301 enum ThemePaintScrollbarParent {
302 ScrollbarParentScrollView,
303 ScrollbarParentRenderLayer,
306 struct ThemePaintScrollbarInfo {
307 ThemePaintScrollbarOrientation orientation;
308 ThemePaintScrollbarParent parent;
315 static void paintScrollbarThumb(GraphicsContext*, ThemePaintState, ThemePaintSize, const IntRect&, const ThemePaintScrollbarInfo&);
317 // The UI part which is being accessed.
319 // ScrollbarTheme parts
320 PartScrollbarDownArrow,
321 PartScrollbarLeftArrow,
322 PartScrollbarRightArrow,
323 PartScrollbarUpArrow,
324 PartScrollbarHorizontalThumb,
325 PartScrollbarVerticalThumb,
326 PartScrollbarHorizontalTrack,
327 PartScrollbarVerticalTrack,
341 // The current state of the associated Part.
342 enum ThemePaintState {
349 struct ScrollbarTrackExtraParams {
350 // The bounds of the entire track, as opposed to the part being painted.
357 struct ButtonExtraParams {
359 bool indeterminate; // Whether the button state is indeterminate.
360 bool isDefault; // Whether the button is default button.
362 unsigned backgroundColor;
365 struct TextFieldExtraParams {
368 unsigned backgroundColor;
371 struct MenuListExtraParams {
373 bool hasBorderRadius;
376 unsigned backgroundColor;
379 struct SliderExtraParams {
384 struct InnerSpinButtonExtraParams {
389 struct ProgressBarExtraParams {
397 union ThemePaintExtraParams {
398 ScrollbarTrackExtraParams scrollbarTrack;
399 ButtonExtraParams button;
400 TextFieldExtraParams textField;
401 MenuListExtraParams menuList;
402 SliderExtraParams slider;
403 InnerSpinButtonExtraParams innerSpin;
404 ProgressBarExtraParams progressBar;
407 // Gets the size of the given theme part. For variable sized items
408 // like vertical scrollbar thumbs, the width will be the required width of
409 // the track while the height will be the minimum height.
410 static IntSize getThemePartSize(ThemePart);
411 // Paint the given the given theme part.
412 static void paintThemePart(GraphicsContext*, ThemePart, ThemePaintState, const IntRect&, const ThemePaintExtraParams*);
415 // Trace Event --------------------------------------------------------
416 static bool isTraceEventEnabled();
417 static void traceEventBegin(const char* name, void*, const char* extra);
418 static void traceEventEnd(const char* name, void*, const char* extra);
420 // Visited links ------------------------------------------------------
421 static LinkHash visitedLinkHash(const UChar* url, unsigned length);
422 static LinkHash visitedLinkHash(const KURL& base, const AtomicString& attributeURL);
423 static bool isLinkVisited(LinkHash);
425 static void didStartWorkerRunLoop(WorkerRunLoop*);
426 static void didStopWorkerRunLoop(WorkerRunLoop*);
429 } // namespace WebCore