webengine/osswebengine/WebKit/win/WebDebugProgram.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     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 "WebDebugProgram.h"
       
    29 
       
    30 #include "WebKitStatistics.h"
       
    31 #include "WebView.h"
       
    32 #include <wtf/Vector.h>
       
    33 
       
    34 static Vector<IWebView*> sViews;
       
    35 
       
    36 // EnumViews ------------------------------------------------------------------
       
    37 
       
    38 class EnumViews : public IEnumVARIANT
       
    39 {
       
    40 public:
       
    41     EnumViews() : m_refCount(1), m_current(sViews.begin()) { }
       
    42 
       
    43     virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject)
       
    44     {
       
    45         *ppvObject = 0;
       
    46         if (IsEqualGUID(riid, IID_IUnknown) || IsEqualGUID(riid, IID_IEnumVARIANT))
       
    47             *ppvObject = this;
       
    48         else
       
    49             return E_NOINTERFACE;
       
    50 
       
    51         AddRef();
       
    52         return S_OK;
       
    53     }
       
    54 
       
    55     virtual ULONG STDMETHODCALLTYPE AddRef(void)
       
    56     {
       
    57         return ++m_refCount;
       
    58     }
       
    59 
       
    60     virtual ULONG STDMETHODCALLTYPE Release(void)
       
    61     {
       
    62         ULONG newRef = --m_refCount;
       
    63         if (!newRef)
       
    64             delete(this);
       
    65         return newRef;
       
    66     }
       
    67 
       
    68     virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
       
    69     {
       
    70         if (pCeltFetched)
       
    71             *pCeltFetched = 0;
       
    72         if (!rgVar)
       
    73             return E_POINTER;
       
    74         VariantInit(rgVar);
       
    75         if (!celt || celt > 1)
       
    76             return S_FALSE;
       
    77         if (m_current == sViews.end())
       
    78             return S_FALSE;
       
    79 
       
    80         IUnknown* unknown;
       
    81         HRESULT hr = (*m_current++)->QueryInterface(IID_IUnknown, (void**)&unknown);
       
    82         if (FAILED(hr))
       
    83             return hr;
       
    84 
       
    85         V_VT(rgVar) = VT_UNKNOWN;
       
    86         V_UNKNOWN(rgVar) = unknown;
       
    87 
       
    88         if (pCeltFetched)
       
    89             *pCeltFetched = 1;
       
    90         return S_OK;
       
    91     }
       
    92 
       
    93     virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt)
       
    94     {
       
    95         m_current += celt;
       
    96         return (m_current != sViews.end()) ? S_OK : S_FALSE;
       
    97     }
       
    98 
       
    99     virtual HRESULT STDMETHODCALLTYPE Reset(void)
       
   100     {
       
   101         m_current = sViews.begin();
       
   102         return S_OK;
       
   103     }
       
   104 
       
   105     virtual HRESULT STDMETHODCALLTYPE Clone(IEnumVARIANT**)
       
   106     {
       
   107         return E_NOTIMPL;
       
   108     }
       
   109 
       
   110 private:
       
   111     ULONG m_refCount;
       
   112     Vector<IWebView*>::iterator m_current;
       
   113 };
       
   114 
       
   115 // WebDebugProgram ------------------------------------------------------------
       
   116 
       
   117 WebDebugProgram::WebDebugProgram()
       
   118 : m_refCount(0)
       
   119 {
       
   120     gClassCount++;
       
   121 }
       
   122 
       
   123 WebDebugProgram::~WebDebugProgram()
       
   124 {
       
   125     gClassCount--;
       
   126 }
       
   127 
       
   128 WebDebugProgram* WebDebugProgram::createInstance()
       
   129 {
       
   130     WebDebugProgram* instance = new WebDebugProgram;
       
   131     instance->AddRef();
       
   132     return instance;
       
   133 }
       
   134 
       
   135 // IUnknown -------------------------------------------------------------------
       
   136 
       
   137 HRESULT STDMETHODCALLTYPE WebDebugProgram::QueryInterface(REFIID riid, void** ppvObject)
       
   138 {
       
   139     *ppvObject = 0;
       
   140     if (IsEqualGUID(riid, IID_IUnknown))
       
   141         *ppvObject = static_cast<WebDebugProgram*>(this);
       
   142     else if (IsEqualGUID(riid, IID_IWebDebugProgram))
       
   143         *ppvObject = static_cast<WebDebugProgram*>(this);
       
   144     else
       
   145         return E_NOINTERFACE;
       
   146 
       
   147     AddRef();
       
   148     return S_OK;
       
   149 }
       
   150 
       
   151 ULONG STDMETHODCALLTYPE WebDebugProgram::AddRef(void)
       
   152 {
       
   153     return ++m_refCount;
       
   154 }
       
   155 
       
   156 ULONG STDMETHODCALLTYPE WebDebugProgram::Release(void)
       
   157 {
       
   158     ULONG newRef = --m_refCount;
       
   159     if (!newRef)
       
   160         delete(this);
       
   161 
       
   162     return newRef;
       
   163 }
       
   164 
       
   165 void WebDebugProgram::viewAdded(IWebView* view)
       
   166 {
       
   167     sViews.append(view);
       
   168 }
       
   169 
       
   170 void WebDebugProgram::viewRemoved(IWebView* view)
       
   171 {
       
   172     Vector<IWebView*>::iterator end = sViews.end();
       
   173     int i=0;
       
   174     for (Vector<IWebView*>::iterator it = sViews.begin(); it != end; ++it, ++i) {
       
   175         if (*it == view) {
       
   176             sViews.remove(i);
       
   177             break;
       
   178         }
       
   179     }
       
   180 }
       
   181 
       
   182 // IWebDebugProgram -----------------------------------------------------------
       
   183 
       
   184 HRESULT STDMETHODCALLTYPE WebDebugProgram::attach( void)
       
   185 {
       
   186     return S_OK;
       
   187 }
       
   188 
       
   189 HRESULT STDMETHODCALLTYPE WebDebugProgram::detach( void)
       
   190 {
       
   191     return S_OK;
       
   192 }
       
   193 
       
   194 HRESULT STDMETHODCALLTYPE WebDebugProgram::statistics( 
       
   195     /* [retval][out] */ IWebKitStatistics **statistics)
       
   196 {
       
   197     if (!statistics)
       
   198         return E_POINTER;
       
   199     *statistics = WebKitStatistics::createInstance();
       
   200     return S_OK;
       
   201 }
       
   202 
       
   203 HRESULT STDMETHODCALLTYPE WebDebugProgram::webViews( 
       
   204     /* [retval][out] */ IEnumVARIANT** enumViews)
       
   205 {
       
   206     if (!enumViews)
       
   207         return E_POINTER;
       
   208     *enumViews = new EnumViews;
       
   209     return S_OK;
       
   210 }