Skip to content

Commit b6ebe42

Browse files
magomezpgorszkowski-igalia
authored andcommitted
[INSPECTOR] Wait a max of 60s before failing on loading libWPEWebInspectorResources.so
1 parent 858cbe9 commit b6ebe42

4 files changed

Lines changed: 43 additions & 16 deletions

File tree

Source/JavaScriptCore/inspector/remote/glib/RemoteInspectorServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ GVariant* RemoteInspectorServer::setupInspectorClient(SocketConnection& clientCo
241241
m_clientConnection = &clientConnection;
242242

243243
GVariant* backendCommands;
244-
if (strcmp(clientBackendCommandsHash, backendCommandsHash().data())) {
244+
if (!backendCommandsHash().isNull() && strcmp(clientBackendCommandsHash, backendCommandsHash().data())) {
245245
auto bytes = Inspector::backendCommands();
246246
backendCommands = g_variant_new_bytestring(static_cast<const char*>(g_bytes_get_data(bytes.get(), nullptr)));
247247
} else

Source/JavaScriptCore/inspector/remote/glib/RemoteInspectorUtils.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,18 @@ namespace Inspector {
4040
GRefPtr<GBytes> backendCommands()
4141
{
4242
#if PLATFORM(WPE)
43-
static std::once_flag flag;
44-
std::call_once(flag, [] {
45-
const char* libDir = PKGLIBDIR;
46-
#if ENABLE(DEVELOPER_MODE)
47-
// Probably no need for a specific env var here. Assume the inspector resources.so file is
48-
// in the same directory as the injected bundle lib, for developer builds.
49-
const char* path = g_getenv("WEBKIT_INJECTED_BUNDLE_PATH");
50-
if (path && g_file_test(path, G_FILE_TEST_IS_DIR))
51-
libDir = path;
52-
#endif
53-
GUniquePtr<char> bundleFilename(g_build_filename(libDir, "libWPEWebInspectorResources.so", nullptr));
54-
GModule* resourcesModule = g_module_open(bundleFilename.get(), G_MODULE_BIND_LAZY);
43+
static bool moduleLoaded = false;
44+
45+
if (!moduleLoaded) {
46+
GModule* resourcesModule = g_module_open(PKGLIBDIR G_DIR_SEPARATOR_S "libWPEWebInspectorResources.so", G_MODULE_BIND_LAZY);
5547
if (!resourcesModule) {
5648
WTFLogAlways("Error loading libWPEWebInspectorResources.so: %s", g_module_error());
57-
return;
49+
return nullptr;
5850
}
5951

6052
g_module_make_resident(resourcesModule);
61-
});
53+
moduleLoaded = true;
54+
}
6255
#endif
6356
GRefPtr<GBytes> bytes = adoptGRef(g_resources_lookup_data(INSPECTOR_BACKEND_COMMANDS_PATH, G_RESOURCE_LOOKUP_FLAGS_NONE, nullptr));
6457
ASSERT(bytes);
@@ -70,6 +63,9 @@ const CString& backendCommandsHash()
7063
static CString hexDigest;
7164
if (hexDigest.isNull()) {
7265
auto bytes = backendCommands();
66+
if (!bytes)
67+
return hexDigest;
68+
7369
size_t dataSize;
7470
gconstpointer data = g_bytes_get_data(bytes.get(), &dataSize);
7571
ASSERT(dataSize);

Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ RemoteInspectorClient::RemoteInspectorClient(String&& hostAndPort, RemoteInspect
172172
: m_hostAndPort(WTFMove(hostAndPort))
173173
, m_observer(observer)
174174
, m_cancellable(adoptGRef(g_cancellable_new()))
175+
, m_setupInspectorClientTimer(*this, &RemoteInspectorClient::setupInspectorClientTimerFired)
175176
{
176177
GRefPtr<GSocketClient> socketClient = adoptGRef(g_socket_client_new());
177178
g_socket_client_connect_to_host_async(socketClient.get(), m_hostAndPort.utf8().data(), 0, m_cancellable.get(),
@@ -200,7 +201,34 @@ RemoteInspectorClient::~RemoteInspectorClient()
200201
void RemoteInspectorClient::setupConnection(Ref<SocketConnection>&& connection)
201202
{
202203
m_socketConnection = WTFMove(connection);
203-
m_socketConnection->sendMessage("SetupInspectorClient", g_variant_new("(@ay)", g_variant_new_bytestring(Inspector::backendCommandsHash().data())));
204+
setupInspectorClientTimerFired();
205+
}
206+
207+
void RemoteInspectorClient::setupInspectorClientTimerFired()
208+
{
209+
// There's an scenario where libWPEWebInspectorResources.so will not be available when the browser is
210+
// launched, but will be downloaded once the network connection is up. To handle this situation we check
211+
// whether the library is present bebore sending the SetupInspectorClient message. We will check for
212+
// the library every 10 seconds to configure the proper commands. After 60 seconds we give up and
213+
// send an empty string of commands, which causes the inspector not to work.
214+
static int numTries = 0;
215+
216+
if (numTries <= 6 && Inspector::backendCommandsHash().isNull()) {
217+
// Retry every 10 seconds for 60 seconds.
218+
m_setupInspectorClientTimer.startOneShot(10_s);
219+
numTries++;
220+
return;
221+
}
222+
223+
GVariant* backendCommandsHashString;
224+
if (!Inspector::backendCommandsHash().isNull())
225+
backendCommandsHashString = g_variant_new_bytestring(Inspector::backendCommandsHash().data());
226+
else {
227+
WTFLogAlways("Unable to load libWPEWebInspectorResources.so after 60 seconds: WebInspector won't work properly");
228+
backendCommandsHashString = g_variant_new_bytestring("");
229+
}
230+
231+
m_socketConnection->sendMessage("SetupInspectorClient", g_variant_new("(@ay)", backendCommandsHashString));
204232
}
205233

206234
void RemoteInspectorClient::setBackendCommands(const char* backendCommands)

Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#if ENABLE(REMOTE_INSPECTOR)
2929

30+
#include <WebCore/Timer.h>
3031
#include <wtf/HashMap.h>
3132
#include <wtf/Vector.h>
3233
#include <wtf/glib/GRefPtr.h>
@@ -80,6 +81,7 @@ class RemoteInspectorClient {
8081
void setBackendCommands(const char*);
8182
void setTargetList(uint64_t connectionID, Vector<Target>&&);
8283
void sendMessageToFrontend(uint64_t connectionID, uint64_t targetID, const char*);
84+
void setupInspectorClientTimerFired();
8385

8486
String m_hostAndPort;
8587
String m_backendCommandsURL;
@@ -88,6 +90,7 @@ class RemoteInspectorClient {
8890
GRefPtr<GCancellable> m_cancellable;
8991
HashMap<uint64_t, Vector<Target>> m_targets;
9092
HashMap<std::pair<uint64_t, uint64_t>, std::unique_ptr<RemoteInspectorProxy>> m_inspectorProxyMap;
93+
WebCore::Timer m_setupInspectorClientTimer;
9194
};
9295

9396
} // namespace WebKit

0 commit comments

Comments
 (0)