iv_controller.cpp 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "iv/iv_controller.h"
  8. #include "base/event_filter.h"
  9. #include "base/platform/base_platform_info.h"
  10. #include "base/qt/qt_key_modifiers.h"
  11. #include "base/invoke_queued.h"
  12. #include "base/qt_signal_producer.h"
  13. #include "base/qthelp_url.h"
  14. #include "core/file_utilities.h"
  15. #include "iv/iv_data.h"
  16. #include "lang/lang_keys.h"
  17. #include "ui/chat/attach/attach_bot_webview.h"
  18. #include "ui/platform/ui_platform_window_title.h"
  19. #include "ui/widgets/buttons.h"
  20. #include "ui/widgets/labels.h"
  21. #include "ui/widgets/menu/menu_action.h"
  22. #include "ui/widgets/rp_window.h"
  23. #include "ui/widgets/popup_menu.h"
  24. #include "ui/widgets/tooltip.h"
  25. #include "ui/wrap/fade_wrap.h"
  26. #include "ui/basic_click_handlers.h"
  27. #include "ui/painter.h"
  28. #include "ui/rect.h"
  29. #include "ui/webview_helpers.h"
  30. #include "ui/ui_utility.h"
  31. #include "webview/webview_data_stream_memory.h"
  32. #include "webview/webview_embed.h"
  33. #include "webview/webview_interface.h"
  34. #include "styles/palette.h"
  35. #include "styles/style_iv.h"
  36. #include "styles/style_menu_icons.h"
  37. #include "styles/style_payments.h" // paymentsCriticalError
  38. #include "styles/style_widgets.h"
  39. #include "styles/style_window.h"
  40. #include <QtCore/QRegularExpression>
  41. #include <QtCore/QJsonDocument>
  42. #include <QtCore/QJsonObject>
  43. #include <QtCore/QJsonValue>
  44. #include <QtCore/QFile>
  45. #include <QtGui/QGuiApplication>
  46. #include <QtGui/QPainter>
  47. #include <QtGui/QWindow>
  48. #include <charconv>
  49. #include <ada.h>
  50. namespace Iv {
  51. namespace {
  52. constexpr auto kZoomStep = int(10);
  53. constexpr auto kZoomSmallStep = int(5);
  54. constexpr auto kZoomTinyStep = int(1);
  55. constexpr auto kDefaultZoom = int(100);
  56. class ItemZoom final
  57. : public Ui::Menu::Action
  58. , public Ui::AbstractTooltipShower {
  59. public:
  60. ItemZoom(
  61. not_null<RpWidget*> parent,
  62. const not_null<Delegate*> delegate,
  63. const style::Menu &st)
  64. : Ui::Menu::Action(
  65. parent,
  66. st,
  67. Ui::CreateChild<QAction>(parent),
  68. nullptr,
  69. nullptr)
  70. , _delegate(delegate)
  71. , _st(st) {
  72. init();
  73. }
  74. void init() {
  75. enableMouseSelecting();
  76. AbstractButton::setDisabled(true);
  77. const auto processTooltip = [=](not_null<Ui::RpWidget*> w) {
  78. w->events() | rpl::start_with_next([=](not_null<QEvent*> e) {
  79. if (e->type() == QEvent::Enter) {
  80. Ui::Tooltip::Show(1000, this);
  81. } else if (e->type() == QEvent::Leave) {
  82. Ui::Tooltip::Hide();
  83. }
  84. }, w->lifetime());
  85. };
  86. const auto reset = Ui::CreateChild<Ui::RoundButton>(
  87. this,
  88. rpl::single<QString>(QString()),
  89. st::ivResetZoom);
  90. processTooltip(reset);
  91. const auto resetLabel = Ui::CreateChild<Ui::FlatLabel>(
  92. reset,
  93. tr::lng_background_reset_default(),
  94. st::ivResetZoomLabel);
  95. resetLabel->setAttribute(Qt::WA_TransparentForMouseEvents);
  96. reset->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
  97. reset->setClickedCallback([this] {
  98. _delegate->ivSetZoom(kDefaultZoom);
  99. });
  100. reset->show();
  101. const auto plus = Ui::CreateSimpleCircleButton(
  102. this,
  103. st::defaultRippleAnimationBgOver);
  104. plus->resize(Size(st::ivZoomButtonsSize));
  105. plus->paintRequest() | rpl::start_with_next([=, fg = _st.itemFg] {
  106. auto p = QPainter(plus);
  107. p.setPen(fg);
  108. p.setFont(st::normalFont);
  109. p.drawText(plus->rect(), QChar('+'), style::al_center);
  110. }, plus->lifetime());
  111. processTooltip(plus);
  112. const auto step = [] {
  113. return base::IsAltPressed()
  114. ? kZoomTinyStep
  115. : base::IsCtrlPressed()
  116. ? kZoomSmallStep
  117. : kZoomStep;
  118. };
  119. plus->setClickedCallback([this, step] {
  120. _delegate->ivSetZoom(_delegate->ivZoom() + step());
  121. });
  122. plus->show();
  123. const auto minus = Ui::CreateSimpleCircleButton(
  124. this,
  125. st::defaultRippleAnimationBgOver);
  126. minus->resize(Size(st::ivZoomButtonsSize));
  127. minus->paintRequest() | rpl::start_with_next([=, fg = _st.itemFg] {
  128. auto p = QPainter(minus);
  129. const auto r = minus->rect();
  130. p.setPen(fg);
  131. p.setFont(st::normalFont);
  132. p.drawText(
  133. QRectF(r).translated(0, style::ConvertFloatScale(-1)),
  134. QChar(0x2013),
  135. style::al_center);
  136. }, minus->lifetime());
  137. processTooltip(minus);
  138. minus->setClickedCallback([this, step] {
  139. _delegate->ivSetZoom(_delegate->ivZoom() - step());
  140. });
  141. minus->show();
  142. {
  143. const auto maxWidthText = u"000%"_q;
  144. _text.setText(_st.itemStyle, maxWidthText);
  145. Ui::Menu::ItemBase::setMinWidth(
  146. _text.maxWidth()
  147. + st::ivResetZoomInnerPadding
  148. + resetLabel->width()
  149. + plus->width()
  150. + minus->width()
  151. + _st.itemPadding.right() * 2);
  152. }
  153. _delegate->ivZoomValue(
  154. ) | rpl::start_with_next([this](int value) {
  155. _text.setText(_st.itemStyle, QString::number(value) + '%');
  156. update();
  157. }, lifetime());
  158. rpl::combine(
  159. sizeValue(),
  160. reset->sizeValue()
  161. ) | rpl::start_with_next([=](const QSize &size, const QSize &) {
  162. reset->setFullWidth(0
  163. + resetLabel->width()
  164. + st::ivResetZoomInnerPadding);
  165. resetLabel->moveToLeft(
  166. (reset->width() - resetLabel->width()) / 2,
  167. (reset->height() - resetLabel->height()) / 2);
  168. reset->moveToRight(
  169. _st.itemPadding.right(),
  170. (size.height() - reset->height()) / 2);
  171. plus->moveToRight(
  172. _st.itemPadding.right() + reset->width(),
  173. (size.height() - plus->height()) / 2);
  174. minus->moveToRight(
  175. _st.itemPadding.right() + plus->width() + reset->width(),
  176. (size.height() - minus->height()) / 2);
  177. }, lifetime());
  178. }
  179. void paintEvent(QPaintEvent *event) override {
  180. auto p = QPainter(this);
  181. p.setPen(_st.itemFg);
  182. _text.draw(p, {
  183. .position = QPoint(
  184. _st.itemIconPosition.x(),
  185. (height() - _text.minHeight()) / 2),
  186. .outerWidth = width(),
  187. .availableWidth = width(),
  188. });
  189. }
  190. QString tooltipText() const override {
  191. #ifdef Q_OS_MAC
  192. return tr::lng_iv_zoom_tooltip_cmd(tr::now);
  193. #else
  194. return tr::lng_iv_zoom_tooltip_ctrl(tr::now);
  195. #endif
  196. }
  197. QPoint tooltipPos() const override {
  198. return QCursor::pos();
  199. }
  200. bool tooltipWindowActive() const override {
  201. return true;
  202. }
  203. private:
  204. const not_null<Delegate*> _delegate;
  205. const style::Menu &_st;
  206. Ui::Text::String _text;
  207. };
  208. [[nodiscard]] QByteArray ComputeStyles(int zoom) {
  209. static const auto map = base::flat_map<QByteArray, const style::color*>{
  210. { "shadow-fg", &st::shadowFg },
  211. { "scroll-bg", &st::scrollBg },
  212. { "scroll-bg-over", &st::scrollBgOver },
  213. { "scroll-bar-bg", &st::scrollBarBg },
  214. { "scroll-bar-bg-over", &st::scrollBarBgOver },
  215. { "window-bg", &st::windowBg },
  216. { "window-bg-over", &st::windowBgOver },
  217. { "window-bg-ripple", &st::windowBgRipple },
  218. { "window-bg-active", &st::windowBgActive },
  219. { "window-fg", &st::windowFg },
  220. { "window-sub-text-fg", &st::windowSubTextFg },
  221. { "window-active-text-fg", &st::windowActiveTextFg },
  222. { "window-shadow-fg", &st::windowShadowFg },
  223. { "box-divider-bg", &st::boxDividerBg },
  224. { "box-divider-fg", &st::boxDividerFg },
  225. { "light-button-fg", &st::lightButtonFg },
  226. //{ "light-button-bg-over", &st::lightButtonBgOver },
  227. { "menu-icon-fg", &st::menuIconFg },
  228. { "menu-icon-fg-over", &st::menuIconFgOver },
  229. { "menu-bg", &st::menuBg },
  230. { "menu-bg-over", &st::menuBgOver },
  231. { "history-to-down-fg", &st::historyToDownFg },
  232. { "history-to-down-fg-over", &st::historyToDownFgOver },
  233. { "history-to-down-bg", &st::historyToDownBg },
  234. { "history-to-down-bg-over", &st::historyToDownBgOver },
  235. { "history-to-down-bg-ripple", &st::historyToDownBgRipple },
  236. { "history-to-down-shadow", &st::historyToDownShadow },
  237. { "toast-bg", &st::toastBg },
  238. { "toast-fg", &st::toastFg },
  239. };
  240. static const auto phrases = base::flat_map<QByteArray, tr::phrase<>>{
  241. { "iv-join-channel", tr::lng_iv_join_channel },
  242. };
  243. return Ui::ComputeStyles(map, phrases, zoom)
  244. + ';'
  245. + Ui::ComputeSemiTransparentOverStyle(
  246. "light-button-bg-over",
  247. st::lightButtonBgOver,
  248. st::windowBg);
  249. }
  250. [[nodiscard]] QByteArray WrapPage(const Prepared &page, int zoom) {
  251. #ifdef Q_OS_MAC
  252. const auto classAttribute = ""_q;
  253. #else // Q_OS_MAC
  254. const auto classAttribute = " class=\"custom_scroll\""_q;
  255. #endif // Q_OS_MAC
  256. const auto js = QByteArray()
  257. + (page.hasCode ? "IV.initPreBlocks();" : "")
  258. + (page.hasEmbeds ? "IV.initEmbedBlocks();" : "")
  259. + "IV.init();"
  260. + page.script;
  261. return R"(<!DOCTYPE html>
  262. <html)"_q
  263. + classAttribute
  264. + R"( style=")"
  265. + Ui::EscapeForAttribute(ComputeStyles(zoom))
  266. + R"(">
  267. <head>
  268. <meta charset="utf-8">
  269. <meta name="robots" content="noindex, nofollow">
  270. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  271. <script src="/iv/page.js"></script>
  272. <link rel="stylesheet" href="/iv/page.css" />
  273. </head>
  274. <body>
  275. <div id="top_shadow"></div>
  276. <button class="fixed_button hidden" id="bottom_up" onclick="IV.scrollTo(0);">
  277. <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
  278. <path d="M14.9972363,18 L9.13865768,12.1414214 C9.06055283,12.0633165 9.06055283,11.9366835 9.13865768,11.8585786 L14.9972363,6 L14.9972363,6" transform="translate(11.997236, 12.000000) scale(-1, -1) rotate(-90.000000) translate(-11.997236, -12.000000) "></path>
  279. </svg>
  280. </button>
  281. <div class="page-scroll" tabindex="-1">)"_q + page.content.trimmed() + R"(</div>
  282. <script>)"_q + js + R"(</script>
  283. </body>
  284. </html>
  285. )"_q;
  286. }
  287. [[nodiscard]] QByteArray ReadResource(const QString &name) {
  288. auto file = QFile(u":/iv/"_q + name);
  289. return file.open(QIODevice::ReadOnly) ? file.readAll() : QByteArray();
  290. }
  291. [[nodiscard]] QString TonsiteToHttps(QString value) {
  292. const auto ChangeHost = [](QString tonsite) {
  293. const auto fake = "http://" + tonsite.toStdString();
  294. const auto parsed = ada::parse<ada::url>(fake);
  295. if (!parsed) {
  296. return QString();
  297. }
  298. tonsite = QString::fromStdString(parsed->get_hostname());
  299. tonsite = tonsite.replace('-', "-h");
  300. tonsite = tonsite.replace('.', "-d");
  301. return tonsite + ".magic.org";
  302. };
  303. const auto prefix = u"tonsite://"_q;
  304. if (!value.toLower().startsWith(prefix)) {
  305. return QString();
  306. }
  307. const auto part = value.mid(prefix.size());
  308. const auto split = part.indexOf('/');
  309. const auto host = ChangeHost((split < 0) ? part : part.left(split));
  310. if (host.isEmpty()) {
  311. return QString();
  312. }
  313. return "https://" + host + ((split < 0) ? u"/"_q : part.mid(split));
  314. }
  315. [[nodiscard]] QString HttpsToTonsite(QString value) {
  316. const auto ChangeHost = [](QString https) {
  317. const auto dot = https.indexOf('.');
  318. if (dot < 0 || https.mid(dot).toLower() != u".magic.org"_q) {
  319. return QString();
  320. }
  321. https = https.mid(0, dot);
  322. https = https.replace("-d", ".");
  323. https = https.replace("-h", "-");
  324. auto parts = https.split('.');
  325. for (auto &part : parts) {
  326. if (part.startsWith(u"xn--"_q)) {
  327. const auto utf8 = part.mid(4).toStdString();
  328. auto out = std::u32string();
  329. if (ada::idna::punycode_to_utf32(utf8, out)) {
  330. part = QString::fromUcs4(out.data(), out.size());
  331. }
  332. }
  333. }
  334. return parts.join('.');
  335. };
  336. const auto prefix = u"https://"_q;
  337. if (!value.toLower().startsWith(prefix)) {
  338. return value;
  339. }
  340. const auto part = value.mid(prefix.size());
  341. const auto split = part.indexOf('/');
  342. const auto host = ChangeHost((split < 0) ? part : part.left(split));
  343. if (host.isEmpty()) {
  344. return value;
  345. }
  346. return "tonsite://"
  347. + host
  348. + ((split < 0) ? u"/"_q : part.mid(split));
  349. }
  350. } // namespace
  351. Controller::Controller(
  352. not_null<Delegate*> delegate,
  353. Fn<ShareBoxResult(ShareBoxDescriptor)> showShareBox)
  354. : _delegate(delegate)
  355. , _updateStyles([=] {
  356. if (_webview) {
  357. const auto webviewZoomController = _webview->zoomController();
  358. const auto styleZoom = webviewZoomController
  359. ? kDefaultZoom
  360. : _delegate->ivZoom();
  361. const auto str = Ui::EscapeForScriptString(ComputeStyles(styleZoom));
  362. _webview->eval("IV.updateStyles('" + str + "');");
  363. if (webviewZoomController) {
  364. webviewZoomController->setZoom(_delegate->ivZoom());
  365. }
  366. }
  367. })
  368. , _showShareBox(std::move(showShareBox)) {
  369. createWindow();
  370. }
  371. Controller::~Controller() {
  372. destroyShareMenu();
  373. if (_window) {
  374. _window->hide();
  375. }
  376. _ready = false;
  377. base::take(_webview);
  378. _back.destroy();
  379. _forward.destroy();
  380. _menu = nullptr;
  381. _menuToggle.destroy();
  382. _subtitle = nullptr;
  383. _subtitleWrap = nullptr;
  384. _window = nullptr;
  385. }
  386. void Controller::updateTitleGeometry(int newWidth) const {
  387. _subtitleWrap->setGeometry(
  388. 0,
  389. 0,
  390. newWidth,
  391. st::ivSubtitleHeight);
  392. _subtitleWrap->paintRequest() | rpl::start_with_next([=](QRect clip) {
  393. QPainter(_subtitleWrap.get()).fillRect(clip, st::windowBg);
  394. }, _subtitleWrap->lifetime());
  395. const auto progressBack = _subtitleBackShift.value(
  396. _back->toggled() ? 1. : 0.);
  397. const auto progressForward = _subtitleForwardShift.value(
  398. _forward->toggled() ? 1. : 0.);
  399. const auto backAdded = _back->width()
  400. + st::ivSubtitleSkip
  401. - st::ivSubtitleLeft;
  402. const auto forwardAdded = _forward->width();
  403. const auto left = st::ivSubtitleLeft
  404. + anim::interpolate(0, backAdded, progressBack)
  405. + anim::interpolate(0, forwardAdded, progressForward);
  406. _subtitle->resizeToWidth(newWidth - left - _menuToggle->width());
  407. _subtitle->moveToLeft(left, st::ivSubtitleTop);
  408. _back->moveToLeft(0, 0);
  409. _forward->moveToLeft(_back->width() * progressBack, 0);
  410. _menuToggle->moveToRight(0, 0);
  411. }
  412. void Controller::initControls() {
  413. _subtitleWrap = std::make_unique<Ui::RpWidget>(_window->body().get());
  414. _subtitleText = _index.value() | rpl::filter(
  415. rpl::mappers::_1 >= 0
  416. ) | rpl::map([=](int index) {
  417. return _pages[index].name;
  418. });
  419. _subtitle = std::make_unique<Ui::FlatLabel>(
  420. _subtitleWrap.get(),
  421. _subtitleText.value(),
  422. st::ivSubtitle);
  423. _subtitle->setSelectable(true);
  424. _windowTitleText = _subtitleText.value(
  425. ) | rpl::map([=](const QString &subtitle) {
  426. const auto prefix = tr::lng_iv_window_title(tr::now);
  427. return prefix + ' ' + QChar(0x2014) + ' ' + subtitle;
  428. });
  429. _windowTitleText.value(
  430. ) | rpl::start_with_next([=](const QString &title) {
  431. _window->setWindowTitle(title);
  432. }, _subtitle->lifetime());
  433. _menuToggle.create(_subtitleWrap.get(), st::ivMenuToggle);
  434. _menuToggle->setClickedCallback([=] { showMenu(); });
  435. _back.create(
  436. _subtitleWrap.get(),
  437. object_ptr<Ui::IconButton>(_subtitleWrap.get(), st::ivBack));
  438. _back->entity()->setClickedCallback([=] {
  439. if (_webview) {
  440. _webview->eval("window.history.back();");
  441. } else {
  442. _back->hide(anim::type::normal);
  443. }
  444. });
  445. _forward.create(
  446. _subtitleWrap.get(),
  447. object_ptr<Ui::IconButton>(_subtitleWrap.get(), st::ivForward));
  448. _forward->entity()->setClickedCallback([=] {
  449. if (_webview) {
  450. _webview->eval("window.history.forward();");
  451. } else {
  452. _forward->hide(anim::type::normal);
  453. }
  454. });
  455. _back->toggledValue(
  456. ) | rpl::start_with_next([=](bool toggled) {
  457. _subtitleBackShift.start(
  458. [=] { updateTitleGeometry(_window->body()->width()); },
  459. toggled ? 0. : 1.,
  460. toggled ? 1. : 0.,
  461. st::fadeWrapDuration);
  462. }, _back->lifetime());
  463. _back->hide(anim::type::instant);
  464. _forward->toggledValue(
  465. ) | rpl::start_with_next([=](bool toggled) {
  466. _subtitleForwardShift.start(
  467. [=] { updateTitleGeometry(_window->body()->width()); },
  468. toggled ? 0. : 1.,
  469. toggled ? 1. : 0.,
  470. st::fadeWrapDuration);
  471. }, _forward->lifetime());
  472. _forward->hide(anim::type::instant);
  473. _subtitleBackShift.stop();
  474. _subtitleForwardShift.stop();
  475. }
  476. void Controller::show(
  477. const Webview::StorageId &storageId,
  478. Prepared page,
  479. base::flat_map<QByteArray, rpl::producer<bool>> inChannelValues) {
  480. page.script = fillInChannelValuesScript(std::move(inChannelValues));
  481. InvokeQueued(_container, [=, page = std::move(page)]() mutable {
  482. showInWindow(storageId, std::move(page));
  483. });
  484. }
  485. void Controller::update(Prepared page) {
  486. const auto url = page.url;
  487. auto i = _indices.find(url);
  488. if (i == end(_indices)) {
  489. return;
  490. }
  491. const auto index = i->second;
  492. _pages[index] = std::move(page);
  493. if (_ready) {
  494. _webview->eval(reloadScript(index));
  495. } else if (!index) {
  496. _reloadInitialWhenReady = true;
  497. }
  498. }
  499. bool Controller::IsGoodTonSiteUrl(const QString &uri) {
  500. return !TonsiteToHttps(uri).isEmpty();
  501. }
  502. void Controller::showTonSite(
  503. const Webview::StorageId &storageId,
  504. QString uri) {
  505. const auto url = TonsiteToHttps(uri);
  506. Assert(!url.isEmpty());
  507. if (!_webview) {
  508. createWebview(storageId);
  509. }
  510. if (_webview && _webview->widget()) {
  511. _webview->navigate(url);
  512. activate();
  513. }
  514. _url = url;
  515. _subtitleText = _url.value(
  516. ) | rpl::filter([=](const QString &url) {
  517. return !url.isEmpty() && url != u"about:blank"_q;
  518. }) | rpl::map([=](QString value) {
  519. return HttpsToTonsite(value);
  520. });
  521. _windowTitleText = _subtitleText.value();
  522. _menuToggle->hide();
  523. }
  524. QByteArray Controller::fillInChannelValuesScript(
  525. base::flat_map<QByteArray, rpl::producer<bool>> inChannelValues) {
  526. auto result = QByteArray();
  527. for (auto &[id, in] : inChannelValues) {
  528. if (_inChannelSubscribed.emplace(id).second) {
  529. std::move(in) | rpl::start_with_next([=](bool in) {
  530. if (_ready) {
  531. _webview->eval(toggleInChannelScript(id, in));
  532. } else {
  533. _inChannelChanged[id] = in;
  534. }
  535. }, _lifetime);
  536. }
  537. }
  538. for (const auto &[id, in] : base::take(_inChannelChanged)) {
  539. result += toggleInChannelScript(id, in);
  540. }
  541. return result;
  542. }
  543. QByteArray Controller::toggleInChannelScript(
  544. const QByteArray &id,
  545. bool in) const {
  546. const auto value = in ? "true" : "false";
  547. return "IV.toggleChannelJoined('" + id + "', " + value + ");";
  548. }
  549. void Controller::createWindow() {
  550. _window = std::make_unique<Ui::RpWindow>();
  551. const auto window = _window.get();
  552. base::qt_signal_producer(
  553. qApp,
  554. &QGuiApplication::focusWindowChanged
  555. ) | rpl::filter([=](QWindow *focused) {
  556. const auto handle = window->window()->windowHandle();
  557. return _webview && handle && (focused == handle);
  558. }) | rpl::start_with_next([=] {
  559. setInnerFocus();
  560. }, window->lifetime());
  561. initControls();
  562. window->body()->widthValue() | rpl::start_with_next([=](int width) {
  563. updateTitleGeometry(width);
  564. }, _subtitle->lifetime());
  565. window->setGeometry(_delegate->ivGeometry());
  566. window->setMinimumSize({ st::windowMinWidth, st::windowMinHeight });
  567. window->geometryValue(
  568. ) | rpl::distinct_until_changed(
  569. ) | rpl::skip(1) | rpl::start_with_next([=] {
  570. _delegate->ivSaveGeometry(window);
  571. }, window->lifetime());
  572. _container = Ui::CreateChild<Ui::RpWidget>(window->body().get());
  573. rpl::combine(
  574. window->body()->sizeValue(),
  575. _subtitleWrap->heightValue()
  576. ) | rpl::start_with_next([=](QSize size, int title) {
  577. _container->setGeometry(QRect(QPoint(), size).marginsRemoved(
  578. { 0, title, 0, 0 }));
  579. }, _container->lifetime());
  580. _container->paintRequest() | rpl::start_with_next([=](QRect clip) {
  581. QPainter(_container).fillRect(clip, st::windowBg);
  582. }, _container->lifetime());
  583. _container->show();
  584. window->show();
  585. }
  586. void Controller::createWebview(const Webview::StorageId &storageId) {
  587. Expects(!_webview);
  588. const auto window = _window.get();
  589. _webview = std::make_unique<Webview::Window>(
  590. _container,
  591. Webview::WindowConfig{
  592. .opaqueBg = st::windowBg->c,
  593. .storageId = storageId,
  594. });
  595. const auto raw = _webview.get();
  596. if (const auto webviewZoomController = raw->zoomController()) {
  597. webviewZoomController->zoomValue(
  598. ) | rpl::start_with_next([this](int value) {
  599. if (value > 0) {
  600. _delegate->ivSetZoom(value);
  601. }
  602. }, lifetime());
  603. _delegate->ivZoomValue(
  604. ) | rpl::start_with_next([=](int value) {
  605. webviewZoomController->setZoom(value);
  606. }, lifetime());
  607. }
  608. window->lifetime().add([=] {
  609. _ready = false;
  610. base::take(_webview);
  611. });
  612. window->events(
  613. ) | rpl::start_with_next([=](not_null<QEvent*> e) {
  614. if (e->type() == QEvent::Close) {
  615. close();
  616. } else if (e->type() == QEvent::KeyPress) {
  617. const auto event = static_cast<QKeyEvent*>(e.get());
  618. if (event->key() == Qt::Key_Escape) {
  619. escape();
  620. }
  621. }
  622. }, window->lifetime());
  623. base::install_event_filter(window, qApp, [=](not_null<QEvent*> e) {
  624. if (e->type() == QEvent::ShortcutOverride) {
  625. if (!window->isActiveWindow()) {
  626. return base::EventFilterResult::Continue;
  627. }
  628. const auto event = static_cast<QKeyEvent*>(e.get());
  629. if (event->modifiers() & Qt::ControlModifier) {
  630. if (event->key() == Qt::Key_Plus
  631. || event->key() == Qt::Key_Equal) {
  632. _delegate->ivSetZoom(_delegate->ivZoom() + kZoomStep);
  633. return base::EventFilterResult::Cancel;
  634. } else if (event->key() == Qt::Key_Minus) {
  635. _delegate->ivSetZoom(_delegate->ivZoom() - kZoomStep);
  636. return base::EventFilterResult::Cancel;
  637. } else if (event->key() == Qt::Key_0) {
  638. _delegate->ivSetZoom(kDefaultZoom);
  639. return base::EventFilterResult::Cancel;
  640. }
  641. }
  642. }
  643. return base::EventFilterResult::Continue;
  644. });
  645. const auto widget = raw->widget();
  646. if (!widget) {
  647. base::take(_webview);
  648. showWebviewError();
  649. return;
  650. }
  651. widget->show();
  652. QObject::connect(widget, &QObject::destroyed, [=] {
  653. if (!_webview) {
  654. // If we destroyed _webview ourselves,
  655. // we don't show any message, nothing crashed.
  656. return;
  657. }
  658. crl::on_main(window, [=] {
  659. showWebviewError({ "Error: WebView has crashed." });
  660. });
  661. base::take(_webview);
  662. });
  663. _container->sizeValue(
  664. ) | rpl::start_with_next([=](QSize size) {
  665. if (const auto widget = raw->widget()) {
  666. widget->setGeometry(QRect(QPoint(), size));
  667. }
  668. }, _container->lifetime());
  669. raw->setNavigationStartHandler([=](const QString &uri, bool newWindow) {
  670. if (uri.startsWith(u"http://desktop-app-resource/"_q)
  671. || QUrl(uri).host().toLower().endsWith(u".magic.org"_q)) {
  672. return true;
  673. }
  674. _events.fire({ .type = Event::Type::OpenLink, .url = uri });
  675. return false;
  676. });
  677. raw->setNavigationDoneHandler([=](bool success) {
  678. });
  679. raw->setMessageHandler([=](const QJsonDocument &message) {
  680. crl::on_main(_window.get(), [=] {
  681. const auto object = message.object();
  682. const auto event = object.value("event").toString();
  683. if (event == u"keydown"_q) {
  684. const auto key = object.value("key").toString();
  685. const auto modifier = object.value("modifier").toString();
  686. processKey(key, modifier);
  687. } else if (event == u"mouseenter"_q) {
  688. window->overrideSystemButtonOver({});
  689. } else if (event == u"mouseup"_q) {
  690. window->overrideSystemButtonDown({});
  691. } else if (event == u"link_click"_q) {
  692. const auto url = object.value("url").toString();
  693. const auto context = object.value("context").toString();
  694. processLink(url, context);
  695. } else if (event == "menu_page_blocker_click") {
  696. if (_menu) {
  697. _menu->hideMenu();
  698. }
  699. } else if (event == u"ready"_q) {
  700. _ready = true;
  701. auto script = QByteArray();
  702. for (const auto &[id, in] : base::take(_inChannelChanged)) {
  703. script += toggleInChannelScript(id, in);
  704. }
  705. if (_navigateToIndexWhenReady >= 0) {
  706. script += navigateScript(
  707. std::exchange(_navigateToIndexWhenReady, -1),
  708. base::take(_navigateToHashWhenReady));
  709. }
  710. if (base::take(_reloadInitialWhenReady)) {
  711. script += reloadScript(0);
  712. }
  713. if (_menu) {
  714. script += "IV.menuShown(true);";
  715. }
  716. if (!script.isEmpty()) {
  717. _webview->eval(script);
  718. }
  719. } else if (event == u"location_change"_q) {
  720. _index = object.value("index").toInt();
  721. _hash = object.value("hash").toString();
  722. _webview->refreshNavigationHistoryState();
  723. }
  724. });
  725. });
  726. raw->setDataRequestHandler([=](Webview::DataRequest request) {
  727. const auto pos = request.id.find('#');
  728. if (pos != request.id.npos) {
  729. request.id = request.id.substr(0, pos);
  730. }
  731. if (!request.id.starts_with("iv/")) {
  732. _dataRequests.fire(std::move(request));
  733. return Webview::DataResult::Pending;
  734. }
  735. const auto finishWith = [&](QByteArray data, std::string mime) {
  736. request.done({
  737. .stream = std::make_unique<Webview::DataStreamFromMemory>(
  738. std::move(data),
  739. std::move(mime)),
  740. });
  741. return Webview::DataResult::Done;
  742. };
  743. const auto id = std::string_view(request.id).substr(3);
  744. if (id.starts_with("page") && id.ends_with(".html")) {
  745. if (!_subscribedToColors) {
  746. _subscribedToColors = true;
  747. rpl::merge(
  748. Lang::Updated(),
  749. style::PaletteChanged(),
  750. _delegate->ivZoomValue() | rpl::to_empty
  751. ) | rpl::start_with_next([=] {
  752. _updateStyles.call();
  753. }, _webview->lifetime());
  754. }
  755. auto index = 0;
  756. const auto result = std::from_chars(
  757. id.data() + 4,
  758. id.data() + id.size() - 5,
  759. index);
  760. if (result.ec != std::errc()
  761. || index < 0
  762. || index >= _pages.size()) {
  763. return Webview::DataResult::Failed;
  764. }
  765. const auto webviewZoomController = _webview->zoomController();
  766. const auto styleZoom = webviewZoomController
  767. ? kDefaultZoom
  768. : _delegate->ivZoom();
  769. return finishWith(
  770. WrapPage(_pages[index], styleZoom),
  771. "text/html; charset=utf-8");
  772. } else if (id.starts_with("page") && id.ends_with(".json")) {
  773. auto index = 0;
  774. const auto result = std::from_chars(
  775. id.data() + 4,
  776. id.data() + id.size() - 5,
  777. index);
  778. if (result.ec != std::errc()
  779. || index < 0
  780. || index >= _pages.size()) {
  781. return Webview::DataResult::Failed;
  782. }
  783. auto &page = _pages[index];
  784. return finishWith(QJsonDocument(QJsonObject{
  785. { "html", QJsonValue(QString::fromUtf8(page.content)) },
  786. { "js", QJsonValue(QString::fromUtf8(page.script)) },
  787. }).toJson(QJsonDocument::Compact), "application/json");
  788. }
  789. const auto css = id.ends_with(".css");
  790. const auto js = !css && id.ends_with(".js");
  791. if (!css && !js) {
  792. return Webview::DataResult::Failed;
  793. }
  794. const auto qstring = QString::fromUtf8(id.data(), id.size());
  795. const auto pattern = u"^[a-zA-Z\\.\\-_0-9]+$"_q;
  796. if (QRegularExpression(pattern).match(qstring).hasMatch()) {
  797. const auto bytes = ReadResource(qstring);
  798. if (!bytes.isEmpty()) {
  799. const auto mime = css ? "text/css" : "text/javascript";
  800. const auto full = (qstring == u"page.js"_q)
  801. ? (ReadResource("morphdom.js") + bytes)
  802. : bytes;
  803. return finishWith(full, mime);
  804. }
  805. }
  806. return Webview::DataResult::Failed;
  807. });
  808. raw->navigationHistoryState(
  809. ) | rpl::start_with_next([=](Webview::NavigationHistoryState state) {
  810. _back->toggle(
  811. state.canGoBack || state.canGoForward,
  812. anim::type::normal);
  813. _forward->toggle(state.canGoForward, anim::type::normal);
  814. _back->entity()->setDisabled(!state.canGoBack);
  815. _back->entity()->setIconOverride(
  816. state.canGoBack ? nullptr : &st::ivBackIconDisabled,
  817. state.canGoBack ? nullptr : &st::ivBackIconDisabled);
  818. _back->setAttribute(
  819. Qt::WA_TransparentForMouseEvents,
  820. !state.canGoBack);
  821. _url = QString::fromStdString(state.url);
  822. }, _webview->lifetime());
  823. raw->init(R"()");
  824. }
  825. void Controller::showWebviewError() {
  826. const auto available = Webview::Availability();
  827. if (available.error != Webview::Available::Error::None) {
  828. showWebviewError(Ui::BotWebView::ErrorText(available));
  829. } else {
  830. showWebviewError({ "Error: Could not initialize WebView." });
  831. }
  832. }
  833. void Controller::showWebviewError(TextWithEntities text) {
  834. auto error = Ui::CreateChild<Ui::PaddingWrap<Ui::FlatLabel>>(
  835. _container,
  836. object_ptr<Ui::FlatLabel>(
  837. _container,
  838. rpl::single(text),
  839. st::paymentsCriticalError),
  840. st::paymentsCriticalErrorPadding);
  841. error->entity()->setClickHandlerFilter([=](
  842. const ClickHandlerPtr &handler,
  843. Qt::MouseButton) {
  844. const auto entity = handler->getTextEntity();
  845. if (entity.type != EntityType::CustomUrl) {
  846. return true;
  847. }
  848. File::OpenUrl(entity.data);
  849. return false;
  850. });
  851. error->show();
  852. _container->sizeValue() | rpl::start_with_next([=](QSize size) {
  853. error->setGeometry(0, 0, size.width(), size.height() * 2 / 3);
  854. }, error->lifetime());
  855. }
  856. void Controller::showInWindow(
  857. const Webview::StorageId &storageId,
  858. Prepared page) {
  859. Expects(_container != nullptr);
  860. const auto url = page.url;
  861. _hash = page.hash;
  862. auto i = _indices.find(url);
  863. if (i == end(_indices)) {
  864. _pages.push_back(std::move(page));
  865. i = _indices.emplace(url, int(_pages.size() - 1)).first;
  866. }
  867. const auto index = i->second;
  868. _index = index;
  869. if (!_webview) {
  870. createWebview(storageId);
  871. if (_webview && _webview->widget()) {
  872. auto id = u"iv/page%1.html"_q.arg(index);
  873. if (!_hash.isEmpty()) {
  874. id += '#' + _hash;
  875. }
  876. _webview->navigateToData(id);
  877. activate();
  878. } else {
  879. _events.fire({ Event::Type::Close });
  880. }
  881. } else if (_ready) {
  882. _webview->eval(navigateScript(index, _hash));
  883. activate();
  884. } else {
  885. _navigateToIndexWhenReady = index;
  886. _navigateToHashWhenReady = _hash;
  887. activate();
  888. }
  889. }
  890. void Controller::activate() {
  891. if (_window->isMinimized()) {
  892. _window->showNormal();
  893. } else if (_window->isHidden()) {
  894. _window->show();
  895. }
  896. _window->raise();
  897. _window->activateWindow();
  898. _window->setFocus();
  899. setInnerFocus();
  900. }
  901. void Controller::setInnerFocus() {
  902. if (const auto onstack = _shareFocus) {
  903. onstack();
  904. } else if (_webview) {
  905. _webview->focus();
  906. }
  907. }
  908. QByteArray Controller::navigateScript(int index, const QString &hash) {
  909. return "IV.navigateTo("
  910. + QByteArray::number(index)
  911. + ", '"
  912. + Ui::EscapeForScriptString(qthelp::url_decode(hash).toUtf8())
  913. + "');";
  914. }
  915. QByteArray Controller::reloadScript(int index) {
  916. return "IV.reloadPage("
  917. + QByteArray::number(index)
  918. + ");";
  919. }
  920. void Controller::processKey(const QString &key, const QString &modifier) {
  921. const auto ctrl = Platform::IsMac() ? u"cmd"_q : u"ctrl"_q;
  922. if (key == u"escape"_q) {
  923. escape();
  924. } else if (key == u"w"_q && modifier == ctrl) {
  925. close();
  926. } else if (key == u"m"_q && modifier == ctrl) {
  927. minimize();
  928. } else if (key == u"q"_q && modifier == ctrl) {
  929. quit();
  930. } else if (key == u"0"_q && modifier == ctrl) {
  931. _delegate->ivSetZoom(kDefaultZoom);
  932. }
  933. }
  934. void Controller::processLink(const QString &url, const QString &context) {
  935. const auto channelPrefix = u"channel"_q;
  936. const auto joinPrefix = u"join_link"_q;
  937. const auto webpagePrefix = u"webpage"_q;
  938. const auto viewerPrefix = u"viewer"_q;
  939. if (context == u"report-iv") {
  940. _events.fire({
  941. .type = Event::Type::Report,
  942. .context = QString::number(compuseCurrentPageId()),
  943. });
  944. } else if (context.startsWith(channelPrefix)) {
  945. _events.fire({
  946. .type = Event::Type::OpenChannel,
  947. .context = context.mid(channelPrefix.size()),
  948. });
  949. } else if (context.startsWith(joinPrefix)) {
  950. _events.fire({
  951. .type = Event::Type::JoinChannel,
  952. .context = context.mid(joinPrefix.size()),
  953. });
  954. } else if (context.startsWith(webpagePrefix)) {
  955. _events.fire({
  956. .type = Event::Type::OpenPage,
  957. .url = url,
  958. .context = context.mid(webpagePrefix.size()),
  959. });
  960. } else if (context.startsWith(viewerPrefix)) {
  961. _events.fire({
  962. .type = Event::Type::OpenMedia,
  963. .url = url,
  964. .context = context.mid(viewerPrefix.size()),
  965. });
  966. } else if (context.isEmpty()) {
  967. _events.fire({ .type = Event::Type::OpenLink, .url = url });
  968. }
  969. }
  970. bool Controller::active() const {
  971. return _window && _window->isActiveWindow();
  972. }
  973. void Controller::showJoinedTooltip() {
  974. if (_webview && _ready) {
  975. _webview->eval("IV.showTooltip('"
  976. + Ui::EscapeForScriptString(
  977. tr::lng_action_you_joined(tr::now).toUtf8())
  978. + "');");
  979. }
  980. }
  981. void Controller::minimize() {
  982. if (_window) {
  983. _window->setWindowState(_window->windowState()
  984. | Qt::WindowMinimized);
  985. }
  986. }
  987. QString Controller::composeCurrentUrl() const {
  988. const auto index = _index.current();
  989. Assert(index >= 0 && index < _pages.size());
  990. return _pages[index].url
  991. + (_hash.isEmpty() ? u""_q : ('#' + _hash));
  992. }
  993. uint64 Controller::compuseCurrentPageId() const {
  994. const auto index = _index.current();
  995. Assert(index >= 0 && index < _pages.size());
  996. return _pages[index].pageId;
  997. }
  998. void Controller::showMenu() {
  999. const auto index = _index.current();
  1000. if (_menu || index < 0 || index > _pages.size()) {
  1001. return;
  1002. }
  1003. _menu = base::make_unique_q<Ui::PopupMenu>(
  1004. _window.get(),
  1005. st::popupMenuWithIcons);
  1006. if (_webview && _ready) {
  1007. _webview->eval("IV.menuShown(true);");
  1008. }
  1009. _menu->setDestroyedCallback(crl::guard(_window.get(), [
  1010. this,
  1011. weakButton = Ui::MakeWeak(_menuToggle.data()),
  1012. menu = _menu.get()] {
  1013. if (_menu == menu && weakButton) {
  1014. weakButton->setForceRippled(false);
  1015. }
  1016. if (const auto widget = _webview ? _webview->widget() : nullptr) {
  1017. InvokeQueued(widget, crl::guard(_window.get(), [=] {
  1018. if (_webview && _ready) {
  1019. _webview->eval("IV.menuShown(false);");
  1020. }
  1021. }));
  1022. }
  1023. }));
  1024. _menuToggle->setForceRippled(true);
  1025. const auto url = composeCurrentUrl();
  1026. const auto openInBrowser = crl::guard(_window.get(), [=] {
  1027. _events.fire({ .type = Event::Type::OpenLinkExternal, .url = url });
  1028. });
  1029. _menu->addAction(
  1030. tr::lng_iv_open_in_browser(tr::now),
  1031. openInBrowser,
  1032. &st::menuIconIpAddress);
  1033. _menu->addAction(tr::lng_iv_share(tr::now), [=] {
  1034. showShareMenu();
  1035. }, &st::menuIconShare);
  1036. _menu->addSeparator();
  1037. _menu->addAction(
  1038. base::make_unique_q<ItemZoom>(_menu, _delegate, _menu->menu()->st()));
  1039. _menu->setForcedOrigin(Ui::PanelAnimation::Origin::TopRight);
  1040. _menu->popup(_window->body()->mapToGlobal(
  1041. QPoint(_window->body()->width(), 0) + st::ivMenuPosition));
  1042. }
  1043. void Controller::escape() {
  1044. if (const auto onstack = _shareHide) {
  1045. onstack();
  1046. } else {
  1047. close();
  1048. }
  1049. }
  1050. void Controller::close() {
  1051. _events.fire({ Event::Type::Close });
  1052. }
  1053. void Controller::quit() {
  1054. _events.fire({ Event::Type::Quit });
  1055. }
  1056. rpl::lifetime &Controller::lifetime() {
  1057. return _lifetime;
  1058. }
  1059. void Controller::destroyShareMenu() {
  1060. _shareHide = nullptr;
  1061. if (_shareFocus) {
  1062. _shareFocus = nullptr;
  1063. setInnerFocus();
  1064. }
  1065. if (_shareWrap) {
  1066. if (_shareContainer) {
  1067. _shareWrap->windowHandle()->setParent(nullptr);
  1068. }
  1069. _shareWrap = nullptr;
  1070. _shareContainer = nullptr;
  1071. }
  1072. if (_shareHidesContent) {
  1073. _shareHidesContent = false;
  1074. if (const auto content = _webview ? _webview->widget() : nullptr) {
  1075. content->show();
  1076. }
  1077. }
  1078. }
  1079. void Controller::showShareMenu() {
  1080. const auto index = _index.current();
  1081. if (_shareWrap || index < 0 || index > _pages.size()) {
  1082. return;
  1083. }
  1084. _shareHidesContent = Platform::IsMac();
  1085. if (_shareHidesContent) {
  1086. if (const auto content = _webview ? _webview->widget() : nullptr) {
  1087. content->hide();
  1088. }
  1089. }
  1090. _shareWrap = std::make_unique<Ui::RpWidget>(_shareHidesContent
  1091. ? _window->body().get()
  1092. : nullptr);
  1093. if (!_shareHidesContent) {
  1094. _shareWrap->setGeometry(_window->body()->rect());
  1095. _shareWrap->setWindowFlag(Qt::FramelessWindowHint);
  1096. _shareWrap->setAttribute(Qt::WA_TranslucentBackground);
  1097. _shareWrap->setAttribute(Qt::WA_NoSystemBackground);
  1098. _shareWrap->createWinId();
  1099. _shareContainer.reset(QWidget::createWindowContainer(
  1100. _shareWrap->windowHandle(),
  1101. _window->body().get(),
  1102. Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint));
  1103. }
  1104. _window->body()->sizeValue() | rpl::start_with_next([=](QSize size) {
  1105. const auto widget = _shareHidesContent
  1106. ? _shareWrap.get()
  1107. : _shareContainer.get();
  1108. widget->setGeometry(QRect(QPoint(), size));
  1109. }, _shareWrap->lifetime());
  1110. auto result = _showShareBox({
  1111. .parent = _shareWrap.get(),
  1112. .url = composeCurrentUrl(),
  1113. });
  1114. _shareFocus = result.focus;
  1115. _shareHide = result.hide;
  1116. std::move(result.destroyRequests) | rpl::start_with_next([=] {
  1117. destroyShareMenu();
  1118. }, _shareWrap->lifetime());
  1119. Ui::ForceFullRepaintSync(_shareWrap.get());
  1120. if (_shareHidesContent) {
  1121. _shareWrap->show();
  1122. } else {
  1123. _shareContainer->show();
  1124. }
  1125. activate();
  1126. }
  1127. } // namespace Iv