Home | History | Annotate | Download | only in jni
      1 /*
      2  * Copyright 2006, 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 // TODO: change name to WebFrame.h
     27 
     28 #ifndef WebCoreFrameBridge_h
     29 #define WebCoreFrameBridge_h
     30 
     31 #include "FrameLoaderClient.h"
     32 #include "PlatformBridge.h"
     33 #include "PlatformString.h"
     34 #include "WebCoreRefObject.h"
     35 #include <jni.h>
     36 #include <string>
     37 #include <wtf/RefCounted.h>
     38 
     39 namespace WebCore {
     40     class HTMLFormElement;
     41     class Frame;
     42     class HistoryItem;
     43     class Image;
     44     class Page;
     45     class RenderPart;
     46     class RenderSkinAndroid;
     47     class ResourceHandle;
     48     class ResourceLoaderAndroid;
     49     class ResourceRequest;
     50 }
     51 
     52 namespace android {
     53 
     54 class WebViewCore;
     55 class WebUrlLoaderClient;
     56 class UrlInterceptResponse;
     57 
     58 // one instance of WebFrame per Page for calling into Java's BrowserFrame
     59 class WebFrame : public WebCoreRefObject {
     60   public:
     61     WebFrame(JNIEnv* env, jobject obj, jobject historyList, WebCore::Page* page);
     62     ~WebFrame();
     63 
     64     // helper function
     65     static WebFrame* getWebFrame(const WebCore::Frame* frame);
     66 
     67     virtual PassRefPtr<WebCore::ResourceLoaderAndroid> startLoadingResource(WebCore::ResourceHandle*,
     68             const WebCore::ResourceRequest& request, bool mainResource,
     69             bool synchronous);
     70 
     71     UrlInterceptResponse* shouldInterceptRequest(const WTF::String& url);
     72 
     73     void reportError(int errorCode, const WTF::String& description,
     74             const WTF::String& failingUrl);
     75 
     76     void loadStarted(WebCore::Frame* frame);
     77 
     78     void transitionToCommitted(WebCore::Frame* frame);
     79 
     80     void didFinishLoad(WebCore::Frame* frame);
     81 
     82     void addHistoryItem(WebCore::HistoryItem* item);
     83 
     84     void removeHistoryItem(int index);
     85 
     86     void updateHistoryIndex(int newIndex);
     87 
     88     void setTitle(const WTF::String& title);
     89 
     90     void windowObjectCleared(WebCore::Frame* frame);
     91 
     92     void setProgress(float newProgress);
     93 
     94     const WTF::String userAgentForURL(const WebCore::KURL* url);
     95 
     96     void didReceiveIcon(WebCore::Image* icon);
     97 
     98     void didReceiveTouchIconURL(const WTF::String& url, bool precomposed);
     99 
    100     void updateVisitedHistory(const WebCore::KURL& url, bool reload);
    101 
    102     // Used to determine whether the WebView should handle the given request.
    103     // Returns true if it should handle it, otherwise false.
    104     virtual bool canHandleRequest(const WebCore::ResourceRequest& request);
    105 
    106     WebCore::Frame* createWindow(bool dialog, bool userGesture);
    107 
    108     void requestFocus() const;
    109 
    110     void closeWindow(WebViewCore* webViewCore);
    111 
    112     void decidePolicyForFormResubmission(WebCore::FramePolicyFunction func);
    113 
    114     void setUserAgent(WTF::String userAgent) { mUserAgent = userAgent; }
    115 
    116     WTF::String getRawResourceFilename(WebCore::PlatformBridge::rawResId) const;
    117 
    118     float density() const;
    119 
    120 #if USE(CHROME_NETWORK_STACK)
    121     void didReceiveAuthenticationChallenge(WebUrlLoaderClient*, const std::string& host, const std::string& realm, bool useCachedCredentials, bool suppressDialog);
    122     void reportSslCertError(WebUrlLoaderClient* client, int cert_error, const std::string& cert, const std::string& url);
    123     void requestClientCert(WebUrlLoaderClient* client, const std::string& hostAndPort);
    124     void downloadStart(const std::string& url, const std::string& userAgent, const std::string& contentDisposition, const std::string& mimetype, long long contentLength);
    125     void didReceiveData(const char* data, int size);
    126     void didFinishLoading();
    127     void setCertificate(const std::string& cert);
    128 #endif
    129 
    130     void maybeSavePassword(WebCore::Frame* frame, const WebCore::ResourceRequest& request);
    131 
    132 
    133     // Parse the x-auto-login header and propagate the parameters to the
    134     // application.
    135     void autoLogin(const std::string& loginHeader);
    136 
    137     /**
    138      * When the user initiates a click, we set mUserInitiatedAction to true.
    139      * If a load happens due to this click, then we ask the application if it wants
    140      * to override the load. Otherwise, we attempt to load the resource internally.
    141      */
    142     void setUserInitiatedAction(bool userInitiatedAction) { mUserInitiatedAction = userInitiatedAction; }
    143 
    144     WebCore::Page* page() const { return mPage; }
    145 
    146     // Currently used only by the chrome net stack.  A similar field is used by
    147     // FrameLoader.java to block java network loads.
    148     void setBlockNetworkLoads(bool block) { mBlockNetworkLoads = block; }
    149     bool blockNetworkLoads() const { return mBlockNetworkLoads; }
    150 
    151     /**
    152      * Helper methods. These are typically chunks of code that are called in
    153      * slightly different ways by the Apache and Chrome HTTP stacks.
    154      */
    155     bool getUsernamePasswordFromDom(WebCore::Frame* frame, WTF::String& username, WTF::String& password);
    156     jbyteArray getPostData(const WebCore::ResourceRequest& request);
    157 
    158     bool shouldSaveFormData();
    159     void saveFormData(WebCore::HTMLFormElement*);
    160     WebCore::RenderSkinAndroid* renderSkins() const { return m_renderSkins; }
    161     void setRenderSkins(WebCore::RenderSkinAndroid* skins) { m_renderSkins = skins; }
    162 
    163     // Convert a URL from potential punycode I18nDomainName to safe to-be-displayed Unicode.
    164     static WTF::String convertIDNToUnicode(const WebCore::KURL& kurl);
    165 
    166   private:
    167     struct JavaBrowserFrame;
    168     JavaBrowserFrame* mJavaFrame;
    169     WebCore::Page* mPage;
    170     WTF::String mUserAgent;
    171     bool mBlockNetworkLoads;
    172     bool mUserInitiatedAction;
    173     WebCore::RenderSkinAndroid* m_renderSkins;
    174 };
    175 
    176 }   // namespace android
    177 
    178 #endif // WebCoreFrameBridge_h
    179