JCHub

  • Home
  • Category
    • A/V
    • WebRTC
    • Beauty of Programming
    • Linux
    • Windows
    • Moments of Life
    • Campus Life
  • Reference
    • API Reference
    • Utilities
    • AV Test
    • Doc
  • Message Board
  • About
JCHub
Code as My Sword, Lost in Obsession
  1. Main page
  2. Web
  3. Main content

FireBreath插件IE浏览器中文字符乱码问题

2019年6月3日 1439hotness 0likes 0comments

去年写过FireBreath插件的文章,那时刚到新公司,独自开发一款传统的视频播放器插件。后面基于Firebreath框架开发,支持IE以及Firefox。转眼一年多了,播放器插件已经成功部署在公司多个项目中,无论特色功能点,性能,稳定性,都达到令人满意的程度。最近一个项目要在IE11浏览器上跑,由于之前都是在Firefox上跑,IE上没怎么测过,所以在IE上跑时出现了个问题:接口传入的中文字符乱码。

播放器插件多个接口需要传入带中文字符参数,比如视频OSD水印,抓图位置以及图片水印,下载录像保存位置,下载录像添加的水印等等。Firebreath JSAPI接口支持std::string以及std:wstring两种类型的字符串,在Firefox上,相应接口参数设置为std:wstring即可满足传入参数带中文字符问题,但是IE11上却不行,传入的中文字符一直都是乱码。由于只支持这两种类型字符串,传入的都是乱码,所以插件内部怎么处理都不行,只能从外部入手了。

后面灵光闪现,想到对中文字符做处理,想到浏览器怎么对地址栏输入地址的处理。所以前端使用encodeURI函数编码传入的带中文参数,插件内部再解码即可,这样就可以顺利地传入带中文的参数。经测试,在IE与Firefox上,这种方法都正常运行。插件内部用到的UriDecode函数如下:

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const char HEX2DEC[256] =
{
/*       0  1  2  3   4  5  6  7   8  9  A  B   C  D  E  F */
/* 0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 1 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 2 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 3 */  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
 
/* 4 */ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 5 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 6 */ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 7 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 
/* 8 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 9 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* A */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* B */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 
/* C */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* D */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* E */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* F */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
 
std::string UriDecode(const std::string &src) {
// Note from RFC1630: "Sequences which start with a percent
// sign but are not followed by two hexadecimal characters
// (0-9, A-F) are reserved for future extension"
 
const unsigned char * p_src = (const unsigned char *)src.c_str();
const int SRC_LEN = src.length();
const unsigned char * const SRC_END = p_src + SRC_LEN;
// last decodable '%'
const unsigned char * const SRC_LAST_DEC = SRC_END - 2;
 
char * const start = new char[SRC_LEN];
char * end = start;
 
while (p_src < SRC_LAST_DEC) {
if (*p_src == '%') {
char dec1, dec2;
if (-1 != (dec1 = HEX2DEC[*(p_src + 1)])
&& -1 != (dec2 = HEX2DEC[*(p_src + 2)])) {
*end++ = (dec1 << 4) + dec2;
p_src += 3;
continue;
}
}
 
*end++ = *p_src++;
}
 
// the last 2- chars
while (p_src < SRC_END)
*end++ = *p_src++;
 
std::string result(start, end);
delete[] start;
return result;
}

This article is licensed with Creative Commons Attribution-NonCommercial-No Derivatives 4.0 International License
Tag: windows
Last updated:2019年6月3日

Jeff

管理员——代码为剑,如痴如醉

Tip the author Like
< Last article
Next article >

Comments

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
Cancel

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts
  • 基于FireBreath的npapi插件在Firefox下的调试
  • Win10任务管理器GPU信息
  • DXGI中的flip显示模型
  • CreateSwapChainForHwnd返回0x887A0001错误
  • DirectX 9 到DirectX 11 API的对应
Categories

COPYRIGHT © 2026 jianchihu.net. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang