1 /* 2 * Copyright (C) 2007 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 COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 #include "config.h" 27 #include "WebKitDLL.h" 28 #include "WebFramePolicyListener.h" 29 30 #include "WebFrame.h" 31 32 #pragma warning(push, 0) 33 #include <WebCore/Frame.h> 34 #include <WebCore/FrameLoader.h> 35 #include <WebCore/FrameLoaderClient.h> 36 #pragma warning(pop) 37 38 using namespace WebCore; 39 40 // WebFramePolicyListener ---------------------------------------------------------------- 41 42 WebFramePolicyListener::WebFramePolicyListener(PassRefPtr<Frame> frame) 43 : m_refCount(0) 44 , m_frame(frame) 45 { 46 gClassCount++; 47 gClassNameCount.add("WebFramePolicyListener"); 48 } 49 50 WebFramePolicyListener::~WebFramePolicyListener() 51 { 52 gClassCount--; 53 gClassNameCount.remove("WebFramePolicyListener"); 54 } 55 56 WebFramePolicyListener* WebFramePolicyListener::createInstance(PassRefPtr<Frame> frame) 57 { 58 WebFramePolicyListener* instance = new WebFramePolicyListener(frame); 59 instance->AddRef(); 60 return instance; 61 } 62 63 // IUnknown ------------------------------------------------------------------- 64 65 HRESULT STDMETHODCALLTYPE WebFramePolicyListener::QueryInterface(REFIID riid, void** ppvObject) 66 { 67 *ppvObject = 0; 68 if (IsEqualGUID(riid, IID_IUnknown)) 69 *ppvObject = static_cast<IWebPolicyDecisionListener*>(this); 70 else if (IsEqualGUID(riid, IID_IWebPolicyDecisionListener)) 71 *ppvObject = static_cast<IWebPolicyDecisionListener*>(this); 72 else if (IsEqualGUID(riid, IID_IWebFormSubmissionListener)) 73 *ppvObject = static_cast<IWebFormSubmissionListener*>(this); 74 else 75 return E_NOINTERFACE; 76 77 AddRef(); 78 return S_OK; 79 } 80 81 ULONG STDMETHODCALLTYPE WebFramePolicyListener::AddRef(void) 82 { 83 return ++m_refCount; 84 } 85 86 ULONG STDMETHODCALLTYPE WebFramePolicyListener::Release(void) 87 { 88 ULONG newRef = --m_refCount; 89 if (!newRef) 90 delete(this); 91 92 return newRef; 93 } 94 95 // IWebPolicyDecisionListener ------------------------------------------------------------ 96 97 HRESULT STDMETHODCALLTYPE WebFramePolicyListener::use(void) 98 { 99 receivedPolicyDecision(PolicyUse); 100 return S_OK; 101 } 102 103 HRESULT STDMETHODCALLTYPE WebFramePolicyListener::download(void) 104 { 105 receivedPolicyDecision(PolicyDownload); 106 return S_OK; 107 } 108 109 HRESULT STDMETHODCALLTYPE WebFramePolicyListener::ignore(void) 110 { 111 receivedPolicyDecision(PolicyIgnore); 112 return S_OK; 113 } 114 115 // IWebFormSubmissionListener ------------------------------------------------------------ 116 117 HRESULT STDMETHODCALLTYPE WebFramePolicyListener::continueSubmit(void) 118 { 119 receivedPolicyDecision(PolicyUse); 120 return S_OK; 121 } 122 123 // WebFramePolicyListener ---------------------------------------------------------------- 124 void WebFramePolicyListener::receivedPolicyDecision(PolicyAction action) 125 { 126 RefPtr<Frame> frame = m_frame.release(); 127 if (frame) 128 static_cast<WebFrame*>(frame->loader()->client())->receivedPolicyDecision(action); 129 } 130 131 void WebFramePolicyListener::invalidate() 132 { 133 m_frame = 0; 134 } 135 136