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()
71 : RefCounted<FrameLoaderClientWx>(0)
77 FrameLoaderClientWx::~FrameLoaderClientWx()
81 void FrameLoaderClientWx::setFrame(Frame *frame)
86 void FrameLoaderClientWx::detachFrameLoader()
91 void FrameLoaderClientWx::ref()
93 RefCounted<FrameLoaderClientWx>::ref();
96 void FrameLoaderClientWx::deref()
98 RefCounted<FrameLoaderClientWx>::deref();
101 bool FrameLoaderClientWx::hasWebView() const
108 bool FrameLoaderClientWx::hasFrameView() const
115 bool FrameLoaderClientWx::hasBackForwardList() const
122 void FrameLoaderClientWx::resetBackForwardList()
128 bool FrameLoaderClientWx::provisionalItemIsTarget() const
134 void FrameLoaderClientWx::makeRepresentation(DocumentLoader*)
140 void FrameLoaderClientWx::forceLayout()
146 void FrameLoaderClientWx::forceLayoutForNonHTML()
152 void FrameLoaderClientWx::updateHistoryForCommit()
158 void FrameLoaderClientWx::updateHistoryForBackForwardNavigation()
164 void FrameLoaderClientWx::updateHistoryForReload()
170 void FrameLoaderClientWx::updateHistoryForStandardLoad()
176 void FrameLoaderClientWx::updateHistoryForInternalLoad()
182 void FrameLoaderClientWx::updateHistoryAfterClientRedirect()
188 void FrameLoaderClientWx::setCopiesOnScroll()
190 // apparently mac specific
195 LoadErrorResetToken* FrameLoaderClientWx::tokenForLoadErrorReset()
202 void FrameLoaderClientWx::resetAfterLoadError(LoadErrorResetToken*)
208 void FrameLoaderClientWx::doNotResetAfterLoadError(LoadErrorResetToken*)
214 void FrameLoaderClientWx::willCloseDocument()
220 void FrameLoaderClientWx::detachedFromParent1()
226 void FrameLoaderClientWx::detachedFromParent2()
232 void FrameLoaderClientWx::detachedFromParent3()
238 void FrameLoaderClientWx::detachedFromParent4()
244 void FrameLoaderClientWx::loadedFromCachedPage()
250 void FrameLoaderClientWx::dispatchDidHandleOnloadEvents()
252 wxWindow* target = m_frame->view()->nativeWindow();
254 wxWebViewLoadEvent wkEvent(target);
255 wkEvent.SetState(wxWEBVIEW_LOAD_ONLOAD_HANDLED);
256 wkEvent.SetURL(m_frame->loader()->documentLoader()->request().url().string());
257 target->GetEventHandler()->ProcessEvent(wkEvent);
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 wxWebViewLoadEvent wkEvent(target);
299 wkEvent.SetState(wxWEBVIEW_LOAD_NEGOTIATING);
300 wkEvent.SetURL(m_frame->loader()->provisionalDocumentLoader()->request().url().string());
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 wxWebViewLoadEvent wkEvent(target);
319 wkEvent.SetState(wxWEBVIEW_LOAD_TRANSFERRING);
320 wkEvent.SetURL(m_frame->loader()->documentLoader()->request().url().string());
321 target->GetEventHandler()->ProcessEvent(wkEvent);
325 void FrameLoaderClientWx::dispatchDidFinishDocumentLoad()
327 wxWindow* target = m_frame->view()->nativeWindow();
329 wxWebViewLoadEvent wkEvent(target);
330 wkEvent.SetState(wxWEBVIEW_LOAD_DOC_COMPLETED);
331 wkEvent.SetURL(m_frame->loader()->url().string());
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*)
381 void FrameLoaderClientWx::postProgressStartedNotification()
386 void FrameLoaderClientWx::postProgressEstimateChangedNotification()
391 void FrameLoaderClientWx::postProgressFinishedNotification()
393 wxWindow* target = m_frame->view()->nativeWindow();
395 wxWebViewLoadEvent wkEvent(target);
396 wkEvent.SetState(wxWEBVIEW_LOAD_DL_COMPLETED);
397 wkEvent.SetURL(m_frame->loader()->url().string());
398 target->GetEventHandler()->ProcessEvent(wkEvent);
402 void FrameLoaderClientWx::progressStarted()
408 void FrameLoaderClientWx::progressCompleted()
414 void FrameLoaderClientWx::setMainFrameDocumentReady(bool b)
417 // this is only interesting once we provide an external API for the DOM
421 void FrameLoaderClientWx::willChangeTitle(DocumentLoader*)
427 void FrameLoaderClientWx::didChangeTitle(DocumentLoader *l)
429 setTitle(l->title(), l->url());
433 void FrameLoaderClientWx::finishedLoading(DocumentLoader*)
439 bool FrameLoaderClientWx::canShowMIMEType(const String& MIMEType) const
446 bool FrameLoaderClientWx::representationExistsForURLScheme(const String& URLScheme) const
453 String FrameLoaderClientWx::generatedMIMETypeForURLScheme(const String& URLScheme) const
460 void FrameLoaderClientWx::frameLoadCompleted()
465 void FrameLoaderClientWx::saveViewStateToItem(HistoryItem*)
470 void FrameLoaderClientWx::restoreViewState()
475 void FrameLoaderClientWx::restoreScrollPositionAndViewState()
481 void FrameLoaderClientWx::provisionalLoadStarted()
487 bool FrameLoaderClientWx::shouldTreatURLAsSameAsCurrent(const KURL&) const
494 void FrameLoaderClientWx::addHistoryItemForFragmentScroll()
500 void FrameLoaderClientWx::didFinishLoad()
506 void FrameLoaderClientWx::prepareForDataSourceReplacement()
508 if (m_frame && m_frame->loader())
509 m_frame->loader()->detachChildren();
513 void FrameLoaderClientWx::setTitle(const String& title, const KURL&)
519 String FrameLoaderClientWx::userAgent(const KURL&)
521 // FIXME: Use the new APIs introduced by the GTK port to fill in these values.
522 return String("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3");
525 void FrameLoaderClientWx::dispatchDidReceiveIcon()
530 void FrameLoaderClientWx::frameLoaderDestroyed()
536 bool FrameLoaderClientWx::canHandleRequest(const WebCore::ResourceRequest&) const
542 void FrameLoaderClientWx::partClearedInBegin()
547 void FrameLoaderClientWx::updateGlobalHistory(const WebCore::KURL&)
552 bool FrameLoaderClientWx::shouldGoToHistoryItem(WebCore::HistoryItem*) const
558 void FrameLoaderClientWx::saveScrollPositionAndViewStateToItem(WebCore::HistoryItem*)
563 bool FrameLoaderClientWx::canCachePage() const
568 void FrameLoaderClientWx::setMainDocumentError(WebCore::DocumentLoader*, const WebCore::ResourceError&)
573 void FrameLoaderClientWx::committedLoad(WebCore::DocumentLoader* loader, const char* data, int length)
577 FrameLoader* fl = loader->frameLoader();
578 fl->setEncoding(m_response.textEncodingName(), false);
579 fl->addData(data, length);
582 WebCore::ResourceError FrameLoaderClientWx::cancelledError(const WebCore::ResourceRequest&)
585 return ResourceError();
588 WebCore::ResourceError FrameLoaderClientWx::blockedError(const ResourceRequest&)
591 return ResourceError();
594 WebCore::ResourceError FrameLoaderClientWx::cannotShowURLError(const WebCore::ResourceRequest&)
597 return ResourceError();
600 WebCore::ResourceError FrameLoaderClientWx::interruptForPolicyChangeError(const WebCore::ResourceRequest&)
603 return ResourceError();
606 WebCore::ResourceError FrameLoaderClientWx::cannotShowMIMETypeError(const WebCore::ResourceResponse&)
609 return ResourceError();
612 WebCore::ResourceError FrameLoaderClientWx::fileDoesNotExistError(const WebCore::ResourceResponse&)
615 return ResourceError();
618 bool FrameLoaderClientWx::shouldFallBack(const WebCore::ResourceError& error)
624 WTF::PassRefPtr<DocumentLoader> FrameLoaderClientWx::createDocumentLoader(const ResourceRequest& request, const SubstituteData& substituteData)
626 RefPtr<DocumentLoader> loader = new DocumentLoader(request, substituteData);
627 return loader.release();
630 void FrameLoaderClientWx::download(ResourceHandle*, const ResourceRequest&, const ResourceRequest&, const ResourceResponse&)
635 void FrameLoaderClientWx::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest&)
640 void FrameLoaderClientWx::dispatchWillSendRequest(DocumentLoader*, unsigned long, ResourceRequest& request, const ResourceResponse& response)
645 void FrameLoaderClientWx::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&)
650 void FrameLoaderClientWx::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&)
655 void FrameLoaderClientWx::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long id, const ResourceResponse& response)
658 m_response = response;
662 void FrameLoaderClientWx::dispatchDidReceiveContentLength(DocumentLoader* loader, unsigned long id, int length)
667 void FrameLoaderClientWx::dispatchDidFinishLoading(DocumentLoader*, unsigned long)
672 void FrameLoaderClientWx::dispatchDidFailLoading(DocumentLoader*, unsigned long, const ResourceError&)
677 bool FrameLoaderClientWx::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int)
683 void FrameLoaderClientWx::dispatchDidFailProvisionalLoad(const ResourceError&)
688 void FrameLoaderClientWx::dispatchDidFailLoad(const ResourceError&)
693 Frame* FrameLoaderClientWx::dispatchCreatePage()
699 void FrameLoaderClientWx::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const String& mimetype, const ResourceRequest& request)
705 (m_frame->loader()->*function)(PolicyUse);
708 void FrameLoaderClientWx::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction&, const ResourceRequest&, const String&)
714 (m_frame->loader()->*function)(PolicyUse);
717 void FrameLoaderClientWx::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request)
722 wxWindow* target = m_frame->view()->nativeWindow();
724 wxWebViewBeforeLoadEvent wkEvent(target);
725 wkEvent.SetNavigationType(wxNavTypeFromWebNavType(action.type()));
726 wkEvent.SetURL(request.url().string());
728 target->GetEventHandler()->ProcessEvent(wkEvent);
729 if (wkEvent.IsCancelled())
730 (m_frame->loader()->*function)(PolicyIgnore);
732 (m_frame->loader()->*function)(PolicyUse);
737 void FrameLoaderClientWx::dispatchUnableToImplementPolicy(const ResourceError&)
742 void FrameLoaderClientWx::startDownload(const ResourceRequest&)
747 PassRefPtr<Frame> FrameLoaderClientWx::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement,
748 const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight)
751 FIXME: Temporarily disabling code for loading subframes. While most
752 (i)frames load and are destroyed properly, the iframe created by
753 google.com in its new homepage does not get destroyed when
754 document()->detach() is called, as other (i)frames do. It is destroyed on
755 app shutdown, but until that point, this 'in limbo' frame will do things
756 like steal keyboard focus and crash when clicked on. (On some platforms,
757 it is actually a visible object, even though it's not in a valid state.)
759 Since just about every user is probably going to test against Google at
760 some point, I'm disabling this functionality until I have time to track down
761 why it is not being destroyed.
765 wxWindow* parent = m_frame->view()->nativeWindow();
767 WebViewFrameData* data = new WebViewFrameData();
769 data->ownerElement = ownerElement;
771 data->referrer = referrer;
772 data->marginWidth = marginWidth;
773 data->marginHeight = marginHeight;
775 wxWebView* newWin = new wxWebView(parent, -1, wxDefaultPosition, wxDefaultSize, data);
777 RefPtr<Frame> childFrame = newWin->m_impl->frame;
779 // FIXME: All of the below should probably be moved over into WebCore
780 childFrame->tree()->setName(name);
781 m_frame->tree()->appendChild(childFrame);
782 // ### set override encoding if we have one
784 FrameLoadType loadType = m_frame->loader()->loadType();
785 FrameLoadType childLoadType = FrameLoadTypeInternal;
787 childFrame->loader()->load(url, referrer, childLoadType,
790 // The frame's onload handler may have removed it from the document.
791 if (!childFrame->tree()->parent())
796 return childFrame.get();
802 ObjectContentType FrameLoaderClientWx::objectContentType(const KURL& url, const String& mimeType)
805 return ObjectContentType();
808 Widget* FrameLoaderClientWx::createPlugin(const IntSize&, Element*, const KURL&, const Vector<String>&, const Vector<String>&, const String&, bool loadManually)
814 void FrameLoaderClientWx::redirectDataToPlugin(Widget* pluginWidget)
820 Widget* FrameLoaderClientWx::createJavaAppletWidget(const IntSize&, Element*, const KURL& baseURL,
821 const Vector<String>& paramNames, const Vector<String>& paramValues)
827 String FrameLoaderClientWx::overrideMediaType() const
833 void FrameLoaderClientWx::windowObjectCleared()
838 void FrameLoaderClientWx::didPerformFirstNavigation() const
843 void FrameLoaderClientWx::registerForIconNotification(bool listen)
848 void FrameLoaderClientWx::savePlatformDataToCachedPage(CachedPage*)
853 void FrameLoaderClientWx::transitionToCommittedFromCachedPage(CachedPage*)
858 void FrameLoaderClientWx::transitionToCommittedForNewPage()