FrameLoaderClientEfl.cpp 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. /*
  2. * Copyright (C) 2006 Zack Rusin <zack@kde.org>
  3. * Copyright (C) 2006, 2011 Apple Inc. All rights reserved.
  4. * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
  5. * Copyright (C) 2008 Collabora Ltd. All rights reserved.
  6. * Copyright (C) 2008 Holger Hans Peter Freyther
  7. * Copyright (C) 2008 Kenneth Rohde Christiansen
  8. * Copyright (C) 2009-2010 ProFUSION embedded systems
  9. * Copyright (C) 2009-2010 Samsung Electronics
  10. * Copyright (C) 2012 Intel Corporation
  11. *
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. * 1. Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in the
  21. * documentation and/or other materials provided with the distribution.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  24. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  26. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  27. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  31. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include "config.h"
  36. #include "FrameLoaderClientEfl.h"
  37. #include "APICast.h"
  38. #include "DocumentLoader.h"
  39. #include "ErrorsEfl.h"
  40. #include "FormState.h"
  41. #include "FrameLoader.h"
  42. #include "FrameNetworkingContextEfl.h"
  43. #include "FrameTree.h"
  44. #include "FrameView.h"
  45. #include "HTMLFormElement.h"
  46. #include "HTTPStatusCodes.h"
  47. #include "MIMETypeRegistry.h"
  48. #include "NotImplemented.h"
  49. #include "Page.h"
  50. #include "PluginDatabase.h"
  51. #include "ProgressTracker.h"
  52. #include "RenderPart.h"
  53. #include "ResourceRequest.h"
  54. #include "ResourceResponse.h"
  55. #include "ScriptController.h"
  56. #include "Settings.h"
  57. #include "WebKitVersion.h"
  58. #include "ewk_frame_private.h"
  59. #include "ewk_private.h"
  60. #include "ewk_settings.h"
  61. #include "ewk_settings_private.h"
  62. #include "ewk_view_private.h"
  63. #include <Ecore_Evas.h>
  64. #include <wtf/text/CString.h>
  65. #include <wtf/text/StringConcatenate.h>
  66. namespace WebCore {
  67. FrameLoaderClientEfl::FrameLoaderClientEfl(Evas_Object* view)
  68. : m_view(view)
  69. , m_frame(0)
  70. , m_userAgent("")
  71. , m_customUserAgent("")
  72. , m_pluginView(0)
  73. , m_hasSentResponseToPlugin(false)
  74. {
  75. }
  76. static String composeUserAgent()
  77. {
  78. return String(ewk_settings_default_user_agent_get());
  79. }
  80. void FrameLoaderClientEfl::setCustomUserAgent(const String& agent)
  81. {
  82. m_customUserAgent = agent;
  83. }
  84. const String& FrameLoaderClientEfl::customUserAgent() const
  85. {
  86. return m_customUserAgent;
  87. }
  88. String FrameLoaderClientEfl::userAgent(const KURL&)
  89. {
  90. if (!m_customUserAgent.isEmpty())
  91. return m_customUserAgent;
  92. if (m_userAgent.isEmpty())
  93. m_userAgent = composeUserAgent();
  94. return m_userAgent;
  95. }
  96. void FrameLoaderClientEfl::callPolicyFunction(FramePolicyFunction function, PolicyAction action)
  97. {
  98. Frame* f = EWKPrivate::coreFrame(m_frame);
  99. ASSERT(f);
  100. (f->loader()->policyChecker()->*function)(action);
  101. }
  102. WTF::PassRefPtr<DocumentLoader> FrameLoaderClientEfl::createDocumentLoader(const ResourceRequest& request, const SubstituteData& substituteData)
  103. {
  104. RefPtr<DocumentLoader> loader = DocumentLoader::create(request, substituteData);
  105. if (substituteData.isValid())
  106. loader->setDeferMainResourceDataLoad(false);
  107. return loader.release();
  108. }
  109. void FrameLoaderClientEfl::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState>)
  110. {
  111. // FIXME: This is surely too simple
  112. ASSERT(function);
  113. callPolicyFunction(function, PolicyUse);
  114. }
  115. void FrameLoaderClientEfl::committedLoad(DocumentLoader* loader, const char* data, int length)
  116. {
  117. if (!m_pluginView) {
  118. loader->commitData(data, length);
  119. // Let the media document handle the rest of loading itself, cancel here.
  120. Frame* coreFrame = loader->frame();
  121. if (coreFrame && coreFrame->document()->isMediaDocument())
  122. loader->cancelMainResourceLoad(pluginWillHandleLoadError(loader->response()));
  123. }
  124. // We re-check here as the plugin can have been created
  125. if (m_pluginView) {
  126. if (!m_hasSentResponseToPlugin) {
  127. m_pluginView->didReceiveResponse(loader->response());
  128. m_hasSentResponseToPlugin = true;
  129. }
  130. m_pluginView->didReceiveData(data, length);
  131. }
  132. }
  133. void FrameLoaderClientEfl::dispatchDidReplaceStateWithinPage()
  134. {
  135. notImplemented();
  136. }
  137. void FrameLoaderClientEfl::dispatchDidPushStateWithinPage()
  138. {
  139. notImplemented();
  140. }
  141. void FrameLoaderClientEfl::dispatchDidPopStateWithinPage()
  142. {
  143. notImplemented();
  144. }
  145. void FrameLoaderClientEfl::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long /*identifier*/, const AuthenticationChallenge&)
  146. {
  147. notImplemented();
  148. }
  149. void FrameLoaderClientEfl::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long /*identifier*/, const AuthenticationChallenge&)
  150. {
  151. notImplemented();
  152. }
  153. void FrameLoaderClientEfl::dispatchWillSendRequest(DocumentLoader* loader, unsigned long identifier, ResourceRequest& coreRequest, const ResourceResponse& coreResponse)
  154. {
  155. CString url = coreRequest.url().string().utf8();
  156. CString firstParty = coreRequest.firstPartyForCookies().string().utf8();
  157. CString httpMethod = coreRequest.httpMethod().utf8();
  158. DBG("Resource url=%s, first_party=%s, http_method=%s", url.data(), firstParty.data(), httpMethod.data());
  159. // We want to distinguish between a request for a document to be loaded into
  160. // the main frame, a sub-frame, or the sub-objects in that document.
  161. bool isMainFrameRequest = false;
  162. if (loader) {
  163. const FrameLoader* frameLoader = loader->frameLoader();
  164. isMainFrameRequest = (loader == frameLoader->provisionalDocumentLoader() && frameLoader->isLoadingMainFrame());
  165. }
  166. Ewk_Frame_Resource_Request request = { 0, firstParty.data(), httpMethod.data(), identifier, m_frame, isMainFrameRequest };
  167. Ewk_Frame_Resource_Request orig = request; /* Initialize const fields. */
  168. orig.url = request.url = url.data();
  169. Ewk_Frame_Resource_Response* redirectResponse;
  170. Ewk_Frame_Resource_Response responseBuffer;
  171. CString redirectUrl, mimeType;
  172. if (coreResponse.isNull())
  173. redirectResponse = 0;
  174. else {
  175. redirectUrl = coreResponse.url().string().utf8();
  176. mimeType = coreResponse.mimeType().utf8();
  177. responseBuffer.url = redirectUrl.data();
  178. responseBuffer.status_code = coreResponse.httpStatusCode();
  179. responseBuffer.identifier = identifier;
  180. responseBuffer.mime_type = mimeType.data();
  181. redirectResponse = &responseBuffer;
  182. }
  183. Ewk_Frame_Resource_Messages messages = { &request, redirectResponse };
  184. ewk_frame_request_will_send(m_frame, &messages);
  185. evas_object_smart_callback_call(m_view, "resource,request,willsend", &messages);
  186. if (request.url != orig.url) {
  187. coreRequest.setURL(KURL(KURL(), request.url));
  188. // Calling client might have changed our url pointer.
  189. // Free the new allocated string.
  190. free(const_cast<char*>(request.url));
  191. }
  192. }
  193. bool FrameLoaderClientEfl::shouldUseCredentialStorage(DocumentLoader*, unsigned long)
  194. {
  195. notImplemented();
  196. return false;
  197. }
  198. void FrameLoaderClientEfl::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader* loader, const ResourceRequest& coreRequest)
  199. {
  200. CString url = coreRequest.url().string().utf8();
  201. CString firstParty = coreRequest.firstPartyForCookies().string().utf8();
  202. CString httpMethod = coreRequest.httpMethod().utf8();
  203. DBG("Resource url=%s, First party=%s, HTTP method=%s", url.data(), firstParty.data(), httpMethod.data());
  204. bool isMainFrameRequest = false;
  205. if (loader) {
  206. const FrameLoader* frameLoader = loader->frameLoader();
  207. isMainFrameRequest = (loader == frameLoader->provisionalDocumentLoader() && frameLoader->isLoadingMainFrame());
  208. }
  209. Ewk_Frame_Resource_Request request = { url.data(), firstParty.data(), httpMethod.data(), identifier, m_frame, isMainFrameRequest };
  210. ewk_frame_request_assign_identifier(m_frame, &request);
  211. evas_object_smart_callback_call(m_view, "resource,request,new", &request);
  212. }
  213. void FrameLoaderClientEfl::postProgressStartedNotification()
  214. {
  215. ewk_frame_load_started(m_frame);
  216. postProgressEstimateChangedNotification();
  217. }
  218. void FrameLoaderClientEfl::postProgressEstimateChangedNotification()
  219. {
  220. ewk_frame_load_progress_changed(m_frame);
  221. }
  222. void FrameLoaderClientEfl::postProgressFinishedNotification()
  223. {
  224. notImplemented();
  225. }
  226. void FrameLoaderClientEfl::frameLoaderDestroyed()
  227. {
  228. if (m_frame)
  229. ewk_frame_core_gone(m_frame);
  230. m_frame = 0;
  231. delete this;
  232. }
  233. void FrameLoaderClientEfl::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& coreResponse)
  234. {
  235. // Update our knowledge of request soup flags - some are only set
  236. // after the request is done.
  237. loader->request().setSoupMessageFlags(coreResponse.soupMessageFlags());
  238. m_response = coreResponse;
  239. CString mimeType = coreResponse.mimeType().utf8();
  240. Ewk_Frame_Resource_Response response = { 0, coreResponse.httpStatusCode(), identifier, mimeType.data() };
  241. CString url = coreResponse.url().string().utf8();
  242. response.url = url.data();
  243. ewk_frame_response_received(m_frame, &response);
  244. evas_object_smart_callback_call(m_view, "resource,response,received", &response);
  245. }
  246. void FrameLoaderClientEfl::dispatchDecidePolicyForResponse(FramePolicyFunction function, const ResourceResponse& response, const ResourceRequest& resourceRequest)
  247. {
  248. // we need to call directly here (currently callPolicyFunction does that!)
  249. ASSERT(function);
  250. if (resourceRequest.isNull()) {
  251. callPolicyFunction(function, PolicyIgnore);
  252. return;
  253. }
  254. // Ignore responses with an HTTP status code of 204 (No Content)
  255. if (response.httpStatusCode() == HTTPNoContent) {
  256. callPolicyFunction(function, PolicyIgnore);
  257. return;
  258. }
  259. if (canShowMIMEType(response.mimeType()))
  260. callPolicyFunction(function, PolicyUse);
  261. else
  262. callPolicyFunction(function, PolicyDownload);
  263. }
  264. void FrameLoaderClientEfl::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction&, const ResourceRequest& resourceRequest, PassRefPtr<FormState>, const String&)
  265. {
  266. ASSERT(function);
  267. ASSERT(m_frame);
  268. if (resourceRequest.isNull()) {
  269. callPolicyFunction(function, PolicyIgnore);
  270. return;
  271. }
  272. // if not acceptNavigationRequest - look at Qt -> PolicyIgnore;
  273. // FIXME: do proper check and only reset forms when on PolicyIgnore
  274. Frame* f = EWKPrivate::coreFrame(m_frame);
  275. f->loader()->resetMultipleFormSubmissionProtection();
  276. callPolicyFunction(function, PolicyUse);
  277. }
  278. void FrameLoaderClientEfl::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& resourceRequest, PassRefPtr<FormState>)
  279. {
  280. ASSERT(function);
  281. ASSERT(m_frame);
  282. if (resourceRequest.isNull()) {
  283. callPolicyFunction(function, PolicyIgnore);
  284. return;
  285. }
  286. // if not acceptNavigationRequest - look at Qt -> PolicyIgnore;
  287. // FIXME: do proper check and only reset forms when on PolicyIgnore
  288. CString url = resourceRequest.url().string().utf8();
  289. CString firstParty = resourceRequest.firstPartyForCookies().string().utf8();
  290. CString httpMethod = resourceRequest.httpMethod().utf8();
  291. Ewk_Frame_Resource_Request request = { url.data(), firstParty.data(), httpMethod.data(), 0, m_frame, false };
  292. bool ret = ewk_view_navigation_policy_decision(m_view, &request, static_cast<Ewk_Navigation_Type>(action.type()));
  293. PolicyAction policy;
  294. if (!ret)
  295. policy = PolicyIgnore;
  296. else {
  297. if (action.type() == NavigationTypeFormSubmitted || action.type() == NavigationTypeFormResubmitted) {
  298. Frame* f = EWKPrivate::coreFrame(m_frame);
  299. f->loader()->resetMultipleFormSubmissionProtection();
  300. }
  301. policy = PolicyUse;
  302. }
  303. callPolicyFunction(function, policy);
  304. }
  305. PassRefPtr<Widget> FrameLoaderClientEfl::createPlugin(const IntSize& pluginSize, HTMLPlugInElement* element, const KURL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually)
  306. {
  307. ASSERT(m_frame);
  308. ASSERT(m_view);
  309. return ewk_view_plugin_create(m_view, m_frame, pluginSize,
  310. element, url, paramNames, paramValues,
  311. mimeType, loadManually);
  312. }
  313. PassRefPtr<Frame> FrameLoaderClientEfl::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement, const String& referrer, bool /*allowsScrolling*/, int /*marginWidth*/, int /*marginHeight*/)
  314. {
  315. ASSERT(m_frame);
  316. ASSERT(m_view);
  317. return ewk_view_frame_create(m_view, m_frame, name, ownerElement, url, referrer);
  318. }
  319. void FrameLoaderClientEfl::redirectDataToPlugin(Widget* pluginWidget)
  320. {
  321. m_pluginView = toPluginView(pluginWidget);
  322. if (pluginWidget)
  323. m_hasSentResponseToPlugin = false;
  324. }
  325. PassRefPtr<Widget> FrameLoaderClientEfl::createJavaAppletWidget(const IntSize&, HTMLAppletElement*, const KURL&,
  326. const Vector<String>& /*paramNames*/, const Vector<String>& /*paramValues*/)
  327. {
  328. notImplemented();
  329. return 0;
  330. }
  331. ObjectContentType FrameLoaderClientEfl::objectContentType(const KURL& url, const String& mimeType, bool shouldPreferPlugInsForImages)
  332. {
  333. // FIXME: once plugin support is enabled, this method needs to correctly handle the 'shouldPreferPlugInsForImages' flag. See
  334. // WebCore::FrameLoader::defaultObjectContentType() for an example.
  335. UNUSED_PARAM(shouldPreferPlugInsForImages);
  336. if (url.isEmpty() && mimeType.isEmpty())
  337. return ObjectContentNone;
  338. // We don't use MIMETypeRegistry::getMIMETypeForPath() because it returns "application/octet-stream" upon failure
  339. String type = mimeType;
  340. if (type.isEmpty())
  341. type = MIMETypeRegistry::getMIMETypeForExtension(url.path().substring(url.path().reverseFind('.') + 1));
  342. if (type.isEmpty())
  343. return ObjectContentFrame;
  344. if (MIMETypeRegistry::isSupportedImageMIMEType(type))
  345. return ObjectContentImage;
  346. #if 0 // PluginDatabase is disabled until we have Plugin system done.
  347. if (PluginDatabase::installedPlugins()->isMIMETypeRegistered(mimeType))
  348. return ObjectContentNetscapePlugin;
  349. #endif
  350. if (MIMETypeRegistry::isSupportedNonImageMIMEType(type))
  351. return ObjectContentFrame;
  352. if (url.protocol() == "about")
  353. return ObjectContentFrame;
  354. return ObjectContentNone;
  355. }
  356. String FrameLoaderClientEfl::overrideMediaType() const
  357. {
  358. return String::fromUTF8(ewk_settings_css_media_type_get());
  359. }
  360. void FrameLoaderClientEfl::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world)
  361. {
  362. if (world != mainThreadNormalWorld())
  363. return;
  364. Frame* coreFrame = EWKPrivate::coreFrame(m_frame);
  365. ASSERT(coreFrame);
  366. Settings* settings = coreFrame->settings();
  367. if (!settings || !settings->isScriptEnabled())
  368. return;
  369. Ewk_Window_Object_Cleared_Event event;
  370. event.context = toGlobalRef(coreFrame->script()->globalObject(mainThreadNormalWorld())->globalExec());
  371. event.windowObject = toRef(coreFrame->script()->globalObject(mainThreadNormalWorld()));
  372. event.frame = m_frame;
  373. evas_object_smart_callback_call(m_view, "window,object,cleared", &event);
  374. #if ENABLE(NETSCAPE_PLUGIN_API)
  375. ewk_view_js_window_object_clear(m_view, m_frame);
  376. #endif
  377. }
  378. void FrameLoaderClientEfl::documentElementAvailable()
  379. {
  380. return;
  381. }
  382. void FrameLoaderClientEfl::didPerformFirstNavigation() const
  383. {
  384. ewk_frame_did_perform_first_navigation(m_frame);
  385. }
  386. void FrameLoaderClientEfl::registerForIconNotification(bool)
  387. {
  388. notImplemented();
  389. }
  390. void FrameLoaderClientEfl::setMainFrameDocumentReady(bool)
  391. {
  392. // this is only interesting once we provide an external API for the DOM
  393. }
  394. bool FrameLoaderClientEfl::hasWebView() const
  395. {
  396. if (!m_view)
  397. return false;
  398. return true;
  399. }
  400. bool FrameLoaderClientEfl::hasFrameView() const
  401. {
  402. notImplemented();
  403. return true;
  404. }
  405. void FrameLoaderClientEfl::dispatchDidFinishLoad()
  406. {
  407. ewk_frame_load_finished(m_frame, 0, 0, 0, 0, 0);
  408. }
  409. void FrameLoaderClientEfl::frameLoadCompleted()
  410. {
  411. // Note: Can be called multiple times.
  412. }
  413. void FrameLoaderClientEfl::saveViewStateToItem(HistoryItem* item)
  414. {
  415. ewk_frame_view_state_save(m_frame, item);
  416. }
  417. void FrameLoaderClientEfl::restoreViewState()
  418. {
  419. ASSERT(m_frame);
  420. ASSERT(m_view);
  421. ewk_view_restore_state(m_view, m_frame);
  422. }
  423. void FrameLoaderClientEfl::updateGlobalHistoryRedirectLinks()
  424. {
  425. WebCore::Frame* frame = EWKPrivate::coreFrame(m_frame);
  426. if (!frame)
  427. return;
  428. WebCore::DocumentLoader* loader = frame->loader()->documentLoader();
  429. if (!loader)
  430. return;
  431. if (!loader->clientRedirectSourceForHistory().isNull()) {
  432. const CString& sourceURL = loader->clientRedirectSourceForHistory().utf8();
  433. const CString& destinationURL = loader->clientRedirectDestinationForHistory().utf8();
  434. Ewk_View_Redirection_Data data = { sourceURL.data(), destinationURL.data() };
  435. evas_object_smart_callback_call(m_view, "perform,client,redirect", &data);
  436. }
  437. if (!loader->serverRedirectSourceForHistory().isNull()) {
  438. const CString& sourceURL = loader->serverRedirectSourceForHistory().utf8();
  439. const CString& destinationURL = loader->serverRedirectDestinationForHistory().utf8();
  440. Ewk_View_Redirection_Data data = { sourceURL.data(), destinationURL.data() };
  441. evas_object_smart_callback_call(m_view, "perform,server,redirect", &data);
  442. }
  443. }
  444. bool FrameLoaderClientEfl::shouldGoToHistoryItem(HistoryItem* item) const
  445. {
  446. // FIXME: This is a very simple implementation. More sophisticated
  447. // implementation would delegate the decision to a PolicyDelegate.
  448. // See mac implementation for example.
  449. return item;
  450. }
  451. bool FrameLoaderClientEfl::shouldStopLoadingForHistoryItem(HistoryItem*) const
  452. {
  453. return true;
  454. }
  455. void FrameLoaderClientEfl::didDisplayInsecureContent()
  456. {
  457. ewk_frame_mixed_content_displayed_set(m_frame, true);
  458. }
  459. void FrameLoaderClientEfl::didRunInsecureContent(SecurityOrigin*, const KURL&)
  460. {
  461. ewk_frame_mixed_content_run_set(m_frame, true);
  462. }
  463. void FrameLoaderClientEfl::didDetectXSS(const KURL& insecureURL, bool didBlockEntirePage)
  464. {
  465. CString cs = insecureURL.string().utf8();
  466. Ewk_Frame_Xss_Notification xssInfo = { cs.data(), didBlockEntirePage };
  467. ewk_frame_xss_detected(m_frame, &xssInfo);
  468. }
  469. void FrameLoaderClientEfl::forceLayout()
  470. {
  471. ewk_frame_force_layout(m_frame);
  472. }
  473. void FrameLoaderClientEfl::forceLayoutForNonHTML()
  474. {
  475. }
  476. void FrameLoaderClientEfl::setCopiesOnScroll()
  477. {
  478. // apparently mac specific (Qt comment)
  479. }
  480. void FrameLoaderClientEfl::detachedFromParent2()
  481. {
  482. }
  483. void FrameLoaderClientEfl::detachedFromParent3()
  484. {
  485. }
  486. void FrameLoaderClientEfl::loadedFromCachedPage()
  487. {
  488. notImplemented();
  489. }
  490. void FrameLoaderClientEfl::dispatchDidHandleOnloadEvents()
  491. {
  492. ewk_view_onload_event(m_view, m_frame);
  493. }
  494. void FrameLoaderClientEfl::dispatchDidReceiveServerRedirectForProvisionalLoad()
  495. {
  496. ewk_frame_redirect_provisional_load(m_frame);
  497. }
  498. void FrameLoaderClientEfl::dispatchDidCancelClientRedirect()
  499. {
  500. ewk_frame_redirect_cancelled(m_frame);
  501. }
  502. void FrameLoaderClientEfl::dispatchWillPerformClientRedirect(const KURL& url, double, double)
  503. {
  504. ewk_frame_redirect_requested(m_frame, url.string().utf8().data());
  505. }
  506. void FrameLoaderClientEfl::dispatchDidChangeLocationWithinPage()
  507. {
  508. ewk_frame_uri_changed(m_frame);
  509. if (!isLoadingMainFrame())
  510. return;
  511. ewk_view_uri_changed(m_view);
  512. }
  513. void FrameLoaderClientEfl::dispatchWillClose()
  514. {
  515. notImplemented();
  516. }
  517. void FrameLoaderClientEfl::dispatchDidReceiveIcon()
  518. {
  519. // IconController loads icons only for the main frame.
  520. ASSERT(isLoadingMainFrame());
  521. ewk_view_frame_main_icon_received(m_view);
  522. }
  523. void FrameLoaderClientEfl::dispatchDidStartProvisionalLoad()
  524. {
  525. ewk_frame_load_provisional(m_frame);
  526. if (isLoadingMainFrame())
  527. ewk_view_load_provisional(m_view);
  528. }
  529. void FrameLoaderClientEfl::dispatchDidReceiveTitle(const StringWithDirection& title)
  530. {
  531. Ewk_Text_With_Direction ewkTitle;
  532. CString cs = title.string().utf8();
  533. ewkTitle.string = cs.data();
  534. ewkTitle.direction = (title.direction() == LTR) ? EWK_TEXT_DIRECTION_LEFT_TO_RIGHT : EWK_TEXT_DIRECTION_RIGHT_TO_LEFT;
  535. ewk_frame_title_set(m_frame, &ewkTitle);
  536. if (!isLoadingMainFrame())
  537. return;
  538. ewk_view_title_set(m_view, &ewkTitle);
  539. }
  540. void FrameLoaderClientEfl::dispatchDidChangeIcons(WebCore::IconType iconType)
  541. {
  542. // Other touch types are apple-specific
  543. ASSERT_UNUSED(iconType, iconType == WebCore::Favicon);
  544. ewk_frame_icon_changed(m_frame);
  545. }
  546. void FrameLoaderClientEfl::dispatchDidCommitLoad()
  547. {
  548. ewk_frame_uri_changed(m_frame);
  549. ewk_frame_load_committed(m_frame);
  550. if (!isLoadingMainFrame())
  551. return;
  552. ewk_view_title_set(m_view, 0);
  553. ewk_view_uri_changed(m_view);
  554. }
  555. void FrameLoaderClientEfl::dispatchDidFinishDocumentLoad()
  556. {
  557. ewk_frame_load_document_finished(m_frame);
  558. }
  559. void FrameLoaderClientEfl::dispatchDidLayout(LayoutMilestones milestones)
  560. {
  561. if (milestones & DidFirstLayout)
  562. ewk_frame_load_firstlayout_finished(m_frame);
  563. if (milestones & DidFirstVisuallyNonEmptyLayout)
  564. ewk_frame_load_firstlayout_nonempty_finished(m_frame);
  565. }
  566. void FrameLoaderClientEfl::dispatchShow()
  567. {
  568. ewk_view_load_show(m_view);
  569. }
  570. void FrameLoaderClientEfl::cancelPolicyCheck()
  571. {
  572. notImplemented();
  573. }
  574. void FrameLoaderClientEfl::willChangeTitle(DocumentLoader*)
  575. {
  576. // no need for, dispatchDidReceiveTitle is the right callback
  577. }
  578. void FrameLoaderClientEfl::didChangeTitle(DocumentLoader*)
  579. {
  580. // no need for, dispatchDidReceiveTitle is the right callback
  581. }
  582. bool FrameLoaderClientEfl::canHandleRequest(const ResourceRequest&) const
  583. {
  584. notImplemented();
  585. return true;
  586. }
  587. bool FrameLoaderClientEfl::canShowMIMETypeAsHTML(const String& /*MIMEType*/) const
  588. {
  589. notImplemented();
  590. return false;
  591. }
  592. bool FrameLoaderClientEfl::canShowMIMEType(const String& MIMEType) const
  593. {
  594. if (MIMETypeRegistry::canShowMIMEType(MIMEType))
  595. return true;
  596. #if 0 // PluginDatabase is disabled until we have Plugin system done.
  597. if (PluginDatabase::installedPlugins()->isMIMETypeRegistered(MIMEType))
  598. return true;
  599. #endif
  600. return false;
  601. }
  602. bool FrameLoaderClientEfl::representationExistsForURLScheme(const String&) const
  603. {
  604. return false;
  605. }
  606. String FrameLoaderClientEfl::generatedMIMETypeForURLScheme(const String&) const
  607. {
  608. notImplemented();
  609. return String();
  610. }
  611. void FrameLoaderClientEfl::finishedLoading(DocumentLoader*)
  612. {
  613. if (!m_pluginView)
  614. return;
  615. m_pluginView->didFinishLoading();
  616. m_pluginView = 0;
  617. m_hasSentResponseToPlugin = false;
  618. }
  619. void FrameLoaderClientEfl::provisionalLoadStarted()
  620. {
  621. notImplemented();
  622. }
  623. void FrameLoaderClientEfl::didFinishLoad()
  624. {
  625. notImplemented();
  626. }
  627. void FrameLoaderClientEfl::prepareForDataSourceReplacement()
  628. {
  629. notImplemented();
  630. }
  631. void FrameLoaderClientEfl::setTitle(const StringWithDirection&, const KURL&)
  632. {
  633. // no need for, dispatchDidReceiveTitle is the right callback
  634. }
  635. void FrameLoaderClientEfl::dispatchDidReceiveContentLength(DocumentLoader*, unsigned long /*identifier*/, int /*dataLength*/)
  636. {
  637. notImplemented();
  638. }
  639. void FrameLoaderClientEfl::dispatchDidFinishLoading(DocumentLoader*, unsigned long identifier)
  640. {
  641. ewk_frame_load_resource_finished(m_frame, identifier);
  642. evas_object_smart_callback_call(m_view, "load,resource,finished", &identifier);
  643. }
  644. void FrameLoaderClientEfl::dispatchDidFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError& err)
  645. {
  646. Ewk_Frame_Load_Error error;
  647. CString errorDomain = err.domain().utf8();
  648. CString errorDescription = err.localizedDescription().utf8();
  649. CString failingUrl = err.failingURL().utf8();
  650. DBG("ewkFrame=%p, resource=%ld, error=%s (%d, cancellation=%hhu) \"%s\", url=%s",
  651. m_frame, identifier, errorDomain.data(), err.errorCode(), err.isCancellation(),
  652. errorDescription.data(), failingUrl.data());
  653. error.code = err.errorCode();
  654. error.is_cancellation = err.isCancellation();
  655. error.domain = errorDomain.data();
  656. error.description = errorDescription.data();
  657. error.failing_url = failingUrl.data();
  658. error.resource_identifier = identifier;
  659. error.frame = m_frame;
  660. ewk_frame_load_resource_failed(m_frame, &error);
  661. evas_object_smart_callback_call(m_view, "load,resource,failed", &error);
  662. }
  663. bool FrameLoaderClientEfl::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int /*length*/)
  664. {
  665. notImplemented();
  666. return false;
  667. }
  668. void FrameLoaderClientEfl::dispatchDidLoadResourceByXMLHttpRequest(unsigned long, const String&)
  669. {
  670. notImplemented();
  671. }
  672. void FrameLoaderClientEfl::dispatchDidFailProvisionalLoad(const ResourceError& err)
  673. {
  674. Ewk_Frame_Load_Error error;
  675. CString errorDomain = err.domain().utf8();
  676. CString errorDescription = err.localizedDescription().utf8();
  677. CString failingUrl = err.failingURL().utf8();
  678. DBG("ewkFrame=%p, error=%s (%d, cancellation=%hhu) \"%s\", url=%s",
  679. m_frame, errorDomain.data(), err.errorCode(), err.isCancellation(),
  680. errorDescription.data(), failingUrl.data());
  681. error.code = err.errorCode();
  682. error.is_cancellation = err.isCancellation();
  683. error.domain = errorDomain.data();
  684. error.description = errorDescription.data();
  685. error.failing_url = failingUrl.data();
  686. error.resource_identifier = 0;
  687. error.frame = m_frame;
  688. ewk_frame_load_provisional_failed(m_frame, &error);
  689. if (isLoadingMainFrame())
  690. ewk_view_load_provisional_failed(m_view, &error);
  691. dispatchDidFailLoad(err);
  692. }
  693. void FrameLoaderClientEfl::dispatchDidFailLoad(const ResourceError& err)
  694. {
  695. ewk_frame_load_error(m_frame,
  696. err.domain().utf8().data(),
  697. err.errorCode(), err.isCancellation(),
  698. err.localizedDescription().utf8().data(),
  699. err.failingURL().utf8().data());
  700. ewk_frame_load_finished(m_frame,
  701. err.domain().utf8().data(),
  702. err.errorCode(),
  703. err.isCancellation(),
  704. err.localizedDescription().utf8().data(),
  705. err.failingURL().utf8().data());
  706. }
  707. void FrameLoaderClientEfl::convertMainResourceLoadToDownload(DocumentLoader*, const ResourceRequest& request, const ResourceResponse&)
  708. {
  709. if (!m_view)
  710. return;
  711. CString url = request.url().string().utf8();
  712. Ewk_Download download;
  713. download.url = url.data();
  714. download.suggested_name = 0;
  715. ewk_view_download_request(m_view, &download);
  716. }
  717. ResourceError FrameLoaderClientEfl::cancelledError(const ResourceRequest& request)
  718. {
  719. return WebCore::cancelledError(request);
  720. }
  721. ResourceError FrameLoaderClientEfl::blockedError(const ResourceRequest& request)
  722. {
  723. return WebCore::blockedError(request);
  724. }
  725. ResourceError FrameLoaderClientEfl::cannotShowURLError(const ResourceRequest& request)
  726. {
  727. return WebCore::cannotShowURLError(request);
  728. }
  729. ResourceError FrameLoaderClientEfl::interruptedForPolicyChangeError(const ResourceRequest& request)
  730. {
  731. return WebCore::interruptedForPolicyChangeError(request);
  732. }
  733. ResourceError FrameLoaderClientEfl::cannotShowMIMETypeError(const ResourceResponse& response)
  734. {
  735. return WebCore::cannotShowMIMETypeError(response);
  736. }
  737. ResourceError FrameLoaderClientEfl::fileDoesNotExistError(const ResourceResponse& response)
  738. {
  739. return WebCore::fileDoesNotExistError(response);
  740. }
  741. ResourceError FrameLoaderClientEfl::pluginWillHandleLoadError(const ResourceResponse& response)
  742. {
  743. return WebCore::pluginWillHandleLoadError(response);
  744. }
  745. bool FrameLoaderClientEfl::shouldFallBack(const ResourceError& error)
  746. {
  747. return !(error.isCancellation() || error.errorCode() == PolicyErrorFrameLoadInterruptedByPolicyChange || error.errorCode() == PluginErrorWillHandleLoad);
  748. }
  749. bool FrameLoaderClientEfl::canCachePage() const
  750. {
  751. return true;
  752. }
  753. Frame* FrameLoaderClientEfl::dispatchCreatePage(const NavigationAction&)
  754. {
  755. if (!m_view)
  756. return 0;
  757. Evas_Object* newView = ewk_view_window_create(m_view, EINA_FALSE, 0);
  758. Evas_Object* mainFrame;
  759. if (!newView)
  760. mainFrame = m_frame;
  761. else
  762. mainFrame = ewk_view_frame_main_get(newView);
  763. return EWKPrivate::coreFrame(mainFrame);
  764. }
  765. void FrameLoaderClientEfl::dispatchUnableToImplementPolicy(const ResourceError&)
  766. {
  767. notImplemented();
  768. }
  769. void FrameLoaderClientEfl::setMainDocumentError(DocumentLoader*, const ResourceError& error)
  770. {
  771. if (!m_pluginView)
  772. return;
  773. m_pluginView->didFail(error);
  774. m_pluginView = 0;
  775. m_hasSentResponseToPlugin = false;
  776. }
  777. void FrameLoaderClientEfl::startDownload(const ResourceRequest& request, const String& suggestedName)
  778. {
  779. if (!m_view)
  780. return;
  781. CString url = request.url().string().utf8();
  782. CString suggestedNameString = suggestedName.utf8();
  783. Ewk_Download download;
  784. download.url = url.data();
  785. download.suggested_name = suggestedNameString.data();
  786. ewk_view_download_request(m_view, &download);
  787. }
  788. void FrameLoaderClientEfl::updateGlobalHistory()
  789. {
  790. WebCore::Frame* frame = EWKPrivate::coreFrame(m_frame);
  791. if (!frame)
  792. return;
  793. WebCore::DocumentLoader* loader = frame->loader()->documentLoader();
  794. if (!loader)
  795. return;
  796. const FrameLoader* frameLoader = loader->frameLoader();
  797. const bool isMainFrameRequest = frameLoader && (loader == frameLoader->provisionalDocumentLoader()) && frameLoader->isLoadingMainFrame();
  798. const CString& urlForHistory = loader->urlForHistory().string().utf8();
  799. const CString& title = loader->title().string().utf8();
  800. const CString& firstParty = loader->request().firstPartyForCookies().string().utf8();
  801. const CString& clientRedirectSource = loader->clientRedirectSourceForHistory().utf8();
  802. const CString& originalURL = loader->originalURL().string().utf8();
  803. const CString& httpMethod = loader->request().httpMethod().utf8();
  804. const CString& responseURL = loader->responseURL().string().utf8();
  805. const CString& mimeType = loader->response().mimeType().utf8();
  806. Ewk_Frame_Resource_Request request = { originalURL.data(), firstParty.data(), httpMethod.data(), 0, m_frame, isMainFrameRequest };
  807. Ewk_Frame_Resource_Response response = { responseURL.data(), loader->response().httpStatusCode(), 0, mimeType.data() };
  808. bool hasSubstituteData = loader->substituteData().isValid();
  809. Ewk_View_Navigation_Data data = { urlForHistory.data(), title.data(), &request, &response, hasSubstituteData, clientRedirectSource.data() };
  810. evas_object_smart_callback_call(m_view, "navigate,with,data", &data);
  811. }
  812. void FrameLoaderClientEfl::savePlatformDataToCachedFrame(CachedFrame*)
  813. {
  814. notImplemented();
  815. }
  816. void FrameLoaderClientEfl::transitionToCommittedFromCachedFrame(CachedFrame*)
  817. {
  818. }
  819. void FrameLoaderClientEfl::transitionToCommittedForNewPage()
  820. {
  821. ASSERT(m_frame);
  822. ASSERT(m_view);
  823. ewk_frame_view_create_for_view(m_frame, m_view);
  824. if (isLoadingMainFrame()) {
  825. ewk_view_frame_view_creation_notify(m_view);
  826. ewk_view_frame_main_cleared(m_view);
  827. }
  828. }
  829. void FrameLoaderClientEfl::didSaveToPageCache()
  830. {
  831. }
  832. void FrameLoaderClientEfl::didRestoreFromPageCache()
  833. {
  834. }
  835. void FrameLoaderClientEfl::dispatchDidBecomeFrameset(bool)
  836. {
  837. }
  838. PassRefPtr<FrameNetworkingContext> FrameLoaderClientEfl::createNetworkingContext()
  839. {
  840. return FrameNetworkingContextEfl::create(EWKPrivate::coreFrame(m_frame), m_frame);
  841. }
  842. }