Bug fix for shouldStartLoading method, should return value from JS, also fix that webview callback is already in Cocos Thread, don't need to post to cocos thread for running again.

This commit is contained in:
James Chen 2015-12-09 22:40:57 +08:00
parent e1656264fc
commit 65eb5fa4ba
1 changed files with 53 additions and 65 deletions

View File

@ -20,24 +20,21 @@ static bool jsb_cocos2dx_experimental_webView_setOnShouldStartLoading(JSContext
if(argc == 1){ if(argc == 1){
std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, obj, args.get(0))); std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, obj, args.get(0)));
cobj->setOnShouldStartLoading([=](experimental::ui::WebView *sender, const std::string &url)->bool{ cobj->setOnShouldStartLoading([=](experimental::ui::WebView *sender, const std::string &url)->bool{
Director::getInstance()->getScheduler()->performFunctionInCocosThread([=] JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
{ jsval arg[2];
JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET js_proxy_t *proxy = js_get_or_create_proxy(cx, sender);
jsval arg[2]; if(proxy)
js_proxy_t *proxy = js_get_or_create_proxy(cx, sender); arg[0] = OBJECT_TO_JSVAL(proxy->obj);
if(proxy) else
arg[0] = OBJECT_TO_JSVAL(proxy->obj); arg[0] = JSVAL_NULL;
else arg[1] = std_string_to_jsval(cx, url);
arg[0] = JSVAL_NULL; JS::RootedValue rval(cx);
arg[1] = std_string_to_jsval(cx, url);
JS::RootedValue rval(cx);
bool ok = func->invoke(2, arg, &rval); bool ok = func->invoke(2, arg, &rval);
if (!ok && JS_IsExceptionPending(cx)) { if (!ok && JS_IsExceptionPending(cx)) {
JS_ReportPendingException(cx); JS_ReportPendingException(cx);
} }
}); return rval.toBoolean();
return true;
}); });
return true; return true;
} }
@ -54,23 +51,20 @@ static bool jsb_cocos2dx_experimental_webView_setOnDidFinishLoading(JSContext *c
if(argc == 1){ if(argc == 1){
std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, obj, args.get(0))); std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, obj, args.get(0)));
cobj->setOnDidFinishLoading([=](experimental::ui::WebView *sender, const std::string &url)->void{ cobj->setOnDidFinishLoading([=](experimental::ui::WebView *sender, const std::string &url)->void{
Director::getInstance()->getScheduler()->performFunctionInCocosThread([=] JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
{ jsval arg[2];
JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET js_proxy_t *proxy = js_get_or_create_proxy(cx, sender);
jsval arg[2]; if(proxy)
js_proxy_t *proxy = js_get_or_create_proxy(cx, sender); arg[0] = OBJECT_TO_JSVAL(proxy->obj);
if(proxy) else
arg[0] = OBJECT_TO_JSVAL(proxy->obj); arg[0] = JSVAL_NULL;
else arg[1] = std_string_to_jsval(cx, url);
arg[0] = JSVAL_NULL; JS::RootedValue rval(cx);
arg[1] = std_string_to_jsval(cx, url);
JS::RootedValue rval(cx);
bool ok = func->invoke(2, arg, &rval); bool ok = func->invoke(2, arg, &rval);
if (!ok && JS_IsExceptionPending(cx)) { if (!ok && JS_IsExceptionPending(cx)) {
JS_ReportPendingException(cx); JS_ReportPendingException(cx);
} }
});
}); });
return true; return true;
} }
@ -87,23 +81,20 @@ static bool jsb_cocos2dx_experimental_webView_setOnDidFailLoading(JSContext *cx,
if(argc == 1){ if(argc == 1){
std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, obj, args.get(0))); std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, obj, args.get(0)));
cobj->setOnDidFailLoading([=](experimental::ui::WebView *sender, const std::string &url)->void{ cobj->setOnDidFailLoading([=](experimental::ui::WebView *sender, const std::string &url)->void{
Director::getInstance()->getScheduler()->performFunctionInCocosThread([=] JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
{ jsval arg[2];
JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET js_proxy_t *proxy = js_get_or_create_proxy(cx, sender);
jsval arg[2]; if(proxy)
js_proxy_t *proxy = js_get_or_create_proxy(cx, sender); arg[0] = OBJECT_TO_JSVAL(proxy->obj);
if(proxy) else
arg[0] = OBJECT_TO_JSVAL(proxy->obj); arg[0] = JSVAL_NULL;
else arg[1] = std_string_to_jsval(cx, url);
arg[0] = JSVAL_NULL; JS::RootedValue rval(cx);
arg[1] = std_string_to_jsval(cx, url);
JS::RootedValue rval(cx);
bool ok = func->invoke(2, arg, &rval); bool ok = func->invoke(2, arg, &rval);
if (!ok && JS_IsExceptionPending(cx)) { if (!ok && JS_IsExceptionPending(cx)) {
JS_ReportPendingException(cx); JS_ReportPendingException(cx);
} }
});
}); });
return true; return true;
} }
@ -120,23 +111,20 @@ static bool jsb_cocos2dx_experimental_webView_setOnJSCallback(JSContext *cx, uin
if(argc == 1){ if(argc == 1){
std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, obj, args.get(0))); std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, obj, args.get(0)));
cobj->setOnJSCallback([=](experimental::ui::WebView *sender, const std::string &url)->void{ cobj->setOnJSCallback([=](experimental::ui::WebView *sender, const std::string &url)->void{
Director::getInstance()->getScheduler()->performFunctionInCocosThread([=] JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
{ jsval arg[2];
JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET js_proxy_t *proxy = js_get_or_create_proxy(cx, sender);
jsval arg[2]; if(proxy)
js_proxy_t *proxy = js_get_or_create_proxy(cx, sender); arg[0] = OBJECT_TO_JSVAL(proxy->obj);
if(proxy) else
arg[0] = OBJECT_TO_JSVAL(proxy->obj); arg[0] = JSVAL_NULL;
else arg[1] = std_string_to_jsval(cx, url);
arg[0] = JSVAL_NULL; JS::RootedValue rval(cx);
arg[1] = std_string_to_jsval(cx, url);
JS::RootedValue rval(cx);
bool ok = func->invoke(2, arg, &rval); bool ok = func->invoke(2, arg, &rval);
if (!ok && JS_IsExceptionPending(cx)) { if (!ok && JS_IsExceptionPending(cx)) {
JS_ReportPendingException(cx); JS_ReportPendingException(cx);
} }
});
}); });
return true; return true;
} }