• 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 "Navigator.h"
25 
26 #include "CookieJar.h"
27 #include "Frame.h"
28 #include "FrameLoader.h"
29 #include "FrameLoaderClient.h"
30 #include "Geolocation.h"
31 #include "Language.h"
32 #include "MimeTypeArray.h"
33 #include "Page.h"
34 #include "PlatformString.h"
35 #include "PluginArray.h"
36 #include "PluginData.h"
37 #include "ScriptController.h"
38 #include "Settings.h"
39 
40 namespace WebCore {
41 
Navigator(Frame * frame)42 Navigator::Navigator(Frame* frame)
43     : m_frame(frame)
44 {
45 }
46 
~Navigator()47 Navigator::~Navigator()
48 {
49     disconnectFrame();
50 }
51 
disconnectFrame()52 void Navigator::disconnectFrame()
53 {
54     if (m_plugins) {
55         m_plugins->disconnectFrame();
56         m_plugins = 0;
57     }
58     if (m_mimeTypes) {
59         m_mimeTypes->disconnectFrame();
60         m_mimeTypes = 0;
61     }
62     if (m_geolocation) {
63         m_geolocation->disconnectFrame();
64         m_geolocation = 0;
65     }
66     m_frame = 0;
67 }
68 
69 // If this function returns true, we need to hide the substring "4." that would otherwise
70 // appear in the appVersion string. This is to avoid problems with old versions of a
71 // library called OpenCube QuickMenu, which as of this writing is still being used on
72 // sites such as nwa.com -- the library thinks Safari is Netscape 4 if we don't do this!
shouldHideFourDot(Frame * frame)73 static bool shouldHideFourDot(Frame* frame)
74 {
75     const String* sourceURL = frame->script()->sourceURL();
76     if (!sourceURL)
77         return false;
78     if (!(sourceURL->endsWith("/dqm_script.js") || sourceURL->endsWith("/dqm_loader.js") || sourceURL->endsWith("/tdqm_loader.js")))
79         return false;
80     Settings* settings = frame->settings();
81     if (!settings)
82         return false;
83     return settings->needsSiteSpecificQuirks();
84 }
85 
appVersion() const86 String Navigator::appVersion() const
87 {
88     if (!m_frame)
89         return String();
90     String appVersion = NavigatorBase::appVersion();
91     if (shouldHideFourDot(m_frame))
92         appVersion.replace("4.", "4_");
93     return appVersion;
94 }
95 
language() const96 String Navigator::language() const
97 {
98     return defaultLanguage();
99 }
100 
userAgent() const101 String Navigator::userAgent() const
102 {
103     if (!m_frame)
104         return String();
105 
106     // If the frame is already detached, FrameLoader::userAgent may malfunction, because it calls a client method
107     // that uses frame's WebView (at least, in Mac WebKit).
108     if (!m_frame->page())
109         return String();
110 
111     return m_frame->loader()->userAgent(m_frame->document()->url());
112 }
113 
plugins() const114 PluginArray* Navigator::plugins() const
115 {
116     if (!m_plugins)
117         m_plugins = PluginArray::create(m_frame);
118     return m_plugins.get();
119 }
120 
mimeTypes() const121 MimeTypeArray* Navigator::mimeTypes() const
122 {
123     if (!m_mimeTypes)
124         m_mimeTypes = MimeTypeArray::create(m_frame);
125     return m_mimeTypes.get();
126 }
127 
cookieEnabled() const128 bool Navigator::cookieEnabled() const
129 {
130     if (!m_frame)
131         return false;
132 
133     if (m_frame->page() && !m_frame->page()->cookieEnabled())
134         return false;
135 
136     return cookiesEnabled(m_frame->document());
137 }
138 
javaEnabled() const139 bool Navigator::javaEnabled() const
140 {
141     if (!m_frame || !m_frame->settings())
142         return false;
143 
144     return m_frame->settings()->isJavaEnabled();
145 }
146 
geolocation() const147 Geolocation* Navigator::geolocation() const
148 {
149     if (!m_geolocation)
150         m_geolocation = Geolocation::create(m_frame);
151     return m_geolocation.get();
152 }
153 
154 } // namespace WebCore
155