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 UrlInterceptResponse* shouldInterceptRequest(const WTF::String& url); 68 69 void reportError(int errorCode, const WTF::String& description, 70 const WTF::String& failingUrl); 71 72 void loadStarted(WebCore::Frame* frame); 73 74 void transitionToCommitted(WebCore::Frame* frame); 75 76 void didFinishLoad(WebCore::Frame* frame); 77 78 void addHistoryItem(WebCore::HistoryItem* item); 79 80 void removeHistoryItem(int index); 81 82 void updateHistoryIndex(int newIndex); 83 84 void setTitle(const WTF::String& title); 85 86 void windowObjectCleared(WebCore::Frame* frame); 87 88 void setProgress(float newProgress); 89 90 const WTF::String userAgentForURL(const WebCore::KURL* url); 91 92 void didReceiveIcon(WebCore::Image* icon); 93 94 void didReceiveTouchIconURL(const WTF::String& url, bool precomposed); 95 96 void updateVisitedHistory(const WebCore::KURL& url, bool reload); 97 98 // Used to determine whether the WebView should handle the given request. 99 // Returns true if it should handle it, otherwise false. 100 virtual bool canHandleRequest(const WebCore::ResourceRequest& request); 101 102 WebCore::Frame* createWindow(bool dialog, bool userGesture); 103 104 void requestFocus() const; 105 106 void closeWindow(WebViewCore* webViewCore); 107 108 void decidePolicyForFormResubmission(WebCore::FramePolicyFunction func); 109 setUserAgent(WTF::String userAgent)110 void setUserAgent(WTF::String userAgent) { mUserAgent = userAgent; } 111 112 WTF::String getRawResourceFilename(WebCore::PlatformBridge::rawResId) const; 113 114 float density() const; 115 116 void didReceiveAuthenticationChallenge(WebUrlLoaderClient*, const std::string& host, const std::string& realm, bool useCachedCredentials, bool suppressDialog); 117 void reportSslCertError(WebUrlLoaderClient* client, int cert_error, const std::string& cert, const std::string& url); 118 void requestClientCert(WebUrlLoaderClient* client, const std::string& hostAndPort); 119 void downloadStart(const std::string& url, const std::string& userAgent, const std::string& contentDisposition, const std::string& mimetype, const std::string& referer, long long contentLength); 120 void didReceiveData(const char* data, int size); 121 void didFinishLoading(); 122 void setCertificate(const std::string& cert); 123 124 void maybeSavePassword(WebCore::Frame* frame, const WebCore::ResourceRequest& request); 125 126 127 // Parse the x-auto-login header and propagate the parameters to the 128 // application. 129 void autoLogin(const std::string& loginHeader); 130 page()131 WebCore::Page* page() const { return mPage; } 132 133 // Currently used only by the chrome net stack. A similar field is used by 134 // FrameLoader.java to block java network loads. setBlockNetworkLoads(bool block)135 void setBlockNetworkLoads(bool block) { mBlockNetworkLoads = block; } blockNetworkLoads()136 bool blockNetworkLoads() const { return mBlockNetworkLoads; } 137 138 /** 139 * Helper methods. These are typically chunks of code that are called in 140 * slightly different ways by the Apache and Chrome HTTP stacks. 141 */ 142 bool getUsernamePasswordFromDom(WebCore::Frame* frame, WTF::String& username, WTF::String& password); 143 jbyteArray getPostData(const WebCore::ResourceRequest& request); 144 145 bool shouldSaveFormData(); 146 void saveFormData(WebCore::HTMLFormElement*); renderSkins()147 WebCore::RenderSkinAndroid* renderSkins() const { return m_renderSkins; } setRenderSkins(WebCore::RenderSkinAndroid * skins)148 void setRenderSkins(WebCore::RenderSkinAndroid* skins) { m_renderSkins = skins; } 149 150 // Convert a URL from potential punycode I18nDomainName to safe to-be-displayed Unicode. 151 static WTF::String convertIDNToUnicode(const WebCore::KURL& kurl); 152 153 private: 154 struct JavaBrowserFrame; 155 JavaBrowserFrame* mJavaFrame; 156 WebCore::Page* mPage; 157 WTF::String mUserAgent; 158 bool mBlockNetworkLoads; 159 WebCore::RenderSkinAndroid* m_renderSkins; 160 }; 161 162 } // namespace android 163 164 #endif // WebCoreFrameBridge_h 165