initial import
[vuplus_webkit] / Source / WebKit / efl / WebCoreSupport / FrameLoaderClientEfl.cpp
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  *
11  * All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  *
22  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
23  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
26  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
30  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include "config.h"
36 #include "FrameLoaderClientEfl.h"
37
38 #include "APICast.h"
39 #include "DocumentLoader.h"
40 #include "EWebKit.h"
41 #include "FormState.h"
42 #include "FrameLoader.h"
43 #include "FrameNetworkingContextEfl.h"
44 #include "FrameTree.h"
45 #include "FrameView.h"
46 #include "HTMLFormElement.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 "WebKitVersion.h"
55 #include "ewk_private.h"
56 #include <wtf/text/CString.h>
57 #include <wtf/text/StringConcatenate.h>
58
59 #if OS(UNIX)
60 #include <sys/utsname.h>
61 #elif OS(WINDOWS)
62 #include "SystemInfo.h"
63 #endif
64
65 #include <Ecore_Evas.h>
66
67 using namespace WebCore;
68
69 namespace WebCore {
70
71 FrameLoaderClientEfl::FrameLoaderClientEfl(Evas_Object *view)
72     : m_view(view)
73     , m_frame(0)
74     , m_userAgent("")
75     , m_customUserAgent("")
76     , m_pluginView(0)
77     , m_hasSentResponseToPlugin(false)
78     , m_hasRepresentation(false)
79 {
80 }
81
82 static String agentOS()
83 {
84 #if OS(DARWIN)
85 #if CPU(X86)
86     return "Intel Mac OS X";
87 #else
88     return "PPC Mac OS X";
89 #endif
90 #elif OS(UNIX)
91     struct utsname name;
92     if (uname(&name) != -1)
93         return makeString(name.sysname, ' ', name.machine);
94
95     return "Unknown";
96 #elif OS(WINDOWS)
97     return windowsVersionForUAString();
98 #else
99     notImplemented();
100     return "Unknown";
101 #endif
102 }
103
104 static String composeUserAgent()
105 {
106     String webKitVersion = String::format("%d.%d", WEBKIT_MAJOR_VERSION, WEBKIT_MINOR_VERSION);
107     return makeString("Mozilla/5.0 (", agentOS(), ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko) Safari/", webKitVersion);
108 }
109
110 void FrameLoaderClientEfl::setCustomUserAgent(const String &agent)
111 {
112     m_customUserAgent = agent;
113 }
114
115 const String& FrameLoaderClientEfl::customUserAgent() const
116 {
117     return m_customUserAgent;
118 }
119
120 String FrameLoaderClientEfl::userAgent(const KURL&)
121 {
122     if (!m_customUserAgent.isEmpty())
123         return m_customUserAgent;
124
125     if (m_userAgent.isEmpty())
126         m_userAgent = composeUserAgent();
127     return m_userAgent;
128 }
129
130 void FrameLoaderClientEfl::callPolicyFunction(FramePolicyFunction function, PolicyAction action)
131 {
132     Frame* f = ewk_frame_core_get(m_frame);
133     ASSERT(f);
134     (f->loader()->policyChecker()->*function)(action);
135 }
136
137 WTF::PassRefPtr<DocumentLoader> FrameLoaderClientEfl::createDocumentLoader(const ResourceRequest& request, const SubstituteData& substituteData)
138 {
139     RefPtr<DocumentLoader> loader = DocumentLoader::create(request, substituteData);
140     if (substituteData.isValid())
141         loader->setDeferMainResourceDataLoad(false);
142     return loader.release();
143 }
144
145 void FrameLoaderClientEfl::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState>)
146 {
147     // FIXME: This is surely too simple
148     ASSERT(function);
149     callPolicyFunction(function, PolicyUse);
150 }
151
152 void FrameLoaderClientEfl::committedLoad(DocumentLoader* loader, const char* data, int length)
153 {
154     if (!m_pluginView)
155         loader->commitData(data, length);
156
157     // We re-check here as the plugin can have been created
158     if (m_pluginView) {
159         if (!m_hasSentResponseToPlugin) {
160             m_pluginView->didReceiveResponse(loader->response());
161             m_hasSentResponseToPlugin = true;
162         }
163         m_pluginView->didReceiveData(data, length);
164     }
165 }
166
167 void FrameLoaderClientEfl::dispatchDidReplaceStateWithinPage()
168 {
169     notImplemented();
170 }
171
172 void FrameLoaderClientEfl::dispatchDidRemoveBackForwardItem(WebCore::HistoryItem*) const
173 {
174     notImplemented();
175 }
176
177 void FrameLoaderClientEfl::dispatchDidPushStateWithinPage()
178 {
179     notImplemented();
180 }
181
182 void FrameLoaderClientEfl::dispatchDidPopStateWithinPage()
183 {
184     notImplemented();
185 }
186
187 void FrameLoaderClientEfl::dispatchDidChangeBackForwardIndex() const
188 {
189     notImplemented();
190 }
191
192 void FrameLoaderClientEfl::dispatchDidAddBackForwardItem(WebCore::HistoryItem*) const
193 {
194     notImplemented();
195 }
196
197 void FrameLoaderClientEfl::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long  identifier, const AuthenticationChallenge&)
198 {
199     notImplemented();
200 }
201
202 void FrameLoaderClientEfl::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long  identifier, const AuthenticationChallenge&)
203 {
204     notImplemented();
205 }
206
207 void FrameLoaderClientEfl::dispatchWillSendRequest(DocumentLoader* loader, unsigned long identifier, ResourceRequest& coreRequest, const ResourceResponse& coreResponse)
208 {
209     CString url = coreRequest.url().string().utf8();
210     DBG("Resource url=%s", url.data());
211
212     Ewk_Frame_Resource_Request request = { 0, identifier };
213     Ewk_Frame_Resource_Request orig = request; /* Initialize const fields. */
214
215     orig.url = request.url = url.data();
216
217     ewk_frame_request_will_send(m_frame, &request);
218
219     if (request.url != orig.url) {
220         coreRequest.setURL(KURL(KURL(), request.url));
221
222         // Calling client might have changed our url pointer.
223         // Free the new allocated string.
224         free(const_cast<char*>(request.url));
225     }
226 }
227
228 bool FrameLoaderClientEfl::shouldUseCredentialStorage(DocumentLoader*, unsigned long)
229 {
230     notImplemented();
231     return false;
232 }
233
234 void FrameLoaderClientEfl::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest& coreRequest)
235 {
236     CString url = coreRequest.url().string().utf8();
237     DBG("Resource url=%s", url.data());
238
239     Ewk_Frame_Resource_Request request = { 0, identifier };
240     ewk_frame_request_assign_identifier(m_frame, &request);
241 }
242
243 void FrameLoaderClientEfl::postProgressStartedNotification()
244 {
245     ewk_frame_load_started(m_frame);
246     postProgressEstimateChangedNotification();
247 }
248
249 void FrameLoaderClientEfl::postProgressEstimateChangedNotification()
250 {
251     ewk_frame_load_progress_changed(m_frame);
252 }
253
254 void FrameLoaderClientEfl::postProgressFinishedNotification()
255 {
256     if (m_loadError.isNull())
257         ewk_frame_load_finished(m_frame, 0, 0, 0, 0, 0);
258     else {
259         ewk_frame_load_finished(m_frame,
260                                 m_loadError.domain().utf8().data(),
261                                 m_loadError.errorCode(),
262                                 m_loadError.isCancellation(),
263                                 m_loadError.localizedDescription().utf8().data(),
264                                 m_loadError.failingURL().utf8().data());
265     }
266 }
267
268 void FrameLoaderClientEfl::frameLoaderDestroyed()
269 {
270     if (m_frame)
271         ewk_frame_core_gone(m_frame);
272     m_frame = 0;
273
274     delete this;
275 }
276
277 void FrameLoaderClientEfl::dispatchDidReceiveResponse(DocumentLoader*, unsigned long, const ResourceResponse& response)
278 {
279     m_response = response;
280 }
281
282 void FrameLoaderClientEfl::dispatchDecidePolicyForResponse(FramePolicyFunction function, const ResourceResponse& response, const ResourceRequest& resourceRequest)
283 {
284     // we need to call directly here (currently callPolicyFunction does that!)
285     ASSERT(function);
286
287     if (resourceRequest.isNull()) {
288         callPolicyFunction(function, PolicyIgnore);
289         return;
290     }
291
292     if (canShowMIMEType(response.mimeType()))
293         callPolicyFunction(function, PolicyUse);
294     else
295         callPolicyFunction(function, PolicyDownload);
296 }
297
298 void FrameLoaderClientEfl::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& resourceRequest, PassRefPtr<FormState>, const String&)
299 {
300     ASSERT(function);
301     ASSERT(m_frame);
302
303     if (resourceRequest.isNull()) {
304         callPolicyFunction(function, PolicyIgnore);
305         return;
306     }
307
308     // if not acceptNavigationRequest - look at Qt -> PolicyIgnore;
309     // FIXME: do proper check and only reset forms when on PolicyIgnore
310     Frame* f = ewk_frame_core_get(m_frame);
311     f->loader()->resetMultipleFormSubmissionProtection();
312     callPolicyFunction(function, PolicyUse);
313 }
314
315 void FrameLoaderClientEfl::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& resourceRequest, PassRefPtr<FormState>)
316 {
317     ASSERT(function);
318     ASSERT(m_frame);
319
320     if (resourceRequest.isNull()) {
321         callPolicyFunction(function, PolicyIgnore);
322         return;
323     }
324
325     // if not acceptNavigationRequest - look at Qt -> PolicyIgnore;
326     // FIXME: do proper check and only reset forms when on PolicyIgnore
327     char* url = strdup(resourceRequest.url().string().utf8().data());
328     Ewk_Frame_Resource_Request request = { url, 0 };
329     Eina_Bool ret = ewk_view_navigation_policy_decision(m_view, &request);
330     free(url);
331
332     PolicyAction policy;
333     if (!ret)
334         policy = PolicyIgnore;
335     else {
336         if (action.type() == NavigationTypeFormSubmitted || action.type() == NavigationTypeFormResubmitted) {
337             Frame* f = ewk_frame_core_get(m_frame);
338             f->loader()->resetMultipleFormSubmissionProtection();
339         }
340         policy = PolicyUse;
341     }
342     callPolicyFunction(function, policy);
343 }
344
345 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)
346 {
347     ASSERT(m_frame);
348     ASSERT(m_view);
349
350     return ewk_view_plugin_create(m_view, m_frame, pluginSize,
351                                   element, url, paramNames, paramValues,
352                                   mimeType, loadManually);
353 }
354
355 PassRefPtr<Frame> FrameLoaderClientEfl::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement, const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight)
356 {
357     ASSERT(m_frame);
358     ASSERT(m_view);
359
360     return ewk_view_frame_create(m_view, m_frame, name, ownerElement, url, referrer);
361 }
362
363 void FrameLoaderClientEfl::didTransferChildFrameToNewDocument(Page*)
364 {
365     ASSERT(m_frame);
366
367     Frame* currentFrame = ewk_frame_core_get(m_frame);
368     Evas_Object* currentView = ewk_frame_view_get(m_frame);
369     Frame* parentFrame = currentFrame->tree()->parent();
370
371     FrameLoaderClientEfl* client = static_cast<FrameLoaderClientEfl*>(parentFrame->loader()->client());
372     Evas_Object* clientFrame = client ? client->webFrame() : 0;
373     Evas_Object* clientView = ewk_frame_view_get(clientFrame);
374
375     if (currentView != clientView) {
376         ewk_frame_view_set(m_frame, clientView);
377         m_view = clientView;
378     }
379
380     ASSERT(ewk_view_core_page_get(ewk_frame_view_get(m_frame)) == currentFrame->page());
381 }
382
383 void FrameLoaderClientEfl::transferLoadingResourceFromPage(ResourceLoader*, const ResourceRequest&, Page*)
384 {
385 }
386
387 void FrameLoaderClientEfl::redirectDataToPlugin(Widget* pluginWidget)
388 {
389     ASSERT(!m_pluginView);
390     m_pluginView = static_cast<PluginView*>(pluginWidget);
391     m_hasSentResponseToPlugin = false;
392 }
393
394 PassRefPtr<Widget> FrameLoaderClientEfl::createJavaAppletWidget(const IntSize&, HTMLAppletElement*, const KURL& baseURL,
395                                                   const Vector<String>& paramNames, const Vector<String>& paramValues)
396 {
397     notImplemented();
398     return 0;
399 }
400
401 ObjectContentType FrameLoaderClientEfl::objectContentType(const KURL& url, const String& mimeType, bool shouldPreferPlugInsForImages)
402 {
403     // FIXME: once plugin support is enabled, this method needs to correctly handle the 'shouldPreferPlugInsForImages' flag. See
404     // WebCore::FrameLoader::defaultObjectContentType() for an example.
405     UNUSED_PARAM(shouldPreferPlugInsForImages);
406
407     if (url.isEmpty() && mimeType.isEmpty())
408         return ObjectContentNone;
409
410     // We don't use MIMETypeRegistry::getMIMETypeForPath() because it returns "application/octet-stream" upon failure
411     String type = mimeType;
412     if (type.isEmpty())
413         type = MIMETypeRegistry::getMIMETypeForExtension(url.path().substring(url.path().reverseFind('.') + 1));
414
415     if (type.isEmpty())
416         return ObjectContentFrame;
417
418     if (MIMETypeRegistry::isSupportedImageMIMEType(type))
419         return ObjectContentImage;
420
421 #if 0 // PluginDatabase is disabled until we have Plugin system done.
422     if (PluginDatabase::installedPlugins()->isMIMETypeRegistered(mimeType))
423         return ObjectContentNetscapePlugin;
424 #endif
425
426     if (MIMETypeRegistry::isSupportedNonImageMIMEType(type))
427         return ObjectContentFrame;
428
429     if (url.protocol() == "about")
430         return ObjectContentFrame;
431
432     return ObjectContentNone;
433 }
434
435 String FrameLoaderClientEfl::overrideMediaType() const
436 {
437     notImplemented();
438     return String();
439 }
440
441 void FrameLoaderClientEfl::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world)
442 {
443     if (world != mainThreadNormalWorld())
444         return;
445
446     Frame* coreFrame = ewk_frame_core_get(m_frame);
447     ASSERT(coreFrame);
448
449     Settings* settings = coreFrame->settings();
450     if (!settings || !settings->isJavaScriptEnabled())
451         return;
452
453     Ewk_Window_Object_Cleared_Event event;
454     event.context = toGlobalRef(coreFrame->script()->globalObject(mainThreadNormalWorld())->globalExec());
455     event.windowObject = toRef(coreFrame->script()->globalObject(mainThreadNormalWorld()));
456     event.frame = m_frame;
457
458     evas_object_smart_callback_call(m_view, "window,object,cleared", &event);
459
460 #if ENABLE(NETSCAPE_PLUGIN_API)
461     ewk_view_js_window_object_clear(m_view, m_frame);
462 #endif
463 }
464
465 void FrameLoaderClientEfl::documentElementAvailable()
466 {
467     return;
468 }
469
470 void FrameLoaderClientEfl::didPerformFirstNavigation() const
471 {
472     ewk_frame_did_perform_first_navigation(m_frame);
473 }
474
475 void FrameLoaderClientEfl::registerForIconNotification(bool)
476 {
477     notImplemented();
478 }
479
480 void FrameLoaderClientEfl::setMainFrameDocumentReady(bool)
481 {
482     // this is only interesting once we provide an external API for the DOM
483 }
484
485 bool FrameLoaderClientEfl::hasWebView() const
486 {
487     if (!m_view)
488         return false;
489
490     return true;
491 }
492
493 bool FrameLoaderClientEfl::hasFrameView() const
494 {
495     notImplemented();
496     return true;
497 }
498
499 void FrameLoaderClientEfl::dispatchDidFinishLoad()
500 {
501     m_loadError = ResourceError(); /* clears previous error */
502 }
503
504 void FrameLoaderClientEfl::frameLoadCompleted()
505 {
506     // Note: Can be called multiple times.
507 }
508
509 void FrameLoaderClientEfl::saveViewStateToItem(HistoryItem* item)
510 {
511     ewk_frame_view_state_save(m_frame, item);
512 }
513
514 void FrameLoaderClientEfl::restoreViewState()
515 {
516     ASSERT(m_frame);
517     ASSERT(m_view);
518
519     ewk_view_restore_state(m_view, m_frame);
520 }
521
522 void FrameLoaderClientEfl::updateGlobalHistoryRedirectLinks()
523 {
524 }
525
526 bool FrameLoaderClientEfl::shouldGoToHistoryItem(HistoryItem* item) const
527 {
528     // FIXME: This is a very simple implementation. More sophisticated
529     // implementation would delegate the decision to a PolicyDelegate.
530     // See mac implementation for example.
531     return item;
532 }
533
534 bool FrameLoaderClientEfl::shouldStopLoadingForHistoryItem(HistoryItem* item) const
535 {
536     return true;
537 }
538
539 void FrameLoaderClientEfl::didDisplayInsecureContent()
540 {
541     notImplemented();
542 }
543
544 void FrameLoaderClientEfl::didRunInsecureContent(SecurityOrigin*, const KURL&)
545 {
546     notImplemented();
547 }
548
549 void FrameLoaderClientEfl::makeRepresentation(DocumentLoader*)
550 {
551     m_hasRepresentation = true;
552 }
553
554 void FrameLoaderClientEfl::forceLayout()
555 {
556     ewk_frame_force_layout(m_frame);
557 }
558
559 void FrameLoaderClientEfl::forceLayoutForNonHTML()
560 {
561 }
562
563 void FrameLoaderClientEfl::setCopiesOnScroll()
564 {
565     // apparently mac specific (Qt comment)
566 }
567
568 void FrameLoaderClientEfl::detachedFromParent2()
569 {
570 }
571
572 void FrameLoaderClientEfl::detachedFromParent3()
573 {
574 }
575
576 void FrameLoaderClientEfl::loadedFromCachedPage()
577 {
578     notImplemented();
579 }
580
581 void FrameLoaderClientEfl::dispatchDidHandleOnloadEvents()
582 {
583     notImplemented();
584 }
585
586 void FrameLoaderClientEfl::dispatchDidReceiveServerRedirectForProvisionalLoad()
587 {
588     notImplemented();
589 }
590
591 void FrameLoaderClientEfl::dispatchDidCancelClientRedirect()
592 {
593     notImplemented();
594 }
595
596 void FrameLoaderClientEfl::dispatchWillPerformClientRedirect(const KURL&, double, double)
597 {
598     notImplemented();
599 }
600
601 void FrameLoaderClientEfl::dispatchDidChangeLocationWithinPage()
602 {
603     ewk_frame_uri_changed(m_frame);
604
605     if (ewk_view_frame_main_get(m_view) != m_frame)
606         return;
607     ewk_view_uri_changed(m_view);
608 }
609
610 void FrameLoaderClientEfl::dispatchWillClose()
611 {
612     notImplemented();
613 }
614
615 void FrameLoaderClientEfl::dispatchDidReceiveIcon()
616 {
617     /* report received favicon only for main frame. */
618     if (ewk_view_frame_main_get(m_view) != m_frame)
619         return;
620
621     ewk_view_frame_main_icon_received(m_view);
622 }
623
624 void FrameLoaderClientEfl::dispatchDidStartProvisionalLoad()
625 {
626     ewk_frame_load_provisional(m_frame);
627     if (ewk_view_frame_main_get(m_view) == m_frame)
628         ewk_view_load_provisional(m_view);
629 }
630
631 void FrameLoaderClientEfl::dispatchDidReceiveTitle(const StringWithDirection& title)
632 {
633     // FIXME: use direction of title.
634     CString cs = title.string().utf8();
635     ewk_frame_title_set(m_frame, cs.data());
636
637     if (ewk_view_frame_main_get(m_view) != m_frame)
638         return;
639     ewk_view_title_set(m_view, cs.data());
640 }
641
642 void FrameLoaderClientEfl::dispatchDidChangeIcons(WebCore::IconType)
643 {
644     notImplemented();
645 }
646
647 void FrameLoaderClientEfl::dispatchDidCommitLoad()
648 {
649     ewk_frame_uri_changed(m_frame);
650     if (ewk_view_frame_main_get(m_view) != m_frame)
651         return;
652     ewk_view_title_set(m_view, 0);
653     ewk_view_uri_changed(m_view);
654 }
655
656 void FrameLoaderClientEfl::dispatchDidFinishDocumentLoad()
657 {
658     ewk_frame_load_document_finished(m_frame);
659 }
660
661 void FrameLoaderClientEfl::dispatchDidFirstLayout()
662 {
663     ewk_frame_load_firstlayout_finished(m_frame);
664 }
665
666 void FrameLoaderClientEfl::dispatchDidFirstVisuallyNonEmptyLayout()
667 {
668     ewk_frame_load_firstlayout_nonempty_finished(m_frame);
669 }
670
671 void FrameLoaderClientEfl::dispatchShow()
672 {
673     ewk_view_load_show(m_view);
674 }
675
676 void FrameLoaderClientEfl::cancelPolicyCheck()
677 {
678     notImplemented();
679 }
680
681 void FrameLoaderClientEfl::dispatchDidLoadMainResource(DocumentLoader*)
682 {
683     notImplemented();
684 }
685
686 void FrameLoaderClientEfl::revertToProvisionalState(DocumentLoader*)
687 {
688     m_hasRepresentation = true;
689 }
690
691 void FrameLoaderClientEfl::willChangeTitle(DocumentLoader*)
692 {
693     // no need for, dispatchDidReceiveTitle is the right callback
694 }
695
696 void FrameLoaderClientEfl::didChangeTitle(DocumentLoader *l)
697 {
698     // no need for, dispatchDidReceiveTitle is the right callback
699 }
700
701 bool FrameLoaderClientEfl::canHandleRequest(const ResourceRequest&) const
702 {
703     notImplemented();
704     return true;
705 }
706
707 bool FrameLoaderClientEfl::canShowMIMETypeAsHTML(const String& MIMEType) const
708 {
709     notImplemented();
710     return false;
711 }
712
713 bool FrameLoaderClientEfl::canShowMIMEType(const String& MIMEType) const
714 {
715     if (MIMETypeRegistry::isSupportedImageMIMEType(MIMEType))
716         return true;
717
718     if (MIMETypeRegistry::isSupportedNonImageMIMEType(MIMEType))
719         return true;
720
721 #if 0 // PluginDatabase is disabled until we have Plugin system done.
722     if (PluginDatabase::installedPlugins()->isMIMETypeRegistered(MIMEType))
723         return true;
724 #endif
725
726     return false;
727 }
728
729 bool FrameLoaderClientEfl::representationExistsForURLScheme(const String&) const
730 {
731     return false;
732 }
733
734 String FrameLoaderClientEfl::generatedMIMETypeForURLScheme(const String&) const
735 {
736     notImplemented();
737     return String();
738 }
739
740 void FrameLoaderClientEfl::finishedLoading(DocumentLoader* documentLoader)
741 {
742     if (!m_pluginView) {
743         if (m_hasRepresentation)
744             documentLoader->writer()->setEncoding("", false);
745         return;
746     }
747     m_pluginView->didFinishLoading();
748     m_pluginView = 0;
749     m_hasSentResponseToPlugin = false;
750 }
751
752
753 void FrameLoaderClientEfl::provisionalLoadStarted()
754 {
755     notImplemented();
756 }
757
758 void FrameLoaderClientEfl::didFinishLoad()
759 {
760     notImplemented();
761 }
762
763 void FrameLoaderClientEfl::prepareForDataSourceReplacement()
764 {
765     notImplemented();
766 }
767
768 void FrameLoaderClientEfl::setTitle(const StringWithDirection& title, const KURL& url)
769 {
770     // no need for, dispatchDidReceiveTitle is the right callback
771 }
772
773 void FrameLoaderClientEfl::dispatchDidReceiveContentLength(DocumentLoader*, unsigned long identifier, int dataLength)
774 {
775     notImplemented();
776 }
777
778 void FrameLoaderClientEfl::dispatchDidFinishLoading(DocumentLoader*, unsigned long identifier)
779 {
780     notImplemented();
781 }
782
783 void FrameLoaderClientEfl::dispatchDidFailLoading(DocumentLoader* loader, unsigned long identifier, const ResourceError& err)
784 {
785     notImplemented();
786 }
787
788 bool FrameLoaderClientEfl::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int length)
789 {
790     notImplemented();
791     return false;
792 }
793
794 void FrameLoaderClientEfl::dispatchDidLoadResourceByXMLHttpRequest(unsigned long, const String&)
795 {
796     notImplemented();
797 }
798
799 void FrameLoaderClientEfl::dispatchDidFailProvisionalLoad(const ResourceError& err)
800 {
801     dispatchDidFailLoad(err);
802 }
803
804 void FrameLoaderClientEfl::dispatchDidFailLoad(const ResourceError& err)
805 {
806     if (!shouldFallBack(err))
807         return;
808
809     m_loadError = err;
810     ewk_frame_load_error(m_frame,
811                          m_loadError.domain().utf8().data(),
812                          m_loadError.errorCode(), m_loadError.isCancellation(),
813                          m_loadError.localizedDescription().utf8().data(),
814                          m_loadError.failingURL().utf8().data());
815 }
816
817 void FrameLoaderClientEfl::download(ResourceHandle*, const ResourceRequest& request, const ResourceRequest&, const ResourceResponse&)
818 {
819     if (!m_view)
820         return;
821
822     CString url = request.url().string().utf8();
823     Ewk_Download download;
824
825     download.url = url.data();
826     ewk_view_download_request(m_view, &download);
827 }
828
829 // copied from WebKit/Misc/WebKitErrors[Private].h
830 enum {
831     WebKitErrorCannotShowMIMEType = 100,
832     WebKitErrorCannotShowURL = 101,
833     WebKitErrorFrameLoadInterruptedByPolicyChange = 102,
834     WebKitErrorCannotUseRestrictedPort = 103,
835     WebKitErrorCannotFindPlugIn = 200,
836     WebKitErrorCannotLoadPlugIn = 201,
837     WebKitErrorJavaUnavailable = 202,
838 };
839
840 ResourceError FrameLoaderClientEfl::cancelledError(const ResourceRequest& request)
841 {
842     ResourceError error("Error", -999, request.url().string(),
843                         "Request cancelled");
844     error.setIsCancellation(true);
845     return error;
846 }
847
848 ResourceError FrameLoaderClientEfl::blockedError(const ResourceRequest& request)
849 {
850     return ResourceError("Error", WebKitErrorCannotUseRestrictedPort, request.url().string(),
851                          "Request blocked");
852 }
853
854 ResourceError FrameLoaderClientEfl::cannotShowURLError(const ResourceRequest& request)
855 {
856     return ResourceError("Error", WebKitErrorCannotShowURL, request.url().string(),
857                          "Cannot show URL");
858 }
859
860 ResourceError FrameLoaderClientEfl::interruptedForPolicyChangeError(const ResourceRequest& request)
861 {
862     return ResourceError("Error", WebKitErrorFrameLoadInterruptedByPolicyChange,
863                          request.url().string(), "Frame load interrupted by policy change");
864 }
865
866 ResourceError FrameLoaderClientEfl::cannotShowMIMETypeError(const ResourceResponse& response)
867 {
868     return ResourceError("Error", WebKitErrorCannotShowMIMEType, response.url().string(),
869                          "Cannot show mimetype");
870 }
871
872 ResourceError FrameLoaderClientEfl::fileDoesNotExistError(const ResourceResponse& response)
873 {
874     return ResourceError("Error", -998 /* ### */, response.url().string(),
875                          "File does not exist");
876 }
877
878 ResourceError FrameLoaderClientEfl::pluginWillHandleLoadError(const ResourceResponse&)
879 {
880     notImplemented();
881     return ResourceError("Error", 0, "", "");
882 }
883
884 bool FrameLoaderClientEfl::shouldFallBack(const ResourceError& error)
885 {
886     return !(error.isCancellation() || (error.errorCode() == WebKitErrorFrameLoadInterruptedByPolicyChange));
887 }
888
889 bool FrameLoaderClientEfl::canCachePage() const
890 {
891     return false;
892 }
893
894 Frame* FrameLoaderClientEfl::dispatchCreatePage(const NavigationAction&)
895 {
896     if (!m_view)
897         return 0;
898
899     Evas_Object* newView = ewk_view_window_create(m_view, EINA_FALSE, 0);
900     Evas_Object* mainFrame;
901     if (!newView)
902         mainFrame = m_frame;
903     else
904         mainFrame = ewk_view_frame_main_get(newView);
905
906     return ewk_frame_core_get(mainFrame);
907 }
908
909 void FrameLoaderClientEfl::dispatchUnableToImplementPolicy(const ResourceError&)
910 {
911     notImplemented();
912 }
913
914 void FrameLoaderClientEfl::setMainDocumentError(DocumentLoader* loader, const ResourceError& error)
915 {
916     if (!m_pluginView)
917         return;
918     m_pluginView->didFail(error);
919     m_pluginView = 0;
920     m_hasSentResponseToPlugin = false;
921 }
922
923 void FrameLoaderClientEfl::startDownload(const ResourceRequest& request, const String& /* suggestedName */)
924 {
925     if (!m_view)
926         return;
927
928     CString url = request.url().string().utf8();
929     Ewk_Download download;
930
931     download.url = url.data();
932     ewk_view_download_request(m_view, &download);
933 }
934
935 void FrameLoaderClientEfl::updateGlobalHistory()
936 {
937     notImplemented();
938 }
939
940 void FrameLoaderClientEfl::savePlatformDataToCachedFrame(CachedFrame*)
941 {
942     notImplemented();
943 }
944
945 void FrameLoaderClientEfl::transitionToCommittedFromCachedFrame(CachedFrame*)
946 {
947 }
948
949 void FrameLoaderClientEfl::transitionToCommittedForNewPage()
950 {
951     ASSERT(m_frame);
952     ASSERT(m_view);
953
954     ewk_frame_view_create_for_view(m_frame, m_view);
955
956     if (m_frame == ewk_view_frame_main_get(m_view))
957         ewk_view_frame_main_cleared(m_view);
958 }
959
960 void FrameLoaderClientEfl::didSaveToPageCache()
961 {
962 }
963
964 void FrameLoaderClientEfl::didRestoreFromPageCache()
965 {
966 }
967
968 void FrameLoaderClientEfl::dispatchDidBecomeFrameset(bool)
969 {
970 }
971
972 PassRefPtr<FrameNetworkingContext> FrameLoaderClientEfl::createNetworkingContext()
973 {
974     return FrameNetworkingContextEfl::create(ewk_frame_core_get(m_frame));
975 }
976
977 }