2 * Copyright (C) 2015 Ryuan Choi <ryuan.choi@gmail.com>. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
30 #include "WKBundleAPICast.h"
31 #include "WKBundleFrame.h"
34 #include "ewk_page_private.h"
36 using namespace WebKit;
38 static inline EwkPage* toEwkPage(const void* clientInfo)
40 return const_cast<EwkPage*>(static_cast<const EwkPage*>(clientInfo));
43 EwkPage::EwkPage(WebPage* page)
46 WKBundlePageLoaderClientV7 loaderClient = {
51 0, // didStartProvisionalLoadForFrame,
52 0, // didReceiveServerRedirectForProvisionalLoadForFrame,
53 0, // didFailProvisionalLoadWithErrorForFrame
54 0, // didCommitLoadForFrame
55 didFinishDocumentLoadForFrame,
56 0, // didFinishLoadForFrame
57 0, // didFailLoadWithErrorForFrame
58 0, // didSameDocumentNavigationForFrame,
59 0, // didReceiveTitleForFrame
60 0, // didFirstLayoutForFrame
61 0, // didFirstVisuallyNonEmptyLayoutForFrame
62 0, // didRemoveFrameFromHierarchy
63 0, // didDisplayInsecureContentForFrame
64 0, // didRunInsecureContentForFrame
65 0, // didClearWindowObjectForFrame,
66 0, // didCancelClientRedirectForFrame
67 0, // willPerformClientRedirectForFrame
68 0, // didHandleOnloadEventsForFrame
69 0, // didLayoutForFrame
70 0, // didNewFirstVisuallyNonEmptyLayout
71 0, // didDetectXSSForFrame
72 0, // shouldGoToBackForwardListItem
73 0, // globalObjectIsAvailableForFrame
74 0, // willDisconnectDOMWindowExtensionFromGlobalObject
75 0, // didReconnectDOMWindowExtensionToGlobalObject
76 0, // willDestroyGlobalObjectForDOMWindowExtension
77 0, // didFinishProgress
78 0, // shouldForceUniversalAccessFromLocalURL
79 0, // didReceiveIntentForFrame_unavailable
80 0, // registerIntentServiceForFrame_unavailable
82 0, // featuresUsedInPage
83 0, // willLoadURLRequest
84 0, // willLoadDataRequest
87 WKBundlePageSetPageLoaderClient(toAPI(page), &loaderClient.base);
90 void EwkPage::append(const Ewk_Page_Client* client)
92 m_clients.append(client);
95 void EwkPage::remove(const Ewk_Page_Client* client)
97 m_clients.remove(m_clients.find(client));
100 void EwkPage::didFinishDocumentLoadForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKTypeRef*, const void* clientInfo)
102 if (!WKBundleFrameIsMainFrame(frame))
105 EwkPage* self = toEwkPage(clientInfo);
106 for (auto& it : self->m_clients) {
107 if (it->load_finished)
108 it->load_finished(self, it->data);
112 JSGlobalContextRef ewk_page_js_global_context_get(const Ewk_Page* ewkPage)
114 EINA_SAFETY_ON_NULL_RETURN_VAL(ewkPage, nullptr);
116 WebFrame* coreFrame = ewkPage->page()->mainWebFrame();
120 return coreFrame->jsContext();
123 void ewk_page_client_register(Ewk_Page* ewkPage, const Ewk_Page_Client* client)
125 EINA_SAFETY_ON_NULL_RETURN(ewkPage);
126 EINA_SAFETY_ON_NULL_RETURN(client);
128 ewkPage->append(client);
131 void ewk_page_client_unregister(Ewk_Page* ewkPage, const Ewk_Page_Client* client)
133 EINA_SAFETY_ON_NULL_RETURN(ewkPage);
134 EINA_SAFETY_ON_NULL_RETURN(client);
136 ewkPage->remove(client);