2011-01-29 Maciej Stachowiak <mjs@apple.com>
authormjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 30 Jan 2011 08:30:27 +0000 (08:30 +0000)
committermjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 30 Jan 2011 08:30:27 +0000 (08:30 +0000)
        Reviewed by Geoffrey Garen.

        Add WKPageCopyPendingAPIRequestURL API
        https://bugs.webkit.org/show_bug.cgi?id=53383

        This API returns the last URL requested for load via API, if neither that load nor any
        other load subsequently reaches the provisional state.

        This is useful to be able to track loads initiated via the API

        * UIProcess/API/C/WKPage.cpp:
        (WKPageCopyPendingAPIRequestURL): Retrieve the pending URL.
        * UIProcess/API/C/WKPage.h:
        * UIProcess/WebPageProxy.cpp:
        (WebKit::WebPageProxy::loadURL): Set pending URL.
        (WebKit::WebPageProxy::loadURLRequest): ditto
        (WebKit::WebPageProxy::reload): ditto
        (WebKit::WebPageProxy::goForward): ditto
        (WebKit::WebPageProxy::goBack): ditto
        (WebKit::WebPageProxy::estimatedProgress): Assume the initial
        progress value when there is a pending URL.
        (WebKit::WebPageProxy::didStartProvisionalLoadForFrame): Clear
        pending URL; clients should look at the provisional URL now.
        (WebKit::WebPageProxy::decidePolicyForNavigationAction): Clear
        pending URL if it doesn't match the policy URL; this means we
        were interrupted by another load.
        * UIProcess/WebPageProxy.h:
        (WebKit::WebPageProxy::pendingAPIRequestURL): Helper function.
        (WebKit::WebPageProxy::clearPendingAPIRequestURL): ditto
        (WebKit::WebPageProxy::setPendingAPIRequestURL): ditto

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@77085 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/C/WKPage.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h

index b07a494..d1b0bc6 100644 (file)
@@ -1,3 +1,36 @@
+2011-01-29  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Geoffrey Garen.
+
+        Add WKPageCopyPendingAPIRequestURL API
+        https://bugs.webkit.org/show_bug.cgi?id=53383
+
+        This API returns the last URL requested for load via API, if neither that load nor any
+        other load subsequently reaches the provisional state.
+        
+        This is useful to be able to track loads initiated via the API
+        
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageCopyPendingAPIRequestURL): Retrieve the pending URL.
+        * UIProcess/API/C/WKPage.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::loadURL): Set pending URL.
+        (WebKit::WebPageProxy::loadURLRequest): ditto
+        (WebKit::WebPageProxy::reload): ditto
+        (WebKit::WebPageProxy::goForward): ditto
+        (WebKit::WebPageProxy::goBack): ditto
+        (WebKit::WebPageProxy::estimatedProgress): Assume the initial
+        progress value when there is a pending URL.
+        (WebKit::WebPageProxy::didStartProvisionalLoadForFrame): Clear
+        pending URL; clients should look at the provisional URL now.
+        (WebKit::WebPageProxy::decidePolicyForNavigationAction): Clear
+        pending URL if it doesn't match the policy URL; this means we
+        were interrupted by another load.
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::pendingAPIRequestURL): Helper function.
+        (WebKit::WebPageProxy::clearPendingAPIRequestURL): ditto
+        (WebKit::WebPageProxy::setPendingAPIRequestURL): ditto
+
 2011-01-28  Jon Honeycutt  <jhoneycutt@apple.com>
 
         Downloads in WK2 on Windows should write resume data to bundle
