WebFrameLoaderClient.mm 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075
  1. /*
  2. * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  14. * its contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  18. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #import "WebFrameLoaderClient.h"
  29. // Terrible hack; lets us get at the WebFrame private structure.
  30. #define private public
  31. #import "WebFrame.h"
  32. #undef private
  33. #import "DOMElementInternal.h"
  34. #import "DOMHTMLFormElementInternal.h"
  35. #import "WebBackForwardList.h"
  36. #import "WebCachedFramePlatformData.h"
  37. #import "WebChromeClient.h"
  38. #import "WebDataSourceInternal.h"
  39. #import "WebDelegateImplementationCaching.h"
  40. #import "WebDocumentInternal.h"
  41. #import "WebDocumentLoaderMac.h"
  42. #import "WebDownloadInternal.h"
  43. #import "WebDynamicScrollBarsViewInternal.h"
  44. #import "WebElementDictionary.h"
  45. #import "WebFormDelegate.h"
  46. #import "WebFrameInternal.h"
  47. #import "WebFrameLoadDelegate.h"
  48. #import "WebFrameNetworkingContext.h"
  49. #import "WebFrameViewInternal.h"
  50. #import "WebHTMLRepresentationPrivate.h"
  51. #import "WebHTMLViewInternal.h"
  52. #import "WebHistoryInternal.h"
  53. #import "WebHistoryItemInternal.h"
  54. #import "WebIconDatabaseInternal.h"
  55. #import "WebKitErrorsPrivate.h"
  56. #import "WebKitLogging.h"
  57. #import "WebKitNSStringExtras.h"
  58. #import "WebNSURLExtras.h"
  59. #import "WebNavigationData.h"
  60. #import "WebNetscapePluginPackage.h"
  61. #import "WebNetscapePluginView.h"
  62. #import "WebPanelAuthenticationHandler.h"
  63. #import "WebPluginController.h"
  64. #import "WebPluginPackage.h"
  65. #import "WebPluginViewFactoryPrivate.h"
  66. #import "WebPolicyDelegate.h"
  67. #import "WebPolicyDelegatePrivate.h"
  68. #import "WebPreferences.h"
  69. #import "WebResourceLoadDelegate.h"
  70. #import "WebScriptWorldInternal.h"
  71. #import "WebSecurityOriginInternal.h"
  72. #import "WebUIDelegate.h"
  73. #import "WebUIDelegatePrivate.h"
  74. #import "WebViewInternal.h"
  75. #import <JavaScriptCore/JSContextInternal.h>
  76. #import <WebCore/AuthenticationCF.h>
  77. #import <WebCore/AuthenticationMac.h>
  78. #import <WebCore/BackForwardController.h>
  79. #import <WebCore/BlockExceptions.h>
  80. #import <WebCore/CachedFrame.h>
  81. #import <WebCore/Chrome.h>
  82. #import <WebCore/Document.h>
  83. #import <WebCore/DocumentLoader.h>
  84. #import <WebCore/EventHandler.h>
  85. #import <WebCore/FocusController.h>
  86. #import <WebCore/FormState.h>
  87. #import <WebCore/Frame.h>
  88. #import <WebCore/FrameLoader.h>
  89. #import <WebCore/FrameLoaderStateMachine.h>
  90. #import <WebCore/FrameLoaderTypes.h>
  91. #import <WebCore/FrameTree.h>
  92. #import <WebCore/FrameView.h>
  93. #import <WebCore/HTMLAppletElement.h>
  94. #import <WebCore/HTMLFormElement.h>
  95. #import <WebCore/HTMLFrameElement.h>
  96. #import <WebCore/HTMLFrameOwnerElement.h>
  97. #import <WebCore/HTMLHeadElement.h>
  98. #import <WebCore/HTMLNames.h>
  99. #import <WebCore/HTMLParserIdioms.h>
  100. #import <WebCore/HTMLPlugInElement.h>
  101. #import <WebCore/HistoryController.h>
  102. #import <WebCore/HistoryItem.h>
  103. #import <WebCore/HitTestResult.h>
  104. #import <WebCore/IconDatabase.h>
  105. #import <WebCore/LoaderNSURLExtras.h>
  106. #import <WebCore/MIMETypeRegistry.h>
  107. #import <WebCore/MouseEvent.h>
  108. #import <WebCore/Page.h>
  109. #import <WebCore/PluginViewBase.h>
  110. #import <WebCore/ProtectionSpace.h>
  111. #import <WebCore/ResourceError.h>
  112. #import <WebCore/ResourceHandle.h>
  113. #import <WebCore/ResourceLoader.h>
  114. #import <WebCore/ResourceRequest.h>
  115. #import <WebCore/RunLoop.h>
  116. #import <WebCore/ScriptController.h>
  117. #import <WebCore/SharedBuffer.h>
  118. #import <WebCore/WebCoreObjCExtras.h>
  119. #import <WebCore/WebScriptObjectPrivate.h>
  120. #import <WebCore/Widget.h>
  121. #import <WebKit/DOMElement.h>
  122. #import <WebKit/DOMHTMLFormElement.h>
  123. #import <WebKitSystemInterface.h>
  124. #import <runtime/InitializeThreading.h>
  125. #import <wtf/MainThread.h>
  126. #import <wtf/PassRefPtr.h>
  127. #import <wtf/text/WTFString.h>
  128. #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
  129. #import <WebCore/HTMLMediaElement.h>
  130. #endif
  131. #if USE(PLUGIN_HOST_PROCESS) && ENABLE(NETSCAPE_PLUGIN_API)
  132. #import "NetscapePluginHostManager.h"
  133. #import "WebHostedNetscapePluginView.h"
  134. #endif
  135. using namespace WebCore;
  136. using namespace HTMLNames;
  137. // For backwards compatibility with older WebKit plug-ins.
  138. NSString *WebPluginBaseURLKey = @"WebPluginBaseURL";
  139. NSString *WebPluginAttributesKey = @"WebPluginAttributes";
  140. NSString *WebPluginContainerKey = @"WebPluginContainer";
  141. @interface WebFramePolicyListener : NSObject <WebPolicyDecisionListener, WebFormSubmissionListener> {
  142. RefPtr<Frame> _frame;
  143. FramePolicyFunction _policyFunction;
  144. }
  145. - (id)initWithFrame:(Frame*)frame policyFunction:(FramePolicyFunction)policyFunction;
  146. - (void)invalidate;
  147. @end
  148. static inline WebDataSource *dataSource(DocumentLoader* loader)
  149. {
  150. return loader ? static_cast<WebDocumentLoaderMac*>(loader)->dataSource() : nil;
  151. }
  152. // Quirk for the Apple Dictionary application.
  153. //
  154. // If a top level frame has a <script> element in its <head> for a script named MainPageJavaScript.js,
  155. // then for that frame's document, ignore changes to the scrolling attribute of frames. That script
  156. // has a bug in it where it sets the scrolling attribute on frames, and that erroneous scrolling
  157. // attribute needs to be ignored to avoid showing extra scroll bars in the window.
  158. // This quirk can be removed when Apple Dictionary is fixed (see <rdar://problem/6471058>).
  159. static void applyAppleDictionaryApplicationQuirkNonInlinePart(WebFrameLoaderClient* client, const ResourceRequest& request)
  160. {
  161. if (!request.url().isLocalFile())
  162. return;
  163. if (!request.url().string().endsWith("MainPageJavaScript.js"))
  164. return;
  165. Frame* frame = core(client->webFrame());
  166. if (!frame)
  167. return;
  168. if (frame->tree()->parent())
  169. return;
  170. Document* document = frame->document();
  171. if (!document)
  172. return;
  173. HTMLHeadElement* head = document->head();
  174. if (!head)
  175. return;
  176. for (Node* c = head->firstChild(); c; c = c->nextSibling()) {
  177. if (c->hasTagName(scriptTag) && toElement(c)->getAttribute(srcAttr) == "MainPageJavaScript.js") {
  178. document->setFrameElementsShouldIgnoreScrolling(true);
  179. return;
  180. }
  181. }
  182. }
  183. static inline void applyAppleDictionaryApplicationQuirk(WebFrameLoaderClient* client, const ResourceRequest& request)
  184. {
  185. // Use a one-time-initialized global variable so we can quickly determine there's nothing to do in
  186. // all applications other than Apple Dictionary.
  187. static bool isAppleDictionary = [[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.Dictionary"];
  188. if (isAppleDictionary)
  189. applyAppleDictionaryApplicationQuirkNonInlinePart(client, request);
  190. }
  191. WebFrameLoaderClient::WebFrameLoaderClient(WebFrame *webFrame)
  192. : m_webFrame(webFrame)
  193. {
  194. }
  195. void WebFrameLoaderClient::frameLoaderDestroyed()
  196. {
  197. [m_webFrame.get() _clearCoreFrame];
  198. delete this;
  199. }
  200. bool WebFrameLoaderClient::hasWebView() const
  201. {
  202. return [m_webFrame.get() webView] != nil;
  203. }
  204. void WebFrameLoaderClient::makeRepresentation(DocumentLoader* loader)
  205. {
  206. [dataSource(loader) _makeRepresentation];
  207. }
  208. bool WebFrameLoaderClient::hasHTMLView() const
  209. {
  210. NSView <WebDocumentView> *view = [m_webFrame->_private->webFrameView documentView];
  211. return [view isKindOfClass:[WebHTMLView class]];
  212. }
  213. void WebFrameLoaderClient::forceLayout()
  214. {
  215. NSView <WebDocumentView> *view = [m_webFrame->_private->webFrameView documentView];
  216. [view setNeedsLayout:YES];
  217. [view layout];
  218. }
  219. void WebFrameLoaderClient::forceLayoutForNonHTML()
  220. {
  221. WebFrameView *thisView = m_webFrame->_private->webFrameView;
  222. NSView <WebDocumentView> *thisDocumentView = [thisView documentView];
  223. ASSERT(thisDocumentView != nil);
  224. // Tell the just loaded document to layout. This may be necessary
  225. // for non-html content that needs a layout message.
  226. if (!([[m_webFrame.get() _dataSource] _isDocumentHTML])) {
  227. [thisDocumentView setNeedsLayout:YES];
  228. [thisDocumentView layout];
  229. [thisDocumentView setNeedsDisplay:YES];
  230. }
  231. }
  232. void WebFrameLoaderClient::setCopiesOnScroll()
  233. {
  234. [[[m_webFrame->_private->webFrameView _scrollView] contentView] setCopiesOnScroll:YES];
  235. }
  236. void WebFrameLoaderClient::detachedFromParent2()
  237. {
  238. //remove any NetScape plugins that are children of this frame because they are about to be detached
  239. WebView *webView = getWebView(m_webFrame.get());
  240. [webView removePluginInstanceViewsFor:(m_webFrame.get())];
  241. [m_webFrame->_private->webFrameView _setWebFrame:nil]; // needed for now to be compatible w/ old behavior
  242. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  243. if (implementations->didRemoveFrameFromHierarchyFunc)
  244. CallFrameLoadDelegate(implementations->didRemoveFrameFromHierarchyFunc, webView, @selector(webView:didRemoveFrameFromHierarchy:), m_webFrame.get());
  245. }
  246. void WebFrameLoaderClient::detachedFromParent3()
  247. {
  248. [m_webFrame->_private->webFrameView release];
  249. m_webFrame->_private->webFrameView = nil;
  250. }
  251. void WebFrameLoaderClient::convertMainResourceLoadToDownload(DocumentLoader* documentLoader, const ResourceRequest& request, const ResourceResponse& response)
  252. {
  253. WebView *webView = getWebView(m_webFrame.get());
  254. if (!documentLoader->mainResourceLoader()) {
  255. // The resource has already been cached, start a new download.
  256. WebDownload *webDownload = [[WebDownload alloc] initWithRequest:request.nsURLRequest(UpdateHTTPBody) delegate:[webView downloadDelegate]];
  257. [webDownload autorelease];
  258. return;
  259. }
  260. ResourceHandle* handle = documentLoader->mainResourceLoader()->handle();
  261. #if USE(CFNETWORK)
  262. ASSERT([WebDownload respondsToSelector:@selector(_downloadWithLoadingCFURLConnection:request:response:delegate:proxy:)]);
  263. CFURLConnectionRef connection = handle->connection();
  264. [WebDownload _downloadWithLoadingCFURLConnection:connection
  265. request:request.cfURLRequest(UpdateHTTPBody)
  266. response:response.cfURLResponse()
  267. delegate:[webView downloadDelegate]
  268. proxy:nil];
  269. // Release the connection since the NSURLDownload (actually CFURLDownload) will retain the connection and use it.
  270. handle->releaseConnectionForDownload();
  271. CFRelease(connection);
  272. #else
  273. [WebDownload _downloadWithLoadingConnection:handle->connection()
  274. request:request.nsURLRequest(UpdateHTTPBody)
  275. response:response.nsURLResponse()
  276. delegate:[webView downloadDelegate]
  277. proxy:nil];
  278. #endif
  279. }
  280. bool WebFrameLoaderClient::dispatchDidLoadResourceFromMemoryCache(DocumentLoader* loader, const ResourceRequest& request, const ResourceResponse& response, int length)
  281. {
  282. applyAppleDictionaryApplicationQuirk(this, request);
  283. WebView *webView = getWebView(m_webFrame.get());
  284. WebResourceDelegateImplementationCache* implementations = WebViewGetResourceLoadDelegateImplementations(webView);
  285. if (!implementations->didLoadResourceFromMemoryCacheFunc)
  286. return false;
  287. CallResourceLoadDelegate(implementations->didLoadResourceFromMemoryCacheFunc, webView, @selector(webView:didLoadResourceFromMemoryCache:response:length:fromDataSource:), request.nsURLRequest(UpdateHTTPBody), response.nsURLResponse(), length, dataSource(loader));
  288. return true;
  289. }
  290. void WebFrameLoaderClient::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request)
  291. {
  292. WebView *webView = getWebView(m_webFrame.get());
  293. WebResourceDelegateImplementationCache* implementations = WebViewGetResourceLoadDelegateImplementations(webView);
  294. id object = nil;
  295. BOOL shouldRelease = NO;
  296. if (implementations->identifierForRequestFunc)
  297. object = CallResourceLoadDelegate(implementations->identifierForRequestFunc, webView, @selector(webView:identifierForInitialRequest:fromDataSource:), request.nsURLRequest(UpdateHTTPBody), dataSource(loader));
  298. else {
  299. object = [[NSObject alloc] init];
  300. shouldRelease = YES;
  301. }
  302. [webView _addObject:object forIdentifier:identifier];
  303. if (shouldRelease)
  304. [object release];
  305. }
  306. void WebFrameLoaderClient::dispatchWillSendRequest(DocumentLoader* loader, unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse)
  307. {
  308. applyAppleDictionaryApplicationQuirk(this, request);
  309. WebView *webView = getWebView(m_webFrame.get());
  310. WebResourceDelegateImplementationCache* implementations = WebViewGetResourceLoadDelegateImplementations(webView);
  311. if (redirectResponse.isNull())
  312. static_cast<WebDocumentLoaderMac*>(loader)->increaseLoadCount(identifier);
  313. NSURLRequest *currentURLRequest = request.nsURLRequest(UpdateHTTPBody);
  314. NSURLRequest *newURLRequest = currentURLRequest;
  315. if (implementations->willSendRequestFunc)
  316. newURLRequest = (NSURLRequest *)CallResourceLoadDelegate(implementations->willSendRequestFunc, webView, @selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:), [webView _objectForIdentifier:identifier], currentURLRequest, redirectResponse.nsURLResponse(), dataSource(loader));
  317. if (newURLRequest != currentURLRequest)
  318. request = newURLRequest;
  319. }
  320. bool WebFrameLoaderClient::shouldUseCredentialStorage(DocumentLoader* loader, unsigned long identifier)
  321. {
  322. WebView *webView = getWebView(m_webFrame.get());
  323. WebResourceDelegateImplementationCache* implementations = WebViewGetResourceLoadDelegateImplementations(webView);
  324. if (implementations->shouldUseCredentialStorageFunc) {
  325. if (id resource = [webView _objectForIdentifier:identifier])
  326. return CallResourceLoadDelegateReturningBoolean(NO, implementations->shouldUseCredentialStorageFunc, webView, @selector(webView:resource:shouldUseCredentialStorageForDataSource:), resource, dataSource(loader));
  327. }
  328. return true;
  329. }
  330. void WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge(DocumentLoader* loader, unsigned long identifier, const AuthenticationChallenge& challenge)
  331. {
  332. WebView *webView = getWebView(m_webFrame.get());
  333. WebResourceDelegateImplementationCache* implementations = WebViewGetResourceLoadDelegateImplementations(webView);
  334. NSURLAuthenticationChallenge *webChallenge = mac(challenge);
  335. if (implementations->didReceiveAuthenticationChallengeFunc) {
  336. if (id resource = [webView _objectForIdentifier:identifier]) {
  337. CallResourceLoadDelegate(implementations->didReceiveAuthenticationChallengeFunc, webView, @selector(webView:resource:didReceiveAuthenticationChallenge:fromDataSource:), resource, webChallenge, dataSource(loader));
  338. return;
  339. }
  340. }
  341. NSWindow *window = [webView hostWindow] ? [webView hostWindow] : [webView window];
  342. [[WebPanelAuthenticationHandler sharedHandler] startAuthentication:webChallenge window:window];
  343. }
  344. #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
  345. bool WebFrameLoaderClient::canAuthenticateAgainstProtectionSpace(DocumentLoader* loader, unsigned long identifier, const ProtectionSpace& protectionSpace)
  346. {
  347. WebView *webView = getWebView(m_webFrame.get());
  348. WebResourceDelegateImplementationCache* implementations = WebViewGetResourceLoadDelegateImplementations(webView);
  349. NSURLProtectionSpace *webProtectionSpace = mac(protectionSpace);
  350. if (implementations->canAuthenticateAgainstProtectionSpaceFunc) {
  351. if (id resource = [webView _objectForIdentifier:identifier]) {
  352. return CallResourceLoadDelegateReturningBoolean(NO, implementations->canAuthenticateAgainstProtectionSpaceFunc, webView, @selector(webView:resource:canAuthenticateAgainstProtectionSpace:forDataSource:), resource, webProtectionSpace, dataSource(loader));
  353. }
  354. }
  355. // If our resource load delegate doesn't handle the question, then only send authentication
  356. // challenges for pre-10.6 protection spaces. This is the same as the default implementation
  357. // in CFNetwork.
  358. return (protectionSpace.authenticationScheme() < ProtectionSpaceAuthenticationSchemeClientCertificateRequested);
  359. }
  360. #endif
  361. bool WebFrameLoaderClient::shouldPaintBrokenImage(const KURL& imageURL) const
  362. {
  363. WebView *webView = getWebView(m_webFrame.get());
  364. WebResourceDelegateImplementationCache* implementations = WebViewGetResourceLoadDelegateImplementations(webView);
  365. if (implementations->shouldPaintBrokenImageForURLFunc) {
  366. NSURL* url = imageURL;
  367. return CallResourceLoadDelegateReturningBoolean(YES, implementations->shouldPaintBrokenImageForURLFunc, webView, @selector(webView:shouldPaintBrokenImageForURL:), url);
  368. }
  369. return true;
  370. }
  371. void WebFrameLoaderClient::dispatchDidCancelAuthenticationChallenge(DocumentLoader* loader, unsigned long identifier, const AuthenticationChallenge&challenge)
  372. {
  373. WebView *webView = getWebView(m_webFrame.get());
  374. WebResourceDelegateImplementationCache* implementations = WebViewGetResourceLoadDelegateImplementations(webView);
  375. NSURLAuthenticationChallenge *webChallenge = mac(challenge);
  376. if (implementations->didCancelAuthenticationChallengeFunc) {
  377. if (id resource = [webView _objectForIdentifier:identifier]) {
  378. CallResourceLoadDelegate(implementations->didCancelAuthenticationChallengeFunc, webView, @selector(webView:resource:didCancelAuthenticationChallenge:fromDataSource:), resource, webChallenge, dataSource(loader));
  379. return;
  380. }
  381. }
  382. [(WebPanelAuthenticationHandler *)[WebPanelAuthenticationHandler sharedHandler] cancelAuthentication:webChallenge];
  383. }
  384. void WebFrameLoaderClient::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& response)
  385. {
  386. WebView *webView = getWebView(m_webFrame.get());
  387. WebResourceDelegateImplementationCache* implementations = WebViewGetResourceLoadDelegateImplementations(webView);
  388. if (implementations->didReceiveResponseFunc) {
  389. if (id resource = [webView _objectForIdentifier:identifier])
  390. CallResourceLoadDelegate(implementations->didReceiveResponseFunc, webView, @selector(webView:resource:didReceiveResponse:fromDataSource:), resource, response.nsURLResponse(), dataSource(loader));
  391. }
  392. }
  393. NSCachedURLResponse* WebFrameLoaderClient::willCacheResponse(DocumentLoader* loader, unsigned long identifier, NSCachedURLResponse* response) const
  394. {
  395. WebView *webView = getWebView(m_webFrame.get());
  396. WebResourceDelegateImplementationCache* implementations = WebViewGetResourceLoadDelegateImplementations(webView);
  397. if (implementations->willCacheResponseFunc) {
  398. if (id resource = [webView _objectForIdentifier:identifier])
  399. return CallResourceLoadDelegate(implementations->willCacheResponseFunc, webView, @selector(webView:resource:willCacheResponse:fromDataSource:), resource, response, dataSource(loader));
  400. }
  401. return response;
  402. }
  403. void WebFrameLoaderClient::dispatchDidReceiveContentLength(DocumentLoader* loader, unsigned long identifier, int dataLength)
  404. {
  405. WebView *webView = getWebView(m_webFrame.get());
  406. WebResourceDelegateImplementationCache* implementations = WebViewGetResourceLoadDelegateImplementations(webView);
  407. if (implementations->didReceiveContentLengthFunc) {
  408. if (id resource = [webView _objectForIdentifier:identifier])
  409. CallResourceLoadDelegate(implementations->didReceiveContentLengthFunc, webView, @selector(webView:resource:didReceiveContentLength:fromDataSource:), resource, (NSInteger)dataLength, dataSource(loader));
  410. }
  411. }
  412. void WebFrameLoaderClient::dispatchDidFinishLoading(DocumentLoader* loader, unsigned long identifier)
  413. {
  414. WebView *webView = getWebView(m_webFrame.get());
  415. WebResourceDelegateImplementationCache* implementations = WebViewGetResourceLoadDelegateImplementations(webView);
  416. if (implementations->didFinishLoadingFromDataSourceFunc) {
  417. if (id resource = [webView _objectForIdentifier:identifier])
  418. CallResourceLoadDelegate(implementations->didFinishLoadingFromDataSourceFunc, webView, @selector(webView:resource:didFinishLoadingFromDataSource:), resource, dataSource(loader));
  419. }
  420. [webView _removeObjectForIdentifier:identifier];
  421. static_cast<WebDocumentLoaderMac*>(loader)->decreaseLoadCount(identifier);
  422. }
  423. void WebFrameLoaderClient::dispatchDidFailLoading(DocumentLoader* loader, unsigned long identifier, const ResourceError& error)
  424. {
  425. WebView *webView = getWebView(m_webFrame.get());
  426. WebResourceDelegateImplementationCache* implementations = WebViewGetResourceLoadDelegateImplementations(webView);
  427. if (implementations->didFailLoadingWithErrorFromDataSourceFunc) {
  428. if (id resource = [webView _objectForIdentifier:identifier])
  429. CallResourceLoadDelegate(implementations->didFailLoadingWithErrorFromDataSourceFunc, webView, @selector(webView:resource:didFailLoadingWithError:fromDataSource:), resource, (NSError *)error, dataSource(loader));
  430. }
  431. [webView _removeObjectForIdentifier:identifier];
  432. static_cast<WebDocumentLoaderMac*>(loader)->decreaseLoadCount(identifier);
  433. }
  434. void WebFrameLoaderClient::dispatchDidHandleOnloadEvents()
  435. {
  436. WebView *webView = getWebView(m_webFrame.get());
  437. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  438. if (implementations->didHandleOnloadEventsForFrameFunc)
  439. CallFrameLoadDelegate(implementations->didHandleOnloadEventsForFrameFunc, webView, @selector(webView:didHandleOnloadEventsForFrame:), m_webFrame.get());
  440. }
  441. void WebFrameLoaderClient::dispatchDidReceiveServerRedirectForProvisionalLoad()
  442. {
  443. m_webFrame->_private->provisionalURL = core(m_webFrame.get())->loader()->provisionalDocumentLoader()->url().string();
  444. WebView *webView = getWebView(m_webFrame.get());
  445. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  446. if (implementations->didReceiveServerRedirectForProvisionalLoadForFrameFunc)
  447. CallFrameLoadDelegate(implementations->didReceiveServerRedirectForProvisionalLoadForFrameFunc, webView, @selector(webView:didReceiveServerRedirectForProvisionalLoadForFrame:), m_webFrame.get());
  448. }
  449. void WebFrameLoaderClient::dispatchDidCancelClientRedirect()
  450. {
  451. WebView *webView = getWebView(m_webFrame.get());
  452. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  453. if (implementations->didCancelClientRedirectForFrameFunc)
  454. CallFrameLoadDelegate(implementations->didCancelClientRedirectForFrameFunc, webView, @selector(webView:didCancelClientRedirectForFrame:), m_webFrame.get());
  455. }
  456. void WebFrameLoaderClient::dispatchWillPerformClientRedirect(const KURL& url, double delay, double fireDate)
  457. {
  458. WebView *webView = getWebView(m_webFrame.get());
  459. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  460. if (implementations->willPerformClientRedirectToURLDelayFireDateForFrameFunc) {
  461. NSURL *cocoaURL = url;
  462. CallFrameLoadDelegate(implementations->willPerformClientRedirectToURLDelayFireDateForFrameFunc, webView, @selector(webView:willPerformClientRedirectToURL:delay:fireDate:forFrame:), cocoaURL, delay, [NSDate dateWithTimeIntervalSince1970:fireDate], m_webFrame.get());
  463. }
  464. }
  465. void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage()
  466. {
  467. m_webFrame->_private->url = core(m_webFrame.get())->document()->url().string();
  468. WebView *webView = getWebView(m_webFrame.get());
  469. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  470. if (implementations->didChangeLocationWithinPageForFrameFunc)
  471. CallFrameLoadDelegate(implementations->didChangeLocationWithinPageForFrameFunc, webView, @selector(webView:didChangeLocationWithinPageForFrame:), m_webFrame.get());
  472. }
  473. void WebFrameLoaderClient::dispatchDidPushStateWithinPage()
  474. {
  475. m_webFrame->_private->url = core(m_webFrame.get())->document()->url().string();
  476. WebView *webView = getWebView(m_webFrame.get());
  477. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  478. if (implementations->didPushStateWithinPageForFrameFunc)
  479. CallFrameLoadDelegate(implementations->didPushStateWithinPageForFrameFunc, webView, @selector(webView:didPushStateWithinPageForFrame:), m_webFrame.get());
  480. }
  481. void WebFrameLoaderClient::dispatchDidReplaceStateWithinPage()
  482. {
  483. m_webFrame->_private->url = core(m_webFrame.get())->document()->url().string();
  484. WebView *webView = getWebView(m_webFrame.get());
  485. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  486. if (implementations->didReplaceStateWithinPageForFrameFunc)
  487. CallFrameLoadDelegate(implementations->didReplaceStateWithinPageForFrameFunc, webView, @selector(webView:didReplaceStateWithinPageForFrame:), m_webFrame.get());
  488. }
  489. void WebFrameLoaderClient::dispatchDidPopStateWithinPage()
  490. {
  491. m_webFrame->_private->url = core(m_webFrame.get())->document()->url().string();
  492. WebView *webView = getWebView(m_webFrame.get());
  493. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  494. if (implementations->didPopStateWithinPageForFrameFunc)
  495. CallFrameLoadDelegate(implementations->didPopStateWithinPageForFrameFunc, webView, @selector(webView:didPopStateWithinPageForFrame:), m_webFrame.get());
  496. }
  497. void WebFrameLoaderClient::dispatchWillClose()
  498. {
  499. WebView *webView = getWebView(m_webFrame.get());
  500. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  501. if (implementations->willCloseFrameFunc)
  502. CallFrameLoadDelegate(implementations->willCloseFrameFunc, webView, @selector(webView:willCloseFrame:), m_webFrame.get());
  503. }
  504. void WebFrameLoaderClient::dispatchDidReceiveIcon()
  505. {
  506. #if ENABLE(ICONDATABASE)
  507. WebView *webView = getWebView(m_webFrame.get());
  508. ASSERT(m_webFrame == [webView mainFrame]);
  509. [webView _dispatchDidReceiveIconFromWebFrame:m_webFrame.get()];
  510. #endif
  511. }
  512. void WebFrameLoaderClient::dispatchDidStartProvisionalLoad()
  513. {
  514. ASSERT(!m_webFrame->_private->provisionalURL);
  515. m_webFrame->_private->provisionalURL = core(m_webFrame.get())->loader()->provisionalDocumentLoader()->url().string();
  516. WebView *webView = getWebView(m_webFrame.get());
  517. [webView _didStartProvisionalLoadForFrame:m_webFrame.get()];
  518. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  519. if (implementations->didStartProvisionalLoadForFrameFunc)
  520. CallFrameLoadDelegate(implementations->didStartProvisionalLoadForFrameFunc, webView, @selector(webView:didStartProvisionalLoadForFrame:), m_webFrame.get());
  521. }
  522. void WebFrameLoaderClient::dispatchDidReceiveTitle(const StringWithDirection& title)
  523. {
  524. WebView *webView = getWebView(m_webFrame.get());
  525. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  526. if (implementations->didReceiveTitleForFrameFunc)
  527. // FIXME: use direction of title.
  528. CallFrameLoadDelegate(implementations->didReceiveTitleForFrameFunc, webView, @selector(webView:didReceiveTitle:forFrame:), (NSString *)title.string(), m_webFrame.get());
  529. }
  530. void WebFrameLoaderClient::dispatchDidChangeIcons(WebCore::IconType)
  531. {
  532. // FIXME: Implement this to allow container to update favicon.
  533. }
  534. void WebFrameLoaderClient::dispatchDidCommitLoad()
  535. {
  536. // Tell the client we've committed this URL.
  537. ASSERT([m_webFrame->_private->webFrameView documentView] != nil);
  538. WebView *webView = getWebView(m_webFrame.get());
  539. [webView _didCommitLoadForFrame:m_webFrame.get()];
  540. m_webFrame->_private->url = m_webFrame->_private->provisionalURL;
  541. m_webFrame->_private->provisionalURL = nullptr;
  542. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  543. if (implementations->didCommitLoadForFrameFunc)
  544. CallFrameLoadDelegate(implementations->didCommitLoadForFrameFunc, webView, @selector(webView:didCommitLoadForFrame:), m_webFrame.get());
  545. }
  546. void WebFrameLoaderClient::dispatchDidFailProvisionalLoad(const ResourceError& error)
  547. {
  548. m_webFrame->_private->provisionalURL = nullptr;
  549. WebView *webView = getWebView(m_webFrame.get());
  550. [webView _didFailProvisionalLoadWithError:error forFrame:m_webFrame.get()];
  551. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  552. if (implementations->didFailProvisionalLoadWithErrorForFrameFunc)
  553. CallFrameLoadDelegate(implementations->didFailProvisionalLoadWithErrorForFrameFunc, webView, @selector(webView:didFailProvisionalLoadWithError:forFrame:), (NSError *)error, m_webFrame.get());
  554. [m_webFrame->_private->internalLoadDelegate webFrame:m_webFrame.get() didFinishLoadWithError:error];
  555. }
  556. void WebFrameLoaderClient::dispatchDidFailLoad(const ResourceError& error)
  557. {
  558. ASSERT(!m_webFrame->_private->provisionalURL);
  559. WebView *webView = getWebView(m_webFrame.get());
  560. [webView _didFailLoadWithError:error forFrame:m_webFrame.get()];
  561. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  562. if (implementations->didFailLoadWithErrorForFrameFunc)
  563. CallFrameLoadDelegate(implementations->didFailLoadWithErrorForFrameFunc, webView, @selector(webView:didFailLoadWithError:forFrame:), (NSError *)error, m_webFrame.get());
  564. [m_webFrame->_private->internalLoadDelegate webFrame:m_webFrame.get() didFinishLoadWithError:error];
  565. }
  566. void WebFrameLoaderClient::dispatchDidFinishDocumentLoad()
  567. {
  568. WebView *webView = getWebView(m_webFrame.get());
  569. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  570. if (implementations->didFinishDocumentLoadForFrameFunc)
  571. CallFrameLoadDelegate(implementations->didFinishDocumentLoadForFrameFunc, webView, @selector(webView:didFinishDocumentLoadForFrame:), m_webFrame.get());
  572. }
  573. void WebFrameLoaderClient::dispatchDidFinishLoad()
  574. {
  575. ASSERT(!m_webFrame->_private->provisionalURL);
  576. WebView *webView = getWebView(m_webFrame.get());
  577. [webView _didFinishLoadForFrame:m_webFrame.get()];
  578. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  579. if (implementations->didFinishLoadForFrameFunc)
  580. CallFrameLoadDelegate(implementations->didFinishLoadForFrameFunc, webView, @selector(webView:didFinishLoadForFrame:), m_webFrame.get());
  581. [m_webFrame->_private->internalLoadDelegate webFrame:m_webFrame.get() didFinishLoadWithError:nil];
  582. }
  583. void WebFrameLoaderClient::dispatchDidLayout(LayoutMilestones milestones)
  584. {
  585. WebView *webView = getWebView(m_webFrame.get());
  586. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  587. if (implementations->didLayoutFunc)
  588. CallFrameLoadDelegate(implementations->didLayoutFunc, webView, @selector(webView:didLayout:), kitLayoutMilestones(milestones));
  589. if (milestones & DidFirstLayout) {
  590. // FIXME: We should consider removing the old didFirstLayout API since this is doing double duty with the
  591. // new didLayout API.
  592. if (implementations->didFirstLayoutInFrameFunc)
  593. CallFrameLoadDelegate(implementations->didFirstLayoutInFrameFunc, webView, @selector(webView:didFirstLayoutInFrame:), m_webFrame.get());
  594. // See WebFrameLoaderClient::provisionalLoadStarted.
  595. WebDynamicScrollBarsView *scrollView = [m_webFrame->_private->webFrameView _scrollView];
  596. if ([getWebView(m_webFrame.get()) drawsBackground])
  597. [scrollView setDrawsBackground:YES];
  598. #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
  599. [scrollView setVerticalScrollElasticity:NSScrollElasticityAutomatic];
  600. [scrollView setHorizontalScrollElasticity:NSScrollElasticityAutomatic];
  601. #endif
  602. }
  603. if (milestones & DidFirstVisuallyNonEmptyLayout) {
  604. // FIXME: We should consider removing the old didFirstVisuallyNonEmptyLayoutForFrame API since this is doing
  605. // double duty with the new didLayout API.
  606. if (implementations->didFirstVisuallyNonEmptyLayoutInFrameFunc)
  607. CallFrameLoadDelegate(implementations->didFirstVisuallyNonEmptyLayoutInFrameFunc, webView, @selector(webView:didFirstVisuallyNonEmptyLayoutInFrame:), m_webFrame.get());
  608. }
  609. }
  610. Frame* WebFrameLoaderClient::dispatchCreatePage(const NavigationAction&)
  611. {
  612. WebView *currentWebView = getWebView(m_webFrame.get());
  613. NSDictionary *features = [[NSDictionary alloc] init];
  614. WebView *newWebView = [[currentWebView _UIDelegateForwarder] webView:currentWebView
  615. createWebViewWithRequest:nil
  616. windowFeatures:features];
  617. [features release];
  618. #if USE(PLUGIN_HOST_PROCESS) && ENABLE(NETSCAPE_PLUGIN_API)
  619. if (newWebView)
  620. WebKit::NetscapePluginHostManager::shared().didCreateWindow();
  621. #endif
  622. return core([newWebView mainFrame]);
  623. }
  624. void WebFrameLoaderClient::dispatchShow()
  625. {
  626. WebView *webView = getWebView(m_webFrame.get());
  627. [[webView _UIDelegateForwarder] webViewShow:webView];
  628. }
  629. void WebFrameLoaderClient::dispatchDecidePolicyForResponse(FramePolicyFunction function,
  630. const ResourceResponse& response, const ResourceRequest& request)
  631. {
  632. WebView *webView = getWebView(m_webFrame.get());
  633. [[webView _policyDelegateForwarder] webView:webView
  634. decidePolicyForMIMEType:response.mimeType()
  635. request:request.nsURLRequest(UpdateHTTPBody)
  636. frame:m_webFrame.get()
  637. decisionListener:setUpPolicyListener(function).get()];
  638. }
  639. void WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function,
  640. const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName)
  641. {
  642. WebView *webView = getWebView(m_webFrame.get());
  643. [[webView _policyDelegateForwarder] webView:webView
  644. decidePolicyForNewWindowAction:actionDictionary(action, formState)
  645. request:request.nsURLRequest(UpdateHTTPBody)
  646. newFrameName:frameName
  647. decisionListener:setUpPolicyListener(function).get()];
  648. }
  649. void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function,
  650. const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState)
  651. {
  652. WebView *webView = getWebView(m_webFrame.get());
  653. [[webView _policyDelegateForwarder] webView:webView
  654. decidePolicyForNavigationAction:actionDictionary(action, formState)
  655. request:request.nsURLRequest(UpdateHTTPBody)
  656. frame:m_webFrame.get()
  657. decisionListener:setUpPolicyListener(function).get()];
  658. }
  659. void WebFrameLoaderClient::cancelPolicyCheck()
  660. {
  661. [m_policyListener invalidate];
  662. m_policyListener = nullptr;
  663. }
  664. void WebFrameLoaderClient::dispatchUnableToImplementPolicy(const ResourceError& error)
  665. {
  666. WebView *webView = getWebView(m_webFrame.get());
  667. [[webView _policyDelegateForwarder] webView:webView unableToImplementPolicyWithError:error frame:m_webFrame.get()];
  668. }
  669. static NSDictionary *makeFormFieldValuesDictionary(FormState* formState)
  670. {
  671. const StringPairVector& textFieldValues = formState->textFieldValues();
  672. size_t size = textFieldValues.size();
  673. NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithCapacity:size];
  674. for (size_t i = 0; i < size; ++i)
  675. [dictionary setObject:textFieldValues[i].second forKey:textFieldValues[i].first];
  676. return [dictionary autorelease];
  677. }
  678. void WebFrameLoaderClient::dispatchWillSendSubmitEvent(PassRefPtr<WebCore::FormState> formState)
  679. {
  680. id <WebFormDelegate> formDelegate = [getWebView(m_webFrame.get()) _formDelegate];
  681. if (!formDelegate)
  682. return;
  683. DOMHTMLFormElement *formElement = kit(formState->form());
  684. NSDictionary *values = makeFormFieldValuesDictionary(formState.get());
  685. CallFormDelegate(getWebView(m_webFrame.get()), @selector(willSendSubmitEventToForm:inFrame:withValues:), formElement, m_webFrame.get(), values);
  686. }
  687. void WebFrameLoaderClient::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState> formState)
  688. {
  689. id <WebFormDelegate> formDelegate = [getWebView(m_webFrame.get()) _formDelegate];
  690. if (!formDelegate) {
  691. (core(m_webFrame.get())->loader()->policyChecker()->*function)(PolicyUse);
  692. return;
  693. }
  694. NSDictionary *values = makeFormFieldValuesDictionary(formState.get());
  695. CallFormDelegate(getWebView(m_webFrame.get()), @selector(frame:sourceFrame:willSubmitForm:withValues:submissionListener:), m_webFrame.get(), kit(formState->sourceDocument()->frame()), kit(formState->form()), values, setUpPolicyListener(function).get());
  696. }
  697. void WebFrameLoaderClient::revertToProvisionalState(DocumentLoader* loader)
  698. {
  699. [dataSource(loader) _revertToProvisionalState];
  700. }
  701. void WebFrameLoaderClient::setMainDocumentError(DocumentLoader* loader, const ResourceError& error)
  702. {
  703. [dataSource(loader) _setMainDocumentError:error];
  704. }
  705. void WebFrameLoaderClient::willChangeEstimatedProgress()
  706. {
  707. [getWebView(m_webFrame.get()) _willChangeValueForKey:_WebEstimatedProgressKey];
  708. }
  709. void WebFrameLoaderClient::didChangeEstimatedProgress()
  710. {
  711. [getWebView(m_webFrame.get()) _didChangeValueForKey:_WebEstimatedProgressKey];
  712. }
  713. void WebFrameLoaderClient::postProgressStartedNotification()
  714. {
  715. [[NSNotificationCenter defaultCenter] postNotificationName:WebViewProgressStartedNotification object:getWebView(m_webFrame.get())];
  716. }
  717. void WebFrameLoaderClient::postProgressEstimateChangedNotification()
  718. {
  719. [[NSNotificationCenter defaultCenter] postNotificationName:WebViewProgressEstimateChangedNotification object:getWebView(m_webFrame.get())];
  720. }
  721. void WebFrameLoaderClient::postProgressFinishedNotification()
  722. {
  723. [[NSNotificationCenter defaultCenter] postNotificationName:WebViewProgressFinishedNotification object:getWebView(m_webFrame.get())];
  724. }
  725. void WebFrameLoaderClient::setMainFrameDocumentReady(bool ready)
  726. {
  727. [getWebView(m_webFrame.get()) setMainFrameDocumentReady:ready];
  728. }
  729. void WebFrameLoaderClient::startDownload(const ResourceRequest& request, const String& /* suggestedName */)
  730. {
  731. // FIXME: Should download full request.
  732. [getWebView(m_webFrame.get()) _downloadURL:request.url()];
  733. }
  734. void WebFrameLoaderClient::willChangeTitle(DocumentLoader* loader)
  735. {
  736. // FIXME: Should do this only in main frame case, right?
  737. [getWebView(m_webFrame.get()) _willChangeValueForKey:_WebMainFrameTitleKey];
  738. }
  739. void WebFrameLoaderClient::didChangeTitle(DocumentLoader* loader)
  740. {
  741. // FIXME: Should do this only in main frame case, right?
  742. [getWebView(m_webFrame.get()) _didChangeValueForKey:_WebMainFrameTitleKey];
  743. }
  744. void WebFrameLoaderClient::committedLoad(DocumentLoader* loader, const char* data, int length)
  745. {
  746. NSData *nsData = [[NSData alloc] initWithBytesNoCopy:(void*)data length:length freeWhenDone:NO];
  747. [dataSource(loader) _receivedData:nsData];
  748. [nsData release];
  749. }
  750. void WebFrameLoaderClient::finishedLoading(DocumentLoader* loader)
  751. {
  752. [dataSource(loader) _finishedLoading];
  753. }
  754. static inline NSString *nilOrNSString(const String& string)
  755. {
  756. if (string.isNull())
  757. return nil;
  758. return string;
  759. }
  760. void WebFrameLoaderClient::updateGlobalHistory()
  761. {
  762. WebView* view = getWebView(m_webFrame.get());
  763. DocumentLoader* loader = core(m_webFrame.get())->loader()->documentLoader();
  764. if ([view historyDelegate]) {
  765. WebHistoryDelegateImplementationCache* implementations = WebViewGetHistoryDelegateImplementations(view);
  766. if (implementations->navigatedFunc) {
  767. WebNavigationData *data = [[WebNavigationData alloc] initWithURLString:loader->url()
  768. title:nilOrNSString(loader->title().string())
  769. originalRequest:loader->originalRequestCopy().nsURLRequest(UpdateHTTPBody)
  770. response:loader->response().nsURLResponse()
  771. hasSubstituteData:loader->substituteData().isValid()
  772. clientRedirectSource:loader->clientRedirectSourceForHistory()];
  773. CallHistoryDelegate(implementations->navigatedFunc, view, @selector(webView:didNavigateWithNavigationData:inFrame:), data, m_webFrame.get());
  774. [data release];
  775. }
  776. return;
  777. }
  778. [[WebHistory optionalSharedHistory] _visitedURL:loader->urlForHistory()
  779. withTitle:loader->title().string()
  780. method:loader->originalRequestCopy().httpMethod()
  781. wasFailure:loader->urlForHistoryReflectsFailure()
  782. increaseVisitCount:!loader->clientRedirectSourceForHistory()]; // Do not increase visit count due to navigations that were not initiated by the user directly, avoiding growth from programmatic reloads.
  783. }
  784. void WebFrameLoaderClient::updateGlobalHistoryRedirectLinks()
  785. {
  786. WebView* view = getWebView(m_webFrame.get());
  787. WebHistoryDelegateImplementationCache* implementations = [view historyDelegate] ? WebViewGetHistoryDelegateImplementations(view) : 0;
  788. DocumentLoader* loader = core(m_webFrame.get())->loader()->documentLoader();
  789. ASSERT(loader->unreachableURL().isEmpty());
  790. if (!loader->clientRedirectSourceForHistory().isNull()) {
  791. if (implementations) {
  792. if (implementations->clientRedirectFunc) {
  793. CallHistoryDelegate(implementations->clientRedirectFunc, view, @selector(webView:didPerformClientRedirectFromURL:toURL:inFrame:),
  794. m_webFrame->_private->url.get(), loader->clientRedirectDestinationForHistory(), m_webFrame.get());
  795. }
  796. } else if (WebHistoryItem *item = [[WebHistory optionalSharedHistory] _itemForURLString:loader->clientRedirectSourceForHistory()])
  797. core(item)->addRedirectURL(loader->clientRedirectDestinationForHistory());
  798. }
  799. if (!loader->serverRedirectSourceForHistory().isNull()) {
  800. if (implementations) {
  801. if (implementations->serverRedirectFunc) {
  802. CallHistoryDelegate(implementations->serverRedirectFunc, view, @selector(webView:didPerformServerRedirectFromURL:toURL:inFrame:),
  803. loader->serverRedirectSourceForHistory(), loader->serverRedirectDestinationForHistory(), m_webFrame.get());
  804. }
  805. } else if (WebHistoryItem *item = [[WebHistory optionalSharedHistory] _itemForURLString:loader->serverRedirectSourceForHistory()])
  806. core(item)->addRedirectURL(loader->serverRedirectDestinationForHistory());
  807. }
  808. }
  809. bool WebFrameLoaderClient::shouldGoToHistoryItem(HistoryItem* item) const
  810. {
  811. WebView* view = getWebView(m_webFrame.get());
  812. WebHistoryItem *webItem = kit(item);
  813. return [[view _policyDelegateForwarder] webView:view shouldGoToHistoryItem:webItem];
  814. }
  815. bool WebFrameLoaderClient::shouldStopLoadingForHistoryItem(HistoryItem* item) const
  816. {
  817. return true;
  818. }
  819. void WebFrameLoaderClient::updateGlobalHistoryItemForPage()
  820. {
  821. HistoryItem* historyItem = 0;
  822. if (Page* page = core(m_webFrame.get())->page()) {
  823. if (!page->settings()->privateBrowsingEnabled())
  824. historyItem = page->backForward()->currentItem();
  825. }
  826. WebView *webView = getWebView(m_webFrame.get());
  827. [webView _setGlobalHistoryItem:historyItem];
  828. }
  829. void WebFrameLoaderClient::didDisplayInsecureContent()
  830. {
  831. WebView *webView = getWebView(m_webFrame.get());
  832. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  833. if (implementations->didDisplayInsecureContentFunc)
  834. CallFrameLoadDelegate(implementations->didDisplayInsecureContentFunc, webView, @selector(webViewDidDisplayInsecureContent:));
  835. }
  836. void WebFrameLoaderClient::didRunInsecureContent(SecurityOrigin* origin, const KURL& insecureURL)
  837. {
  838. WebView *webView = getWebView(m_webFrame.get());
  839. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  840. if (implementations->didRunInsecureContentFunc) {
  841. RetainPtr<WebSecurityOrigin> webSecurityOrigin = adoptNS([[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:origin]);
  842. CallFrameLoadDelegate(implementations->didRunInsecureContentFunc, webView, @selector(webView:didRunInsecureContent:), webSecurityOrigin.get());
  843. }
  844. }
  845. void WebFrameLoaderClient::didDetectXSS(const KURL& insecureURL, bool didBlockEntirePage)
  846. {
  847. WebView *webView = getWebView(m_webFrame.get());
  848. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  849. if (implementations->didDetectXSSFunc) {
  850. // FIXME: must pass didBlockEntirePage if we want to do more on mac than just pass tests.
  851. NSURL* insecureNSURL = insecureURL;
  852. CallFrameLoadDelegate(implementations->didDetectXSSFunc, webView, @selector(webView:didDetectXSS:), insecureNSURL);
  853. }
  854. }
  855. ResourceError WebFrameLoaderClient::cancelledError(const ResourceRequest& request)
  856. {
  857. return [NSError _webKitErrorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled URL:request.url()];
  858. }
  859. ResourceError WebFrameLoaderClient::blockedError(const ResourceRequest& request)
  860. {
  861. return [NSError _webKitErrorWithDomain:WebKitErrorDomain code:WebKitErrorCannotUseRestrictedPort URL:request.url()];
  862. }
  863. ResourceError WebFrameLoaderClient::cannotShowURLError(const ResourceRequest& request)
  864. {
  865. return [NSError _webKitErrorWithDomain:WebKitErrorDomain code:WebKitErrorCannotShowURL URL:request.url()];
  866. }
  867. ResourceError WebFrameLoaderClient::interruptedForPolicyChangeError(const ResourceRequest& request)
  868. {
  869. return [NSError _webKitErrorWithDomain:WebKitErrorDomain code:WebKitErrorFrameLoadInterruptedByPolicyChange URL:request.url()];
  870. }
  871. ResourceError WebFrameLoaderClient::cannotShowMIMETypeError(const ResourceResponse& response)
  872. {
  873. return [NSError _webKitErrorWithDomain:NSURLErrorDomain code:WebKitErrorCannotShowMIMEType URL:response.url()];
  874. }
  875. ResourceError WebFrameLoaderClient::fileDoesNotExistError(const ResourceResponse& response)
  876. {
  877. return [NSError _webKitErrorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist URL:response.url()];
  878. }
  879. ResourceError WebFrameLoaderClient::pluginWillHandleLoadError(const ResourceResponse& response)
  880. {
  881. NSError *error = [[NSError alloc] _initWithPluginErrorCode:WebKitErrorPlugInWillHandleLoad
  882. contentURL:response.url()
  883. pluginPageURL:nil
  884. pluginName:nil
  885. MIMEType:response.mimeType()];
  886. return [error autorelease];
  887. }
  888. bool WebFrameLoaderClient::shouldFallBack(const ResourceError& error)
  889. {
  890. // FIXME: Needs to check domain.
  891. // FIXME: WebKitErrorPlugInWillHandleLoad is a workaround for the cancel we do to prevent
  892. // loading plugin content twice. See <rdar://problem/4258008>
  893. return error.errorCode() != NSURLErrorCancelled && error.errorCode() != WebKitErrorPlugInWillHandleLoad;
  894. }
  895. bool WebFrameLoaderClient::canHandleRequest(const ResourceRequest& request) const
  896. {
  897. Frame* frame = core(m_webFrame.get());
  898. Page* page = frame->page();
  899. BOOL forMainFrame = page && page->mainFrame() == frame;
  900. return [WebView _canHandleRequest:request.nsURLRequest(UpdateHTTPBody) forMainFrame:forMainFrame];
  901. }
  902. bool WebFrameLoaderClient::canShowMIMEType(const String& MIMEType) const
  903. {
  904. return [getWebView(m_webFrame.get()) _canShowMIMEType:MIMEType];
  905. }
  906. bool WebFrameLoaderClient::canShowMIMETypeAsHTML(const String& MIMEType) const
  907. {
  908. return [WebView canShowMIMETypeAsHTML:MIMEType];
  909. }
  910. bool WebFrameLoaderClient::representationExistsForURLScheme(const String& URLScheme) const
  911. {
  912. return [WebView _representationExistsForURLScheme:URLScheme];
  913. }
  914. String WebFrameLoaderClient::generatedMIMETypeForURLScheme(const String& URLScheme) const
  915. {
  916. return [WebView _generatedMIMETypeForURLScheme:URLScheme];
  917. }
  918. void WebFrameLoaderClient::frameLoadCompleted()
  919. {
  920. // Note: Can be called multiple times.
  921. // See WebFrameLoaderClient::provisionalLoadStarted.
  922. if ([getWebView(m_webFrame.get()) drawsBackground])
  923. [[m_webFrame->_private->webFrameView _scrollView] setDrawsBackground:YES];
  924. }
  925. void WebFrameLoaderClient::saveViewStateToItem(HistoryItem* item)
  926. {
  927. if (!item)
  928. return;
  929. NSView <WebDocumentView> *docView = [m_webFrame->_private->webFrameView documentView];
  930. // we might already be detached when this is called from detachFromParent, in which
  931. // case we don't want to override real data earlier gathered with (0,0)
  932. if ([docView superview] && [docView conformsToProtocol:@protocol(_WebDocumentViewState)])
  933. item->setViewState([(id <_WebDocumentViewState>)docView viewState]);
  934. }
  935. void WebFrameLoaderClient::restoreViewState()
  936. {
  937. HistoryItem* currentItem = core(m_webFrame.get())->loader()->history()->currentItem();
  938. ASSERT(currentItem);
  939. // FIXME: As the ASSERT attests, it seems we should always have a currentItem here.
  940. // One counterexample is <rdar://problem/4917290>
  941. // For now, to cover this issue in release builds, there is no technical harm to returning
  942. // early and from a user standpoint - as in the above radar - the previous page load failed
  943. // so there *is* no scroll state to restore!
  944. if (!currentItem)
  945. return;
  946. NSView <WebDocumentView> *docView = [m_webFrame->_private->webFrameView documentView];
  947. if ([docView conformsToProtocol:@protocol(_WebDocumentViewState)]) {
  948. id state = currentItem->viewState();
  949. if (state) {
  950. [(id <_WebDocumentViewState>)docView setViewState:state];
  951. }
  952. }
  953. }
  954. void WebFrameLoaderClient::provisionalLoadStarted()
  955. {
  956. // Tell the scroll view not to draw a background so we can leave the contents of
  957. // the old page showing during the beginning of the loading process.
  958. // This will stay set to NO until:
  959. // 1) The load gets far enough along: WebFrameLoader::frameLoadCompleted.
  960. // 2) The window is resized: -[WebFrameView setFrameSize:].
  961. // or 3) The view is moved out of the window: -[WebFrameView viewDidMoveToWindow].
  962. // Please keep the comments in these four functions in agreement with each other.
  963. WebDynamicScrollBarsView *scrollView = [m_webFrame->_private->webFrameView _scrollView];
  964. [scrollView setDrawsBackground:NO];
  965. #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
  966. [scrollView setVerticalScrollElasticity:NSScrollElasticityNone];
  967. [scrollView setHorizontalScrollElasticity:NSScrollElasticityNone];
  968. #endif
  969. }
  970. void WebFrameLoaderClient::didFinishLoad()
  971. {
  972. [m_webFrame->_private->internalLoadDelegate webFrame:m_webFrame.get() didFinishLoadWithError:nil];
  973. }
  974. void WebFrameLoaderClient::prepareForDataSourceReplacement()
  975. {
  976. if (![m_webFrame.get() _dataSource]) {
  977. ASSERT(!core(m_webFrame.get())->tree()->childCount());
  978. return;
  979. }
  980. // Make sure that any work that is triggered by resigning first reponder can get done.
  981. // The main example where this came up is the textDidEndEditing that is sent to the
  982. // FormsDelegate (3223413). We need to do this before _detachChildren, since that will
  983. // remove the views as a side-effect of freeing the frame, at which point we can't
  984. // post the FormDelegate messages.
  985. //
  986. // Note that this can also take FirstResponder away from a child of our frameView that
  987. // is not in a child frame's view. This is OK because we are in the process
  988. // of loading new content, which will blow away all editors in this top frame, and if
  989. // a non-editor is firstReponder it will not be affected by endEditingFor:.
  990. // Potentially one day someone could write a DocView whose editors were not all
  991. // replaced by loading new content, but that does not apply currently.
  992. NSView *frameView = m_webFrame->_private->webFrameView;
  993. NSWindow *window = [frameView window];
  994. NSResponder *firstResp = [window firstResponder];
  995. if ([firstResp isKindOfClass:[NSView class]] && [(NSView *)firstResp isDescendantOf:frameView])
  996. [window endEditingFor:firstResp];
  997. }
  998. PassRefPtr<DocumentLoader> WebFrameLoaderClient::createDocumentLoader(const ResourceRequest& request, const SubstituteData& substituteData)
  999. {
  1000. RefPtr<WebDocumentLoaderMac> loader = WebDocumentLoaderMac::create(request, substituteData);
  1001. WebDataSource *dataSource = [[WebDataSource alloc] _initWithDocumentLoader:loader.get()];
  1002. loader->setDataSource(dataSource, getWebView(m_webFrame.get()));
  1003. [dataSource release];
  1004. return loader.release();
  1005. }
  1006. void WebFrameLoaderClient::setTitle(const StringWithDirection& title, const KURL& url)
  1007. {
  1008. WebView* view = getWebView(m_webFrame.get());
  1009. if ([view historyDelegate]) {
  1010. WebHistoryDelegateImplementationCache* implementations = WebViewGetHistoryDelegateImplementations(view);
  1011. // FIXME: use direction of title.
  1012. if (implementations->setTitleFunc)
  1013. CallHistoryDelegate(implementations->setTitleFunc, view, @selector(webView:updateHistoryTitle:forURL:inFrame:), (NSString *)title.string(), (NSString *)url, m_webFrame.get());
  1014. else if (implementations->deprecatedSetTitleFunc)
  1015. CallHistoryDelegate(implementations->deprecatedSetTitleFunc, view, @selector(webView:updateHistoryTitle:forURL:), (NSString *)title.string(), (NSString *)url);
  1016. return;
  1017. }
  1018. NSURL* nsURL = url;
  1019. nsURL = [nsURL _webkit_canonicalize];
  1020. if(!nsURL)
  1021. return;
  1022. NSString *titleNSString = title.string();
  1023. [[[WebHistory optionalSharedHistory] itemForURL:nsURL] setTitle:titleNSString];
  1024. }
  1025. void WebFrameLoaderClient::savePlatformDataToCachedFrame(CachedFrame* cachedFrame)
  1026. {
  1027. OwnPtr<WebCachedFramePlatformData> webPlatformData = adoptPtr(new WebCachedFramePlatformData([m_webFrame->_private->webFrameView documentView]));
  1028. cachedFrame->setCachedFramePlatformData(webPlatformData.release());
  1029. }
  1030. void WebFrameLoaderClient::transitionToCommittedFromCachedFrame(CachedFrame* cachedFrame)
  1031. {
  1032. WebCachedFramePlatformData* platformData = reinterpret_cast<WebCachedFramePlatformData*>(cachedFrame->cachedFramePlatformData());
  1033. NSView <WebDocumentView> *cachedView = platformData->webDocumentView();
  1034. ASSERT(cachedView != nil);
  1035. ASSERT(cachedFrame->documentLoader());
  1036. [cachedView setDataSource:dataSource(cachedFrame->documentLoader())];
  1037. // clean up webkit plugin instances before WebHTMLView gets freed.
  1038. WebView *webView = getWebView(m_webFrame.get());
  1039. [webView removePluginInstanceViewsFor:(m_webFrame.get())];
  1040. [m_webFrame->_private->webFrameView _setDocumentView:cachedView];
  1041. }
  1042. void WebFrameLoaderClient::transitionToCommittedForNewPage()
  1043. {
  1044. WebView *webView = getWebView(m_webFrame.get());
  1045. WebDataSource *dataSource = [m_webFrame.get() _dataSource];
  1046. bool willProduceHTMLView = [m_webFrame->_private->webFrameView _viewClassForMIMEType:[dataSource _responseMIMEType]] == [WebHTMLView class];
  1047. bool canSkipCreation = core(m_webFrame.get())->loader()->stateMachine()->committingFirstRealLoad() && willProduceHTMLView;
  1048. if (canSkipCreation) {
  1049. [[m_webFrame->_private->webFrameView documentView] setDataSource:dataSource];
  1050. return;
  1051. }
  1052. // Don't suppress scrollbars before the view creation if we're making the view for a non-HTML view.
  1053. if (!willProduceHTMLView)
  1054. [[m_webFrame->_private->webFrameView _scrollView] setScrollBarsSuppressed:NO repaintOnUnsuppress:NO];
  1055. // clean up webkit plugin instances before WebHTMLView gets freed.
  1056. [webView removePluginInstanceViewsFor:(m_webFrame.get())];
  1057. NSView <WebDocumentView> *documentView = [m_webFrame->_private->webFrameView _makeDocumentViewForDataSource:dataSource];
  1058. if (!documentView)
  1059. return;
  1060. // FIXME: Could we skip some of this work for a top-level view that is not a WebHTMLView?
  1061. // If we own the view, delete the old one - otherwise the render m_frame will take care of deleting the view.
  1062. Frame* coreFrame = core(m_webFrame.get());
  1063. Page* page = coreFrame->page();
  1064. bool isMainFrame = coreFrame == page->mainFrame();
  1065. if (isMainFrame && coreFrame->view())
  1066. coreFrame->view()->setParentVisible(false);
  1067. coreFrame->setView(0);
  1068. RefPtr<FrameView> coreView = FrameView::create(coreFrame);
  1069. coreFrame->setView(coreView);
  1070. [m_webFrame.get() _updateBackgroundAndUpdatesWhileOffscreen];
  1071. [m_webFrame->_private->webFrameView _install];
  1072. if (isMainFrame)
  1073. coreView->setParentVisible(true);
  1074. // Call setDataSource on the document view after it has been placed in the view hierarchy.
  1075. // This what we for the top-level view, so should do this for views in subframes as well.
  1076. [documentView setDataSource:dataSource];
  1077. // The following is a no-op for WebHTMLRepresentation, but for custom document types
  1078. // like the ones that Safari uses for bookmarks it is the only way the DocumentLoader
  1079. // will get the proper title.
  1080. if (DocumentLoader* documentLoader = [dataSource _documentLoader])
  1081. documentLoader->setTitle(StringWithDirection([dataSource pageTitle], LTR));
  1082. if (HTMLFrameOwnerElement* owner = coreFrame->ownerElement())
  1083. coreFrame->view()->setCanHaveScrollbars(owner->scrollingMode() != ScrollbarAlwaysOff);
  1084. // If the document view implicitly became first responder, make sure to set the focused frame properly.
  1085. if ([[documentView window] firstResponder] == documentView) {
  1086. page->focusController()->setFocusedFrame(coreFrame);
  1087. page->focusController()->setFocused(true);
  1088. }
  1089. }
  1090. void WebFrameLoaderClient::didSaveToPageCache()
  1091. {
  1092. }
  1093. void WebFrameLoaderClient::didRestoreFromPageCache()
  1094. {
  1095. }
  1096. void WebFrameLoaderClient::dispatchDidBecomeFrameset(bool)
  1097. {
  1098. }
  1099. RetainPtr<WebFramePolicyListener> WebFrameLoaderClient::setUpPolicyListener(FramePolicyFunction function)
  1100. {
  1101. // FIXME: <rdar://5634381> We need to support multiple active policy listeners.
  1102. [m_policyListener invalidate];
  1103. m_policyListener = adoptNS([[WebFramePolicyListener alloc] initWithFrame:core(m_webFrame.get()) policyFunction:function]);
  1104. return m_policyListener;
  1105. }
  1106. String WebFrameLoaderClient::userAgent(const KURL& url)
  1107. {
  1108. WebView *webView = getWebView(m_webFrame.get());
  1109. ASSERT(webView);
  1110. // We should never get here with nil for the WebView unless there is a bug somewhere else.
  1111. // But if we do, it's better to return the empty string than just crashing on the spot.
  1112. // Most other call sites are tolerant of nil because of Objective-C behavior, but this one
  1113. // is not because the return value of _userAgentForURL is a const KURL&.
  1114. if (!webView)
  1115. return String("");
  1116. return [webView _userAgentString];
  1117. }
  1118. static const MouseEvent* findMouseEvent(const Event* event)
  1119. {
  1120. for (const Event* e = event; e; e = e->underlyingEvent())
  1121. if (e->isMouseEvent())
  1122. return static_cast<const MouseEvent*>(e);
  1123. return 0;
  1124. }
  1125. NSDictionary *WebFrameLoaderClient::actionDictionary(const NavigationAction& action, PassRefPtr<FormState> formState) const
  1126. {
  1127. unsigned modifierFlags = 0;
  1128. const Event* event = action.event();
  1129. if (const UIEventWithKeyState* keyStateEvent = findEventWithKeyState(const_cast<Event*>(event))) {
  1130. if (keyStateEvent->ctrlKey())
  1131. modifierFlags |= NSControlKeyMask;
  1132. if (keyStateEvent->altKey())
  1133. modifierFlags |= NSAlternateKeyMask;
  1134. if (keyStateEvent->shiftKey())
  1135. modifierFlags |= NSShiftKeyMask;
  1136. if (keyStateEvent->metaKey())
  1137. modifierFlags |= NSCommandKeyMask;
  1138. }
  1139. NSURL *originalURL = action.url();
  1140. NSMutableDictionary *result = [NSMutableDictionary dictionaryWithObjectsAndKeys:
  1141. [NSNumber numberWithInt:action.type()], WebActionNavigationTypeKey,
  1142. [NSNumber numberWithInt:modifierFlags], WebActionModifierFlagsKey,
  1143. originalURL, WebActionOriginalURLKey,
  1144. nil];
  1145. if (const MouseEvent* mouseEvent = findMouseEvent(event)) {
  1146. WebElementDictionary *element = [[WebElementDictionary alloc]
  1147. initWithHitTestResult:core(m_webFrame.get())->eventHandler()->hitTestResultAtPoint(mouseEvent->absoluteLocation())];
  1148. [result setObject:element forKey:WebActionElementKey];
  1149. [element release];
  1150. [result setObject:[NSNumber numberWithInt:mouseEvent->button()] forKey:WebActionButtonKey];
  1151. }
  1152. if (formState) {
  1153. ASSERT(formState->form());
  1154. [result setObject:kit(formState->form()) forKey:WebActionFormKey];
  1155. }
  1156. return result;
  1157. }
  1158. bool WebFrameLoaderClient::canCachePage() const
  1159. {
  1160. // We can only cache HTML pages right now
  1161. return [[[m_webFrame.get() _dataSource] representation] isKindOfClass:[WebHTMLRepresentation class]];
  1162. }
  1163. PassRefPtr<Frame> WebFrameLoaderClient::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement,
  1164. const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight)
  1165. {
  1166. BEGIN_BLOCK_OBJC_EXCEPTIONS;
  1167. ASSERT(m_webFrame);
  1168. WebFrameView *childView = [[WebFrameView alloc] init];
  1169. RefPtr<Frame> result = [WebFrame _createSubframeWithOwnerElement:ownerElement frameName:name frameView:childView];
  1170. [childView release];
  1171. WebFrame *newFrame = kit(result.get());
  1172. if ([newFrame _dataSource])
  1173. [[newFrame _dataSource] _documentLoader]->setOverrideEncoding([[m_webFrame.get() _dataSource] _documentLoader]->overrideEncoding());
  1174. // The creation of the frame may have run arbitrary JavaScript that removed it from the page already.
  1175. if (!result->page())
  1176. return 0;
  1177. core(m_webFrame.get())->loader()->loadURLIntoChildFrame(url, referrer, result.get());
  1178. // The frame's onload handler may have removed it from the document.
  1179. if (!result->tree()->parent())
  1180. return 0;
  1181. return result.release();
  1182. END_BLOCK_OBJC_EXCEPTIONS;
  1183. return 0;
  1184. }
  1185. ObjectContentType WebFrameLoaderClient::objectContentType(const KURL& url, const String& mimeType, bool shouldPreferPlugInsForImages)
  1186. {
  1187. BEGIN_BLOCK_OBJC_EXCEPTIONS;
  1188. String type = mimeType;
  1189. if (type.isEmpty()) {
  1190. // Try to guess the MIME type based off the extension.
  1191. NSURL *URL = url;
  1192. NSString *extension = [[URL path] pathExtension];
  1193. if ([extension length] > 0) {
  1194. type = WKGetMIMETypeForExtension(extension);
  1195. if (type.isEmpty()) {
  1196. // If no MIME type is specified, use a plug-in if we have one that can handle the extension.
  1197. if (WebBasePluginPackage *package = [getWebView(m_webFrame.get()) _pluginForExtension:extension]) {
  1198. if ([package isKindOfClass:[WebPluginPackage class]])
  1199. return ObjectContentOtherPlugin;
  1200. #if ENABLE(NETSCAPE_PLUGIN_API)
  1201. else {
  1202. ASSERT([package isKindOfClass:[WebNetscapePluginPackage class]]);
  1203. return ObjectContentNetscapePlugin;
  1204. }
  1205. #endif
  1206. }
  1207. }
  1208. }
  1209. }
  1210. if (type.isEmpty())
  1211. return ObjectContentFrame; // Go ahead and hope that we can display the content.
  1212. WebBasePluginPackage *package = [getWebView(m_webFrame.get()) _pluginForMIMEType:type];
  1213. ObjectContentType plugInType = ObjectContentNone;
  1214. if (package) {
  1215. #if ENABLE(NETSCAPE_PLUGIN_API)
  1216. if ([package isKindOfClass:[WebNetscapePluginPackage class]])
  1217. plugInType = ObjectContentNetscapePlugin;
  1218. else
  1219. #endif
  1220. {
  1221. ASSERT([package isKindOfClass:[WebPluginPackage class]]);
  1222. plugInType = ObjectContentOtherPlugin;
  1223. }
  1224. }
  1225. if (MIMETypeRegistry::isSupportedImageMIMEType(type))
  1226. return shouldPreferPlugInsForImages && plugInType != ObjectContentNone ? plugInType : ObjectContentImage;
  1227. if (plugInType != ObjectContentNone)
  1228. return plugInType;
  1229. if ([m_webFrame->_private->webFrameView _viewClassForMIMEType:type])
  1230. return ObjectContentFrame;
  1231. return ObjectContentNone;
  1232. END_BLOCK_OBJC_EXCEPTIONS;
  1233. return ObjectContentNone;
  1234. }
  1235. static NSMutableArray* kit(const Vector<String>& vector)
  1236. {
  1237. unsigned len = vector.size();
  1238. NSMutableArray* array = [NSMutableArray arrayWithCapacity:len];
  1239. for (unsigned x = 0; x < len; x++)
  1240. [array addObject:vector[x]];
  1241. return array;
  1242. }
  1243. static String parameterValue(const Vector<String>& paramNames, const Vector<String>& paramValues, const String& name)
  1244. {
  1245. size_t size = paramNames.size();
  1246. ASSERT(size == paramValues.size());
  1247. for (size_t i = 0; i < size; ++i) {
  1248. if (equalIgnoringCase(paramNames[i], name))
  1249. return paramValues[i];
  1250. }
  1251. return String();
  1252. }
  1253. static NSView *pluginView(WebFrame *frame, WebPluginPackage *pluginPackage,
  1254. NSArray *attributeNames, NSArray *attributeValues, NSURL *baseURL,
  1255. DOMElement *element, BOOL loadManually)
  1256. {
  1257. WebHTMLView *docView = (WebHTMLView *)[[frame frameView] documentView];
  1258. ASSERT([docView isKindOfClass:[WebHTMLView class]]);
  1259. WebPluginController *pluginController = [docView _pluginController];
  1260. // Store attributes in a dictionary so they can be passed to WebPlugins.
  1261. NSMutableDictionary *attributes = [[NSMutableDictionary alloc] initWithObjects:attributeValues forKeys:attributeNames];
  1262. [pluginPackage load];
  1263. Class viewFactory = [pluginPackage viewFactory];
  1264. NSView *view = nil;
  1265. NSDictionary *arguments = nil;
  1266. if ([viewFactory respondsToSelector:@selector(plugInViewWithArguments:)]) {
  1267. arguments = [NSDictionary dictionaryWithObjectsAndKeys:
  1268. baseURL, WebPlugInBaseURLKey,
  1269. attributes, WebPlugInAttributesKey,
  1270. pluginController, WebPlugInContainerKey,
  1271. [NSNumber numberWithInt:loadManually ? WebPlugInModeFull : WebPlugInModeEmbed], WebPlugInModeKey,
  1272. [NSNumber numberWithBool:!loadManually], WebPlugInShouldLoadMainResourceKey,
  1273. element, WebPlugInContainingElementKey,
  1274. nil];
  1275. LOG(Plugins, "arguments:\n%@", arguments);
  1276. } else if ([viewFactory respondsToSelector:@selector(pluginViewWithArguments:)]) {
  1277. arguments = [NSDictionary dictionaryWithObjectsAndKeys:
  1278. baseURL, WebPluginBaseURLKey,
  1279. attributes, WebPluginAttributesKey,
  1280. pluginController, WebPluginContainerKey,
  1281. element, WebPlugInContainingElementKey,
  1282. nil];
  1283. LOG(Plugins, "arguments:\n%@", arguments);
  1284. }
  1285. view = [WebPluginController plugInViewWithArguments:arguments fromPluginPackage:pluginPackage];
  1286. [attributes release];
  1287. return view;
  1288. }
  1289. class PluginWidget : public PluginViewBase {
  1290. public:
  1291. PluginWidget(NSView *view = 0)
  1292. : PluginViewBase(view)
  1293. {
  1294. }
  1295. private:
  1296. virtual void invalidateRect(const IntRect& rect)
  1297. {
  1298. [platformWidget() setNeedsDisplayInRect:rect];
  1299. }
  1300. };
  1301. #if ENABLE(NETSCAPE_PLUGIN_API)
  1302. class NetscapePluginWidget : public PluginWidget {
  1303. public:
  1304. NetscapePluginWidget(WebBaseNetscapePluginView *view)
  1305. : PluginWidget(view)
  1306. {
  1307. }
  1308. #if USE(ACCELERATED_COMPOSITING)
  1309. virtual PlatformLayer* platformLayer() const
  1310. {
  1311. return [(WebBaseNetscapePluginView *)platformWidget() pluginLayer];
  1312. }
  1313. #endif
  1314. virtual bool getFormValue(String& value)
  1315. {
  1316. NSString* nsValue = 0;
  1317. if ([(WebBaseNetscapePluginView *)platformWidget() getFormValue:&nsValue]) {
  1318. if (!nsValue)
  1319. return false;
  1320. value = String(nsValue);
  1321. [nsValue release];
  1322. return true;
  1323. }
  1324. return false;
  1325. }
  1326. virtual void handleEvent(Event* event)
  1327. {
  1328. Frame* frame = Frame::frameForWidget(this);
  1329. if (!frame)
  1330. return;
  1331. NSEvent* currentNSEvent = frame->eventHandler()->currentNSEvent();
  1332. if (event->type() == eventNames().mousemoveEvent)
  1333. [(WebBaseNetscapePluginView *)platformWidget() handleMouseMoved:currentNSEvent];
  1334. else if (event->type() == eventNames().mouseoverEvent)
  1335. [(WebBaseNetscapePluginView *)platformWidget() handleMouseEntered:currentNSEvent];
  1336. else if (event->type() == eventNames().mouseoutEvent)
  1337. [(WebBaseNetscapePluginView *)platformWidget() handleMouseExited:currentNSEvent];
  1338. else if (event->type() == eventNames().contextmenuEvent)
  1339. event->setDefaultHandled(); // We don't know if the plug-in has handled mousedown event by displaying a context menu, so we never want WebKit to show a default one.
  1340. }
  1341. virtual void clipRectChanged()
  1342. {
  1343. // Changing the clip rect doesn't affect the view hierarchy, so the plugin must be told about the change directly.
  1344. [(WebBaseNetscapePluginView *)platformWidget() updateAndSetWindow];
  1345. }
  1346. private:
  1347. virtual void notifyWidget(WidgetNotification notification)
  1348. {
  1349. switch (notification) {
  1350. case WillPaintFlattened: {
  1351. BEGIN_BLOCK_OBJC_EXCEPTIONS;
  1352. [(WebBaseNetscapePluginView *)platformWidget() cacheSnapshot];
  1353. END_BLOCK_OBJC_EXCEPTIONS;
  1354. break;
  1355. }
  1356. case DidPaintFlattened: {
  1357. BEGIN_BLOCK_OBJC_EXCEPTIONS;
  1358. [(WebBaseNetscapePluginView *)platformWidget() clearCachedSnapshot];
  1359. END_BLOCK_OBJC_EXCEPTIONS;
  1360. break;
  1361. }
  1362. }
  1363. }
  1364. };
  1365. #if USE(PLUGIN_HOST_PROCESS)
  1366. #define NETSCAPE_PLUGIN_VIEW WebHostedNetscapePluginView
  1367. #else
  1368. #define NETSCAPE_PLUGIN_VIEW WebNetscapePluginView
  1369. #endif
  1370. #endif // ENABLE(NETSCAPE_PLUGIN_API)
  1371. PassRefPtr<Widget> WebFrameLoaderClient::createPlugin(const IntSize& size, HTMLPlugInElement* element, const KURL& url,
  1372. const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually)
  1373. {
  1374. BEGIN_BLOCK_OBJC_EXCEPTIONS;
  1375. ASSERT(paramNames.size() == paramValues.size());
  1376. int errorCode = 0;
  1377. WebView *webView = getWebView(m_webFrame.get());
  1378. SEL selector = @selector(webView:plugInViewWithArguments:);
  1379. Document* document = core(m_webFrame.get())->document();
  1380. NSURL *baseURL = document->baseURL();
  1381. NSURL *pluginURL = url;
  1382. // <rdar://problem/8366089>: AppleConnect has a bug where it does not
  1383. // understand the parameter names specified in the <object> element that
  1384. // embeds its plug-in. This site-specific hack works around the issue by
  1385. // converting the parameter names to lowercase before passing them to the
  1386. // plug-in.
  1387. Frame* frame = core(m_webFrame.get());
  1388. NSMutableArray *attributeKeys = kit(paramNames);
  1389. if (frame && frame->settings()->needsSiteSpecificQuirks() && equalIgnoringCase(mimeType, "application/x-snkp")) {
  1390. for (NSUInteger i = 0; i < [attributeKeys count]; ++i)
  1391. [attributeKeys replaceObjectAtIndex:i withObject:[[attributeKeys objectAtIndex:i] lowercaseString]];
  1392. }
  1393. if ([[webView UIDelegate] respondsToSelector:selector]) {
  1394. NSMutableDictionary *attributes = [[NSMutableDictionary alloc] initWithObjects:kit(paramValues) forKeys:attributeKeys];
  1395. NSDictionary *arguments = [[NSDictionary alloc] initWithObjectsAndKeys:
  1396. attributes, WebPlugInAttributesKey,
  1397. [NSNumber numberWithInt:loadManually ? WebPlugInModeFull : WebPlugInModeEmbed], WebPlugInModeKey,
  1398. [NSNumber numberWithBool:!loadManually], WebPlugInShouldLoadMainResourceKey,
  1399. kit(element), WebPlugInContainingElementKey,
  1400. // FIXME: We should be passing base URL, see <https://bugs.webkit.org/show_bug.cgi?id=35215>.
  1401. pluginURL, WebPlugInBaseURLKey, // pluginURL might be nil, so add it last
  1402. nil];
  1403. NSView *view = CallUIDelegate(webView, selector, arguments);
  1404. [attributes release];
  1405. [arguments release];
  1406. if (view)
  1407. return adoptRef(new PluginWidget(view));
  1408. }
  1409. NSString *MIMEType;
  1410. WebBasePluginPackage *pluginPackage;
  1411. if (mimeType.isEmpty()) {
  1412. MIMEType = nil;
  1413. pluginPackage = nil;
  1414. } else {
  1415. MIMEType = mimeType;
  1416. pluginPackage = [webView _pluginForMIMEType:mimeType];
  1417. }
  1418. NSString *extension = [[pluginURL path] pathExtension];
  1419. if (!pluginPackage && [extension length] && ![MIMEType length]) {
  1420. pluginPackage = [webView _pluginForExtension:extension];
  1421. if (pluginPackage) {
  1422. NSString *newMIMEType = [pluginPackage MIMETypeForExtension:extension];
  1423. if ([newMIMEType length] != 0)
  1424. MIMEType = newMIMEType;
  1425. }
  1426. }
  1427. NSView *view = nil;
  1428. if (pluginPackage) {
  1429. if (WKShouldBlockPlugin([pluginPackage bundleIdentifier], [pluginPackage bundleVersion])) {
  1430. errorCode = WebKitErrorBlockedPlugInVersion;
  1431. if (element->renderer()->isEmbeddedObject())
  1432. toRenderEmbeddedObject(element->renderer())->setPluginUnavailabilityReason(RenderEmbeddedObject::InsecurePluginVersion);
  1433. } else {
  1434. if ([pluginPackage isKindOfClass:[WebPluginPackage class]])
  1435. view = pluginView(m_webFrame.get(), (WebPluginPackage *)pluginPackage, attributeKeys, kit(paramValues), baseURL, kit(element), loadManually);
  1436. #if ENABLE(NETSCAPE_PLUGIN_API)
  1437. else if ([pluginPackage isKindOfClass:[WebNetscapePluginPackage class]]) {
  1438. WebBaseNetscapePluginView *pluginView = [[[NETSCAPE_PLUGIN_VIEW alloc]
  1439. initWithFrame:NSMakeRect(0, 0, size.width(), size.height())
  1440. pluginPackage:(WebNetscapePluginPackage *)pluginPackage
  1441. URL:pluginURL
  1442. baseURL:baseURL
  1443. MIMEType:MIMEType
  1444. attributeKeys:attributeKeys
  1445. attributeValues:kit(paramValues)
  1446. loadManually:loadManually
  1447. element:element] autorelease];
  1448. return adoptRef(new NetscapePluginWidget(pluginView));
  1449. }
  1450. #endif
  1451. }
  1452. } else
  1453. errorCode = WebKitErrorCannotFindPlugIn;
  1454. if (!errorCode && !view)
  1455. errorCode = WebKitErrorCannotLoadPlugIn;
  1456. if (errorCode && m_webFrame) {
  1457. WebResourceDelegateImplementationCache* implementations = WebViewGetResourceLoadDelegateImplementations(webView);
  1458. if (implementations->plugInFailedWithErrorFunc) {
  1459. KURL pluginPageURL = document->completeURL(stripLeadingAndTrailingHTMLSpaces(parameterValue(paramNames, paramValues, "pluginspage")));
  1460. if (!pluginPageURL.protocolIsInHTTPFamily())
  1461. pluginPageURL = KURL();
  1462. NSString *pluginName = pluginPackage ? (NSString *)[pluginPackage pluginInfo].name : nil;
  1463. NSError *error = [[NSError alloc] _initWithPluginErrorCode:errorCode
  1464. contentURL:pluginURL pluginPageURL:pluginPageURL pluginName:pluginName MIMEType:MIMEType];
  1465. CallResourceLoadDelegate(implementations->plugInFailedWithErrorFunc, [m_webFrame.get() webView],
  1466. @selector(webView:plugInFailedWithError:dataSource:), error, [m_webFrame.get() _dataSource]);
  1467. [error release];
  1468. }
  1469. return 0;
  1470. }
  1471. ASSERT(view);
  1472. return adoptRef(new PluginWidget(view));
  1473. END_BLOCK_OBJC_EXCEPTIONS;
  1474. return 0;
  1475. }
  1476. void WebFrameLoaderClient::recreatePlugin(Widget*)
  1477. {
  1478. }
  1479. void WebFrameLoaderClient::redirectDataToPlugin(Widget* pluginWidget)
  1480. {
  1481. if (!pluginWidget)
  1482. return;
  1483. BEGIN_BLOCK_OBJC_EXCEPTIONS;
  1484. WebHTMLRepresentation *representation = (WebHTMLRepresentation *)[[m_webFrame.get() _dataSource] representation];
  1485. NSView *pluginView = pluginWidget->platformWidget();
  1486. #if ENABLE(NETSCAPE_PLUGIN_API)
  1487. if ([pluginView isKindOfClass:[NETSCAPE_PLUGIN_VIEW class]])
  1488. [representation _redirectDataToManualLoader:(NETSCAPE_PLUGIN_VIEW *)pluginView forPluginView:pluginView];
  1489. else {
  1490. #else
  1491. {
  1492. #endif
  1493. WebHTMLView *documentView = (WebHTMLView *)[[m_webFrame.get() frameView] documentView];
  1494. ASSERT([documentView isKindOfClass:[WebHTMLView class]]);
  1495. [representation _redirectDataToManualLoader:[documentView _pluginController] forPluginView:pluginView];
  1496. }
  1497. END_BLOCK_OBJC_EXCEPTIONS;
  1498. }
  1499. PassRefPtr<Widget> WebFrameLoaderClient::createJavaAppletWidget(const IntSize& size, HTMLAppletElement* element, const KURL& baseURL,
  1500. const Vector<String>& paramNames, const Vector<String>& paramValues)
  1501. {
  1502. BEGIN_BLOCK_OBJC_EXCEPTIONS;
  1503. NSView *view = nil;
  1504. NSString *MIMEType = @"application/x-java-applet";
  1505. WebView *webView = getWebView(m_webFrame.get());
  1506. WebBasePluginPackage *pluginPackage = [webView _pluginForMIMEType:MIMEType];
  1507. int errorCode = WebKitErrorJavaUnavailable;
  1508. if (pluginPackage) {
  1509. if (WKShouldBlockPlugin([pluginPackage bundleIdentifier], [pluginPackage bundleVersion])) {
  1510. errorCode = WebKitErrorBlockedPlugInVersion;
  1511. if (element->renderer()->isEmbeddedObject())
  1512. toRenderEmbeddedObject(element->renderer())->setPluginUnavailabilityReason(RenderEmbeddedObject::InsecurePluginVersion);
  1513. } else {
  1514. #if ENABLE(NETSCAPE_PLUGIN_API)
  1515. if ([pluginPackage isKindOfClass:[WebNetscapePluginPackage class]]) {
  1516. view = [[[NETSCAPE_PLUGIN_VIEW alloc] initWithFrame:NSMakeRect(0, 0, size.width(), size.height())
  1517. pluginPackage:(WebNetscapePluginPackage *)pluginPackage
  1518. URL:nil
  1519. baseURL:baseURL
  1520. MIMEType:MIMEType
  1521. attributeKeys:kit(paramNames)
  1522. attributeValues:kit(paramValues)
  1523. loadManually:NO
  1524. element:element] autorelease];
  1525. if (view)
  1526. return adoptRef(new NetscapePluginWidget(static_cast<WebBaseNetscapePluginView *>(view)));
  1527. }
  1528. #endif
  1529. }
  1530. }
  1531. if (!view) {
  1532. WebResourceDelegateImplementationCache* implementations = WebViewGetResourceLoadDelegateImplementations(getWebView(m_webFrame.get()));
  1533. if (implementations->plugInFailedWithErrorFunc) {
  1534. NSString *pluginName = pluginPackage ? (NSString *)[pluginPackage pluginInfo].name : nil;
  1535. NSError *error = [[NSError alloc] _initWithPluginErrorCode:errorCode contentURL:nil pluginPageURL:nil pluginName:pluginName MIMEType:MIMEType];
  1536. CallResourceLoadDelegate(implementations->plugInFailedWithErrorFunc, [m_webFrame.get() webView],
  1537. @selector(webView:plugInFailedWithError:dataSource:), error, [m_webFrame.get() _dataSource]);
  1538. [error release];
  1539. }
  1540. }
  1541. END_BLOCK_OBJC_EXCEPTIONS;
  1542. return 0;
  1543. }
  1544. #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
  1545. PassRefPtr<Widget> WebFrameLoaderClient::createMediaPlayerProxyPlugin(const IntSize& size, HTMLMediaElement* element, const KURL& url,
  1546. const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType)
  1547. {
  1548. BEGIN_BLOCK_OBJC_EXCEPTIONS;
  1549. ASSERT(paramNames.size() == paramValues.size());
  1550. ASSERT(mimeType);
  1551. int errorCode = 0;
  1552. WebView *webView = getWebView(m_webFrame.get());
  1553. NSURL *URL = url;
  1554. SEL selector = @selector(webView:plugInViewWithArguments:);
  1555. if ([[webView UIDelegate] respondsToSelector:selector]) {
  1556. NSMutableDictionary *attributes = [[NSMutableDictionary alloc] initWithObjects:kit(paramValues) forKeys:kit(paramNames)];
  1557. NSDictionary *arguments = [[NSDictionary alloc] initWithObjectsAndKeys:
  1558. attributes, WebPlugInAttributesKey,
  1559. [NSNumber numberWithInt:WebPlugInModeEmbed], WebPlugInModeKey,
  1560. [NSNumber numberWithBool:YES], WebPlugInShouldLoadMainResourceKey,
  1561. kit(element), WebPlugInContainingElementKey,
  1562. URL, WebPlugInBaseURLKey, // URL might be nil, so add it last
  1563. nil];
  1564. NSView *view = CallUIDelegate(webView, selector, arguments);
  1565. [attributes release];
  1566. [arguments release];
  1567. if (view)
  1568. return adoptRef(new PluginWidget(view));
  1569. }
  1570. WebBasePluginPackage *pluginPackage = [webView _videoProxyPluginForMIMEType:mimeType];
  1571. Document* document = core(m_webFrame.get())->document();
  1572. NSURL *baseURL = document->baseURL();
  1573. NSView *view = nil;
  1574. if (pluginPackage) {
  1575. if ([pluginPackage isKindOfClass:[WebPluginPackage class]])
  1576. view = pluginView(m_webFrame.get(), (WebPluginPackage *)pluginPackage, kit(paramNames), kit(paramValues), baseURL, kit(element), false);
  1577. } else
  1578. errorCode = WebKitErrorCannotFindPlugIn;
  1579. if (!errorCode && !view)
  1580. errorCode = WebKitErrorCannotLoadPlugIn;
  1581. if (errorCode) {
  1582. NSError *error = [[NSError alloc] _initWithPluginErrorCode:errorCode
  1583. contentURL:URL pluginPageURL:nil pluginName:[pluginPackage pluginInfo].name MIMEType:mimeType];
  1584. WebNullPluginView *nullView = [[[WebNullPluginView alloc] initWithFrame:NSMakeRect(0, 0, size.width(), size.height())
  1585. error:error DOMElement:kit(element)] autorelease];
  1586. view = nullView;
  1587. [error release];
  1588. }
  1589. ASSERT(view);
  1590. return adoptRef(new PluginWidget(view));
  1591. END_BLOCK_OBJC_EXCEPTIONS;
  1592. return 0;
  1593. }
  1594. void WebFrameLoaderClient::hideMediaPlayerProxyPlugin(Widget* widget)
  1595. {
  1596. [WebPluginController pluginViewHidden:widget->platformWidget()];
  1597. }
  1598. void WebFrameLoaderClient::showMediaPlayerProxyPlugin(Widget* widget)
  1599. {
  1600. [WebPluginController addPlugInView:widget->platformWidget()];
  1601. }
  1602. #endif // ENABLE(PLUGIN_PROXY_FOR_VIDEO)
  1603. String WebFrameLoaderClient::overrideMediaType() const
  1604. {
  1605. NSString* overrideType = [getWebView(m_webFrame.get()) mediaStyle];
  1606. if (overrideType)
  1607. return overrideType;
  1608. return String();
  1609. }
  1610. void WebFrameLoaderClient::documentElementAvailable() {
  1611. }
  1612. void WebFrameLoaderClient::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world)
  1613. {
  1614. WebView *webView = getWebView(m_webFrame.get());
  1615. WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
  1616. if (implementations->didClearWindowObjectForFrameInScriptWorldFunc) {
  1617. CallFrameLoadDelegate(implementations->didClearWindowObjectForFrameInScriptWorldFunc,
  1618. webView, @selector(webView:didClearWindowObjectForFrame:inScriptWorld:), m_webFrame.get(), [WebScriptWorld findOrCreateWorld:world]);
  1619. return;
  1620. }
  1621. if (world != mainThreadNormalWorld())
  1622. return;
  1623. Frame *frame = core(m_webFrame.get());
  1624. ScriptController *script = frame->script();
  1625. #if JSC_OBJC_API_ENABLED
  1626. if (implementations->didCreateJavaScriptContextForFrameFunc) {
  1627. CallFrameLoadDelegate(implementations->didCreateJavaScriptContextForFrameFunc, webView, @selector(webView:didCreateJavaScriptContext:forFrame:),
  1628. script->javaScriptContext(), m_webFrame.get());
  1629. } else if (implementations->didClearWindowObjectForFrameFunc) {
  1630. #else
  1631. if (implementations->didClearWindowObjectForFrameFunc) {
  1632. #endif
  1633. CallFrameLoadDelegate(implementations->didClearWindowObjectForFrameFunc, webView, @selector(webView:didClearWindowObject:forFrame:),
  1634. script->windowScriptObject(), m_webFrame.get());
  1635. } else if (implementations->windowScriptObjectAvailableFunc) {
  1636. CallFrameLoadDelegate(implementations->windowScriptObjectAvailableFunc, webView, @selector(webView:windowScriptObjectAvailable:),
  1637. script->windowScriptObject());
  1638. }
  1639. if ([webView scriptDebugDelegate]) {
  1640. [m_webFrame.get() _detachScriptDebugger];
  1641. [m_webFrame.get() _attachScriptDebugger];
  1642. }
  1643. }
  1644. void WebFrameLoaderClient::registerForIconNotification(bool listen)
  1645. {
  1646. #if ENABLE(ICONDATABASE)
  1647. [[m_webFrame.get() webView] _registerForIconNotification:listen];
  1648. #endif
  1649. }
  1650. void WebFrameLoaderClient::didPerformFirstNavigation() const
  1651. {
  1652. WebPreferences *preferences = [[m_webFrame.get() webView] preferences];
  1653. if ([preferences automaticallyDetectsCacheModel] && [preferences cacheModel] < WebCacheModelDocumentBrowser)
  1654. [preferences setCacheModel:WebCacheModelDocumentBrowser];
  1655. }
  1656. PassRefPtr<FrameNetworkingContext> WebFrameLoaderClient::createNetworkingContext()
  1657. {
  1658. return WebFrameNetworkingContext::create(core(m_webFrame.get()));
  1659. }
  1660. @implementation WebFramePolicyListener
  1661. + (void)initialize
  1662. {
  1663. JSC::initializeThreading();
  1664. WTF::initializeMainThreadToProcessMainThread();
  1665. WebCore::RunLoop::initializeMainRunLoop();
  1666. WebCoreObjCFinalizeOnMainThread(self);
  1667. }
  1668. - (id)initWithFrame:(Frame*)frame policyFunction:(FramePolicyFunction)policyFunction
  1669. {
  1670. self = [self init];
  1671. if (!self)
  1672. return nil;
  1673. _frame = frame;
  1674. _policyFunction = policyFunction;
  1675. return self;
  1676. }
  1677. - (void)invalidate
  1678. {
  1679. _frame = nullptr;
  1680. }
  1681. - (void)dealloc
  1682. {
  1683. if (WebCoreObjCScheduleDeallocateOnMainThread([WebFramePolicyListener class], self))
  1684. return;
  1685. [super dealloc];
  1686. }
  1687. - (void)receivedPolicyDecision:(PolicyAction)action
  1688. {
  1689. RefPtr<Frame> frame = _frame.release();
  1690. if (!frame)
  1691. return;
  1692. FramePolicyFunction policyFunction = _policyFunction;
  1693. _policyFunction = nullptr;
  1694. ASSERT(policyFunction);
  1695. (frame->loader()->policyChecker()->*policyFunction)(action);
  1696. }
  1697. - (void)ignore
  1698. {
  1699. [self receivedPolicyDecision:PolicyIgnore];
  1700. }
  1701. - (void)download
  1702. {
  1703. [self receivedPolicyDecision:PolicyDownload];
  1704. }
  1705. - (void)use
  1706. {
  1707. [self receivedPolicyDecision:PolicyUse];
  1708. }
  1709. - (void)continue
  1710. {
  1711. [self receivedPolicyDecision:PolicyUse];
  1712. }
  1713. @end