FrameLoaderClientManx.cpp 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  1. /*
  2. * Copyright (C) 2008 Apple Computer, Inc. All rights reserved.
  3. * Copyright (C) 2012 Sony Computer Entertainment Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  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. *
  14. * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  15. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  18. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "config.h"
  27. #include "FrameLoaderClientManx.h"
  28. #include "BackForwardList.h"
  29. #include "DocumentLoader.h"
  30. #include "FormState.h"
  31. #include "Frame.h"
  32. #include "FrameLoaderTypes.h"
  33. #include "FrameNetworkingContextManx.h"
  34. #include "FrameTree.h"
  35. #include "FrameView.h"
  36. #include "HTMLFormElement.h"
  37. #include "HTMLFrameOwnerElement.h"
  38. #include "MIMETypeRegistry.h"
  39. #include "NotImplemented.h"
  40. #include "Page.h"
  41. #include "ProgressTracker.h"
  42. #include "RenderPart.h"
  43. #include "ResourceError.h"
  44. #include "ResourceHandleManager.h"
  45. #include "ResourceResponse.h"
  46. #include "SchemeRegistry.h"
  47. #include "ScriptController.h"
  48. #include "Settings.h"
  49. #include "WebViewJavaScriptObject.h"
  50. #include "WebViewPrivate.h"
  51. #include <JavaScriptCore/APICast.h>
  52. #include <JavaScriptCore/JavaScript.h>
  53. #include <JavaScriptCore/OpaqueJSString.h>
  54. #include <manx/LoadTypes.h>
  55. #include <stdio.h>
  56. #include <webkit/WebView.h>
  57. #include <wtf/PassRefPtr.h>
  58. #include <wtf/RefPtr.h>
  59. #include <wtf/text/WTFString.h>
  60. #if ENABLE(TILED_BACKING_STORE)
  61. #include "TiledBackingStore.h"
  62. #endif
  63. namespace WebCore {
  64. static FrameLoaderClientManx* gFrameLoaderClient = 0;
  65. enum {
  66. SecurityStatus_None = 0, // None
  67. SecurityStatus_NonSecured, // Non secured
  68. SecurityStatus_Secured, // Secured
  69. SecurityStatus_Mixed, // Mixed
  70. };
  71. FrameLoaderClientManx::FrameLoaderClientManx(WebKit::WebViewPrivate* webView)
  72. : m_webView(webView)
  73. , m_frame(0)
  74. , m_hasRepresentation(false)
  75. , m_securityStatus(SecurityStatus_None)
  76. {
  77. m_cert = 0;
  78. }
  79. FrameLoaderClientManx::~FrameLoaderClientManx()
  80. {
  81. }
  82. void FrameLoaderClientManx::frameLoaderDestroyed()
  83. {
  84. m_webView = 0;
  85. m_frame = 0;
  86. #if OS(PSP2)
  87. if (m_cert) {
  88. delete reinterpret_cast<Manx::X509chain*>(m_cert);
  89. m_cert = 0;
  90. }
  91. #endif
  92. delete this;
  93. }
  94. bool FrameLoaderClientManx::hasWebView() const
  95. {
  96. return true;
  97. }
  98. void FrameLoaderClientManx::makeRepresentation(DocumentLoader*)
  99. {
  100. m_hasRepresentation = true;
  101. }
  102. void FrameLoaderClientManx::forceLayout()
  103. {
  104. notImplemented();
  105. }
  106. void FrameLoaderClientManx::forceLayoutForNonHTML()
  107. {
  108. notImplemented();
  109. }
  110. void FrameLoaderClientManx::setCopiesOnScroll()
  111. {
  112. notImplemented();
  113. }
  114. void FrameLoaderClientManx::detachedFromParent2()
  115. {
  116. notImplemented();
  117. }
  118. void FrameLoaderClientManx::detachedFromParent3()
  119. {
  120. notImplemented();
  121. }
  122. void FrameLoaderClientManx::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request)
  123. {
  124. notImplemented();
  125. }
  126. void FrameLoaderClientManx::dispatchWillSendRequest(DocumentLoader*, unsigned long identifier, ResourceRequest&, const ResourceResponse& redirectResponse)
  127. {
  128. notImplemented();
  129. }
  130. bool FrameLoaderClientManx::shouldUseCredentialStorage(DocumentLoader*, unsigned long identifier)
  131. {
  132. notImplemented();
  133. return false;
  134. }
  135. void FrameLoaderClientManx::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge& challenge)
  136. {
  137. Credential cred = challenge.proposedCredential();
  138. ProtectionSpace space = challenge.protectionSpace();
  139. bool toSave = false;
  140. String user;
  141. String pass;
  142. if (httpAuthenticationChallenge(space.host(), space.realm(), user, pass, toSave)) {
  143. challenge.m_user = user;
  144. challenge.m_pass = pass;
  145. challenge.m_ok = true;
  146. }
  147. }
  148. void FrameLoaderClientManx::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&)
  149. {
  150. notImplemented();
  151. }
  152. #if PLATFORM(MANX)
  153. bool FrameLoaderClientManx::httpAuthenticationChallenge(const String& siteUrl, const String& message, String& user, String& password, bool& updatedSavedFlag)
  154. {
  155. WebKit::WebString webUser = user;
  156. WebKit::WebString webPassword = password;
  157. bool ok = m_webView->client().httpAuthenticationChallenge(siteUrl, message, webUser, webPassword);
  158. user = webUser;
  159. password = webPassword;
  160. return ok;
  161. }
  162. #endif
  163. void FrameLoaderClientManx::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long id, const ResourceResponse& response)
  164. {
  165. bool isSecure = (response.url().protocol() == "https");
  166. switch (m_securityStatus) {
  167. case SecurityStatus_None:
  168. if (isSecure)
  169. m_securityStatus = SecurityStatus_Secured;
  170. else
  171. m_securityStatus = SecurityStatus_NonSecured;
  172. break;
  173. case SecurityStatus_NonSecured:
  174. if (isSecure)
  175. m_securityStatus = SecurityStatus_Mixed;
  176. break;
  177. case SecurityStatus_Secured:
  178. if (!isSecure)
  179. m_securityStatus = SecurityStatus_Mixed;
  180. break;
  181. default:
  182. break;
  183. }
  184. if (loader->isLoadingMainResource() && !response.replaceUrl().isEmpty())
  185. loader->replaceRequestURLForSameDocumentNavigation(response.replaceUrl());
  186. #if OS(PSP2)
  187. if (response.isMainResource() && response.cert()) {
  188. if (m_cert)
  189. delete reinterpret_cast<Manx::X509chain*>(m_cert);
  190. m_cert = new Manx::X509chain(reinterpret_cast<Manx::X509chain*>(response.cert()));
  191. }
  192. #endif
  193. }
  194. void FrameLoaderClientManx::dispatchDidReceiveContentLength(DocumentLoader*, unsigned long identifier, int lengthReceived)
  195. {
  196. notImplemented();
  197. }
  198. void FrameLoaderClientManx::dispatchDidFinishLoading(DocumentLoader*, unsigned long identifier)
  199. {
  200. notImplemented();
  201. }
  202. void FrameLoaderClientManx::dispatchDidFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError& error)
  203. {
  204. notImplemented();
  205. }
  206. bool FrameLoaderClientManx::dispatchDidLoadResourceFromMemoryCache(DocumentLoader* loader, const ResourceRequest& request, const ResourceResponse& response, int length)
  207. {
  208. notImplemented();
  209. return true;
  210. }
  211. void FrameLoaderClientManx::dispatchDidHandleOnloadEvents()
  212. {
  213. notImplemented();
  214. }
  215. void FrameLoaderClientManx::dispatchDidReceiveServerRedirectForProvisionalLoad()
  216. {
  217. notImplemented();
  218. }
  219. void FrameLoaderClientManx::dispatchDidCancelClientRedirect()
  220. {
  221. notImplemented();
  222. }
  223. void FrameLoaderClientManx::dispatchWillPerformClientRedirect(const KURL&, double interval, double fireDate)
  224. {
  225. notImplemented();
  226. }
  227. void FrameLoaderClientManx::dispatchDidNavigateWithinPage()
  228. {
  229. notImplemented();
  230. }
  231. void FrameLoaderClientManx::dispatchDidChangeLocationWithinPage()
  232. {
  233. // check if this frame is the main frame, otherwise do nothing for now
  234. if (m_webView->m_frame != m_frame)
  235. return;
  236. m_webView->client().didLocationChanged(m_frame->document()->url().string());
  237. }
  238. void FrameLoaderClientManx::dispatchDidPushStateWithinPage()
  239. {
  240. notImplemented();
  241. }
  242. void FrameLoaderClientManx::dispatchDidReplaceStateWithinPage()
  243. {
  244. notImplemented();
  245. }
  246. void FrameLoaderClientManx::dispatchDidPopStateWithinPage()
  247. {
  248. notImplemented();
  249. }
  250. void FrameLoaderClientManx::dispatchWillClose()
  251. {
  252. notImplemented();
  253. }
  254. void FrameLoaderClientManx::dispatchDidReceiveIcon()
  255. {
  256. notImplemented();
  257. }
  258. void FrameLoaderClientManx::dispatchDidStartProvisionalLoad()
  259. {
  260. }
  261. void FrameLoaderClientManx::dispatchDidReceiveTitle(const StringWithDirection& title)
  262. {
  263. // check if this frame is the main frame, otherwise do nothing for now
  264. if (m_webView->m_frame != m_frame)
  265. return;
  266. m_webView->client().didReceiveTitle(title.string());
  267. }
  268. void FrameLoaderClientManx::dispatchDidChangeIcons(WebCore::IconType)
  269. {
  270. notImplemented();
  271. }
  272. void FrameLoaderClientManx::dispatchDidCommitLoad()
  273. {
  274. // check if this frame is the main frame, otherwise do nothing for now
  275. if (m_webView->m_frame != m_frame)
  276. return;
  277. m_webView->didCommitLoad();
  278. m_webView->client().didCommitLoad();
  279. m_webView->client().didLocationChanged(m_frame->document()->url().string());
  280. }
  281. void FrameLoaderClientManx::dispatchDidFailProvisionalLoad(const ResourceError& error)
  282. {
  283. dispatchDidFailLoad(error);
  284. }
  285. void FrameLoaderClientManx::dispatchDidFailLoad(const ResourceError& error)
  286. {
  287. if (error.shouldCertificateVerify()) {
  288. bool ok = m_webView->client().verifyCertificate((int)error.sslError(), static_cast<Manx::X509chain*>(error.cert()));
  289. error.setConfirmCert(ok);
  290. } else {
  291. // check if this frame is the main frame, otherwise do nothing for now
  292. if (m_webView->m_frame != m_frame)
  293. return;
  294. if (!error.isCancellation())
  295. m_webView->client().didLoadFailed(error.errorCode(), error.domain(), error.failingURL(), error.localizedDescription());
  296. }
  297. }
  298. void FrameLoaderClientManx::dispatchDidFinishDocumentLoad()
  299. {
  300. }
  301. void FrameLoaderClientManx::dispatchDidFinishLoad()
  302. {
  303. }
  304. void FrameLoaderClientManx::dispatchDidFirstLayout()
  305. {
  306. notImplemented();
  307. }
  308. void FrameLoaderClientManx::dispatchDidFirstVisuallyNonEmptyLayout()
  309. {
  310. }
  311. Frame* FrameLoaderClientManx::dispatchCreatePage(const NavigationAction& action)
  312. {
  313. Frame* newFrame = 0;
  314. if (m_frame) {
  315. CString url = action.url().string().utf8();
  316. int width = m_frame->view() ? m_frame->view()->frameRect().width() : 0;
  317. int height = m_frame->view() ? m_frame->view()->frameRect().height() : 0;
  318. WebKit::WebView* webview = m_webView->client().createWindow(url.data(), width, height, false);
  319. if (webview) {
  320. WebKit::WebViewPrivate* webViewPriv = static_cast<WebKit::WebViewPrivate*>(webview);
  321. newFrame = webViewPriv->m_page->mainFrame();
  322. // set useragent of parent webview.
  323. webViewPriv->setUserAgent(m_webView->userAgent());
  324. }
  325. }
  326. return newFrame;
  327. }
  328. void FrameLoaderClientManx::dispatchShow()
  329. {
  330. notImplemented();
  331. }
  332. void FrameLoaderClientManx::dispatchDecidePolicyForResponse(FramePolicyFunction function, const ResourceResponse& response, const ResourceRequest& request)
  333. {
  334. if (canShowMIMEType(response.mimeType()) || !response.mimeType())
  335. (m_frame->loader()->policyChecker()->*function)(PolicyUse);
  336. else {
  337. m_webView->client().startDownload(request.url().string(), response.mimeType());
  338. // PolicyIgnore is used instread of PolicyDownload so that unsed ResourceHandle will be canceled
  339. (m_frame->loader()->policyChecker()->*function)(PolicyIgnore);
  340. }
  341. }
  342. void FrameLoaderClientManx::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction&, const ResourceRequest&, PassRefPtr<FormState>, const String& frameName)
  343. {
  344. notImplemented();
  345. (m_frame->loader()->policyChecker()->*function)(PolicyUse);
  346. }
  347. void FrameLoaderClientManx::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& navigationAction, const ResourceRequest& res, PassRefPtr<FormState>)
  348. {
  349. bool supportScheme = false;
  350. PolicyAction action = PolicyIgnore;
  351. bool handleRequest = false;
  352. bool isMainDoc = (m_frame && m_frame->page()->mainFrame() == m_frame);
  353. NavigationType type = navigationAction.type();
  354. if (!res.isNull()) {
  355. handleRequest = true;
  356. if (isMainDoc)
  357. handleRequest = m_webView->client().decidePolicyForNavigationAction(res.url().string(), type);
  358. }
  359. if (handleRequest) {
  360. // http, https
  361. WTF::String scheme = res.url().protocol();
  362. supportScheme = WebCore::SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(scheme);
  363. // about
  364. supportScheme |= WebCore::SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(scheme);
  365. // file
  366. supportScheme |= WebCore::SchemeRegistry::shouldTreatURLSchemeAsLocal(scheme);
  367. // data
  368. supportScheme |= WebCore::SchemeRegistry::shouldTreatURLSchemeAsNoAccess(scheme);
  369. if (!supportScheme)
  370. m_webView->client().notifyUnsupportScheme(res.url().string());
  371. else
  372. action = PolicyUse;
  373. bool allowed = true;
  374. if (isMainDoc) {
  375. WebCore::KURL reqUrl = res.url();
  376. WebCore::KURL srcUrl(m_frame->document()->url());
  377. bool nextIsSecure = reqUrl.protocolIs("https");
  378. bool prevIsSecure = srcUrl.protocolIs("https");
  379. if (type == NavigationTypeFormResubmitted)
  380. allowed = m_webView->client().decidePolicyForNavigationWarning(NAVIGATION_WARNING_EVENT_TYPE_POSTING_FROM_CACHE);
  381. else if (res.getRedirected() && !nextIsSecure && prevIsSecure)
  382. allowed = m_webView->client().decidePolicyForNavigationWarning(NAVIGATION_WARNING_EVENT_TYPE_LEAVING_SECURE_SITE_AT_REDIRECTION);
  383. }
  384. if (!allowed)
  385. action = WebCore::PolicyIgnore;
  386. }
  387. (m_frame->loader()->policyChecker()->*function)(action);
  388. }
  389. void FrameLoaderClientManx::cancelPolicyCheck()
  390. {
  391. notImplemented();
  392. }
  393. void FrameLoaderClientManx::dispatchUnableToImplementPolicy(const ResourceError&)
  394. {
  395. notImplemented();
  396. }
  397. void FrameLoaderClientManx::dispatchWillSendSubmitEvent(PassRefPtr<FormState>)
  398. {
  399. notImplemented();
  400. }
  401. void FrameLoaderClientManx::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState>)
  402. {
  403. notImplemented();
  404. (m_frame->loader()->policyChecker()->*function)(PolicyUse);
  405. }
  406. void FrameLoaderClientManx::revertToProvisionalState(DocumentLoader*)
  407. {
  408. m_hasRepresentation = true;
  409. }
  410. void FrameLoaderClientManx::setMainDocumentError(DocumentLoader*, const ResourceError&)
  411. {
  412. notImplemented();
  413. }
  414. void FrameLoaderClientManx::postProgressStartedNotification()
  415. {
  416. // check if this frame is the main frame, otherwise do nothing for now
  417. if (m_webView->m_frame != m_frame)
  418. return;
  419. m_webView->client().notifyLoadStarted(static_cast<void*>(m_frame));
  420. }
  421. void FrameLoaderClientManx::postProgressEstimateChangedNotification()
  422. {
  423. // check if this frame is the main frame, otherwise do nothing for now
  424. if (m_webView->m_frame != m_frame)
  425. return;
  426. float progress = (float)m_webView->m_page->progress()->estimatedProgress();
  427. m_webView->client().notifyLoadProgress(progress);
  428. }
  429. void FrameLoaderClientManx::postProgressFinishedNotification()
  430. {
  431. // check if this frame is the main frame, otherwise do nothing for now
  432. if (m_webView->m_frame != m_frame)
  433. return;
  434. WebCore::ResourceHandleManager::sharedInstance()->saveCookies();
  435. m_webView->client().notifyLoadSecurityStatus(m_securityStatus);
  436. m_securityStatus = SecurityStatus_None;
  437. m_webView->client().notifyLoadFinished();
  438. }
  439. ObjectContentType FrameLoaderClientManx::objectContentType(const KURL& url, const String& mimeType, bool shouldPreferPlugInsForImages)
  440. {
  441. // FIXME: once plugin support is enabled, this method needs to correctly handle the 'shouldPreferPlugInsForImages' flag. See
  442. // WebCore::FrameLoader::defaultObjectContentType() for an example.
  443. UNUSED_PARAM(shouldPreferPlugInsForImages);
  444. if (url.isEmpty() && mimeType.isEmpty())
  445. return ObjectContentNone;
  446. // We don't use MIMETypeRegistry::getMIMETypeForPath() because it returns "application/octet-stream" upon failure
  447. String type = mimeType;
  448. if (type.isEmpty())
  449. type = MIMETypeRegistry::getMIMETypeForExtension(url.path().substring(url.path().reverseFind('.') + 1));
  450. if (type.isEmpty())
  451. return ObjectContentFrame;
  452. if (MIMETypeRegistry::isSupportedImageMIMEType(type))
  453. return ObjectContentImage;
  454. #if 0 // PluginDatabase is disabled until we have Plugin system done.
  455. if (PluginDatabase::installedPlugins()->isMIMETypeRegistered(mimeType))
  456. return ObjectContentNetscapePlugin;
  457. #endif
  458. if (MIMETypeRegistry::isSupportedNonImageMIMEType(type))
  459. return ObjectContentFrame;
  460. if (url.protocol() == "about")
  461. return ObjectContentFrame;
  462. return ObjectContentNone;
  463. }
  464. void FrameLoaderClientManx::setMainFrameDocumentReady(bool)
  465. {
  466. notImplemented();
  467. }
  468. void FrameLoaderClientManx::startDownload(const ResourceRequest&, const String& suggestedName)
  469. {
  470. notImplemented();
  471. }
  472. void FrameLoaderClientManx::willChangeTitle(DocumentLoader*)
  473. {
  474. // not used: see dispatchDidReceiveTitle
  475. }
  476. void FrameLoaderClientManx::didChangeTitle(DocumentLoader*)
  477. {
  478. // not used: see dispatchDidReceiveTitle
  479. }
  480. void FrameLoaderClientManx::committedLoad(WebCore::DocumentLoader* loader, const char* data, int length)
  481. {
  482. loader->commitData(data, length);
  483. }
  484. void FrameLoaderClientManx::finishedLoading(DocumentLoader* documentLoader)
  485. {
  486. // This is necessary to create an empty document,
  487. // but it has to be skipped in the provisional phase.
  488. if (m_hasRepresentation)
  489. documentLoader->writer()->setEncoding("", false);
  490. }
  491. void FrameLoaderClientManx::updateGlobalHistory()
  492. {
  493. updateGlobalHistoryItemForPage();
  494. }
  495. void FrameLoaderClientManx::updateGlobalHistoryRedirectLinks()
  496. {
  497. notImplemented();
  498. }
  499. void FrameLoaderClientManx::updateGlobalHistoryItemForPage()
  500. {
  501. m_webView->client().notifyHistoryChanged(m_webView->canGoBack(), m_webView->canGoForward());
  502. }
  503. bool FrameLoaderClientManx::shouldGoToHistoryItem(HistoryItem*) const
  504. {
  505. return true;
  506. }
  507. bool FrameLoaderClientManx::shouldStopLoadingForHistoryItem(WebCore::HistoryItem*) const
  508. {
  509. return true;
  510. }
  511. void FrameLoaderClientManx::didDisplayInsecureContent()
  512. {
  513. notImplemented();
  514. }
  515. void FrameLoaderClientManx::didRunInsecureContent(SecurityOrigin*, const KURL&)
  516. {
  517. notImplemented();
  518. }
  519. void FrameLoaderClientManx::didDetectXSS(const KURL&, bool didBlockEntirePage)
  520. {
  521. notImplemented();
  522. }
  523. ResourceError FrameLoaderClientManx::cancelledError(const ResourceRequest& request)
  524. {
  525. return ResourceError(WebKitError,
  526. LOAD_ERROR_CANCELLED,
  527. request.url().string(),
  528. String("Load cancelled"));
  529. }
  530. ResourceError FrameLoaderClientManx::blockedError(const ResourceRequest& request)
  531. {
  532. return ResourceError(WebKitError,
  533. LOAD_ERROR_BLOCKED,
  534. request.url().string(),
  535. String("Load blocked"));
  536. }
  537. ResourceError FrameLoaderClientManx::cannotShowURLError(const ResourceRequest& request)
  538. {
  539. return ResourceError(WebKitError,
  540. LOAD_ERROR_CANNOT_SHOW_URL,
  541. request.url().string(),
  542. String("Cannot show url"));
  543. }
  544. ResourceError FrameLoaderClientManx::interruptedForPolicyChangeError(const ResourceRequest& request)
  545. {
  546. return ResourceError(WebKitError,
  547. LOAD_ERROR_INTERRUPTED_FOR_POLICY_CHANGE,
  548. request.url().string(),
  549. String("Interrupted for policy change"));
  550. }
  551. ResourceError FrameLoaderClientManx::cannotShowMIMETypeError(const ResourceResponse& response)
  552. {
  553. return ResourceError(WebKitError,
  554. LOAD_ERROR_CANNOT_SHOW_MIME_TYPE,
  555. response.url().string(),
  556. String("Cannot show mime type"));
  557. }
  558. ResourceError FrameLoaderClientManx::fileDoesNotExistError(const ResourceResponse& response)
  559. {
  560. return ResourceError(WebKitError,
  561. LOAD_ERROR_FILE_DOES_NOT_EXIST,
  562. response.url().string(),
  563. String("File does not exist"));
  564. }
  565. ResourceError FrameLoaderClientManx::pluginWillHandleLoadError(const ResourceResponse& response)
  566. {
  567. return ResourceError(WebKitError,
  568. LOAD_ERROR_PLUGIN_WILL_HANDLE_LOAD,
  569. response.url().string(),
  570. String("Plugin will handle load"));
  571. }
  572. bool FrameLoaderClientManx::shouldFallBack(const ResourceError&)
  573. {
  574. notImplemented();
  575. return false;
  576. }
  577. bool FrameLoaderClientManx::canHandleRequest(const ResourceRequest& request) const
  578. {
  579. bool handleRequest = true;
  580. return handleRequest;
  581. }
  582. bool FrameLoaderClientManx::canShowMIMEType(const String& MIMEType) const
  583. {
  584. if (MIMETypeRegistry::isSupportedImageMIMEType(MIMEType))
  585. return true;
  586. if (MIMETypeRegistry::isSupportedNonImageMIMEType(MIMEType))
  587. return true;
  588. #if 0 // PluginDatabase is disabled until we have Plugin system done.
  589. if (PluginDatabase::installedPlugins()->isMIMETypeRegistered(MIMEType))
  590. return true;
  591. #endif
  592. return false;
  593. }
  594. bool FrameLoaderClientManx::canShowMIMETypeAsHTML(const String& MIMEType) const
  595. {
  596. notImplemented();
  597. return false;
  598. }
  599. bool FrameLoaderClientManx::representationExistsForURLScheme(const String& URLScheme) const
  600. {
  601. notImplemented();
  602. return false;
  603. }
  604. String FrameLoaderClientManx::generatedMIMETypeForURLScheme(const String& URLScheme) const
  605. {
  606. notImplemented();
  607. return String();
  608. }
  609. void FrameLoaderClientManx::frameLoadCompleted()
  610. {
  611. notImplemented();
  612. }
  613. void FrameLoaderClientManx::saveViewStateToItem(HistoryItem*)
  614. {
  615. notImplemented();
  616. }
  617. void FrameLoaderClientManx::restoreViewState()
  618. {
  619. notImplemented();
  620. }
  621. void FrameLoaderClientManx::provisionalLoadStarted()
  622. {
  623. notImplemented();
  624. }
  625. void FrameLoaderClientManx::didFinishLoad()
  626. {
  627. notImplemented();
  628. }
  629. void FrameLoaderClientManx::prepareForDataSourceReplacement()
  630. {
  631. notImplemented();
  632. }
  633. WTF::PassRefPtr<DocumentLoader> FrameLoaderClientManx::createDocumentLoader(const ResourceRequest& request, const SubstituteData& substituteData)
  634. {
  635. return DocumentLoader::create(request, substituteData);
  636. }
  637. void FrameLoaderClientManx::setTitle(const StringWithDirection& title, const KURL& url)
  638. {
  639. // not used: see dispatchDidReceiveTitle
  640. }
  641. String FrameLoaderClientManx::userAgent(const KURL&)
  642. {
  643. return m_webView->userAgent();
  644. }
  645. void FrameLoaderClientManx::savePlatformDataToCachedFrame(CachedFrame*)
  646. {
  647. notImplemented();
  648. }
  649. void FrameLoaderClientManx::transitionToCommittedFromCachedFrame(CachedFrame*)
  650. {
  651. notImplemented();
  652. }
  653. void FrameLoaderClientManx::transitionToCommittedForNewPage()
  654. {
  655. ASSERT(m_webView);
  656. ASSERT(m_frame);
  657. IntSize size = IntSize(m_webView->m_textureWidth, m_webView->m_textureHeight);
  658. bool transparent = false; // FIXME: get setting from WebView
  659. Color backgroundColor = transparent ? WebCore::Color::transparent : WebCore::Color::white;
  660. #if USE_TILED_BUFFER
  661. // If this is a main frame, clear the tiled buffers.
  662. if (m_webView->m_frame == m_frame) {
  663. IntSize fixedLayoutSize = m_webView->m_viewSize;
  664. m_webView->m_tiledBufferPainter->clear();
  665. m_webView->m_tiledBufferPainter->setContentsScale(0.0f);
  666. m_frame->createView(size, backgroundColor, transparent, fixedLayoutSize, IntRect(), !fixedLayoutSize.isEmpty());
  667. m_frame->view()->setDelegatesScrolling(true);
  668. } else
  669. m_frame->createView(size, backgroundColor, transparent);
  670. #else
  671. m_frame->createView(size, backgroundColor, transparent);
  672. #endif
  673. #if ENABLE(TILED_BACKING_STORE)
  674. m_frame->view()->setDelegatesScrolling(m_frame->tiledBackingStore());
  675. if (m_frame->tiledBackingStore()) {
  676. m_frame->tiledBackingStore()->setTileSize(IntSize(256, 256));
  677. m_frame->view()->setFixedVisibleContentRect(IntRect(IntPoint::zero(), size));
  678. }
  679. #endif
  680. }
  681. void FrameLoaderClientManx::didSaveToPageCache()
  682. {
  683. notImplemented();
  684. }
  685. void FrameLoaderClientManx::didRestoreFromPageCache()
  686. {
  687. notImplemented();
  688. }
  689. void FrameLoaderClientManx::dispatchDidBecomeFrameset(bool)
  690. {
  691. notImplemented();
  692. }
  693. bool FrameLoaderClientManx::canCachePage() const
  694. {
  695. notImplemented();
  696. return false;
  697. }
  698. void FrameLoaderClientManx::convertMainResourceLoadToDownload(WebCore::DocumentLoader* documentLoader, const ResourceRequest& request, const ResourceResponse& response)
  699. {
  700. }
  701. PassRefPtr<Frame> FrameLoaderClientManx::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement, const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight)
  702. {
  703. ASSERT(m_webView);
  704. ASSERT(m_frame);
  705. FrameLoaderClientManx* loaderClient = new FrameLoaderClientManx(m_webView);
  706. RefPtr<Frame> childFrame = Frame::create(m_webView->m_page.get(), ownerElement, loaderClient);
  707. loaderClient->setFrame(childFrame.get());
  708. childFrame->tree()->setName(name);
  709. m_frame->tree()->appendChild(childFrame.get());
  710. childFrame->init();
  711. // The creation of the frame may have run arbitrary JavaScript that removed it from the page already.
  712. if (!childFrame->page())
  713. return 0;
  714. m_frame->loader()->loadURLIntoChildFrame(url, referrer, childFrame.get());
  715. // The frame's onload handler may have removed it from the document.
  716. if (!childFrame->tree()->parent())
  717. return 0;
  718. return childFrame.release();
  719. }
  720. PassRefPtr<Widget> FrameLoaderClientManx::createPlugin(const IntSize&, HTMLPlugInElement*, const KURL&, const Vector<String>&, const Vector<String>&, const String&, bool loadManually)
  721. {
  722. notImplemented();
  723. return 0;
  724. }
  725. void FrameLoaderClientManx::redirectDataToPlugin(Widget* pluginWidget)
  726. {
  727. notImplemented();
  728. }
  729. PassRefPtr<Widget> FrameLoaderClientManx::createJavaAppletWidget(const IntSize&, HTMLAppletElement*, const KURL& baseURL, const Vector<String>& paramNames, const Vector<String>& paramValues)
  730. {
  731. notImplemented();
  732. return 0;
  733. }
  734. String FrameLoaderClientManx::overrideMediaType() const
  735. {
  736. notImplemented();
  737. return String();
  738. }
  739. JSValueRef FrameLoaderClientManx::jsDelegate(JSContextRef ctx, JSObjectRef function, size_t argumentCount, const JSValueRef arguments[])
  740. {
  741. JSStringRef funcStr = JSValueToStringCopy(ctx, function, 0);
  742. unsigned strSize = funcStr->length() + 1;
  743. char* buffer = new char[strSize];
  744. size_t copySize = JSStringGetUTF8CString(funcStr, buffer, strSize);
  745. String subFunc(buffer);
  746. size_t subFuncHead = sizeof("function ") - 1;
  747. size_t subFuncSize = subFunc.find(")") - 1 - subFuncHead;
  748. String subFuncName = subFunc.substring(subFuncHead, subFuncSize);
  749. WebViewJavaScriptObjectDelegate delegate(subFuncName.utf8().data(), argumentCount);
  750. delete[] buffer;
  751. for (int i = 0; i < argumentCount; i++) {
  752. switch (JSValueGetType(ctx, arguments[i])) {
  753. case kJSTypeBoolean:
  754. delegate.args[i].type = JSTYPE_BOOLEAN;
  755. delegate.args[i].argBool = JSValueToBoolean(ctx, arguments[i]);
  756. break;
  757. case kJSTypeNumber:
  758. delegate.args[i].type = JSTYPE_NUMBER;
  759. delegate.args[i].argDouble = JSValueToNumber(ctx, arguments[i], 0);
  760. break;
  761. case kJSTypeString:
  762. {
  763. JSStringRef funcStr = JSValueToStringCopy(ctx, arguments[i], 0);
  764. unsigned strSize = funcStr->length() + 1;
  765. char* buffer = new char[strSize];
  766. size_t copySize = JSStringGetUTF8CString(funcStr, buffer, strSize);
  767. delegate.args[i].type = JSTYPE_STRING;
  768. delegate.args[i].argString = new char[strlen(buffer) + 1];
  769. strncpy(delegate.args[i].argString, buffer, strSize);
  770. delete[] buffer;
  771. }
  772. break;
  773. default:
  774. break;
  775. }
  776. }
  777. int returnType = 0;
  778. double value = 0;
  779. WebKit::WebString string;
  780. m_webView->client().didFunctionCalled(delegate, returnType, value, string);
  781. JSValueRef ret = JSValueMakeNull(ctx);
  782. switch (returnType) {
  783. case JSTYPE_NUMBER:
  784. ret = JSValueMakeNumber(ctx, value);
  785. break;
  786. case JSTYPE_STRING:
  787. {
  788. JSStringRef objName = JSStringCreateWithCharacters(string.data(), string.length());
  789. ret = JSValueMakeString(ctx, objName);
  790. JSStringRelease(objName);
  791. }
  792. break;
  793. default:
  794. ret = JSValueMakeNull(ctx);
  795. break;
  796. }
  797. return ret;
  798. }
  799. JSValueRef FrameLoaderClientManx::jsFunctionCallbackWithDelegate(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  800. {
  801. return gFrameLoaderClient->jsDelegate(ctx, function, argumentCount, arguments);
  802. // return function;
  803. }
  804. JSValueRef FrameLoaderClientManx::jsFunctionCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  805. {
  806. return function;
  807. }
  808. void FrameLoaderClientManx::setJSObject(WebViewJavaScriptObject* parentObj, JSObjectRef parentObjRef)
  809. {
  810. if (!parentObj)
  811. return;
  812. JSGlobalContextRef context = toGlobalRef(m_frame->script()->globalObject(mainThreadNormalWorld())->globalExec());
  813. WebViewJavaScriptObject* child = 0;
  814. int index = 0;
  815. while (child = parentObj->childObjectAtIndex(index)) {
  816. JSDOMWindow* domWindow = m_frame->script()->globalObject(mainThreadNormalWorld());
  817. if (!parentObjRef)
  818. parentObjRef = toRef(domWindow);
  819. if (!child->auth(m_cert, domWindow->impl()->document()->url().host().utf8().data())) {
  820. index++;
  821. continue;
  822. }
  823. switch (child->objectType()) {
  824. case OBJECT_TYPE_OBJECT:
  825. {
  826. JSStringRef objName = JSStringCreateWithUTF8CString(child->baseUrl());
  827. JSObjectRef obj = JSObjectMake(context, 0, 0);
  828. JSObjectSetProperty(context, parentObjRef, objName, obj, kJSPropertyAttributeReadOnly, 0);
  829. JSStringRelease(objName);
  830. setJSObject(child, obj);
  831. }
  832. break;
  833. case OBJECT_TYPE_FUNCTION:
  834. {
  835. JSStringRef funcName = JSStringCreateWithUTF8CString(child->baseUrl());
  836. if (child->delegate()) {
  837. JSObjectRef func = JSObjectMakeFunctionWithCallback(context, funcName, jsFunctionCallbackWithDelegate);
  838. JSObjectSetProperty(context, parentObjRef, funcName, func, kJSPropertyAttributeReadOnly, 0);
  839. } else {
  840. JSObjectRef func = JSObjectMakeFunctionWithCallback(context, funcName, jsFunctionCallback);
  841. JSObjectSetProperty(context, parentObjRef, funcName, func, kJSPropertyAttributeReadOnly, 0);
  842. }
  843. JSStringRelease(funcName);
  844. }
  845. break;
  846. }
  847. index++;
  848. }
  849. }
  850. void FrameLoaderClientManx::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world)
  851. {
  852. if (world != mainThreadNormalWorld())
  853. return;
  854. ASSERT(m_frame);
  855. Settings* settings = m_frame->settings();
  856. if (!settings || !settings->isScriptEnabled())
  857. return;
  858. gFrameLoaderClient = this;
  859. JSGlobalContextRef context = toGlobalRef(m_frame->script()->globalObject(mainThreadNormalWorld())->globalExec());
  860. JSDOMWindow* domWindow = m_frame->script()->globalObject(mainThreadNormalWorld());
  861. JSObjectRef windowObject = toRef(domWindow);
  862. ASSERT(windowObject);
  863. // Add window.external
  864. JSStringRef objName = JSStringCreateWithUTF8CString("external");
  865. JSObjectRef obj = JSObjectMake(context, 0, 0);
  866. JSObjectSetProperty(context, windowObject, objName, obj, kJSPropertyAttributeReadOnly, 0);
  867. JSStringRelease(objName);
  868. setJSObject(m_webView->javaScriptObj());
  869. m_webView->client().didWindowObjectCleared((void*)m_frame, (void*)context, (void*)windowObject);
  870. }
  871. void FrameLoaderClientManx::documentElementAvailable()
  872. {
  873. notImplemented();
  874. }
  875. void FrameLoaderClientManx::didPerformFirstNavigation() const
  876. {
  877. notImplemented();
  878. }
  879. void FrameLoaderClientManx::registerForIconNotification(bool listen)
  880. {
  881. notImplemented();
  882. }
  883. PassRefPtr<FrameNetworkingContext> FrameLoaderClientManx::createNetworkingContext()
  884. {
  885. return FrameNetworkingContextManx::create(m_frame);
  886. }
  887. }