Forráskód Böngészése

WebContent: Protect the switch-to-window endpoint against null BCs

This is one of the few endpoints that does not ensure a top-level BC is
open. It's a bit of an implementation-defined endpoint, so let's protect
against a non-existent BC explicitly.
Timothy Flynn 10 hónapja
szülő
commit
c7db1204ca
1 módosított fájl, 9 hozzáadás és 7 törlés
  1. 9 7
      Userland/Services/WebContent/WebDriverConnection.cpp

+ 9 - 7
Userland/Services/WebContent/WebDriverConnection.cpp

@@ -449,15 +449,17 @@ Messages::WebDriverClient::SwitchToWindowResponse WebDriverConnection::switch_to
     //    Otherwise, return error with error code no such window.
     bool found_matching_context = false;
 
-    current_top_level_browsing_context()->for_each_in_inclusive_subtree([&](Web::HTML::BrowsingContext& context) {
-        if (handle != context.top_level_traversable()->window_handle())
-            return Web::TraversalDecision::Continue;
+    if (auto browsing_context = current_top_level_browsing_context()) {
+        browsing_context->for_each_in_inclusive_subtree([&](Web::HTML::BrowsingContext& context) {
+            if (handle != context.top_level_traversable()->window_handle())
+                return Web::TraversalDecision::Continue;
 
-        m_current_browsing_context = context;
-        found_matching_context = true;
+            m_current_browsing_context = context;
+            found_matching_context = true;
 
-        return Web::TraversalDecision::Break;
-    });
+            return Web::TraversalDecision::Break;
+        });
+    }
 
     if (!found_matching_context)
         return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchWindow, "Window not found");