1 /* 2 * Copyright 2009, 2010, The Android Open Source Project 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef PlatformBridge_h 27 #define PlatformBridge_h 28 29 #include "KURL.h" 30 #include "npapi.h" 31 #include "PlatformString.h" 32 33 #include <wtf/Vector.h> 34 35 // V8 bindings use the ARRAYSIZE_UNSAFE macro. This macro was copied 36 // from http://src.chromium.org/viewvc/chrome/trunk/src/base/basictypes.h 37 // 38 // ARRAYSIZE_UNSAFE performs essentially the same calculation as arraysize, 39 // but can be used on anonymous types or types defined inside 40 // functions. It's less safe than arraysize as it accepts some 41 // (although not all) pointers. Therefore, you should use arraysize 42 // whenever possible. 43 // 44 // The expression ARRAYSIZE_UNSAFE(a) is a compile-time constant of type 45 // size_t. 46 // 47 // ARRAYSIZE_UNSAFE catches a few type errors. If you see a compiler error 48 // 49 // "warning: division by zero in ..." 50 // 51 // when using ARRAYSIZE_UNSAFE, you are (wrongfully) giving it a pointer. 52 // You should only use ARRAYSIZE_UNSAFE on statically allocated arrays. 53 // 54 // The following comments are on the implementation details, and can 55 // be ignored by the users. 56 // 57 // ARRAYSIZE_UNSAFE(arr) works by inspecting sizeof(arr) (the # of bytes in 58 // the array) and sizeof(*(arr)) (the # of bytes in one array 59 // element). If the former is divisible by the latter, perhaps arr is 60 // indeed an array, in which case the division result is the # of 61 // elements in the array. Otherwise, arr cannot possibly be an array, 62 // and we generate a compiler error to prevent the code from 63 // compiling. 64 // 65 // Since the size of bool is implementation-defined, we need to cast 66 // !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final 67 // result has type size_t. 68 // 69 // This macro is not perfect as it wrongfully accepts certain 70 // pointers, namely where the pointer size is divisible by the pointee 71 // size. Since all our code has to go through a 32-bit compiler, 72 // where a pointer is 4 bytes, this means all pointers to a type whose 73 // size is 3 or greater than 4 will be (righteously) rejected. 74 75 #define ARRAYSIZE_UNSAFE(a) \ 76 ((sizeof(a) / sizeof(*(a))) / \ 77 static_cast<size_t>(!(sizeof(a) % sizeof(*(a))))) 78 79 80 class NPObject; 81 82 namespace WebCore { 83 84 #if USE(ACCELERATED_COMPOSITING) 85 class LayerAndroid; 86 #endif 87 88 class FrameView; 89 class Widget; 90 91 // An interface to the embedding layer, which has the ability to answer 92 // questions about the system and so on... 93 // This is very similar to ChromiumBridge and the two are likely to converge 94 // in the future. 95 // 96 // The methods in this class all need to reach across a JNI layer to the Java VM 97 // where the embedder runs. The JNI machinery is currently all in WebKit/android 98 // but the long term plan is to move to the WebKit API and share the bridge and its 99 // implementation with Chromium. The JNI machinery will then move outside of WebKit, 100 // similarly to how Chromium's IPC layer lives outside of WebKit. 101 class PlatformBridge { 102 public: 103 // KeyGenerator 104 static WTF::Vector<String> getSupportedKeyStrengthList(); 105 static String getSignedPublicKeyAndChallengeString(unsigned index, const String& challenge, const KURL&); 106 // Cookies 107 static void setCookies(const KURL&, const String& value); 108 static String cookies(const KURL&); 109 static bool cookiesEnabled(); 110 // Plugin 111 static NPObject* pluginScriptableObject(Widget*); 112 // Popups 113 static bool popupsAllowed(NPP); 114 115 // These ids need to be in sync with the constants in BrowserFrame.java 116 enum rawResId { 117 NoDomain = 1, 118 LoadError, 119 DrawableDir, 120 FileUploadLabel, 121 ResetLabel, 122 SubmitLabel 123 }; 124 static String* globalLocalizedName(rawResId resId); 125 126 #if USE(ACCELERATED_COMPOSITING) 127 // Those methods are used by the layers system 128 static void setUIRootLayer(const FrameView* view, const LayerAndroid* layer); 129 static void immediateRepaint(const FrameView* view); 130 #endif // USE(ACCELERATED_COMPOSITING) 131 static int screenWidth(const FrameView* view); 132 static int screenHeight(const FrameView* view); 133 134 // Whether the WebView is paused. 135 // ANDROID 136 // TODO: Upstream to webkit.org. See https://bugs.webkit.org/show_bug.cgi?id=34082 137 static bool isWebViewPaused(const FrameView*); 138 }; 139 140 } 141 #endif // PlatformBridge_h 142