Home | History | Annotate | Download | only in page
      1 /*
      2  *  Copyright (C) 2000 Harri Porten (porten (at) kde.org)
      3  *  Copyright (c) 2000 Daniel Molkentin (molkentin (at) kde.org)
      4  *  Copyright (c) 2000 Stefan Schimanski (schimmi (at) 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/page/Navigator.h"
     25 
     26 #include "bindings/v8/ScriptController.h"
     27 #include "core/dom/Document.h"
     28 #include "core/loader/CookieJar.h"
     29 #include "core/loader/FrameLoader.h"
     30 #include "core/page/Frame.h"
     31 #include "core/page/Page.h"
     32 #include "core/page/Settings.h"
     33 #include "core/platform/Language.h"
     34 #include "core/plugins/DOMMimeTypeArray.h"
     35 #include "core/plugins/DOMPluginArray.h"
     36 
     37 namespace WebCore {
     38 
     39 Navigator::Navigator(Frame* frame)
     40     : DOMWindowProperty(frame)
     41 {
     42     ScriptWrappable::init(this);
     43 }
     44 
     45 Navigator::~Navigator()
     46 {
     47 }
     48 
     49 // If this function returns true, we need to hide the substring "4." that would otherwise
     50 // appear in the appVersion string. This is to avoid problems with old versions of a
     51 // library called OpenCube QuickMenu, which as of this writing is still being used on
     52 // sites such as nwa.com -- the library thinks Safari is Netscape 4 if we don't do this!
     53 static bool shouldHideFourDot(Frame* frame)
     54 {
     55     const String* sourceURL = frame->script()->sourceURL();
     56     if (!sourceURL)
     57         return false;
     58     if (!(sourceURL->endsWith("/dqm_script.js") || sourceURL->endsWith("/dqm_loader.js") || sourceURL->endsWith("/tdqm_loader.js")))
     59         return false;
     60     Settings* settings = frame->settings();
     61     if (!settings)
     62         return false;
     63     return settings->needsSiteSpecificQuirks();
     64 }
     65 
     66 String Navigator::appVersion() const
     67 {
     68     if (!m_frame)
     69         return String();
     70     String appVersion = NavigatorBase::appVersion();
     71     if (shouldHideFourDot(m_frame))
     72         appVersion.replace("4.", "4_");
     73     return appVersion;
     74 }
     75 
     76 String Navigator::language() const
     77 {
     78     return defaultLanguage();
     79 }
     80 
     81 String Navigator::userAgent() const
     82 {
     83     if (!m_frame)
     84         return String();
     85 
     86     // If the frame is already detached, FrameLoader::userAgent may malfunction, because it calls a client method
     87     // that uses frame's WebView (at least, in Mac WebKit).
     88     if (!m_frame->page())
     89         return String();
     90 
     91     return m_frame->loader()->userAgent(m_frame->document()->url());
     92 }
     93 
     94 DOMPluginArray* Navigator::plugins() const
     95 {
     96     if (!m_plugins)
     97         m_plugins = DOMPluginArray::create(m_frame);
     98     return m_plugins.get();
     99 }
    100 
    101 DOMMimeTypeArray* Navigator::mimeTypes() const
    102 {
    103     if (!m_mimeTypes)
    104         m_mimeTypes = DOMMimeTypeArray::create(m_frame);
    105     return m_mimeTypes.get();
    106 }
    107 
    108 bool Navigator::cookieEnabled() const
    109 {
    110     if (!m_frame)
    111         return false;
    112 
    113     if (m_frame->page() && !m_frame->page()->settings()->cookieEnabled())
    114         return false;
    115 
    116     return cookiesEnabled(m_frame->document());
    117 }
    118 
    119 bool Navigator::javaEnabled() const
    120 {
    121     if (!m_frame || !m_frame->settings())
    122         return false;
    123 
    124     if (!m_frame->settings()->isJavaEnabled())
    125         return false;
    126 
    127     return true;
    128 }
    129 
    130 void Navigator::getStorageUpdates()
    131 {
    132     // FIXME: Remove this method or rename to yieldForStorageUpdates.
    133 }
    134 
    135 } // namespace WebCore
    136