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 Computer, 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/StdLibExtras.h> 43 44namespace WebCore { 45 46Navigator::Navigator(Frame* frame) 47 : DOMWindowProperty(frame) 48{ 49} 50 51Navigator::~Navigator() 52{ 53} 54 55// If this function returns true, we need to hide the substring "4." that would otherwise 56// appear in the appVersion string. This is to avoid problems with old versions of a 57// library called OpenCube QuickMenu, which as of this writing is still being used on 58// sites such as nwa.com -- the library thinks Safari is Netscape 4 if we don't do this! 59static bool shouldHideFourDot(Frame* frame) 60{ 61 const String* sourceURL = frame->script()->sourceURL(); 62 if (!sourceURL) 63 return false; 64 if (!(sourceURL->endsWith("/dqm_script.js") || sourceURL->endsWith("/dqm_loader.js") || sourceURL->endsWith("/tdqm_loader.js"))) 65 return false; 66 Settings* settings = frame->settings(); 67 if (!settings) 68 return false; 69 return 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 || !m_frame->settings()) 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 138void Navigator::getStorageUpdates() 139{ 140 // FIXME: Remove this method or rename to yieldForStorageUpdates. 141} 142 143} // namespace WebCore 144