Home | History | Annotate | Download | only in qt
      1 /*
      2     Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
      3 
      4     This library is free software; you can redistribute it and/or
      5     modify it under the terms of the GNU Library General Public
      6     License as published by the Free Software Foundation; either
      7     version 2 of the License, or (at your option) any later version.
      8 
      9     This library is distributed in the hope that it will be useful,
     10     but WITHOUT ANY WARRANTY; without even the implied warranty of
     11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12     Library General Public License for more details.
     13 
     14     You should have received a copy of the GNU Library General Public License
     15     along with this library; see the file COPYING.LIB.  If not, write to
     16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17     Boston, MA 02110-1301, USA.
     18 */
     19 
     20 #include "config.h"
     21 #include "ClientImpl.h"
     22 
     23 #include "WebFrameProxy.h"
     24 #include "WKAPICast.h"
     25 #include "WKStringQt.h"
     26 #include "WKURLQt.h"
     27 #include <qwkpage.h>
     28 #include <qwkpage_p.h>
     29 #include <WKFrame.h>
     30 #include <WKType.h>
     31 
     32 using namespace WebKit;
     33 
     34 static QWKPage* toQWKPage(const void* clientInfo)
     35 {
     36     if (clientInfo)
     37         return reinterpret_cast<QWKPage*>(const_cast<void*>(clientInfo));
     38     return 0;
     39 }
     40 
     41 static void loadFinished(WKFrameRef frame, const void* clientInfo, bool ok)
     42 {
     43     if (!WKFrameIsMainFrame(frame))
     44         return;
     45     emit toQWKPage(clientInfo)->loadFinished(ok);
     46     QWKPagePrivate::get(toQWKPage(clientInfo))->updateNavigationActions();
     47 }
     48 
     49 void qt_wk_didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
     50 {
     51     if (!WKFrameIsMainFrame(frame))
     52         return;
     53     emit toQWKPage(clientInfo)->loadStarted();
     54     QWKPagePrivate::get(toQWKPage(clientInfo))->updateNavigationActions();
     55 }
     56 
     57 void qt_wk_didReceiveServerRedirectForProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
     58 {
     59 }
     60 
     61 void qt_wk_didFailProvisionalLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void* clientInfo)
     62 {
     63     loadFinished(frame, clientInfo, false);
     64 }
     65 
     66 void qt_wk_didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
     67 {
     68     if (!WKFrameIsMainFrame(frame))
     69         return;
     70     WebFrameProxy* wkframe = toImpl(frame);
     71     QString urlStr(wkframe->url());
     72     QUrl qUrl = urlStr;
     73     emit toQWKPage(clientInfo)->urlChanged(qUrl);
     74     QWKPagePrivate::get(toQWKPage(clientInfo))->updateNavigationActions();
     75 }
     76 
     77 void qt_wk_didFinishDocumentLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
     78 {
     79     // FIXME: Implement (bug #44934)
     80 }
     81 
     82 void qt_wk_didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
     83 {
     84     loadFinished(frame, clientInfo, true);
     85 }
     86 
     87 void qt_wk_didFailLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void* clientInfo)
     88 {
     89     loadFinished(frame, clientInfo, false);
     90 }
     91 
     92 void qt_wk_didReceiveTitleForFrame(WKPageRef page, WKStringRef title, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
     93 {
     94     if (!WKFrameIsMainFrame(frame))
     95         return;
     96     QString qTitle = WKStringCopyQString(title);
     97     emit toQWKPage(clientInfo)->titleChanged(qTitle);
     98 }
     99 
    100 void qt_wk_didFirstLayoutForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
    101 {
    102     if (!WKFrameIsMainFrame(frame))
    103         return;
    104     emit toQWKPage(clientInfo)->initialLayoutCompleted();
    105 }
    106 
    107 void qt_wk_didRemoveFrameFromHierarchy(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
    108 {
    109     // FIXME: Implement (bug #46432)
    110 }
    111 
    112 void qt_wk_didFirstVisuallyNonEmptyLayoutForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
    113 {
    114     if (!WKFrameIsMainFrame(frame))
    115         return;
    116     // FIXME: emit toWKView(clientInfo)->initialLayoutCompleted();
    117 }
    118 
    119 void qt_wk_didStartProgress(WKPageRef page, const void* clientInfo)
    120 {
    121     emit toQWKPage(clientInfo)->loadProgress(0);
    122 }
    123 
    124 void qt_wk_didChangeProgress(WKPageRef page, const void* clientInfo)
    125 {
    126     emit toQWKPage(clientInfo)->loadProgress(WKPageGetEstimatedProgress(page) * 100);
    127 }
    128 
    129 void qt_wk_didFinishProgress(WKPageRef page, const void* clientInfo)
    130 {
    131     emit toQWKPage(clientInfo)->loadProgress(100);
    132 }
    133 
    134 void qt_wk_didBecomeUnresponsive(WKPageRef page, const void* clientInfo)
    135 {
    136 }
    137 
    138 void qt_wk_didBecomeResponsive(WKPageRef page, const void* clientInfo)
    139 {
    140 }
    141 
    142 WKPageRef qt_wk_createNewPage(WKPageRef page, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton mouseButton, const void* clientInfo)
    143 {
    144     QWKPage* wkPage = toQWKPage(clientInfo);
    145     QWKPagePrivate* d = QWKPagePrivate::get(wkPage);
    146     QWKPage::CreateNewPageFn createNewPageFn = d->createNewPageFn;
    147 
    148     if (!createNewPageFn)
    149         return 0;
    150 
    151     if (QWKPage* newPage = createNewPageFn(wkPage)) {
    152         WKRetain(newPage->pageRef());
    153         return newPage->pageRef();
    154     }
    155 
    156     return 0;
    157 }
    158 
    159 void qt_wk_showPage(WKPageRef page, const void* clientInfo)
    160 {
    161 }
    162 
    163 void qt_wk_close(WKPageRef page, const void* clientInfo)
    164 {
    165     emit toQWKPage(clientInfo)->windowCloseRequested();
    166 }
    167 
    168 void qt_wk_takeFocus(WKPageRef page, WKFocusDirection direction, const void *clientInfo)
    169 {
    170     emit toQWKPage(clientInfo)->focusNextPrevChild(direction == kWKFocusDirectionForward);
    171 }
    172 
    173 void qt_wk_runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo)
    174 {
    175 }
    176 
    177 void qt_wk_setStatusText(WKPageRef page, WKStringRef text, const void *clientInfo)
    178 {
    179     QString qText = WKStringCopyQString(text);
    180     emit toQWKPage(clientInfo)->statusBarMessage(qText);
    181 }
    182