Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / web / WebDevToolsAgentImpl.cpp
index 3b3e300..e178866 100644 (file)
 #include "wtf/CurrentTime.h"
 #include "wtf/MathExtras.h"
 #include "wtf/Noncopyable.h"
+#include "wtf/ProcessID.h"
 #include "wtf/text/WTFString.h"
 
-using namespace blink;
-
 namespace OverlayZOrders {
 // Use 99 as a big z-order number so that highlight is above other overlays.
 static const int highlight = 99;
@@ -83,6 +82,8 @@ static const int highlight = 99;
 
 namespace blink {
 
+static int s_nextDebuggerId = 1;
+
 class ClientMessageLoopAdapter : public PageScriptDebugServer::ClientMessageLoop {
 public:
     static void ensureClientMessageLoopCreated(WebDevToolsAgentClient* client)
@@ -108,7 +109,7 @@ public:
     }
 
 private:
-    ClientMessageLoopAdapter(PassOwnPtr<blink::WebDevToolsAgentClient::WebKitClientMessageLoop> messageLoop)
+    ClientMessageLoopAdapter(PassOwnPtr<WebDevToolsAgentClient::WebKitClientMessageLoop> messageLoop)
         : m_running(false)
         , m_messageLoop(messageLoop) { }
 
@@ -170,7 +171,7 @@ private:
     }
 
     bool m_running;
-    OwnPtr<blink::WebDevToolsAgentClient::WebKitClientMessageLoop> m_messageLoop;
+    OwnPtr<WebDevToolsAgentClient::WebKitClientMessageLoop> m_messageLoop;
     typedef HashSet<WebViewImpl*> FrozenViewsSet;
     FrozenViewsSet m_frozenViews;
     // FIXME: The ownership model for s_instance is somewhat complicated. Can we make this simpler?
@@ -200,7 +201,7 @@ private:
 WebDevToolsAgentImpl::WebDevToolsAgentImpl(
     WebViewImpl* webViewImpl,
     WebDevToolsAgentClient* client)
-    : m_debuggerId(client->debuggerId())
+    : m_debuggerId(s_nextDebuggerId++)
     , m_layerTreeId(0)
     , m_client(client)
     , m_webViewImpl(webViewImpl)
@@ -216,7 +217,9 @@ WebDevToolsAgentImpl::WebDevToolsAgentImpl(
     , m_pageScaleLimitsOverriden(false)
     , m_touchEventEmulationEnabled(false)
 {
-    long processId = client->processId();
+    ASSERT(isMainThread());
+
+    long processId = WTF::getCurrentProcessID();
     ASSERT(processId > 0);
     inspectorController()->setProcessId(processId);
 
@@ -228,7 +231,7 @@ WebDevToolsAgentImpl::~WebDevToolsAgentImpl()
 {
     ClientMessageLoopAdapter::inspectedViewClosed(m_webViewImpl);
     if (m_attached)
-        blink::Platform::current()->currentThread()->removeTaskObserver(this);
+        Platform::current()->currentThread()->removeTaskObserver(this);
 }
 
 void WebDevToolsAgentImpl::attach(const WebString& hostId)
@@ -237,7 +240,7 @@ void WebDevToolsAgentImpl::attach(const WebString& hostId)
         return;
 
     inspectorController()->connectFrontend(hostId, this);
-    blink::Platform::current()->currentThread()->addTaskObserver(this);
+    Platform::current()->currentThread()->addTaskObserver(this);
     m_attached = true;
 }
 
@@ -247,13 +250,13 @@ void WebDevToolsAgentImpl::reattach(const WebString& hostId, const WebString& sa
         return;
 
     inspectorController()->reuseFrontend(hostId, this, savedState);
-    blink::Platform::current()->currentThread()->addTaskObserver(this);
+    Platform::current()->currentThread()->addTaskObserver(this);
     m_attached = true;
 }
 
 void WebDevToolsAgentImpl::detach()
 {
-    blink::Platform::current()->currentThread()->removeTaskObserver(this);
+    Platform::current()->currentThread()->removeTaskObserver(this);
 
     // Prevent controller from sending messages to the frontend.
     InspectorController* ic = inspectorController();
@@ -295,7 +298,7 @@ void WebDevToolsAgentImpl::didComposite()
 
 void WebDevToolsAgentImpl::didCreateScriptContext(WebLocalFrameImpl* webframe, int worldId)
 {
-    if (blink::LocalFrame* frame = webframe->frame())
+    if (LocalFrame* frame = webframe->frame())
         frame->script().setWorldDebugId(worldId, m_debuggerId);
     // Skip non main world contexts.
     if (worldId)
@@ -303,7 +306,7 @@ void WebDevToolsAgentImpl::didCreateScriptContext(WebLocalFrameImpl* webframe, i
     m_webViewDidLayoutOnceAfterLoad = false;
 }
 
-bool WebDevToolsAgentImpl::handleInputEvent(blink::Page* page, const WebInputEvent& inputEvent)
+bool WebDevToolsAgentImpl::handleInputEvent(Page* page, const WebInputEvent& inputEvent)
 {
     if (!m_attached && !m_generatingEvent)
         return false;
@@ -316,13 +319,13 @@ bool WebDevToolsAgentImpl::handleInputEvent(blink::Page* page, const WebInputEve
         PlatformGestureEventBuilder gestureEvent(frameView, static_cast<const WebGestureEvent&>(inputEvent));
         float pageScaleFactor = page->pageScaleFactor();
         if (gestureEvent.type() == PlatformEvent::GesturePinchBegin) {
-            m_lastPinchAnchorCss = adoptPtr(new blink::IntPoint(frameView->scrollPosition() + gestureEvent.position()));
-            m_lastPinchAnchorDip = adoptPtr(new blink::IntPoint(gestureEvent.position()));
+            m_lastPinchAnchorCss = adoptPtr(new IntPoint(frameView->scrollPosition() + gestureEvent.position()));
+            m_lastPinchAnchorDip = adoptPtr(new IntPoint(gestureEvent.position()));
             m_lastPinchAnchorDip->scale(pageScaleFactor, pageScaleFactor);
         }
         if (gestureEvent.type() == PlatformEvent::GesturePinchUpdate && m_lastPinchAnchorCss) {
             float newPageScaleFactor = pageScaleFactor * gestureEvent.scale();
-            blink::IntPoint anchorCss(*m_lastPinchAnchorDip.get());
+            IntPoint anchorCss(*m_lastPinchAnchorDip.get());
             anchorCss.scale(1.f / newPageScaleFactor, 1.f / newPageScaleFactor);
             m_webViewImpl->setPageScaleFactor(newPageScaleFactor);
             m_webViewImpl->setMainFrameScrollOffset(*m_lastPinchAnchorCss.get() - toIntSize(anchorCss));
@@ -458,102 +461,6 @@ void WebDevToolsAgentImpl::updatePageScaleFactorLimits()
     }
 }
 
-void WebDevToolsAgentImpl::getAllocatedObjects(HashSet<const void*>& set)
-{
-    class CountingVisitor : public WebDevToolsAgentClient::AllocatedObjectVisitor {
-    public:
-        CountingVisitor() : m_totalObjectsCount(0)
-        {
-        }
-
-        virtual bool visitObject(const void* ptr)
-        {
-            ++m_totalObjectsCount;
-            return true;
-        }
-        size_t totalObjectsCount() const
-        {
-            return m_totalObjectsCount;
-        }
-
-    private:
-        size_t m_totalObjectsCount;
-    };
-
-    CountingVisitor counter;
-    m_client->visitAllocatedObjects(&counter);
-
-    class PointerCollector : public WebDevToolsAgentClient::AllocatedObjectVisitor {
-    public:
-        explicit PointerCollector(size_t maxObjectsCount)
-            : m_maxObjectsCount(maxObjectsCount)
-            , m_index(0)
-            , m_success(true)
-            , m_pointers(new const void*[maxObjectsCount])
-        {
-        }
-        virtual ~PointerCollector()
-        {
-            delete[] m_pointers;
-        }
-        virtual bool visitObject(const void* ptr)
-        {
-            if (m_index == m_maxObjectsCount) {
-                m_success = false;
-                return false;
-            }
-            m_pointers[m_index++] = ptr;
-            return true;
-        }
-
-        bool success() const { return m_success; }
-
-        void copyTo(HashSet<const void*>& set)
-        {
-            for (size_t i = 0; i < m_index; i++)
-                set.add(m_pointers[i]);
-        }
-
-    private:
-        const size_t m_maxObjectsCount;
-        size_t m_index;
-        bool m_success;
-        const void** m_pointers;
-    };
-
-    // Double size to allow room for all objects that may have been allocated
-    // since we counted them.
-    size_t estimatedMaxObjectsCount = counter.totalObjectsCount() * 2;
-    while (true) {
-        PointerCollector collector(estimatedMaxObjectsCount);
-        m_client->visitAllocatedObjects(&collector);
-        if (collector.success()) {
-            collector.copyTo(set);
-            break;
-        }
-        estimatedMaxObjectsCount *= 2;
-    }
-}
-
-void WebDevToolsAgentImpl::dumpUncountedAllocatedObjects(const HashMap<const void*, size_t>& map)
-{
-    class InstrumentedObjectSizeProvider : public WebDevToolsAgentClient::InstrumentedObjectSizeProvider {
-    public:
-        InstrumentedObjectSizeProvider(const HashMap<const void*, size_t>& map) : m_map(map) { }
-        virtual size_t objectSize(const void* ptr) const
-        {
-            HashMap<const void*, size_t>::const_iterator i = m_map.find(ptr);
-            return i == m_map.end() ? 0 : i->value;
-        }
-
-    private:
-        const HashMap<const void*, size_t>& m_map;
-    };
-
-    InstrumentedObjectSizeProvider provider(map);
-    m_client->dumpUncountedAllocatedObjects(&provider);
-}
-
 void WebDevToolsAgentImpl::setTraceEventCallback(const String& categoryFilter, TraceEventCallback callback)
 {
     m_client->setTraceEventCallback(categoryFilter, callback);
@@ -663,7 +570,7 @@ void WebDevToolsAgentImpl::hideHighlight()
     m_webViewImpl->removePageOverlay(this);
 }
 
-void WebDevToolsAgentImpl::sendMessageToFrontend(PassRefPtr<blink::JSONObject> message)
+void WebDevToolsAgentImpl::sendMessageToFrontend(PassRefPtr<JSONObject> message)
 {
     m_frontendMessageQueue.append(message);
 }
@@ -678,6 +585,11 @@ void WebDevToolsAgentImpl::updateInspectorStateCookie(const String& state)
     m_client->saveAgentRuntimeState(state);
 }
 
+void WebDevToolsAgentImpl::resumeStartup()
+{
+    m_client->resumeStartup();
+}
+
 void WebDevToolsAgentImpl::setLayerTreeId(int layerTreeId)
 {
     m_layerTreeId = layerTreeId;