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 "Navigator.h"
27 #include "CookieJar.h"
28 #include "DOMMimeTypeArray.h"
29 #include "DOMPluginArray.h"
30 #include "ExceptionCode.h"
32 #include "FrameLoader.h"
33 #include "FrameLoaderClient.h"
34 #include "Geolocation.h"
38 #include "PageGroup.h"
39 #include "PlatformString.h"
40 #include "PluginData.h"
41 #include "ScriptController.h"
43 #include "StorageNamespace.h"
44 #include <wtf/StdLibExtras.h>
47 #include "ApplicationInstalledCallback.h"
48 #include "Connection.h"
49 #include "PackageNotifier.h"
54 Navigator::Navigator(Frame* frame)
59 Navigator::~Navigator()
64 void Navigator::disconnectFrame()
67 m_plugins->disconnectFrame();
71 m_mimeTypes->disconnectFrame();
75 m_geolocation->disconnectFrame();
81 // If this function returns true, we need to hide the substring "4." that would otherwise
82 // appear in the appVersion string. This is to avoid problems with old versions of a
83 // library called OpenCube QuickMenu, which as of this writing is still being used on
84 // sites such as nwa.com -- the library thinks Safari is Netscape 4 if we don't do this!
85 static bool shouldHideFourDot(Frame* frame)
87 const String* sourceURL = frame->script()->sourceURL();
90 if (!(sourceURL->endsWith("/dqm_script.js") || sourceURL->endsWith("/dqm_loader.js") || sourceURL->endsWith("/tdqm_loader.js")))
92 Settings* settings = frame->settings();
95 return settings->needsSiteSpecificQuirks();
98 String Navigator::appVersion() const
102 String appVersion = NavigatorBase::appVersion();
103 if (shouldHideFourDot(m_frame))
104 appVersion.replace("4.", "4_");
108 String Navigator::language() const
110 return defaultLanguage();
113 String Navigator::userAgent() const
118 // If the frame is already detached, FrameLoader::userAgent may malfunction, because it calls a client method
119 // that uses frame's WebView (at least, in Mac WebKit).
120 if (!m_frame->page())
123 return m_frame->loader()->userAgent(m_frame->document()->url());
126 DOMPluginArray* Navigator::plugins() const
129 m_plugins = DOMPluginArray::create(m_frame);
130 return m_plugins.get();
133 DOMMimeTypeArray* Navigator::mimeTypes() const
136 m_mimeTypes = DOMMimeTypeArray::create(m_frame);
137 return m_mimeTypes.get();
140 bool Navigator::cookieEnabled() const
145 if (m_frame->page() && !m_frame->page()->cookieEnabled())
148 return cookiesEnabled(m_frame->document());
151 bool Navigator::javaEnabled() const
153 if (!m_frame || !m_frame->settings())
156 return m_frame->settings()->isJavaEnabled();
159 Geolocation* Navigator::geolocation() const
162 m_geolocation = Geolocation::create(m_frame);
163 return m_geolocation.get();
166 #if PLATFORM(ANDROID)
167 Connection* Navigator::connection() const
170 m_connection = Connection::create();
171 return m_connection.get();
175 #if PLATFORM(ANDROID) && ENABLE(APPLICATION_INSTALLED)
177 bool Navigator::isApplicationInstalled(const String& name, PassRefPtr<ApplicationInstalledCallback> callback)
179 if (m_applicationInstalledCallback)
182 m_applicationInstalledCallback = callback;
183 m_applicationNameQuery = name;
185 packageNotifier().requestPackageResult();
190 void Navigator::onPackageResult()
192 if (m_applicationInstalledCallback) {
193 m_applicationInstalledCallback->handleEvent(packageNotifier().isPackageInstalled(m_applicationNameQuery));
194 m_applicationInstalledCallback = 0;
199 #if ENABLE(DOM_STORAGE)
200 void Navigator::getStorageUpdates()
205 Page* page = m_frame->page();
209 StorageNamespace* localStorage = page->group().localStorage();
211 localStorage->unlock();
215 #if ENABLE(REGISTER_PROTOCOL_HANDLER)
216 static bool verifyCustomHandlerURL(const String& baseURL, const String& url, ExceptionCode& ec)
218 // The specification requires that it is a SYNTAX_ERR if the "%s" token is
220 static const char token[] = "%s";
221 int index = url.find(token);
227 // It is also a SYNTAX_ERR if the custom handler URL, as created by removing
228 // the "%s" token and prepending the base url, does not resolve.
230 newURL.remove(index, WTF_ARRAY_LENGTH(token) - 1);
232 KURL base(ParsedURLString, baseURL);
233 KURL kurl(base, newURL);
235 if (kurl.isEmpty() || !kurl.isValid()) {
243 static bool verifyProtocolHandlerScheme(const String& scheme, ExceptionCode& ec)
245 // It is a SECURITY_ERR for these schemes to be handled by a custom handler.
246 if (equalIgnoringCase(scheme, "http") || equalIgnoringCase(scheme, "https") || equalIgnoringCase(scheme, "file")) {
253 void Navigator::registerProtocolHandler(const String& scheme, const String& url, const String& title, ExceptionCode& ec)
255 if (!verifyProtocolHandlerScheme(scheme, ec))
261 Document* document = m_frame->document();
265 String baseURL = document->baseURL().baseAsString();
267 if (!verifyCustomHandlerURL(baseURL, url, ec))
270 Page* page = m_frame->page();
274 page->chrome()->registerProtocolHandler(scheme, baseURL, url, m_frame->displayStringModifiedByEncoding(title));
278 } // namespace WebCore