Home | History | Annotate | Download | only in win
      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  *
      8  * 1.  Redistributions of source code must retain the above copyright
      9  *     notice, this list of conditions and the following disclaimer.
     10  * 2.  Redistributions in binary form must reproduce the above copyright
     11  *     notice, this list of conditions and the following disclaimer in the
     12  *     documentation and/or other materials provided with the distribution.
     13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
     14  *     its contributors may be used to endorse or promote products derived
     15  *     from this software without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include "config.h"
     30 #include "WebInspector.h"
     31 
     32 #include "WebKitDLL.h"
     33 #include "WebView.h"
     34 #pragma warning(push, 0)
     35 #include <WebCore/InspectorController.h>
     36 #include <WebCore/Page.h>
     37 #pragma warning(pop)
     38 #include <wtf/Assertions.h>
     39 
     40 using namespace WebCore;
     41 
     42 WebInspector* WebInspector::createInstance(WebView* webView)
     43 {
     44     WebInspector* inspector = new WebInspector(webView);
     45     inspector->AddRef();
     46     return inspector;
     47 }
     48 
     49 WebInspector::WebInspector(WebView* webView)
     50     : m_refCount(0)
     51     , m_webView(webView)
     52 {
     53     ASSERT_ARG(webView, webView);
     54 
     55     gClassCount++;
     56     gClassNameCount.add("WebInspector");
     57 }
     58 
     59 WebInspector::~WebInspector()
     60 {
     61     gClassCount--;
     62     gClassNameCount.remove("WebInspector");
     63 }
     64 
     65 void WebInspector::webViewClosed()
     66 {
     67     m_webView = 0;
     68 }
     69 
     70 HRESULT STDMETHODCALLTYPE WebInspector::QueryInterface(REFIID riid, void** ppvObject)
     71 {
     72     *ppvObject = 0;
     73     if (IsEqualGUID(riid, IID_IWebInspector))
     74         *ppvObject = static_cast<IWebInspector*>(this);
     75     else if (IsEqualGUID(riid, IID_IWebInspectorPrivate))
     76         *ppvObject = static_cast<IWebInspectorPrivate*>(this);
     77     else if (IsEqualGUID(riid, IID_IUnknown))
     78         *ppvObject = static_cast<IWebInspector*>(this);
     79     else
     80         return E_NOINTERFACE;
     81 
     82     AddRef();
     83     return S_OK;
     84 }
     85 
     86 ULONG STDMETHODCALLTYPE WebInspector::AddRef(void)
     87 {
     88     return ++m_refCount;
     89 }
     90 
     91 ULONG STDMETHODCALLTYPE WebInspector::Release(void)
     92 {
     93     ULONG newRef = --m_refCount;
     94     if (!newRef)
     95         delete this;
     96 
     97     return newRef;
     98 }
     99 
    100 HRESULT STDMETHODCALLTYPE WebInspector::show()
    101 {
    102     if (m_webView)
    103         if (Page* page = m_webView->page())
    104             page->inspectorController()->show();
    105 
    106     return S_OK;
    107 }
    108 
    109 HRESULT STDMETHODCALLTYPE WebInspector::showConsole()
    110 {
    111     if (m_webView)
    112         if (Page* page = m_webView->page())
    113             page->inspectorController()->showPanel(InspectorController::ConsolePanel);
    114 
    115     return S_OK;
    116 }
    117 
    118 HRESULT STDMETHODCALLTYPE WebInspector::unused1()
    119 {
    120     return S_OK;
    121 }
    122 
    123 HRESULT STDMETHODCALLTYPE WebInspector::close()
    124 {
    125     if (m_webView)
    126         if (Page* page = m_webView->page())
    127             page->inspectorController()->close();
    128 
    129     return S_OK;
    130 }
    131 
    132 HRESULT STDMETHODCALLTYPE WebInspector::attach()
    133 {
    134     if (m_webView)
    135         if (Page* page = m_webView->page())
    136             page->inspectorController()->attachWindow();
    137 
    138     return S_OK;
    139 }
    140 
    141 HRESULT STDMETHODCALLTYPE WebInspector::detach()
    142 {
    143     if (m_webView)
    144         if (Page* page = m_webView->page())
    145             page->inspectorController()->detachWindow();
    146 
    147     return S_OK;
    148 }
    149 
    150 HRESULT STDMETHODCALLTYPE WebInspector::isDebuggingJavaScript(BOOL* isDebugging)
    151 {
    152     if (!isDebugging)
    153         return E_POINTER;
    154 
    155     *isDebugging = FALSE;
    156 
    157     if (!m_webView)
    158         return S_OK;
    159 
    160     Page* page = m_webView->page();
    161     if (!page)
    162         return S_OK;
    163 
    164     *isDebugging = page->inspectorController()->debuggerEnabled();
    165     return S_OK;
    166 }
    167 
    168 HRESULT STDMETHODCALLTYPE WebInspector::toggleDebuggingJavaScript()
    169 {
    170     if (!m_webView)
    171         return S_OK;
    172 
    173     Page* page = m_webView->page();
    174     if (!page)
    175         return S_OK;
    176 
    177     InspectorController* inspector = page->inspectorController();
    178 
    179     if (inspector->debuggerEnabled())
    180         inspector->disableDebugger();
    181     else {
    182         inspector->showPanel(InspectorController::ScriptsPanel);
    183         inspector->enableDebugger();
    184     }
    185 
    186     return S_OK;
    187 }
    188 
    189 HRESULT STDMETHODCALLTYPE WebInspector::isProfilingJavaScript(BOOL* isProfiling)
    190 {
    191     if (!isProfiling)
    192         return E_POINTER;
    193 
    194     *isProfiling = FALSE;
    195 
    196     if (!m_webView)
    197         return S_OK;
    198 
    199     Page* page = m_webView->page();
    200     if (!page)
    201         return S_OK;
    202 
    203     *isProfiling = page->inspectorController()->isRecordingUserInitiatedProfile();
    204     return S_OK;
    205 }
    206 
    207 HRESULT STDMETHODCALLTYPE WebInspector::toggleProfilingJavaScript()
    208 {
    209     if (!m_webView)
    210         return S_OK;
    211 
    212     Page* page = m_webView->page();
    213     if (!page)
    214         return S_OK;
    215 
    216     InspectorController* inspector = page->inspectorController();
    217 
    218     if (inspector->isRecordingUserInitiatedProfile()) {
    219         inspector->stopUserInitiatedProfiling();
    220         inspector->showPanel(InspectorController::ProfilesPanel);
    221     } else
    222         inspector->startUserInitiatedProfiling();
    223 
    224     return S_OK;
    225 }
    226 
    227 HRESULT STDMETHODCALLTYPE WebInspector::isJavaScriptProfilingEnabled(BOOL* isProfilingEnabled)
    228 {
    229     if (!isProfilingEnabled)
    230         return E_POINTER;
    231 
    232     *isProfilingEnabled = FALSE;
    233 
    234     if (!m_webView)
    235         return S_OK;
    236 
    237     Page* page = m_webView->page();
    238     if (!page)
    239         return S_OK;
    240 
    241     *isProfilingEnabled = page->inspectorController()->profilerEnabled();
    242     return S_OK;
    243 }
    244 
    245 HRESULT STDMETHODCALLTYPE WebInspector::setJavaScriptProfilingEnabled(BOOL enabled)
    246 {
    247     if (!m_webView)
    248         return S_OK;
    249 
    250     Page* page = m_webView->page();
    251     if (!page)
    252         return S_OK;
    253 
    254     if (enabled)
    255         page->inspectorController()->enableProfiler();
    256     else
    257         page->inspectorController()->disableProfiler();
    258 
    259     return S_OK;
    260 }
    261 
    262 HRESULT STDMETHODCALLTYPE  WebInspector::evaluateInFrontend(ULONG callId, BSTR bScript)
    263 {
    264     if (!m_webView)
    265         return S_OK;
    266 
    267     Page* page = m_webView->page();
    268     if (!page)
    269         return S_OK;
    270 
    271     String script(bScript, SysStringLen(bScript));
    272     page->inspectorController()->evaluateForTestInFrontend(callId, script);
    273     return S_OK;
    274 }
    275 
    276 HRESULT STDMETHODCALLTYPE WebInspector::isTimelineProfilingEnabled(BOOL* isEnabled)
    277 {
    278     if (!isEnabled)
    279         return E_POINTER;
    280 
    281     *isEnabled = FALSE;
    282 
    283     if (!m_webView)
    284         return S_OK;
    285 
    286     Page* page = m_webView->page();
    287     if (!page)
    288         return S_OK;
    289 
    290     *isEnabled = page->inspectorController()->timelineAgent() != 0;
    291     return S_OK;
    292 }
    293 
    294 HRESULT STDMETHODCALLTYPE WebInspector::setTimelineProfilingEnabled(BOOL enabled)
    295 {
    296     if (!m_webView)
    297         return S_OK;
    298 
    299     Page* page = m_webView->page();
    300     if (!page)
    301         return S_OK;
    302 
    303     if (enabled)
    304         page->inspectorController()->startTimelineProfiler();
    305     else
    306         page->inspectorController()->stopTimelineProfiler();
    307 
    308     return S_OK;
    309 }
    310