This source file includes following definitions.
- dispatch
- stop
- schedule
- run
- deliver
- windowObjectCleared
- sendMessageToBackend
#include "config.h"
#include "InspectorFrontendClientLocal.h"
#include "bindings/v8/ScriptObject.h"
#include "bindings/v8/ScriptState.h"
#include "core/inspector/InspectorController.h"
#include "core/inspector/InspectorFrontendHost.h"
#include "core/page/Page.h"
#include "core/frame/Settings.h"
#include "platform/Timer.h"
#include "public/platform/Platform.h"
#include "public/platform/WebThread.h"
#include "wtf/Deque.h"
namespace WebCore {
class InspectorBackendMessageQueue : public RefCounted<InspectorBackendMessageQueue> {
WTF_MAKE_FAST_ALLOCATED;
public:
explicit InspectorBackendMessageQueue(InspectorController& inspectorController)
: m_inspectorController(&inspectorController)
{
}
void dispatch(const String& message)
{
ASSERT(m_inspectorController);
m_messages.append(message);
schedule();
}
void stop()
{
m_inspectorController = 0;
m_messages.clear();
}
private:
void schedule()
{
class TaskImpl : public blink::WebThread::Task {
public:
RefPtr<InspectorBackendMessageQueue> owner;
virtual void run()
{
owner->deliver();
}
};
TaskImpl* taskImpl = new TaskImpl;
taskImpl->owner = this;
blink::Platform::current()->currentThread()->postTask(taskImpl);
}
void deliver()
{
if (!m_inspectorController)
return;
if (!m_messages.isEmpty()) {
schedule();
m_inspectorController->dispatchMessageFromFrontend(m_messages.takeFirst());
}
}
InspectorController* m_inspectorController;
Deque<String> m_messages;
};
InspectorFrontendClientLocal::InspectorFrontendClientLocal(InspectorController& inspectorController, Page* frontendPage)
: m_frontendPage(frontendPage)
{
m_frontendPage->settings().setAllowFileAccessFromFileURLs(true);
m_messageQueue = adoptRef(new InspectorBackendMessageQueue(inspectorController));
}
InspectorFrontendClientLocal::~InspectorFrontendClientLocal()
{
m_messageQueue->stop();
if (m_frontendHost)
m_frontendHost->disconnectClient();
m_frontendPage = 0;
}
void InspectorFrontendClientLocal::windowObjectCleared()
{
if (m_frontendHost)
m_frontendHost->disconnectClient();
ScriptState* frontendScriptState = mainWorldScriptState(m_frontendPage->mainFrame());
m_frontendHost = InspectorFrontendHost::create(this, m_frontendPage);
ScriptGlobalObject::set(frontendScriptState, "InspectorFrontendHost", m_frontendHost.get());
}
void InspectorFrontendClientLocal::sendMessageToBackend(const String& message)
{
m_messageQueue->dispatch(message);
}
}