|
@@ -160,21 +160,67 @@ namespace Chromium {
|
|
|
|
|
|
void CChromiumEntity::OpenCommonPage(SpReqAnsContext<ChromiumSrv_OpenCommonPage_Req, ChromiumSrv_OpenCommonPage_Ans>::Pointer ctx)
|
|
|
{
|
|
|
- std::string strTitle = ctx->Req.title.GetData();
|
|
|
- std::string strUrl = ctx->Req.url.GetData();
|
|
|
- int width = ctx->Req.width;
|
|
|
- int height = ctx->Req.height;
|
|
|
- int point_x = ctx->Req.point_x;
|
|
|
- int point_y = ctx->Req.point_y;
|
|
|
- std::string strTop = ctx->Req.top.GetData();
|
|
|
- auto ret = CModTools::get_mutable_instance().startCommonPage(strTitle, strUrl, width, height, point_x, point_y, strTop);
|
|
|
- ctx->Answer(ret.first, ret.first);
|
|
|
-
|
|
|
+ auto openCommonPageThread = [this](SpReqAnsContext<ChromiumSrv_OpenCommonPage_Req, ChromiumSrv_OpenCommonPage_Ans>::Pointer ctx)
|
|
|
+ {
|
|
|
+ std::string strTitle = ctx->Req.title.GetData();
|
|
|
+ std::string strUrl = ctx->Req.url.GetData();
|
|
|
+ int width = ctx->Req.width;
|
|
|
+ int height = ctx->Req.height;
|
|
|
+ int point_x = ctx->Req.point_x;
|
|
|
+ int point_y = ctx->Req.point_y;
|
|
|
+ std::string strTop = ctx->Req.top.GetData();
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ auto ret = CModTools::get_mutable_instance().startCommonPage(strTitle, strUrl, width, height, point_x, point_y, strTop);
|
|
|
+#else
|
|
|
+ auto srcPids = getUosBrowserPIDs();
|
|
|
+ auto ret = CModTools::get_mutable_instance().startCommonPage(strTitle, strUrl, width, height, point_x, point_y, strTop);
|
|
|
+ std::this_thread::sleep_for(std::chrono::seconds(2));
|
|
|
+ auto dstPids = getUosBrowserPIDs();
|
|
|
+
|
|
|
+ if (m_commonPageArr.find(strTitle) == m_commonPageArr.end())
|
|
|
+ {
|
|
|
+ std::vector<int> tmp;
|
|
|
+ m_commonPageArr[strTitle] = tmp;
|
|
|
+ }
|
|
|
+ std::vector<int> difference;
|
|
|
+ // 使用 std::set_difference 查找差值
|
|
|
+ std::set_difference(dstPids.begin(), dstPids.end(), srcPids.begin(), srcPids.end(), std::back_inserter(difference));
|
|
|
+ for (auto it : difference)
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("open commonPage %d", it);
|
|
|
+ m_commonPageArr[strTitle].push_back(it);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#endif
|
|
|
+ ctx->Answer(ret.first, ret.first);
|
|
|
+ };
|
|
|
+
|
|
|
+ std::thread(openCommonPageThread, ctx).detach();
|
|
|
}
|
|
|
void CChromiumEntity::CloseCommonPage(SpReqAnsContext<ChromiumSrv_CloseCommonPage_Req, ChromiumSrv_CloseCommonPage_Ans>::Pointer ctx)
|
|
|
{
|
|
|
std::string strName = ctx->Req.title.GetData();
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
CModTools::get_mutable_instance().stopCommonPage(strName);
|
|
|
+#else
|
|
|
+ if (m_commonPageArr.find(strName) != m_commonPageArr.end())
|
|
|
+ {
|
|
|
+ auto arr = m_commonPageArr[strName];
|
|
|
+ for (auto it : arr)
|
|
|
+ {
|
|
|
+ CSimpleStringA cmd = CSimpleStringA::Format("sudo kill -9 %d", it);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CloseCommonPage %s", cmd.GetData());
|
|
|
+ system(cmd.GetData());
|
|
|
+ }
|
|
|
+ arr.clear();
|
|
|
+ m_commonPageArr[strName] = arr;
|
|
|
+
|
|
|
+ }
|
|
|
+#endif // RVC_OS_WIN
|
|
|
+
|
|
|
+
|
|
|
ctx->Answer(ErrorCodeEnum::Error_Succeed);
|
|
|
}
|
|
|
|
|
@@ -543,10 +589,6 @@ namespace Chromium {
|
|
|
{
|
|
|
OnPreStart_Init(m_strArgs, m_pTransactionContext);//初始化部分, perf ,killchromium, signal, get custom url
|
|
|
|
|
|
-#if defined(RVC_OS_LINUX)
|
|
|
- Chromium::CModTools::get_mutable_instance().killAllChromium();//linux will kill all browser before open main page
|
|
|
-#endif // RVC_OS_UOS
|
|
|
-
|
|
|
|
|
|
if (!IsConfigMode()) {
|
|
|
if (!OnPreStart_register(m_strArgs, m_pTransactionContext)) {
|
|
@@ -614,9 +656,8 @@ namespace Chromium {
|
|
|
|
|
|
void CChromiumEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
|
|
|
{
|
|
|
- m_strArgs = strArgs;
|
|
|
- m_pTransactionContext = pTransactionContext;
|
|
|
- pTransactionContext->SendAnswer(Error_Succeed);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
#if defined(RVC_OS_LINUX)
|
|
|
// clear all the browser
|
|
@@ -715,9 +756,17 @@ namespace Chromium {
|
|
|
}
|
|
|
|
|
|
};
|
|
|
-
|
|
|
- boost::thread(startFun).detach();
|
|
|
|
|
|
+ boost::thread t(startFun);
|
|
|
+
|
|
|
+ // 等待线程 3 秒,如果超时则 detach 线程
|
|
|
+ if (!t.timed_join(boost::chrono::seconds(3))) {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Timed out, detaching thread.");
|
|
|
+ t.detach();
|
|
|
+ }
|
|
|
+ m_strArgs = strArgs;
|
|
|
+ m_pTransactionContext = pTransactionContext;
|
|
|
+ pTransactionContext->SendAnswer(Error_Succeed);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -762,7 +811,12 @@ namespace Chromium {
|
|
|
{
|
|
|
if (CModTools::get_mutable_instance().IsConfigWork())//url正常时才关闭
|
|
|
{
|
|
|
+#if defined(RVC_OS_LINUX)
|
|
|
+ Chromium::CModTools::get_mutable_instance().killAllChromium();//linux will kill all browser before open main page
|
|
|
+#else
|
|
|
CModTools::get_mutable_instance().StopChromiumBrowser(ERR_PAGE_REASON::startup);
|
|
|
+#endif // RVC_OS_UOS
|
|
|
+
|
|
|
if (m_runAd) openAdPage();
|
|
|
openMainPage();
|
|
|
CModTools::get_mutable_instance().StopChromiumBrowser(ERR_PAGE_REASON::breakdown);
|
|
@@ -776,7 +830,11 @@ namespace Chromium {
|
|
|
{
|
|
|
if (!m_withBrowser)
|
|
|
{
|
|
|
+#if defined(RVC_OS_LINUX)
|
|
|
+ Chromium::CModTools::get_mutable_instance().killAllChromium();//linux will kill all browser before open main page
|
|
|
+#else
|
|
|
CModTools::get_mutable_instance().StopChromiumBrowser(ERR_PAGE_REASON::startup);
|
|
|
+#endif // RVC_OS_UOS
|
|
|
|
|
|
auto openRet = CModTools::get_mutable_instance().StartChromiumBrowser(
|
|
|
0 == CSimpleStringA("S").Compare(curEvent.value.c_str(), true) ? ERR_PAGE_REASON::warnPrompt : ERR_PAGE_REASON::breakdown,
|