WebFrameLoaderClient.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. /*
  2. * Copyright (C) 2006, 2007, 2008, 2009 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. #include "config.h"
  29. #include "WebFrameLoaderClient.h"
  30. #include "CFDictionaryPropertyBag.h"
  31. #include "COMPropertyBag.h"
  32. #include "DOMHTMLClasses.h"
  33. #include "EmbeddedWidget.h"
  34. #include "MarshallingHelpers.h"
  35. #include "NotImplemented.h"
  36. #include "WebCachedFramePlatformData.h"
  37. #include "WebChromeClient.h"
  38. #include "WebDocumentLoader.h"
  39. #include "WebError.h"
  40. #include "WebFrame.h"
  41. #include "WebHistory.h"
  42. #include "WebHistoryItem.h"
  43. #include "WebMutableURLRequest.h"
  44. #include "WebNavigationData.h"
  45. #include "WebNotificationCenter.h"
  46. #include "WebSecurityOrigin.h"
  47. #include "WebURLAuthenticationChallenge.h"
  48. #include "WebURLResponse.h"
  49. #include "WebView.h"
  50. #include <WebCore/BackForwardController.h>
  51. #include <WebCore/CachedFrame.h>
  52. #include <WebCore/DocumentLoader.h>
  53. #include <WebCore/Frame.h>
  54. #include <WebCore/FrameLoader.h>
  55. #include <WebCore/FrameTree.h>
  56. #include <WebCore/FrameView.h>
  57. #include <WebCore/HTMLAppletElement.h>
  58. #include <WebCore/HTMLFrameElement.h>
  59. #include <WebCore/HTMLFrameOwnerElement.h>
  60. #include <WebCore/HTMLNames.h>
  61. #include <WebCore/HTMLParserIdioms.h>
  62. #include <WebCore/HTMLPlugInElement.h>
  63. #include <WebCore/HistoryItem.h>
  64. #include <WebCore/Page.h>
  65. #include <WebCore/PluginPackage.h>
  66. #include <WebCore/PluginView.h>
  67. #include <WebCore/RenderPart.h>
  68. #include <WebCore/ResourceHandle.h>
  69. #include <WebCore/ResourceLoader.h>
  70. #include <WebCore/Settings.h>
  71. using namespace WebCore;
  72. using namespace HTMLNames;
  73. static WebDataSource* getWebDataSource(DocumentLoader* loader)
  74. {
  75. return loader ? static_cast<WebDocumentLoader*>(loader)->dataSource() : 0;
  76. }
  77. WebFrameLoaderClient::WebFrameLoaderClient(WebFrame* webFrame)
  78. : m_webFrame(webFrame)
  79. , m_manualLoader(0)
  80. , m_hasSentResponseToPlugin(false)
  81. {
  82. ASSERT_ARG(webFrame, webFrame);
  83. }
  84. WebFrameLoaderClient::~WebFrameLoaderClient()
  85. {
  86. }
  87. bool WebFrameLoaderClient::hasWebView() const
  88. {
  89. return m_webFrame->webView();
  90. }
  91. void WebFrameLoaderClient::forceLayout()
  92. {
  93. Frame* frame = core(m_webFrame);
  94. if (!frame)
  95. return;
  96. if (frame->document() && frame->document()->inPageCache())
  97. return;
  98. FrameView* view = frame->view();
  99. if (!view)
  100. return;
  101. view->setNeedsLayout();
  102. view->forceLayout(true);
  103. }
  104. void WebFrameLoaderClient::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request)
  105. {
  106. WebView* webView = m_webFrame->webView();
  107. COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
  108. if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))
  109. return;
  110. COMPtr<WebMutableURLRequest> webURLRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));
  111. resourceLoadDelegate->identifierForInitialRequest(webView, webURLRequest.get(), getWebDataSource(loader), identifier);
  112. }
  113. bool WebFrameLoaderClient::shouldUseCredentialStorage(DocumentLoader* loader, unsigned long identifier)
  114. {
  115. WebView* webView = m_webFrame->webView();
  116. COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
  117. if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))
  118. return true;
  119. COMPtr<IWebResourceLoadDelegatePrivate> resourceLoadDelegatePrivate;
  120. if (FAILED(resourceLoadDelegate->QueryInterface(IID_IWebResourceLoadDelegatePrivate, reinterpret_cast<void**>(&resourceLoadDelegatePrivate))))
  121. return true;
  122. BOOL shouldUse;
  123. if (SUCCEEDED(resourceLoadDelegatePrivate->shouldUseCredentialStorage(webView, identifier, getWebDataSource(loader), &shouldUse)))
  124. return shouldUse;
  125. return true;
  126. }
  127. void WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge(DocumentLoader* loader, unsigned long identifier, const AuthenticationChallenge& challenge)
  128. {
  129. #if USE(CFNETWORK)
  130. ASSERT(challenge.authenticationClient());
  131. WebView* webView = m_webFrame->webView();
  132. COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
  133. if (SUCCEEDED(webView->resourceLoadDelegate(&resourceLoadDelegate))) {
  134. COMPtr<WebURLAuthenticationChallenge> webChallenge(AdoptCOM, WebURLAuthenticationChallenge::createInstance(challenge));
  135. if (SUCCEEDED(resourceLoadDelegate->didReceiveAuthenticationChallenge(webView, identifier, webChallenge.get(), getWebDataSource(loader))))
  136. return;
  137. }
  138. // If the ResourceLoadDelegate doesn't exist or fails to handle the call, we tell the ResourceHandle
  139. // to continue without credential - this is the best approximation of Mac behavior
  140. challenge.authenticationClient()->receivedRequestToContinueWithoutCredential(challenge);
  141. #else
  142. notImplemented();
  143. #endif
  144. }
  145. void WebFrameLoaderClient::dispatchDidCancelAuthenticationChallenge(DocumentLoader* loader, unsigned long identifier, const AuthenticationChallenge& challenge)
  146. {
  147. WebView* webView = m_webFrame->webView();
  148. COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
  149. if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))
  150. return;
  151. COMPtr<WebURLAuthenticationChallenge> webChallenge(AdoptCOM, WebURLAuthenticationChallenge::createInstance(challenge));
  152. resourceLoadDelegate->didCancelAuthenticationChallenge(webView, identifier, webChallenge.get(), getWebDataSource(loader));
  153. }
  154. void WebFrameLoaderClient::dispatchWillSendRequest(DocumentLoader* loader, unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse)
  155. {
  156. WebView* webView = m_webFrame->webView();
  157. COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
  158. if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))
  159. return;
  160. COMPtr<WebMutableURLRequest> webURLRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));
  161. COMPtr<WebURLResponse> webURLRedirectResponse(AdoptCOM, WebURLResponse::createInstance(redirectResponse));
  162. COMPtr<IWebURLRequest> newWebURLRequest;
  163. if (FAILED(resourceLoadDelegate->willSendRequest(webView, identifier, webURLRequest.get(), webURLRedirectResponse.get(), getWebDataSource(loader), &newWebURLRequest)))
  164. return;
  165. if (webURLRequest == newWebURLRequest)
  166. return;
  167. if (!newWebURLRequest) {
  168. request = ResourceRequest();
  169. return;
  170. }
  171. COMPtr<WebMutableURLRequest> newWebURLRequestImpl(Query, newWebURLRequest);
  172. if (!newWebURLRequestImpl)
  173. return;
  174. request = newWebURLRequestImpl->resourceRequest();
  175. }
  176. void WebFrameLoaderClient::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& response)
  177. {
  178. WebView* webView = m_webFrame->webView();
  179. COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
  180. if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))
  181. return;
  182. COMPtr<WebURLResponse> webURLResponse(AdoptCOM, WebURLResponse::createInstance(response));
  183. resourceLoadDelegate->didReceiveResponse(webView, identifier, webURLResponse.get(), getWebDataSource(loader));
  184. }
  185. void WebFrameLoaderClient::dispatchDidReceiveContentLength(DocumentLoader* loader, unsigned long identifier, int length)
  186. {
  187. WebView* webView = m_webFrame->webView();
  188. COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
  189. if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))
  190. return;
  191. resourceLoadDelegate->didReceiveContentLength(webView, identifier, length, getWebDataSource(loader));
  192. }
  193. void WebFrameLoaderClient::dispatchDidFinishLoading(DocumentLoader* loader, unsigned long identifier)
  194. {
  195. WebView* webView = m_webFrame->webView();
  196. COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
  197. if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))
  198. return;
  199. resourceLoadDelegate->didFinishLoadingFromDataSource(webView, identifier, getWebDataSource(loader));
  200. }
  201. void WebFrameLoaderClient::dispatchDidFailLoading(DocumentLoader* loader, unsigned long identifier, const ResourceError& error)
  202. {
  203. WebView* webView = m_webFrame->webView();
  204. COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
  205. if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))
  206. return;
  207. COMPtr<WebError> webError(AdoptCOM, WebError::createInstance(error));
  208. resourceLoadDelegate->didFailLoadingWithError(webView, identifier, webError.get(), getWebDataSource(loader));
  209. }
  210. bool WebFrameLoaderClient::shouldCacheResponse(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& response, const unsigned char* data, const unsigned long long length)
  211. {
  212. WebView* webView = m_webFrame->webView();
  213. COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
  214. if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))
  215. return true;
  216. COMPtr<IWebResourceLoadDelegatePrivate> resourceLoadDelegatePrivate(Query, resourceLoadDelegate);
  217. if (!resourceLoadDelegatePrivate)
  218. return true;
  219. COMPtr<IWebURLResponse> urlResponse(AdoptCOM, WebURLResponse::createInstance(response));
  220. BOOL shouldCache;
  221. if (SUCCEEDED(resourceLoadDelegatePrivate->shouldCacheResponse(webView, identifier, urlResponse.get(), data, length, getWebDataSource(loader), &shouldCache)))
  222. return shouldCache;
  223. return true;
  224. }
  225. void WebFrameLoaderClient::dispatchDidHandleOnloadEvents()
  226. {
  227. WebView* webView = m_webFrame->webView();
  228. COMPtr<IWebFrameLoadDelegatePrivate> frameLoadDelegatePriv;
  229. if (SUCCEEDED(webView->frameLoadDelegatePrivate(&frameLoadDelegatePriv)) && frameLoadDelegatePriv)
  230. frameLoadDelegatePriv->didHandleOnloadEventsForFrame(webView, m_webFrame);
  231. }
  232. void WebFrameLoaderClient::dispatchDidReceiveServerRedirectForProvisionalLoad()
  233. {
  234. WebView* webView = m_webFrame->webView();
  235. COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
  236. if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))
  237. frameLoadDelegate->didReceiveServerRedirectForProvisionalLoadForFrame(webView, m_webFrame);
  238. }
  239. void WebFrameLoaderClient::dispatchDidCancelClientRedirect()
  240. {
  241. WebView* webView = m_webFrame->webView();
  242. COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
  243. if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))
  244. frameLoadDelegate->didCancelClientRedirectForFrame(webView, m_webFrame);
  245. }
  246. void WebFrameLoaderClient::dispatchWillPerformClientRedirect(const KURL& url, double delay, double fireDate)
  247. {
  248. WebView* webView = m_webFrame->webView();
  249. COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
  250. if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))
  251. frameLoadDelegate->willPerformClientRedirectToURL(webView, BString(url.string()), delay, MarshallingHelpers::CFAbsoluteTimeToDATE(fireDate), m_webFrame);
  252. }
  253. void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage()
  254. {
  255. WebView* webView = m_webFrame->webView();
  256. COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
  257. if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))
  258. frameLoadDelegate->didChangeLocationWithinPageForFrame(webView, m_webFrame);
  259. }
  260. void WebFrameLoaderClient::dispatchDidPushStateWithinPage()
  261. {
  262. WebView* webView = m_webFrame->webView();
  263. COMPtr<IWebFrameLoadDelegatePrivate> frameLoadDelegatePriv;
  264. if (FAILED(webView->frameLoadDelegatePrivate(&frameLoadDelegatePriv)) || !frameLoadDelegatePriv)
  265. return;
  266. COMPtr<IWebFrameLoadDelegatePrivate2> frameLoadDelegatePriv2(Query, frameLoadDelegatePriv);
  267. if (!frameLoadDelegatePriv2)
  268. return;
  269. frameLoadDelegatePriv2->didPushStateWithinPageForFrame(webView, m_webFrame);
  270. }
  271. void WebFrameLoaderClient::dispatchDidReplaceStateWithinPage()
  272. {
  273. WebView* webView = m_webFrame->webView();
  274. COMPtr<IWebFrameLoadDelegatePrivate> frameLoadDelegatePriv;
  275. if (FAILED(webView->frameLoadDelegatePrivate(&frameLoadDelegatePriv)) || !frameLoadDelegatePriv)
  276. return;
  277. COMPtr<IWebFrameLoadDelegatePrivate2> frameLoadDelegatePriv2(Query, frameLoadDelegatePriv);
  278. if (!frameLoadDelegatePriv2)
  279. return;
  280. frameLoadDelegatePriv2->didReplaceStateWithinPageForFrame(webView, m_webFrame);
  281. }
  282. void WebFrameLoaderClient::dispatchDidPopStateWithinPage()
  283. {
  284. WebView* webView = m_webFrame->webView();
  285. COMPtr<IWebFrameLoadDelegatePrivate> frameLoadDelegatePriv;
  286. if (FAILED(webView->frameLoadDelegatePrivate(&frameLoadDelegatePriv)) || !frameLoadDelegatePriv)
  287. return;
  288. COMPtr<IWebFrameLoadDelegatePrivate2> frameLoadDelegatePriv2(Query, frameLoadDelegatePriv);
  289. if (!frameLoadDelegatePriv2)
  290. return;
  291. frameLoadDelegatePriv2->didPopStateWithinPageForFrame(webView, m_webFrame);
  292. }
  293. void WebFrameLoaderClient::dispatchWillClose()
  294. {
  295. WebView* webView = m_webFrame->webView();
  296. COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
  297. if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))
  298. frameLoadDelegate->willCloseFrame(webView, m_webFrame);
  299. }
  300. void WebFrameLoaderClient::dispatchDidReceiveIcon()
  301. {
  302. m_webFrame->webView()->dispatchDidReceiveIconFromWebFrame(m_webFrame);
  303. }
  304. void WebFrameLoaderClient::dispatchDidStartProvisionalLoad()
  305. {
  306. WebView* webView = m_webFrame->webView();
  307. COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
  308. if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))
  309. frameLoadDelegate->didStartProvisionalLoadForFrame(webView, m_webFrame);
  310. }
  311. void WebFrameLoaderClient::dispatchDidReceiveTitle(const StringWithDirection& title)
  312. {
  313. WebView* webView = m_webFrame->webView();
  314. COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
  315. if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))
  316. // FIXME: use direction of title.
  317. frameLoadDelegate->didReceiveTitle(webView, BString(title.string()), m_webFrame);
  318. }
  319. void WebFrameLoaderClient::dispatchDidChangeIcons(WebCore::IconType type)
  320. {
  321. if (type != WebCore::Favicon)
  322. return;
  323. WebView* webView = m_webFrame->webView();
  324. COMPtr<IWebFrameLoadDelegatePrivate> frameLoadDelegatePriv;
  325. if (FAILED(webView->frameLoadDelegatePrivate(&frameLoadDelegatePriv)) || !frameLoadDelegatePriv)
  326. return;
  327. COMPtr<IWebFrameLoadDelegatePrivate2> frameLoadDelegatePriv2(Query, frameLoadDelegatePriv);
  328. if (!frameLoadDelegatePriv2)
  329. return;
  330. frameLoadDelegatePriv2->didChangeIcons(webView, m_webFrame);
  331. }
  332. void WebFrameLoaderClient::dispatchDidCommitLoad()
  333. {
  334. WebView* webView = m_webFrame->webView();
  335. COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
  336. if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))
  337. frameLoadDelegate->didCommitLoadForFrame(webView, m_webFrame);
  338. }
  339. void WebFrameLoaderClient::dispatchDidFinishDocumentLoad()
  340. {
  341. WebView* webView = m_webFrame->webView();
  342. COMPtr<IWebFrameLoadDelegatePrivate> frameLoadDelegatePriv;
  343. if (SUCCEEDED(webView->frameLoadDelegatePrivate(&frameLoadDelegatePriv)) && frameLoadDelegatePriv)
  344. frameLoadDelegatePriv->didFinishDocumentLoadForFrame(webView, m_webFrame);
  345. }
  346. void WebFrameLoaderClient::dispatchDidFinishLoad()
  347. {
  348. WebView* webView = m_webFrame->webView();
  349. COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
  350. if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))
  351. frameLoadDelegate->didFinishLoadForFrame(webView, m_webFrame);
  352. }
  353. void WebFrameLoaderClient::dispatchDidLayout(LayoutMilestones milestones)
  354. {
  355. WebView* webView = m_webFrame->webView();
  356. if (milestones & DidFirstLayout) {
  357. COMPtr<IWebFrameLoadDelegatePrivate> frameLoadDelegatePrivate;
  358. if (SUCCEEDED(webView->frameLoadDelegatePrivate(&frameLoadDelegatePrivate)) && frameLoadDelegatePrivate)
  359. frameLoadDelegatePrivate->didFirstLayoutInFrame(webView, m_webFrame);
  360. }
  361. if (milestones & DidFirstVisuallyNonEmptyLayout) {
  362. COMPtr<IWebFrameLoadDelegatePrivate> frameLoadDelegatePrivate;
  363. if (SUCCEEDED(webView->frameLoadDelegatePrivate(&frameLoadDelegatePrivate)) && frameLoadDelegatePrivate)
  364. frameLoadDelegatePrivate->didFirstVisuallyNonEmptyLayoutInFrame(webView, m_webFrame);
  365. }
  366. }
  367. Frame* WebFrameLoaderClient::dispatchCreatePage(const NavigationAction&)
  368. {
  369. WebView* webView = m_webFrame->webView();
  370. COMPtr<IWebUIDelegate> ui;
  371. if (FAILED(webView->uiDelegate(&ui)))
  372. return 0;
  373. COMPtr<IWebView> newWebView;
  374. if (FAILED(ui->createWebViewWithRequest(webView, 0, &newWebView)))
  375. return 0;
  376. COMPtr<IWebFrame> mainFrame;
  377. if (FAILED(newWebView->mainFrame(&mainFrame)))
  378. return 0;
  379. COMPtr<WebFrame> mainFrameImpl(Query, mainFrame);
  380. return core(mainFrameImpl.get());
  381. }
  382. void WebFrameLoaderClient::dispatchShow()
  383. {
  384. WebView* webView = m_webFrame->webView();
  385. COMPtr<IWebUIDelegate> ui;
  386. if (SUCCEEDED(webView->uiDelegate(&ui)))
  387. ui->webViewShow(webView);
  388. }
  389. void WebFrameLoaderClient::setMainDocumentError(DocumentLoader*, const ResourceError& error)
  390. {
  391. if (!m_manualLoader)
  392. return;
  393. m_manualLoader->didFail(error);
  394. m_manualLoader = 0;
  395. m_hasSentResponseToPlugin = false;
  396. }
  397. void WebFrameLoaderClient::postProgressStartedNotification()
  398. {
  399. static BSTR progressStartedName = SysAllocString(WebViewProgressStartedNotification);
  400. IWebNotificationCenter* notifyCenter = WebNotificationCenter::defaultCenterInternal();
  401. notifyCenter->postNotificationName(progressStartedName, static_cast<IWebView*>(m_webFrame->webView()), 0);
  402. }
  403. void WebFrameLoaderClient::postProgressEstimateChangedNotification()
  404. {
  405. static BSTR progressEstimateChangedName = SysAllocString(WebViewProgressEstimateChangedNotification);
  406. IWebNotificationCenter* notifyCenter = WebNotificationCenter::defaultCenterInternal();
  407. notifyCenter->postNotificationName(progressEstimateChangedName, static_cast<IWebView*>(m_webFrame->webView()), 0);
  408. }
  409. void WebFrameLoaderClient::postProgressFinishedNotification()
  410. {
  411. static BSTR progressFinishedName = SysAllocString(WebViewProgressFinishedNotification);
  412. IWebNotificationCenter* notifyCenter = WebNotificationCenter::defaultCenterInternal();
  413. notifyCenter->postNotificationName(progressFinishedName, static_cast<IWebView*>(m_webFrame->webView()), 0);
  414. }
  415. void WebFrameLoaderClient::committedLoad(DocumentLoader* loader, const char* data, int length)
  416. {
  417. if (!m_manualLoader)
  418. loader->commitData(data, length);
  419. // If the document is a stand-alone media document, now is the right time to cancel the WebKit load.
  420. // FIXME: This code should be shared across all ports. <http://webkit.org/b/48762>.
  421. Frame* coreFrame = core(m_webFrame);
  422. if (coreFrame->document()->isMediaDocument())
  423. loader->cancelMainResourceLoad(pluginWillHandleLoadError(loader->response()));
  424. if (!m_manualLoader)
  425. return;
  426. if (!m_hasSentResponseToPlugin) {
  427. m_manualLoader->didReceiveResponse(loader->response());
  428. // didReceiveResponse sets up a new stream to the plug-in. on a full-page plug-in, a failure in
  429. // setting up this stream can cause the main document load to be cancelled, setting m_manualLoader
  430. // to null
  431. if (!m_manualLoader)
  432. return;
  433. m_hasSentResponseToPlugin = true;
  434. }
  435. m_manualLoader->didReceiveData(data, length);
  436. }
  437. void WebFrameLoaderClient::finishedLoading(DocumentLoader*)
  438. {
  439. if (!m_manualLoader)
  440. return;
  441. m_manualLoader->didFinishLoading();
  442. m_manualLoader = 0;
  443. m_hasSentResponseToPlugin = false;
  444. }
  445. void WebFrameLoaderClient::updateGlobalHistory()
  446. {
  447. DocumentLoader* loader = core(m_webFrame)->loader()->documentLoader();
  448. WebView* webView = m_webFrame->webView();
  449. COMPtr<IWebHistoryDelegate> historyDelegate;
  450. webView->historyDelegate(&historyDelegate);
  451. if (historyDelegate) {
  452. COMPtr<IWebURLResponse> urlResponse(AdoptCOM, WebURLResponse::createInstance(loader->response()));
  453. COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(loader->originalRequestCopy()));
  454. COMPtr<IWebNavigationData> navigationData(AdoptCOM, WebNavigationData::createInstance(
  455. loader->urlForHistory(), loader->title().string(), urlRequest.get(), urlResponse.get(), loader->substituteData().isValid(), loader->clientRedirectSourceForHistory()));
  456. historyDelegate->didNavigateWithNavigationData(webView, navigationData.get(), m_webFrame);
  457. return;
  458. }
  459. WebHistory* history = WebHistory::sharedHistory();
  460. if (!history)
  461. return;
  462. history->visitedURL(loader->urlForHistory(), loader->title().string(), loader->originalRequestCopy().httpMethod(), loader->urlForHistoryReflectsFailure(), !loader->clientRedirectSourceForHistory());
  463. }
  464. void WebFrameLoaderClient::updateGlobalHistoryRedirectLinks()
  465. {
  466. WebView* webView = m_webFrame->webView();
  467. COMPtr<IWebHistoryDelegate> historyDelegate;
  468. webView->historyDelegate(&historyDelegate);
  469. WebHistory* history = WebHistory::sharedHistory();
  470. DocumentLoader* loader = core(m_webFrame)->loader()->documentLoader();
  471. ASSERT(loader->unreachableURL().isEmpty());
  472. if (!loader->clientRedirectSourceForHistory().isNull()) {
  473. if (historyDelegate) {
  474. BString sourceURL(loader->clientRedirectSourceForHistory());
  475. BString destURL(loader->clientRedirectDestinationForHistory());
  476. historyDelegate->didPerformClientRedirectFromURL(webView, sourceURL, destURL, m_webFrame);
  477. } else {
  478. if (history) {
  479. if (COMPtr<IWebHistoryItem> iWebHistoryItem = history->itemForURLString(loader->clientRedirectSourceForHistory())) {
  480. COMPtr<WebHistoryItem> webHistoryItem(Query, iWebHistoryItem);
  481. webHistoryItem->historyItem()->addRedirectURL(loader->clientRedirectDestinationForHistory());
  482. }
  483. }
  484. }
  485. }
  486. if (!loader->serverRedirectSourceForHistory().isNull()) {
  487. if (historyDelegate) {
  488. BString sourceURL(loader->serverRedirectSourceForHistory());
  489. BString destURL(loader->serverRedirectDestinationForHistory());
  490. historyDelegate->didPerformServerRedirectFromURL(webView, sourceURL, destURL, m_webFrame);
  491. } else {
  492. if (history) {
  493. if (COMPtr<IWebHistoryItem> iWebHistoryItem = history->itemForURLString(loader->serverRedirectSourceForHistory())) {
  494. COMPtr<WebHistoryItem> webHistoryItem(Query, iWebHistoryItem);
  495. webHistoryItem->historyItem()->addRedirectURL(loader->serverRedirectDestinationForHistory());
  496. }
  497. }
  498. }
  499. }
  500. }
  501. bool WebFrameLoaderClient::shouldGoToHistoryItem(HistoryItem*) const
  502. {
  503. return true;
  504. }
  505. bool WebFrameLoaderClient::shouldStopLoadingForHistoryItem(HistoryItem*) const
  506. {
  507. return true;
  508. }
  509. void WebFrameLoaderClient::updateGlobalHistoryItemForPage()
  510. {
  511. HistoryItem* historyItem = 0;
  512. WebView* webView = m_webFrame->webView();
  513. if (Page* page = webView->page()) {
  514. if (!page->settings()->privateBrowsingEnabled())
  515. historyItem = page->backForward()->currentItem();
  516. }
  517. webView->setGlobalHistoryItem(historyItem);
  518. }
  519. void WebFrameLoaderClient::didDisplayInsecureContent()
  520. {
  521. WebView* webView = m_webFrame->webView();
  522. COMPtr<IWebFrameLoadDelegatePrivate> frameLoadDelegatePriv;
  523. if (FAILED(webView->frameLoadDelegatePrivate(&frameLoadDelegatePriv)) || !frameLoadDelegatePriv)
  524. return;
  525. COMPtr<IWebFrameLoadDelegatePrivate2> frameLoadDelegatePriv2(Query, frameLoadDelegatePriv);
  526. if (!frameLoadDelegatePriv2)
  527. return;
  528. frameLoadDelegatePriv2->didDisplayInsecureContent(webView);
  529. }
  530. void WebFrameLoaderClient::didRunInsecureContent(SecurityOrigin* origin, const KURL& insecureURL)
  531. {
  532. COMPtr<IWebSecurityOrigin> webSecurityOrigin = WebSecurityOrigin::createInstance(origin);
  533. WebView* webView = m_webFrame->webView();
  534. COMPtr<IWebFrameLoadDelegatePrivate> frameLoadDelegatePriv;
  535. if (FAILED(webView->frameLoadDelegatePrivate(&frameLoadDelegatePriv)) || !frameLoadDelegatePriv)
  536. return;
  537. COMPtr<IWebFrameLoadDelegatePrivate2> frameLoadDelegatePriv2(Query, frameLoadDelegatePriv);
  538. if (!frameLoadDelegatePriv2)
  539. return;
  540. frameLoadDelegatePriv2->didRunInsecureContent(webView, webSecurityOrigin.get());
  541. }
  542. void WebFrameLoaderClient::didDetectXSS(const KURL&, bool)
  543. {
  544. // FIXME: propogate call into the private delegate.
  545. }
  546. PassRefPtr<DocumentLoader> WebFrameLoaderClient::createDocumentLoader(const ResourceRequest& request, const SubstituteData& substituteData)
  547. {
  548. RefPtr<WebDocumentLoader> loader = WebDocumentLoader::create(request, substituteData);
  549. COMPtr<WebDataSource> dataSource(AdoptCOM, WebDataSource::createInstance(loader.get()));
  550. loader->setDataSource(dataSource.get());
  551. return loader.release();
  552. }
  553. void WebFrameLoaderClient::setTitle(const StringWithDirection& title, const KURL& url)
  554. {
  555. WebView* webView = m_webFrame->webView();
  556. COMPtr<IWebHistoryDelegate> historyDelegate;
  557. webView->historyDelegate(&historyDelegate);
  558. if (historyDelegate) {
  559. BString titleBSTR(title.string());
  560. BString urlBSTR(url.string());
  561. historyDelegate->updateHistoryTitle(webView, titleBSTR, urlBSTR);
  562. return;
  563. }
  564. BOOL privateBrowsingEnabled = FALSE;
  565. COMPtr<IWebPreferences> preferences;
  566. if (SUCCEEDED(m_webFrame->webView()->preferences(&preferences)))
  567. preferences->privateBrowsingEnabled(&privateBrowsingEnabled);
  568. if (privateBrowsingEnabled)
  569. return;
  570. // update title in global history
  571. COMPtr<WebHistory> history = webHistory();
  572. if (!history)
  573. return;
  574. COMPtr<IWebHistoryItem> item;
  575. if (FAILED(history->itemForURL(BString(url.string()), &item)))
  576. return;
  577. COMPtr<IWebHistoryItemPrivate> itemPrivate(Query, item);
  578. if (!itemPrivate)
  579. return;
  580. itemPrivate->setTitle(BString(title.string()));
  581. }
  582. void WebFrameLoaderClient::savePlatformDataToCachedFrame(CachedFrame* cachedFrame)
  583. {
  584. #if USE(CFNETWORK)
  585. Frame* coreFrame = core(m_webFrame);
  586. if (!coreFrame)
  587. return;
  588. ASSERT(coreFrame->loader()->documentLoader() == cachedFrame->documentLoader());
  589. cachedFrame->setCachedFramePlatformData(adoptPtr(new WebCachedFramePlatformData(static_cast<IWebDataSource*>(getWebDataSource(coreFrame->loader()->documentLoader())))));
  590. #else
  591. notImplemented();
  592. #endif
  593. }
  594. void WebFrameLoaderClient::transitionToCommittedFromCachedFrame(CachedFrame*)
  595. {
  596. }
  597. void WebFrameLoaderClient::transitionToCommittedForNewPage()
  598. {
  599. WebView* view = m_webFrame->webView();
  600. RECT rect;
  601. view->frameRect(&rect);
  602. bool transparent = view->transparent();
  603. Color backgroundColor = transparent ? Color::transparent : Color::white;
  604. core(m_webFrame)->createView(IntRect(rect).size(), backgroundColor, transparent);
  605. }
  606. void WebFrameLoaderClient::didSaveToPageCache()
  607. {
  608. }
  609. void WebFrameLoaderClient::didRestoreFromPageCache()
  610. {
  611. }
  612. void WebFrameLoaderClient::dispatchDidBecomeFrameset(bool)
  613. {
  614. }
  615. bool WebFrameLoaderClient::canCachePage() const
  616. {
  617. return true;
  618. }
  619. PassRefPtr<Frame> WebFrameLoaderClient::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement,
  620. const String& referrer, bool /*allowsScrolling*/, int /*marginWidth*/, int /*marginHeight*/)
  621. {
  622. RefPtr<Frame> result = createFrame(url, name, ownerElement, referrer);
  623. if (!result)
  624. return 0;
  625. return result.release();
  626. }
  627. PassRefPtr<Frame> WebFrameLoaderClient::createFrame(const KURL& URL, const String& name, HTMLFrameOwnerElement* ownerElement, const String& referrer)
  628. {
  629. Frame* coreFrame = core(m_webFrame);
  630. ASSERT(coreFrame);
  631. COMPtr<WebFrame> webFrame(AdoptCOM, WebFrame::createInstance());
  632. RefPtr<Frame> childFrame = webFrame->init(m_webFrame->webView(), coreFrame->page(), ownerElement);
  633. childFrame->tree()->setName(name);
  634. coreFrame->tree()->appendChild(childFrame);
  635. childFrame->init();
  636. coreFrame->loader()->loadURLIntoChildFrame(URL, referrer, childFrame.get());
  637. // The frame's onload handler may have removed it from the document.
  638. if (!childFrame->tree()->parent())
  639. return 0;
  640. return childFrame.release();
  641. }
  642. void WebFrameLoaderClient::dispatchDidFailToStartPlugin(const PluginView* pluginView) const
  643. {
  644. WebView* webView = m_webFrame->webView();
  645. COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
  646. if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))
  647. return;
  648. RetainPtr<CFMutableDictionaryRef> userInfo = adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
  649. Frame* frame = core(m_webFrame);
  650. ASSERT(frame == pluginView->parentFrame());
  651. if (!pluginView->pluginsPage().isNull()) {
  652. KURL pluginPageURL = frame->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(pluginView->pluginsPage()));
  653. if (pluginPageURL.protocolIsInHTTPFamily()) {
  654. static CFStringRef key = MarshallingHelpers::LPCOLESTRToCFStringRef(WebKitErrorPlugInPageURLStringKey);
  655. CFDictionarySetValue(userInfo.get(), key, pluginPageURL.string().createCFString().get());
  656. }
  657. }
  658. if (!pluginView->mimeType().isNull()) {
  659. static CFStringRef key = MarshallingHelpers::LPCOLESTRToCFStringRef(WebKitErrorMIMETypeKey);
  660. CFDictionarySetValue(userInfo.get(), key, pluginView->mimeType().createCFString().get());
  661. }
  662. if (pluginView->plugin()) {
  663. String pluginName = pluginView->plugin()->name();
  664. if (!pluginName.isNull()) {
  665. static CFStringRef key = MarshallingHelpers::LPCOLESTRToCFStringRef(WebKitErrorPlugInNameKey);
  666. CFDictionarySetValue(userInfo.get(), key, pluginName.createCFString().get());
  667. }
  668. }
  669. COMPtr<CFDictionaryPropertyBag> userInfoBag = CFDictionaryPropertyBag::createInstance();
  670. userInfoBag->setDictionary(userInfo.get());
  671. int errorCode = 0;
  672. switch (pluginView->status()) {
  673. case PluginStatusCanNotFindPlugin:
  674. errorCode = WebKitErrorCannotFindPlugIn;
  675. break;
  676. case PluginStatusCanNotLoadPlugin:
  677. errorCode = WebKitErrorCannotLoadPlugIn;
  678. break;
  679. default:
  680. ASSERT_NOT_REACHED();
  681. }
  682. ResourceError resourceError(String(WebKitErrorDomain), errorCode, pluginView->url().string(), String());
  683. COMPtr<IWebError> error(AdoptCOM, WebError::createInstance(resourceError, userInfoBag.get()));
  684. resourceLoadDelegate->plugInFailedWithError(webView, error.get(), getWebDataSource(frame->loader()->documentLoader()));
  685. }
  686. PassRefPtr<Widget> WebFrameLoaderClient::createPlugin(const IntSize& pluginSize, HTMLPlugInElement* element, const KURL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually)
  687. {
  688. WebView* webView = m_webFrame->webView();
  689. COMPtr<IWebUIDelegate> ui;
  690. if (SUCCEEDED(webView->uiDelegate(&ui)) && ui) {
  691. COMPtr<IWebUIDelegatePrivate> uiPrivate(Query, ui);
  692. if (uiPrivate) {
  693. // Assemble the view arguments in a property bag.
  694. HashMap<String, String> viewArguments;
  695. for (unsigned i = 0; i < paramNames.size(); i++)
  696. viewArguments.set(paramNames[i], paramValues[i]);
  697. COMPtr<IPropertyBag> viewArgumentsBag(AdoptCOM, COMPropertyBag<String>::adopt(viewArguments));
  698. COMPtr<IDOMElement> containingElement(AdoptCOM, DOMElement::createInstance(element));
  699. HashMap<String, COMVariant> arguments;
  700. arguments.set(WebEmbeddedViewAttributesKey, viewArgumentsBag);
  701. arguments.set(WebEmbeddedViewBaseURLKey, url.string());
  702. arguments.set(WebEmbeddedViewContainingElementKey, containingElement);
  703. arguments.set(WebEmbeddedViewMIMETypeKey, mimeType);
  704. COMPtr<IPropertyBag> argumentsBag(AdoptCOM, COMPropertyBag<COMVariant>::adopt(arguments));
  705. COMPtr<IWebEmbeddedView> view;
  706. HRESULT result = uiPrivate->embeddedViewWithArguments(webView, m_webFrame, argumentsBag.get(), &view);
  707. if (SUCCEEDED(result)) {
  708. HWND parentWindow;
  709. HRESULT hr = webView->viewWindow((OLE_HANDLE*)&parentWindow);
  710. ASSERT(SUCCEEDED(hr));
  711. return EmbeddedWidget::create(view.get(), element, parentWindow, pluginSize);
  712. }
  713. }
  714. }
  715. Frame* frame = core(m_webFrame);
  716. RefPtr<PluginView> pluginView = PluginView::create(frame, pluginSize, element, url, paramNames, paramValues, mimeType, loadManually);
  717. if (pluginView->status() == PluginStatusLoadedSuccessfully)
  718. return pluginView;
  719. dispatchDidFailToStartPlugin(pluginView.get());
  720. return 0;
  721. }
  722. void WebFrameLoaderClient::redirectDataToPlugin(Widget* pluginWidget)
  723. {
  724. // Ideally, this function shouldn't be necessary, see <rdar://problem/4852889>
  725. if (!pluginWidget || pluginWidget->isPluginView())
  726. m_manualLoader = toPluginView(pluginWidget);
  727. else
  728. m_manualLoader = static_cast<EmbeddedWidget*>(pluginWidget);
  729. }
  730. WebHistory* WebFrameLoaderClient::webHistory() const
  731. {
  732. if (m_webFrame != m_webFrame->webView()->topLevelFrame())
  733. return 0;
  734. return WebHistory::sharedHistory();
  735. }
  736. bool WebFrameLoaderClient::shouldAlwaysUsePluginDocument(const String& mimeType) const
  737. {
  738. WebView* webView = m_webFrame->webView();
  739. if (!webView)
  740. return false;
  741. return webView->shouldUseEmbeddedView(mimeType);
  742. }