FrameLoaderClientBlackBerry.cpp [plain text]
#include "config.h"
#include "FrameLoaderClientBlackBerry.h"
#include "AboutData.h"
#include "AutofillManager.h"
#include "BackForwardController.h"
#include "BackingStoreClient.h"
#include "BackingStore_p.h"
#include "BlobStream.h"
#include "CredentialManager.h"
#include "CredentialTransformData.h"
#include "DumpRenderTreeClient.h"
#include "FrameLoadRequest.h"
#include "FrameNetworkingContextBlackBerry.h"
#include "FrameView.h"
#include "HTMLHeadElement.h"
#include "HTMLLinkElement.h"
#include "HTMLMediaElement.h"
#include "HTMLMetaElement.h"
#include "HTMLNames.h"
#include "HTMLPlugInElement.h"
#include "HTTPParsers.h"
#include "HistoryController.h"
#include "HistoryItem.h"
#include "IconDatabase.h"
#include "Image.h"
#include "InputHandler.h"
#include "MIMETypeRegistry.h"
#include "NetworkManager.h"
#include "NodeList.h"
#include "PNGImageEncoder.h"
#include "Page.h"
#include "PluginDatabase.h"
#include "PluginView.h"
#include "ProgressTracker.h"
#include "ResourceBuffer.h"
#include "ScopePointer.h"
#include "SelectionHandler.h"
#if ENABLE(BLACKBERRY_CREDENTIAL_PERSIST)
#include "Settings.h"
#endif
#include "SharedBuffer.h"
#include "TextEncoding.h"
#include "TouchEventHandler.h"
#include "WebPageClient.h"
#include <BlackBerryPlatformExecutableMessage.h>
#include <BlackBerryPlatformLog.h>
#include <BlackBerryPlatformMessageClient.h>
#include <BlackBerryPlatformScreen.h>
#include <BlackBerryPlatformStringBuilder.h>
#include <JavaScriptCore/APICast.h>
#include <TiledImage.h>
#include <network/DataStream.h>
#include <network/FilterStream.h>
#include <network/NetworkRequest.h>
#include <wtf/text/Base64.h>
using WTF::String;
using namespace WebCore;
using namespace BlackBerry::WebKit;
using BlackBerry::Platform::NetworkRequest;
enum {
WebKitErrorCannotShowMIMEType = 100,
WebKitErrorCannotShowURL = 101,
WebKitErrorFrameLoadInterruptedByPolicyChange = 102,
WebKitErrorCannotUseRestrictedPort = 103,
WebKitErrorCannotFindPlugIn = 200,
WebKitErrorCannotLoadPlugIn = 201,
WebKitErrorJavaUnavailable = 202,
WebKitErrorPluginWillHandleLoad = 203
};
namespace WebCore {
FrameLoaderClientBlackBerry::FrameLoaderClientBlackBerry()
: m_frame(0)
, m_webPagePrivate(0)
, m_sentReadyToRender(false)
, m_pendingFragmentScrollPolicyFunction(0)
, m_loadingErrorPage(false)
, m_clientRedirectIsPending(false)
, m_childFrameCreationSuppressed(false)
, m_pluginView(0)
, m_hasSentResponseToPlugin(false)
, m_cancelLoadOnNextData(false)
, m_wasProvisionalLoadTriggeredByUserGesture(true) {
}
FrameLoaderClientBlackBerry::~FrameLoaderClientBlackBerry()
{
}
int FrameLoaderClientBlackBerry::playerId() const
{
return m_webPagePrivate ? m_webPagePrivate->playerID() : 0;
}
bool FrameLoaderClientBlackBerry::cookiesEnabled() const
{
return m_webPagePrivate->m_webSettings->areCookiesEnabled();
}
void FrameLoaderClientBlackBerry::dispatchDidChangeLocationWithinPage()
{
if (!isMainFrame())
return;
String url = m_frame->document()->url().string();
String token = m_frame->loader()->documentLoader()->request().token();
m_webPagePrivate->m_client->notifyLoadToAnchor(url.characters(), url.length(), token.characters(), token.length());
}
void FrameLoaderClientBlackBerry::dispatchDidPushStateWithinPage()
{
dispatchDidChangeLocationWithinPage();
}
void FrameLoaderClientBlackBerry::dispatchDidReplaceStateWithinPage()
{
dispatchDidChangeLocationWithinPage();
}
void FrameLoaderClientBlackBerry::dispatchDidPopStateWithinPage()
{
}
void FrameLoaderClientBlackBerry::dispatchDidCancelClientRedirect()
{
m_clientRedirectIsPending = false;
}
void FrameLoaderClientBlackBerry::dispatchWillPerformClientRedirect(const KURL&, double, double)
{
if (m_webPagePrivate->m_dumpRenderTree)
m_webPagePrivate->m_dumpRenderTree->didDispatchWillPerformClientRedirect();
m_clientRedirectIsPending = true;
}
void FrameLoaderClientBlackBerry::dispatchDecidePolicyForResponse(FramePolicyFunction function, const ResourceResponse& response, const ResourceRequest& request)
{
PolicyAction policy = PolicyIgnore;
if (contentDispositionType(response.httpHeaderField("Content-Disposition")) == ContentDispositionAttachment
|| request.forceDownload())
policy = PolicyDownload;
else if (canShowMIMEType(response.mimeType()))
policy = PolicyUse;
else if (ResourceRequest::TargetIsMainFrame == request.targetType() && m_webPagePrivate->m_client->downloadAllowed(request.url().string()))
policy = PolicyDownload;
if (m_webPagePrivate->m_dumpRenderTree)
m_webPagePrivate->m_dumpRenderTree->didDecidePolicyForResponse(response);
(m_frame->loader()->policyChecker()->*function)(policy);
}
void FrameLoaderClientBlackBerry::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState>)
{
PolicyAction decision = PolicyIgnore;
const KURL& url = request.url();
if (!url.isNull()) {
const KURL& currentUrl = m_frame->document()->url();
bool isFragmentScroll = url.hasFragmentIdentifier() && url != currentUrl && equalIgnoringFragmentIdentifier(currentUrl, url);
decision = decidePolicyForExternalLoad(request, isFragmentScroll);
NetworkRequest platformRequest;
request.initializePlatformRequest(platformRequest, cookiesEnabled());
if (!platformRequest.getUrlRef().empty()) { if (platformRequest.getTargetType() == NetworkRequest::TargetIsUnknown)
platformRequest.setTargetType(isMainFrame() ? NetworkRequest::TargetIsMainFrame : NetworkRequest::TargetIsSubframe);
if (!m_webPagePrivate->m_client->acceptNavigationRequest(platformRequest, BlackBerry::Platform::NavigationType(action.type()))) {
decision = PolicyIgnore;
if (isMainFrame()) {
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);
}
}
}
}
}
if (decision == PolicyIgnore)
dispatchDidCancelClientRedirect();
if (m_webPagePrivate->m_dumpRenderTree)
m_webPagePrivate->m_dumpRenderTree->didDecidePolicyForNavigationAction(action, request, m_frame);
(m_frame->loader()->policyChecker()->*function)(decision);
}
void FrameLoaderClientBlackBerry::delayPolicyCheckUntilFragmentExists(const String& fragment, FramePolicyFunction function)
{
ASSERT(isMainFrame());
if (m_webPagePrivate->loadState() < WebPagePrivate::Finished && !m_frame->document()->findAnchor(fragment)) {
m_webPagePrivate->m_client->needMoreData();
m_pendingFragmentScrollPolicyFunction = function;
m_pendingFragmentScroll = fragment;
return;
}
(m_frame->loader()->policyChecker()->*function)(PolicyUse);
}
void FrameLoaderClientBlackBerry::cancelPolicyCheck()
{
m_pendingFragmentScrollPolicyFunction = 0;
m_pendingFragmentScroll = String();
}
void FrameLoaderClientBlackBerry::doPendingFragmentScroll()
{
if (m_pendingFragmentScroll.isNull())
return;
String fragment = m_pendingFragmentScroll;
m_pendingFragmentScroll = String();
FramePolicyFunction function = m_pendingFragmentScrollPolicyFunction;
m_pendingFragmentScrollPolicyFunction = 0;
delayPolicyCheckUntilFragmentExists(fragment, function);
}
void FrameLoaderClientBlackBerry::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction&, const ResourceRequest& request, PassRefPtr<FormState>, const String&)
{
if (ScriptController::processingUserGesture() && !m_webPagePrivate->m_pluginMayOpenNewTab) {
(m_frame->loader()->policyChecker()->*function)(PolicyIgnore);
return;
}
PolicyAction decision = decidePolicyForExternalLoad(request, false);
(m_frame->loader()->policyChecker()->*function)(decision);
}
void FrameLoaderClientBlackBerry::committedLoad(DocumentLoader* loader, const char* data, int length)
{
if (!m_pluginView)
receivedData(loader, data, length);
if (m_pluginView) {
if (!m_hasSentResponseToPlugin) {
m_pluginView->didReceiveResponse(loader->response());
m_hasSentResponseToPlugin = true;
}
if (!m_pluginView)
return;
m_pluginView->didReceiveData(data, length);
}
}
bool FrameLoaderClientBlackBerry::shouldAlwaysUsePluginDocument(const String& mimeType) const
{
return mimeType == "application/x-shockwave-flash";
}
PassRefPtr<Widget> FrameLoaderClientBlackBerry::createPlugin(const IntSize& pluginSize,
HTMLPlugInElement* element, const KURL& url, const Vector<String>& paramNames,
const Vector<String>& paramValues, const String& mimeTypeIn, bool loadManually)
{
String mimeType(mimeTypeIn);
if (mimeType.isEmpty()) {
mimeType = MIMETypeRegistry::getMIMETypeForPath(url.path());
mimeType = MIMETypeRegistry::getNormalizedMIMEType(mimeType);
if (!shouldAlwaysUsePluginDocument(mimeType))
mimeType = mimeTypeIn;
}
if (PluginDatabase::installedPlugins()->isMIMETypeRegistered(mimeType))
return PluginView::create(m_frame, pluginSize, element, url, paramNames, paramValues, mimeType, loadManually);
if (!shouldAlwaysUsePluginDocument(mimeType) && m_frame->loader() && m_frame->loader()->subframeLoader() && !url.isNull())
m_frame->loader()->subframeLoader()->requestFrame(element, url, String());
return 0;
}
void FrameLoaderClientBlackBerry::redirectDataToPlugin(Widget* pluginWidget)
{
m_pluginView = toPluginView(pluginWidget);
if (pluginWidget)
m_hasSentResponseToPlugin = false;
}
void FrameLoaderClientBlackBerry::receivedData(DocumentLoader* loader, const char* data, int length)
{
if (!m_frame)
return;
if (m_cancelLoadOnNextData) {
m_frame->loader()->activeDocumentLoader()->stopLoading();
m_frame->loader()->documentLoader()->writer()->end();
m_cancelLoadOnNextData = false;
return;
}
loader->commitData(data, length);
}
void FrameLoaderClientBlackBerry::finishedLoading(DocumentLoader*)
{
if (m_pluginView) {
if (m_hasSentResponseToPlugin)
m_pluginView->didFinishLoading();
m_pluginView = 0;
m_hasSentResponseToPlugin = false;
}
}
PassRefPtr<DocumentLoader> FrameLoaderClientBlackBerry::createDocumentLoader(const ResourceRequest& request, const SubstituteData& substituteData)
{
ResourceRequest newRequest(request);
if (m_frame && m_frame->loader() && m_frame->loader()->documentLoader()) {
const ResourceRequest& originalRequest = m_frame->loader()->documentLoader()->originalRequest();
if (request.token().isNull() && !originalRequest.token().isNull())
newRequest.setToken(originalRequest.token());
}
SubstituteData substituteDataLocal = substituteData;
if (isMainFrame()) {
String source;
if (request.url().protocolIs("about")) {
String aboutWhat = request.url().string().substring(6);
source = aboutData(aboutWhat);
}
if (!source.isEmpty()) {
WTF::RefPtr<SharedBuffer> buffer = SharedBuffer::create(source.is8Bit() ? reinterpret_cast<const char*>(source.characters8()) : source.latin1().data(), source.length());
substituteDataLocal = SubstituteData(buffer, "text/html", "latin1", KURL());
}
}
RefPtr<DocumentLoader> loader = DocumentLoader::create(newRequest, substituteDataLocal);
if (substituteDataLocal.isValid())
loader->setDeferMainResourceDataLoad(false);
return loader.release();
}
void FrameLoaderClientBlackBerry::frameLoaderDestroyed()
{
delete this;
}
void FrameLoaderClientBlackBerry::transitionToCommittedForNewPage()
{
m_cancelLoadOnNextData = false;
if (isMainFrame() && m_webPagePrivate->backingStoreClient()) {
m_webPagePrivate->backingStoreClient()->backingStore()->d->suspendBackingStoreUpdates();
m_webPagePrivate->backingStoreClient()->backingStore()->d->suspendScreenUpdates();
}
if (m_frame->document())
m_webPagePrivate->clearDocumentData(m_frame->document());
Color backgroundColor(m_webPagePrivate->m_webSettings->backgroundColor());
m_frame->createView(m_webPagePrivate->viewportSize(),
backgroundColor,
backgroundColor.hasAlpha(),
m_webPagePrivate->actualVisibleSize(),
m_webPagePrivate->fixedLayoutSize(),
IntRect(),
m_webPagePrivate->useFixedLayout(),
ScrollbarAlwaysOff,
true,
ScrollbarAlwaysOff,
true);
if (isMainFrame() && m_webPagePrivate->backingStoreClient()) {
m_webPagePrivate->backingStoreClient()->backingStore()->d->resumeBackingStoreUpdates();
m_webPagePrivate->backingStoreClient()->backingStore()->d->resumeScreenUpdates(BackingStore::None);
}
m_frame->view()->updateCanHaveScrollbars();
if (isMainFrame()) {
m_frame->view()->setPaintsEntireContents(true);
}
}
String FrameLoaderClientBlackBerry::userAgent(const KURL&)
{
return m_webPagePrivate->m_webSettings->userAgentString();
}
bool FrameLoaderClientBlackBerry::canHandleRequest(const ResourceRequest&) const
{
return true;
}
bool FrameLoaderClientBlackBerry::canShowMIMEType(const String& mimeTypeIn) const
{
String mimeType = MIMETypeRegistry::getNormalizedMIMEType(mimeTypeIn);
return MIMETypeRegistry::canShowMIMEType(mimeType)
|| WebSettings::isSupportedObjectMIMEType(mimeType)
|| (mimeType == "application/x-shockwave-flash");
}
bool FrameLoaderClientBlackBerry::canShowMIMETypeAsHTML(const String&) const
{
return true;
}
bool FrameLoaderClientBlackBerry::isMainFrame() const
{
return m_webPagePrivate && m_frame == m_webPagePrivate->m_mainFrame;
}
void FrameLoaderClientBlackBerry::dispatchDidStartProvisionalLoad()
{
if (isMainFrame())
m_webPagePrivate->setLoadState(WebPagePrivate::Provisional);
if (m_webPagePrivate->m_dumpRenderTree)
m_webPagePrivate->m_dumpRenderTree->didStartProvisionalLoadForFrame(m_frame);
m_wasProvisionalLoadTriggeredByUserGesture = ScriptController::processingUserGesture();
}
void FrameLoaderClientBlackBerry::dispatchDidReceiveResponse(DocumentLoader*, unsigned long, const ResourceResponse& response)
{
if (m_webPagePrivate->m_dumpRenderTree)
m_webPagePrivate->m_dumpRenderTree->didReceiveResponseForFrame(m_frame, response);
}
void FrameLoaderClientBlackBerry::dispatchDidReceiveTitle(const StringWithDirection& title)
{
if (isMainFrame())
m_webPagePrivate->m_client->setPageTitle(title.string().characters(), title.string().length());
if (m_webPagePrivate->m_dumpRenderTree)
m_webPagePrivate->m_dumpRenderTree->didReceiveTitleForFrame(title.string(), m_frame);
}
void FrameLoaderClientBlackBerry::setTitle(const StringWithDirection& , const KURL& )
{
notImplemented();
}
void FrameLoaderClientBlackBerry::dispatchDidCommitLoad()
{
if (isMainFrame()) {
m_webPagePrivate->setLoadState(WebPagePrivate::Committed);
String originalUrl = m_frame->loader()->documentLoader()->originalRequest().url().string();
String url = m_frame->loader()->documentLoader()->request().url().string();
String token = m_frame->loader()->documentLoader()->request().token();
if (m_loadingErrorPage) {
m_loadingErrorPage = false;
if (HistoryItem* item = m_frame->loader()->history()->currentItem())
item->viewState().shouldSaveViewState = false;
m_webPagePrivate->m_client->notifyLoadFailedBeforeCommit(
originalUrl.characters(), originalUrl.length(),
url.characters(), url.length(), token.characters(), token.length());
} else {
m_webPagePrivate->m_client->notifyLoadCommitted(
originalUrl.characters(), originalUrl.length(),
url.characters(), url.length(), token.characters(), token.length());
HistoryItem* currentItem = m_frame->loader()->history()->currentItem();
if (currentItem && currentItem->isInPageCache())
dispatchDidReceiveIcon();
}
}
if (m_webPagePrivate->m_dumpRenderTree)
m_webPagePrivate->m_dumpRenderTree->didCommitLoadForFrame(m_frame);
}
void FrameLoaderClientBlackBerry::dispatchDidHandleOnloadEvents()
{
if (!m_frame->page())
return;
m_webPagePrivate->m_client->notifyDocumentOnLoad(isMainFrame());
if (m_webPagePrivate->m_dumpRenderTree)
m_webPagePrivate->m_dumpRenderTree->didHandleOnloadEventsForFrame(m_frame);
}
void FrameLoaderClientBlackBerry::dispatchDidFinishLoad()
{
didFinishOrFailLoading(ResourceError());
if (m_webPagePrivate->m_dumpRenderTree)
m_webPagePrivate->m_dumpRenderTree->didFinishLoadForFrame(m_frame);
if (!isMainFrame() || m_webPagePrivate->m_webSettings->isEmailMode()
|| !m_frame->document() || !m_frame->document()->head())
return;
HTMLHeadElement* headElement = m_frame->document()->head();
RefPtr<NodeList> nodeList = headElement->getElementsByTagName(HTMLNames::metaTag.localName());
unsigned size = nodeList->length();
ScopeArray<BlackBerry::Platform::String> headers;
headers.reset(new BlackBerry::Platform::String[2 * size]);
unsigned headersLength = 0;
for (unsigned i = 0; i < size; ++i) {
HTMLMetaElement* metaElement = static_cast<HTMLMetaElement*>(nodeList->item(i));
if (WTF::equalIgnoringCase(metaElement->name(), "apple-mobile-web-app-capable")
&& WTF::equalIgnoringCase(metaElement->content().stripWhiteSpace(), "yes"))
m_webPagePrivate->m_client->setWebAppCapable();
else {
String httpEquiv = metaElement->httpEquiv().stripWhiteSpace();
String content = metaElement->content().stripWhiteSpace();
if (!httpEquiv.isNull() && !content.isNull()) {
headers[headersLength++] = httpEquiv;
headers[headersLength++] = content;
}
}
}
if (headersLength > 0)
m_webPagePrivate->m_client->setMetaHeaders(headers, headersLength);
nodeList = headElement->getElementsByTagName(HTMLNames::linkTag.localName());
size = nodeList->length();
for (unsigned i = 0; i < size; ++i) {
HTMLLinkElement* linkElement = static_cast<HTMLLinkElement*>(nodeList->item(i));
String href = linkElement->href().string();
if (!href.isEmpty()) {
String title = linkElement->title();
if (WTF::equalIgnoringCase(linkElement->rel(), "apple-touch-icon"))
m_webPagePrivate->m_client->setLargeIcon(href);
else if (WTF::equalIgnoringCase(linkElement->rel(), "search")) {
if (WTF::equalIgnoringCase(linkElement->type(), "application/opensearchdescription+xml"))
m_webPagePrivate->m_client->setSearchProviderDetails(title, href);
} else if (WTF::equalIgnoringCase(linkElement->rel(), "alternate")
&& (WTF::equalIgnoringCase(linkElement->type(), "application/rss+xml")
|| WTF::equalIgnoringCase(linkElement->type(), "application/atom+xml")))
m_webPagePrivate->m_client->setAlternateFeedDetails(title, href);
}
}
#if ENABLE(BLACKBERRY_CREDENTIAL_PERSIST)
if (m_webPagePrivate->m_webSettings->isFormAutofillEnabled()
&& m_webPagePrivate->m_webSettings->isCredentialAutofillEnabled()
&& !m_webPagePrivate->m_webSettings->isPrivateBrowsingEnabled())
credentialManager().autofillPasswordForms(m_frame->document()->forms());
#endif
m_webPagePrivate->m_inputHandler->focusedNodeChanged();
}
void FrameLoaderClientBlackBerry::dispatchDidFinishDocumentLoad()
{
if (m_webPagePrivate->m_dumpRenderTree)
m_webPagePrivate->m_dumpRenderTree->didFinishDocumentLoadForFrame(m_frame);
notImplemented();
}
void FrameLoaderClientBlackBerry::dispatchDidFailLoad(const ResourceError& error)
{
didFinishOrFailLoading(error);
if (m_webPagePrivate->m_dumpRenderTree)
m_webPagePrivate->m_dumpRenderTree->didFailLoadForFrame(m_frame);
}
void FrameLoaderClientBlackBerry::didFinishOrFailLoading(const ResourceError& error)
{
m_redirectURLsToSkipDueToHistoryNavigation.swap(m_historyNavigationSourceURLs);
m_historyNavigationSourceURLs.clear();
if (isMainFrame()) {
m_loadError = error;
m_webPagePrivate->setLoadState(error.isNull() ? WebPagePrivate::Finished : WebPagePrivate::Failed);
}
}
void FrameLoaderClientBlackBerry::dispatchDidFailProvisionalLoad(const ResourceError& error)
{
if (isMainFrame()) {
m_loadError = error;
m_webPagePrivate->setLoadState(WebPagePrivate::Failed);
if (error.domain() == ResourceError::platformErrorDomain
&& (error.errorCode() == BlackBerry::Platform::FilterStream::StatusErrorAlreadyHandled)) {
return;
}
if (error.domain().isEmpty() && !error.errorCode() && error.failingURL().isEmpty() && error.localizedDescription().isEmpty()) {
return;
}
}
if (m_webPagePrivate->m_dumpRenderTree)
m_webPagePrivate->m_dumpRenderTree->didFailProvisionalLoadForFrame(m_frame);
if (!isMainFrame())
return;
if (error.domain() == ResourceError::platformErrorDomain
&& (error.errorCode() == BlackBerry::Platform::FilterStream::StatusDeniedByApplication)) {
return;
}
if (!m_frame->loader()->provisionalDocumentLoader())
return;
ResourceRequest originalRequest = m_frame->loader()->provisionalDocumentLoader()->originalRequest();
if (originalRequest.forceDownload())
return;
String errorPage = m_webPagePrivate->m_client->getErrorPage(error.errorCode(), error.localizedDescription(), error.failingURL());
SubstituteData errorData(utf8Buffer(errorPage), "text/html", "utf-8", KURL(KURL(), error.failingURL()));
if (isBackForwardLoadType(m_frame->loader()->loadType())) {
m_frame->loader()->history()->saveScrollPositionAndViewStateToItem(m_frame->loader()->history()->currentItem());
ASSERT(m_frame->loader()->history()->provisionalItem());
m_frame->loader()->history()->provisionalItem()->viewState().shouldSaveViewState = false;
}
m_webPagePrivate->m_client->cancelSelectionVisuals();
m_loadingErrorPage = true;
m_frame->loader()->load(FrameLoadRequest(m_frame, originalRequest, errorData));
}
void FrameLoaderClientBlackBerry::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState>)
{
(m_frame->loader()->policyChecker()->*function)(PolicyUse);
#if ENABLE(BLACKBERRY_CREDENTIAL_PERSIST)
if (m_formCredentials.isValid())
credentialManager().saveCredentialIfConfirmed(m_webPagePrivate, m_formCredentials);
#endif
}
void FrameLoaderClientBlackBerry::dispatchWillSendSubmitEvent(PassRefPtr<FormState> prpFormState)
{
#if ENABLE(BLACKBERRY_CREDENTIAL_PERSIST)
m_formCredentials = CredentialTransformData();
#endif
if (!m_webPagePrivate->m_webSettings->isPrivateBrowsingEnabled()) {
if (m_webPagePrivate->m_webSettings->isFormAutofillEnabled()) {
m_webPagePrivate->m_autofillManager->saveTextFields(prpFormState->form());
#if ENABLE(BLACKBERRY_CREDENTIAL_PERSIST)
if (m_webPagePrivate->m_webSettings->isCredentialAutofillEnabled())
m_formCredentials = CredentialTransformData(prpFormState->form(), true);
#endif
}
}
}
PassRefPtr<Frame> FrameLoaderClientBlackBerry::createFrame(const KURL& url, const String& name
, HTMLFrameOwnerElement* ownerElement, const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight)
{
if (!m_webPagePrivate)
return 0;
if (m_childFrameCreationSuppressed)
return 0;
FrameLoaderClientBlackBerry* frameLoaderClient = new FrameLoaderClientBlackBerry();
RefPtr<Frame> childFrame = Frame::create(m_frame->page(), ownerElement, frameLoaderClient);
frameLoaderClient->setFrame(childFrame.get(), m_webPagePrivate);
RefPtr<FrameView> frameView = FrameView::create(childFrame.get());
childFrame->setView(frameView.get());
if (!allowsScrolling)
frameView->setScrollbarModes(ScrollbarAlwaysOff, ScrollbarAlwaysOff);
if (marginWidth != -1)
frameView->setMarginWidth(marginWidth);
if (marginHeight != -1)
frameView->setMarginHeight(marginHeight);
childFrame->tree()->setName(name);
m_frame->tree()->appendChild(childFrame);
childFrame->init();
if (!childFrame->tree()->parent())
return 0;
m_frame->loader()->loadURLIntoChildFrame(url, referrer, childFrame.get());
if (!childFrame->tree()->parent())
return 0;
return childFrame.release();
}
ObjectContentType FrameLoaderClientBlackBerry::objectContentType(const KURL& url, const String& mimeTypeIn, bool shouldPreferPlugInsForImages)
{
String mimeType = mimeTypeIn;
if (mimeType.isEmpty())
mimeType = MIMETypeRegistry::getMIMETypeForPath(url.path());
mimeType = MIMETypeRegistry::getNormalizedMIMEType(mimeType);
ObjectContentType defaultType = FrameLoader::defaultObjectContentType(url, mimeType, shouldPreferPlugInsForImages);
if (defaultType != ObjectContentNone)
return defaultType;
if (WebSettings::isSupportedObjectMIMEType(mimeType))
return ObjectContentOtherPlugin;
return ObjectContentNone;
}
void FrameLoaderClientBlackBerry::dispatchWillClose()
{
m_webPagePrivate->frameUnloaded(m_frame);
}
void FrameLoaderClientBlackBerry::setMainDocumentError(DocumentLoader*, const ResourceError& error)
{
if (!m_pluginView)
return;
m_pluginView->didFail(error);
m_pluginView = 0;
m_hasSentResponseToPlugin = false;
}
void FrameLoaderClientBlackBerry::postProgressStartedNotification()
{
if (!isMainFrame())
return;
m_loadError = ResourceError();
m_sentReadyToRender = false;
m_webPagePrivate->m_client->notifyLoadStarted();
}
void FrameLoaderClientBlackBerry::postProgressEstimateChangedNotification()
{
if (!isMainFrame() || !m_frame->page())
return;
m_webPagePrivate->m_client->notifyLoadProgress(m_frame->page()->progress()->estimatedProgress() * 100);
}
void FrameLoaderClientBlackBerry::dispatchDidLayout(LayoutMilestones milestones)
{
if (!isMainFrame())
return;
if (milestones & DidFirstVisuallyNonEmptyLayout) {
BBLOG(BlackBerry::Platform::LogLevelInfo, "dispatchDidFirstVisuallyNonEmptyLayout");
readyToRender(true);
FrameLoadType frameLoadType = m_frame->loader()->loadType();
if (m_webPagePrivate->loadState() == WebPagePrivate::Finished && (frameLoadType == FrameLoadTypeSame || frameLoadType == FrameLoadTypeStandard))
m_webPagePrivate->setShouldZoomToInitialScaleAfterLoadFinished(true);
if (m_webPagePrivate->shouldZoomToInitialScaleOnLoad()) {
BackingStorePrivate* backingStorePrivate = m_webPagePrivate->m_backingStore->d;
m_webPagePrivate->zoomToInitialScaleOnLoad(); backingStorePrivate->renderAndBlitVisibleContentsImmediately();
}
m_webPagePrivate->m_client->notifyFirstVisuallyNonEmptyLayout();
}
}
void FrameLoaderClientBlackBerry::postProgressFinishedNotification()
{
if (!isMainFrame())
return;
readyToRender(false);
m_webPagePrivate->m_client->notifyLoadFinished(m_loadError.isNull() ? 0 : m_loadError.errorCode());
m_webPagePrivate->notifyPageOnLoad();
}
void FrameLoaderClientBlackBerry::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world)
{
if (world != mainThreadNormalWorld())
return;
m_webPagePrivate->m_client->notifyWindowObjectCleared();
if (m_webPagePrivate->m_dumpRenderTree) {
JSGlobalContextRef context = toGlobalRef(m_frame->script()->globalObject(mainThreadNormalWorld())->globalExec());
JSObjectRef windowObject = toRef(m_frame->script()->globalObject(mainThreadNormalWorld()));
ASSERT(windowObject);
m_webPagePrivate->m_dumpRenderTree->didClearWindowObjectInWorld(world, context, windowObject);
}
}
bool FrameLoaderClientBlackBerry::shouldGoToHistoryItem(HistoryItem*) const
{
return true;
}
bool FrameLoaderClientBlackBerry::shouldStopLoadingForHistoryItem(HistoryItem*) const
{
return true;
}
Frame* FrameLoaderClientBlackBerry::dispatchCreatePage(const NavigationAction& navigation)
{
WebPage* webPage = m_webPagePrivate->m_client->createWindow(0, 0, -1, -1, WebPageClient::FlagWindowDefault, navigation.url().string(), BlackBerry::Platform::String::emptyString(), m_frame->document()->url().string(), ScriptController::processingUserGesture());
if (!webPage)
return 0;
return webPage->d->m_page->mainFrame();
}
void FrameLoaderClientBlackBerry::detachedFromParent2()
{
if (!m_webPagePrivate)
return;
if (m_frame->document())
m_webPagePrivate->clearDocumentData(m_frame->document());
m_webPagePrivate->frameUnloaded(m_frame);
m_webPagePrivate->m_client->notifyFrameDetached(m_frame);
m_webPagePrivate = 0;
}
void FrameLoaderClientBlackBerry::dispatchWillSendRequest(DocumentLoader* docLoader, long unsigned, ResourceRequest& request, const ResourceResponse&)
{
bool isMainResourceLoad = docLoader && docLoader == docLoader->frameLoader()->provisionalDocumentLoader();
if (isMainResourceLoad)
request.setTargetType(docLoader->frameLoader()->isLoadingMainFrame() ? ResourceRequest::TargetIsMainFrame : ResourceRequest::TargetIsSubframe);
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) {
BlackBerry::Platform::String headerString = it->first;
BlackBerry::Platform::String headerValueString = it->second;
request.setHTTPHeaderField(String::fromUTF8WithLatin1Fallback(headerString.data(), headerString.length()), String::fromUTF8WithLatin1Fallback(headerValueString.data(), headerValueString.length()));
}
if (!isMainResourceLoad) {
return;
}
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())) {
DocumentLoader* docLoader = m_frame->loader()->documentLoader();
ASSERT(docLoader);
m_historyNavigationSourceURLs.add(docLoader->url());
m_historyNavigationSourceURLs.add(docLoader->originalURL());
}
}
bool FrameLoaderClientBlackBerry::shouldUseCredentialStorage(DocumentLoader*, long unsigned)
{
#if ENABLE(BLACKBERRY_CREDENTIAL_PERSIST)
if (m_frame->page()->settings()->privateBrowsingEnabled())
return false;
return true;
#else
return false;
#endif
}
void FrameLoaderClientBlackBerry::loadIconExternally(const String& originalPageUrl, const String& finalPageUrl, const String& iconUrl)
{
m_webPagePrivate->m_client->setIconForUrl(originalPageUrl, finalPageUrl, iconUrl);
}
void FrameLoaderClientBlackBerry::saveViewStateToItem(HistoryItem* item)
{
if (!isMainFrame())
return;
ASSERT(item);
HistoryItemViewState& viewState = item->viewState();
if (viewState.shouldSaveViewState) {
viewState.orientation = m_webPagePrivate->mainFrame()->orientation();
viewState.isZoomToFitScale = fabsf(m_webPagePrivate->currentScale() - m_webPagePrivate->zoomToFitScale()) < 0.01;
viewState.scale = m_webPagePrivate->currentScale();
viewState.shouldReflowBlock = m_webPagePrivate->m_shouldReflowBlock;
viewState.minimumScale = m_webPagePrivate->m_minimumScale;
viewState.maximumScale = m_webPagePrivate->m_maximumScale;
viewState.isUserScalable = m_webPagePrivate->m_userScalable;
viewState.webPageClientState = m_webPagePrivate->m_client->serializePageCacheState();
}
}
void FrameLoaderClientBlackBerry::restoreViewState()
{
if (!isMainFrame())
return;
HistoryItem* currentItem = m_frame->loader()->history()->currentItem();
ASSERT(currentItem);
if (!currentItem)
return;
HistoryItemViewState& viewState = currentItem->viewState();
if (!viewState.shouldSaveViewState)
return;
m_webPagePrivate->m_client->deserializePageCacheState(viewState.webPageClientState);
IntPoint scrollPosition = currentItem->scrollPoint();
if (m_webPagePrivate->m_userPerformedManualScroll)
scrollPosition = m_webPagePrivate->scrollPosition();
m_webPagePrivate->m_didRestoreFromPageCache = false;
m_webPagePrivate->m_minimumScale = viewState.minimumScale;
m_webPagePrivate->m_maximumScale = viewState.maximumScale;
m_webPagePrivate->m_userScalable = viewState.isUserScalable;
double scale = viewState.scale;
bool shouldReflowBlock = viewState.shouldReflowBlock;
if (m_webPagePrivate->m_userPerformedManualZoom) {
scale = m_webPagePrivate->currentScale();
shouldReflowBlock = m_webPagePrivate->m_shouldReflowBlock;
}
bool scrollChanged = scrollPosition != m_webPagePrivate->scrollPosition();
bool scaleChanged = scale != m_webPagePrivate->currentScale();
bool reflowChanged = shouldReflowBlock != m_webPagePrivate->m_shouldReflowBlock;
bool orientationChanged = viewState.orientation % 180 != m_webPagePrivate->mainFrame()->orientation() % 180;
m_webPagePrivate->m_inputHandler->restoreViewState();
if (!scrollChanged && !scaleChanged && !reflowChanged && !orientationChanged)
return;
if (orientationChanged && viewState.isZoomToFitScale && !m_webPagePrivate->hasVirtualViewport())
scale = BlackBerry::Platform::Graphics::Screen::primaryScreen()->width() * scale / static_cast<double>(BlackBerry::Platform::Graphics::Screen::primaryScreen()->height());
m_webPagePrivate->m_backingStore->d->suspendBackingStoreUpdates();
m_webPagePrivate->m_backingStore->d->suspendScreenUpdates();
BlackBerry::Platform::webKitThreadMessageClient()->dispatchMessage(BlackBerry::Platform::createMethodCallMessage(
&WebPagePrivate::restoreHistoryViewState, m_webPagePrivate, scrollPosition, scale, viewState.shouldReflowBlock));
}
PolicyAction FrameLoaderClientBlackBerry::decidePolicyForExternalLoad(const ResourceRequest& request, bool isFragmentScroll)
{
#if 0
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;
}
void FrameLoaderClientBlackBerry::willDeferLoading()
{
if (!isMainFrame())
return;
m_webPagePrivate->willDeferLoading();
}
void FrameLoaderClientBlackBerry::didResumeLoading()
{
if (!isMainFrame())
return;
m_webPagePrivate->didResumeLoading();
}
void FrameLoaderClientBlackBerry::readyToRender(bool pageIsVisuallyNonEmpty)
{
if (!m_sentReadyToRender) {
m_webPagePrivate->m_client->notifyLoadReadyToRender(pageIsVisuallyNonEmpty);
m_sentReadyToRender = true;
}
}
PassRefPtr<FrameNetworkingContext> FrameLoaderClientBlackBerry::createNetworkingContext()
{
return FrameNetworkingContextBlackBerry::create(m_frame);
}
void FrameLoaderClientBlackBerry::startDownload(const ResourceRequest& request, const String& suggestedName)
{
ResourceRequest requestCopy = request;
requestCopy.setSuggestedSaveName(suggestedName);
requestCopy.setForceDownload(true);
m_webPagePrivate->m_mainFrame->loader()->load(FrameLoadRequest(m_webPagePrivate->m_mainFrame, requestCopy));
}
void FrameLoaderClientBlackBerry::convertMainResourceLoadToDownload(DocumentLoader* documentLoader, const ResourceRequest& request, const ResourceResponse& response)
{
ASSERT(documentLoader);
ResourceBuffer* buff = documentLoader->mainResourceData().get();
BlackBerry::Platform::String filename = response.suggestedFilename();
if (filename.empty())
filename = request.suggestedSaveName();
if (!buff) {
ASSERT(documentLoader->mainResourceLoader() && documentLoader->mainResourceLoader()->handle());
ResourceHandle* handle = documentLoader->mainResourceLoader()->handle();
BlackBerry::Platform::FilterStream* stream = NetworkManager::instance()->streamForHandle(handle);
if (!stream)
stream = new BlobStream(response, handle);
ASSERT(stream);
m_webPagePrivate->m_client->downloadRequested(stream, filename);
return;
}
BlackBerry::Platform::StringBuilder url;
STATIC_LOCAL_STRING(s_create, "data:");
url.append(s_create);
url.append(BlackBerry::Platform::String::fromUtf8(response.mimeType().utf8().data()));
STATIC_LOCAL_STRING(s_base64, ";base64,");
url.append(s_base64);
url.append(BlackBerry::Platform::String::fromUtf8(base64Encode(CString(buff->data(), buff->size())).utf8().data()));
NetworkRequest netRequest;
netRequest.setRequestUrl(url.string());
BlackBerry::Platform::DataStream *stream = new BlackBerry::Platform::DataStream(netRequest);
m_webPagePrivate->m_client->downloadRequested(stream, filename);
stream->streamOpen();
}
void FrameLoaderClientBlackBerry::dispatchDidReceiveIcon()
{
String url = m_frame->document()->url().string();
NativeImagePtr bitmap = iconDatabase().synchronousNativeIconForPageURL(url, IntSize(10, 10));
if (!bitmap || bitmap->isNull())
return;
int dataSize = bitmap->width() * bitmap->height();
Vector<unsigned> data;
data.reserveCapacity(dataSize);
if (!bitmap->readPixels(data.data(), dataSize))
return;
unsigned char* pixels = reinterpret_cast<unsigned char*>(data.data());
for (int i = 0; i < bitmap->height(); ++i) {
unsigned char* bgra = pixels + i * bitmap->width() * 4;
for (int j = 0; j < bitmap->width(); ++j, bgra += 4)
std::swap(bgra[0], bgra[2]);
}
Vector<char> pngData;
if (!compressRGBABigEndianToPNG(pixels, bitmap->size(), pngData))
return;
Vector<char> out;
base64Encode(pngData, out);
String iconUrl = iconDatabase().synchronousIconURLForPageURL(url);
m_webPagePrivate->m_client->setFavicon(BlackBerry::Platform::String::fromAscii(out.data(), out.size()), iconUrl);
}
bool FrameLoaderClientBlackBerry::canCachePage() const
{
ASSERT(m_frame->loader()->documentLoader());
const ResponseVector& responses = m_frame->loader()->documentLoader()->responses();
size_t count = responses.size();
for (size_t i = 0; i < count; i++) {
if (responses[i].isMultipartPayload())
return false;
}
return true;
}
void FrameLoaderClientBlackBerry::didSaveToPageCache()
{
m_webPagePrivate->clearDocumentData(m_frame->document());
if (!isMainFrame()) {
m_webPagePrivate = 0;
}
}
void FrameLoaderClientBlackBerry::provisionalLoadStarted()
{
if (isMainFrame())
m_webPagePrivate->showVirtualKeyboard(false);
}
ResourceError FrameLoaderClientBlackBerry::cannotShowURLError(const ResourceRequest& request)
{
return ResourceError("WebKitErrorDomain", WebKitErrorCannotShowURL, request.url().string(), String());
}
void FrameLoaderClientBlackBerry::didRestoreFromPageCache()
{
if (!isMainFrame()) {
m_webPagePrivate = static_cast<FrameLoaderClientBlackBerry*>(m_frame->page()->mainFrame()->loader()->client())->m_webPagePrivate;
}
m_webPagePrivate->m_didRestoreFromPageCache = true;
}
void FrameLoaderClientBlackBerry::dispatchWillUpdateApplicationCache(const ResourceRequest&)
{
ASSERT(isMainFrame());
if (!isMainFrame())
return;
m_webPagePrivate->m_client->notifyWillUpdateApplicationCache();
}
void FrameLoaderClientBlackBerry::dispatchDidLoadFromApplicationCache(const ResourceRequest&)
{
ASSERT(isMainFrame());
if (!isMainFrame())
return;
m_webPagePrivate->m_client->notifyDidLoadFromApplicationCache();
}
PassRefPtr<SecurityOrigin> FrameLoaderClientBlackBerry::securityOriginForNewDocument(const KURL& url)
{
RefPtr<SecurityOrigin> newSecurityOrigin = SecurityOrigin::create(url);
if (m_wasProvisionalLoadTriggeredByUserGesture || !url.isLocalFile())
return newSecurityOrigin;
RefPtr<SecurityOrigin> currentSecurityOrigin = m_frame->document()->securityOrigin();
if (currentSecurityOrigin && currentSecurityOrigin->containsInFolder(newSecurityOrigin.get()))
return currentSecurityOrigin;
return newSecurityOrigin;
}
}