bool DisplayHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser, const CefString& message, const CefString& source, int line)
{
	if (GetCallback())
	{
		CefStringUTF8 m(ConvertToUtf8(message));
		CefStringUTF8 s(ConvertToUtf8(source));
		GetCallback()->onLogConsoleMsg(m.c_str(), s.c_str(), line);
	}
		
	return true;
}
bool LifeSpanHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
                                    CefRefPtr<CefFrame> frame,
                                    const CefString& target_url,
                                    const CefString& target_frame_name,
                                    const CefPopupFeatures& popupFeatures,
                                    CefWindowInfo& windowInfo,
                                    CefRefPtr<CefClient>& client,
                                    CefBrowserSettings& settings,
                                    bool* no_javascript_access)
{
	//dont show popups unless its the inspector
	CefStringUTF8 t(ConvertToUtf8(target_url));

	cef3Trace("Url: %s", t.c_str());

	if (!t.empty() && std::string(t.c_str()).find("resources/inspector/devtools.") != std::string::npos)
		return false;

	if (GetCallbackV2())
	{
		if (GetCallbackV2()->onNewWindowUrl(t.c_str()))
			GetBrowser()->GetMainFrame()->LoadURL(target_url);
	}
	else
	{
		if (GetCallback()->onNavigateUrl(t.c_str(), true))
			GetBrowser()->GetMainFrame()->LoadURL(target_url);
	}
	
	return true;
}
bool JSDialogHandler::OnJSDialog(CefRefPtr<CefBrowser> browser,
	const CefString& origin_url,
	const CefString& accept_lang,
	JSDialogType dialog_type,
	const CefString& message_text,
	const CefString& default_prompt_text,
	CefRefPtr<CefJSDialogCallback> callback,
	bool& suppress_message)
{
	if (!GetCallback())
		return false;

	char resultBuff[255] = { 0 };
	bool success = false;
	bool res = false;

	CefStringUTF8 m(ConvertToUtf8(message_text));

	if (dialog_type == JSDIALOGTYPE_ALERT)
	{
		res = GetCallback()->onJScriptAlert(m.c_str());
		success = true;
	}
	else if (dialog_type == JSDIALOGTYPE_CONFIRM)
	{
		res = GetCallback()->onJScriptConfirm(m.c_str(), &success);
	}
	else if (dialog_type == JSDIALOGTYPE_PROMPT)
	{
		CefStringUTF8 d(ConvertToUtf8(default_prompt_text));
		res = GetCallback()->onJScriptPrompt(m.c_str(), d.c_str(), &success, resultBuff);
	}

	if (res)
		callback->Continue(success, resultBuff);

	return res;
}
Example #4
0
/**
 * Test the boundaries of the Utf8 strings.
 */
