Skip to content

Commit 627bd67

Browse files
[GTK][WPE] missing URI for injected user scripts and style sheets
https://bugs.webkit.org/show_bug.cgi?id=272152 Reviewed by Adrian Perez de Castro. User scripts/style sheets without the URI are not visible in WebInspector. With this change the URI of injected user scripts/style sheets are generated as: user-script:incremented_identifier user-style:incremented_identifier * LayoutTests/userscripts/window-onerror-for-isolated-world-1-expected.txt: * LayoutTests/userscripts/window-onerror-for-isolated-world-2-expected.txt: * LayoutTests/userscripts/window-onerror-for-isolated-world-3-expected.txt: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/page/UserScript.cpp: Copied from Source/WebKit/UIProcess/API/APIUserScript.cpp. (WebCore::generateUniqueURL): (WebCore::UserScript::UserScript): * Source/WebCore/page/UserScript.h: (WebCore::UserScript::UserScript): Deleted. * Source/WebCore/page/UserStyleSheet.cpp: Copied from Source/WebKit/UIProcess/API/APIUserScript.cpp. (WebCore::generateUniqueURL): (WebCore::UserStyleSheet::UserStyleSheet): * Source/WebCore/page/UserStyleSheet.h: * Source/WebCore/page/WorkerNavigator.cpp: * Source/WebKit/UIProcess/API/APIUserScript.cpp: (API::UserScript::generateUniqueURL): Deleted. * Source/WebKit/UIProcess/API/APIUserScript.h: * Source/WebKit/UIProcess/API/APIUserStyleSheet.cpp: (API::UserStyleSheet::generateUniqueURL): Deleted. * Source/WebKit/UIProcess/API/APIUserStyleSheet.h: * Source/WebKit/UIProcess/API/C/WKUserScriptRef.cpp: (WKUserScriptCreateWithSource): Canonical link: https://commits.webkit.org/277470@main
1 parent 7877902 commit 627bd67

17 files changed

Lines changed: 128 additions & 60 deletions

LayoutTests/userscripts/window-onerror-for-isolated-world-1-expected.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ Test that window.onerror and "error" event listeners from main world are invoked
22

33
Main world window.onerror: Error: Error in main world inline script. at window-onerror-for-isolated-world-1.html:55:68 Error: Error in main world inline script.
44
Main world error event listener: Error: Error in main world inline script. at window-onerror-for-isolated-world-1.html:55:68 Error: Error in main world inline script.
5-
Main world window.onerror: Error: Error in user script inline script. at undefined:12:20 null
6-
Main world error event listener: Error: Error in user script inline script. at undefined:12:20 null
5+
Main world window.onerror: Error: Error in user script inline script. at user-script:13:12:68 Error: Error in user script inline script.
6+
Main world error event listener: Error: Error in user script inline script. at user-script:13:12:68 Error: Error in user script inline script.
77
Main world window.onerror: Error: Error in main world load handler. at window-onerror-for-isolated-world-1.html:51:72 Error: Error in main world load handler.
88
Main world error event listener: Error: Error in main world load handler. at window-onerror-for-isolated-world-1.html:51:72 Error: Error in main world load handler.
9-
Main world window.onerror: Error: Error in user script load handler. at undefined:8:24 null
10-
Main world error event listener: Error: Error in user script load handler. at undefined:8:24 null
9+
Main world window.onerror: Error: Error in user script load handler. at user-script:13:8:72 Error: Error in user script load handler.
10+
Main world error event listener: Error: Error in user script load handler. at user-script:13:8:72 Error: Error in user script load handler.
1111
Main world window.onerror: Error: Error in main world setTimeout callback. at window-onerror-for-isolated-world-1.html:49:83 Error: Error in main world setTimeout callback.
1212
Main world error event listener: Error: Error in main world setTimeout callback. at window-onerror-for-isolated-world-1.html:49:83 Error: Error in main world setTimeout callback.
13-
Main world window.onerror: Error: Error in user script setTimeout callback. at undefined:6:28 null
14-
Main world error event listener: Error: Error in user script setTimeout callback. at undefined:6:28 null
13+
Main world window.onerror: Error: Error in user script setTimeout callback. at user-script:13:6:83 Error: Error in user script setTimeout callback.
14+
Main world error event listener: Error: Error in user script setTimeout callback. at user-script:13:6:83 Error: Error in user script setTimeout callback.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
CONSOLE MESSAGE: Error: Error in main world inline script.
22
Test that window.onerror and "error" event listeners from isolated world are invoked for uncaught exceptions in user scripts running in isolate worlds as well as for exceptions in the main world.Bug 8519.
33

