• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "core/frame/Navigator.h"
25 
26 #include "bindings/v8/ScriptController.h"
27 #include "core/dom/Document.h"
28 #include "core/frame/NavigatorID.h"
29 #include "core/loader/CookieJar.h"
30 #include "core/loader/FrameLoader.h"
31 #include "core/frame/Frame.h"
32 #include "core/frame/Settings.h"
33 #include "core/plugins/DOMMimeTypeArray.h"
34 #include "core/plugins/DOMPluginArray.h"
35 #include "platform/Language.h"
36 
37 #ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
38 #define WEBCORE_NAVIGATOR_PRODUCT_SUB "20030107"
39 #endif // ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
40 
41 #ifndef WEBCORE_NAVIGATOR_VENDOR
42 #define WEBCORE_NAVIGATOR_VENDOR "Google Inc."
43 #endif // ifndef WEBCORE_NAVIGATOR_VENDOR
44 
45 #ifndef WEBCORE_NAVIGATOR_VENDOR_SUB
46 #define WEBCORE_NAVIGATOR_VENDOR_SUB ""
47 #endif // ifndef WEBCORE_NAVIGATOR_VENDOR_SUB
48 
49 namespace WebCore {
50 
Navigator(Frame * frame)51 Navigator::Navigator(Frame* frame)
52     : DOMWindowProperty(frame)
53 {
54     ScriptWrappable::init(this);
55 }
56 
~Navigator()57 Navigator::~Navigator()
58 {
59 }
60 
61 // If this function returns true, we need to hide the substring "4." that would otherwise
62 // appear in the appVersion string. This is to avoid problems with old versions of a
63 // library called OpenCube QuickMenu, which as of this writing is still being used on
64 // sites such as nwa.com -- the library thinks Safari is Netscape 4 if we don't do this!
shouldHideFourDot(Frame * frame)65 static bool shouldHideFourDot(Frame* frame)
66 {
67     const String* sourceURL = frame->script().sourceURL();
68     if (!sourceURL)
69         return false;
70     if (!(sourceURL->endsWith("/dqm_script.js") || sourceURL->endsWith("/dqm_loader.js") || sourceURL->endsWith("/tdqm_loader.js")))
71         return false;
72     Settings* settings = frame->settings();
73     if (!settings)
74         return false;
75     return settings->needsSiteSpecificQuirks();
76 }
77 
appVersion() const78 String Navigator::appVersion() const
79 {
80     if (!m_frame)
81         return String();
82     String appVersion = NavigatorID::appVersion(this);
83     if (shouldHideFourDot(m_frame))
84         appVersion.replace("4.", "4_");
85     return appVersion;
86 }
87 
language() const88 String Navigator::language() const
89 {
90     return defaultLanguage();
91 }
92 
productSub() const93 String Navigator::productSub() const
94 {
95     return WEBCORE_NAVIGATOR_PRODUCT_SUB;
96 }
97 
vendor() const98 String Navigator::vendor() const
99 {
100     return WEBCORE_NAVIGATOR_VENDOR;
101 }
102 
vendorSub() const103 String Navigator::vendorSub() const
104 {
105     return WEBCORE_NAVIGATOR_VENDOR_SUB;
106 }
107 
userAgent() const108 String Navigator::userAgent() const
109 {
110     // If the frame is already detached it no longer has a meaningful useragent.
111     if (!m_frame || !m_frame->page())
112         return String();
113 
114     return m_frame->loader().userAgent(m_frame->document()->url());
115 }
116 
plugins() const117 DOMPluginArray* Navigator::plugins() const
118 {
119     if (!m_plugins)
120         m_plugins = DOMPluginArray::create(m_frame);
121     return m_plugins.get();
122 }
123 
mimeTypes() const124 DOMMimeTypeArray* Navigator::mimeTypes() const
125 {
126     if (!m_mimeTypes)
127         m_mimeTypes = DOMMimeTypeArray::create(m_frame);
128     return m_mimeTypes.get();
129 }
130 
cookieEnabled() const131 bool Navigator::cookieEnabled() const
132 {
133     if (!m_frame)
134         return false;
135 
136     Settings* settings = m_frame->settings();
137     if (!settings || !settings->cookieEnabled())
138         return false;
139 
140     return cookiesEnabled(m_frame->document());
141 }
142 
javaEnabled() const143 bool Navigator::javaEnabled() const
144 {
145     if (!m_frame || !m_frame->settings())
146         return false;
147 
148     if (!m_frame->settings()->javaEnabled())
149         return false;
150 
151     return true;
152 }
153 
getStorageUpdates()154 void Navigator::getStorageUpdates()
155 {
156     // FIXME: Remove this method or rename to yieldForStorageUpdates.
157 }
158 
159 } // namespace WebCore
160