⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftpdirectorydocument.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */#include "config.h"#if ENABLE(FTPDIR)#include "FTPDirectoryDocument.h"#include "CharacterNames.h"#include "CString.h"#include "HTMLNames.h"#include "HTMLTableElement.h"#include "HTMLTokenizer.h"#include "LocalizedStrings.h"#include "Logging.h"#include "FTPDirectoryParser.h"#include "SegmentedString.h"#include "Settings.h"#include "SharedBuffer.h"#include "Text.h"#include <wtf/StdLibExtras.h>#if PLATFORM(QT)#include <QDateTime>// On Windows, use the threadsafe *_r functions provided by pthread.#elif PLATFORM(WIN_OS) && (USE(PTHREADS) || HAVE(PTHREAD_H))#include <pthread.h>#endifusing namespace std;namespace WebCore {using namespace HTMLNames;    class FTPDirectoryTokenizer : public HTMLTokenizer {public:    FTPDirectoryTokenizer(HTMLDocument*);    virtual void write(const SegmentedString&, bool appendData);    virtual void finish();        virtual bool isWaitingForScripts() const { return false; }    inline void checkBuffer(int len = 10)    {        if ((m_dest - m_buffer) > m_size - len) {            // Enlarge buffer            int newSize = max(m_size * 2, m_size + len);            int oldOffset = m_dest - m_buffer;            m_buffer = static_cast<UChar*>(fastRealloc(m_buffer, newSize * sizeof(UChar)));            m_dest = m_buffer + oldOffset;            m_size = newSize;        }    }        private:    // The tokenizer will attempt to load the document template specified via the preference    // Failing that, it will fall back and create the basic document which will have a minimal    // table for presenting the FTP directory in a useful manner    bool loadDocumentTemplate();    void createBasicDocument();    void parseAndAppendOneLine(const String&);    void appendEntry(const String& name, const String& size, const String& date, bool isDirectory);        PassRefPtr<Element> createTDForFilename(const String&);        Document* m_doc;    RefPtr<HTMLTableElement> m_tableElement;    bool m_skipLF;    bool m_parsedTemplate;        int m_size;    UChar* m_buffer;    UChar* m_dest;    String m_carryOver;        ListState m_listState;};FTPDirectoryTokenizer::FTPDirectoryTokenizer(HTMLDocument* doc)    : HTMLTokenizer(doc, false)    , m_doc(doc)    , m_skipLF(false)    , m_parsedTemplate(false)    , m_size(254)    , m_buffer(static_cast<UChar*>(fastMalloc(sizeof(UChar) * m_size)))    , m_dest(m_buffer){    }    void FTPDirectoryTokenizer::appendEntry(const String& filename, const String& size, const String& date, bool isDirectory){    ExceptionCode ec;    RefPtr<Element> rowElement = m_tableElement->insertRow(-1, ec);    rowElement->setAttribute("class", "ftpDirectoryEntryRow", ec);       RefPtr<Element> element = m_doc->createElement(tdTag, false);    element->appendChild(new Text(m_doc, String(&noBreakSpace, 1)), ec);    if (isDirectory)        element->setAttribute("class", "ftpDirectoryIcon ftpDirectoryTypeDirectory", ec);    else        element->setAttribute("class", "ftpDirectoryIcon ftpDirectoryTypeFile", ec);    rowElement->appendChild(element, ec);        element = createTDForFilename(filename);    element->setAttribute("class", "ftpDirectoryFileName", ec);    rowElement->appendChild(element, ec);        element = m_doc->createElement(tdTag, false);    element->appendChild(new Text(m_doc, date), ec);    element->setAttribute("class", "ftpDirectoryFileDate", ec);    rowElement->appendChild(element, ec);        element = m_doc->createElement(tdTag, false);    element->appendChild(new Text(m_doc, size), ec);    element->setAttribute("class", "ftpDirectoryFileSize", ec);    rowElement->appendChild(element, ec);}PassRefPtr<Element> FTPDirectoryTokenizer::createTDForFilename(const String& filename){    ExceptionCode ec;        String fullURL = m_doc->baseURL().string();    if (fullURL[fullURL.length() - 1] == '/')        fullURL.append(filename);    else        fullURL.append("/" + filename);    RefPtr<Element> anchorElement = m_doc->createElement(aTag, false);    anchorElement->setAttribute("href", fullURL, ec);    anchorElement->appendChild(new Text(m_doc, filename), ec);        RefPtr<Element> tdElement = m_doc->createElement(tdTag, false);    tdElement->appendChild(anchorElement, ec);        return tdElement.release();}static String processFilesizeString(const String& size, bool isDirectory){    if (isDirectory)        return "--";        bool valid;    int64_t bytes = size.toUInt64(&valid);    if (!valid)        return unknownFileSizeText();         if (bytes < 1000000)        return String::format("%.2f KB", static_cast<float>(bytes)/1000);    if (bytes < 1000000000)        return String::format("%.2f MB", static_cast<float>(bytes)/1000000);            return String::format("%.2f GB", static_cast<float>(bytes)/1000000000);}static bool wasLastDayOfMonth(int year, int month, int day){    static int lastDays[] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };    if (month < 0 || month > 11)        return false;            if (month == 2) {        if (year % 4 == 0 && (year % 100 || year % 400 == 0)) {            if (day == 29)                return true;            return false;        }                 if (day == 28)            return true;        return false;    }        return lastDays[month] == day;}#if PLATFORM(QT)/*! Replacement for localtime_r() which is not available on MinGW. We use this on all of Qt's platforms for portability. */struct tm gmtimeQt(const QDateTime &input){    tm result;    const QDate date(input.date());    result.tm_year = date.year() - 1900;    result.tm_mon = date.month();    result.tm_mday = date.day();    result.tm_wday = date.dayOfWeek();    result.tm_yday = date.dayOfYear();    const QTime time(input.time());    result.tm_sec = time.second();    result.tm_min = time.minute();    result.tm_hour = time.hour();    return result;}static struct tm *localTimeQt(const time_t *const timep, struct tm *result){    const QDateTime dt(QDateTime::fromTime_t(*timep));    *result = WebCore::gmtimeQt(dt.toLocalTime());    return result;}#define localtime_r(x, y) localTimeQt(x, y)#elif PLATFORM(WIN_OS) && !defined(localtime_r)#define localtime_r(x, y) localtime_s((y), (x))#endifstatic String processFileDateString(const FTPTime& fileTime){    // FIXME: Need to localize this string?    String timeOfDay;        if (!(fileTime.tm_hour == 0 && fileTime.tm_min == 0 && fileTime.tm_sec == 0)) {        int hour = fileTime.tm_hour;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -