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

📄 webview.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/* * Copyright (C) 2006, 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, * 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 "WebKitDLL.h"#include "WebView.h"#include "CFDictionaryPropertyBag.h"#include "DOMCoreClasses.h"#include "MarshallingHelpers.h"#include "WebDatabaseManager.h"#include "WebDocumentLoader.h"#include "WebEditorClient.h"#include "WebElementPropertyBag.h"#include "WebFrame.h"#include "WebBackForwardList.h"#include "WebChromeClient.h"#include "WebContextMenuClient.h"#include "WebCoreTextRenderer.h"#include "WebDragClient.h"#include "WebIconDatabase.h"#include "WebInspector.h"#include "WebInspectorClient.h"#include "WebKit.h"#include "WebKitStatisticsPrivate.h"#include "WebKitSystemBits.h"#include "WebMutableURLRequest.h"#include "WebNotificationCenter.h"#include "WebPreferences.h"#pragma warning( push, 0 )#include <CoreGraphics/CGContext.h>#include <WebCore/ApplicationCacheStorage.h>#include <WebCore/AXObjectCache.h>#include <WebCore/BString.h>#include <WebCore/Cache.h>#include <WebCore/ContextMenu.h>#include <WebCore/ContextMenuController.h>#include <WebCore/CookieStorageWin.h>#include <WebCore/CString.h>#include <WebCore/Cursor.h>#include <WebCore/Document.h>#include <WebCore/DragController.h>#include <WebCore/DragData.h>#include <WebCore/Editor.h>#include <WebCore/EventHandler.h>#include <WebCore/EventNames.h>#include <WebCore/FileSystem.h>#include <WebCore/FocusController.h>#include <WebCore/FloatQuad.h>#include <WebCore/FrameLoader.h>#include <WebCore/FrameTree.h>#include <WebCore/FrameView.h>#include <WebCore/FrameWin.h>#include <WebCore/GDIObjectCounter.h>#include <WebCore/GraphicsContext.h>#include <WebCore/HistoryItem.h>#include <WebCore/HitTestResult.h>#include <WebCore/IntRect.h>#include <WebCore/KeyboardEvent.h>#include <WebCore/Language.h>#include <WebCore/MIMETypeRegistry.h>#include <WebCore/NotImplemented.h>#include <WebCore/Page.h>#include <WebCore/PageCache.h>#include <WebCore/PlatformKeyboardEvent.h>#include <WebCore/PlatformMouseEvent.h>#include <WebCore/PlatformWheelEvent.h>#include <WebCore/PluginDatabase.h>#include <WebCore/PluginInfoStore.h>#include <WebCore/PluginView.h>#include <WebCore/ProgressTracker.h>#include <WebCore/RenderTheme.h>#include <WebCore/ResourceHandle.h>#include <WebCore/ResourceHandleClient.h>#include <WebCore/ScriptValue.h>#include <WebCore/ScrollbarTheme.h>#include <WebCore/SelectionController.h>#include <WebCore/Settings.h>#include <WebCore/SimpleFontData.h>#include <WebCore/TypingCommand.h>#include <WebCore/WindowMessageBroadcaster.h>#pragma warning(pop)#include <JavaScriptCore/InitializeThreading.h>#include <JavaScriptCore/JSLock.h>#include <JavaScriptCore/JSValue.h>#include <CFNetwork/CFURLCachePriv.h>#include <CFNetwork/CFURLProtocolPriv.h>#include <CoreFoundation/CoreFoundation.h>#include <WebKitSystemInterface/WebKitSystemInterface.h> #include <wtf/HashSet.h>#include <dimm.h>#include <oleacc.h>#include <ShlObj.h>#include <tchar.h>#include <windowsx.h>using namespace WebCore;using JSC::JSLock;using std::min;using std::max;static HMODULE accessibilityLib;static HashSet<WebView*> pendingDeleteBackingStoreSet;static String osVersion();static String webKitVersion();WebView* kit(Page* page){    return page ? static_cast<WebChromeClient*>(page->chrome()->client())->webView() : 0;}class PreferencesChangedOrRemovedObserver : public IWebNotificationObserver {public:    static PreferencesChangedOrRemovedObserver* sharedInstance();private:    PreferencesChangedOrRemovedObserver() {}    ~PreferencesChangedOrRemovedObserver() {}    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void**) { return E_FAIL; }    virtual ULONG STDMETHODCALLTYPE AddRef(void) { return 0; }    virtual ULONG STDMETHODCALLTYPE Release(void) { return 0; }public:    // IWebNotificationObserver    virtual HRESULT STDMETHODCALLTYPE onNotify(         /* [in] */ IWebNotification* notification);private:    HRESULT notifyPreferencesChanged(WebCacheModel);    HRESULT notifyPreferencesRemoved(WebCacheModel);};PreferencesChangedOrRemovedObserver* PreferencesChangedOrRemovedObserver::sharedInstance(){    static PreferencesChangedOrRemovedObserver* shared = new PreferencesChangedOrRemovedObserver;    return shared;}HRESULT PreferencesChangedOrRemovedObserver::onNotify(IWebNotification* notification){    HRESULT hr = S_OK;    COMPtr<IUnknown> unkPrefs;    hr = notification->getObject(&unkPrefs);    if (FAILED(hr))        return hr;    COMPtr<IWebPreferences> preferences(Query, unkPrefs);    if (!preferences)        return E_NOINTERFACE;    WebCacheModel cacheModel;    hr = preferences->cacheModel(&cacheModel);    if (FAILED(hr))        return hr;    BSTR nameBSTR;    hr = notification->name(&nameBSTR);    if (FAILED(hr))        return hr;    BString name;    name.adoptBSTR(nameBSTR);    if (wcscmp(name, WebPreferences::webPreferencesChangedNotification()) == 0)        return notifyPreferencesChanged(cacheModel);    if (wcscmp(name, WebPreferences::webPreferencesRemovedNotification()) == 0)        return notifyPreferencesRemoved(cacheModel);    ASSERT_NOT_REACHED();    return E_FAIL;}HRESULT PreferencesChangedOrRemovedObserver::notifyPreferencesChanged(WebCacheModel cacheModel){    HRESULT hr = S_OK;    if (!WebView::didSetCacheModel() || cacheModel > WebView::cacheModel())        WebView::setCacheModel(cacheModel);    else if (cacheModel < WebView::cacheModel()) {        WebCacheModel sharedPreferencesCacheModel;        hr = WebPreferences::sharedStandardPreferences()->cacheModel(&sharedPreferencesCacheModel);        if (FAILED(hr))            return hr;        WebView::setCacheModel(max(sharedPreferencesCacheModel, WebView::maxCacheModelInAnyInstance()));    }    return hr;}HRESULT PreferencesChangedOrRemovedObserver::notifyPreferencesRemoved(WebCacheModel cacheModel){    HRESULT hr = S_OK;    if (cacheModel == WebView::cacheModel()) {        WebCacheModel sharedPreferencesCacheModel;        hr = WebPreferences::sharedStandardPreferences()->cacheModel(&sharedPreferencesCacheModel);        if (FAILED(hr))            return hr;        WebView::setCacheModel(max(sharedPreferencesCacheModel, WebView::maxCacheModelInAnyInstance()));    }    return hr;}const LPCWSTR kWebViewWindowClassName = L"WebViewWindowClass";const int WM_XP_THEMECHANGED = 0x031A;const int WM_VISTA_MOUSEHWHEEL = 0x020E;static const int maxToolTipWidth = 250;static const int delayBeforeDeletingBackingStoreMsec = 5000;static ATOM registerWebView();static LRESULT CALLBACK WebViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);static void initializeStaticObservers();static HRESULT updateSharedSettingsFromPreferencesIfNeeded(IWebPreferences*);HRESULT createMatchEnumerator(Vector<IntRect>* rects, IEnumTextMatches** matches);static bool continuousSpellCheckingEnabled;static bool grammarCheckingEnabled;static bool s_didSetCacheModel;static WebCacheModel s_cacheModel = WebCacheModelDocumentViewer;enum {    UpdateActiveStateTimer = 1,    DeleteBackingStoreTimer = 2,};// WebView ----------------------------------------------------------------bool WebView::s_allowSiteSpecificHacks = false;WebView::WebView(): m_refCount(0), m_hostWindow(0), m_viewWindow(0), m_mainFrame(0), m_page(0), m_hasCustomDropTarget(false), m_useBackForwardList(true), m_userAgentOverridden(false), m_zoomMultiplier(1.0f), m_mouseActivated(false), m_dragData(0), m_currentCharacterCode(0), m_isBeingDestroyed(false), m_paintCount(0), m_hasSpellCheckerDocumentTag(false), m_smartInsertDeleteEnabled(false), m_didClose(false), m_inIMEComposition(0), m_toolTipHwnd(0), m_closeWindowTimer(this, &WebView::closeWindowTimerFired), m_topLevelParent(0), m_deleteBackingStoreTimerActive(false), m_transparent(false), m_selectTrailingWhitespaceEnabled(false){    JSC::initializeThreading();    m_backingStoreSize.cx = m_backingStoreSize.cy = 0;    CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, IID_IDropTargetHelper,(void**)&m_dropTargetHelper);    initializeStaticObservers();    WebPreferences* sharedPreferences = WebPreferences::sharedStandardPreferences();    BOOL enabled;    if (SUCCEEDED(sharedPreferences->continuousSpellCheckingEnabled(&enabled)))        continuousSpellCheckingEnabled = !!enabled;    if (SUCCEEDED(sharedPreferences->grammarCheckingEnabled(&enabled)))        grammarCheckingEnabled = !!enabled;    WebViewCount++;    gClassCount++;    gClassNameCount.add("WebView");}WebView::~WebView(){    deleteBackingStore();    // <rdar://4958382> m_viewWindow will be destroyed when m_hostWindow is destroyed, but if    // setHostWindow was never called we will leak our HWND. If we still have a valid HWND at    // this point, we should just destroy it ourselves.    if (!isBeingDestroyed() && ::IsWindow(m_viewWindow))        ::DestroyWindow(m_viewWindow);    // the tooltip window needs to be explicitly destroyed since it isn't a WS_CHILD    if (::IsWindow(m_toolTipHwnd))        ::DestroyWindow(m_toolTipHwnd);    ASSERT(!m_page);    ASSERT(!m_preferences);    WebViewCount--;    gClassCount--;    gClassNameCount.remove("WebView");}WebView* WebView::createInstance(){    WebView* instance = new WebView();    instance->AddRef();    return instance;}void initializeStaticObservers(){    static bool initialized;    if (initialized)        return;    initialized = true;    IWebNotificationCenter* notifyCenter = WebNotificationCenter::defaultCenterInternal();    notifyCenter->addObserver(PreferencesChangedOrRemovedObserver::sharedInstance(), WebPreferences::webPreferencesChangedNotification(), 0);    notifyCenter->addObserver(PreferencesChangedOrRemovedObserver::sharedInstance(), WebPreferences::webPreferencesRemovedNotification(), 0);}static HashSet<WebView*>& allWebViewsSet(){    static HashSet<WebView*> allWebViewsSet;    return allWebViewsSet;}void WebView::addToAllWebViewsSet(){    allWebViewsSet().add(this);}void WebView::removeFromAllWebViewsSet(){    allWebViewsSet().remove(this);

⌨️ 快捷键说明

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