#include "config.h"
#include "Navigator.h"
#include "CookieJar.h"
#include "DOMMimeTypeArray.h"
#include "DOMPluginArray.h"
#include "Document.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameLoaderClient.h"
#include "Geolocation.h"
#include "Language.h"
#include "Page.h"
#include "PluginData.h"
#include "ScriptController.h"
#include "SecurityOrigin.h"
#include "Settings.h"
#include <wtf/HashSet.h>
#include <wtf/NumberOfCores.h>
#include <wtf/StdLibExtras.h>
using namespace WTF;
namespace WebCore {
Navigator::Navigator(Frame* frame)
: DOMWindowProperty(frame)
{
}
Navigator::~Navigator()
{
}
static bool shouldHideFourDot(Frame* frame)
{
const String* sourceURL = frame->script().sourceURL();
if (!sourceURL)
return false;
if (!(sourceURL->endsWith("/dqm_script.js") || sourceURL->endsWith("/dqm_loader.js") || sourceURL->endsWith("/tdqm_loader.js")))
return false;
return frame->settings().needsSiteSpecificQuirks();
}
String Navigator::appVersion() const
{
if (!m_frame)
return String();
String appVersion = NavigatorBase::appVersion();
if (shouldHideFourDot(m_frame))
appVersion.replace("4.", "4_");
return appVersion;
}
String Navigator::language() const
{
return defaultLanguage();
}
String Navigator::userAgent() const
{
if (!m_frame)
return String();
if (!m_frame->page())
return String();
return m_frame->loader().userAgent(m_frame->document()->url());
}
DOMPluginArray* Navigator::plugins() const
{
if (!m_plugins)
m_plugins = DOMPluginArray::create(m_frame);
return m_plugins.get();
}
DOMMimeTypeArray* Navigator::mimeTypes() const
{
if (!m_mimeTypes)
m_mimeTypes = DOMMimeTypeArray::create(m_frame);
return m_mimeTypes.get();
}
bool Navigator::cookieEnabled() const
{
if (!m_frame)
return false;
if (m_frame->page() && !m_frame->page()->settings().cookieEnabled())
return false;
return cookiesEnabled(m_frame->document());
}
bool Navigator::javaEnabled() const
{
if (!m_frame)
return false;
if (!m_frame->settings().isJavaEnabled())
return false;
if (m_frame->document()->securityOrigin()->isLocal() && !m_frame->settings().isJavaEnabledForLocalFiles())
return false;
return true;
}
#if defined(ENABLE_NAVIGATOR_HWCONCURRENCY)
int Navigator::hardwareConcurrency() const
{
#if PLATFORM(IOS)
const int maxCoresToReport = 2;
#else
const int maxCoresToReport = 8;
#endif
int hardwareConcurrency = numberOfProcessorCores();
if (hardwareConcurrency > maxCoresToReport)
return maxCoresToReport;
return hardwareConcurrency;
}
#endif
#if PLATFORM(IOS)
bool Navigator::standalone() const
{
return m_frame && m_frame->settings().standalone();
}
#endif
void Navigator::getStorageUpdates()
{
}
}