Home | History | Annotate | Download | only in qt
      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 "PlatformString.h"
     31 
     32 #include <wtf/Vector.h>
     33 
     34 // V8 bindings use the ARRAYSIZE_UNSAFE macro. This macro was copied
     35 // from http://src.chromium.org/viewvc/chrome/trunk/src/base/basictypes.h
     36 //
     37 // ARRAYSIZE_UNSAFE performs essentially the same calculation as arraysize,
     38 // but can be used on anonymous types or types defined inside
     39 // functions. It's less safe than arraysize as it accepts some
     40 // (although not all) pointers. Therefore, you should use arraysize
     41 // whenever possible.
     42 //
     43 // The expression ARRAYSIZE_UNSAFE(a) is a compile-time constant of type
     44 // size_t.
     45 //
     46 // ARRAYSIZE_UNSAFE catches a few type errors. If you see a compiler error
     47 //
     48 //   "warning: division by zero in ..."
     49 //
     50 // when using ARRAYSIZE_UNSAFE, you are (wrongfully) giving it a pointer.
     51 // You should only use ARRAYSIZE_UNSAFE on statically allocated arrays.
     52 //
     53 // The following comments are on the implementation details, and can
     54 // be ignored by the users.
     55 //
     56 // ARRAYSIZE_UNSAFE(arr) works by inspecting sizeof(arr) (the # of bytes in
     57 // the array) and sizeof(*(arr)) (the # of bytes in one array
     58 // element). If the former is divisible by the latter, perhaps arr is
     59 // indeed an array, in which case the division result is the # of
     60 // elements in the array. Otherwise, arr cannot possibly be an array,
     61 // and we generate a compiler error to prevent the code from
     62 // compiling.
     63 //
     64 // Since the size of bool is implementation-defined, we need to cast
     65 // !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final
     66 // result has type size_t.
     67 //
     68 // This macro is not perfect as it wrongfully accepts certain
     69 // pointers, namely where the pointer size is divisible by the pointee
     70 // size. Since all our code has to go through a 32-bit compiler,
     71 // where a pointer is 4 bytes, this means all pointers to a type whose
     72 // size is 3 or greater than 4 will be (righteously) rejected.
     73 
     74 #define ARRAYSIZE_UNSAFE(a) \
     75   ((sizeof(a) / sizeof(*(a))) / \
     76    static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
     77 
     78 
     79 typedef struct NPObject NPObject;
     80 typedef struct _NPP NPP_t;
     81 typedef NPP_t* NPP;
     82 
     83 namespace WebCore {
     84 
     85 class Widget;
     86 
     87 // An interface to the embedding layer, which has the ability to answer
     88 // questions about the system and so on...
     89 // This is very similar to chromium/PlatformBridge and the two are likely to converge
     90 // in the future.
     91 class PlatformBridge {
     92 public:
     93     static bool popupsAllowed(NPP npp);
     94     // Plugin
     95     static NPObject* pluginScriptableObject(Widget*);
     96 };
     97 
     98 }
     99 #endif // PlatformBridge_h
    100