📄 webview.cpp
字号:
}void WebView::setCacheModel(WebCacheModel cacheModel){ if (s_didSetCacheModel && cacheModel == s_cacheModel) return; RetainPtr<CFURLCacheRef> cfurlCache(AdoptCF, CFURLCacheCopySharedURLCache()); RetainPtr<CFStringRef> cfurlCacheDirectory(AdoptCF, wkCopyFoundationCacheDirectory()); if (!cfurlCacheDirectory) cfurlCacheDirectory.adoptCF(WebCore::localUserSpecificStorageDirectory().createCFString()); // As a fudge factor, use 1000 instead of 1024, in case the reported byte // count doesn't align exactly to a megabyte boundary. unsigned long long memSize = WebMemorySize() / 1024 / 1000; unsigned long long diskFreeSize = WebVolumeFreeSize(cfurlCacheDirectory.get()) / 1024 / 1000; unsigned cacheTotalCapacity = 0; unsigned cacheMinDeadCapacity = 0; unsigned cacheMaxDeadCapacity = 0; double deadDecodedDataDeletionInterval = 0; unsigned pageCacheCapacity = 0; CFIndex cfurlCacheMemoryCapacity = 0; CFIndex cfurlCacheDiskCapacity = 0; switch (cacheModel) { case WebCacheModelDocumentViewer: { // Page cache capacity (in pages) pageCacheCapacity = 0; // Object cache capacities (in bytes) if (memSize >= 2048) cacheTotalCapacity = 96 * 1024 * 1024; else if (memSize >= 1536) cacheTotalCapacity = 64 * 1024 * 1024; else if (memSize >= 1024) cacheTotalCapacity = 32 * 1024 * 1024; else if (memSize >= 512) cacheTotalCapacity = 16 * 1024 * 1024; cacheMinDeadCapacity = 0; cacheMaxDeadCapacity = 0; // Foundation memory cache capacity (in bytes) cfurlCacheMemoryCapacity = 0; // Foundation disk cache capacity (in bytes) cfurlCacheDiskCapacity = CFURLCacheDiskCapacity(cfurlCache.get()); break; } case WebCacheModelDocumentBrowser: { // Page cache capacity (in pages) if (memSize >= 1024) pageCacheCapacity = 3; else if (memSize >= 512) pageCacheCapacity = 2; else if (memSize >= 256) pageCacheCapacity = 1; else pageCacheCapacity = 0; // Object cache capacities (in bytes) if (memSize >= 2048) cacheTotalCapacity = 96 * 1024 * 1024; else if (memSize >= 1536) cacheTotalCapacity = 64 * 1024 * 1024; else if (memSize >= 1024) cacheTotalCapacity = 32 * 1024 * 1024; else if (memSize >= 512) cacheTotalCapacity = 16 * 1024 * 1024; cacheMinDeadCapacity = cacheTotalCapacity / 8; cacheMaxDeadCapacity = cacheTotalCapacity / 4; // Foundation memory cache capacity (in bytes) if (memSize >= 2048) cfurlCacheMemoryCapacity = 4 * 1024 * 1024; else if (memSize >= 1024) cfurlCacheMemoryCapacity = 2 * 1024 * 1024; else if (memSize >= 512) cfurlCacheMemoryCapacity = 1 * 1024 * 1024; else cfurlCacheMemoryCapacity = 512 * 1024; // Foundation disk cache capacity (in bytes) if (diskFreeSize >= 16384) cfurlCacheDiskCapacity = 50 * 1024 * 1024; else if (diskFreeSize >= 8192) cfurlCacheDiskCapacity = 40 * 1024 * 1024; else if (diskFreeSize >= 4096) cfurlCacheDiskCapacity = 30 * 1024 * 1024; else cfurlCacheDiskCapacity = 20 * 1024 * 1024; break; } case WebCacheModelPrimaryWebBrowser: { // Page cache capacity (in pages) // (Research indicates that value / page drops substantially after 3 pages.) if (memSize >= 2048) pageCacheCapacity = 5; else if (memSize >= 1024) pageCacheCapacity = 4; else if (memSize >= 512) pageCacheCapacity = 3; else if (memSize >= 256) pageCacheCapacity = 2; else pageCacheCapacity = 1; // Object cache capacities (in bytes) // (Testing indicates that value / MB depends heavily on content and // browsing pattern. Even growth above 128MB can have substantial // value / MB for some content / browsing patterns.) if (memSize >= 2048) cacheTotalCapacity = 128 * 1024 * 1024; else if (memSize >= 1536) cacheTotalCapacity = 96 * 1024 * 1024; else if (memSize >= 1024) cacheTotalCapacity = 64 * 1024 * 1024; else if (memSize >= 512) cacheTotalCapacity = 32 * 1024 * 1024; cacheMinDeadCapacity = cacheTotalCapacity / 4; cacheMaxDeadCapacity = cacheTotalCapacity / 2; // This code is here to avoid a PLT regression. We can remove it if we // can prove that the overall system gain would justify the regression. cacheMaxDeadCapacity = max(24u, cacheMaxDeadCapacity); deadDecodedDataDeletionInterval = 60; // Foundation memory cache capacity (in bytes) // (These values are small because WebCore does most caching itself.) if (memSize >= 1024) cfurlCacheMemoryCapacity = 4 * 1024 * 1024; else if (memSize >= 512) cfurlCacheMemoryCapacity = 2 * 1024 * 1024; else if (memSize >= 256) cfurlCacheMemoryCapacity = 1 * 1024 * 1024; else cfurlCacheMemoryCapacity = 512 * 1024; // Foundation disk cache capacity (in bytes) if (diskFreeSize >= 16384) cfurlCacheDiskCapacity = 175 * 1024 * 1024; else if (diskFreeSize >= 8192) cfurlCacheDiskCapacity = 150 * 1024 * 1024; else if (diskFreeSize >= 4096) cfurlCacheDiskCapacity = 125 * 1024 * 1024; else if (diskFreeSize >= 2048) cfurlCacheDiskCapacity = 100 * 1024 * 1024; else if (diskFreeSize >= 1024) cfurlCacheDiskCapacity = 75 * 1024 * 1024; else cfurlCacheDiskCapacity = 50 * 1024 * 1024; break; } default: ASSERT_NOT_REACHED(); } // Don't shrink a big disk cache, since that would cause churn. cfurlCacheDiskCapacity = max(cfurlCacheDiskCapacity, CFURLCacheDiskCapacity(cfurlCache.get())); cache()->setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity); cache()->setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval); pageCache()->setCapacity(pageCacheCapacity); CFURLCacheSetMemoryCapacity(cfurlCache.get(), cfurlCacheMemoryCapacity); CFURLCacheSetDiskCapacity(cfurlCache.get(), cfurlCacheDiskCapacity); s_didSetCacheModel = true; s_cacheModel = cacheModel; return;}WebCacheModel WebView::cacheModel(){ return s_cacheModel;}bool WebView::didSetCacheModel(){ return s_didSetCacheModel;}WebCacheModel WebView::maxCacheModelInAnyInstance(){ WebCacheModel cacheModel = WebCacheModelDocumentViewer; HashSet<WebView*>::iterator end = allWebViewsSet().end(); for (HashSet<WebView*>::iterator it = allWebViewsSet().begin(); it != end; ++it) { COMPtr<IWebPreferences> pref; if (FAILED((*it)->preferences(&pref))) continue; WebCacheModel prefCacheModel = WebCacheModelDocumentViewer; if (FAILED(pref->cacheModel(&prefCacheModel))) continue; cacheModel = max(cacheModel, prefCacheModel); } return cacheModel;}void WebView::close(){ if (m_didClose) return; m_didClose = true; removeFromAllWebViewsSet(); Frame* frame = m_page->mainFrame(); if (frame) frame->loader()->detachFromParent(); if (m_mouseOutTracker) { m_mouseOutTracker->dwFlags = TME_CANCEL; ::TrackMouseEvent(m_mouseOutTracker.get()); m_mouseOutTracker.set(0); } setHostWindow(0); setDownloadDelegate(0); setEditingDelegate(0); setFrameLoadDelegate(0); setFrameLoadDelegatePrivate(0); setPolicyDelegate(0); setResourceLoadDelegate(0); setUIDelegate(0); setFormDelegate(0); if (m_webInspector) m_webInspector->webViewClosed(); delete m_page; m_page = 0; registerForIconNotification(false); IWebNotificationCenter* notifyCenter = WebNotificationCenter::defaultCenterInternal(); notifyCenter->removeObserver(this, WebPreferences::webPreferencesChangedNotification(), static_cast<IWebPreferences*>(m_preferences.get())); BSTR identifier = 0; m_preferences->identifier(&identifier); COMPtr<WebPreferences> preferences = m_preferences; m_preferences = 0; preferences->didRemoveFromWebView(); // Make sure we release the reference, since WebPreferences::removeReferenceForIdentifier will check for last reference to WebPreferences preferences = 0; if (identifier) { WebPreferences::removeReferenceForIdentifier(identifier); SysFreeString(identifier); } deleteBackingStore();}void WebView::repaint(const WebCore::IntRect& windowRect, bool contentChanged, bool immediate, bool repaintContentOnly){ if (!repaintContentOnly) { RECT rect = windowRect; ::InvalidateRect(m_viewWindow, &rect, false); } if (contentChanged) addToDirtyRegion(windowRect); if (immediate) { if (repaintContentOnly) updateBackingStore(core(topLevelFrame())->view()); else ::UpdateWindow(m_viewWindow); }}void WebView::deleteBackingStore(){ pendingDeleteBackingStoreSet.remove(this); if (m_deleteBackingStoreTimerActive) { KillTimer(m_viewWindow, DeleteBackingStoreTimer); m_deleteBackingStoreTimerActive = false; } m_backingStoreBitmap.clear(); m_backingStoreDirtyRegion.clear(); m_backingStoreSize.cx = m_backingStoreSize.cy = 0;}bool WebView::ensureBackingStore(){ RECT windowRect; ::GetClientRect(m_viewWindow, &windowRect); LONG width = windowRect.right - windowRect.left; LONG height = windowRect.bottom - windowRect.top; if (width > 0 && height > 0 && (width != m_backingStoreSize.cx || height != m_backingStoreSize.cy)) { deleteBackingStore(); m_backingStoreSize.cx = width; m_backingStoreSize.cy = height; BITMAPINFO bitmapInfo; bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bitmapInfo.bmiHeader.biWidth = width; bitmapInfo.bmiHeader.biHeight = -height; bitmapInfo.bmiHeader.biPlanes = 1; bitmapInfo.bmiHeader.biBitCount = 32; bitmapInfo.bmiHeader.biCompression = BI_RGB; bitmapInfo.bmiHeader.biSizeImage = 0; bitmapInfo.bmiHeader.biXPelsPerMeter = 0; bitmapInfo.bmiHeader.biYPelsPerMeter = 0; bitmapInfo.bmiHeader.biClrUsed = 0; bitmapInfo.bmiHeader.biClrImportant = 0; void* pixels = NULL; m_backingStoreBitmap.set(::CreateDIBSection(NULL, &bitmapInfo, DIB_RGB_COLORS, &pixels, NULL, 0)); return true; } return false;}void WebView::addToDirtyRegion(const IntRect& dirtyRect){ HRGN newRegion = ::CreateRectRgn(dirtyRect.x(), dirtyRect.y(), dirtyRect.right(), dirtyRect.bottom()); addToDirtyRegion(newRegion);}void WebView::addToDirtyRegion(HRGN newRegion){ LOCAL_GDI_COUNTER(0, __FUNCTION__); if (m_backingStoreDirtyRegion) { HRGN combinedRegion = ::CreateRectRgn(0,0,0,0); ::CombineRgn(combinedRegion, m_backingStoreDirtyRegion.get(), newRegion, RGN_OR); ::DeleteObject(newRegion); m_backingStoreDirtyRegion.set(combinedRegion); } else m_backingStoreDirtyRegion.set(newRegion);}void WebView::scrollBackingStore(FrameView* frameView, int dx, int dy, const IntRect& scrollViewRect, const IntRect& clipRect){ LOCAL_GDI_COUNTER(0, __FUNCTION__); // If there's no backing store we don't need to update it if (!m_backingStoreBitmap) { if (m_uiDelegatePrivate) m_uiDelegatePrivate->webViewScrolled(this); return; } // Make a region to hold the invalidated scroll area. HRGN updateRegion = ::CreateRectRgn(0, 0, 0, 0); // Collect our device context info and select the bitmap to scroll.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -