WebKitTools:
authoraliceli1 <aliceli1@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Oct 2007 17:25:49 +0000 (17:25 +0000)
committeraliceli1 <aliceli1@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Oct 2007 17:25:49 +0000 (17:25 +0000)
        Reviewed by Sam Weinig.

        Fixed <rdar://5382546> layoutTestController.setCustomPolicyDelegate is unimplemented causing tests to fail

        * DumpRenderTree/win/DumpRenderTree.cpp:
        (runTest): Like on mac, before running each test, set the webview's policy delegate to null
        (main): allocate the global policy delegate for DRT's custom use
        * DumpRenderTree/win/DumpRenderTree.vcproj:
        Adding files to project
        * DumpRenderTree/win/DumpRenderTreeWin.h: declaring global DRT policy delegate
        * DumpRenderTree/win/LayoutTestControllerWin.cpp:
        (LayoutTestController::setCustomPolicyDelegate):
        set the webview's policy delegate to DRT's custom one if the test requests it.
        * DumpRenderTree/win/PolicyDelegate.cpp: Added.
        Implementation is a direct port of DumpRenderTree/mac/PolicyDelegate.mm
        (PolicyDelegate::PolicyDelegate):
        (PolicyDelegate::QueryInterface):
        (PolicyDelegate::AddRef):
        (PolicyDelegate::Release):
        (PolicyDelegate::decidePolicyForNavigationAction):
        * DumpRenderTree/win/PolicyDelegate.h: Added.
        (PolicyDelegate::decidePolicyForNewWindowAction):
        (PolicyDelegate::decidePolicyForMIMEType):
        (PolicyDelegate::unableToImplementPolicyWithError):

win:

        Reviewed by Sam Weinig.

        Fixed <rdar://5382546> layoutTestController.setCustomPolicyDelegate is unimplemented causing tests to fail

        * DefaultPolicyDelegate.cpp: Added.
        Implementation is a direct port of WebKit/DefaultDelegates/WebDefaultPolicyDelegate.m
        (DefaultPolicyDelegate::DefaultPolicyDelegate):
        (DefaultPolicyDelegate::~DefaultPolicyDelegate):
        (DefaultPolicyDelegate::sharedInstance):
        (DefaultPolicyDelegate::createInstance):
        (DefaultPolicyDelegate::QueryInterface):
        (DefaultPolicyDelegate::AddRef):
        (DefaultPolicyDelegate::Release):
        (DefaultPolicyDelegate::decidePolicyForNavigationAction):
        (DefaultPolicyDelegate::decidePolicyForNewWindowAction):
        (DefaultPolicyDelegate::decidePolicyForMIMEType):
        (DefaultPolicyDelegate::unableToImplementPolicyWithError):
        * DefaultPolicyDelegate.h: Added.
        * WebFrame.cpp:
        (WebFrame::dispatchDecidePolicyForNavigationAction):
        Implemented default action
        * WebKit.vcproj/WebKit.vcproj:
        Adding files to project

LayoutTests:

        removing fixed test

        * platform/win/Skipped:

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

14 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/win/Skipped
WebKit/win/ChangeLog
WebKit/win/DefaultPolicyDelegate.cpp [new file with mode: 0644]
WebKit/win/DefaultPolicyDelegate.h [new file with mode: 0644]
WebKit/win/WebFrame.cpp
WebKit/win/WebKit.vcproj/WebKit.vcproj
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/win/DumpRenderTree.cpp
WebKitTools/DumpRenderTree/win/DumpRenderTree.vcproj
WebKitTools/DumpRenderTree/win/DumpRenderTreeWin.h
WebKitTools/DumpRenderTree/win/LayoutTestControllerWin.cpp
WebKitTools/DumpRenderTree/win/PolicyDelegate.cpp [new file with mode: 0644]
WebKitTools/DumpRenderTree/win/PolicyDelegate.h [new file with mode: 0644]

