WebNetworkInfoManager.cpp [plain text]
#include "config.h"
#include "WebNetworkInfoManager.h"
#if ENABLE(NETWORK_INFO)
#include "WebNetworkInfoManagerMessages.h"
#include "WebNetworkInfoManagerProxyMessages.h"
#include "WebPage.h"
#include "WebProcess.h"
#include <WebCore/NetworkInfo.h>
#include <WebCore/NetworkInfoController.h>
#include <limits.h>
using namespace WebCore;
namespace WebKit {
const char* WebNetworkInfoManager::supplementName()
{
return "WebNetworkInfoManager";
}
WebNetworkInfoManager::WebNetworkInfoManager(WebProcess* process)
: m_process(process)
{
m_process->addMessageReceiver(Messages::WebNetworkInfoManager::messageReceiverName(), this);
}
WebNetworkInfoManager::~WebNetworkInfoManager()
{
}
void WebNetworkInfoManager::registerWebPage(WebPage* page)
{
bool wasEmpty = m_pageSet.isEmpty();
m_pageSet.add(page);
if (wasEmpty)
m_process->parentProcessConnection()->send(Messages::WebNetworkInfoManagerProxy::StartUpdating(), 0);
}
void WebNetworkInfoManager::unregisterWebPage(WebPage* page)
{
m_pageSet.remove(page);
if (m_pageSet.isEmpty())
m_process->parentProcessConnection()->send(Messages::WebNetworkInfoManagerProxy::StopUpdating(), 0);
}
double WebNetworkInfoManager::bandwidth(WebPage* page) const
{
double bandwidth = std::numeric_limits<double>::infinity();
m_process->parentProcessConnection()->sendSync(Messages::WebNetworkInfoManagerProxy::GetBandwidth(), Messages::WebNetworkInfoManagerProxy::GetBandwidth::Reply(bandwidth), page->pageID());
return bandwidth;
}
bool WebNetworkInfoManager::metered(WebPage* page) const
{
bool metered = false;
m_process->parentProcessConnection()->sendSync(Messages::WebNetworkInfoManagerProxy::IsMetered(), Messages::WebNetworkInfoManagerProxy::IsMetered::Reply(metered), page->pageID());
return metered;
}
void WebNetworkInfoManager::didChangeNetworkInformation(const AtomicString& eventType, const WebNetworkInfo::Data& data)
{
RefPtr<NetworkInfo> networkInformation = NetworkInfo::create(data.bandwidth, data.metered);
HashSet<WebPage*>::const_iterator it = m_pageSet.begin();
HashSet<WebPage*>::const_iterator end = m_pageSet.end();
for (; it != end; ++it) {
WebPage* page = *it;
if (page->corePage())
NetworkInfoController::from(page->corePage())->didChangeNetworkInformation(eventType, networkInformation.get());
}
}
}
#endif // ENABLE(NETWORK_INFO)