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

📄 dumprendertree.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    BSTR targetB;    if (FAILED(itemB->target(&targetB))) {        SysFreeString(targetA);        return 0;    }    int result = wcsicmp(wstring(targetA, SysStringLen(targetA)).c_str(), wstring(targetB, SysStringLen(targetB)).c_str());    SysFreeString(targetA);    SysFreeString(targetB);    return result;}static void dumpHistoryItem(IWebHistoryItem* item, int indent, bool current){    assert(item);    int start = 0;    if (current) {        printf("curr->");        start = 6;    }    for (int i = start; i < indent; i++)        putchar(' ');    BSTR url;    if (FAILED(item->URLString(&url)))        return;    printf("%S", url ? url : L"");    SysFreeString(url);    COMPtr<IWebHistoryItemPrivate> itemPrivate;    if (FAILED(item->QueryInterface(&itemPrivate)))        return;    BSTR target;    if (FAILED(itemPrivate->target(&target)))        return;    if (SysStringLen(target))        printf(" (in frame \"%S\")", target);    SysFreeString(target);    BOOL isTargetItem = FALSE;    if (FAILED(itemPrivate->isTargetItem(&isTargetItem)))        return;    if (isTargetItem)        printf("  **nav target**");    putchar('\n');    unsigned kidsCount;    SAFEARRAY* arrPtr;    if (FAILED(itemPrivate->children(&kidsCount, &arrPtr)) || !kidsCount)        return;    Vector<COMPtr<IUnknown> > kidsVector;    LONG lowerBound;    if (FAILED(::SafeArrayGetLBound(arrPtr, 1, &lowerBound)))        goto exit;    LONG upperBound;    if (FAILED(::SafeArrayGetUBound(arrPtr, 1, &upperBound)))        goto exit;    LONG length = upperBound - lowerBound + 1;    if (!length)        goto exit;    ASSERT(length == kidsCount);    IUnknown** safeArrayData;    if (FAILED(::SafeArrayAccessData(arrPtr, (void**)&safeArrayData)))        goto exit;    for (int i = 0; i < length; ++i)        kidsVector.append(safeArrayData[i]);    ::SafeArrayUnaccessData(arrPtr);    // must sort to eliminate arbitrary result ordering which defeats reproducible testing    qsort(kidsVector.data(), kidsCount, sizeof(kidsVector[0]), compareHistoryItems);    for (unsigned i = 0; i < kidsCount; ++i) {        COMPtr<IWebHistoryItem> item;        kidsVector[i]->QueryInterface(&item);        dumpHistoryItem(item.get(), indent + 4, false);    }exit:    if (arrPtr && SUCCEEDED(::SafeArrayUnlock(arrPtr)))        ::SafeArrayDestroy(arrPtr);}static void dumpBackForwardList(IWebView* webView){    ASSERT(webView);    printf("\n============== Back Forward List ==============\n");    COMPtr<IWebBackForwardList> bfList;    if (FAILED(webView->backForwardList(&bfList)))        return;    // Print out all items in the list after prevTestBFItem, which was from the previous test    // Gather items from the end of the list, the print them out from oldest to newest    Vector<COMPtr<IUnknown> > itemsToPrint;    int forwardListCount;    if (FAILED(bfList->forwardListCount(&forwardListCount)))        return;    for (int i = forwardListCount; i > 0; --i) {        COMPtr<IWebHistoryItem> item;        if (FAILED(bfList->itemAtIndex(i, &item)))            return;        // something is wrong if the item from the last test is in the forward part of the b/f list        assert(item != prevTestBFItem);        COMPtr<IUnknown> itemUnknown;        item->QueryInterface(&itemUnknown);        itemsToPrint.append(itemUnknown);    }        COMPtr<IWebHistoryItem> currentItem;    if (FAILED(bfList->currentItem(&currentItem)))        return;    assert(currentItem != prevTestBFItem);    COMPtr<IUnknown> currentItemUnknown;    currentItem->QueryInterface(&currentItemUnknown);    itemsToPrint.append(currentItemUnknown);    int currentItemIndex = itemsToPrint.size() - 1;    int backListCount;    if (FAILED(bfList->backListCount(&backListCount)))        return;    for (int i = -1; i >= -backListCount; --i) {        COMPtr<IWebHistoryItem> item;        if (FAILED(bfList->itemAtIndex(i, &item)))            return;        if (item == prevTestBFItem)            break;        COMPtr<IUnknown> itemUnknown;        item->QueryInterface(&itemUnknown);        itemsToPrint.append(itemUnknown);    }    for (int i = itemsToPrint.size() - 1; i >= 0; --i) {        COMPtr<IWebHistoryItem> historyItemToPrint;        itemsToPrint[i]->QueryInterface(&historyItemToPrint);        dumpHistoryItem(historyItemToPrint.get(), 8, i == currentItemIndex);    }    printf("===============================================\n");}static void dumpBackForwardListForAllWindows(){    unsigned count = openWindows().size();    for (unsigned i = 0; i < count; i++) {        HWND window = openWindows()[i];        IWebView* webView = windowToWebViewMap().get(window).get();        dumpBackForwardList(webView);    }}void dump(){    COMPtr<IWebDataSource> dataSource;    if (SUCCEEDED(frame->dataSource(&dataSource))) {        COMPtr<IWebURLResponse> response;        if (SUCCEEDED(dataSource->response(&response)) && response) {            BSTR mimeType;            if (SUCCEEDED(response->MIMEType(&mimeType)))                ::gLayoutTestController->setDumpAsText(::gLayoutTestController->dumpAsText() | !_tcscmp(mimeType, TEXT("text/plain")));            SysFreeString(mimeType);        }    }    BSTR resultString = 0;    if (dumpTree) {        if (::gLayoutTestController->dumpAsText()) {            ::InvalidateRect(webViewWindow, 0, TRUE);            ::SendMessage(webViewWindow, WM_PAINT, 0, 0);            wstring result = dumpFramesAsText(frame);            resultString = SysAllocStringLen(result.data(), result.size());        } else {            bool isSVGW3CTest = (gLayoutTestController->testPathOrURL().find("svg\\W3C-SVG-1.1") != string::npos);            unsigned width;            unsigned height;            if (isSVGW3CTest) {                width = 480;                height = 360;            } else {                width = maxViewWidth;                height = maxViewHeight;            }            ::SetWindowPos(webViewWindow, 0, 0, 0, width, height, SWP_NOMOVE);            ::InvalidateRect(webViewWindow, 0, TRUE);            ::SendMessage(webViewWindow, WM_PAINT, 0, 0);            COMPtr<IWebFramePrivate> framePrivate;            if (FAILED(frame->QueryInterface(&framePrivate)))                goto fail;            framePrivate->renderTreeAsExternalRepresentation(&resultString);        }                if (!resultString)            printf("ERROR: nil result from %s", ::gLayoutTestController->dumpAsText() ? "IDOMElement::innerText" : "IFrameViewPrivate::renderTreeAsExternalRepresentation");        else {            unsigned stringLength = SysStringLen(resultString);            int bufferSize = ::WideCharToMultiByte(CP_UTF8, 0, resultString, stringLength, 0, 0, 0, 0);            char* buffer = (char*)malloc(bufferSize + 1);            ::WideCharToMultiByte(CP_UTF8, 0, resultString, stringLength, buffer, bufferSize + 1, 0, 0);            fwrite(buffer, 1, bufferSize, stdout);            free(buffer);            if (!::gLayoutTestController->dumpAsText())                dumpFrameScrollPosition(frame);        }        if (::gLayoutTestController->dumpBackForwardList())            dumpBackForwardListForAllWindows();    }    if (printSeparators) {        puts("#EOF");   // terminate the content block        fputs("#EOF\n", stderr);        fflush(stdout);        fflush(stderr);    }    if (dumpPixels) {        if (!gLayoutTestController->dumpAsText() && !gLayoutTestController->dumpDOMAsWebArchive() && !gLayoutTestController->dumpSourceAsWebArchive())            dumpWebViewAsPixelsAndCompareWithExpected(gLayoutTestController->expectedPixelHash());    }    printf("#EOF\n");   // terminate the (possibly empty) pixels block    fflush(stdout);fail:    SysFreeString(resultString);    // This will exit from our message loop    PostQuitMessage(0);    done = true;}static bool shouldLogFrameLoadDelegates(const char* pathOrURL){    return strstr(pathOrURL, "loading/");}static void resetWebViewToConsistentStateBeforeTesting(){    COMPtr<IWebView> webView;    if (FAILED(frame->webView(&webView)))         return;    webView->setPolicyDelegate(0);    COMPtr<IWebIBActions> webIBActions(Query, webView);    if (webIBActions) {        webIBActions->makeTextStandardSize(0);        webIBActions->resetPageZoom(0);    }    COMPtr<IWebPreferences> preferences;    if (SUCCEEDED(webView->preferences(&preferences))) {        preferences->setPrivateBrowsingEnabled(FALSE);        preferences->setJavaScriptCanOpenWindowsAutomatically(TRUE);        if (persistentUserStyleSheetLocation) {            Vector<wchar_t> urlCharacters(CFStringGetLength(persistentUserStyleSheetLocation.get()));            CFStringGetCharacters(persistentUserStyleSheetLocation.get(), CFRangeMake(0, CFStringGetLength(persistentUserStyleSheetLocation.get())), (UniChar *)urlCharacters.data());            BSTR url = SysAllocStringLen(urlCharacters.data(), urlCharacters.size());            preferences->setUserStyleSheetLocation(url);            SysFreeString(url);            preferences->setUserStyleSheetEnabled(TRUE);        } else            preferences->setUserStyleSheetEnabled(FALSE);        COMPtr<IWebPreferencesPrivate> prefsPrivate(Query, preferences);        if (prefsPrivate) {            prefsPrivate->setAuthorAndUserStylesEnabled(TRUE);            prefsPrivate->setDeveloperExtrasEnabled(FALSE);        }    }    COMPtr<IWebViewEditing> viewEditing;    if (SUCCEEDED(webView->QueryInterface(&viewEditing)))        viewEditing->setSmartInsertDeleteEnabled(TRUE);    COMPtr<IWebViewPrivate> webViewPrivate(Query, webView);    if (!webViewPrivate)        return;    COMPtr<IWebInspector> inspector;    if (SUCCEEDED(webViewPrivate->inspector(&inspector)))        inspector->setJavaScriptProfilingEnabled(FALSE);    HWND viewWindow;    if (SUCCEEDED(webViewPrivate->viewWindow(reinterpret_cast<OLE_HANDLE*>(&viewWindow))) && viewWindow)        SetFocus(viewWindow);    webViewPrivate->clearMainFrameName();}static void runTest(const string& testPathOrURL){    static BSTR methodBStr = SysAllocString(TEXT("GET"));    // Look for "'" as a separator between the path or URL, and the pixel dump hash that follows.    string pathOrURL(testPathOrURL);    string expectedPixelHash;        size_t separatorPos = pathOrURL.find("'");    if (separatorPos != string::npos) {        pathOrURL = string(testPathOrURL, 0, separatorPos);        expectedPixelHash = string(testPathOrURL, separatorPos + 1);    }        BSTR urlBStr;     CFStringRef str = CFStringCreateWithCString(0, pathOrURL.c_str(), kCFStringEncodingWindowsLatin1);    CFURLRef url = CFURLCreateWithString(0, str, 0);    if (!url)        url = CFURLCreateWithFileSystemPath(0, str, kCFURLWindowsPathStyle, false);    CFRelease(str);    str = CFURLGetString(url);    CFIndex length = CFStringGetLength(str);    UniChar* buffer = new UniChar[length];    CFStringGetCharacters(str, CFRangeMake(0, length), buffer);    urlBStr = SysAllocStringLen((OLECHAR*)buffer, length);    delete[] buffer;    CFRelease(url);    ::gLayoutTestController = new LayoutTestController(pathOrURL, expectedPixelHash);    done = false;    topLoadingFrame = 0;    gLayoutTestController->setIconDatabaseEnabled(false);    if (shouldLogFrameLoadDelegates(pathOrURL.c_str()))        gLayoutTestController->setDumpFrameLoadCallbacks(true);    COMPtr<IWebHistory> history(Create, CLSID_WebHistory);    if (history)        history->setOptionalSharedHistory(0);    resetWebViewToConsistentStateBeforeTesting();    sharedUIDelegate->resetUndoManager();    prevTestBFItem = 0;    COMPtr<IWebView> webView;    if (SUCCEEDED(frame->webView(&webView))) {        COMPtr<IWebBackForwardList> bfList;        if (SUCCEEDED(webView->backForwardList(&bfList)))            bfList->currentItem(&prevTestBFItem);    }    WorkQueue::shared()->clear();    WorkQueue::shared()->setFrozen(false);    HWND hostWindow;    webView->hostWindow(reinterpret_cast<OLE_HANDLE*>(&hostWindow));    COMPtr<IWebMutableURLRequest> request;    HRESULT hr = CoCreateInstance(CLSID_WebMutableURLRequest, 0, CLSCTX_ALL, IID_IWebMutableURLRequest, (void**)&request);    if (FAILED(hr))        goto exit;    request->initWithURL(urlBStr, WebURLRequestUseProtocolCachePolicy, 60);    request->setHTTPMethod(methodBStr);

⌨️ 快捷键说明

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