4-
user script window.onerror: Error: Error in user script inline script. at undefined:33:20 Error: Error in user script inline script.
5-
user script error event listener: Error: Error in user script inline script. at undefined:33:20 Error: Error in user script inline script.
4+
user script window.onerror: Error: Error in user script inline script. at user-script:14:33:68 Error: Error in user script inline script.
5+
user script error event listener: Error: Error in user script inline script. at user-script:14:33:68 Error: Error in user script inline script.
66
user script window.onerror: Error: Error in main world load handler. at window-onerror-for-isolated-world-2.html:27:72 null
77
user script error event listener: Error: Error in main world load handler. at window-onerror-for-isolated-world-2.html:27:72 null
8-
user script window.onerror: Error: Error in user script load handler. at undefined:30:24 Error: Error in user script load handler.
9-
user script error event listener: Error: Error in user script load handler. at undefined:30:24 Error: Error in user script load handler.
8+
user script window.onerror: Error: Error in user script load handler. at user-script:14:30:72 Error: Error in user script load handler.
9+
user script error event listener: Error: Error in user script load handler. at user-script:14:30:72 Error: Error in user script load handler.
1010
user script window.onerror: Error: Error in main world setTimeout callback. at window-onerror-for-isolated-world-2.html:25:83 null
1111
user script error event listener: Error: Error in main world setTimeout callback. at window-onerror-for-isolated-world-2.html:25:83 null
12-
user script window.onerror: Error: Error in user script setTimeout callback. at undefined:28:28 Error: Error in user script setTimeout callback.
13-
user script error event listener: Error: Error in user script setTimeout callback. at undefined:28:28 Error: Error in user script setTimeout callback.
12+
user script window.onerror: Error: Error in user script setTimeout callback. at user-script:14:28:83 Error: Error in user script setTimeout callback.
13+
user script error event listener: Error: Error in user script setTimeout callback. at user-script:14:28:83 Error: Error in user script setTimeout callback.

LayoutTests/userscripts/window-onerror-for-isolated-world-3-expected.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ Test that window.onerror and "error" event listeners from main world are invoked
22

33

44
User Script
5-
Main world window.onerror: SerializableError from (user script) at :5:59 SerializableError from (user script)
6-
Main world error event listener: SerializableError from (user script) at :5:59 SerializableError from (user script)
7-
Main world window.onerror: [object Window] at undefined:0:0 null
8-
Main world error event listener: [object Window] at undefined:0:0 null
5+
Main world window.onerror: SerializableError from (user script) at user-script:15:5:59 SerializableError from (user script)
6+
Main world error event listener: SerializableError from (user script) at user-script:15:5:59 SerializableError from (user script)
7+
Main world window.onerror: [object Window] at user-script:15:11:27 null
8+
Main world error event listener: [object Window] at user-script:15:11:27 null
99

1010
Main World
1111
Main world window.onerror: SerializableError from (main world) at window-onerror-for-isolated-world-3.html:49:59 SerializableError from (main world)

Source/WebCore/Sources.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,6 +1836,8 @@ page/UndoManager.cpp
18361836
page/UserContentController.cpp
18371837
page/UserContentProvider.cpp
18381838
page/UserContentURLPattern.cpp
1839+
page/UserScript.cpp
1840+
page/UserStyleSheet.cpp
18391841
page/VisitedLinkStore.cpp
18401842
page/VisualViewport.cpp
18411843
page/WheelEventDeltaFilter.cpp