void Utf8Test::testUtf8()
{
	TU_INIT_TESTCASE("testUtf8");

	// Construct a wide string with characters big enough to need multiple bytes.
	//                                                = Is UTF8 leading bits
	//                                                - Is the actual character
	const wchar_t wchars[] = 
	{
		L'\x41',	//  7 bits = 1 byte UTF8 =                     0100 0001 = 0x41
					//                                             =--- ----
		L'\x81',	//  8 bits = 2 byte UTF8 =           1100 0010 1000 0001 = 0xC2 81
					//                                   ===- ---- ==-- ----
		L'\x401', 	// 11 bits = 2 byte UTF8 =           1101 0000 1000 0001 = 0xD0 81 
					//                                   ===- ---- ==-- ----
		L'\x801',	// 12 bits = 3 byte UTF8 = 1110 0000 1010 0000 1000 0001 = 0xE0 A0 81
					//                         ==== ---- ==-- ---- ==-- ----
		L'\x8001',  // 16 bits = 3 byte UTF8 = 1110 1000 1000 0000 1000 0001 = 0xE8 80 81 
					//                         ==== ---- ==-- ---- ==-- ----
		L'\x44',    //  7 bits = 1 byte UTF8 =                     0100 0100 = 0x44
					//                                             =--- ---- 
		L'\x00'     //                       =                     0000 0000 = 0x00 
					//                                             =--- ----
	};

	wstring wstr;
	wstr.assign(wchars,wcslen(wchars));


	// Construct a UTF8 string that is equivalent to the above.
	const char chars[] = 
	{ 
		'\x41', '\xc2', '\x81', '\xd0', '\x81', '\xe0', '\xa0', 
		'\x81', '\xe8', '\x80', '\x81', '\x44', '\x00'
	};

	string str;
	str.assign(chars,strlen(chars));

	// Generate a new UTF8 string fromt the wide string
	string new_str = ConvertToUtf8(wstr);

	// Compare the two UTF8 strings.
	CPPUNIT_ASSERT(new_str == str);
}
Example #5
0
void MyFrame::OnTools(wxCommandEvent& event)
{//=========================================
	int err;
	FILE *log;
	int debug_flag=0;
	char fname_log[sizeof(path_dsource)+12];
	char err_fname[sizeof(path_home)+15];

	switch(event.GetId())
	{
	case MENU_TEST:
		TestTest(0);
		break;

	case MENU_TEST2:
		TestTest(2);
		break;

	case MENU_TO_UTF8:
		ConvertToUtf8();
		break;

	case MENU_COUNT_WORDS:
		MakeWordFreqList();
		break;

	case MENU_LEXICON_RU:
	case MENU_LEXICON_BG:
	case MENU_LEXICON_DE:
	case MENU_LEXICON_IT:
	case MENU_LEXICON_TEST:
		CompareLexicon(event.GetId());  // Compare a lexicon with _rules translation
		break;

	case MENU_COMPILE_PH:
		CompilePhonemeData();
		SetVoiceTitle(voice_name2);
		break;

	case MENU_COMPILE_PH2:
		CompileSampleRate();
		SetVoiceTitle(voice_name2);
		break;

	case MENU_COMPILE_MBROLA:
		CompileMbrola();
		break;

	case MENU_COMPILE_INTONATION:
		CompileIntonation();
		break;

	case MENU_COMPILE_DICT_DEBUG:
		debug_flag =1;  // and drop through to next case
	case MENU_COMPILE_DICT:
		sprintf(fname_log,"%s%s",path_dsource,"dict_log");
		log = fopen(fname_log,"w");

		LoadDictionary(translator, translator->dictionary_name, 0);
		if((err = CompileDictionary(path_dsource,translator->dictionary_name,log,err_fname,debug_flag)) < 0)
		{
			wxLogError(_T("Can't access file:\n")+wxString(err_fname,wxConvLocal));

			wxString dir = wxDirSelector(_T("Directory containing dictionary files"),path_dictsource);
			if(!dir.IsEmpty())
			{
				path_dictsource = dir;
				strncpy0(path_dsource,path_dictsource.mb_str(wxConvLocal),sizeof(path_dsource)-1);
				strcat(path_dsource,"/");
			}
			break;
		}
		wxLogStatus(_T("Compiled '")+wxString(dictionary_name,wxConvLocal)+_T("', %d errors"),err);

		if(log != NULL)
		{
			fclose(log);

			if(err > 0)
			{
				// display the error messages
				DisplayErrorFile(fname_log);
			}
		}
		break;

	case MENU_FORMAT_DICTIONARY:
		DictionaryFormat(dictionary_name);
		break;

	case MENU_SORT_DICTIONARY:
		DictionarySort(dictionary_name);
		break;

	case MENU_VOWELCHART1:
		MakeVowelLists();
		break;

	case MENU_VOWELCHART2:
		VowelChart(2,NULL);
		break;

	case MENU_VOWELCHART3:
		VowelChart(3,NULL);
		break;

	case MENU_LOAD_WAV:
//		LoadWavFile();
		break;
	}
}
Example #6
0
const char* TiXmlElement::ReadValue( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
{
	TiXmlDocument* document = GetDocument();
	// Read in text and elements in any order.
	const char* pWithWhiteSpace = p;
	p = SkipWhiteSpace( p, encoding );

	while ( p && *p )
	{
		if ( *p != '<' )
		{
			// Take what we have, make a text element.
			TiXmlText* textNode = new TiXmlText( "" );

			if ( !textNode )
			{
				if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, encoding );
				    return 0;
			}

			if ( TiXmlBase::IsWhiteSpaceCondensed() )
			{
				p = textNode->Parse( p, data, encoding );
			}
			else
			{
				// Special case: we want to keep the white space
				// so that leading spaces aren't removed.
				p = textNode->Parse( pWithWhiteSpace, data, encoding );
			}

			if ( !textNode->Blank() )
			{
				LinkEndChild( textNode );
#ifdef HAS_ICONV
        ConvertToUtf8(document, &textNode->value);
#endif    				
			}
			else
				delete textNode;
		} 
		else 
		{
			// We hit a '<'
			// Have we hit a new element or an end tag? This could also be
			// a TiXmlText in the "CDATA" style.
			if ( StringEqual( p, "</", false, encoding ) )
			{
				return p;
			}
			else
			{
				TiXmlNode* node = Identify( p, encoding );
				if ( node )
				{
					p = node->Parse( p, data, encoding );
					LinkEndChild( node );
				}				
				else
				{
					return 0;
				}
			}
		}
		pWithWhiteSpace = p;
		p = SkipWhiteSpace( p, encoding );
	}

	if ( !p )
	{
		if ( document ) document->SetError( TIXML_ERROR_READING_ELEMENT_VALUE, 0, 0, encoding );
	}	
	return p;
}
Example #7
0
static bool SendAsUtf8(FSocket* Conn, const FString& Message)
{
	FTCHARToUTF8 ConvertToUtf8(*Message);
	int32 BytesSent = 0;
	return Conn->Send(reinterpret_cast<const uint8*>(ConvertToUtf8.Get()), ConvertToUtf8.Length(), BytesSent) && BytesSent == ConvertToUtf8.Length();
}
void LoadHandler::OnLoadError(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, ErrorCode errorCode, const CefString& errorText, const CefString& failedUrl)
{
	if (errorCode == ERR_ABORTED)
		return;

	std::string errorMsg;
	std::map<int, std::string>::iterator it = g_mErrorMsgMap.find(errorCode);
	
	CefStringUTF8 strUrl = ConvertToUtf8(failedUrl);
	CefStringUTF8 et = ConvertToUtf8(errorText);
	cef3Trace("ErrId: %d, ErrMsg: [%s], Url: [%s]", errorCode, et.c_str(), strUrl.c_str());

	if (it != g_mErrorMsgMap.end())
	{
		std::stringstream stream;
		stream << g_mErrorMsgMap[errorCode] << " [" << errorCode << "]";
		errorMsg = stream.str();
	}
	else
	{
		std::stringstream stream;
		stream << "Error Code " << errorCode;
		errorMsg = stream.str();
	}

	std::string out;

	//if no frame its the whole page
	if (GetCallback())
	{
		const size_t size = 100*1024;
		char buff[size];
		buff[0] = 0;

		if (GetCallback()->onLoadError(errorMsg.c_str(), strUrl.c_str(), buff, size) && buff[0])
		{
			size_t nSize = strlen(buff);

			if (nSize > size)
				nSize = size;

			out = std::string(buff, nSize);
		}
	}

	if (out.empty())
	{
		// All other messages.
		std::stringstream ss;
		ss << "<html><head><title>Load Failed</title></head>"
			"<body><h1>Load Failed</h1>"
			"<h2>Load of URL " << strUrl.c_str() <<
			" failed: " << errorMsg <<
			".</h2></body>"
			"</html>";

		out = ss.str();
	}

	CefRefPtr<CefPostData> postData = CefPostData::Create();

	CefRefPtr<CefPostDataElement> el = CefPostDataElement::Create();
	el->SetToBytes(out.size(), out.c_str());

	postData->AddElement(el);

	CefRefPtr<CefRequest> req = CefRequest::Create();
	req->SetMethod("POST");
	req->SetURL("internal://loaderror");
	req->SetPostData(postData);
	frame->LoadRequest(req);
}