Browse Source

UI/Qt: Set debug menu checkbox options across all tabs

The "Enable Scripting", "Block Pop-ups" and "Enable Same-Origin Policy"
options are now set for every tab when toggled. They are also applied
to new tabs when they are created.
Tim Ledbetter 1 năm trước cách đây
mục cha
commit
99555f19f4
4 tập tin đã thay đổi với 54 bổ sung24 xóa
  1. 33 24
      Ladybird/Qt/BrowserWindow.cpp
  2. 3 0
      Ladybird/Qt/BrowserWindow.h
  3. 15 0
      Ladybird/Qt/Tab.cpp
  4. 3 0
      Ladybird/Qt/Tab.h

+ 33 - 24
Ladybird/Qt/BrowserWindow.cpp

@@ -341,10 +341,9 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::Cook
     debug_menu->addAction(m_show_line_box_borders_action);
     QObject::connect(m_show_line_box_borders_action, &QAction::triggered, this, [this] {
         bool state = m_show_line_box_borders_action->isChecked();
-        for (auto index = 0; index < m_tabs_container->count(); ++index) {
-            auto tab = verify_cast<Tab>(m_tabs_container->widget(index));
-            tab->set_line_box_borders(state);
-        }
+        for_each_tab([state](auto& tab) {
+            tab.set_line_box_borders(state);
+        });
     });
 
     debug_menu->addSeparator();
@@ -414,30 +413,36 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::Cook
 
     debug_menu->addSeparator();
 
-    auto* enable_scripting_action = new QAction("Enable Scripting", this);
-    enable_scripting_action->setCheckable(true);
-    enable_scripting_action->setChecked(true);
-    debug_menu->addAction(enable_scripting_action);
-    QObject::connect(enable_scripting_action, &QAction::triggered, this, [this, enable_scripting_action] {
-        bool state = enable_scripting_action->isChecked();
-        debug_request("scripting", state ? "on" : "off");
+    m_enable_scripting_action = new QAction("Enable Scripting", this);
+    m_enable_scripting_action->setCheckable(true);
+    m_enable_scripting_action->setChecked(true);
+    debug_menu->addAction(m_enable_scripting_action);
+    QObject::connect(m_enable_scripting_action, &QAction::triggered, this, [this] {
+        bool state = m_enable_scripting_action->isChecked();
+        for_each_tab([state](auto& tab) {
+            tab.set_scripting(state);
+        });
     });
 
-    auto* block_pop_ups_action = new QAction("Block Pop-ups", this);
-    block_pop_ups_action->setCheckable(true);
-    block_pop_ups_action->setChecked(true);
-    debug_menu->addAction(block_pop_ups_action);
-    QObject::connect(block_pop_ups_action, &QAction::triggered, this, [this, block_pop_ups_action] {
-        bool state = block_pop_ups_action->isChecked();
-        debug_request("block-pop-ups", state ? "on" : "off");
+    m_block_pop_ups_action = new QAction("Block Pop-ups", this);
+    m_block_pop_ups_action->setCheckable(true);
+    m_block_pop_ups_action->setChecked(true);
+    debug_menu->addAction(m_block_pop_ups_action);
+    QObject::connect(m_block_pop_ups_action, &QAction::triggered, this, [this] {
+        bool state = m_block_pop_ups_action->isChecked();
+        for_each_tab([state](auto& tab) {
+            tab.set_block_popups(state);
+        });
     });
 
-    auto* enable_same_origin_policy_action = new QAction("Enable Same-Origin Policy", this);
-    enable_same_origin_policy_action->setCheckable(true);
-    debug_menu->addAction(enable_same_origin_policy_action);
-    QObject::connect(enable_same_origin_policy_action, &QAction::triggered, this, [this, enable_same_origin_policy_action] {
-        bool state = enable_same_origin_policy_action->isChecked();
-        debug_request("same-origin-policy", state ? "on" : "off");
+    m_enable_same_origin_policy_action = new QAction("Enable Same-Origin Policy", this);
+    m_enable_same_origin_policy_action->setCheckable(true);
+    debug_menu->addAction(m_enable_same_origin_policy_action);
+    QObject::connect(m_enable_same_origin_policy_action, &QAction::triggered, this, [this] {
+        bool state = m_enable_same_origin_policy_action->isChecked();
+        for_each_tab([state](auto& tab) {
+            tab.set_same_origin_policy(state);
+        });
     });
 
     auto* help_menu = m_hamburger_menu->addMenu("&Help");
@@ -680,7 +685,11 @@ void BrowserWindow::initialize_tab(Tab* tab)
     create_close_button_for_tab(tab);
 
     tab->focus_location_editor();
+
     tab->set_line_box_borders(m_show_line_box_borders_action->isChecked());
+    tab->set_scripting(m_enable_scripting_action->isChecked());
+    tab->set_block_popups(m_block_pop_ups_action->isChecked());
+    tab->set_same_origin_policy(m_enable_same_origin_policy_action->isChecked());
 }
 
 void BrowserWindow::activate_tab(int index)

+ 3 - 0
Ladybird/Qt/BrowserWindow.h

@@ -185,6 +185,9 @@ private:
     QAction* m_view_source_action { nullptr };
     QAction* m_inspect_dom_node_action { nullptr };
     QAction* m_show_line_box_borders_action { nullptr };
+    QAction* m_enable_scripting_action { nullptr };
+    QAction* m_block_pop_ups_action { nullptr };
+    QAction* m_enable_same_origin_policy_action { nullptr };
 
     SettingsDialog* m_settings_dialog { nullptr };
 

+ 15 - 0
Ladybird/Qt/Tab.cpp

@@ -956,9 +956,24 @@ void Tab::close_sub_widgets()
     close_widget_window(m_inspector_widget);
 }
 
+void Tab::set_block_popups(bool enabled)
+{
+    debug_request("block-pop-ups", enabled ? "on" : "off");
+}
+
 void Tab::set_line_box_borders(bool enabled)
 {
     debug_request("set-line-box-borders", enabled ? "on" : "off");
 }
 
+void Tab::set_same_origin_policy(bool enabled)
+{
+    debug_request("same-origin-policy", enabled ? "on" : "off");
+}
+
+void Tab::set_scripting(bool enabled)
+{
+    debug_request("scripting", enabled ? "on" : "off");
+}
+
 }

+ 3 - 0
Ladybird/Qt/Tab.h

@@ -65,7 +65,10 @@ public:
 
     void update_hover_label();
 
+    void set_block_popups(bool);
     void set_line_box_borders(bool);
+    void set_same_origin_policy(bool);
+    void set_scripting(bool);
 
 public slots:
     void focus_location_editor();