index 120e846..8227ce5 100644 (file)
@@ -435,3 +435,10 @@ void WKPageForceRepaint(WKPageRef pageRef, void* context, WKPageForceRepaintFunc
 {
     toImpl(pageRef)->forceRepaint(VoidCallback::create(context, callback));
 }
+
+WK_EXPORT WKURLRef WKPageCopyPendingAPIRequestURL(WKPageRef pageRef)
+{
+    if (toImpl(pageRef)->pendingAPIRequestURL().isNull())
+        return 0;
+    return toCopiedURLAPI(toImpl(pageRef)->pendingAPIRequestURL());
+}
index 7ad4918..251cde9 100644 (file)
@@ -344,6 +344,8 @@ WK_EXPORT void WKPageGetContentsAsString_b(WKPageRef page, WKPageGetContentsAsSt
 typedef void (*WKPageForceRepaintFunction)(WKErrorRef, void*);
 WK_EXPORT void WKPageForceRepaint(WKPageRef page, void* context, WKPageForceRepaintFunction function);
 
+WK_EXPORT WKURLRef WKPageCopyPendingAPIRequestURL(WKPageRef page);
+
 #ifdef __cplusplus
 }
 #endif
index faf17c7..348be78 100644 (file)
@@ -320,6 +320,8 @@ static void initializeSandboxExtensionHandle(const KURL& url, SandboxExtension::
 
 void WebPageProxy::loadURL(const String& url)
 {
+    setPendingAPIRequestURL(url);
+
     if (!isValid())
         reattachToWebProcess();
 
@@ -330,6 +332,8 @@ void WebPageProxy::loadURL(const String& url)
 
 void WebPageProxy::loadURLRequest(WebURLRequest* urlRequest)
 {
+    setPendingAPIRequestURL(urlRequest->resourceRequest().url());
+
     if (!isValid())
         reattachToWebProcess();
 
@@ -373,6 +377,8 @@ void WebPageProxy::stopLoading()
 
 void WebPageProxy::reload(bool reloadFromOrigin)
 {
+    setPendingAPIRequestURL(m_backForwardList->currentItem()->url());
+
     if (!isValid()) {
         reattachToWebProcessWithItem(m_backForwardList->currentItem());
         return;
@@ -383,14 +389,16 @@ void WebPageProxy::reload(bool reloadFromOrigin)
 
 void WebPageProxy::goForward()
 {
+    if (isValid() && !canGoForward())
+        return;
+
+    setPendingAPIRequestURL(m_backForwardList->forwardItem()->url());
+
     if (!isValid()) {
         reattachToWebProcessWithItem(m_backForwardList->forwardItem());
         return;
     }
 
-    if (!canGoForward())
-        return;
-
     process()->send(Messages::WebPage::GoForward(m_backForwardList->forwardItem()->itemID()), m_pageID);
 }
 
@@ -401,14 +409,16 @@ bool WebPageProxy::canGoForward() const
 
 void WebPageProxy::goBack()
 {
+    if (isValid() && !canGoBack())
+        return;
+
+    setPendingAPIRequestURL(m_backForwardList->backItem()->url());
+
     if (!isValid()) {
         reattachToWebProcessWithItem(m_backForwardList->backItem());
         return;
     }
 
-    if (!canGoBack())
-        return;
-
     process()->send(Messages::WebPage::GoBack(m_backForwardList->backItem()->itemID()), m_pageID);
 }
 
@@ -1180,6 +1190,13 @@ void WebPageProxy::didRestoreFrameFromPageCache(uint64_t frameID, uint64_t paren
 
 static const double initialProgressValue = 0.1;
 
+double WebPageProxy::estimatedProgress() const
+{
+    if (!pendingAPIRequestURL().isNull())
+        return initialProgressValue;
+    return m_estimatedProgress; 
+}
+
 void WebPageProxy::didStartProgress()
 {
     m_estimatedProgress = initialProgressValue;
@@ -1203,6 +1220,8 @@ void WebPageProxy::didFinishProgress()
 
 void WebPageProxy::didStartProvisionalLoadForFrame(uint64_t frameID, const String& url, bool loadingSubstituteDataForUnreachableURL, CoreIPC::ArgumentDecoder* arguments)
 {
+    clearPendingAPIRequestURL();
+
     RefPtr<APIObject> userData;
     WebContextUserMessageDecoder messageDecoder(userData, context());
     if (!arguments->decode(messageDecoder))
@@ -1429,6 +1448,9 @@ void WebPageProxy::frameDidBecomeFrameSet(uint64_t frameID, bool value)
 
 void WebPageProxy::decidePolicyForNavigationAction(uint64_t frameID, uint32_t opaqueNavigationType, uint32_t opaqueModifiers, int32_t opaqueMouseButton, const String& url, uint64_t listenerID)
 {
+    if (url != pendingAPIRequestURL())
+        clearPendingAPIRequestURL();
+
     WebFrameProxy* frame = process()->webFrame(frameID);
     MESSAGE_CHECK(frame);
 
index a98ea06..c52a39a 100644 (file)
@@ -240,7 +240,7 @@ public:
     void setCustomTextEncodingName(const String&);
     String customTextEncodingName() const { return m_customTextEncodingName; }
 
-    double estimatedProgress() const { return m_estimatedProgress; }
+    double estimatedProgress() const;
 
     void terminateProcess();
 
@@ -372,6 +372,8 @@ public:
     void drawPagesToPDF(WebFrameProxy*, uint32_t first, uint32_t count, PassRefPtr<DataCallback>);
 #endif
 
+    const String& pendingAPIRequestURL() const { return m_pendingAPIRequestURL; }
+
 private:
     WebPageProxy(PageClient*, WebContext*, WebPageGroup*, uint64_t pageID);
 
@@ -544,6 +546,9 @@ private:
 
     static String standardUserAgent(const String& applicationName = String());
 
+    void clearPendingAPIRequestURL() { m_pendingAPIRequestURL = String(); }
+    void setPendingAPIRequestURL(const String& pendingAPIRequestURL) { m_pendingAPIRequestURL = pendingAPIRequestURL; }
+
     PageClient* m_pageClient;
     WebLoaderClient m_loaderClient;
     WebPolicyClient m_policyClient;
@@ -643,6 +648,8 @@ private:
 
     bool m_mainFrameHasCustomRepresentation;
     WebCore::DragOperation m_currentDragOperation;
+
+    String m_pendingAPIRequestURL;
 };
 
 } // namespace WebKit