index 6c6a929ac91032dbbed48461d8f9b407fd92e8fa..89820d357e9d57e088ddc2c85ff21ad5007d8396 100644 (file)
@@ -1,3 +1,9 @@
+2007-10-15  Alice Liu  <alice.liu@apple.com>\r
+\r
+        removing fixed test\r
+\r
+        * platform/win/Skipped:\r
+
 2007-10-15  Kevin McCullough  <kmccullough@apple.com>
 
         Reviewed by Sam.
index 0a3cb0f341fe67103be0ee83a88f94e06ce0b7fe..25681eeb9acf7924e80d28a8f9165a811a7d80cb 100644 (file)
@@ -414,9 +414,6 @@ editing/selection/5109817.html
 editing/selection/5354455-1.html
 editing/selection/5354455-2.html
 
-# layoutTestController.setCustomPolicyDelegate is unimplemented <rdar://problem/5382546>
-http/tests/security/feed-urls-from-remote.html
-
 # These tests time out <rdar://problem/5382558>
 http/tests/security/cross-frame-access-protocol-explicit-domain.html
 http/tests/security/cross-frame-access-protocol.html
index 0b7b99fbb0bac69bd11407e2a189f00081152f62..dce8885f8f9ca83e437921401d66eb90294ce4db 100644 (file)
@@ -1,3 +1,29 @@
+2007-10-15  Alice Liu  <alice.liu@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Fixed <rdar://5382546> layoutTestController.setCustomPolicyDelegate is unimplemented causing tests to fail
+
+        * DefaultPolicyDelegate.cpp: Added.
+        Implementation is a direct port of WebKit/DefaultDelegates/WebDefaultPolicyDelegate.m
+        (DefaultPolicyDelegate::DefaultPolicyDelegate):
+        (DefaultPolicyDelegate::~DefaultPolicyDelegate):
+        (DefaultPolicyDelegate::sharedInstance):
+        (DefaultPolicyDelegate::createInstance):
+        (DefaultPolicyDelegate::QueryInterface):
+        (DefaultPolicyDelegate::AddRef):
+        (DefaultPolicyDelegate::Release):
+        (DefaultPolicyDelegate::decidePolicyForNavigationAction):
+        (DefaultPolicyDelegate::decidePolicyForNewWindowAction):
+        (DefaultPolicyDelegate::decidePolicyForMIMEType):
+        (DefaultPolicyDelegate::unableToImplementPolicyWithError):
+        * DefaultPolicyDelegate.h: Added.
+        * WebFrame.cpp:
+        (WebFrame::dispatchDecidePolicyForNavigationAction):
+        Implemented default action
+        * WebKit.vcproj/WebKit.vcproj:
+        Adding files to project
+
 2007-10-12  Steve Falkenburg  <sfalken@apple.com>
 
         Move pthreads up in the linker order and don't mark it for delay load.
