Navigator.cpp 4.07 KB
Newer Older
1 2 3 4 5
/*
 *  Copyright (C) 2000 Harri Porten (porten@kde.org)
 *  Copyright (c) 2000 Daniel Molkentin (molkentin@kde.org)
 *  Copyright (c) 2000 Stefan Schimanski (schimmi@kde.org)
 *  Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
6
 *  Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "config.h"
#include "Navigator.h"

#include "CookieJar.h"
27 28
#include "DOMMimeTypeArray.h"
#include "DOMPluginArray.h"
29
#include "Document.h"
30 31 32
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameLoaderClient.h"
ddkilzer@apple.com's avatar
ddkilzer@apple.com committed
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 44 45 46

namespace WebCore {

Navigator::Navigator(Frame* frame)
47
    : DOMWindowProperty(frame)
48 49 50 51 52 53 54
{
}

Navigator::~Navigator()
{
}

55 56
// If this function returns true, we need to hide the substring "4." that would otherwise
// 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 59 60
// sites such as nwa.com -- the library thinks Safari is Netscape 4 if we don't do this!
static bool shouldHideFourDot(Frame* frame)
{
61
    const String* sourceURL = frame->script().sourceURL();
62 63
    if (!sourceURL)
        return false;
mitz@apple.com's avatar
mitz@apple.com committed
64
    if (!(sourceURL->endsWith("/dqm_script.js") || sourceURL->endsWith("/dqm_loader.js") || sourceURL->endsWith("/tdqm_loader.js")))
65
        return false;
66
    return frame->settings().needsSiteSpecificQuirks();
67 68
}

69 70 71 72
String Navigator::appVersion() const
{
    if (!m_frame)
        return String();
ap@webkit.org's avatar
ap@webkit.org committed
73
    String appVersion = NavigatorBase::appVersion();
74 75 76
    if (shouldHideFourDot(m_frame))
        appVersion.replace("4.", "4_");
    return appVersion;
77 78 79 80 81 82 83 84 85 86 87
}

String Navigator::language() const
{
    return defaultLanguage();
}

String Navigator::userAgent() const
{
    if (!m_frame)
        return String();
88 89 90 91 92 93
        
    // If the frame is already detached, FrameLoader::userAgent may malfunction, because it calls a client method
    // that uses frame's WebView (at least, in Mac WebKit).
    if (!m_frame->page())
        return String();
        
94
    return m_frame->loader().userAgent(m_frame->document()->url());
95 96
}

97
DOMPluginArray* Navigator::plugins() const
98 99
{
    if (!m_plugins)
100
        m_plugins = DOMPluginArray::create(m_frame);
101 102 103
    return m_plugins.get();
}

104
DOMMimeTypeArray* Navigator::mimeTypes() const
105 106
{
    if (!m_mimeTypes)
107
        m_mimeTypes = DOMMimeTypeArray::create(m_frame);
108 109 110 111 112
    return m_mimeTypes.get();
}

bool Navigator::cookieEnabled() const
{
113 114
    if (!m_frame)
        return false;
115

116
    if (m_frame->page() && !m_frame->page()->settings().cookieEnabled())
mitz@apple.com's avatar
mitz@apple.com committed
117 118
        return false;

119 120 121 122 123
    return cookiesEnabled(m_frame->document());
}

bool Navigator::javaEnabled() const
{
124
    if (!m_frame)
125
        return false;
126

127
    if (!m_frame->settings().isJavaEnabled())
128
        return false;
129
    if (m_frame->document()->securityOrigin()->isLocal() && !m_frame->settings().isJavaEnabledForLocalFiles())
130 131 132
        return false;

    return true;
133 134
}

135 136 137 138 139 140 141
#if PLATFORM(IOS)
bool Navigator::standalone() const
{
    return m_frame && m_frame->settings().standalone();
}
#endif

142 143
void Navigator::getStorageUpdates()
{
144
    // FIXME: Remove this method or rename to yieldForStorageUpdates.
145 146
}

147
} // namespace WebCore