electron_api_base_window.cc 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. // Copyright (c) 2018 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/api/electron_api_base_window.h"
  5. #include <algorithm>
  6. #include <string>
  7. #include <utility>
  8. #include <vector>
  9. #include "base/containers/contains.h"
  10. #include "base/task/single_thread_task_runner.h"
  11. #include "content/public/common/color_parser.h"
  12. #include "electron/buildflags/buildflags.h"
  13. #include "gin/dictionary.h"
  14. #include "gin/handle.h"
  15. #include "shell/browser/api/electron_api_menu.h"
  16. #include "shell/browser/api/electron_api_view.h"
  17. #include "shell/browser/api/electron_api_web_contents.h"
  18. #include "shell/browser/javascript_environment.h"
  19. #include "shell/browser/native_window.h"
  20. #include "shell/common/color_util.h"
  21. #include "shell/common/gin_converters/callback_converter.h"
  22. #include "shell/common/gin_converters/file_path_converter.h"
  23. #include "shell/common/gin_converters/gfx_converter.h"
  24. #include "shell/common/gin_converters/image_converter.h"
  25. #include "shell/common/gin_converters/native_window_converter.h"
  26. #include "shell/common/gin_converters/optional_converter.h"
  27. #include "shell/common/gin_converters/value_converter.h"
  28. #include "shell/common/gin_helper/dictionary.h"
  29. #include "shell/common/gin_helper/object_template_builder.h"
  30. #include "shell/common/gin_helper/persistent_dictionary.h"
  31. #include "shell/common/node_includes.h"
  32. #include "shell/common/options_switches.h"
  33. #if defined(TOOLKIT_VIEWS)
  34. #include "shell/browser/native_window_views.h"
  35. #endif
  36. #if BUILDFLAG(IS_WIN)
  37. #include "shell/browser/ui/views/win_frame_view.h"
  38. #include "shell/browser/ui/win/taskbar_host.h"
  39. #include "ui/base/win/shell.h"
  40. #elif BUILDFLAG(IS_LINUX)
  41. #include "shell/browser/ui/views/opaque_frame_view.h"
  42. #endif
  43. #if BUILDFLAG(IS_WIN)
  44. namespace gin {
  45. template <>
  46. struct Converter<electron::TaskbarHost::ThumbarButton> {
  47. static bool FromV8(v8::Isolate* isolate,
  48. v8::Local<v8::Value> val,
  49. electron::TaskbarHost::ThumbarButton* out) {
  50. gin::Dictionary dict(isolate);
  51. if (!gin::ConvertFromV8(isolate, val, &dict))
  52. return false;
  53. dict.Get("click", &(out->clicked_callback));
  54. dict.Get("tooltip", &(out->tooltip));
  55. dict.Get("flags", &out->flags);
  56. return dict.Get("icon", &(out->icon));
  57. }
  58. };
  59. } // namespace gin
  60. #endif
  61. namespace electron::api {
  62. namespace {
  63. // Converts binary data to Buffer.
  64. v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
  65. auto buffer = node::Buffer::Copy(isolate, static_cast<char*>(val), size);
  66. if (buffer.IsEmpty())
  67. return v8::Null(isolate);
  68. else
  69. return buffer.ToLocalChecked();
  70. }
  71. } // namespace
  72. BaseWindow::BaseWindow(v8::Isolate* isolate,
  73. const gin_helper::Dictionary& options) {
  74. // The parent window.
  75. gin::Handle<BaseWindow> parent;
  76. if (options.Get("parent", &parent) && !parent.IsEmpty())
  77. parent_window_.Reset(isolate, parent.ToV8());
  78. // Offscreen windows are always created frameless.
  79. gin_helper::Dictionary web_preferences;
  80. bool offscreen;
  81. if (options.Get(options::kWebPreferences, &web_preferences) &&
  82. web_preferences.Get(options::kOffscreen, &offscreen) && offscreen) {
  83. const_cast<gin_helper::Dictionary&>(options).Set(options::kFrame, false);
  84. }
  85. // Creates NativeWindow.
  86. window_ = NativeWindow::Create(
  87. options, parent.IsEmpty() ? nullptr : parent->window_.get());
  88. window_->AddObserver(this);
  89. SetContentView(View::Create(isolate));
  90. #if defined(TOOLKIT_VIEWS)
  91. v8::Local<v8::Value> icon;
  92. if (options.Get(options::kIcon, &icon)) {
  93. SetIconImpl(isolate, icon, NativeImage::OnConvertError::kWarn);
  94. }
  95. #endif
  96. }
  97. BaseWindow::BaseWindow(gin_helper::Arguments* args,
  98. const gin_helper::Dictionary& options)
  99. : BaseWindow(args->isolate(), options) {
  100. InitWithArgs(args);
  101. // Init window after everything has been setup.
  102. window()->InitFromOptions(options);
  103. }
  104. BaseWindow::~BaseWindow() {
  105. CloseImmediately();
  106. // Destroy the native window in next tick because the native code might be
  107. // iterating all windows.
  108. base::SingleThreadTaskRunner::GetCurrentDefault()->DeleteSoon(
  109. FROM_HERE, window_.release());
  110. // Remove global reference so the JS object can be garbage collected.
  111. self_ref_.Reset();
  112. }
  113. void BaseWindow::InitWith(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) {
  114. AttachAsUserData(window_.get());
  115. gin_helper::TrackableObject<BaseWindow>::InitWith(isolate, wrapper);
  116. // We can only append this window to parent window's child windows after this
  117. // window's JS wrapper gets initialized.
  118. if (!parent_window_.IsEmpty()) {
  119. gin::Handle<BaseWindow> parent;
  120. gin::ConvertFromV8(isolate, GetParentWindow(), &parent);
  121. DCHECK(!parent.IsEmpty());
  122. parent->child_windows_.Set(isolate, weak_map_id(), wrapper);
  123. }
  124. // Reference this object in case it got garbage collected.
  125. self_ref_.Reset(isolate, wrapper);
  126. }
  127. void BaseWindow::WillCloseWindow(bool* prevent_default) {
  128. if (Emit("close")) {
  129. *prevent_default = true;
  130. }
  131. }
  132. void BaseWindow::OnWindowClosed() {
  133. // Invalidate weak ptrs before the Javascript object is destroyed,
  134. // there might be some delayed emit events which shouldn't be
  135. // triggered after this.
  136. weak_factory_.InvalidateWeakPtrs();
  137. RemoveFromWeakMap();
  138. window_->RemoveObserver(this);
  139. // We can not call Destroy here because we need to call Emit first, but we
  140. // also do not want any method to be used, so just mark as destroyed here.
  141. MarkDestroyed();
  142. Emit("closed");
  143. RemoveFromParentChildWindows();
  144. // Destroy the native class when window is closed.
  145. base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
  146. FROM_HERE, GetDestroyClosure());
  147. }
  148. void BaseWindow::OnWindowQueryEndSession(
  149. const std::vector<std::string>& reasons,
  150. bool* prevent_default) {
  151. v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
  152. v8::HandleScope handle_scope(isolate);
  153. gin::Handle<gin_helper::internal::Event> event =
  154. gin_helper::internal::Event::New(isolate);
  155. v8::Local<v8::Object> event_object = event.ToV8().As<v8::Object>();
  156. gin::Dictionary dict(isolate, event_object);
  157. dict.Set("reasons", reasons);
  158. EmitWithoutEvent("query-session-end", event);
  159. if (event->GetDefaultPrevented()) {
  160. *prevent_default = true;
  161. }
  162. }
  163. void BaseWindow::OnWindowEndSession(const std::vector<std::string>& reasons) {
  164. v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
  165. v8::HandleScope handle_scope(isolate);
  166. gin::Handle<gin_helper::internal::Event> event =
  167. gin_helper::internal::Event::New(isolate);
  168. v8::Local<v8::Object> event_object = event.ToV8().As<v8::Object>();
  169. gin::Dictionary dict(isolate, event_object);
  170. dict.Set("reasons", reasons);
  171. EmitWithoutEvent("session-end", event);
  172. }
  173. void BaseWindow::OnWindowBlur() {
  174. EmitEventSoon("blur");
  175. }
  176. void BaseWindow::OnWindowFocus() {
  177. EmitEventSoon("focus");
  178. }
  179. void BaseWindow::OnWindowShow() {
  180. Emit("show");
  181. }
  182. void BaseWindow::OnWindowHide() {
  183. Emit("hide");
  184. }
  185. void BaseWindow::OnWindowMaximize() {
  186. Emit("maximize");
  187. }
  188. void BaseWindow::OnWindowUnmaximize() {
  189. Emit("unmaximize");
  190. }
  191. void BaseWindow::OnWindowMinimize() {
  192. Emit("minimize");
  193. }
  194. void BaseWindow::OnWindowRestore() {
  195. Emit("restore");
  196. }
  197. void BaseWindow::OnWindowWillResize(const gfx::Rect& new_bounds,
  198. const gfx::ResizeEdge& edge,
  199. bool* prevent_default) {
  200. v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
  201. v8::HandleScope handle_scope(isolate);
  202. auto info = gin::Dictionary::CreateEmpty(isolate);
  203. info.Set("edge", edge);
  204. if (Emit("will-resize", new_bounds, info)) {
  205. *prevent_default = true;
  206. }
  207. }
  208. void BaseWindow::OnWindowResize() {
  209. Emit("resize");
  210. }
  211. void BaseWindow::OnWindowResized() {
  212. Emit("resized");
  213. }
  214. void BaseWindow::OnWindowWillMove(const gfx::Rect& new_bounds,
  215. bool* prevent_default) {
  216. if (Emit("will-move", new_bounds)) {
  217. *prevent_default = true;
  218. }
  219. }
  220. void BaseWindow::OnWindowMove() {
  221. Emit("move");
  222. }
  223. void BaseWindow::OnWindowMoved() {
  224. Emit("moved");
  225. }
  226. void BaseWindow::OnWindowEnterFullScreen() {
  227. Emit("enter-full-screen");
  228. }
  229. void BaseWindow::OnWindowLeaveFullScreen() {
  230. Emit("leave-full-screen");
  231. }
  232. void BaseWindow::OnWindowSwipe(const std::string& direction) {
  233. Emit("swipe", direction);
  234. }
  235. void BaseWindow::OnWindowRotateGesture(float rotation) {
  236. Emit("rotate-gesture", rotation);
  237. }
  238. void BaseWindow::OnWindowSheetBegin() {
  239. Emit("sheet-begin");
  240. }
  241. void BaseWindow::OnWindowSheetEnd() {
  242. Emit("sheet-end");
  243. }
  244. void BaseWindow::OnWindowEnterHtmlFullScreen() {
  245. Emit("enter-html-full-screen");
  246. }
  247. void BaseWindow::OnWindowLeaveHtmlFullScreen() {
  248. Emit("leave-html-full-screen");
  249. }
  250. void BaseWindow::OnWindowAlwaysOnTopChanged() {
  251. Emit("always-on-top-changed", IsAlwaysOnTop());
  252. }
  253. void BaseWindow::OnExecuteAppCommand(const std::string_view command_name) {
  254. Emit("app-command", command_name);
  255. }
  256. void BaseWindow::OnTouchBarItemResult(const std::string& item_id,
  257. const base::Value::Dict& details) {
  258. Emit("-touch-bar-interaction", item_id, details);
  259. }
  260. void BaseWindow::OnNewWindowForTab() {
  261. Emit("new-window-for-tab");
  262. }
  263. void BaseWindow::OnSystemContextMenu(int x, int y, bool* prevent_default) {
  264. if (Emit("system-context-menu", gfx::Point(x, y))) {
  265. *prevent_default = true;
  266. }
  267. }
  268. #if BUILDFLAG(IS_WIN)
  269. void BaseWindow::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
  270. if (IsWindowMessageHooked(message)) {
  271. v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
  272. v8::HandleScope scope(isolate);
  273. messages_callback_map_[message].Run(
  274. ToBuffer(isolate, static_cast<void*>(&w_param), sizeof(WPARAM)),
  275. ToBuffer(isolate, static_cast<void*>(&l_param), sizeof(LPARAM)));
  276. }
  277. }
  278. #endif
  279. void BaseWindow::SetContentView(gin::Handle<View> view) {
  280. content_view_.Reset(JavascriptEnvironment::GetIsolate(), view.ToV8());
  281. window_->SetContentView(view->view());
  282. }
  283. void BaseWindow::CloseImmediately() {
  284. if (!window_->IsClosed())
  285. window_->CloseImmediately();
  286. }
  287. void BaseWindow::Close() {
  288. window_->Close();
  289. }
  290. void BaseWindow::Focus() {
  291. window_->Focus(true);
  292. }
  293. void BaseWindow::Blur() {
  294. window_->Focus(false);
  295. }
  296. bool BaseWindow::IsFocused() const {
  297. return window_->IsFocused();
  298. }
  299. void BaseWindow::Show() {
  300. window_->Show();
  301. }
  302. void BaseWindow::ShowInactive() {
  303. // This method doesn't make sense for modal window.
  304. if (IsModal())
  305. return;
  306. window_->ShowInactive();
  307. }
  308. void BaseWindow::Hide() {
  309. window_->Hide();
  310. }
  311. bool BaseWindow::IsVisible() const {
  312. return window_->IsVisible();
  313. }
  314. bool BaseWindow::IsEnabled() const {
  315. return window_->IsEnabled();
  316. }
  317. void BaseWindow::SetEnabled(bool enable) {
  318. window_->SetEnabled(enable);
  319. }
  320. void BaseWindow::Maximize() {
  321. window_->Maximize();
  322. }
  323. void BaseWindow::Unmaximize() {
  324. window_->Unmaximize();
  325. }
  326. bool BaseWindow::IsMaximized() const {
  327. return window_->IsMaximized();
  328. }
  329. void BaseWindow::Minimize() {
  330. window_->Minimize();
  331. }
  332. void BaseWindow::Restore() {
  333. window_->Restore();
  334. }
  335. bool BaseWindow::IsMinimized() const {
  336. return window_->IsMinimized();
  337. }
  338. void BaseWindow::SetFullScreen(bool fullscreen) {
  339. window_->SetFullScreen(fullscreen);
  340. }
  341. bool BaseWindow::IsFullscreen() const {
  342. return window_->IsFullscreen();
  343. }
  344. void BaseWindow::SetBounds(const gfx::Rect& bounds,
  345. gin_helper::Arguments* args) {
  346. bool animate = false;
  347. args->GetNext(&animate);
  348. window_->SetBounds(bounds, animate);
  349. }
  350. gfx::Rect BaseWindow::GetBounds() const {
  351. return window_->GetBounds();
  352. }
  353. bool BaseWindow::IsNormal() const {
  354. return window_->IsNormal();
  355. }
  356. gfx::Rect BaseWindow::GetNormalBounds() const {
  357. return window_->GetNormalBounds();
  358. }
  359. void BaseWindow::SetContentBounds(const gfx::Rect& bounds,
  360. gin_helper::Arguments* args) {
  361. bool animate = false;
  362. args->GetNext(&animate);
  363. window_->SetContentBounds(bounds, animate);
  364. }
  365. gfx::Rect BaseWindow::GetContentBounds() const {
  366. return window_->GetContentBounds();
  367. }
  368. void BaseWindow::SetSize(int width, int height, gin_helper::Arguments* args) {
  369. bool animate = false;
  370. gfx::Size size = window_->GetMinimumSize();
  371. size.SetToMax(gfx::Size(width, height));
  372. args->GetNext(&animate);
  373. window_->SetSize(size, animate);
  374. }
  375. std::vector<int> BaseWindow::GetSize() const {
  376. std::vector<int> result(2);
  377. gfx::Size size = window_->GetSize();
  378. result[0] = size.width();
  379. result[1] = size.height();
  380. return result;
  381. }
  382. void BaseWindow::SetContentSize(int width,
  383. int height,
  384. gin_helper::Arguments* args) {
  385. bool animate = false;
  386. args->GetNext(&animate);
  387. window_->SetContentSize(gfx::Size(width, height), animate);
  388. }
  389. std::vector<int> BaseWindow::GetContentSize() const {
  390. std::vector<int> result(2);
  391. gfx::Size size = window_->GetContentSize();
  392. result[0] = size.width();
  393. result[1] = size.height();
  394. return result;
  395. }
  396. void BaseWindow::SetMinimumSize(int width, int height) {
  397. window_->SetMinimumSize(gfx::Size(width, height));
  398. }
  399. std::vector<int> BaseWindow::GetMinimumSize() const {
  400. std::vector<int> result(2);
  401. gfx::Size size = window_->GetMinimumSize();
  402. result[0] = size.width();
  403. result[1] = size.height();
  404. return result;
  405. }
  406. void BaseWindow::SetMaximumSize(int width, int height) {
  407. window_->SetMaximumSize(gfx::Size(width, height));
  408. }
  409. std::vector<int> BaseWindow::GetMaximumSize() const {
  410. std::vector<int> result(2);
  411. gfx::Size size = window_->GetMaximumSize();
  412. result[0] = size.width();
  413. result[1] = size.height();
  414. return result;
  415. }
  416. void BaseWindow::SetSheetOffset(double offsetY, gin_helper::Arguments* args) {
  417. double offsetX = 0.0;
  418. args->GetNext(&offsetX);
  419. window_->SetSheetOffset(offsetX, offsetY);
  420. }
  421. void BaseWindow::SetResizable(bool resizable) {
  422. window_->SetResizable(resizable);
  423. }
  424. bool BaseWindow::IsResizable() const {
  425. return window_->IsResizable();
  426. }
  427. void BaseWindow::SetMovable(bool movable) {
  428. window_->SetMovable(movable);
  429. }
  430. bool BaseWindow::IsMovable() const {
  431. return window_->IsMovable();
  432. }
  433. void BaseWindow::SetMinimizable(bool minimizable) {
  434. window_->SetMinimizable(minimizable);
  435. }
  436. bool BaseWindow::IsMinimizable() const {
  437. return window_->IsMinimizable();
  438. }
  439. void BaseWindow::SetMaximizable(bool maximizable) {
  440. window_->SetMaximizable(maximizable);
  441. }
  442. bool BaseWindow::IsMaximizable() const {
  443. return window_->IsMaximizable();
  444. }
  445. void BaseWindow::SetFullScreenable(bool fullscreenable) {
  446. window_->SetFullScreenable(fullscreenable);
  447. }
  448. bool BaseWindow::IsFullScreenable() const {
  449. return window_->IsFullScreenable();
  450. }
  451. void BaseWindow::SetClosable(bool closable) {
  452. window_->SetClosable(closable);
  453. }
  454. bool BaseWindow::IsClosable() const {
  455. return window_->IsClosable();
  456. }
  457. void BaseWindow::SetAlwaysOnTop(bool top, gin_helper::Arguments* args) {
  458. std::string level = "floating";
  459. int relative_level = 0;
  460. args->GetNext(&level);
  461. args->GetNext(&relative_level);
  462. ui::ZOrderLevel z_order =
  463. top ? ui::ZOrderLevel::kFloatingWindow : ui::ZOrderLevel::kNormal;
  464. window_->SetAlwaysOnTop(z_order, level, relative_level);
  465. }
  466. bool BaseWindow::IsAlwaysOnTop() const {
  467. return window_->GetZOrderLevel() != ui::ZOrderLevel::kNormal;
  468. }
  469. void BaseWindow::Center() {
  470. window_->Center();
  471. }
  472. void BaseWindow::SetPosition(int x, int y, gin_helper::Arguments* args) {
  473. bool animate = false;
  474. args->GetNext(&animate);
  475. window_->SetPosition(gfx::Point(x, y), animate);
  476. }
  477. std::vector<int> BaseWindow::GetPosition() const {
  478. std::vector<int> result(2);
  479. gfx::Point pos = window_->GetPosition();
  480. result[0] = pos.x();
  481. result[1] = pos.y();
  482. return result;
  483. }
  484. void BaseWindow::MoveAbove(const std::string& sourceId,
  485. gin_helper::Arguments* args) {
  486. if (!window_->MoveAbove(sourceId))
  487. args->ThrowError("Invalid media source id");
  488. }
  489. void BaseWindow::MoveTop() {
  490. window_->MoveTop();
  491. }
  492. void BaseWindow::SetTitle(const std::string& title) {
  493. window_->SetTitle(title);
  494. }
  495. std::string BaseWindow::GetTitle() const {
  496. return window_->GetTitle();
  497. }
  498. void BaseWindow::SetAccessibleTitle(const std::string& title) {
  499. window_->SetAccessibleTitle(title);
  500. }
  501. std::string BaseWindow::GetAccessibleTitle() const {
  502. return window_->GetAccessibleTitle();
  503. }
  504. void BaseWindow::FlashFrame(bool flash) {
  505. window_->FlashFrame(flash);
  506. }
  507. void BaseWindow::SetSkipTaskbar(bool skip) {
  508. window_->SetSkipTaskbar(skip);
  509. }
  510. void BaseWindow::SetExcludedFromShownWindowsMenu(bool excluded) {
  511. window_->SetExcludedFromShownWindowsMenu(excluded);
  512. }
  513. bool BaseWindow::IsExcludedFromShownWindowsMenu() const {
  514. return window_->IsExcludedFromShownWindowsMenu();
  515. }
  516. void BaseWindow::SetSimpleFullScreen(bool simple_fullscreen) {
  517. window_->SetSimpleFullScreen(simple_fullscreen);
  518. }
  519. bool BaseWindow::IsSimpleFullScreen() const {
  520. return window_->IsSimpleFullScreen();
  521. }
  522. void BaseWindow::SetKiosk(bool kiosk) {
  523. window_->SetKiosk(kiosk);
  524. }
  525. bool BaseWindow::IsKiosk() const {
  526. return window_->IsKiosk();
  527. }
  528. bool BaseWindow::IsTabletMode() const {
  529. return window_->IsTabletMode();
  530. }
  531. void BaseWindow::SetBackgroundColor(const std::string& color_name) {
  532. SkColor color = ParseCSSColor(color_name);
  533. window_->SetBackgroundColor(color);
  534. }
  535. std::string BaseWindow::GetBackgroundColor() const {
  536. return ToRGBHex(window_->GetBackgroundColor());
  537. }
  538. void BaseWindow::InvalidateShadow() {
  539. window_->InvalidateShadow();
  540. }
  541. void BaseWindow::SetHasShadow(bool has_shadow) {
  542. window_->SetHasShadow(has_shadow);
  543. }
  544. bool BaseWindow::HasShadow() const {
  545. return window_->HasShadow();
  546. }
  547. void BaseWindow::SetOpacity(const double opacity) {
  548. window_->SetOpacity(opacity);
  549. }
  550. double BaseWindow::GetOpacity() const {
  551. return window_->GetOpacity();
  552. }
  553. void BaseWindow::SetShape(const std::vector<gfx::Rect>& rects) {
  554. window_->widget()->SetShape(std::make_unique<std::vector<gfx::Rect>>(rects));
  555. }
  556. void BaseWindow::SetRepresentedFilename(const std::string& filename) {
  557. window_->SetRepresentedFilename(filename);
  558. }
  559. std::string BaseWindow::GetRepresentedFilename() const {
  560. return window_->GetRepresentedFilename();
  561. }
  562. void BaseWindow::SetDocumentEdited(bool edited) {
  563. window_->SetDocumentEdited(edited);
  564. }
  565. bool BaseWindow::IsDocumentEdited() const {
  566. return window_->IsDocumentEdited();
  567. }
  568. void BaseWindow::SetIgnoreMouseEvents(bool ignore,
  569. gin_helper::Arguments* args) {
  570. gin_helper::Dictionary options;
  571. bool forward = false;
  572. args->GetNext(&options) && options.Get("forward", &forward);
  573. return window_->SetIgnoreMouseEvents(ignore, forward);
  574. }
  575. void BaseWindow::SetContentProtection(bool enable) {
  576. return window_->SetContentProtection(enable);
  577. }
  578. void BaseWindow::SetFocusable(bool focusable) {
  579. return window_->SetFocusable(focusable);
  580. }
  581. bool BaseWindow::IsFocusable() const {
  582. return window_->IsFocusable();
  583. }
  584. void BaseWindow::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
  585. auto context = isolate->GetCurrentContext();
  586. gin::Handle<Menu> menu;
  587. v8::Local<v8::Object> object;
  588. if (value->IsObject() && value->ToObject(context).ToLocal(&object) &&
  589. gin::ConvertFromV8(isolate, value, &menu) && !menu.IsEmpty()) {
  590. // We only want to update the menu if the menu has a non-zero item count,
  591. // or we risk crashes.
  592. if (menu->model()->GetItemCount() == 0) {
  593. RemoveMenu();
  594. } else {
  595. window_->SetMenu(menu->model());
  596. }
  597. menu_.Reset(isolate, menu.ToV8());
  598. } else if (value->IsNull()) {
  599. RemoveMenu();
  600. } else {
  601. isolate->ThrowException(
  602. v8::Exception::TypeError(gin::StringToV8(isolate, "Invalid Menu")));
  603. }
  604. }
  605. void BaseWindow::RemoveMenu() {
  606. menu_.Reset();
  607. window_->SetMenu(nullptr);
  608. }
  609. void BaseWindow::SetParentWindow(v8::Local<v8::Value> value,
  610. gin_helper::Arguments* args) {
  611. if (IsModal()) {
  612. args->ThrowError("Can not be called for modal window");
  613. return;
  614. }
  615. gin::Handle<BaseWindow> parent;
  616. if (value->IsNull() || value->IsUndefined()) {
  617. RemoveFromParentChildWindows();
  618. parent_window_.Reset();
  619. window_->SetParentWindow(nullptr);
  620. } else if (gin::ConvertFromV8(isolate(), value, &parent)) {
  621. RemoveFromParentChildWindows();
  622. parent_window_.Reset(isolate(), value);
  623. window_->SetParentWindow(parent->window_.get());
  624. parent->child_windows_.Set(isolate(), weak_map_id(), GetWrapper());
  625. } else {
  626. args->ThrowError("Must pass BaseWindow instance or null");
  627. }
  628. }
  629. std::string BaseWindow::GetMediaSourceId() const {
  630. return window_->GetDesktopMediaID().ToString();
  631. }
  632. v8::Local<v8::Value> BaseWindow::GetNativeWindowHandle() {
  633. // TODO(MarshallOfSound): Replace once
  634. // https://chromium-review.googlesource.com/c/chromium/src/+/1253094/ has
  635. // landed
  636. NativeWindowHandle handle = window_->GetNativeWindowHandle();
  637. return ToBuffer(isolate(), &handle, sizeof(handle));
  638. }
  639. void BaseWindow::SetProgressBar(double progress, gin_helper::Arguments* args) {
  640. gin_helper::Dictionary options;
  641. std::string mode;
  642. args->GetNext(&options) && options.Get("mode", &mode);
  643. NativeWindow::ProgressState state = NativeWindow::ProgressState::kNormal;
  644. if (mode == "error")
  645. state = NativeWindow::ProgressState::kError;
  646. else if (mode == "paused")
  647. state = NativeWindow::ProgressState::kPaused;
  648. else if (mode == "indeterminate")
  649. state = NativeWindow::ProgressState::kIndeterminate;
  650. else if (mode == "none")
  651. state = NativeWindow::ProgressState::kNone;
  652. window_->SetProgressBar(progress, state);
  653. }
  654. void BaseWindow::SetOverlayIcon(const gfx::Image& overlay,
  655. const std::string& description) {
  656. window_->SetOverlayIcon(overlay, description);
  657. }
  658. void BaseWindow::SetVisibleOnAllWorkspaces(bool visible,
  659. gin_helper::Arguments* args) {
  660. gin_helper::Dictionary options;
  661. bool visibleOnFullScreen = false;
  662. bool skipTransformProcessType = false;
  663. if (args->GetNext(&options)) {
  664. options.Get("visibleOnFullScreen", &visibleOnFullScreen);
  665. options.Get("skipTransformProcessType", &skipTransformProcessType);
  666. }
  667. return window_->SetVisibleOnAllWorkspaces(visible, visibleOnFullScreen,
  668. skipTransformProcessType);
  669. }
  670. bool BaseWindow::IsVisibleOnAllWorkspaces() const {
  671. return window_->IsVisibleOnAllWorkspaces();
  672. }
  673. void BaseWindow::SetAutoHideCursor(bool auto_hide) {
  674. window_->SetAutoHideCursor(auto_hide);
  675. }
  676. void BaseWindow::SetVibrancy(v8::Isolate* isolate,
  677. v8::Local<v8::Value> value,
  678. gin_helper::Arguments* args) {
  679. std::string type = gin::V8ToString(isolate, value);
  680. gin_helper::Dictionary options;
  681. int animation_duration_ms = 0;
  682. if (args->GetNext(&options)) {
  683. options.Get("animationDuration", &animation_duration_ms);
  684. }
  685. window_->SetVibrancy(type, animation_duration_ms);
  686. }
  687. void BaseWindow::SetBackgroundMaterial(const std::string& material_type) {
  688. window_->SetBackgroundMaterial(material_type);
  689. }
  690. #if BUILDFLAG(IS_MAC)
  691. std::string BaseWindow::GetAlwaysOnTopLevel() const {
  692. return window_->GetAlwaysOnTopLevel();
  693. }
  694. void BaseWindow::SetWindowButtonVisibility(bool visible) {
  695. window_->SetWindowButtonVisibility(visible);
  696. }
  697. bool BaseWindow::GetWindowButtonVisibility() const {
  698. return window_->GetWindowButtonVisibility();
  699. }
  700. void BaseWindow::SetWindowButtonPosition(std::optional<gfx::Point> position) {
  701. window_->SetWindowButtonPosition(std::move(position));
  702. }
  703. std::optional<gfx::Point> BaseWindow::GetWindowButtonPosition() const {
  704. return window_->GetWindowButtonPosition();
  705. }
  706. #endif
  707. #if BUILDFLAG(IS_MAC)
  708. bool BaseWindow::IsHiddenInMissionControl() {
  709. return window_->IsHiddenInMissionControl();
  710. }
  711. void BaseWindow::SetHiddenInMissionControl(bool hidden) {
  712. window_->SetHiddenInMissionControl(hidden);
  713. }
  714. #endif
  715. void BaseWindow::SetTouchBar(
  716. std::vector<gin_helper::PersistentDictionary> items) {
  717. window_->SetTouchBar(std::move(items));
  718. }
  719. void BaseWindow::RefreshTouchBarItem(const std::string& item_id) {
  720. window_->RefreshTouchBarItem(item_id);
  721. }
  722. void BaseWindow::SetEscapeTouchBarItem(gin_helper::PersistentDictionary item) {
  723. window_->SetEscapeTouchBarItem(std::move(item));
  724. }
  725. void BaseWindow::SelectPreviousTab() {
  726. window_->SelectPreviousTab();
  727. }
  728. void BaseWindow::SelectNextTab() {
  729. window_->SelectNextTab();
  730. }
  731. void BaseWindow::ShowAllTabs() {
  732. window_->ShowAllTabs();
  733. }
  734. void BaseWindow::MergeAllWindows() {
  735. window_->MergeAllWindows();
  736. }
  737. void BaseWindow::MoveTabToNewWindow() {
  738. window_->MoveTabToNewWindow();
  739. }
  740. void BaseWindow::ToggleTabBar() {
  741. window_->ToggleTabBar();
  742. }
  743. void BaseWindow::AddTabbedWindow(NativeWindow* window,
  744. gin_helper::Arguments* args) {
  745. if (!window_->AddTabbedWindow(window))
  746. args->ThrowError("AddTabbedWindow cannot be called by a window on itself.");
  747. }
  748. v8::Local<v8::Value> BaseWindow::GetTabbingIdentifier() {
  749. auto tabbing_id = window_->GetTabbingIdentifier();
  750. if (!tabbing_id.has_value())
  751. return v8::Undefined(isolate());
  752. return gin::ConvertToV8(isolate(), tabbing_id.value());
  753. }
  754. void BaseWindow::SetAutoHideMenuBar(bool auto_hide) {
  755. window_->SetAutoHideMenuBar(auto_hide);
  756. }
  757. bool BaseWindow::IsMenuBarAutoHide() const {
  758. return window_->IsMenuBarAutoHide();
  759. }
  760. void BaseWindow::SetMenuBarVisibility(bool visible) {
  761. window_->SetMenuBarVisibility(visible);
  762. }
  763. bool BaseWindow::IsMenuBarVisible() const {
  764. return window_->IsMenuBarVisible();
  765. }
  766. void BaseWindow::SetAspectRatio(double aspect_ratio,
  767. gin_helper::Arguments* args) {
  768. gfx::Size extra_size;
  769. args->GetNext(&extra_size);
  770. window_->SetAspectRatio(aspect_ratio, extra_size);
  771. }
  772. void BaseWindow::PreviewFile(const std::string& path,
  773. gin_helper::Arguments* args) {
  774. std::string display_name;
  775. if (!args->GetNext(&display_name))
  776. display_name = path;
  777. window_->PreviewFile(path, display_name);
  778. }
  779. void BaseWindow::CloseFilePreview() {
  780. window_->CloseFilePreview();
  781. }
  782. void BaseWindow::SetGTKDarkThemeEnabled(bool use_dark_theme) {
  783. window_->SetGTKDarkThemeEnabled(use_dark_theme);
  784. }
  785. v8::Local<v8::Value> BaseWindow::GetContentView() const {
  786. if (content_view_.IsEmpty())
  787. return v8::Null(isolate());
  788. else
  789. return v8::Local<v8::Value>::New(isolate(), content_view_);
  790. }
  791. v8::Local<v8::Value> BaseWindow::GetParentWindow() const {
  792. if (parent_window_.IsEmpty())
  793. return v8::Null(isolate());
  794. else
  795. return v8::Local<v8::Value>::New(isolate(), parent_window_);
  796. }
  797. std::vector<v8::Local<v8::Object>> BaseWindow::GetChildWindows() const {
  798. return child_windows_.Values(isolate());
  799. }
  800. bool BaseWindow::IsModal() const {
  801. return window_->is_modal();
  802. }
  803. bool BaseWindow::SetThumbarButtons(gin_helper::Arguments* args) {
  804. #if BUILDFLAG(IS_WIN)
  805. std::vector<TaskbarHost::ThumbarButton> buttons;
  806. if (!args->GetNext(&buttons)) {
  807. args->ThrowError();
  808. return false;
  809. }
  810. auto* window = static_cast<NativeWindowViews*>(window_.get());
  811. return window->taskbar_host().SetThumbarButtons(
  812. window_->GetAcceleratedWidget(), buttons);
  813. #else
  814. return false;
  815. #endif
  816. }
  817. #if defined(TOOLKIT_VIEWS)
  818. void BaseWindow::SetIcon(v8::Isolate* isolate, v8::Local<v8::Value> icon) {
  819. SetIconImpl(isolate, icon, NativeImage::OnConvertError::kThrow);
  820. }
  821. void BaseWindow::SetIconImpl(v8::Isolate* isolate,
  822. v8::Local<v8::Value> icon,
  823. NativeImage::OnConvertError on_error) {
  824. NativeImage* native_image = nullptr;
  825. if (!NativeImage::TryConvertNativeImage(isolate, icon, &native_image,
  826. on_error))
  827. return;
  828. #if BUILDFLAG(IS_WIN)
  829. static_cast<NativeWindowViews*>(window_.get())
  830. ->SetIcon(native_image->GetHICON(GetSystemMetrics(SM_CXSMICON)),
  831. native_image->GetHICON(GetSystemMetrics(SM_CXICON)));
  832. #elif BUILDFLAG(IS_LINUX)
  833. static_cast<NativeWindowViews*>(window_.get())
  834. ->SetIcon(native_image->image().AsImageSkia());
  835. #endif
  836. }
  837. #endif
  838. #if BUILDFLAG(IS_WIN)
  839. bool BaseWindow::HookWindowMessage(UINT message,
  840. const MessageCallback& callback) {
  841. messages_callback_map_[message] = callback;
  842. return true;
  843. }
  844. void BaseWindow::UnhookWindowMessage(UINT message) {
  845. messages_callback_map_.erase(message);
  846. }
  847. bool BaseWindow::IsWindowMessageHooked(UINT message) {
  848. return base::Contains(messages_callback_map_, message);
  849. }
  850. void BaseWindow::UnhookAllWindowMessages() {
  851. messages_callback_map_.clear();
  852. }
  853. bool BaseWindow::SetThumbnailClip(const gfx::Rect& region) {
  854. auto* window = static_cast<NativeWindowViews*>(window_.get());
  855. return window->taskbar_host().SetThumbnailClip(
  856. window_->GetAcceleratedWidget(), region);
  857. }
  858. bool BaseWindow::SetThumbnailToolTip(const std::string& tooltip) {
  859. auto* window = static_cast<NativeWindowViews*>(window_.get());
  860. return window->taskbar_host().SetThumbnailToolTip(
  861. window_->GetAcceleratedWidget(), tooltip);
  862. }
  863. void BaseWindow::SetAppDetails(const gin_helper::Dictionary& options) {
  864. std::wstring app_id;
  865. base::FilePath app_icon_path;
  866. int app_icon_index = 0;
  867. std::wstring relaunch_command;
  868. std::wstring relaunch_display_name;
  869. options.Get("appId", &app_id);
  870. options.Get("appIconPath", &app_icon_path);
  871. options.Get("appIconIndex", &app_icon_index);
  872. options.Get("relaunchCommand", &relaunch_command);
  873. options.Get("relaunchDisplayName", &relaunch_display_name);
  874. ui::win::SetAppDetailsForWindow(app_id, app_icon_path, app_icon_index,
  875. relaunch_command, relaunch_display_name,
  876. window_->GetAcceleratedWidget());
  877. }
  878. #endif
  879. #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
  880. void BaseWindow::SetTitleBarOverlay(const gin_helper::Dictionary& options,
  881. gin_helper::Arguments* args) {
  882. // Ensure WCO is already enabled on this window
  883. if (!window_->IsWindowControlsOverlayEnabled()) {
  884. args->ThrowError("Titlebar overlay is not enabled");
  885. return;
  886. }
  887. auto* window = static_cast<NativeWindowViews*>(window_.get());
  888. bool updated = false;
  889. // Check and update the button color
  890. std::string btn_color;
  891. if (options.Get(options::kOverlayButtonColor, &btn_color)) {
  892. // Parse the string as a CSS color
  893. SkColor color;
  894. if (!content::ParseCssColorString(btn_color, &color)) {
  895. args->ThrowError("Could not parse color as CSS color");
  896. return;
  897. }
  898. // Update the view
  899. window->set_overlay_button_color(color);
  900. updated = true;
  901. }
  902. // Check and update the symbol color
  903. std::string symbol_color;
  904. if (options.Get(options::kOverlaySymbolColor, &symbol_color)) {
  905. // Parse the string as a CSS color
  906. SkColor color;
  907. if (!content::ParseCssColorString(symbol_color, &color)) {
  908. args->ThrowError("Could not parse symbol color as CSS color");
  909. return;
  910. }
  911. // Update the view
  912. window->set_overlay_symbol_color(color);
  913. updated = true;
  914. }
  915. // Check and update the height
  916. int height = 0;
  917. if (options.Get(options::kOverlayHeight, &height)) {
  918. window->set_titlebar_overlay_height(height);
  919. updated = true;
  920. }
  921. if (!updated)
  922. return;
  923. // If anything was updated, ensure the overlay is repainted.
  924. #if BUILDFLAG(IS_WIN)
  925. auto* frame_view = static_cast<WinFrameView*>(
  926. window->widget()->non_client_view()->frame_view());
  927. #else
  928. auto* frame_view = static_cast<OpaqueFrameView*>(
  929. window->widget()->non_client_view()->frame_view());
  930. #endif
  931. frame_view->InvalidateCaptionButtons();
  932. }
  933. #endif
  934. int32_t BaseWindow::GetID() const {
  935. return weak_map_id();
  936. }
  937. void BaseWindow::RemoveFromParentChildWindows() {
  938. if (parent_window_.IsEmpty())
  939. return;
  940. gin::Handle<BaseWindow> parent;
  941. if (!gin::ConvertFromV8(isolate(), GetParentWindow(), &parent) ||
  942. parent.IsEmpty()) {
  943. return;
  944. }
  945. parent->child_windows_.Remove(weak_map_id());
  946. }
  947. // static
  948. gin_helper::WrappableBase* BaseWindow::New(gin_helper::Arguments* args) {
  949. auto options = gin_helper::Dictionary::CreateEmpty(args->isolate());
  950. args->GetNext(&options);
  951. return new BaseWindow(args, options);
  952. }
  953. // static
  954. void BaseWindow::BuildPrototype(v8::Isolate* isolate,
  955. v8::Local<v8::FunctionTemplate> prototype) {
  956. prototype->SetClassName(gin::StringToV8(isolate, "BaseWindow"));
  957. gin_helper::Destroyable::MakeDestroyable(isolate, prototype);
  958. gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
  959. .SetMethod("setContentView", &BaseWindow::SetContentView)
  960. .SetMethod("close", &BaseWindow::Close)
  961. .SetMethod("focus", &BaseWindow::Focus)
  962. .SetMethod("blur", &BaseWindow::Blur)
  963. .SetMethod("isFocused", &BaseWindow::IsFocused)
  964. .SetMethod("show", &BaseWindow::Show)
  965. .SetMethod("showInactive", &BaseWindow::ShowInactive)
  966. .SetMethod("hide", &BaseWindow::Hide)
  967. .SetMethod("isVisible", &BaseWindow::IsVisible)
  968. .SetMethod("isEnabled", &BaseWindow::IsEnabled)
  969. .SetMethod("setEnabled", &BaseWindow::SetEnabled)
  970. .SetMethod("maximize", &BaseWindow::Maximize)
  971. .SetMethod("unmaximize", &BaseWindow::Unmaximize)
  972. .SetMethod("isMaximized", &BaseWindow::IsMaximized)
  973. .SetMethod("minimize", &BaseWindow::Minimize)
  974. .SetMethod("restore", &BaseWindow::Restore)
  975. .SetMethod("isMinimized", &BaseWindow::IsMinimized)
  976. .SetMethod("setFullScreen", &BaseWindow::SetFullScreen)
  977. .SetMethod("isFullScreen", &BaseWindow::IsFullscreen)
  978. .SetMethod("setBounds", &BaseWindow::SetBounds)
  979. .SetMethod("getBounds", &BaseWindow::GetBounds)
  980. .SetMethod("isNormal", &BaseWindow::IsNormal)
  981. .SetMethod("getNormalBounds", &BaseWindow::GetNormalBounds)
  982. .SetMethod("setSize", &BaseWindow::SetSize)
  983. .SetMethod("getSize", &BaseWindow::GetSize)
  984. .SetMethod("setContentBounds", &BaseWindow::SetContentBounds)
  985. .SetMethod("getContentBounds", &BaseWindow::GetContentBounds)
  986. .SetMethod("setContentSize", &BaseWindow::SetContentSize)
  987. .SetMethod("getContentSize", &BaseWindow::GetContentSize)
  988. .SetMethod("setMinimumSize", &BaseWindow::SetMinimumSize)
  989. .SetMethod("getMinimumSize", &BaseWindow::GetMinimumSize)
  990. .SetMethod("setMaximumSize", &BaseWindow::SetMaximumSize)
  991. .SetMethod("getMaximumSize", &BaseWindow::GetMaximumSize)
  992. .SetMethod("setSheetOffset", &BaseWindow::SetSheetOffset)
  993. .SetMethod("moveAbove", &BaseWindow::MoveAbove)
  994. .SetMethod("moveTop", &BaseWindow::MoveTop)
  995. .SetMethod("setResizable", &BaseWindow::SetResizable)
  996. .SetMethod("isResizable", &BaseWindow::IsResizable)
  997. .SetMethod("setMovable", &BaseWindow::SetMovable)
  998. .SetMethod("isMovable", &BaseWindow::IsMovable)
  999. .SetMethod("setMinimizable", &BaseWindow::SetMinimizable)
  1000. .SetMethod("isMinimizable", &BaseWindow::IsMinimizable)
  1001. .SetMethod("setMaximizable", &BaseWindow::SetMaximizable)
  1002. .SetMethod("isMaximizable", &BaseWindow::IsMaximizable)
  1003. .SetMethod("setFullScreenable", &BaseWindow::SetFullScreenable)
  1004. .SetMethod("isFullScreenable", &BaseWindow::IsFullScreenable)
  1005. .SetMethod("setClosable", &BaseWindow::SetClosable)
  1006. .SetMethod("isClosable", &BaseWindow::IsClosable)
  1007. .SetMethod("setAlwaysOnTop", &BaseWindow::SetAlwaysOnTop)
  1008. .SetMethod("isAlwaysOnTop", &BaseWindow::IsAlwaysOnTop)
  1009. .SetMethod("center", &BaseWindow::Center)
  1010. .SetMethod("setPosition", &BaseWindow::SetPosition)
  1011. .SetMethod("getPosition", &BaseWindow::GetPosition)
  1012. .SetMethod("setTitle", &BaseWindow::SetTitle)
  1013. .SetMethod("getTitle", &BaseWindow::GetTitle)
  1014. .SetProperty("accessibleTitle", &BaseWindow::GetAccessibleTitle,
  1015. &BaseWindow::SetAccessibleTitle)
  1016. .SetMethod("flashFrame", &BaseWindow::FlashFrame)
  1017. .SetMethod("setSkipTaskbar", &BaseWindow::SetSkipTaskbar)
  1018. .SetMethod("setSimpleFullScreen", &BaseWindow::SetSimpleFullScreen)
  1019. .SetMethod("isSimpleFullScreen", &BaseWindow::IsSimpleFullScreen)
  1020. .SetMethod("setKiosk", &BaseWindow::SetKiosk)
  1021. .SetMethod("isKiosk", &BaseWindow::IsKiosk)
  1022. .SetMethod("isTabletMode", &BaseWindow::IsTabletMode)
  1023. .SetMethod("setBackgroundColor", &BaseWindow::SetBackgroundColor)
  1024. .SetMethod("getBackgroundColor", &BaseWindow::GetBackgroundColor)
  1025. .SetMethod("setHasShadow", &BaseWindow::SetHasShadow)
  1026. .SetMethod("hasShadow", &BaseWindow::HasShadow)
  1027. .SetMethod("setOpacity", &BaseWindow::SetOpacity)
  1028. .SetMethod("getOpacity", &BaseWindow::GetOpacity)
  1029. .SetMethod("setShape", &BaseWindow::SetShape)
  1030. .SetMethod("setRepresentedFilename", &BaseWindow::SetRepresentedFilename)
  1031. .SetMethod("getRepresentedFilename", &BaseWindow::GetRepresentedFilename)
  1032. .SetMethod("setDocumentEdited", &BaseWindow::SetDocumentEdited)
  1033. .SetMethod("isDocumentEdited", &BaseWindow::IsDocumentEdited)
  1034. .SetMethod("setIgnoreMouseEvents", &BaseWindow::SetIgnoreMouseEvents)
  1035. .SetMethod("setContentProtection", &BaseWindow::SetContentProtection)
  1036. .SetMethod("setFocusable", &BaseWindow::SetFocusable)
  1037. .SetMethod("isFocusable", &BaseWindow::IsFocusable)
  1038. .SetMethod("setMenu", &BaseWindow::SetMenu)
  1039. .SetMethod("removeMenu", &BaseWindow::RemoveMenu)
  1040. .SetMethod("setParentWindow", &BaseWindow::SetParentWindow)
  1041. .SetMethod("getMediaSourceId", &BaseWindow::GetMediaSourceId)
  1042. .SetMethod("getNativeWindowHandle", &BaseWindow::GetNativeWindowHandle)
  1043. .SetMethod("setProgressBar", &BaseWindow::SetProgressBar)
  1044. .SetMethod("setOverlayIcon", &BaseWindow::SetOverlayIcon)
  1045. .SetMethod("setVisibleOnAllWorkspaces",
  1046. &BaseWindow::SetVisibleOnAllWorkspaces)
  1047. .SetMethod("isVisibleOnAllWorkspaces",
  1048. &BaseWindow::IsVisibleOnAllWorkspaces)
  1049. #if BUILDFLAG(IS_MAC)
  1050. .SetMethod("invalidateShadow", &BaseWindow::InvalidateShadow)
  1051. .SetMethod("_getAlwaysOnTopLevel", &BaseWindow::GetAlwaysOnTopLevel)
  1052. .SetMethod("setAutoHideCursor", &BaseWindow::SetAutoHideCursor)
  1053. #endif
  1054. .SetMethod("setVibrancy", &BaseWindow::SetVibrancy)
  1055. .SetMethod("setBackgroundMaterial", &BaseWindow::SetBackgroundMaterial)
  1056. #if BUILDFLAG(IS_MAC)
  1057. .SetMethod("isHiddenInMissionControl",
  1058. &BaseWindow::IsHiddenInMissionControl)
  1059. .SetMethod("setHiddenInMissionControl",
  1060. &BaseWindow::SetHiddenInMissionControl)
  1061. #endif
  1062. .SetMethod("_setTouchBarItems", &BaseWindow::SetTouchBar)
  1063. .SetMethod("_refreshTouchBarItem", &BaseWindow::RefreshTouchBarItem)
  1064. .SetMethod("_setEscapeTouchBarItem", &BaseWindow::SetEscapeTouchBarItem)
  1065. #if BUILDFLAG(IS_MAC)
  1066. .SetMethod("selectPreviousTab", &BaseWindow::SelectPreviousTab)
  1067. .SetMethod("selectNextTab", &BaseWindow::SelectNextTab)
  1068. .SetMethod("showAllTabs", &BaseWindow::ShowAllTabs)
  1069. .SetMethod("mergeAllWindows", &BaseWindow::MergeAllWindows)
  1070. .SetMethod("moveTabToNewWindow", &BaseWindow::MoveTabToNewWindow)
  1071. .SetMethod("toggleTabBar", &BaseWindow::ToggleTabBar)
  1072. .SetMethod("addTabbedWindow", &BaseWindow::AddTabbedWindow)
  1073. .SetProperty("tabbingIdentifier", &BaseWindow::GetTabbingIdentifier)
  1074. .SetMethod("setWindowButtonVisibility",
  1075. &BaseWindow::SetWindowButtonVisibility)
  1076. .SetMethod("_getWindowButtonVisibility",
  1077. &BaseWindow::GetWindowButtonVisibility)
  1078. .SetMethod("setWindowButtonPosition",
  1079. &BaseWindow::SetWindowButtonPosition)
  1080. .SetMethod("getWindowButtonPosition",
  1081. &BaseWindow::GetWindowButtonPosition)
  1082. .SetProperty("excludedFromShownWindowsMenu",
  1083. &BaseWindow::IsExcludedFromShownWindowsMenu,
  1084. &BaseWindow::SetExcludedFromShownWindowsMenu)
  1085. #endif
  1086. .SetMethod("setAutoHideMenuBar", &BaseWindow::SetAutoHideMenuBar)
  1087. .SetMethod("isMenuBarAutoHide", &BaseWindow::IsMenuBarAutoHide)
  1088. .SetMethod("setMenuBarVisibility", &BaseWindow::SetMenuBarVisibility)
  1089. .SetMethod("isMenuBarVisible", &BaseWindow::IsMenuBarVisible)
  1090. .SetMethod("setAspectRatio", &BaseWindow::SetAspectRatio)
  1091. .SetMethod("previewFile", &BaseWindow::PreviewFile)
  1092. .SetMethod("closeFilePreview", &BaseWindow::CloseFilePreview)
  1093. .SetMethod("getContentView", &BaseWindow::GetContentView)
  1094. .SetProperty("contentView", &BaseWindow::GetContentView,
  1095. &BaseWindow::SetContentView)
  1096. .SetMethod("getParentWindow", &BaseWindow::GetParentWindow)
  1097. .SetMethod("getChildWindows", &BaseWindow::GetChildWindows)
  1098. .SetMethod("isModal", &BaseWindow::IsModal)
  1099. .SetMethod("setThumbarButtons", &BaseWindow::SetThumbarButtons)
  1100. #if defined(TOOLKIT_VIEWS)
  1101. .SetMethod("setIcon", &BaseWindow::SetIcon)
  1102. #endif
  1103. #if BUILDFLAG(IS_WIN)
  1104. .SetMethod("hookWindowMessage", &BaseWindow::HookWindowMessage)
  1105. .SetMethod("isWindowMessageHooked", &BaseWindow::IsWindowMessageHooked)
  1106. .SetMethod("unhookWindowMessage", &BaseWindow::UnhookWindowMessage)
  1107. .SetMethod("unhookAllWindowMessages",
  1108. &BaseWindow::UnhookAllWindowMessages)
  1109. .SetMethod("setThumbnailClip", &BaseWindow::SetThumbnailClip)
  1110. .SetMethod("setThumbnailToolTip", &BaseWindow::SetThumbnailToolTip)
  1111. .SetMethod("setAppDetails", &BaseWindow::SetAppDetails)
  1112. #endif
  1113. #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
  1114. .SetMethod("setTitleBarOverlay", &BaseWindow::SetTitleBarOverlay)
  1115. #endif
  1116. .SetProperty("id", &BaseWindow::GetID);
  1117. }
  1118. } // namespace electron::api
  1119. namespace {
  1120. using electron::api::BaseWindow;
  1121. void Initialize(v8::Local<v8::Object> exports,
  1122. v8::Local<v8::Value> unused,
  1123. v8::Local<v8::Context> context,
  1124. void* priv) {
  1125. v8::Isolate* isolate = context->GetIsolate();
  1126. BaseWindow::SetConstructor(isolate, base::BindRepeating(&BaseWindow::New));
  1127. gin_helper::Dictionary constructor(isolate,
  1128. BaseWindow::GetConstructor(isolate)
  1129. ->GetFunction(context)
  1130. .ToLocalChecked());
  1131. constructor.SetMethod("fromId", &BaseWindow::FromWeakMapID);
  1132. constructor.SetMethod("getAllWindows", &BaseWindow::GetAll);
  1133. gin_helper::Dictionary dict(isolate, exports);
  1134. dict.Set("BaseWindow", constructor);
  1135. }
  1136. } // namespace
  1137. NODE_LINKED_BINDING_CONTEXT_AWARE(electron_browser_base_window, Initialize)