2 * Copyright (C) 2007 Kevin Ollivier <kevino@theolliviers.com>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "FrameLoaderClientWx.h"
31 #include "DocumentLoader.h"
33 #include "FrameLoaderTypes.h"
34 #include "FrameView.h"
35 #include "FrameTree.h"
36 #include "HTMLFormElement.h"
37 #include "NotImplemented.h"
39 #include "PlatformString.h"
40 #include "ProgressTracker.h"
41 #include "ResourceError.h"
42 #include "ResourceResponse.h"
47 #include "WebViewPrivate.h"
51 inline int wxNavTypeFromWebNavType(NavigationType type){
52 if (type == NavigationTypeLinkClicked)
53 return wxWEBVIEW_NAV_LINK_CLICKED;
55 if (type == NavigationTypeFormSubmitted)
56 return wxWEBVIEW_NAV_FORM_SUBMITTED;
58 if (type == NavigationTypeBackForward)
59 return wxWEBVIEW_NAV_BACK_NEXT;
61 if (type == NavigationTypeReload)
62 return wxWEBVIEW_NAV_RELOAD;
64 if (type == NavigationTypeFormResubmitted)
65 return wxWEBVIEW_NAV_FORM_RESUBMITTED;
67 return wxWEBVIEW_NAV_OTHER;
70 FrameLoaderClientWx::FrameLoaderClientWx()
76 FrameLoaderClientWx::~FrameLoaderClientWx()
80 void FrameLoaderClientWx::setFrame(Frame *frame)
85 void FrameLoaderClientWx::detachFrameLoader()
90 void FrameLoaderClientWx::ref()
92 RefCounted<FrameLoaderClientWx>::ref();
95 void FrameLoaderClientWx::deref()
97 RefCounted<FrameLoaderClientWx>::deref();
100 bool FrameLoaderClientWx::hasWebView() const
107 bool FrameLoaderClientWx::hasFrameView() const
114 bool FrameLoaderClientWx::hasBackForwardList() const
121 void FrameLoaderClientWx::resetBackForwardList()
127 bool FrameLoaderClientWx::provisionalItemIsTarget() const
133 void FrameLoaderClientWx::makeRepresentation(DocumentLoader*)
139 void FrameLoaderClientWx::forceLayout()
145 void FrameLoaderClientWx::forceLayoutForNonHTML()
151 void FrameLoaderClientWx::updateHistoryForCommit()
157 void FrameLoaderClientWx::updateHistoryForBackForwardNavigation()
163 void FrameLoaderClientWx::updateHistoryForReload()
169 void FrameLoaderClientWx::updateHistoryForStandardLoad()
175 void FrameLoaderClientWx::updateHistoryForInternalLoad()
181 void FrameLoaderClientWx::updateHistoryAfterClientRedirect()
187 void FrameLoaderClientWx::setCopiesOnScroll()
189 // apparently mac specific
194 LoadErrorResetToken* FrameLoaderClientWx::tokenForLoadErrorReset()
201 void FrameLoaderClientWx::resetAfterLoadError(LoadErrorResetToken*)
207 void FrameLoaderClientWx::doNotResetAfterLoadError(LoadErrorResetToken*)
213 void FrameLoaderClientWx::willCloseDocument()
219 void FrameLoaderClientWx::detachedFromParent1()
225 void FrameLoaderClientWx::detachedFromParent2()
231 void FrameLoaderClientWx::detachedFromParent3()
237 void FrameLoaderClientWx::detachedFromParent4()
243 void FrameLoaderClientWx::loadedFromCachedPage()
249 void FrameLoaderClientWx::dispatchDidHandleOnloadEvents()
255 void FrameLoaderClientWx::dispatchDidReceiveServerRedirectForProvisionalLoad()
261 void FrameLoaderClientWx::dispatchDidCancelClientRedirect()
267 void FrameLoaderClientWx::dispatchWillPerformClientRedirect(const KURL&,
275 void FrameLoaderClientWx::dispatchDidChangeLocationWithinPage()
281 void FrameLoaderClientWx::dispatchWillClose()
287 void FrameLoaderClientWx::dispatchDidStartProvisionalLoad()
289 wxWindow* target = m_frame->view()->nativeWindow();
291 wxWebViewStateChangedEvent wkEvent(target);
292 wkEvent.SetState(wxWEBVIEW_STATE_NEGOTIATING);
293 wkEvent.SetURL(m_frame->loader()->provisionalDocumentLoader()->request().url().string());
294 target->GetEventHandler()->ProcessEvent(wkEvent);
299 void FrameLoaderClientWx::dispatchDidReceiveTitle(const String& title)
301 wxWebView* target = static_cast<wxWebView*>(m_frame->view()->nativeWindow());
303 target->SetPageTitle(title);
307 void FrameLoaderClientWx::dispatchDidCommitLoad()
309 wxWindow* target = m_frame->view()->nativeWindow();
311 wxWebViewStateChangedEvent wkEvent(target);
312 wkEvent.SetState(wxWEBVIEW_STATE_TRANSFERRING);
313 wkEvent.SetURL(m_frame->loader()->documentLoader()->request().url().string());
314 target->GetEventHandler()->ProcessEvent(wkEvent);
318 void FrameLoaderClientWx::dispatchDidFinishDocumentLoad()
320 wxWindow* target = m_frame->view()->nativeWindow();
322 wxWebViewStateChangedEvent wkEvent(target);
323 wkEvent.SetState(wxWEBVIEW_STATE_STOP);
324 wkEvent.SetURL(m_frame->loader()->url().string());
325 target->GetEventHandler()->ProcessEvent(wkEvent);
329 void FrameLoaderClientWx::dispatchDidFinishLoad()
335 void FrameLoaderClientWx::dispatchDidFirstLayout()
341 void FrameLoaderClientWx::dispatchShow()
347 void FrameLoaderClientWx::cancelPolicyCheck()
353 void FrameLoaderClientWx::dispatchWillSubmitForm(FramePolicyFunction function,
354 PassRefPtr<FormState>)
356 // FIXME: Send an event to allow for alerts and cancellation
359 (m_frame->loader()->*function)(PolicyUse);
363 void FrameLoaderClientWx::dispatchDidLoadMainResource(DocumentLoader*)
369 void FrameLoaderClientWx::revertToProvisionalState(DocumentLoader*)
375 void FrameLoaderClientWx::clearUnarchivingState(DocumentLoader*)
380 void FrameLoaderClientWx::postProgressStartedNotification()
385 void FrameLoaderClientWx::postProgressEstimateChangedNotification()
390 void FrameLoaderClientWx::postProgressFinishedNotification()
392 wxWindow* target = m_frame->view()->nativeWindow();
394 wxWebViewStateChangedEvent wkEvent(target);
395 wkEvent.SetState(wxWEBVIEW_STATE_STOP);
396 wkEvent.SetURL(m_frame->loader()->url().string());
397 target->GetEventHandler()->ProcessEvent(wkEvent);
401 void FrameLoaderClientWx::progressStarted()
407 void FrameLoaderClientWx::progressCompleted()
413 void FrameLoaderClientWx::setMainFrameDocumentReady(bool b)
416 // this is only interesting once we provide an external API for the DOM
420 void FrameLoaderClientWx::willChangeTitle(DocumentLoader*)
426 void FrameLoaderClientWx::didChangeTitle(DocumentLoader *l)
428 setTitle(l->title(), l->url());
432 void FrameLoaderClientWx::finishedLoading(DocumentLoader*)
438 void FrameLoaderClientWx::finalSetupForReplace(DocumentLoader*)
444 void FrameLoaderClientWx::setDefersLoading(bool)
450 bool FrameLoaderClientWx::isArchiveLoadPending(ResourceLoader*) const
457 void FrameLoaderClientWx::cancelPendingArchiveLoad(ResourceLoader*)
463 void FrameLoaderClientWx::clearArchivedResources()
469 bool FrameLoaderClientWx::canShowMIMEType(const String& MIMEType) const
476 bool FrameLoaderClientWx::representationExistsForURLScheme(const String& URLScheme) const
483 String FrameLoaderClientWx::generatedMIMETypeForURLScheme(const String& URLScheme) const
490 void FrameLoaderClientWx::frameLoadCompleted()
495 void FrameLoaderClientWx::saveViewStateToItem(HistoryItem*)
500 void FrameLoaderClientWx::restoreViewState()
505 void FrameLoaderClientWx::restoreScrollPositionAndViewState()
511 void FrameLoaderClientWx::provisionalLoadStarted()
517 bool FrameLoaderClientWx::shouldTreatURLAsSameAsCurrent(const KURL&) const
524 void FrameLoaderClientWx::addHistoryItemForFragmentScroll()
530 void FrameLoaderClientWx::didFinishLoad()
536 void FrameLoaderClientWx::prepareForDataSourceReplacement()
538 if (m_frame && m_frame->loader())
539 m_frame->loader()->detachChildren();
543 void FrameLoaderClientWx::setTitle(const String& title, const KURL&)
549 String FrameLoaderClientWx::userAgent(const KURL&)
551 // FIXME: Use the new APIs introduced by the GTK port to fill in these values.
552 return String("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3");
555 void FrameLoaderClientWx::dispatchDidReceiveIcon()
560 void FrameLoaderClientWx::frameLoaderDestroyed()
566 bool FrameLoaderClientWx::canHandleRequest(const WebCore::ResourceRequest&) const
572 void FrameLoaderClientWx::partClearedInBegin()
577 void FrameLoaderClientWx::updateGlobalHistoryForStandardLoad(const WebCore::KURL&)
582 void FrameLoaderClientWx::updateGlobalHistoryForReload(const WebCore::KURL&)
587 bool FrameLoaderClientWx::shouldGoToHistoryItem(WebCore::HistoryItem*) const
593 void FrameLoaderClientWx::saveScrollPositionAndViewStateToItem(WebCore::HistoryItem*)
598 bool FrameLoaderClientWx::canCachePage() const
603 void FrameLoaderClientWx::setMainDocumentError(WebCore::DocumentLoader*, const WebCore::ResourceError&)
608 void FrameLoaderClientWx::committedLoad(WebCore::DocumentLoader* loader, const char* data, int length)
612 FrameLoader* fl = loader->frameLoader();
613 fl->setEncoding(m_response.textEncodingName(), false);
614 fl->addData(data, length);
617 WebCore::ResourceError FrameLoaderClientWx::cancelledError(const WebCore::ResourceRequest&)
620 return ResourceError();
623 WebCore::ResourceError FrameLoaderClientWx::blockedError(const ResourceRequest&)
626 return ResourceError();
629 WebCore::ResourceError FrameLoaderClientWx::cannotShowURLError(const WebCore::ResourceRequest&)
632 return ResourceError();
635 WebCore::ResourceError FrameLoaderClientWx::interruptForPolicyChangeError(const WebCore::ResourceRequest&)
638 return ResourceError();
641 WebCore::ResourceError FrameLoaderClientWx::cannotShowMIMETypeError(const WebCore::ResourceResponse&)
644 return ResourceError();
647 WebCore::ResourceError FrameLoaderClientWx::fileDoesNotExistError(const WebCore::ResourceResponse&)
650 return ResourceError();
653 bool FrameLoaderClientWx::shouldFallBack(const WebCore::ResourceError& error)
659 WTF::PassRefPtr<DocumentLoader> FrameLoaderClientWx::createDocumentLoader(const ResourceRequest& request, const SubstituteData& substituteData)
661 RefPtr<DocumentLoader> loader = new DocumentLoader(request, substituteData);
662 return loader.release();
665 void FrameLoaderClientWx::download(ResourceHandle*, const ResourceRequest&, const ResourceRequest&, const ResourceResponse&)
670 void FrameLoaderClientWx::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest&)
675 void FrameLoaderClientWx::dispatchWillSendRequest(DocumentLoader*, unsigned long, ResourceRequest& request, const ResourceResponse& response)
680 void FrameLoaderClientWx::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&)
685 void FrameLoaderClientWx::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&)
690 void FrameLoaderClientWx::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long id, const ResourceResponse& response)
693 m_response = response;
697 void FrameLoaderClientWx::dispatchDidReceiveContentLength(DocumentLoader* loader, unsigned long id, int length)
702 void FrameLoaderClientWx::dispatchDidFinishLoading(DocumentLoader*, unsigned long)
707 void FrameLoaderClientWx::dispatchDidFailLoading(DocumentLoader*, unsigned long, const ResourceError&)
712 bool FrameLoaderClientWx::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int)
718 void FrameLoaderClientWx::dispatchDidFailProvisionalLoad(const ResourceError&)
723 void FrameLoaderClientWx::dispatchDidFailLoad(const ResourceError&)
728 Frame* FrameLoaderClientWx::dispatchCreatePage()
734 void FrameLoaderClientWx::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const String& mimetype, const ResourceRequest& request)
740 (m_frame->loader()->*function)(PolicyUse);
743 void FrameLoaderClientWx::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction&, const ResourceRequest&, const String&)
749 (m_frame->loader()->*function)(PolicyUse);
752 void FrameLoaderClientWx::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request)
757 wxWindow* target = m_frame->view()->nativeWindow();
759 wxWebViewBeforeLoadEvent wkEvent(target);
760 wkEvent.SetNavigationType(wxNavTypeFromWebNavType(action.type()));
761 wkEvent.SetURL(request.url().string());
763 target->GetEventHandler()->ProcessEvent(wkEvent);
764 if (wkEvent.IsCancelled())
765 (m_frame->loader()->*function)(PolicyIgnore);
767 (m_frame->loader()->*function)(PolicyUse);
772 void FrameLoaderClientWx::dispatchUnableToImplementPolicy(const ResourceError&)
777 void FrameLoaderClientWx::startDownload(const ResourceRequest&)
782 bool FrameLoaderClientWx::willUseArchive(ResourceLoader*, const ResourceRequest&, const KURL&) const
788 PassRefPtr<Frame> FrameLoaderClientWx::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement,
789 const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight)
792 FIXME: Temporarily disabling code for loading subframes. While most
793 (i)frames load and are destroyed properly, the iframe created by
794 google.com in its new homepage does not get destroyed when
795 document()->detach() is called, as other (i)frames do. It is destroyed on
796 app shutdown, but until that point, this 'in limbo' frame will do things
797 like steal keyboard focus and crash when clicked on. (On some platforms,
798 it is actually a visible object, even though it's not in a valid state.)
800 Since just about every user is probably going to test against Google at
801 some point, I'm disabling this functionality until I have time to track down
802 why it is not being destroyed.
806 wxWindow* parent = m_frame->view()->nativeWindow();
808 WebViewFrameData* data = new WebViewFrameData();
810 data->ownerElement = ownerElement;
812 data->referrer = referrer;
813 data->marginWidth = marginWidth;
814 data->marginHeight = marginHeight;
816 wxWebView* newWin = new wxWebView(parent, -1, wxDefaultPosition, wxDefaultSize, data);
818 RefPtr<Frame> childFrame = newWin->m_impl->frame;
820 // FIXME: All of the below should probably be moved over into WebCore
821 childFrame->tree()->setName(name);
822 m_frame->tree()->appendChild(childFrame);
823 // ### set override encoding if we have one
825 FrameLoadType loadType = m_frame->loader()->loadType();
826 FrameLoadType childLoadType = FrameLoadTypeInternal;
828 childFrame->loader()->load(url, referrer, childLoadType,
831 // The frame's onload handler may have removed it from the document.
832 if (!childFrame->tree()->parent())
837 return childFrame.get();
843 ObjectContentType FrameLoaderClientWx::objectContentType(const KURL& url, const String& mimeType)
846 return ObjectContentType();
849 Widget* FrameLoaderClientWx::createPlugin(const IntSize&, Element*, const KURL&, const Vector<String>&, const Vector<String>&, const String&, bool loadManually)
855 void FrameLoaderClientWx::redirectDataToPlugin(Widget* pluginWidget)
861 Widget* FrameLoaderClientWx::createJavaAppletWidget(const IntSize&, Element*, const KURL& baseURL,
862 const Vector<String>& paramNames, const Vector<String>& paramValues)
868 String FrameLoaderClientWx::overrideMediaType() const
874 void FrameLoaderClientWx::windowObjectCleared()
879 void FrameLoaderClientWx::didPerformFirstNavigation() const
884 void FrameLoaderClientWx::registerForIconNotification(bool listen)
889 void FrameLoaderClientWx::savePlatformDataToCachedPage(CachedPage*)
894 void FrameLoaderClientWx::transitionToCommittedFromCachedPage(CachedPage*)
899 void FrameLoaderClientWx::transitionToCommittedForNewPage()