tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / chromium / PlatformSupport.h
1 /*
2  * Copyright (c) 2010, Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30
31 #ifndef PlatformSupport_h
32 #define PlatformSupport_h
33
34 #if ENABLE(WEB_AUDIO)
35 #include "AudioBus.h"
36 #endif
37
38 #include "FileSystem.h"
39 #include "ImageSource.h"
40 #include "LinkHash.h"
41 #include "PassRefPtr.h"
42 #include "PasteboardPrivate.h"
43 #include "PluginData.h"
44
45 #include <wtf/Forward.h>
46 #include <wtf/HashSet.h>
47 #include <wtf/Vector.h>
48
49 typedef struct NPObject NPObject;
50 typedef struct _NPP NPP_t;
51 typedef NPP_t* NPP;
52
53 #if OS(DARWIN)
54 typedef struct CGFont* CGFontRef;
55 typedef uintptr_t ATSFontContainerRef;
56 #ifdef __OBJC__
57 @class NSFont;
58 #else
59 class NSFont;
60 #endif
61 #endif // OS(DARWIN)
62
63 #if OS(WINDOWS)
64 typedef struct HFONT__* HFONT;
65 #endif
66
67 namespace WebCore {
68
69 class Clipboard;
70 class Color;
71 class Cursor;
72 class Document;
73 class Frame;
74 class GamepadList;
75 class GeolocationServiceBridge;
76 class GeolocationServiceChromium;
77 class GraphicsContext;
78 class Image;
79 class IDBFactoryBackendInterface;
80 class IDBKey;
81 class IntRect;
82 class KURL;
83 class SerializedScriptValue;
84 class Widget;
85 class WorkerRunLoop;
86
87 struct Cookie;
88 struct FontRenderStyle;
89
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).
93
94 class PlatformSupport {
95 public:
96     // Cache --------------------------------------------------------------
97     static void cacheMetadata(const KURL&, double responseTime, const Vector<char>&);
98
99     // Clipboard ----------------------------------------------------------
100     static uint64_t clipboardSequenceNumber(PasteboardPrivate::ClipboardBuffer);
101
102     static bool clipboardIsFormatAvailable(PasteboardPrivate::ClipboardFormat, PasteboardPrivate::ClipboardBuffer);
103     static HashSet<String> clipboardReadAvailableTypes(PasteboardPrivate::ClipboardBuffer, bool* containsFilenames);
104
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);
108
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*);
117
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*);
125
126     // DNS ----------------------------------------------------------------
127     static void prefetchDNS(const String& hostname);
128
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);
148
149     // Font ---------------------------------------------------------------
150 #if OS(WINDOWS)
151     static bool ensureFontLoaded(HFONT);
152 #endif
153 #if OS(DARWIN)
154     static bool loadFont(NSFont* srcFont, CGFontRef*, uint32_t* fontID);
155 #elif OS(UNIX)
156     static void getRenderStyleForStrike(const char* family, int sizeAndStyle, FontRenderStyle* result);
157     struct FontFamily {
158         String name;
159         bool isBold;
160         bool isItalic;
161     };
162     static void getFontFamilyForCharacters(const UChar*, size_t numCharacters, const char* preferredLocale, FontFamily*);
163 #endif
164
165     // Forms --------------------------------------------------------------
166     static void notifyFormStateChanged(const Document*);
167
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);
179
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);
186
187     // Gamepad -----------------------------------------------------------
188     static void sampleGamepads(GamepadList* into);
189
190     // JavaScript ---------------------------------------------------------
191     static void notifyJSOutOfMemory(Frame*);
192     static bool allowScriptDespiteSettings(const KURL& documentURL);
193
194     // Keygen -------------------------------------------------------------
195     static String signedPublicKeyAndChallengeString(unsigned keySizeIndex, const String& challenge, const KURL&);
196
197     // Language -----------------------------------------------------------
198     static String computedDefaultLanguage();
199
200     // LayoutTestMode -----------------------------------------------------
201     static bool layoutTestMode();
202
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();
215
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);
224
225     // Plugin -------------------------------------------------------------
226     static bool plugins(bool refresh, Vector<PluginInfo>*);
227     static NPObject* pluginScriptableObject(Widget*);
228     static bool popupsAllowed(NPP);
229
230     // Resources ----------------------------------------------------------
231     static PassRefPtr<Image> loadPlatformImageResource(const char* name);
232
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);
236 #endif
237
238     // Sandbox ------------------------------------------------------------
239     static bool sandboxEnabled();
240
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*);
248
249     // SharedTimers -------------------------------------------------------
250     static void setSharedTimerFiredFunction(void (*func)());
251     static void setSharedTimerFireInterval(double);
252     static void stopSharedTimer();
253
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);
259
260     // Sudden Termination
261     static void suddenTerminationChanged(bool enabled);
262
263     // Theming ------------------------------------------------------------
264 #if OS(WINDOWS)
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);
283 #elif OS(DARWIN)
284     enum ThemePaintState {
285         StateDisabled,
286         StateInactive,
287         StateActive,
288         StatePressed,
289     };
290
291     enum ThemePaintSize {
292         SizeRegular,
293         SizeSmall,
294     };
295
296     enum ThemePaintScrollbarOrientation {
297         ScrollbarOrientationHorizontal,
298         ScrollbarOrientationVertical,
299     };
300
301     enum ThemePaintScrollbarParent {
302         ScrollbarParentScrollView,
303         ScrollbarParentRenderLayer,
304     };
305
306     struct ThemePaintScrollbarInfo {
307         ThemePaintScrollbarOrientation orientation;
308         ThemePaintScrollbarParent parent;
309         int maxValue;
310         int currentValue;
311         int visibleSize;
312         int totalSize;
313     };
314
315     static void paintScrollbarThumb(GraphicsContext*, ThemePaintState, ThemePaintSize, const IntRect&, const ThemePaintScrollbarInfo&);
316 #elif OS(UNIX)
317     // The UI part which is being accessed.
318     enum ThemePart {
319         // ScrollbarTheme parts
320         PartScrollbarDownArrow,
321         PartScrollbarLeftArrow,
322         PartScrollbarRightArrow,
323         PartScrollbarUpArrow,
324         PartScrollbarHorizontalThumb,
325         PartScrollbarVerticalThumb,
326         PartScrollbarHorizontalTrack,
327         PartScrollbarVerticalTrack,
328
329         // RenderTheme parts
330         PartCheckbox,
331         PartRadio,
332         PartButton,
333         PartTextField,
334         PartMenuList,
335         PartSliderTrack,
336         PartSliderThumb,
337         PartInnerSpinButton,
338         PartProgressBar
339     };
340
341     // The current state of the associated Part.
342     enum ThemePaintState {
343         StateDisabled,
344         StateHover,
345         StateNormal,
346         StatePressed
347     };
348
349     struct ScrollbarTrackExtraParams {
350         // The bounds of the entire track, as opposed to the part being painted.
351         int trackX;
352         int trackY;
353         int trackWidth;
354         int trackHeight;
355     };
356
357     struct ButtonExtraParams {
358         bool checked;
359         bool indeterminate; // Whether the button state is indeterminate.
360         bool isDefault; // Whether the button is default button.
361         bool hasBorder;
362         unsigned backgroundColor;
363     };
364
365     struct TextFieldExtraParams {
366         bool isTextArea;
367         bool isListbox;
368         unsigned backgroundColor;
369     };
370
371     struct MenuListExtraParams {
372         bool hasBorder;
373         bool hasBorderRadius;
374         int arrowX;
375         int arrowY;
376         unsigned backgroundColor;
377     };
378
379     struct SliderExtraParams {
380         bool vertical;
381         bool inDrag;
382     };
383
384     struct InnerSpinButtonExtraParams {
385         bool spinUp;
386         bool readOnly;
387     };
388
389     struct ProgressBarExtraParams {
390         bool determinate;
391         int valueRectX;
392         int valueRectY;
393         int valueRectWidth;
394         int valueRectHeight;
395     };
396
397     union ThemePaintExtraParams {
398         ScrollbarTrackExtraParams scrollbarTrack;
399         ButtonExtraParams button;
400         TextFieldExtraParams textField;
401         MenuListExtraParams menuList;
402         SliderExtraParams slider;
403         InnerSpinButtonExtraParams innerSpin;
404         ProgressBarExtraParams progressBar;
405     };
406
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*);
413 #endif
414
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);
419
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);
424
425     static void didStartWorkerRunLoop(WorkerRunLoop*);
426     static void didStopWorkerRunLoop(WorkerRunLoop*);
427 };
428
429 } // namespace WebCore
430
431 #endif