2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file AppBoxRenderView.cpp
18 * @author Yunchan Cho (yunchan.cho@samsung.com)
24 #include <livebox-service.h>
25 #include <i_runnable_widget_object.h>
26 #include <core_module.h>
27 #include <dpl/fast_delegate.h>
28 #include <Core/View/IRenderView.h>
29 #include <Core/View/IPdHelper.h>
30 #include <Core/View/PdHelper.h>
31 #include <Core/Util/Log.h>
32 #include "AppBoxObserver.h"
33 #include "AppBoxRenderBuffer.h"
34 #include "AppBoxRenderView.h"
36 #define RENDER_MAX_TIME 10.0
38 AppBoxRenderView::AppBoxRenderView(
39 std::string boxId, std::string instanceId,
40 Evas_Object* boxWin, EwkContextPtr ewkContext)
43 , m_instanceId(instanceId)
51 , m_ewkContext(ewkContext)
54 m_appId = getAppId(m_boxId);
55 if (m_appId.empty()) {
56 throw; //exception throw!
59 evas_object_show(m_boxWin);
60 m_renderBuffer = AppBoxObserver::Instance()->getRenderBuffer(m_instanceId);
61 AppBoxObserver::Instance()->registerRenderView(m_instanceId, this);
64 AppBoxRenderView::~AppBoxRenderView()
67 evas_object_hide(m_boxWin);
68 AppBoxObserver::Instance()->unregisterRenderView(m_instanceId);
71 void AppBoxRenderView::showBox(RenderInfoPtr renderInfo)
75 // delete already running timer
79 if (livebox_service_mouse_event(m_boxId.c_str())) {
80 m_renderBuffer->deleteTouchTimer();
84 m_startUrl = getStartUrl(URL_TYPE_BOX, renderInfo->defaultUrlParams);
87 LogD("can't create view instance");
91 // in case of showing box by request of pd open
93 m_pdHelper->setBaseWebView(m_baseWebView);
96 // resize webview fitted to width, height of Box
103 m_renderInfo = renderInfo;
106 bool AppBoxRenderView::createView()
113 m_baseWebView = NULL;
116 m_view = WRT::CoreModuleSingleton::
117 Instance().getRunnableWidgetObject(m_appId);
120 if (m_startUrl.empty()) {
121 LogD("no start url");
124 m_view->PrepareView(m_startUrl, m_boxWin, m_ewkContext.get());
125 m_view->CheckBeforeLaunch();
127 // set callback functions of RunnableWidgetObject
128 WRT::UserDelegatesPtr cbs(new WRT::UserDelegates);
129 cbs->loadStart = DPL::MakeDelegate(this, &AppBoxRenderView::startLoadCallback);
130 cbs->loadFinish = DPL::MakeDelegate(this, &AppBoxRenderView::finishLoadCallback);
131 cbs->bufferSet = DPL::MakeDelegate(this, &AppBoxRenderView::setBufferCallback);
132 cbs->bufferUnset = DPL::MakeDelegate(this, &AppBoxRenderView::unsetBufferCallback);
133 cbs->windowCreateBefore = DPL::MakeDelegate(this, &AppBoxRenderView::createWindowBeforeCallback);
134 cbs->windowCreateAfter = DPL::MakeDelegate(this, &AppBoxRenderView::createWindowAfterCallback);
135 m_view->SetUserDelegates(cbs);
138 m_baseWebView = m_view->GetCurrentWebview();
139 m_renderBuffer->startCanvasUpdate();
143 bool AppBoxRenderView::destroyView()
147 m_renderBuffer->stopCanvasUpdate();
148 ecore_idler_add(destroyViewIdlerCallback, this);
152 void AppBoxRenderView::hideBox()
158 void AppBoxRenderView::pauseBox()
163 void AppBoxRenderView::resumeBox()
168 void AppBoxRenderView::showPd(Evas_Object* pdWin, RenderInfoPtr renderInfo)
173 std::string pdStartUrl = getStartUrl(URL_TYPE_PD, renderInfo->defaultUrlParams);
174 m_pdHelper = PdHelper::create(pdWin, pdStartUrl, renderInfo);
177 evas_object_show(pdWin);
178 showBox(m_renderInfo);
181 void AppBoxRenderView::hidePd()
188 // destory box webview to stop rendering
192 std::string AppBoxRenderView::getAppId(std::string& boxId)
194 // TODO more exact and safe parsing is needed
195 std::string temp = std::string(boxId);
196 int found = temp.find_last_of(".");
197 if (found == std::string::npos) {
198 return std::string();
201 temp.assign(temp, 0, found);
205 std::string AppBoxRenderView::getStartUrl(UrlType type, std::string& defaultParams)
210 url = livebox_service_lb_script_path(m_boxId.c_str());
213 url = livebox_service_pd_script_path(m_boxId.c_str());
216 LogD("no available type");
219 // add default parameters to start url
220 url += defaultParams;
225 void AppBoxRenderView::addRenderTimer()
228 if (m_fireRenderTimer) {
232 m_fireRenderTimer = ecore_timer_add(
234 fireRenderTimerCallback,
238 void AppBoxRenderView::deleteRenderTimer()
241 if (m_fireRenderTimer) {
242 ecore_timer_del(m_fireRenderTimer);
243 m_fireRenderTimer = NULL;
247 Eina_Bool AppBoxRenderView::fireRenderTimerCallback(void* data)
251 AppBoxRenderView* This = static_cast<AppBoxRenderView*>(data);
252 This->m_fireRenderTimer = NULL;
254 This->m_renderBuffer->stopCanvasUpdate();
255 if (livebox_service_mouse_event(This->m_boxId.c_str())) {
257 This->m_renderBuffer->deleteTouchTimer();
258 This->m_view->Suspend();
260 // webview should be removed
261 ecore_idler_add(destroyViewIdlerCallback, This);
264 return ECORE_CALLBACK_CANCEL;
267 Eina_Bool AppBoxRenderView::destroyViewIdlerCallback(void* data)
271 AppBoxRenderView* This = static_cast<AppBoxRenderView*>(data);
273 This->m_view->Hide();
274 This->m_view.reset();
275 This->m_baseWebView = NULL;
278 return ECORE_CALLBACK_CANCEL;
281 void AppBoxRenderView::startLoadCallback(Evas_Object* webview)
286 void AppBoxRenderView::finishLoadCallback(Evas_Object* webview)
289 ewk_view_visibility_set(webview, EINA_TRUE);
292 // start render timer
295 if (!(m_pdHelper->isPdOpened()) &&
296 webview == m_pdHelper->getBaseWebView())
298 m_pdHelper->startOpen();
303 void AppBoxRenderView::createWindowBeforeCallback(Evas** canvas, Evas_Object* parent)
308 if (!(m_pdHelper->isPdOpened()) &&
309 parent == m_pdHelper->getBaseWebView())
311 LogD("pd canvas is used");
312 *canvas = m_pdHelper->getPdCanvas();
317 LogD("canvas of this webview is used");
318 *canvas = evas_object_evas_get(parent);
321 void AppBoxRenderView::createWindowAfterCallback(Evas_Object* parent, Evas_Object* child)
326 Evas* parentCanvas = evas_object_evas_get(parent);
327 Evas* childCanvas = evas_object_evas_get(child);
329 if (parentCanvas != childCanvas) {
330 evas_object_show(parent);
331 evas_object_show(child);
332 m_pdHelper->finishOpen(child);
337 void AppBoxRenderView::setBufferCallback(Evas_Object* webview)
340 evas_object_show(webview);
341 evas_object_focus_set(webview, EINA_TRUE);
344 void AppBoxRenderView::unsetBufferCallback(Evas_Object* webview)
347 evas_object_hide(webview);