Home | History | Annotate | Download | only in frame
      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/frame/Navigator.h"
     25 
     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"
     39 
     40 #ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
     41 #define WEBCORE_NAVIGATOR_PRODUCT_SUB "20030107"
     42 #endif // ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
     43 
     44 #ifndef WEBCORE_NAVIGATOR_VENDOR
     45 #define WEBCORE_NAVIGATOR_VENDOR "Google Inc."
     46 #endif // ifndef WEBCORE_NAVIGATOR_VENDOR
     47 
     48 #ifndef WEBCORE_NAVIGATOR_VENDOR_SUB
     49 #define WEBCORE_NAVIGATOR_VENDOR_SUB ""
     50 #endif // ifndef WEBCORE_NAVIGATOR_VENDOR_SUB
     51 
     52 namespace blink {
     53 
     54 Navigator::Navigator(LocalFrame* frame)
     55     : DOMWindowProperty(frame)
     56 {
     57 }
     58 
     59 Navigator::~Navigator()
     60 {
     61 }
     62 
     63 String Navigator::productSub() const
     64 {
     65     return WEBCORE_NAVIGATOR_PRODUCT_SUB;
     66 }
     67 
     68 String Navigator::vendor() const
     69 {
     70     return WEBCORE_NAVIGATOR_VENDOR;
     71 }
     72 
     73 String Navigator::vendorSub() const
     74 {
     75     return WEBCORE_NAVIGATOR_VENDOR_SUB;
     76 }
     77 
     78 String Navigator::userAgent() const
     79 {
     80     // If the frame is already detached it no longer has a meaningful useragent.
     81     if (!m_frame || !m_frame->page())
     82         return String();
     83 
     84     return m_frame->loader().userAgent(m_frame->document()->url());
     85 }
     86 
     87 DOMPluginArray* Navigator::plugins() const
     88 {
     89     if (!m_plugins)
     90         m_plugins = DOMPluginArray::create(m_frame);
     91     return m_plugins.get();
     92 }
     93 
     94 DOMMimeTypeArray* Navigator::mimeTypes() const
     95 {
     96     if (!m_mimeTypes)
     97         m_mimeTypes = DOMMimeTypeArray::create(m_frame);
     98     return m_mimeTypes.get();
     99 }
    100 
    101 bool Navigator::cookieEnabled() const
    102 {
    103     if (!m_frame)
    104         return false;
    105 
    106     Settings* settings = m_frame->settings();
    107     if (!settings || !settings->cookieEnabled())
    108         return false;
    109 
    110     return cookiesEnabled(m_frame->document());
    111 }
    112 
    113 bool Navigator::javaEnabled() const
    114 {
    115     if (!m_frame || !m_frame->settings())
    116         return false;
    117 
    118     if (!m_frame->settings()->javaEnabled())
    119         return false;
    120 
    121     return true;
    122 }
    123 
    124 void Navigator::getStorageUpdates()
    125 {
    126     // FIXME: Remove this method or rename to yieldForStorageUpdates.
    127 }
    128 
    129 Vector<String> Navigator::languages()
    130 {
    131     Vector<String> languages;
    132 
    133     if (!m_frame || !m_frame->host()) {
    134         languages.append(defaultLanguage());
    135         return languages;
    136     }
    137 
    138     String acceptLanguages = m_frame->host()->chrome().client().acceptLanguages();
    139     acceptLanguages.split(',', languages);
    140 
    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, "-");
    149     }
    150 
    151     return languages;
    152 }
    153 
    154 void Navigator::trace(Visitor* visitor)
    155 {
    156 #if ENABLE(OILPAN)
    157     visitor->trace(m_plugins);
    158     visitor->trace(m_mimeTypes);
    159     HeapSupplementable<Navigator>::trace(visitor);
    160 #endif
    161     DOMWindowProperty::trace(visitor);
    162 }
    163 
    164 } // namespace blink
    165