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(); }
void WebFrameLoaderClient::updateGlobalHistory() { DocumentLoader* loader = core(m_webFrame)->loader()->documentLoader(); WebView* webView = m_webFrame->webView(); COMPtr<IWebHistoryDelegate> historyDelegate; webView->historyDelegate(&historyDelegate); if (historyDelegate) { COMPtr<IWebURLResponse> urlResponse(AdoptCOM, WebURLResponse::createInstance(loader->response())); COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(loader->originalRequestCopy())); COMPtr<IWebNavigationData> navigationData(AdoptCOM, WebNavigationData::createInstance( loader->urlForHistory(), loader->title(), urlRequest.get(), urlResponse.get(), loader->substituteData().isValid(), loader->clientRedirectSourceForHistory())); historyDelegate->didNavigateWithNavigationData(webView, navigationData.get(), m_webFrame); return; } WebHistory* history = WebHistory::sharedHistory(); if (!history) return; history->visitedURL(loader->urlForHistory(), loader->title(), loader->originalRequestCopy().httpMethod(), loader->urlForHistoryReflectsFailure(), !loader->clientRedirectSourceForHistory()); }
static bool canCacheFrame(Frame& frame, DiagnosticLoggingClient& diagnosticLoggingClient, unsigned indentLevel) { PCLOG("+---"); FrameLoader& frameLoader = frame.loader(); // Prevent page caching if a subframe is still in provisional load stage. // We only do this check for subframes because the main frame is reused when navigating to a new page. if (!frame.isMainFrame() && frameLoader.state() == FrameStateProvisional) { PCLOG(" -Frame is in provisional load stage"); logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::provisionalLoadKey()); return false; } DocumentLoader* documentLoader = frameLoader.documentLoader(); if (!documentLoader) { PCLOG(" -There is no DocumentLoader object"); logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::noDocumentLoaderKey()); return false; } URL currentURL = documentLoader->url(); URL newURL = frameLoader.provisionalDocumentLoader() ? frameLoader.provisionalDocumentLoader()->url() : URL(); if (!newURL.isEmpty()) PCLOG(" Determining if frame can be cached navigating from (", currentURL.string(), ") to (", newURL.string(), "):"); else PCLOG(" Determining if subframe with URL (", currentURL.string(), ") can be cached:"); bool isCacheable = true; if (!documentLoader->mainDocumentError().isNull()) { PCLOG(" -Main document has an error"); logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::mainDocumentErrorKey()); if (documentLoader->mainDocumentError().isCancellation() && documentLoader->subresourceLoadersArePageCacheAcceptable()) PCLOG(" -But, it was a cancellation and all loaders during the cancelation were loading images or XHR."); else isCacheable = false; } // Do not cache error pages (these can be recognized as pages with substitute data or unreachable URLs). if (documentLoader->substituteData().isValid() && !documentLoader->substituteData().failingURL().isEmpty()) { PCLOG(" -Frame is an error page"); logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::isErrorPageKey()); isCacheable = false; } if (frameLoader.subframeLoader().containsPlugins() && !frame.page()->settings().pageCacheSupportsPlugins()) { PCLOG(" -Frame contains plugins"); logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::hasPluginsKey()); isCacheable = false; } if (frame.isMainFrame() && frame.document() && frame.document()->url().protocolIs("https") && documentLoader->response().cacheControlContainsNoStore()) { PCLOG(" -Frame is HTTPS, and cache control prohibits storing"); logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::httpsNoStoreKey()); isCacheable = false; } if (frame.isMainFrame() && !frameLoader.history().currentItem()) { PCLOG(" -Main frame has no current history item"); logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::noCurrentHistoryItemKey()); isCacheable = false; } if (frameLoader.quickRedirectComing()) { PCLOG(" -Quick redirect is coming"); logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::quirkRedirectComingKey()); isCacheable = false; } if (documentLoader->isLoading()) { PCLOG(" -DocumentLoader is still loading"); logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::isLoadingKey()); isCacheable = false; } if (documentLoader->isStopping()) { PCLOG(" -DocumentLoader is in the middle of stopping"); logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::documentLoaderStoppingKey()); isCacheable = false; } Vector<ActiveDOMObject*> unsuspendableObjects; if (frame.document() && !frame.document()->canSuspendActiveDOMObjectsForDocumentSuspension(&unsuspendableObjects)) { PCLOG(" -The document cannot suspend its active DOM Objects"); for (auto* activeDOMObject : unsuspendableObjects) { PCLOG(" - Unsuspendable: ", activeDOMObject->activeDOMObjectName()); diagnosticLoggingClient.logDiagnosticMessageWithValue(DiagnosticLoggingKeys::pageCacheKey(), DiagnosticLoggingKeys::unsuspendableDOMObjectKey(), activeDOMObject->activeDOMObjectName(), ShouldSample::Yes); UNUSED_PARAM(activeDOMObject); } logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::cannotSuspendActiveDOMObjectsKey()); isCacheable = false; } // FIXME: We should investigating caching frames that have an associated // application cache. <rdar://problem/5917899> tracks that work. if (!documentLoader->applicationCacheHost()->canCacheInPageCache()) { PCLOG(" -The DocumentLoader uses an application cache"); logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::applicationCacheKey()); isCacheable = false; } if (!frameLoader.client().canCachePage()) { PCLOG(" -The client says this frame cannot be cached"); logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::deniedByClientKey()); isCacheable = false; } for (Frame* child = frame.tree().firstChild(); child; child = child->tree().nextSibling()) { if (!canCacheFrame(*child, diagnosticLoggingClient, indentLevel + 1)) isCacheable = false; } PCLOG(isCacheable ? " Frame CAN be cached" : " Frame CANNOT be cached"); PCLOG("+---"); return isCacheable; }
void WebFrameLoaderClient::updateGlobalHistory() { DocumentLoader* loader = core(m_webFrame)->loader()->documentLoader(); WebView* webView = m_webFrame->webView(); SharedPtr<WebHistoryDelegate> historyDelegate = webView->historyDelegate(); if (historyDelegate) { String url(loader->urlForHistory().string()); String title(loader->title()); String redirectSource(loader->clientRedirectSourceForHistory()); OwnPtr<WebURLResponse> urlResponse(WebURLResponse::createInstance(loader->response())); OwnPtr<WebMutableURLRequest> urlRequest(WebMutableURLRequest::createInstance(loader->originalRequestCopy())); OwnPtr<WebNavigationData> navigationData(WebNavigationData::createInstance(url.utf8().data(), title.utf8().data(), urlRequest.get(), urlResponse.get(), loader->substituteData().isValid(), redirectSource.utf8().data())); historyDelegate->didNavigateWithNavigationData(webView, navigationData.get(), m_webFrame); return; } WebHistory* history = WebHistory::sharedHistory(); if (!history) return; history->visitedURL(strdup(loader->urlForHistory().string().utf8().data()), strdup(loader->title().utf8().data()), strdup(loader->originalRequestCopy().httpMethod().utf8().data()), loader->urlForHistoryReflectsFailure()); }