Home | History | Annotate | Download | only in android
      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 "FloatRect.h"
     30 #include "KURL.h"
     31 #include "PlatformString.h"
     32 #include "npapi.h"
     33 
     34 #include <wtf/Vector.h>
     35 
     36 // V8 bindings use the ARRAYSIZE_UNSAFE macro. This macro was copied
     37 // from http://src.chromium.org/viewvc/chrome/trunk/src/base/basictypes.h
     38 //
     39 // ARRAYSIZE_UNSAFE performs essentially the same calculation as arraysize,
     40 // but can be used on anonymous types or types defined inside
     41 // functions. It's less safe than arraysize as it accepts some
     42 // (although not all) pointers. Therefore, you should use arraysize
     43 // whenever possible.
     44 //
     45 // The expression ARRAYSIZE_UNSAFE(a) is a compile-time constant of type
     46 // size_t.
     47 //
     48 // ARRAYSIZE_UNSAFE catches a few type errors. If you see a compiler error
     49 //
     50 //   "warning: division by zero in ..."
     51 //
     52 // when using ARRAYSIZE_UNSAFE, you are (wrongfully) giving it a pointer.
     53 // You should only use ARRAYSIZE_UNSAFE on statically allocated arrays.
     54 //
     55 // The following comments are on the implementation details, and can
     56 // be ignored by the users.
     57 //
     58 // ARRAYSIZE_UNSAFE(arr) works by inspecting sizeof(arr) (the # of bytes in
     59 // the array) and sizeof(*(arr)) (the # of bytes in one array
     60 // element). If the former is divisible by the latter, perhaps arr is
     61 // indeed an array, in which case the division result is the # of
     62 // elements in the array. Otherwise, arr cannot possibly be an array,
     63 // and we generate a compiler error to prevent the code from
     64 // compiling.
     65 //
     66 // Since the size of bool is implementation-defined, we need to cast
     67 // !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final
     68 // result has type size_t.
     69 //
     70 // This macro is not perfect as it wrongfully accepts certain
     71 // pointers, namely where the pointer size is divisible by the pointee
     72 // size. Since all our code has to go through a 32-bit compiler,
     73 // where a pointer is 4 bytes, this means all pointers to a type whose
     74 // size is 3 or greater than 4 will be (righteously) rejected.
     75 
     76 #define ARRAYSIZE_UNSAFE(a) \
     77   ((sizeof(a) / sizeof(*(a))) / \
     78    static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
     79 
     80 
     81 class NPObject;
     82 
     83 namespace WebCore {
     84 
     85 class Document;
     86 class FrameView;
     87 class Node;
     88 class ScrollView;
     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 chromium/PlatformBridge 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 Document*, const KURL&, const String& value);
    108     static String cookies(const Document*, const KURL&);
    109     static bool cookiesEnabled(const Document*);
    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         FileUploadNoFileChosenLabel
    124     };
    125     static String* globalLocalizedName(rawResId resId);
    126 
    127     // Whether the WebView is paused.
    128     // ANDROID
    129     // TODO: Upstream to webkit.org. See https://bugs.webkit.org/show_bug.cgi?id=34082
    130     static bool isWebViewPaused(const FrameView*);
    131     static String resolveFilePathForContentUri(const String&);
    132 
    133     static int screenDepth();
    134     static FloatRect screenRect();
    135 
    136     // Update the viewport meta data.
    137     static void updateViewport(FrameView*);
    138 
    139     static void updateTextfield(FrameView*, Node*, bool changeToPassword, const WTF::String& text);
    140 
    141     static void setScrollPosition(ScrollView*, int x, int y);
    142 
    143     // Language
    144     static String computeDefaultLanguage();
    145     // Memory details for V8 GC
    146     static int lowMemoryUsageMB();
    147     static int highMemoryUsageMB();
    148     static int highUsageDeltaMB();
    149     static int memoryUsageMB();
    150     static int actualMemoryUsageMB();
    151     static bool canSatisfyMemoryAllocation(long bytes);
    152 
    153     static int screenWidthInDocCoord(const FrameView*);
    154     static int screenHeightInDocCoord(const FrameView*);
    155 };
    156 
    157 }
    158 #endif // PlatformBridge_h
    159