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

📄 layouttestcontrollerwin.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2006, 2007, 2008, 2009 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. * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of *     its contributors may be used to endorse or promote products derived *     from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR 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"#include "LayoutTestController.h"#include "DumpRenderTree.h"#include "EditingDelegate.h"#include "PolicyDelegate.h"#include "WorkQueue.h"#include "WorkQueueItem.h"#include <WebCore/COMPtr.h>#include <wtf/Platform.h>#include <wtf/RetainPtr.h>#include <wtf/Vector.h>#include <JavaScriptCore/Assertions.h>#include <JavaScriptCore/JavaScriptCore.h>#include <JavaScriptCore/JSRetainPtr.h>#include <JavaScriptCore/JSStringRefBSTR.h>#include <WebKit/WebKit.h>#include <string>#include <CoreFoundation/CoreFoundation.h>#include <shlwapi.h>#include <shlguid.h>#include <shobjidl.h>using std::string;using std::wstring;static bool resolveCygwinPath(const wstring& cygwinPath, wstring& windowsPath);LayoutTestController::~LayoutTestController(){    COMPtr<IWebView> webView;    if (FAILED(frame->webView(&webView)))        return;    // reset webview-related states back to default values in preparation for next test    COMPtr<IWebViewPrivate> viewPrivate;    if (SUCCEEDED(webView->QueryInterface(&viewPrivate)))        viewPrivate->setTabKeyCyclesThroughElements(TRUE);    COMPtr<IWebViewEditing> viewEditing;    if (FAILED(webView->QueryInterface(&viewEditing)))        return;    COMPtr<IWebEditingDelegate> delegate;    if (FAILED(viewEditing->editingDelegate(&delegate)))        return;    COMPtr<EditingDelegate> editingDelegate(Query, viewEditing.get());    if (editingDelegate)        editingDelegate->setAcceptsEditing(TRUE);}void LayoutTestController::addDisallowedURL(JSStringRef url){    // FIXME: Implement!}void LayoutTestController::clearBackForwardList(){    COMPtr<IWebView> webView;    if (FAILED(frame->webView(&webView)))        return;    COMPtr<IWebBackForwardList> backForwardList;    if (FAILED(webView->backForwardList(&backForwardList)))        return;    COMPtr<IWebHistoryItem> item;    if (FAILED(backForwardList->currentItem(&item)))        return;    // We clear the history by setting the back/forward list's capacity to 0    // then restoring it back and adding back the current item.    int capacity;    if (FAILED(backForwardList->capacity(&capacity)))        return;    backForwardList->setCapacity(0);    backForwardList->setCapacity(capacity);    backForwardList->addItem(item.get());    backForwardList->goToItem(item.get());}JSStringRef LayoutTestController::copyDecodedHostName(JSStringRef name){    // FIXME: Implement!    return 0;}JSStringRef LayoutTestController::copyEncodedHostName(JSStringRef name){    // FIXME: Implement!    return 0;}void LayoutTestController::display(){    displayWebView();}void LayoutTestController::keepWebHistory(){    COMPtr<IWebHistory> history(Create, CLSID_WebHistory);    if (!history)        return;    COMPtr<IWebHistory> sharedHistory(Create, CLSID_WebHistory);    if (!sharedHistory)        return;    history->setOptionalSharedHistory(sharedHistory.get());}size_t LayoutTestController::webHistoryItemCount(){    COMPtr<IWebHistory> history(Create, CLSID_WebHistory);    if (!history)        return 0;    COMPtr<IWebHistory> sharedHistory;    if (FAILED(history->optionalSharedHistory(&sharedHistory)) || !sharedHistory)        return 0;    COMPtr<IWebHistoryPrivate> sharedHistoryPrivate;    if (FAILED(sharedHistory->QueryInterface(&sharedHistoryPrivate)))        return 0;    int count;    if (FAILED(sharedHistoryPrivate->allItems(&count, 0)))        return 0;    return count;}void LayoutTestController::notifyDone(){    // Same as on mac.  This can be shared.    if (m_waitToDump && !topLoadingFrame && !WorkQueue::shared()->count())        dump();    m_waitToDump = false;}JSStringRef LayoutTestController::pathToLocalResource(JSContextRef context, JSStringRef url){    wstring input(JSStringGetCharactersPtr(url), JSStringGetLength(url));    wstring localPath;    if (!resolveCygwinPath(input, localPath)) {        printf("ERROR: Failed to resolve Cygwin path %S\n", input.c_str());        return 0;    }    return JSStringCreateWithCharacters(localPath.c_str(), localPath.length());}void LayoutTestController::queueBackNavigation(int howFarBack){    // Same as on mac.  This can be shared.    WorkQueue::shared()->queue(new BackItem(howFarBack));}void LayoutTestController::queueForwardNavigation(int howFarForward){    // Same as on mac.  This can be shared.    WorkQueue::shared()->queue(new ForwardItem(howFarForward));}static wstring jsStringRefToWString(JSStringRef jsStr){    size_t length = JSStringGetLength(jsStr);    Vector<WCHAR> buffer(length + 1);    memcpy(buffer.data(), JSStringGetCharactersPtr(jsStr), length * sizeof(WCHAR));    buffer[length] = '\0';    return buffer.data();}void LayoutTestController::queueLoad(JSStringRef url, JSStringRef target){    COMPtr<IWebDataSource> dataSource;    if (FAILED(frame->dataSource(&dataSource)))        return;    COMPtr<IWebURLResponse> response;    if (FAILED(dataSource->response(&response)) || !response)        return;    BSTR responseURLBSTR;    if (FAILED(response->URL(&responseURLBSTR)))        return;    wstring responseURL(responseURLBSTR, SysStringLen(responseURLBSTR));    SysFreeString(responseURLBSTR);    // FIXME: We should do real relative URL resolution here.    int lastSlash = responseURL.rfind('/');    if (lastSlash != -1)        responseURL = responseURL.substr(0, lastSlash);    wstring wURL = jsStringRefToWString(url);    wstring wAbsoluteURL = responseURL + TEXT("/") + wURL;    JSRetainPtr<JSStringRef> jsAbsoluteURL(Adopt, JSStringCreateWithCharacters(wAbsoluteURL.data(), wAbsoluteURL.length()));    WorkQueue::shared()->queue(new LoadItem(jsAbsoluteURL.get(), target));}void LayoutTestController::queueReload(){    WorkQueue::shared()->queue(new ReloadItem);}void LayoutTestController::queueScript(JSStringRef script){    WorkQueue::shared()->queue(new ScriptItem(script));}void LayoutTestController::setAcceptsEditing(bool acceptsEditing){    COMPtr<IWebView> webView;    if (FAILED(frame->webView(&webView)))        return;    COMPtr<IWebViewEditing> viewEditing;    if (FAILED(webView->QueryInterface(&viewEditing)))        return;    COMPtr<IWebEditingDelegate> delegate;    if (FAILED(viewEditing->editingDelegate(&delegate)))        return;    EditingDelegate* editingDelegate = (EditingDelegate*)(IWebEditingDelegate*)delegate.get();    editingDelegate->setAcceptsEditing(acceptsEditing);}void LayoutTestController::setAuthorAndUserStylesEnabled(bool flag){    COMPtr<IWebView> webView;    if (FAILED(frame->webView(&webView)))        return;    COMPtr<IWebPreferences> preferences;    if (FAILED(webView->preferences(&preferences)))        return;    COMPtr<IWebPreferencesPrivate> prefsPrivate(Query, preferences);    if (!prefsPrivate)        return;    prefsPrivate->setAuthorAndUserStylesEnabled(flag);}void LayoutTestController::setCustomPolicyDelegate(bool setDelegate, bool permissive){    COMPtr<IWebView> webView;    if (FAILED(frame->webView(&webView)))        return;    if (setDelegate) {        policyDelegate->setPermissive(permissive);        webView->setPolicyDelegate(policyDelegate);    } else        webView->setPolicyDelegate(NULL);}void LayoutTestController::setIconDatabaseEnabled(bool iconDatabaseEnabled){    // See also <rdar://problem/6480108>    COMPtr<IWebIconDatabase> iconDatabase;    COMPtr<IWebIconDatabase> tmpIconDatabase;    if (FAILED(CoCreateInstance(CLSID_WebIconDatabase, 0, CLSCTX_ALL, IID_IWebIconDatabase, (void**)&tmpIconDatabase)))        return;    if (FAILED(tmpIconDatabase->sharedIconDatabase(&iconDatabase)))        return;    iconDatabase->setEnabled(iconDatabaseEnabled);}void LayoutTestController::setMainFrameIsFirstResponder(bool flag){    // FIXME: Implement!}void LayoutTestController::setPrivateBrowsingEnabled(bool privateBrowsingEnabled){    COMPtr<IWebView> webView;    if (FAILED(frame->webView(&webView)))        return;    COMPtr<IWebPreferences> preferences;    if (FAILED(webView->preferences(&preferences)))        return;    preferences->setPrivateBrowsingEnabled(privateBrowsingEnabled);}void LayoutTestController::setPopupBlockingEnabled(bool privateBrowsingEnabled){    COMPtr<IWebView> webView;    if (FAILED(frame->webView(&webView)))        return;    COMPtr<IWebPreferences> preferences;    if (FAILED(webView->preferences(&preferences)))        return;    preferences->setJavaScriptCanOpenWindowsAutomatically(!privateBrowsingEnabled);}void LayoutTestController::setTabKeyCyclesThroughElements(bool shouldCycle){    COMPtr<IWebView> webView;    if (FAILED(frame->webView(&webView)))        return;    COMPtr<IWebViewPrivate> viewPrivate;    if (FAILED(webView->QueryInterface(&viewPrivate)))        return;    viewPrivate->setTabKeyCyclesThroughElements(shouldCycle ? TRUE : FALSE);}void LayoutTestController::setUseDashboardCompatibilityMode(bool flag){    // FIXME: Implement!}void LayoutTestController::setUserStyleSheetEnabled(bool flag){    COMPtr<IWebView> webView;    if (FAILED(frame->webView(&webView)))        return;    COMPtr<IWebPreferences> preferences;    if (FAILED(webView->preferences(&preferences)))        return;   preferences->setUserStyleSheetEnabled(flag);}bool appendComponentToPath(wstring& path, const wstring& component){    WCHAR buffer[MAX_PATH];    if (path.size() + 1 > MAX_PATH)        return false;    memcpy(buffer, path.data(), path.size() * sizeof(WCHAR));    buffer[path.size()] = '\0';

⌨️ 快捷键说明

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