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
134 void FrameLoaderClientWx::makeDocumentView()
140 void FrameLoaderClientWx::makeRepresentation(DocumentLoader*)
146 void FrameLoaderClientWx::forceLayout()
152 void FrameLoaderClientWx::forceLayoutForNonHTML()
158 void FrameLoaderClientWx::updateHistoryForCommit()
164 void FrameLoaderClientWx::updateHistoryForBackForwardNavigation()
170 void FrameLoaderClientWx::updateHistoryForReload()
176 void FrameLoaderClientWx::updateHistoryForStandardLoad()
182 void FrameLoaderClientWx::updateHistoryForInternalLoad()
188 void FrameLoaderClientWx::updateHistoryAfterClientRedirect()
194 void FrameLoaderClientWx::setCopiesOnScroll()
196 // apparently mac specific
201 LoadErrorResetToken* FrameLoaderClientWx::tokenForLoadErrorReset()
208 void FrameLoaderClientWx::resetAfterLoadError(LoadErrorResetToken*)
214 void FrameLoaderClientWx::doNotResetAfterLoadError(LoadErrorResetToken*)
220 void FrameLoaderClientWx::willCloseDocument()
226 void FrameLoaderClientWx::detachedFromParent1()
232 void FrameLoaderClientWx::detachedFromParent2()
238 void FrameLoaderClientWx::detachedFromParent3()
244 void FrameLoaderClientWx::detachedFromParent4()
250 void FrameLoaderClientWx::loadedFromCachedPage()
256 void FrameLoaderClientWx::dispatchDidHandleOnloadEvents()
262 void FrameLoaderClientWx::dispatchDidReceiveServerRedirectForProvisionalLoad()
268 void FrameLoaderClientWx::dispatchDidCancelClientRedirect()
274 void FrameLoaderClientWx::dispatchWillPerformClientRedirect(const KURL&,
282 void FrameLoaderClientWx::dispatchDidChangeLocationWithinPage()
288 void FrameLoaderClientWx::dispatchWillClose()
294 void FrameLoaderClientWx::dispatchDidStartProvisionalLoad()
296 wxWindow* target = m_frame->view()->nativeWindow();
298 wxWebViewStateChangedEvent wkEvent(target);
299 wkEvent.SetState(wxWEBVIEW_STATE_NEGOTIATING);
300 wkEvent.SetURL(m_frame->loader()->provisionalDocumentLoader()->request().url().url());
301 target->GetEventHandler()->ProcessEvent(wkEvent);
306 void FrameLoaderClientWx::dispatchDidReceiveTitle(const String& title)
308 wxWebView* target = static_cast<wxWebView*>(m_frame->view()->nativeWindow());
310 target->SetPageTitle(title);
314 void FrameLoaderClientWx::dispatchDidCommitLoad()
316 wxWindow* target = m_frame->view()->nativeWindow();
318 wxWebViewStateChangedEvent wkEvent(target);
319 wkEvent.SetState(wxWEBVIEW_STATE_TRANSFERRING);
320 wkEvent.SetURL(m_frame->loader()->documentLoader()->request().url().url());
321 target->GetEventHandler()->ProcessEvent(wkEvent);
325 void FrameLoaderClientWx::dispatchDidFinishDocumentLoad()
327 wxWindow* target = m_frame->view()->nativeWindow();
329 wxWebViewStateChangedEvent wkEvent(target);
330 wkEvent.SetState(wxWEBVIEW_STATE_STOP);
331 wkEvent.SetURL(m_frame->loader()->URL().url());
332 target->GetEventHandler()->ProcessEvent(wkEvent);
336 void FrameLoaderClientWx::dispatchDidFinishLoad()
342 void FrameLoaderClientWx::dispatchDidFirstLayout()
348 void FrameLoaderClientWx::dispatchShow()
354 void FrameLoaderClientWx::cancelPolicyCheck()
360 void FrameLoaderClientWx::dispatchWillSubmitForm(FramePolicyFunction function,
361 PassRefPtr<FormState>)
363 // FIXME: Send an event to allow for alerts and cancellation
366 (m_frame->loader()->*function)(PolicyUse);
370 void FrameLoaderClientWx::dispatchDidLoadMainResource(DocumentLoader*)
376 void FrameLoaderClientWx::revertToProvisionalState(DocumentLoader*)
382 void FrameLoaderClientWx::clearUnarchivingState(DocumentLoader*)
387 void FrameLoaderClientWx::postProgressStartedNotification()
392 void FrameLoaderClientWx::postProgressEstimateChangedNotification()
397 void FrameLoaderClientWx::postProgressFinishedNotification()
399 wxWindow* target = m_frame->view()->nativeWindow();
401 wxWebViewStateChangedEvent wkEvent(target);
402 wkEvent.SetState(wxWEBVIEW_STATE_STOP);
403 wkEvent.SetURL(m_frame->loader()->url().url());
404 target->GetEventHandler()->ProcessEvent(wkEvent);
408 void FrameLoaderClientWx::progressStarted()
414 void FrameLoaderClientWx::progressCompleted()
420 void FrameLoaderClientWx::setMainFrameDocumentReady(bool b)
423 // this is only interesting once we provide an external API for the DOM
427 void FrameLoaderClientWx::willChangeTitle(DocumentLoader*)
433 void FrameLoaderClientWx::didChangeTitle(DocumentLoader *l)
435 setTitle(l->title(), l->URL());
439 void FrameLoaderClientWx::finishedLoading(DocumentLoader*)
445 void FrameLoaderClientWx::finalSetupForReplace(DocumentLoader*)
451 void FrameLoaderClientWx::setDefersLoading(bool)
457 bool FrameLoaderClientWx::isArchiveLoadPending(ResourceLoader*) const
464 void FrameLoaderClientWx::cancelPendingArchiveLoad(ResourceLoader*)
470 void FrameLoaderClientWx::clearArchivedResources()
476 bool FrameLoaderClientWx::canShowMIMEType(const String& MIMEType) const
483 bool FrameLoaderClientWx::representationExistsForURLScheme(const String& URLScheme) const
490 String FrameLoaderClientWx::generatedMIMETypeForURLScheme(const String& URLScheme) const
497 void FrameLoaderClientWx::frameLoadCompleted()
502 void FrameLoaderClientWx::saveViewStateToItem(HistoryItem*)
507 void FrameLoaderClientWx::restoreViewState()
512 void FrameLoaderClientWx::restoreScrollPositionAndViewState()
518 void FrameLoaderClientWx::provisionalLoadStarted()
524 bool FrameLoaderClientWx::shouldTreatURLAsSameAsCurrent(const KURL&) const
531 void FrameLoaderClientWx::addHistoryItemForFragmentScroll()
537 void FrameLoaderClientWx::didFinishLoad()
543 void FrameLoaderClientWx::prepareForDataSourceReplacement()
545 if (m_frame && m_frame->loader())
546 m_frame->loader()->detachChildren();
550 void FrameLoaderClientWx::setTitle(const String& title, const KURL&)
556 String FrameLoaderClientWx::userAgent(const KURL&)
558 // FIXME: Use the new APIs introduced by the GTK port to fill in these values.
559 return String("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3");
562 void FrameLoaderClientWx::dispatchDidReceiveIcon()
567 void FrameLoaderClientWx::frameLoaderDestroyed()
573 bool FrameLoaderClientWx::canHandleRequest(const WebCore::ResourceRequest&) const
579 void FrameLoaderClientWx::partClearedInBegin()
584 void FrameLoaderClientWx::setDocumentViewFromCachedPage(WebCore::CachedPage*)
589 void FrameLoaderClientWx::updateGlobalHistoryForStandardLoad(const WebCore::KURL&)
594 void FrameLoaderClientWx::updateGlobalHistoryForReload(const WebCore::KURL&)
599 bool FrameLoaderClientWx::shouldGoToHistoryItem(WebCore::HistoryItem*) const
605 void FrameLoaderClientWx::saveScrollPositionAndViewStateToItem(WebCore::HistoryItem*)
610 void FrameLoaderClientWx::saveDocumentViewToCachedPage(WebCore::CachedPage*)
615 bool FrameLoaderClientWx::canCachePage() const
620 void FrameLoaderClientWx::setMainDocumentError(WebCore::DocumentLoader*, const WebCore::ResourceError&)
625 void FrameLoaderClientWx::committedLoad(WebCore::DocumentLoader* loader, const char* data, int length)
629 FrameLoader* fl = loader->frameLoader();
630 fl->setEncoding(m_response.textEncodingName(), false);
631 fl->addData(data, length);
634 WebCore::ResourceError FrameLoaderClientWx::cancelledError(const WebCore::ResourceRequest&)
637 return ResourceError();
640 WebCore::ResourceError FrameLoaderClientWx::blockedError(const ResourceRequest&)
643 return ResourceError();
646 WebCore::ResourceError FrameLoaderClientWx::cannotShowURLError(const WebCore::ResourceRequest&)
649 return ResourceError();
652 WebCore::ResourceError FrameLoaderClientWx::interruptForPolicyChangeError(const WebCore::ResourceRequest&)
655 return ResourceError();
658 WebCore::ResourceError FrameLoaderClientWx::cannotShowMIMETypeError(const WebCore::ResourceResponse&)
661 return ResourceError();
664 WebCore::ResourceError FrameLoaderClientWx::fileDoesNotExistError(const WebCore::ResourceResponse&)
667 return ResourceError();
670 bool FrameLoaderClientWx::shouldFallBack(const WebCore::ResourceError& error)
676 WTF::PassRefPtr<DocumentLoader> FrameLoaderClientWx::createDocumentLoader(const ResourceRequest& request, const SubstituteData& substituteData)
678 RefPtr<DocumentLoader> loader = new DocumentLoader(request, substituteData);
679 return loader.release();
682 void FrameLoaderClientWx::download(ResourceHandle*, const ResourceRequest&, const ResourceRequest&, const ResourceResponse&)
687 void FrameLoaderClientWx::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest&)
692 void FrameLoaderClientWx::dispatchWillSendRequest(DocumentLoader*, unsigned long, ResourceRequest& request, const ResourceResponse& response)
697 void FrameLoaderClientWx::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&)
702 void FrameLoaderClientWx::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&)
707 void FrameLoaderClientWx::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long id, const ResourceResponse& response)
710 m_response = response;
714 void FrameLoaderClientWx::dispatchDidReceiveContentLength(DocumentLoader* loader, unsigned long id, int length)
719 void FrameLoaderClientWx::dispatchDidFinishLoading(DocumentLoader*, unsigned long)
724 void FrameLoaderClientWx::dispatchDidFailLoading(DocumentLoader*, unsigned long, const ResourceError&)
729 bool FrameLoaderClientWx::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int)
735 void FrameLoaderClientWx::dispatchDidFailProvisionalLoad(const ResourceError&)
740 void FrameLoaderClientWx::dispatchDidFailLoad(const ResourceError&)
745 Frame* FrameLoaderClientWx::dispatchCreatePage()
751 void FrameLoaderClientWx::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const String& mimetype, const ResourceRequest& request)
757 (m_frame->loader()->*function)(PolicyUse);
760 void FrameLoaderClientWx::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction&, const ResourceRequest&, const String&)
766 (m_frame->loader()->*function)(PolicyUse);
769 void FrameLoaderClientWx::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request)
774 wxWindow* target = m_frame->view()->nativeWindow();
776 wxWebViewBeforeLoadEvent wkEvent(target);
777 wkEvent.SetNavigationType(wxNavTypeFromWebNavType(action.type()));
778 wkEvent.SetURL(request.url().url());
780 target->GetEventHandler()->ProcessEvent(wkEvent);
781 if (wkEvent.IsCancelled())
782 (m_frame->loader()->*function)(PolicyIgnore);
784 (m_frame->loader()->*function)(PolicyUse);
789 void FrameLoaderClientWx::dispatchUnableToImplementPolicy(const ResourceError&)
794 void FrameLoaderClientWx::startDownload(const ResourceRequest&)
799 bool FrameLoaderClientWx::willUseArchive(ResourceLoader*, const ResourceRequest&, const KURL&) const
805 PassRefPtr<Frame> FrameLoaderClientWx::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement,
806 const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight)
809 FIXME: Temporarily disabling code for loading subframes. While most
810 (i)frames load and are destroyed properly, the iframe created by
811 google.com in its new homepage does not get destroyed when
812 document()->detach() is called, as other (i)frames do. It is destroyed on
813 app shutdown, but until that point, this 'in limbo' frame will do things
814 like steal keyboard focus and crash when clicked on. (On some platforms,
815 it is actually a visible object, even though it's not in a valid state.)
817 Since just about every user is probably going to test against Google at
818 some point, I'm disabling this functionality until I have time to track down
819 why it is not being destroyed.
823 wxWindow* parent = m_frame->view()->nativeWindow();
825 WebViewFrameData* data = new WebViewFrameData();
827 data->ownerElement = ownerElement;
829 data->referrer = referrer;
830 data->marginWidth = marginWidth;
831 data->marginHeight = marginHeight;
833 wxWebView* newWin = new wxWebView(parent, -1, wxDefaultPosition, wxDefaultSize, data);
835 RefPtr<Frame> childFrame = newWin->m_impl->frame;
837 // FIXME: All of the below should probably be moved over into WebCore
838 childFrame->tree()->setName(name);
839 m_frame->tree()->appendChild(childFrame);
840 // ### set override encoding if we have one
842 FrameLoadType loadType = m_frame->loader()->loadType();
843 FrameLoadType childLoadType = FrameLoadTypeInternal;
845 childFrame->loader()->load(url, referrer, childLoadType,
848 // The frame's onload handler may have removed it from the document.
849 if (!childFrame->tree()->parent())
854 return childFrame.get();
860 ObjectContentType FrameLoaderClientWx::objectContentType(const KURL& url, const String& mimeType)
863 return ObjectContentType();
866 Widget* FrameLoaderClientWx::createPlugin(const IntSize&, Element*, const KURL&, const Vector<String>&, const Vector<String>&, const String&, bool loadManually)
872 void FrameLoaderClientWx::redirectDataToPlugin(Widget* pluginWidget)
878 Widget* FrameLoaderClientWx::createJavaAppletWidget(const IntSize&, Element*, const KURL& baseURL,
879 const Vector<String>& paramNames, const Vector<String>& paramValues)
885 String FrameLoaderClientWx::overrideMediaType() const
891 void FrameLoaderClientWx::windowObjectCleared()
896 void FrameLoaderClientWx::didPerformFirstNavigation() const
901 void FrameLoaderClientWx::registerForIconNotification(bool listen)