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 "HTMLFrameOwnerElement.h"
38 #include "NotImplemented.h"
40 #include "PlatformString.h"
41 #include "ProgressTracker.h"
42 #include "RenderPart.h"
43 #include "ResourceError.h"
44 #include "ResourceResponse.h"
49 #include "WebViewPrivate.h"
53 inline int wxNavTypeFromWebNavType(NavigationType type){
54 if (type == NavigationTypeLinkClicked)
55 return wxWEBVIEW_NAV_LINK_CLICKED;
57 if (type == NavigationTypeFormSubmitted)
58 return wxWEBVIEW_NAV_FORM_SUBMITTED;
60 if (type == NavigationTypeBackForward)
61 return wxWEBVIEW_NAV_BACK_NEXT;
63 if (type == NavigationTypeReload)
64 return wxWEBVIEW_NAV_RELOAD;
66 if (type == NavigationTypeFormResubmitted)
67 return wxWEBVIEW_NAV_FORM_RESUBMITTED;
69 return wxWEBVIEW_NAV_OTHER;
72 FrameLoaderClientWx::FrameLoaderClientWx()
73 : RefCounted<FrameLoaderClientWx>(0)
79 FrameLoaderClientWx::~FrameLoaderClientWx()
83 void FrameLoaderClientWx::setFrame(Frame *frame)
88 void FrameLoaderClientWx::setWebView(wxWebView *webview)
93 void FrameLoaderClientWx::detachFrameLoader()
98 void FrameLoaderClientWx::ref()
100 RefCounted<FrameLoaderClientWx>::ref();
103 void FrameLoaderClientWx::deref()
105 RefCounted<FrameLoaderClientWx>::deref();
108 bool FrameLoaderClientWx::hasWebView() const
115 bool FrameLoaderClientWx::hasFrameView() const
122 bool FrameLoaderClientWx::hasBackForwardList() const
129 void FrameLoaderClientWx::resetBackForwardList()
135 bool FrameLoaderClientWx::provisionalItemIsTarget() const
141 void FrameLoaderClientWx::makeRepresentation(DocumentLoader*)
147 void FrameLoaderClientWx::forceLayout()
153 void FrameLoaderClientWx::forceLayoutForNonHTML()
159 void FrameLoaderClientWx::updateHistoryForCommit()
165 void FrameLoaderClientWx::updateHistoryForBackForwardNavigation()
171 void FrameLoaderClientWx::updateHistoryForReload()
177 void FrameLoaderClientWx::updateHistoryForStandardLoad()
183 void FrameLoaderClientWx::updateHistoryForInternalLoad()
189 void FrameLoaderClientWx::updateHistoryAfterClientRedirect()
195 void FrameLoaderClientWx::setCopiesOnScroll()
197 // apparently mac specific
202 LoadErrorResetToken* FrameLoaderClientWx::tokenForLoadErrorReset()
209 void FrameLoaderClientWx::resetAfterLoadError(LoadErrorResetToken*)
215 void FrameLoaderClientWx::doNotResetAfterLoadError(LoadErrorResetToken*)
221 void FrameLoaderClientWx::willCloseDocument()
227 void FrameLoaderClientWx::detachedFromParent1()
233 void FrameLoaderClientWx::detachedFromParent2()
239 void FrameLoaderClientWx::detachedFromParent3()
245 void FrameLoaderClientWx::detachedFromParent4()
251 void FrameLoaderClientWx::loadedFromCachedPage()
257 void FrameLoaderClientWx::dispatchDidHandleOnloadEvents()
260 wxWebViewLoadEvent wkEvent(m_webView);
261 wkEvent.SetState(wxWEBVIEW_LOAD_ONLOAD_HANDLED);
262 wkEvent.SetURL(m_frame->loader()->documentLoader()->request().url().string());
263 m_webView->GetEventHandler()->ProcessEvent(wkEvent);
268 void FrameLoaderClientWx::dispatchDidReceiveServerRedirectForProvisionalLoad()
274 void FrameLoaderClientWx::dispatchDidCancelClientRedirect()
280 void FrameLoaderClientWx::dispatchWillPerformClientRedirect(const KURL&,
288 void FrameLoaderClientWx::dispatchDidChangeLocationWithinPage()
294 void FrameLoaderClientWx::dispatchWillClose()
300 void FrameLoaderClientWx::dispatchDidStartProvisionalLoad()
303 wxWebViewLoadEvent wkEvent(m_webView);
304 wkEvent.SetState(wxWEBVIEW_LOAD_NEGOTIATING);
305 wkEvent.SetURL(m_frame->loader()->provisionalDocumentLoader()->request().url().string());
306 m_webView->GetEventHandler()->ProcessEvent(wkEvent);
311 void FrameLoaderClientWx::dispatchDidReceiveTitle(const String& title)
314 m_webView->SetPageTitle(title);
318 void FrameLoaderClientWx::dispatchDidCommitLoad()
321 wxWebViewLoadEvent wkEvent(m_webView);
322 wkEvent.SetState(wxWEBVIEW_LOAD_TRANSFERRING);
323 wkEvent.SetURL(m_frame->loader()->documentLoader()->request().url().string());
324 m_webView->GetEventHandler()->ProcessEvent(wkEvent);
328 void FrameLoaderClientWx::dispatchDidFinishDocumentLoad()
331 wxWebViewLoadEvent wkEvent(m_webView);
332 wkEvent.SetState(wxWEBVIEW_LOAD_DOC_COMPLETED);
333 wkEvent.SetURL(m_frame->loader()->url().string());
334 m_webView->GetEventHandler()->ProcessEvent(wkEvent);
338 void FrameLoaderClientWx::dispatchDidFinishLoad()
344 void FrameLoaderClientWx::dispatchDidFirstLayout()
350 void FrameLoaderClientWx::dispatchShow()
356 void FrameLoaderClientWx::cancelPolicyCheck()
362 void FrameLoaderClientWx::dispatchWillSubmitForm(FramePolicyFunction function,
363 PassRefPtr<FormState>)
365 // FIXME: Send an event to allow for alerts and cancellation
368 (m_frame->loader()->*function)(PolicyUse);
372 void FrameLoaderClientWx::dispatchDidLoadMainResource(DocumentLoader*)
378 void FrameLoaderClientWx::revertToProvisionalState(DocumentLoader*)
383 void FrameLoaderClientWx::postProgressStartedNotification()
388 void FrameLoaderClientWx::postProgressEstimateChangedNotification()
393 void FrameLoaderClientWx::postProgressFinishedNotification()
396 wxWebViewLoadEvent wkEvent(m_webView);
397 wkEvent.SetState(wxWEBVIEW_LOAD_DL_COMPLETED);
398 wkEvent.SetURL(m_frame->loader()->url().string());
399 m_webView->GetEventHandler()->ProcessEvent(wkEvent);
403 void FrameLoaderClientWx::progressStarted()
409 void FrameLoaderClientWx::progressCompleted()
415 void FrameLoaderClientWx::setMainFrameDocumentReady(bool b)
418 // this is only interesting once we provide an external API for the DOM
422 void FrameLoaderClientWx::willChangeTitle(DocumentLoader*)
428 void FrameLoaderClientWx::didChangeTitle(DocumentLoader *l)
430 setTitle(l->title(), l->url());
434 void FrameLoaderClientWx::finishedLoading(DocumentLoader*)
440 bool FrameLoaderClientWx::canShowMIMEType(const String& MIMEType) const
447 bool FrameLoaderClientWx::representationExistsForURLScheme(const String& URLScheme) const
454 String FrameLoaderClientWx::generatedMIMETypeForURLScheme(const String& URLScheme) const
461 void FrameLoaderClientWx::frameLoadCompleted()
466 void FrameLoaderClientWx::saveViewStateToItem(HistoryItem*)
471 void FrameLoaderClientWx::restoreViewState()
476 void FrameLoaderClientWx::restoreScrollPositionAndViewState()
482 void FrameLoaderClientWx::provisionalLoadStarted()
488 bool FrameLoaderClientWx::shouldTreatURLAsSameAsCurrent(const KURL&) const
495 void FrameLoaderClientWx::addHistoryItemForFragmentScroll()
501 void FrameLoaderClientWx::didFinishLoad()
507 void FrameLoaderClientWx::prepareForDataSourceReplacement()
509 if (m_frame && m_frame->loader())
510 m_frame->loader()->detachChildren();
514 void FrameLoaderClientWx::setTitle(const String& title, const KURL&)
520 String FrameLoaderClientWx::userAgent(const KURL&)
522 // FIXME: Use the new APIs introduced by the GTK port to fill in these values.
523 return String("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3");
526 void FrameLoaderClientWx::dispatchDidReceiveIcon()
531 void FrameLoaderClientWx::frameLoaderDestroyed()
537 bool FrameLoaderClientWx::canHandleRequest(const WebCore::ResourceRequest&) const
543 void FrameLoaderClientWx::partClearedInBegin()
548 void FrameLoaderClientWx::updateGlobalHistory(const WebCore::KURL&)
553 bool FrameLoaderClientWx::shouldGoToHistoryItem(WebCore::HistoryItem*) const
559 void FrameLoaderClientWx::saveScrollPositionAndViewStateToItem(WebCore::HistoryItem*)
564 bool FrameLoaderClientWx::canCachePage() const
569 void FrameLoaderClientWx::setMainDocumentError(WebCore::DocumentLoader*, const WebCore::ResourceError&)
574 void FrameLoaderClientWx::committedLoad(WebCore::DocumentLoader* loader, const char* data, int length)
578 FrameLoader* fl = loader->frameLoader();
579 fl->setEncoding(m_response.textEncodingName(), false);
580 fl->addData(data, length);
583 WebCore::ResourceError FrameLoaderClientWx::cancelledError(const WebCore::ResourceRequest&)
586 return ResourceError();
589 WebCore::ResourceError FrameLoaderClientWx::blockedError(const ResourceRequest&)
592 return ResourceError();
595 WebCore::ResourceError FrameLoaderClientWx::cannotShowURLError(const WebCore::ResourceRequest&)
598 return ResourceError();
601 WebCore::ResourceError FrameLoaderClientWx::interruptForPolicyChangeError(const WebCore::ResourceRequest&)
604 return ResourceError();
607 WebCore::ResourceError FrameLoaderClientWx::cannotShowMIMETypeError(const WebCore::ResourceResponse&)
610 return ResourceError();
613 WebCore::ResourceError FrameLoaderClientWx::fileDoesNotExistError(const WebCore::ResourceResponse&)
616 return ResourceError();
619 bool FrameLoaderClientWx::shouldFallBack(const WebCore::ResourceError& error)
625 WTF::PassRefPtr<DocumentLoader> FrameLoaderClientWx::createDocumentLoader(const ResourceRequest& request, const SubstituteData& substituteData)
627 RefPtr<DocumentLoader> loader = new DocumentLoader(request, substituteData);
628 return loader.release();
631 void FrameLoaderClientWx::download(ResourceHandle*, const ResourceRequest&, const ResourceRequest&, const ResourceResponse&)
636 void FrameLoaderClientWx::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest&)
641 void FrameLoaderClientWx::dispatchWillSendRequest(DocumentLoader*, unsigned long, ResourceRequest& request, const ResourceResponse& response)
646 void FrameLoaderClientWx::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&)
651 void FrameLoaderClientWx::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&)
656 void FrameLoaderClientWx::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long id, const ResourceResponse& response)
659 m_response = response;
663 void FrameLoaderClientWx::dispatchDidReceiveContentLength(DocumentLoader* loader, unsigned long id, int length)
668 void FrameLoaderClientWx::dispatchDidFinishLoading(DocumentLoader*, unsigned long)
673 void FrameLoaderClientWx::dispatchDidFailLoading(DocumentLoader*, unsigned long, const ResourceError&)
678 bool FrameLoaderClientWx::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int)
684 void FrameLoaderClientWx::dispatchDidFailProvisionalLoad(const ResourceError&)
689 void FrameLoaderClientWx::dispatchDidFailLoad(const ResourceError&)
694 Frame* FrameLoaderClientWx::dispatchCreatePage()
700 void FrameLoaderClientWx::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const String& mimetype, const ResourceRequest& request)
706 (m_frame->loader()->*function)(PolicyUse);
709 void FrameLoaderClientWx::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction&, const ResourceRequest&, const String&)
715 (m_frame->loader()->*function)(PolicyUse);
718 void FrameLoaderClientWx::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request)
724 wxWebViewBeforeLoadEvent wkEvent(m_webView);
725 wkEvent.SetNavigationType(wxNavTypeFromWebNavType(action.type()));
726 wkEvent.SetURL(request.url().string());
728 m_webView->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_webView;
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()
863 Page* page = m_frame->page();
866 bool isMainFrame = m_frame == page->mainFrame();
870 FrameView* frameView;
872 frameView = new FrameView(m_frame, IntRect(m_webView->GetRect()).size());
874 frameView = new FrameView(m_frame);
877 m_frame->setView(frameView);
878 frameView->deref(); // FrameViews are created with a ref count of 1. Release this ref since we've assigned it to frame.
880 frameView->setNativeWindow(m_webView);
882 if (m_frame->ownerRenderer())
883 m_frame->ownerRenderer()->setWidget(frameView);
885 if (HTMLFrameOwnerElement* owner = m_frame->ownerElement())
886 m_frame->view()->setScrollbarsMode(owner->scrollingMode());