Source/WebCore/WebCore.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15743,6 +15743,7 @@
1574315743
BC8B853C0E7C7F1100AB6984 /* ScrollbarThemeMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollbarThemeMac.h; sourceTree = "<group>"; };
1574415744
BC8B854A0E7C7F5600AB6984 /* ScrollbarTheme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollbarTheme.h; sourceTree = "<group>"; };
1574515745
BC8BF150105813BF00A40A07 /* UserStyleSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserStyleSheet.h; sourceTree = "<group>"; };
15746+
BC8BF150105814BF00A40A07 /* UserStyleSheet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserStyleSheet.cpp; sourceTree = "<group>"; };
1574615747
BC8BF1591058141800A40A07 /* UserStyleSheetTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserStyleSheetTypes.h; sourceTree = "<group>"; };
1574715748
BC8C8FAB0DDCD31B00B592F4 /* RenderStyle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderStyle.cpp; sourceTree = "<group>"; };
1574815749
BC8C8FAC0DDCD31B00B592F4 /* RenderStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderStyle.h; sourceTree = "<group>"; };
@@ -15772,6 +15773,7 @@
1577215773
BCA169A10BFD55B40019CA76 /* JSHTMLTableCaptionElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLTableCaptionElement.h; sourceTree = "<group>"; };
1577315774
BCA257141293C010007A263D /* VerticalPositionCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VerticalPositionCache.h; sourceTree = "<group>"; };
1577415775
BCA2B0601050475F0043BD1C /* UserScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserScript.h; sourceTree = "<group>"; };
15776+
BCA2B0601050485F0043BD1C /* UserScript.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserScript.cpp; sourceTree = "<group>"; };
1577515777
BCA2B08A10505BCD0043BD1C /* UserScriptTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserScriptTypes.h; sourceTree = "<group>"; };
1577615778
BCA378BA0D15F64200B793D6 /* ScheduledAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScheduledAction.cpp; sourceTree = "<group>"; };
1577715779
BCA378BB0D15F64200B793D6 /* ScheduledAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScheduledAction.h; sourceTree = "<group>"; };
@@ -24824,8 +24826,10 @@
2482424826
7C73FB05191EF416007DE061 /* UserMessageHandlersNamespace.cpp */,
2482524827
7C73FB06191EF417007DE061 /* UserMessageHandlersNamespace.h */,
2482624828
7C73FB09191EF49F007DE061 /* UserMessageHandlersNamespace.idl */,
24829+
BCA2B0601050485F0043BD1C /* UserScript.cpp */,
2482724830
BCA2B0601050475F0043BD1C /* UserScript.h */,
2482824831
BCA2B08A10505BCD0043BD1C /* UserScriptTypes.h */,
24832+
BC8BF150105814BF00A40A07 /* UserStyleSheet.cpp */,
2482924833
BC8BF150105813BF00A40A07 /* UserStyleSheet.h */,
2483024834
BC8BF1591058141800A40A07 /* UserStyleSheetTypes.h */,
2483124835
F513A3E915FF4841001526DB /* ValidationMessageClient.h */,

Source/WebCore/page/UserScript.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (C) 2024 Igalia S.L. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#include "config.h"
27+
#include "UserScript.h"
28+
29+
#include <wtf/text/StringConcatenateNumbers.h>
30+
31+
namespace WebCore {
32+
33+
static WTF::URL generateUserScriptUniqueURL()
34+
{
35+
static uint64_t identifier;
36+
return { { }, makeString("user-script:", ++identifier) };
37+
}
38+
39+
UserScript::UserScript(String&& source, URL&& url, Vector<String>&& allowlist, Vector<String>&& blocklist, UserScriptInjectionTime injectionTime, UserContentInjectedFrames injectedFrames, WaitForNotificationBeforeInjecting waitForNotification)
40+
: m_source(WTFMove(source))
41+
, m_url(url.isEmpty() ? generateUserScriptUniqueURL() : WTFMove(url))
42+
, m_allowlist(WTFMove(allowlist))
43+
, m_blocklist(WTFMove(blocklist))
44+
, m_injectionTime(injectionTime)
45+
, m_injectedFrames(injectedFrames)
46+
, m_waitForNotificationBeforeInjecting(waitForNotification)
47+
{
48+
}
49+
50+
} // namespace WebCore

