Browse Source

Browser: Provide ability to create new browser windows

This change allows a user to spawn new browser processes by either
going to "File -> New Window" or by the shortcut "Ctrl + N".
Kemal Zebari 2 years ago
parent
commit
90719d34af

+ 5 - 0
Userland/Applications/Browser/BrowserWindow.cpp

@@ -103,6 +103,10 @@ BrowserWindow::BrowserWindow(CookieJar& cookie_jar, URL url)
         create_new_tab(Browser::url_from_user_input(Browser::g_new_tab_url), true);
     };
 
+    m_window_actions.on_create_new_window = [this] {
+        GUI::Process::spawn_or_show_error(this, "/bin/Browser"sv);
+    };
+
     m_window_actions.on_next_tab = [this] {
         m_tab_widget->activate_next_tab();
     };
@@ -154,6 +158,7 @@ void BrowserWindow::build_menus()
 {
     auto& file_menu = add_menu("&File");
     file_menu.add_action(WindowActions::the().create_new_tab_action());
+    file_menu.add_action(WindowActions::the().create_new_window_action());
 
     auto close_tab_action = GUI::CommonActions::make_close_tab_action([this](auto&) {
         active_tab().on_tab_close_request(active_tab());

+ 10 - 0
Userland/Applications/Browser/WindowActions.cpp

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2022, the SerenityOS developers.
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -32,6 +33,15 @@ WindowActions::WindowActions(GUI::Window& window)
         &window);
     m_create_new_tab_action->set_status_tip("Open a new tab");
 
+    m_create_new_window_action = GUI::Action::create(
+        "&New Window", { Mod_Ctrl, Key_N }, g_icon_bag.go_to, [this](auto&) {
+            if (on_create_new_window) {
+                on_create_new_window();
+            }
+        },
+        &window);
+    m_create_new_window_action->set_status_tip("Open a new browser window");
+
     m_next_tab_action = GUI::Action::create(
         "&Next Tab", { Mod_Ctrl, Key_PageDown }, [this](auto&) {
             if (on_next_tab)

+ 4 - 0
Userland/Applications/Browser/WindowActions.h

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2022, the SerenityOS developers.
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -17,6 +18,7 @@ public:
     WindowActions(GUI::Window&);
 
     Function<void()> on_create_new_tab;
+    Function<void()> on_create_new_window;
     Function<void()> on_next_tab;
     Function<void()> on_previous_tab;
     Vector<Function<void()>> on_tabs;
@@ -25,6 +27,7 @@ public:
     Function<void(GUI::Action&)> on_vertical_tabs;
 
     GUI::Action& create_new_tab_action() { return *m_create_new_tab_action; }
+    GUI::Action& create_new_window_action() { return *m_create_new_window_action; }
     GUI::Action& next_tab_action() { return *m_next_tab_action; }
     GUI::Action& previous_tab_action() { return *m_previous_tab_action; }
     GUI::Action& about_action() { return *m_about_action; }
@@ -33,6 +36,7 @@ public:
 
 private:
     RefPtr<GUI::Action> m_create_new_tab_action;
+    RefPtr<GUI::Action> m_create_new_window_action;
     RefPtr<GUI::Action> m_next_tab_action;
     RefPtr<GUI::Action> m_previous_tab_action;
     NonnullRefPtrVector<GUI::Action> m_tab_actions;

+ 2 - 0
Userland/Applications/Browser/main.cpp

@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
+ * Copyright (c) 2022, the SerenityOS developers.
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -91,6 +92,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     TRY(Core::System::unveil("/etc/passwd", "r"));
     TRY(Core::System::unveil("/etc/timezone", "r"));
     TRY(Core::System::unveil("/bin/BrowserSettings", "x"));
+    TRY(Core::System::unveil("/bin/Browser", "x"));
     TRY(Core::System::unveil(nullptr, nullptr));
 
     Web::ResourceLoader::initialize(TRY(WebView::RequestServerAdapter::try_create()));