PolicyAction FrameLoaderClientBlackBerry::decidePolicyForExternalLoad(const ResourceRequest& request, bool isFragmentScroll) { #if 0 // FIXME: Enable these commented out when WebPageClient::handleStringPattern is implemented // and exposed to client. Before that, don't return PolicyIgnore so we can continue to // create new window and get to dispatchDecidePolicyForNavigationAction() where the client // is given a chance to decide how to handle patterns such as 'mailto:'. const KURL& url = request.url(); String pattern = m_webPagePrivate->findPatternStringForUrl(url); if (!pattern.isEmpty()) { m_webPagePrivate->m_client->handleStringPattern(pattern.characters(), pattern.length()); return PolicyIgnore; } #endif if (m_webPagePrivate->m_webSettings->areLinksHandledExternally() && isMainFrame() && !request.mustHandleInternally() && !isFragmentScroll) { NetworkRequest platformRequest; request.initializePlatformRequest(platformRequest, cookiesEnabled()); if (platformRequest.getTargetType() == NetworkRequest::TargetIsUnknown) platformRequest.setTargetType(isMainFrame() ? NetworkRequest::TargetIsMainFrame : NetworkRequest::TargetIsSubframe); m_webPagePrivate->m_client->handleExternalLink(platformRequest, request.anchorText().characters(), request.anchorText().length(), m_clientRedirectIsPending); return PolicyIgnore; } return PolicyUse; }
bool Navigator::cookieEnabled() const { if (m_frame->page() && !m_frame->page()->cookieEnabled()) return false; return cookiesEnabled(m_frame->document()); }
String cookies(Document const* document, KURL const& url) { // 'HttpOnly' cookies should no be accessible from scripts, so we filter them out here if (cookiesEnabled(document)) return cookieManager().getCookie(url, NoHttpOnlyCookie); return String(); }
void FrameLoaderClientBlackBerry::dispatchWillSendRequest(DocumentLoader* docLoader, long unsigned int, ResourceRequest& request, const ResourceResponse&) { // If the request is being loaded by the provisional document loader, then // it is a new top level request which has not been commited. bool isMainResourceLoad = docLoader && docLoader == docLoader->frameLoader()->provisionalDocumentLoader(); // TargetType for subresource loads should have been set in CachedResource::load(). if (isMainResourceLoad && request.targetType() == ResourceRequest::TargetIsUnspecified) request.setTargetType(isMainFrame() ? ResourceRequest::TargetIsMainFrame : ResourceRequest::TargetIsSubframe); // Any processing which is done for all loads (both main and subresource) should go here. NetworkRequest platformRequest; request.initializePlatformRequest(platformRequest, cookiesEnabled()); m_webPagePrivate->m_client->populateCustomHeaders(platformRequest); const NetworkRequest::HeaderList& headerLists = platformRequest.getHeaderListRef(); for (NetworkRequest::HeaderList::const_iterator it = headerLists.begin(); it != headerLists.end(); ++it) { std::string headerString = it->first; std::string headerValueString = it->second; request.setHTTPHeaderField(String::fromUTF8WithLatin1Fallback(headerString.data(), headerString.length()), String::fromUTF8WithLatin1Fallback(headerValueString.data(), headerValueString.length())); } if (!isMainResourceLoad) { // Do nothing for now. // Any processing which is done only for subresources should go here. return; } // All processing beyond this point is done only for main resource loads. if (m_clientRedirectIsPending && isMainFrame()) { String originalUrl = m_frame->document()->url().string(); String finalUrl = request.url().string(); m_webPagePrivate->m_client->notifyClientRedirect(originalUrl.characters(), originalUrl.length(), finalUrl.characters(), finalUrl.length()); } FrameLoader* loader = m_frame->loader(); ASSERT(loader); if (isBackForwardLoadType(loader->loadType())) { // Do not use the passed DocumentLoader because it is the loader that // will be used for the new request (the DESTINATION of the history // navigation - we want to use the current DocumentLoader to record the // SOURCE). DocumentLoader* docLoader = m_frame->loader()->documentLoader(); ASSERT(docLoader); m_historyNavigationSourceURLs.add(docLoader->url()); m_historyNavigationSourceURLs.add(docLoader->originalURL()); } }
bool WebSocketChannel::processBuffer() { ASSERT(!m_suspended); ASSERT(m_client); ASSERT(!m_buffer.isEmpty()); LOG(Network, "WebSocketChannel %p processBuffer() Receive buffer has %u bytes", this, static_cast<unsigned>(m_buffer.size())); if (m_shouldDiscardReceivedData) return false; if (m_receivedClosingHandshake) { skipBuffer(m_buffer.size()); return false; } Ref<WebSocketChannel> protectedThis(*this); // The client can close the channel, potentially removing the last reference. if (m_handshake->mode() == WebSocketHandshake::Incomplete) { int headerLength = m_handshake->readServerHandshake(m_buffer.data(), m_buffer.size()); if (headerLength <= 0) return false; if (m_handshake->mode() == WebSocketHandshake::Connected) { if (m_identifier) InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m_document, m_identifier, m_handshake->serverHandshakeResponse()); if (!m_handshake->serverSetCookie().isEmpty()) { if (m_document && cookiesEnabled(*m_document)) { // Exception (for sandboxed documents) ignored. m_document->setCookie(m_handshake->serverSetCookie()); } } // FIXME: handle set-cookie2. LOG(Network, "WebSocketChannel %p Connected", this); skipBuffer(headerLength); m_client->didConnect(); LOG(Network, "WebSocketChannel %p %u bytes remaining in m_buffer", this, static_cast<unsigned>(m_buffer.size())); return !m_buffer.isEmpty(); } ASSERT(m_handshake->mode() == WebSocketHandshake::Failed); LOG(Network, "WebSocketChannel %p Connection failed", this); skipBuffer(headerLength); m_shouldDiscardReceivedData = true; fail(m_handshake->failureReason()); return false; } if (m_handshake->mode() != WebSocketHandshake::Connected) return false; return processFrame(); }
bool WebSocketChannel::processBuffer() { ASSERT(!m_suspended); ASSERT(m_client); ASSERT(m_buffer); if (m_shouldDiscardReceivedData) return false; /// M: HTML5 web socket @{ RefPtr<WebSocketChannel> protect(this); // The client can close the channel, potentially removing the last reference. if (m_handshake->mode() == WebSocketHandshake::Incomplete) { int headerLength = m_handshake->readServerHandshake(m_buffer, m_bufferSize); if (headerLength <= 0) return false; if (m_handshake->mode() == WebSocketHandshake::Connected) { if (m_identifier) InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m_context, m_identifier, m_handshake->serverHandshakeResponse()); if (!m_handshake->serverSetCookie().isEmpty()) { if (m_context->isDocument()) { Document* document = static_cast<Document*>(m_context); if (cookiesEnabled(document)) { ExceptionCode ec; // Exception (for sandboxed documents) ignored. document->setCookie(m_handshake->serverSetCookie(), ec); } } } // FIXME: handle set-cookie2. LOG(Network, "WebSocketChannel %p connected", this); skipBuffer(headerLength); m_client->didConnect(); LOG(Network, "remaining in read buf %lu", static_cast<unsigned long>(m_bufferSize)); return m_buffer; } LOG(Network, "WebSocketChannel %p connection failed", this); skipBuffer(headerLength); m_shouldDiscardReceivedData = true; if (!m_closed) m_handle->close(); return false; } if (m_handshake->mode() != WebSocketHandshake::Connected) return false; /// @} /// M: HTML5 web socket return processFrame(); }
void FrameLoaderClientBlackBerry::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState>) { PolicyAction decision = PolicyIgnore; const KURL& url = request.url(); if (!url.isNull()) { // Fragment scrolls on the same page should always be handled internally. // (Only count as a fragment scroll if we are scrolling to a #fragment url, not back to the top, and reloading // the same url is not a fragment scroll even if it has a #fragment.) const KURL& currentUrl = m_frame->document()->url(); bool isFragmentScroll = url.hasFragmentIdentifier() && url != currentUrl && equalIgnoringFragmentIdentifier(currentUrl, url); decision = decidePolicyForExternalLoad(request, isFragmentScroll); // Let the client have a chance to say whether this navigation should // be ignored or not. NetworkRequest platformRequest; request.initializePlatformRequest(platformRequest, cookiesEnabled()); if (platformRequest.getTargetType() == NetworkRequest::TargetIsUnknown) platformRequest.setTargetType(isMainFrame() ? NetworkRequest::TargetIsMainFrame : NetworkRequest::TargetIsSubframe); if (isMainFrame() && !m_webPagePrivate->m_client->acceptNavigationRequest( platformRequest, BlackBerry::Platform::NavigationType(action.type()))) { if (action.type() == NavigationTypeFormSubmitted || action.type() == NavigationTypeFormResubmitted) m_frame->loader()->resetMultipleFormSubmissionProtection(); if (action.type() == NavigationTypeLinkClicked && url.hasFragmentIdentifier()) { ResourceRequest emptyRequest; m_frame->loader()->activeDocumentLoader()->setLastCheckedRequest(emptyRequest); } decision = PolicyIgnore; } } // If we abort here, dispatchDidCancelClientRedirect will not be called. // So call it by hand. if (decision == PolicyIgnore) dispatchDidCancelClientRedirect(); (m_frame->loader()->policyChecker()->*function)(decision); if (m_webPagePrivate->m_dumpRenderTree) m_webPagePrivate->m_dumpRenderTree->didDecidePolicyForNavigationAction(action, request); }
String cookieRequestHeaderFieldValue(const Document* document, const KURL &url) { if (cookiesEnabled(document)) return cookieManager().getCookie(url, WithHttpOnlyCookies); return String(); }
void setCookies(Document* document, KURL const& url, String const& value) { if (cookiesEnabled(document)) cookieManager().setCookies(url, value, NoHttpOnlyCookie); }
bool WebSocketChannel::processBuffer() { ASSERT(!m_suspended); ASSERT(m_client); ASSERT(m_buffer); if (m_shouldDiscardReceivedData) return false; if (m_handshake.mode() == WebSocketHandshake::Incomplete) { int headerLength = m_handshake.readServerHandshake(m_buffer, m_bufferSize); if (headerLength <= 0) return false; if (m_handshake.mode() == WebSocketHandshake::Connected) { if (m_identifier) InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m_context, m_identifier, m_handshake.serverHandshakeResponse()); if (!m_handshake.serverSetCookie().isEmpty()) { if (m_context->isDocument()) { Document* document = static_cast<Document*>(m_context); if (cookiesEnabled(document)) { ExceptionCode ec; // Exception (for sandboxed documents) ignored. document->setCookie(m_handshake.serverSetCookie(), ec); } } } // FIXME: handle set-cookie2. LOG(Network, "WebSocketChannel %p connected", this); skipBuffer(headerLength); m_client->didConnect(); LOG(Network, "remaining in read buf %lu", static_cast<unsigned long>(m_bufferSize)); return m_buffer; } LOG(Network, "WebSocketChannel %p connection failed", this); skipBuffer(headerLength); m_shouldDiscardReceivedData = true; if (!m_closed) m_handle->close(); return false; } if (m_handshake.mode() != WebSocketHandshake::Connected) return false; const char* nextFrame = m_buffer; const char* p = m_buffer; const char* end = p + m_bufferSize; unsigned char frameByte = static_cast<unsigned char>(*p++); if ((frameByte & 0x80) == 0x80) { size_t length = 0; bool errorFrame = false; while (p < end) { if (length > std::numeric_limits<size_t>::max() / 128) { LOG(Network, "frame length overflow %lu", static_cast<unsigned long>(length)); errorFrame = true; break; } size_t newLength = length * 128; unsigned char msgByte = static_cast<unsigned char>(*p); unsigned int lengthMsgByte = msgByte & 0x7f; if (newLength > std::numeric_limits<size_t>::max() - lengthMsgByte) { LOG(Network, "frame length overflow %lu+%u", static_cast<unsigned long>(newLength), lengthMsgByte); errorFrame = true; break; } newLength += lengthMsgByte; if (newLength < length) { // sanity check LOG(Network, "frame length integer wrap %lu->%lu", static_cast<unsigned long>(length), static_cast<unsigned long>(newLength)); errorFrame = true; break; } length = newLength; ++p; if (!(msgByte & 0x80)) break; } if (p + length < p) { LOG(Network, "frame buffer pointer wrap %p+%lu->%p", p, static_cast<unsigned long>(length), p + length); errorFrame = true; } if (errorFrame) { skipBuffer(m_bufferSize); // Save memory. m_shouldDiscardReceivedData = true; if (!m_client) return false; m_client->didReceiveMessageError(); if (!m_closed) m_handle->close(); return false; } ASSERT(p + length >= p); if (p + length < end) { p += length; nextFrame = p; ASSERT(nextFrame > m_buffer); skipBuffer(nextFrame - m_buffer); m_client->didReceiveMessageError(); return m_buffer; } return false; } const char* msgStart = p; while (p < end && *p != '\xff') ++p; if (p < end && *p == '\xff') { int msgLength = p - msgStart; ++p; nextFrame = p; if (frameByte == 0x00) { String msg = String::fromUTF8(msgStart, msgLength); skipBuffer(nextFrame - m_buffer); m_client->didReceiveMessage(msg); } else { skipBuffer(nextFrame - m_buffer); m_client->didReceiveMessageError(); } return m_buffer; } return false; }
bool HTTPSessionList::isAuthenticated(const String &sessionID, const String &ip, String &userName) { PEG_METHOD_ENTER(TRC_AUTHENTICATION, "HTTPSessionList::isAuthenticated"); HTTPSession *data; AutoMutex lock(_sessionsMutex); if (!cookiesEnabled()) { PEG_TRACE((TRC_AUTHENTICATION, Tracer::LEVEL3, "Rejected session %s from %s, sessions are disabled " "by configuration", (const char *) sessionID.getCString(), (const char *) ip.getCString())); PEG_METHOD_EXIT(); return false; } if (!_sessions.lookup(sessionID, data)) { PEG_TRACE((TRC_AUTHENTICATION, Tracer::LEVEL2, "Rejected unknown session %s from %s", (const char *) sessionID.getCString(), (const char *) ip.getCString())); PEG_METHOD_EXIT(); return false; } int timeout = _getSessionTimeout(); if (data->expired(timeout)) { PEG_TRACE((TRC_AUTHENTICATION, Tracer::LEVEL2, "Rejected expired session %s from %s", (const char *) sessionID.getCString(), (const char *) ip.getCString())); delete data; _sessions.remove(sessionID); PEG_METHOD_EXIT(); return false; } if (data->getIp() != ip) { PEG_TRACE((TRC_AUTHENTICATION, Tracer::LEVEL2, "Rejected session %s from wrong IP address %s (expected %s)", (const char *) sessionID.getCString(), (const char *) ip.getCString(), (const char *) data->getIp().getCString())); PEG_METHOD_EXIT(); return false; } userName = data->getUserName(); PEG_TRACE((TRC_AUTHENTICATION, Tracer::LEVEL3, "Accepted session %s from %s@%s", (const char *) sessionID.getCString(), (const char *) userName.getCString(), (const char *) ip.getCString())); PEG_METHOD_EXIT(); return true; }