Source/WebCore/page/UserScript.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,7 @@ class UserScript {
4141
UserScript& operator=(const UserScript&) = default;
4242
UserScript& operator=(UserScript&&) = default;
4343

44-
UserScript(String&& source, URL&& url, Vector<String>&& allowlist, Vector<String>&& blocklist, UserScriptInjectionTime injectionTime, UserContentInjectedFrames injectedFrames, WaitForNotificationBeforeInjecting waitForNotification)
45-
: m_source(WTFMove(source))
46-
, m_url(WTFMove(url))
47-
, m_allowlist(WTFMove(allowlist))
48-
, m_blocklist(WTFMove(blocklist))
49-
, m_injectionTime(injectionTime)
50-
, m_injectedFrames(injectedFrames)
51-
, m_waitForNotificationBeforeInjecting(waitForNotification)
52-
{
53-
}
44+
WEBCORE_EXPORT UserScript(String&&, URL&&, Vector<String>&&, Vector<String>&&, UserScriptInjectionTime, UserContentInjectedFrames, WaitForNotificationBeforeInjecting);
5445

5546
const String& source() const { return m_source; }
5647
const URL& url() const { return m_url; }
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (C) 2024 Igalia S.L. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#include "config.h"
27+
#include "UserStyleSheet.h"
28+
29+
#include <wtf/text/StringConcatenateNumbers.h>
30+
31+
namespace WebCore {
32+
33+
static WTF::URL generateUserStyleUniqueURL()
34+
{
35+
static uint64_t identifier;
36+
return { { }, makeString("user-style:", ++identifier) };
37+
}
38+
39+
UserStyleSheet::UserStyleSheet(const String& source, const URL& url, Vector<String>&& allowlist, Vector<String>&& blocklist, UserContentInjectedFrames injectedFrames, UserStyleLevel level, std::optional<PageIdentifier> pageID)
40+
: m_source(source)
41+
, m_url(url.isEmpty() ? generateUserStyleUniqueURL() : url)
42+
, m_allowlist(WTFMove(allowlist))
43+
, m_blocklist(WTFMove(blocklist))
44+
, m_injectedFrames(injectedFrames)
45+
, m_level(level)
46+
, m_pageID(pageID)
47+
{
48+
}
49+
50+
} // namespace WebCore

Source/WebCore/page/UserStyleSheet.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,7 @@ class UserStyleSheet {
4242
{
4343
}
4444

45-
UserStyleSheet(const String& source, const URL& url, Vector<String>&& allowlist, Vector<String>&& blocklist, UserContentInjectedFrames injectedFrames, UserStyleLevel level, std::optional<PageIdentifier> pageID = std::nullopt)
46-
: m_source(source)
47-
, m_url(url)
48-
, m_allowlist(WTFMove(allowlist))
49-
, m_blocklist(WTFMove(blocklist))
50-
, m_injectedFrames(injectedFrames)
51-
, m_level(level)
52-
, m_pageID(pageID)
53-
{
54-
}
45+
WEBCORE_EXPORT UserStyleSheet(const String&, const URL&, Vector<String>&&, Vector<String>&&, UserContentInjectedFrames, UserStyleLevel, std::optional<PageIdentifier> = std::nullopt);
5546

5647
const String& source() const { return m_source; }
5748
const URL& url() const { return m_url; }

Source/WebCore/page/WorkerNavigator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "config.h"
2828
#include "WorkerNavigator.h"
2929

30+
#include "Page.h"
3031
namespace WebCore {
3132

3233
WorkerNavigator::WorkerNavigator(ScriptExecutionContext& context, const String& userAgent, bool isOnline)

0 commit comments

Comments
 (0)