bool PageCache::canCache(Page* page) const { if (!page) return false; #if PLATFORM(CHROMIUM) || !defined(NDEBUG) logCanCachePageDecision(page); #endif // Cache the page, if possible. // Don't write to the cache if in the middle of a redirect, since we will want to // store the final page we end up on. // No point writing to the cache on a reload or loadSame, since we will just write // over it again when we leave that page. FrameLoadType loadType = page->mainFrame()->loader()->loadType(); return m_capacity > 0 && canCachePageContainingThisFrame(page->mainFrame()) && page->backForward()->isActive() && page->settings()->usesPageCache() #if ENABLE(DEVICE_ORIENTATION) && !DeviceMotionController::isActiveAt(page) && !DeviceOrientationController::isActiveAt(page) #endif #if ENABLE(PROXIMITY_EVENTS) && !DeviceProximityController::isActiveAt(page) #endif && loadType != FrameLoadTypeReload && loadType != FrameLoadTypeReloadFromOrigin && loadType != FrameLoadTypeSame; }
bool PageCache::canCache(Page* page) const { if (!page) return false; #if !defined(NDEBUG) logCanCachePageDecision(page); #endif if (memoryPressureHandler().isUnderMemoryPressure()) return false; // Cache the page, if possible. // Don't write to the cache if in the middle of a redirect, since we will want to // store the final page we end up on. // No point writing to the cache on a reload or loadSame, since we will just write // over it again when we leave that page. FrameLoadType loadType = page->mainFrame().loader().loadType(); return m_capacity > 0 && canCachePageContainingThisFrame(&page->mainFrame()) && page->settings().usesPageCache() #if ENABLE(DEVICE_ORIENTATION) && !PLATFORM(IOS) && !DeviceMotionController::isActiveAt(page) && !DeviceOrientationController::isActiveAt(page) #endif #if ENABLE(PROXIMITY_EVENTS) && !DeviceProximityController::isActiveAt(page) #endif && (loadType == FrameLoadType::Standard || loadType == FrameLoadType::Back || loadType == FrameLoadType::Forward || loadType == FrameLoadType::IndexedBackForward); }
bool PageCache::canCachePageContainingThisFrame(Frame* frame) { for (Frame* child = frame->tree()->firstChild(); child; child = child->tree()->nextSibling()) { if (!canCachePageContainingThisFrame(child)) return false; } FrameLoader* frameLoader = frame->loader(); DocumentLoader* documentLoader = frameLoader->documentLoader(); Document* document = frame->document(); return documentLoader && documentLoader->mainDocumentError().isNull() // Do not cache error pages (these can be recognized as pages with substitute data or unreachable URLs). && !(documentLoader->substituteData().isValid() && !documentLoader->substituteData().failingURL().isEmpty()) && (!frameLoader->subframeLoader()->containsPlugins() || frame->page()->settings()->pageCacheSupportsPlugins()) && (!document->url().protocolIs("https") || (!documentLoader->response().cacheControlContainsNoCache() && !documentLoader->response().cacheControlContainsNoStore())) && (!document->domWindow() || !document->domWindow()->hasEventListeners(eventNames().unloadEvent)) #if ENABLE(SQL_DATABASE) && !DatabaseManager::manager().hasOpenDatabases(document) #endif #if ENABLE(SHARED_WORKERS) && !SharedWorkerRepository::hasSharedWorkers(document) #endif && frameLoader->history()->currentItem() && !frameLoader->quickRedirectComing() && !documentLoader->isLoadingInAPISense() && !documentLoader->isStopping() && document->canSuspendActiveDOMObjects() // FIXME: We should investigating caching frames that have an associated // application cache. <rdar://problem/5917899> tracks that work. && documentLoader->applicationCacheHost()->canCacheInPageCache() && frameLoader->client()->canCachePage(); }
bool PageCache::canCachePageContainingThisFrame(Frame& frame) { for (Frame* child = frame.tree().firstChild(); child; child = child->tree().nextSibling()) { if (!canCachePageContainingThisFrame(*child)) return false; } FrameLoader& frameLoader = frame.loader(); DocumentLoader* documentLoader = frameLoader.documentLoader(); Document* document = frame.document(); return documentLoader && (documentLoader->mainDocumentError().isNull() || (documentLoader->mainDocumentError().isCancellation() && documentLoader->subresourceLoadersArePageCacheAcceptable())) // Do not cache error pages (these can be recognized as pages with substitute data or unreachable URLs). && !(documentLoader->substituteData().isValid() && !documentLoader->substituteData().failingURL().isEmpty()) && (!frameLoader.subframeLoader().containsPlugins() || frame.page()->settings().pageCacheSupportsPlugins()) && !(frame.isMainFrame() && document->url().protocolIs("https") && documentLoader->response().cacheControlContainsNoStore()) && frameLoader.history().currentItem() && !frameLoader.quickRedirectComing() && !documentLoader->isLoading() && !documentLoader->isStopping() && document->canSuspendActiveDOMObjectsForPageCache() // FIXME: We should investigating caching frames that have an associated // application cache. <rdar://problem/5917899> tracks that work. && documentLoader->applicationCacheHost()->canCacheInPageCache() && frameLoader.client().canCachePage(); }