void browser::onJavascriptCallback( Berkelium::Window* win, void* reply_msg, Berkelium::URLString origin, Berkelium::WideString func_name, Berkelium::Script::Variant* args, size_t num_args ) { sf::Mutex mtx; mtx.lock(); { #ifdef BROWSER_USE_EXCEPTIONS try #endif { last_callback_window = instances.at( win ); } #ifdef BROWSER_USE_EXCEPTIONS catch( ... ) { } #endif std::wstring func( func_name.data(), func_name.length() ); if( num_args > 0 ) { handle_callbacks( func, args ); } else handle_callbacks( func, 0 ); } mtx.unlock(); }
void ofxBerkelium::onScriptAlert(Berkelium::Window *win, Berkelium::WideString message, Berkelium::WideString defaultValue, Berkelium::URLString url, int flags, bool &success, Berkelium::WideString &value) { status = wstring2string( message.data() ); if(listener) listener->onScriptAlert(message.data(), defaultValue.data(), url.data(), flags, success, value.data()); }
void UnityBerkeliumWindow::onExternalHost(Berkelium::Window *win, Berkelium::WideString message, Berkelium::URLString origin, Berkelium::URLString target) { cerr << "[UnityBerkeliumWindow] onExternalHost called (window: " << win << ")" << endl; wcerr << " message: " << message << endl; cerr << " origin: " << origin << endl; cerr << " target: " << target << endl; if(m_externalHostFunc) { m_lastExternalHostMessage = std::wstring(message.data(), message.length()); m_externalHostFunc(message.data()); } }
//============================================================================================== virtual void onConsoleMessage( Berkelium::Window * win, Berkelium::WideString message, Berkelium::WideString sourceId, int line_no) { printf("console.log: %ls\n", message.data() ); }
void browser::onConsoleMessage( Berkelium::Window* win, Berkelium::WideString message, Berkelium::WideString sourceId, int line_no ) { std::wstring content( message.data(), message.length() ); std::wcout << L"Line " << line_no << ": " << content << std::endl; }
void browser::onScriptAlert( Berkelium::Window* win, Berkelium::WideString message, Berkelium::WideString defaultValue, Berkelium::URLString url, int flags, bool& success, Berkelium::WideString& value ) { std::wstring content( message.data(), message.length() ); std::wcout << content << std::endl; }
//============================================================================================== virtual void onExternalHost( Berkelium::Window *win, Berkelium::WideString message, Berkelium::URLString origin, Berkelium::URLString target) { //someone thought it would be a good idea to use wchar_t. It wasn't. //apparently it's chromium's fault char * cstr = new char[ message.length()+1 ]; std::string * msg = 0; const wchar_t * wmsg = message.data(); //we only expect ascii characters, this assupmtion will get us into trouble eventually for( int i = 0; i < message.length(); i++) { cstr[i] = (char)wmsg[i]; } msg = new std::string( cstr, message.length() ); // this->m_uiSignal->emit( msg ); }
void ofxBerkelium::onExternalHost(Berkelium::Window *win, Berkelium::WideString message, Berkelium::URLString origin, Berkelium::URLString target) { if(listener) listener->onExternalHost(message.data(), origin.data(), target.data()); }
void ofxBerkelium::onJavascriptCallback(Berkelium::Window *win, void* replyMsg, Berkelium::URLString url, Berkelium::WideString funcName, Berkelium::Script::Variant *args, size_t numArgs) { if(listener) listener->onJavascriptCallback(replyMsg, url.data(), funcName.data(), args, numArgs); }
void ofxBerkelium::onTooltipChanged(Berkelium::Window *win, Berkelium::WideString text) { status = wstring2string( text.data() ); if(listener) listener->onTooltipChanged(text.data()); }
void ofxBerkelium::onTitleChanged(Berkelium::Window *win, Berkelium::WideString _title) { title = wstring2string( _title.data() ); if(listener) listener->onTitleChanged(_title.data()); }
void ofxBerkelium::onConsoleMessage(Berkelium::Window *win, Berkelium::WideString message, Berkelium::WideString sourceId, int line_no) { status = wstring2string(message.data()); if(listener) listener->onConsoleMessage(message.data(), sourceId.data(), line_no); }
void ofxBerkelium::onCrashedPlugin(Berkelium::Window *win, Berkelium::WideString pluginName) { if(listener) listener->onCrashedPlugin(pluginName.data()); }
void HTML::WidestringToWString(const Berkelium::WideString& wstr, std::wstring& str) { str = std::wstring(wstr.data()); str.resize(wstr.length()); }
void JSObject::Fill(Berkelium::WideString str) { using namespace rapidjson; children.clear(); /** {Test} Berkelium::WideString <-> std::string, std::wstring */ /* Berkelium::UTF8String utf8str = Berkelium::WideToUTF8(str); std::string cstr = Berkelium::WideToUTF8(str).data(); cstr.resize(str.length()); std::wstring wstr = str.data(); wstr.resize(str.length()); // convert back from ctr Berkelium::WideString w1 = Berkelium::UTF8ToWide( Berkelium::UTF8String::point_to(cstr) ); // convert back from utf8str Berkelium::WideString w2 = Berkelium::UTF8ToWide( utf8str ); // wstring -> WideString [this must be correct one] Berkelium::WideString w3 = Berkelium::WideString::point_to(wstr.c_str()); */ if(!str.length()) { value.str = L""; value.type = JSTypeString; return; } std::wstring wstr = str.data(); wstr.resize(str.length()); GenericDocument<UTF8<wchar_t>> d; d.Parse<0>(wstr.c_str()); if(d.HasParseError()) { value.str = wstr; value.type = JSTypeString; return; } switch(d.GetType()) { case kNullType: //!< null value = JSValue(); break; case kFalseType: //!< false value = JSValue(false); break; case kTrueType: //!< true value = JSValue(true); break; case kObjectType: //!< object value.type = JSTypeObject; for(GenericValue<UTF8<wchar_t>>::ConstMemberIterator itr = d.MemberBegin(); itr != d.MemberEnd(); ++itr) { children.push_back(std::make_pair(itr->name.GetString(), JSObject())); children.back().second.FillRecursive(itr->value); } break; case kArrayType: //!< array value.type = JSTypeObject; children.resize(d.Size()); for(SizeType i = 0; i < d.Size(); i++) { children[i].second.FillRecursive(d[i]); } break; case kStringType: //!< string value.str = wstr; value.type = JSTypeString; break; case kNumberType: //!< number value = JSValue(d.GetDouble()); break; } }