diff --git a/WebKit/win/DefaultPolicyDelegate.cpp b/WebKit/win/DefaultPolicyDelegate.cpp
new file mode 100644 (file)
index 0000000..d11900c
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "WebKitDLL.h"
+#include "DefaultPolicyDelegate.h"
+
+#include "IWebViewPrivate.h"
+
+#pragma warning(push, 0)
+#include <WebCore/PlatformString.h>
+#pragma warning(pop)
+
+using namespace WebCore;
+
+// FIXME: move this enum to a separate header file when other code begins to use it.
+typedef enum WebExtraNavigationType {
+    WebNavigationTypePlugInRequest = WebNavigationTypeOther + 1
+} WebExtraNavigationType;
+
+// DefaultPolicyDelegate ----------------------------------------------------------------
+
+DefaultPolicyDelegate::DefaultPolicyDelegate()
+    : m_refCount(0)
+{
+    gClassCount++;
+}
+
+DefaultPolicyDelegate::~DefaultPolicyDelegate()
+{
+    gClassCount--;
+}
+
+DefaultPolicyDelegate* DefaultPolicyDelegate::sharedInstance()
+{
+    static COMPtr<DefaultPolicyDelegate> shared;
+    if (!shared)
+        shared.adoptRef(DefaultPolicyDelegate::createInstance());
+    return shared.get();
+}
+
+DefaultPolicyDelegate* DefaultPolicyDelegate::createInstance()
+{
+    DefaultPolicyDelegate* instance = new DefaultPolicyDelegate();
+    instance->AddRef();
+    return instance;
+}
+
+// IUnknown -------------------------------------------------------------------
+
+HRESULT STDMETHODCALLTYPE DefaultPolicyDelegate::QueryInterface(REFIID riid, void** ppvObject)
+{
+    *ppvObject = 0;
+    if (IsEqualGUID(riid, IID_IUnknown))
+        *ppvObject = static_cast<IUnknown*>(this);
+    else if (IsEqualGUID(riid, IID_IWebPolicyDelegate))
+        *ppvObject = static_cast<IWebPolicyDelegate*>(this);
+    else
+        return E_NOINTERFACE;
+
+    AddRef();
+    return S_OK;
+}
+
+ULONG STDMETHODCALLTYPE DefaultPolicyDelegate::AddRef()
+{
+    return ++m_refCount;
+}
+
+ULONG STDMETHODCALLTYPE DefaultPolicyDelegate::Release()
+{
+    ULONG newRef = --m_refCount;
+    if (!newRef)
+        delete(this);
+
+    return newRef;
+}
+
+HRESULT STDMETHODCALLTYPE DefaultPolicyDelegate::decidePolicyForNavigationAction(
+    /*[in]*/ IWebView* webView, 
+    /*[in]*/ IPropertyBag* actionInformation, 
+    /*[in]*/ IWebURLRequest* request, 
+    /*[in]*/ IWebFrame* /*frame*/, 
+    /*[in]*/ IWebPolicyDecisionListener* listener)
+{
+    int navType = 0;
+    VARIANT var;
+    if (SUCCEEDED(actionInformation->Read(WebActionNavigationTypeKey, &var, 0))) {
+        V_VT(&var) = VT_I4;
+        navType = V_I4(&var);
+    }
+    COMPtr<IWebViewPrivate> wvPrivate(Query, webView);
+    if (wvPrivate) {
+        BOOL canHandleRequest = FALSE;
+        if (SUCCEEDED(wvPrivate->canHandleRequest(request, &canHandleRequest)) && canHandleRequest)
+            listener->use();
+        else if (navType == WebNavigationTypePlugInRequest)
+            listener->use();
+        else {
+            BSTR url;
+            // A file URL shouldn't fall through to here, but if it did,
+            // it would be a security risk to open it.
+            if (SUCCEEDED(request->URL(&url)) && !String(url, SysStringLen(url)).startsWith("file:")) {
+                // FIXME: Open the URL not by means of a webframe, but by handing it over to the system and letting it determine how to open that particular URL scheme.  See documentation for [NSWorkspace openURL]
+                ;
+            }
+            listener->ignore();
+            SysFreeString(url);
+        }
+    }
+    return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE DefaultPolicyDelegate::decidePolicyForNewWindowAction(
+    /*[in]*/ IWebView* /*webView*/, 
+    /*[in]*/ IPropertyBag* /*actionInformation*/, 
+    /*[in]*/ IWebURLRequest* /*request*/, 
+    /*[in]*/ BSTR /*frameName*/, 
+    /*[in]*/ IWebPolicyDecisionListener* listener)
+{
+    listener->use();
+    return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE DefaultPolicyDelegate::decidePolicyForMIMEType(
+    /*[in]*/ IWebView* webView, 
+    /*[in]*/ BSTR type, 
+    /*[in]*/ IWebURLRequest* request, 
+    /*[in]*/ IWebFrame* /*frame*/, 
+    /*[in]*/ IWebPolicyDecisionListener* listener)
+{
+    BOOL canShowMIMEType;
+    if (FAILED(webView->canShowMIMEType(type, &canShowMIMEType)))
+        canShowMIMEType = FALSE;
+
+    BSTR url;
+    request->URL(&url);
+
+    if (String(url, SysStringLen(url)).startsWith("file:")) {
+        BOOL isDirectory = FALSE;
+        WIN32_FILE_ATTRIBUTE_DATA attrs;
+        if (GetFileAttributesEx(url, GetFileExInfoStandard, &attrs))
+            isDirectory = !!(attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
+
+        if (isDirectory)
+            listener->ignore();
+        else if(canShowMIMEType)
+            listener->use();
+        else
+            listener->ignore();
+    } else if (canShowMIMEType)
+        listener->use();
+    else
+        listener->ignore();
+    SysFreeString(url);
+    return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE DefaultPolicyDelegate::unableToImplementPolicyWithError(
+    /*[in]*/ IWebView* /*webView*/, 
+    /*[in]*/ IWebError* error, 
+    /*[in]*/ IWebFrame* frame)
+{
+    BSTR errorStr;
+    error->localizedDescription(&errorStr);
+
+    BSTR frameName;
+    frame->name(&frameName);
+
+    LOG_ERROR("called unableToImplementPolicyWithError:%S inFrame:%S", errorStr ? errorStr : TEXT(""), frameName ? frameName : TEXT(""));
+    SysFreeString(errorStr);
+    SysFreeString(frameName);
+
+    return S_OK;
+}
diff --git a/WebKit/win/DefaultPolicyDelegate.h b/WebKit/win/DefaultPolicyDelegate.h
new file mode 100644 (file)
index 0000000..78fa9d3
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef DefaultPolicyDelegate_h
+#define DefaultPolicyDelegate_h
+
+#include "COMPtr.h"
+#include "IWebPolicyDelegate.h"
+
+class DefaultPolicyDelegate : public IWebPolicyDelegate {
+public:
+    static DefaultPolicyDelegate* sharedInstance();
+    static DefaultPolicyDelegate* createInstance();
+private:
+    DefaultPolicyDelegate();
+    ~DefaultPolicyDelegate();
+public:
+    // IUnknown
+    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
+    virtual ULONG STDMETHODCALLTYPE AddRef(void);
+    virtual ULONG STDMETHODCALLTYPE Release(void);
+
+    // IWebPolicyDelegate
+    virtual HRESULT STDMETHODCALLTYPE decidePolicyForNavigationAction( 
+        /* [in] */ IWebView *webView,
+        /* [in] */ IPropertyBag *actionInformation,
+        /* [in] */ IWebURLRequest *request,
+        /* [in] */ IWebFrame *frame,
+        /* [in] */ IWebPolicyDecisionListener *listener);
+    
+    virtual HRESULT STDMETHODCALLTYPE decidePolicyForNewWindowAction( 
+        /* [in] */ IWebView *webView,
+        /* [in] */ IPropertyBag *actionInformation,
+        /* [in] */ IWebURLRequest *request,
+        /* [in] */ BSTR frameName,
+        /* [in] */ IWebPolicyDecisionListener *listener);
+    
+    virtual HRESULT STDMETHODCALLTYPE decidePolicyForMIMEType( 
+        /* [in] */ IWebView *webView,
+        /* [in] */ BSTR type,
+        /* [in] */ IWebURLRequest *request,
+        /* [in] */ IWebFrame *frame,
+        /* [in] */ IWebPolicyDecisionListener *listener);
+    
+    virtual HRESULT STDMETHODCALLTYPE unableToImplementPolicyWithError( 
+        /* [in] */ IWebView *webView,
+        /* [in] */ IWebError *error,
+        /* [in] */ IWebFrame *frame);
+
+protected:
+    ULONG m_refCount;
+};
+
+#endif // DefaultPolicyDelegate_h
index 991db4effc048aec108e51812eeb93d82253ca06..0adf370b18666f4cf9be9595b3c53a2864a0dad5 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "CFDictionaryPropertyBag.h"
 #include "COMPtr.h"
+#include "DefaultPolicyDelegate.h"
 #include "DOMCoreClasses.h"
 #include "IWebError.h"
 #include "IWebErrorPrivate.h"
@@ -2010,17 +2011,15 @@ void WebFrame::dispatchDecidePolicyForNavigationAction(FramePolicyFunction funct
     ASSERT(coreFrame);
 
     COMPtr<IWebPolicyDelegate> policyDelegate;
-    if (SUCCEEDED(d->webView->policyDelegate(&policyDelegate))) {
-        COMPtr<IWebURLRequest> urlRequest;
-        urlRequest.adoptRef(WebMutableURLRequest::createInstance(request));
-        COMPtr<WebActionPropertyBag> actionInformation;
-        actionInformation.adoptRef(WebActionPropertyBag::createInstance(action, coreFrame));
+    if (FAILED(d->webView->policyDelegate(&policyDelegate)))
+        policyDelegate = DefaultPolicyDelegate::sharedInstance();
 
-        if (SUCCEEDED(policyDelegate->decidePolicyForNavigationAction(d->webView, actionInformation.get(), urlRequest.get(), this, setUpPolicyListener(function).get())))
-            return;
-    }
+    COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));
+    COMPtr<WebActionPropertyBag> actionInformation(AdoptCOM, WebActionPropertyBag::createInstance(action, coreFrame));
+
+    if (SUCCEEDED(policyDelegate->decidePolicyForNavigationAction(d->webView, actionInformation.get(), urlRequest.get(), this, setUpPolicyListener(function).get())))
+        return;
 
-    // FIXME: Add a sane default implementation
     (coreFrame->loader()->*function)(PolicyUse);
 }
 
index db72b509887634624f34443b9429c62241b938b4..8bc0131d85d917a309b8434fb733204b94fe6021 100644 (file)
                                RelativePath="..\DefaultDownloadDelegate.h"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\DefaultPolicyDelegate.h"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\DOMCoreClasses.h"\r
                                >\r
                                RelativePath="..\DefaultDownloadDelegate.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\DefaultPolicyDelegate.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\DOMCoreClasses.cpp"\r
                                >\r
index 9f2947814dc0d5e17bd651424dff185ff5e34bc1..a115321c2e67c693c0785cc4d553030a3af9782a 100644 (file)
@@ -1,3 +1,30 @@
+2007-10-15  Alice Liu  <alice.liu@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Fixed <rdar://5382546> layoutTestController.setCustomPolicyDelegate is unimplemented causing tests to fail
+
+        * DumpRenderTree/win/DumpRenderTree.cpp:
+        (runTest): Like on mac, before running each test, set the webview's policy delegate to null
+        (main): allocate the global policy delegate for DRT's custom use
+        * DumpRenderTree/win/DumpRenderTree.vcproj:
+        Adding files to project
+        * DumpRenderTree/win/DumpRenderTreeWin.h: declaring global DRT policy delegate
+        * DumpRenderTree/win/LayoutTestControllerWin.cpp:
+        (LayoutTestController::setCustomPolicyDelegate):
+        set the webview's policy delegate to DRT's custom one if the test requests it.
+        * DumpRenderTree/win/PolicyDelegate.cpp: Added.
+        Implementation is a direct port of DumpRenderTree/mac/PolicyDelegate.mm
+        (PolicyDelegate::PolicyDelegate):
+        (PolicyDelegate::QueryInterface):
+        (PolicyDelegate::AddRef):
+        (PolicyDelegate::Release):
+        (PolicyDelegate::decidePolicyForNavigationAction):
+        * DumpRenderTree/win/PolicyDelegate.h: Added.
+        (PolicyDelegate::decidePolicyForNewWindowAction):
+        (PolicyDelegate::decidePolicyForMIMEType):
+        (PolicyDelegate::unableToImplementPolicyWithError):
+
 2007-10-14  Holger Hans Peter Freyther  <zecke@selfish.org>
 
         Reviewed by Mark.
index 0f2fbff8f8c3526a743f7cd60ce68b8bef9f87f6..652de2098a58b3aa09ecf3ccac75e591393e51e6 100644 (file)
@@ -31,6 +31,7 @@
 #include "EditingDelegate.h"
 #include "FrameLoaderDelegate.h"
 #include "LayoutTestController.h"
+#include "PolicyDelegate.h"
 #include "UIDelegate.h"
 #include "WorkQueueItem.h"
 #include "WorkQueue.h"
@@ -80,6 +81,7 @@ volatile bool done;
 // that child frame is the "topmost frame that is loading".
 IWebFrame* topLoadingFrame;     // !nil iff a load is in progress
 static COMPtr<IWebHistoryItem> prevTestBFItem;  // current b/f item at the end of the previous test
+IWebPolicyDelegate* policyDelegate; 
 
 IWebFrame* frame;
 HWND webViewWindow;
@@ -573,6 +575,8 @@ static void runTest(const char* pathOrURL)
         if (SUCCEEDED(webView->backForwardList(&bfList)))
             bfList->currentItem(&prevTestBFItem);
 
+        webView->setPolicyDelegate(NULL);
+
         COMPtr<IWebIBActions> webIBActions;
         if (SUCCEEDED(webView->QueryInterface(IID_IWebIBActions, (void**)&webIBActions)))
             webIBActions->makeTextStandardSize(0);
@@ -805,6 +809,8 @@ int main(int argc, char* argv[])
     if (FAILED(webView->setFrameLoadDelegate(frameLoadDelegate.get())))
         return -1;
 
+    policyDelegate = new PolicyDelegate();
+
     COMPtr<UIDelegate> uiDelegate;
     uiDelegate.adoptRef(new UIDelegate);
     if (FAILED(webView->setUIDelegate(uiDelegate.get())))
@@ -874,6 +880,7 @@ int main(int argc, char* argv[])
     if (threaded)
         stopJavaScriptThreads();
     
+    delete policyDelegate;
     frame->Release();
 
     if (leakChecking) {
index ea68505fc139b7f0252f9579a2eb31bdedd0c2a2..2ec6110d85695346444bbd046ecbe816b9a73562 100644 (file)
                                RelativePath=".\FrameLoaderDelegate.h"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\PolicyDelegate.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\PolicyDelegate.h"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\UIDelegate.cpp"\r
                                >\r
index adee6447338c849e3d90c472e6b978f27fba9177..2b2045026f094374198aa304072f9b7cd7e934d9 100644 (file)
 #define _WINSOCKAPI_ // Prevent inclusion of winsock.h in windows.h
 
 struct IWebFrame;
+struct IWebPolicyDelegate;
 typedef struct HWND__* HWND;
 
 extern IWebFrame* topLoadingFrame;
 extern IWebFrame* frame;
+extern IWebPolicyDelegate* policyDelegate;
 
 extern HWND webViewWindow;
 
index 3c04fa696a3cfd3cdc1cdcf1a4ddf2e33faea779..a61f6dd432e368f4914b795b8e2e42f817787770 100644 (file)
@@ -30,6 +30,7 @@
 #include "LayoutTestController.h"
 
 #include "EditingDelegate.h"
+#include "PolicyDelegate.h"
 #include "WorkQueue.h"
 #include "WorkQueueItem.h"
 #include <WebCore/COMPtr.h>
@@ -187,7 +188,14 @@ void LayoutTestController::setAcceptsEditing(bool acceptsEditing)
 
 void LayoutTestController::setCustomPolicyDelegate(bool setDelegate)
 {
-    // FIXME: Implement!
+    COMPtr<IWebView> webView;
+    if (FAILED(frame->webView(&webView)))
+        return;
+
+    if (setDelegate)
+        webView->setPolicyDelegate(policyDelegate);
+    else
+        webView->setPolicyDelegate(NULL);
 }
 
 void LayoutTestController::setMainFrameIsFirstResponder(bool flag)
diff --git a/WebKitTools/DumpRenderTree/win/PolicyDelegate.cpp b/WebKitTools/DumpRenderTree/win/PolicyDelegate.cpp
new file mode 100644 (file)
index 0000000..6fc4ef2
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "DumpRenderTree.h"
+#include "PolicyDelegate.h"
+
+#include <string>
+
+using std::wstring;
+
+PolicyDelegate::PolicyDelegate()
+    : m_refCount(1)
+{
+}
+
+// IUnknown
+HRESULT STDMETHODCALLTYPE PolicyDelegate::QueryInterface(REFIID riid, void** ppvObject)
+{
+    *ppvObject = 0;
+    if (IsEqualGUID(riid, IID_IUnknown))
+        *ppvObject = static_cast<IWebPolicyDelegate*>(this);
+    else if (IsEqualGUID(riid, IID_IWebPolicyDelegate))
+        *ppvObject = static_cast<IWebPolicyDelegate*>(this);
+    else
+        return E_NOINTERFACE;
+
+    AddRef();
+    return S_OK;
+}
+
+ULONG STDMETHODCALLTYPE PolicyDelegate::AddRef(void)
+{
+    return ++m_refCount;
+}
+
+ULONG STDMETHODCALLTYPE PolicyDelegate::Release(void)
+{
+    ULONG newRef = --m_refCount;
+    if (!newRef)
+        delete this;
+
+    return newRef;
+}
+
+HRESULT STDMETHODCALLTYPE PolicyDelegate::decidePolicyForNavigationAction(
+    /*[in]*/ IWebView* /*webView*/, 
+    /*[in]*/ IPropertyBag* /*actionInformation*/, 
+    /*[in]*/ IWebURLRequest* request, 
+    /*[in]*/ IWebFrame* frame, 
+    /*[in]*/ IWebPolicyDecisionListener* listener)
+{
+    BSTR frameName;
+    frame->name(&frameName);
+
+    BSTR url;
+    request->URL(&url);
+
+    printf("Frame %S attempted to load %S\n", frameName ? frameName : TEXT(""), url ? url : TEXT(""));
+    SysFreeString(frameName);
+    SysFreeString(url);
+    listener->ignore();
+
+    return S_OK;
+}
diff --git a/WebKitTools/DumpRenderTree/win/PolicyDelegate.h b/WebKitTools/DumpRenderTree/win/PolicyDelegate.h
new file mode 100644 (file)
index 0000000..d59dd9d
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PolicyDelegate_h
+#define PolicyDelegate_h
+
+#include <WebKit/IWebPolicyDelegate.h>
+
+class PolicyDelegate : public IWebPolicyDelegate {
+public:
+    PolicyDelegate();
+
+    // IUnknown
+    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
+    virtual ULONG STDMETHODCALLTYPE AddRef(void);
+    virtual ULONG STDMETHODCALLTYPE Release(void);
+
+    // IWebPolicyDelegate
+    virtual HRESULT STDMETHODCALLTYPE decidePolicyForNavigationAction( 
+        /* [in] */ IWebView *webView,
+        /* [in] */ IPropertyBag *actionInformation,
+        /* [in] */ IWebURLRequest *request,
+        /* [in] */ IWebFrame *frame,
+        /* [in] */ IWebPolicyDecisionListener *listener);
+    
+    virtual HRESULT STDMETHODCALLTYPE decidePolicyForNewWindowAction( 
+        /* [in] */ IWebView *webView,
+        /* [in] */ IPropertyBag *actionInformation,
+        /* [in] */ IWebURLRequest *request,
+        /* [in] */ BSTR frameName,
+        /* [in] */ IWebPolicyDecisionListener *listener){ return E_NOTIMPL; }
+    
+    virtual HRESULT STDMETHODCALLTYPE decidePolicyForMIMEType( 
+        /* [in] */ IWebView *webView,
+        /* [in] */ BSTR type,
+        /* [in] */ IWebURLRequest *request,
+        /* [in] */ IWebFrame *frame,
+        /* [in] */ IWebPolicyDecisionListener *listener){ return E_NOTIMPL; }
+    
+    virtual HRESULT STDMETHODCALLTYPE unableToImplementPolicyWithError( 
+        /* [in] */ IWebView *webView,
+        /* [in] */ IWebError *error,
+        /* [in] */ IWebFrame *frame){ return E_NOTIMPL; }
+
+private:
+    ULONG m_refCount;
+};
+
+#endif // PolicyDelegate_h