javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/library/webkit/os.cpp
changeset 35 85266cc22c7f
child 47 f40128debb5d
equal deleted inserted replaced
26:dc7c549001d5 35:85266cc22c7f
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved. This program and the accompanying materials
       
     4  * are made available under the terms of the Eclipse Public License v1.0
       
     5  * which accompanies this distribution, and is available at
       
     6  * http://www.eclipse.org/legal/epl-v10.html
       
     7  *
       
     8  * Contributors:
       
     9  *     Nokia Corporation - initial implementation
       
    10  *******************************************************************************/
       
    11 
       
    12 #ifndef QT_NO_WEBKIT
       
    13 #include <QWebView>
       
    14 #include <QWebFrame>
       
    15 #include <QWebHistory>
       
    16 #endif
       
    17 
       
    18 #include "org_eclipse_swt_internal_qt_webkit_OS_0005fwebkit.h"
       
    19 #include "swt.h"
       
    20 #include "swtlog.h"
       
    21 #include "swtapplication.h"
       
    22 #include "jniutils.h"
       
    23 
       
    24 #define OS_NATIVE(func) Java_org_eclipse_swt_internal_qt_webkit_OS_1webkit_##func
       
    25 
       
    26 using namespace Java::eSWT;
       
    27 
       
    28 //
       
    29 // QWebView
       
    30 //
       
    31 JNIEXPORT jint JNICALL OS_NATIVE( QWebView_1new )
       
    32     ( JNIEnv* aJniEnv , jclass )
       
    33     {
       
    34 #ifndef QT_NO_WEBKIT
       
    35     QWebView* browser = NULL;
       
    36     SWT_TRY
       
    37         {
       
    38         SWT_LOG_JNI_CALL();
       
    39         browser = new QWebView();
       
    40         }
       
    41     SWT_CATCH
       
    42     return POINTER_TO_HANDLE( browser );
       
    43 #endif
       
    44 #ifdef QT_NO_WEBKIT
       
    45     swtApp->jniUtils().Throw( aJniEnv, ESwtErrorNotImplemented );
       
    46     return 0;
       
    47 #endif
       
    48     }
       
    49 
       
    50 JNIEXPORT void JNICALL OS_NATIVE( QWebView_1back )
       
    51     ( JNIEnv* aJniEnv , jclass, jint
       
    52 #ifndef QT_NO_WEBKIT
       
    53 aHandle
       
    54 #endif
       
    55 )
       
    56     {
       
    57     SWT_TRY
       
    58         {
       
    59         SWT_LOG_JNI_CALL();
       
    60 #ifndef QT_NO_WEBKIT
       
    61         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
    62         browser->back();
       
    63 #endif
       
    64         }
       
    65     SWT_CATCH
       
    66     }
       
    67 
       
    68 JNIEXPORT void JNICALL OS_NATIVE( QWebView_1forward )
       
    69     ( JNIEnv* aJniEnv , jclass, jint
       
    70 #ifndef QT_NO_WEBKIT
       
    71 aHandle
       
    72 #endif
       
    73 )
       
    74     {
       
    75     SWT_TRY
       
    76         {
       
    77         SWT_LOG_JNI_CALL();
       
    78 #ifndef QT_NO_WEBKIT
       
    79         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
    80         browser->forward();
       
    81 #endif
       
    82         }
       
    83     SWT_CATCH
       
    84     }
       
    85 
       
    86 JNIEXPORT void JNICALL OS_NATIVE( QWebView_1reload )
       
    87     ( JNIEnv* aJniEnv , jclass, jint
       
    88 #ifndef QT_NO_WEBKIT
       
    89 aHandle
       
    90 #endif
       
    91 )
       
    92     {
       
    93     SWT_TRY
       
    94         {
       
    95         SWT_LOG_JNI_CALL();
       
    96 #ifndef QT_NO_WEBKIT
       
    97         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
    98         browser->reload();
       
    99 #endif
       
   100         }
       
   101     SWT_CATCH
       
   102     }
       
   103 
       
   104 JNIEXPORT void JNICALL OS_NATIVE( QWebView_1setHtml )
       
   105     ( JNIEnv* aJniEnv , jclass, jint
       
   106 #ifndef QT_NO_WEBKIT
       
   107 aHandle
       
   108 #endif
       
   109 , jstring
       
   110 #ifndef QT_NO_WEBKIT
       
   111 aText
       
   112 #endif
       
   113 )
       
   114     {
       
   115     SWT_TRY
       
   116         {
       
   117         SWT_LOG_JNI_CALL();
       
   118 #ifndef QT_NO_WEBKIT
       
   119         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
   120         browser->setHtml( swtApp->jniUtils().JavaStringToQString( aJniEnv, aText ) );
       
   121 #endif
       
   122         }
       
   123     SWT_CATCH
       
   124     }
       
   125 
       
   126 JNIEXPORT void JNICALL OS_NATIVE( QWebView_1setUrl )
       
   127     ( JNIEnv* aJniEnv , jclass, jint
       
   128 #ifndef QT_NO_WEBKIT
       
   129 aHandle
       
   130 #endif
       
   131 , jstring
       
   132 #ifndef QT_NO_WEBKIT
       
   133 aText
       
   134 #endif
       
   135 )
       
   136     {
       
   137     SWT_TRY
       
   138         {
       
   139         SWT_LOG_JNI_CALL();
       
   140 #ifndef QT_NO_WEBKIT
       
   141         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
   142         browser->setUrl( QUrl( swtApp->jniUtils().JavaStringToQString( aJniEnv, aText ) ) );
       
   143 #endif
       
   144         }
       
   145     SWT_CATCH
       
   146     }
       
   147 
       
   148 JNIEXPORT void JNICALL OS_NATIVE( QWebView_1stop )
       
   149     ( JNIEnv* aJniEnv , jclass, jint
       
   150 #ifndef QT_NO_WEBKIT
       
   151 aHandle
       
   152 #endif
       
   153 )
       
   154     {
       
   155     SWT_TRY
       
   156         {
       
   157         SWT_LOG_JNI_CALL();
       
   158 #ifndef QT_NO_WEBKIT
       
   159         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
   160         browser->stop();
       
   161 #endif
       
   162         }
       
   163     SWT_CATCH
       
   164     }
       
   165 
       
   166 JNIEXPORT jstring JNICALL OS_NATIVE( QWebView_1swt_1backUrl )
       
   167     ( JNIEnv* aJniEnv , jclass, jint
       
   168 #ifndef QT_NO_WEBKIT
       
   169 aHandle
       
   170 #endif
       
   171 )
       
   172     {
       
   173     jstring res = NULL;
       
   174     SWT_TRY
       
   175         {
       
   176         SWT_LOG_JNI_CALL();
       
   177 #ifndef QT_NO_WEBKIT
       
   178         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
   179         QWebHistory* history = browser->history();
       
   180         if ( history && history->canGoBack() )
       
   181             {
       
   182             res = swtApp->jniUtils().QStringToJavaString( aJniEnv, history->backItem().url().toString() );
       
   183             }
       
   184 #endif
       
   185         }
       
   186     SWT_CATCH
       
   187     return res;
       
   188     }
       
   189 
       
   190 JNIEXPORT jboolean JNICALL OS_NATIVE( QWebView_1swt_1canGoBack )
       
   191     ( JNIEnv* aJniEnv , jclass, jint
       
   192 #ifndef QT_NO_WEBKIT
       
   193 aHandle
       
   194 #endif
       
   195 )
       
   196     {
       
   197     jboolean res = false;
       
   198     SWT_TRY
       
   199         {
       
   200         SWT_LOG_JNI_CALL();
       
   201 #ifndef QT_NO_WEBKIT
       
   202         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
   203         QWebHistory* history = browser->history();
       
   204         if ( history )
       
   205             {
       
   206             res = history->canGoBack();
       
   207             }
       
   208 #endif
       
   209         }
       
   210     SWT_CATCH
       
   211     return res;
       
   212     }
       
   213 
       
   214 JNIEXPORT jboolean JNICALL OS_NATIVE( QWebView_1swt_1canGoForward )
       
   215     ( JNIEnv* aJniEnv , jclass, jint
       
   216 #ifndef QT_NO_WEBKIT
       
   217 aHandle
       
   218 #endif
       
   219 )
       
   220     {
       
   221     jboolean res = false;
       
   222     SWT_TRY
       
   223         {
       
   224         SWT_LOG_JNI_CALL();
       
   225 #ifndef QT_NO_WEBKIT
       
   226         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
   227         QWebHistory* history = browser->history();
       
   228         if ( history )
       
   229             {
       
   230             res = history->canGoForward();
       
   231             }
       
   232 #endif
       
   233         }
       
   234     SWT_CATCH
       
   235     return res;
       
   236     }
       
   237 
       
   238 JNIEXPORT jboolean JNICALL OS_NATIVE( QWebView_1swt_1evaluateJavaScript )
       
   239     ( JNIEnv* aJniEnv , jclass, jint
       
   240 #ifndef QT_NO_WEBKIT
       
   241 aHandle
       
   242 #endif
       
   243 , jstring
       
   244 #ifndef QT_NO_WEBKIT
       
   245 aText
       
   246 #endif
       
   247 )
       
   248     {
       
   249     jboolean res = false;
       
   250     SWT_TRY
       
   251         {
       
   252         SWT_LOG_JNI_CALL();
       
   253 #ifndef QT_NO_WEBKIT
       
   254         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
   255         QWebPage* page = browser->page();
       
   256         if ( page )
       
   257             {
       
   258             QWebFrame* frame = page->currentFrame();
       
   259             if ( !frame )
       
   260                 {
       
   261                 frame = page->mainFrame();
       
   262                 }
       
   263             if ( frame )
       
   264                 {
       
   265                 res = ( frame->evaluateJavaScript( swtApp->jniUtils().JavaStringToQString( aJniEnv, aText ) ) ).toBool();
       
   266                 }
       
   267             }
       
   268 #endif
       
   269         }
       
   270     SWT_CATCH
       
   271     return res;
       
   272     }
       
   273 
       
   274 JNIEXPORT jstring JNICALL OS_NATIVE( QWebView_1swt_1forwardUrl )
       
   275     ( JNIEnv* aJniEnv , jclass, jint
       
   276 #ifndef QT_NO_WEBKIT
       
   277 aHandle
       
   278 #endif
       
   279 )
       
   280     {
       
   281     jstring res = NULL;
       
   282     SWT_TRY
       
   283         {
       
   284         SWT_LOG_JNI_CALL();
       
   285 #ifndef QT_NO_WEBKIT
       
   286         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
   287         QWebHistory* history = browser->history();
       
   288         if ( history && history->canGoForward() )
       
   289             {
       
   290             res = swtApp->jniUtils().QStringToJavaString( aJniEnv, history->forwardItem().url().toString() );
       
   291             }
       
   292 #endif
       
   293         }
       
   294     SWT_CATCH
       
   295     return res;
       
   296     }
       
   297 
       
   298 JNIEXPORT jstring JNICALL OS_NATIVE( QWebView_1url )
       
   299     ( JNIEnv* aJniEnv , jclass, jint
       
   300 #ifndef QT_NO_WEBKIT
       
   301 aHandle
       
   302 #endif
       
   303 )
       
   304     {
       
   305     jstring res = NULL;
       
   306     SWT_TRY
       
   307         {
       
   308         SWT_LOG_JNI_CALL();
       
   309 #ifndef QT_NO_WEBKIT
       
   310         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
   311         res = swtApp->jniUtils().QStringToJavaString( aJniEnv, browser->url().toString() );
       
   312 #endif
       
   313         }
       
   314     SWT_CATCH
       
   315     return res;
       
   316     }