Home | History | Annotate | Download | only in InjectedBundle
      1 /*
      2  * Copyright (C) 2010 Apple Inc. All rights reserved.
      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  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. 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 APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
     14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     23  * THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #include "config.h"
     27 #include "InjectedBundlePageUIClient.h"
     28 
     29 #include "InjectedBundleHitTestResult.h"
     30 #include "WKAPICast.h"
     31 #include "WebGraphicsContext.h"
     32 #include "WKBundleAPICast.h"
     33 #include <wtf/text/WTFString.h>
     34 
     35 using namespace WebCore;
     36 
     37 namespace WebKit {
     38 
     39 void InjectedBundlePageUIClient::willAddMessageToConsole(WebPage* page, const String& message, int32_t lineNumber)
     40 {
     41     if (m_client.willAddMessageToConsole)
     42         m_client.willAddMessageToConsole(toAPI(page), toAPI(message.impl()), lineNumber, m_client.clientInfo);
     43 }
     44 
     45 void InjectedBundlePageUIClient::willSetStatusbarText(WebPage* page, const String& statusbarText)
     46 {
     47     if (m_client.willSetStatusbarText)
     48         m_client.willSetStatusbarText(toAPI(page), toAPI(statusbarText.impl()), m_client.clientInfo);
     49 }
     50 
     51 void InjectedBundlePageUIClient::willRunJavaScriptAlert(WebPage* page, const String& alertText, WebFrame* frame)
     52 {
     53     if (m_client.willRunJavaScriptAlert)
     54         m_client.willRunJavaScriptAlert(toAPI(page), toAPI(alertText.impl()), toAPI(frame), m_client.clientInfo);
     55 }
     56 
     57 void InjectedBundlePageUIClient::willRunJavaScriptConfirm(WebPage* page, const String& message, WebFrame* frame)
     58 {
     59     if (m_client.willRunJavaScriptConfirm)
     60         m_client.willRunJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.clientInfo);
     61 }
     62 
     63 void InjectedBundlePageUIClient::willRunJavaScriptPrompt(WebPage* page, const String& message, const String& defaultValue, WebFrame* frame)
     64 {
     65     if (m_client.willRunJavaScriptPrompt)
     66         m_client.willRunJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.clientInfo);
     67 }
     68 
     69 void InjectedBundlePageUIClient::mouseDidMoveOverElement(WebPage* page, const HitTestResult& coreHitTestResult, WebEvent::Modifiers modifiers, RefPtr<APIObject>& userData)
     70 {
     71     if (!m_client.mouseDidMoveOverElement)
     72         return;
     73 
     74     RefPtr<InjectedBundleHitTestResult> hitTestResult = InjectedBundleHitTestResult::create(coreHitTestResult);
     75 
     76     WKTypeRef userDataToPass = 0;
     77     m_client.mouseDidMoveOverElement(toAPI(page), toAPI(hitTestResult.get()), toAPI(modifiers), &userDataToPass, m_client.clientInfo);
     78     userData = adoptRef(toImpl(userDataToPass));
     79 }
     80 
     81 void InjectedBundlePageUIClient::pageDidScroll(WebPage* page)
     82 {
     83     if (!m_client.pageDidScroll)
     84         return;
     85 
     86     m_client.pageDidScroll(toAPI(page), m_client.clientInfo);
     87 }
     88 
     89 bool InjectedBundlePageUIClient::shouldPaintCustomOverhangArea()
     90 {
     91     return m_client.paintCustomOverhangArea;
     92 }
     93 
     94 void InjectedBundlePageUIClient::paintCustomOverhangArea(WebPage* page, GraphicsContext* graphicsContext, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
     95 {
     96     ASSERT(shouldPaintCustomOverhangArea());
     97 
     98     RefPtr<WebGraphicsContext> context = WebGraphicsContext::create(graphicsContext);
     99     m_client.paintCustomOverhangArea(toAPI(page), toAPI(context.get()), toAPI(horizontalOverhangArea), toAPI(verticalOverhangArea), toAPI(dirtyRect), m_client.clientInfo);
    100 }
    101 
    102 String InjectedBundlePageUIClient::shouldGenerateFileForUpload(WebPage* page, const String& originalFilePath)
    103 {
    104     if (!m_client.shouldGenerateFileForUpload)
    105         return String();
    106     RefPtr<WebString> generatedFilePath = adoptRef(toImpl(m_client.shouldGenerateFileForUpload(toAPI(page), toAPI(originalFilePath.impl()), m_client.clientInfo)));
    107     return generatedFilePath ? generatedFilePath->string() : String();
    108 }
    109 
    110 String InjectedBundlePageUIClient::generateFileForUpload(WebPage* page, const String& originalFilePath)
    111 {
    112     if (!m_client.shouldGenerateFileForUpload)
    113         return String();
    114     RefPtr<WebString> generatedFilePath = adoptRef(toImpl(m_client.generateFileForUpload(toAPI(page), toAPI(originalFilePath.impl()), m_client.clientInfo)));
    115     return generatedFilePath ? generatedFilePath->string() : String();
    116 }
    117 
    118 } // namespace WebKit
    119