1/*
2 * Copyright (C) 2009 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 "WebNavigationData.h"
29
30using namespace WebCore;
31
32// IUnknown -------------------------------------------------------------------
33
34HRESULT STDMETHODCALLTYPE WebNavigationData::QueryInterface(REFIID riid, void** ppvObject)
35{
36    *ppvObject = 0;
37    if (IsEqualGUID(riid, IID_IUnknown))
38        *ppvObject = static_cast<IWebNavigationData*>(this);
39    else if (IsEqualGUID(riid, IID_IWebNavigationData))
40        *ppvObject = static_cast<IWebNavigationData*>(this);
41    else
42        return E_NOINTERFACE;
43
44    AddRef();
45    return S_OK;
46}
47
48ULONG STDMETHODCALLTYPE WebNavigationData::AddRef(void)
49{
50    return ++m_refCount;
51}
52
53ULONG STDMETHODCALLTYPE WebNavigationData::Release(void)
54{
55    ULONG newRef = --m_refCount;
56    if (!newRef)
57        delete(this);
58
59    return newRef;
60}
61
62// WebNavigationData -------------------------------------------------------------------
63
64WebNavigationData::WebNavigationData(const String& url, const String& title, IWebURLRequest* request, IWebURLResponse* response, bool hasSubstituteData, const String& clientRedirectSource)
65    : m_refCount(0)
66    , m_url(url)
67    , m_title(title)
68    , m_request(request)
69    , m_response(response)
70    , m_hasSubstituteData(hasSubstituteData)
71    , m_clientRedirectSource(clientRedirectSource)
72
73{
74    gClassCount++;
75    gClassNameCount.add("WebNavigationData");
76}
77
78WebNavigationData::~WebNavigationData()
79{
80    gClassCount--;
81    gClassNameCount.remove("WebNavigationData");
82}
83
84WebNavigationData* WebNavigationData::createInstance(const String& url, const String& title, IWebURLRequest* request, IWebURLResponse* response, bool hasSubstituteData, const String& clientRedirectSource)
85{
86    WebNavigationData* instance = new WebNavigationData(url, title, request, response, hasSubstituteData, clientRedirectSource);
87    instance->AddRef();
88    return instance;
89}
90
91// IWebNavigationData -------------------------------------------------------------------
92
93HRESULT WebNavigationData::url(BSTR* url)
94{
95    if (!url)
96        return E_POINTER;
97    *url = BString(m_url).release();
98    return S_OK;
99}
100
101HRESULT WebNavigationData::title(BSTR* title)
102{
103    if (!title)
104        return E_POINTER;
105    *title = BString(m_title).release();
106    return S_OK;
107}
108
109HRESULT WebNavigationData::originalRequest(IWebURLRequest** request)
110{
111    if (!request)
112        return E_POINTER;
113    *request = m_request.get();
114    m_request->AddRef();
115    return S_OK;
116}
117
118HRESULT WebNavigationData::response(IWebURLResponse** response)
119{
120    if (!response)
121        return E_POINTER;
122    *response = m_response.get();
123    m_response->AddRef();
124    return S_OK;
125}
126
127HRESULT WebNavigationData::hasSubstituteData(BOOL* hasSubstituteData)
128{
129    if (!hasSubstituteData)
130        return E_POINTER;
131    *hasSubstituteData = m_hasSubstituteData;
132    return S_OK;
133}
134
135HRESULT WebNavigationData::clientRedirectSource(BSTR* clientRedirectSource)
136{
137    if (!clientRedirectSource)
138        return E_POINTER;
139
140    *clientRedirectSource = BString(m_clientRedirectSource).release();
141    return S_OK;
142}
143