1/* 2 * Copyright (C) 2000 Harri Porten (porten@kde.org) 3 * Copyright (c) 2000 Daniel Molkentin (molkentin@kde.org) 4 * Copyright (c) 2000 Stefan Schimanski (schimmi@kde.org) 5 * Copyright (C) 2003, 2004, 2005, 2006 Apple Inc. 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 */ 22 23#include "config.h" 24#include "Navigator.h" 25 26#include "CookieJar.h" 27#include "DOMMimeTypeArray.h" 28#include "DOMPluginArray.h" 29#include "Document.h" 30#include "Frame.h" 31#include "FrameLoader.h" 32#include "FrameLoaderClient.h" 33#include "Geolocation.h" 34#include "Language.h" 35#include "Page.h" 36#include "PluginData.h" 37#include "ScriptController.h" 38#include "SecurityOrigin.h" 39#include "Settings.h" 40#include "StorageNamespace.h" 41#include <wtf/HashSet.h> 42#include <wtf/NumberOfCores.h> 43#include <wtf/StdLibExtras.h> 44 45using namespace WTF; 46 47namespace WebCore { 48 49Navigator::Navigator(Frame* frame) 50 : DOMWindowProperty(frame) 51{ 52} 53 54Navigator::~Navigator() 55{ 56} 57 58// If this function returns true, we need to hide the substring "4." that would otherwise 59// appear in the appVersion string. This is to avoid problems with old versions of a 60// library called OpenCube QuickMenu, which as of this writing is still being used on 61// sites such as nwa.com -- the library thinks Safari is Netscape 4 if we don't do this! 62static bool shouldHideFourDot(Frame* frame) 63{ 64 const String* sourceURL = frame->script().sourceURL(); 65 if (!sourceURL) 66 return false; 67 if (!(sourceURL->endsWith("/dqm_script.js") || sourceURL->endsWith("/dqm_loader.js") || sourceURL->endsWith("/tdqm_loader.js"))) 68 return false; 69 return frame->settings().needsSiteSpecificQuirks(); 70} 71 72String Navigator::appVersion() const 73{ 74 if (!m_frame) 75 return String(); 76 String appVersion = NavigatorBase::appVersion(); 77 if (shouldHideFourDot(m_frame)) 78 appVersion.replace("4.", "4_"); 79 return appVersion; 80} 81 82String Navigator::language() const 83{ 84 return defaultLanguage(); 85} 86 87String Navigator::userAgent() const 88{ 89 if (!m_frame) 90 return String(); 91 92 // If the frame is already detached, FrameLoader::userAgent may malfunction, because it calls a client method 93 // that uses frame's WebView (at least, in Mac WebKit). 94 if (!m_frame->page()) 95 return String(); 96 97 return m_frame->loader().userAgent(m_frame->document()->url()); 98} 99 100DOMPluginArray* Navigator::plugins() const 101{ 102 if (!m_plugins) 103 m_plugins = DOMPluginArray::create(m_frame); 104 return m_plugins.get(); 105} 106 107DOMMimeTypeArray* Navigator::mimeTypes() const 108{ 109 if (!m_mimeTypes) 110 m_mimeTypes = DOMMimeTypeArray::create(m_frame); 111 return m_mimeTypes.get(); 112} 113 114bool Navigator::cookieEnabled() const 115{ 116 if (!m_frame) 117 return false; 118 119 if (m_frame->page() && !m_frame->page()->settings().cookieEnabled()) 120 return false; 121 122 return cookiesEnabled(m_frame->document()); 123} 124 125bool Navigator::javaEnabled() const 126{ 127 if (!m_frame) 128 return false; 129 130 if (!m_frame->settings().isJavaEnabled()) 131 return false; 132 if (m_frame->document()->securityOrigin()->isLocal() && !m_frame->settings().isJavaEnabledForLocalFiles()) 133 return false; 134 135 return true; 136} 137 138#if defined(ENABLE_NAVIGATOR_HWCONCURRENCY) 139int Navigator::hardwareConcurrency() const 140{ 141 // Enforce a maximum for the number of cores reported to mitigate 142 // fingerprinting for the minority of machines with large numbers of cores. 143 // If machines with more than 8 cores become commonplace, we should bump this number. 144 // see https://bugs.webkit.org/show_bug.cgi?id=132588 for the 145 // rationale behind this decision. 146#if PLATFORM(IOS) 147 const int maxCoresToReport = 2; 148#else 149 const int maxCoresToReport = 8; 150#endif 151 int hardwareConcurrency = numberOfProcessorCores(); 152 153 if (hardwareConcurrency > maxCoresToReport) 154 return maxCoresToReport; 155 156 return hardwareConcurrency; 157} 158#endif 159 160#if PLATFORM(IOS) 161bool Navigator::standalone() const 162{ 163 return m_frame && m_frame->settings().standalone(); 164} 165#endif 166 167void Navigator::getStorageUpdates() 168{ 169 // FIXME: Remove this method or rename to yieldForStorageUpdates. 170} 171 172} // namespace WebCore 173