1/*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 */
26
27#include "config.h"
28#include "NavigatorBase.h"
29
30#include "NetworkStateNotifier.h"
31#include <wtf/text/WTFString.h>
32
33#if OS(LINUX)
34#include "sys/utsname.h"
35#include <wtf/StdLibExtras.h>
36#endif
37
38#ifndef WEBCORE_NAVIGATOR_PLATFORM
39#if OS(MAC_OS_X) && (CPU(PPC) || CPU(PPC64))
40#define WEBCORE_NAVIGATOR_PLATFORM "MacPPC"
41#elif OS(MAC_OS_X) && (CPU(X86) || CPU(X86_64))
42#define WEBCORE_NAVIGATOR_PLATFORM "MacIntel"
43#elif OS(WINDOWS)
44#define WEBCORE_NAVIGATOR_PLATFORM "Win32"
45#elif PLATFORM(BLACKBERRY)
46#define WEBCORE_NAVIGATOR_PLATFORM "BlackBerry"
47#else
48#define WEBCORE_NAVIGATOR_PLATFORM ""
49#endif
50#endif // ifndef WEBCORE_NAVIGATOR_PLATFORM
51
52#ifndef WEBCORE_NAVIGATOR_PRODUCT
53#define WEBCORE_NAVIGATOR_PRODUCT "Gecko"
54#endif // ifndef WEBCORE_NAVIGATOR_PRODUCT
55
56#ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
57#define WEBCORE_NAVIGATOR_PRODUCT_SUB "20030107"
58#endif // ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
59
60#ifndef WEBCORE_NAVIGATOR_VENDOR
61#define WEBCORE_NAVIGATOR_VENDOR "Apple Computer, Inc."
62#endif // ifndef WEBCORE_NAVIGATOR_VENDOR
63
64#ifndef WEBCORE_NAVIGATOR_VENDOR_SUB
65#define WEBCORE_NAVIGATOR_VENDOR_SUB ""
66#endif // ifndef WEBCORE_NAVIGATOR_VENDOR_SUB
67
68
69namespace WebCore {
70
71NavigatorBase::~NavigatorBase()
72{
73}
74
75String NavigatorBase::appName() const
76{
77    return "Netscape";
78}
79
80String NavigatorBase::appVersion() const
81{
82    // Version is everything in the user agent string past the "Mozilla/" prefix.
83    const String& agent = userAgent();
84    return agent.substring(agent.find('/') + 1);
85}
86
87String NavigatorBase::platform() const
88{
89#if OS(LINUX)
90    if (!String(WEBCORE_NAVIGATOR_PLATFORM).isEmpty())
91        return WEBCORE_NAVIGATOR_PLATFORM;
92    struct utsname osname;
93    DEFINE_STATIC_LOCAL(String, platformName, (uname(&osname) >= 0 ? String(osname.sysname) + String(" ") + String(osname.machine) : emptyString()));
94    return platformName;
95#else
96    return WEBCORE_NAVIGATOR_PLATFORM;
97#endif
98}
99
100String NavigatorBase::appCodeName() const
101{
102    return "Mozilla";
103}
104
105String NavigatorBase::product() const
106{
107    return WEBCORE_NAVIGATOR_PRODUCT;
108}
109
110String NavigatorBase::productSub() const
111{
112    return WEBCORE_NAVIGATOR_PRODUCT_SUB;
113}
114
115String NavigatorBase::vendor() const
116{
117    return WEBCORE_NAVIGATOR_VENDOR;
118}
119
120String NavigatorBase::vendorSub() const
121{
122    return WEBCORE_NAVIGATOR_VENDOR_SUB;
123}
124
125bool NavigatorBase::onLine() const
126{
127    return networkStateNotifier().onLine();
128}
129
130} // namespace WebCore
131