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)
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.
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.
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
24 #include "core/frame/Navigator.h"
26 #include "bindings/core/v8/ScriptController.h"
27 #include "core/dom/Document.h"
28 #include "core/frame/FrameHost.h"
29 #include "core/frame/LocalFrame.h"
30 #include "core/frame/NavigatorID.h"
31 #include "core/frame/Settings.h"
32 #include "core/loader/CookieJar.h"
33 #include "core/loader/FrameLoader.h"
34 #include "core/page/Chrome.h"
35 #include "core/page/ChromeClient.h"
36 #include "core/plugins/DOMMimeTypeArray.h"
37 #include "core/plugins/DOMPluginArray.h"
38 #include "platform/Language.h"
40 #ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
41 #define WEBCORE_NAVIGATOR_PRODUCT_SUB "20030107"
42 #endif // ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
44 #ifndef WEBCORE_NAVIGATOR_VENDOR
45 #define WEBCORE_NAVIGATOR_VENDOR "Google Inc."
46 #endif // ifndef WEBCORE_NAVIGATOR_VENDOR
48 #ifndef WEBCORE_NAVIGATOR_VENDOR_SUB
49 #define WEBCORE_NAVIGATOR_VENDOR_SUB ""
50 #endif // ifndef WEBCORE_NAVIGATOR_VENDOR_SUB
54 Navigator::Navigator(LocalFrame* frame)
55 : DOMWindowProperty(frame)
59 Navigator::~Navigator()
63 String Navigator::productSub() const
65 return WEBCORE_NAVIGATOR_PRODUCT_SUB;
68 String Navigator::vendor() const
70 return WEBCORE_NAVIGATOR_VENDOR;
73 String Navigator::vendorSub() const
75 return WEBCORE_NAVIGATOR_VENDOR_SUB;
78 String Navigator::userAgent() const
80 // If the frame is already detached it no longer has a meaningful useragent.
81 if (!m_frame || !m_frame->page())
84 return m_frame->loader().userAgent(m_frame->document()->url());
87 DOMPluginArray* Navigator::plugins() const
90 m_plugins = DOMPluginArray::create(m_frame);
91 return m_plugins.get();
94 DOMMimeTypeArray* Navigator::mimeTypes() const
97 m_mimeTypes = DOMMimeTypeArray::create(m_frame);
98 return m_mimeTypes.get();
101 bool Navigator::cookieEnabled() const
106 Settings* settings = m_frame->settings();
107 if (!settings || !settings->cookieEnabled())
110 return cookiesEnabled(m_frame->document());
113 bool Navigator::javaEnabled() const
115 if (!m_frame || !m_frame->settings())
118 if (!m_frame->settings()->javaEnabled())
124 void Navigator::getStorageUpdates()
126 // FIXME: Remove this method or rename to yieldForStorageUpdates.
129 Vector<String> Navigator::languages()
131 Vector<String> languages;
133 if (!m_frame || !m_frame->host()) {
134 languages.append(defaultLanguage());
138 String acceptLanguages = m_frame->host()->chrome().client().acceptLanguages();
139 acceptLanguages.split(',', languages);
141 // Sanitizing tokens. We could do that more extensively but we should assume
142 // that the accept languages are already sane and support BCP47. It is
143 // likely a waste of time to make sure the tokens matches that spec here.
144 for (size_t i = 0; i < languages.size(); ++i) {
145 String& token = languages[i];
146 token = token.stripWhiteSpace();
147 if (token.length() >= 3 && token[2] == '_')
148 token.replace(2, 1, "-");
154 void Navigator::trace(Visitor* visitor)
157 visitor->trace(m_plugins);
158 visitor->trace(m_mimeTypes);
159 HeapSupplementable<Navigator>::trace(visitor);
161 DOMWindowProperty::trace(visitor);