Home | History | Annotate | Download | only in web
      1 /*
      2  * Copyright (C) 2010 Google 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 are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include "config.h"
     32 #include "InspectorFrontendClientImpl.h"
     33 
     34 #include "V8InspectorFrontendHost.h"
     35 #include "WebDevToolsFrontendClient.h"
     36 #include "WebDevToolsFrontendImpl.h"
     37 #include "bindings/v8/ScriptController.h"
     38 #include "core/dom/Document.h"
     39 #include "core/inspector/InspectorFrontendHost.h"
     40 #include "core/page/Frame.h"
     41 #include "core/page/Page.h"
     42 #include "core/platform/NotImplemented.h"
     43 #include "public/platform/WebFloatPoint.h"
     44 #include "public/platform/WebString.h"
     45 #include "wtf/text/WTFString.h"
     46 
     47 using namespace WebCore;
     48 
     49 namespace WebKit {
     50 
     51 InspectorFrontendClientImpl::InspectorFrontendClientImpl(Page* frontendPage, WebDevToolsFrontendClient* client, WebDevToolsFrontendImpl* frontend)
     52     : m_frontendPage(frontendPage)
     53     , m_client(client)
     54 {
     55 }
     56 
     57 InspectorFrontendClientImpl::~InspectorFrontendClientImpl()
     58 {
     59     if (m_frontendHost)
     60         m_frontendHost->disconnectClient();
     61     m_client = 0;
     62 }
     63 
     64 void InspectorFrontendClientImpl::windowObjectCleared()
     65 {
     66     v8::HandleScope handleScope;
     67     v8::Handle<v8::Context> frameContext = m_frontendPage->mainFrame() ? m_frontendPage->mainFrame()->script()->currentWorldContext() : v8::Local<v8::Context>();
     68     v8::Context::Scope contextScope(frameContext);
     69 
     70     if (m_frontendHost)
     71         m_frontendHost->disconnectClient();
     72     m_frontendHost = InspectorFrontendHost::create(this, m_frontendPage);
     73     v8::Handle<v8::Value> frontendHostObj = toV8(m_frontendHost.get(), v8::Handle<v8::Object>(), frameContext->GetIsolate());
     74     v8::Handle<v8::Object> global = frameContext->Global();
     75 
     76     global->Set(v8::String::New("InspectorFrontendHost"), frontendHostObj);
     77 }
     78 
     79 void InspectorFrontendClientImpl::moveWindowBy(float x, float y)
     80 {
     81     m_client->moveWindowBy(WebFloatPoint(x, y));
     82 }
     83 
     84 void InspectorFrontendClientImpl::bringToFront()
     85 {
     86     m_client->activateWindow();
     87 }
     88 
     89 void InspectorFrontendClientImpl::closeWindow()
     90 {
     91     m_client->closeWindow();
     92 }
     93 
     94 void InspectorFrontendClientImpl::requestSetDockSide(DockSide side)
     95 {
     96     String sideString = "undocked";
     97     switch (side) {
     98     case DockedToRight: sideString = "right"; break;
     99     case DockedToBottom: sideString = "bottom"; break;
    100     case Undocked: sideString = "undocked"; break;
    101     }
    102     m_client->requestSetDockSide(sideString);
    103 }
    104 
    105 void InspectorFrontendClientImpl::changeAttachedWindowHeight(unsigned height)
    106 {
    107     m_client->changeAttachedWindowHeight(height);
    108 }
    109 
    110 void InspectorFrontendClientImpl::openInNewTab(const String& url)
    111 {
    112     m_client->openInNewTab(url);
    113 }
    114 
    115 void InspectorFrontendClientImpl::save(const String& url, const String& content, bool forceSaveAs)
    116 {
    117     m_client->save(url, content, forceSaveAs);
    118 }
    119 
    120 void InspectorFrontendClientImpl::append(const String& url, const String& content)
    121 {
    122     m_client->append(url, content);
    123 }
    124 
    125 void InspectorFrontendClientImpl::inspectedURLChanged(const String& url)
    126 {
    127     m_frontendPage->mainFrame()->document()->setTitle("Developer Tools - " + url);
    128 }
    129 
    130 void InspectorFrontendClientImpl::sendMessageToBackend(const String& message)
    131 {
    132     m_client->sendMessageToBackend(message);
    133 }
    134 
    135 void InspectorFrontendClientImpl::requestFileSystems()
    136 {
    137     m_client->requestFileSystems();
    138 }
    139 
    140 void InspectorFrontendClientImpl::indexPath(int requestId, const String& fileSystemPath)
    141 {
    142     m_client->indexPath(requestId, fileSystemPath);
    143 }
    144 
    145 void InspectorFrontendClientImpl::stopIndexing(int requestId)
    146 {
    147     m_client->stopIndexing(requestId);
    148 }
    149 
    150 void InspectorFrontendClientImpl::searchInPath(int requestId, const String& fileSystemPath, const String& query)
    151 {
    152     m_client->searchInPath(requestId, fileSystemPath, query);
    153 }
    154 
    155 void InspectorFrontendClientImpl::addFileSystem()
    156 {
    157     m_client->addFileSystem();
    158 }
    159 
    160 void InspectorFrontendClientImpl::removeFileSystem(const String& fileSystemPath)
    161 {
    162     m_client->removeFileSystem(fileSystemPath);
    163 }
    164 
    165 bool InspectorFrontendClientImpl::isUnderTest()
    166 {
    167     return m_client->isUnderTest();
    168 }
    169 
    170 } // namespace WebKit
    171