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/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 WebCore { 53 54 Navigator::Navigator(LocalFrame* frame) 55 : DOMWindowProperty(frame) 56 { 57 ScriptWrappable::init(this); 58 } 59 60 Navigator::~Navigator() 61 { 62 } 63 64 String Navigator::productSub() const 65 { 66 return WEBCORE_NAVIGATOR_PRODUCT_SUB; 67 } 68 69 String Navigator::vendor() const 70 { 71 return WEBCORE_NAVIGATOR_VENDOR; 72 } 73 74 String Navigator::vendorSub() const 75 { 76 return WEBCORE_NAVIGATOR_VENDOR_SUB; 77 } 78 79 String Navigator::userAgent() const 80 { 81 // If the frame is already detached it no longer has a meaningful useragent. 82 if (!m_frame || !m_frame->page()) 83 return String(); 84 85 return m_frame->loader().userAgent(m_frame->document()->url()); 86 } 87 88 DOMPluginArray* Navigator::plugins() const 89 { 90 if (!m_plugins) 91 m_plugins = DOMPluginArray::create(m_frame); 92 return m_plugins.get(); 93 } 94 95 DOMMimeTypeArray* Navigator::mimeTypes() const 96 { 97 if (!m_mimeTypes) 98 m_mimeTypes = DOMMimeTypeArray::create(m_frame); 99 return m_mimeTypes.get(); 100 } 101 102 bool Navigator::cookieEnabled() const 103 { 104 if (!m_frame) 105 return false; 106 107 Settings* settings = m_frame->settings(); 108 if (!settings || !settings->cookieEnabled()) 109 return false; 110 111 return cookiesEnabled(m_frame->document()); 112 } 113 114 bool Navigator::javaEnabled() const 115 { 116 if (!m_frame || !m_frame->settings()) 117 return false; 118 119 if (!m_frame->settings()->javaEnabled()) 120 return false; 121 122 return true; 123 } 124 125 void Navigator::getStorageUpdates() 126 { 127 // FIXME: Remove this method or rename to yieldForStorageUpdates. 128 } 129 130 Vector<String> Navigator::languages() 131 { 132 Vector<String> languages; 133 134 if (!m_frame || !m_frame->host()) { 135 languages.append(defaultLanguage()); 136 return languages; 137 } 138 139 String acceptLanguages = m_frame->host()->chrome().client().acceptLanguages(); 140 acceptLanguages.split(",", languages); 141 142 // Sanitizing tokens. We could do that more extensively but we should assume 143 // that the accept languages are already sane and support BCP47. It is 144 // likely a waste of time to make sure the tokens matches that spec here. 145 for (size_t i = 0; i < languages.size(); ++i) { 146 String& token = languages[i]; 147 token = token.stripWhiteSpace(); 148 if (token.length() >= 3 && token[2] == '_') 149 token.replace(2, 1, "-"); 150 } 151 152 return languages; 153 } 154 155 void Navigator::trace(Visitor* visitor) 156 { 157 visitor->trace(m_plugins); 158 visitor->trace(m_mimeTypes); 159 WillBeHeapSupplementable<Navigator>::trace(visitor); 160 } 161 162 } // namespace WebCore 163