Skip to content

Commit 2bb0d38

Browse files
committedAug 16, 2023
Merge
2 parents 39beee9 + 4ff0b7d commit 2bb0d38

File tree

15 files changed

+317
-12
lines changed

15 files changed

+317
-12
lines changed
 

‎modules/javafx.graphics/src/main/native-font/pango.c

+26-4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ JNI_OnLoad_javafx_font_pango(JavaVM * vm, void * reserved) {
5050

5151
#define OS_NATIVE(func) Java_com_sun_javafx_font_freetype_OSPango_##func
5252

53+
#define SAFE_FREE(PTR) \
54+
if ((PTR) != NULL) { \
55+
free(PTR); \
56+
(PTR) = NULL; \
57+
}
58+
5359
extern jboolean checkAndClearException(JNIEnv *env);
5460

5561
#ifndef STATIC_BUILD // can't have this twice in a static build
@@ -159,15 +165,28 @@ JNIEXPORT jobject JNICALL OS_NATIVE(pango_1shape)
159165
jobject result = NULL;
160166
pango_shape(text, item->length, &analysis, glyphString);
161167
int count = glyphString->num_glyphs;
162-
if(count == 0) goto fail;
168+
jint *glyphs = NULL;
169+
jint *widths = NULL;
170+
jint *cluster = NULL;
171+
if (count <= 0) goto fail;
172+
if ((size_t)count >= INT_MAX / sizeof(jint)) {
173+
fprintf(stderr, "OS_NATIVE error: large glyph count value in pango_1shape\n");
174+
goto fail;
175+
}
163176

164177
jintArray glyphsArray = (*env)->NewIntArray(env, count);
165178
jintArray widthsArray = (*env)->NewIntArray(env, count);
166179
jintArray clusterArray = (*env)->NewIntArray(env, count);
167180
if (glyphsArray && widthsArray && clusterArray) {
168-
jint glyphs[count];
169-
jint widths[count];
170-
jint cluster[count];
181+
glyphs = (jint*) malloc(count * sizeof(jint));
182+
widths = (jint*) malloc(count * sizeof(jint));
183+
cluster = (jint*) malloc(count * sizeof(jint));
184+
if (glyphs == NULL ||
185+
widths == NULL ||
186+
cluster == NULL) {
187+
fprintf(stderr, "OS_NATIVE error: Unable to allocate memory in pango_1shape\n");
188+
goto fail;
189+
}
171190
int i;
172191
for (i = 0; i < count; i++) {
173192
glyphs[i] = glyphString->glyphs[i].glyph;
@@ -206,6 +225,9 @@ JNIEXPORT jobject JNICALL OS_NATIVE(pango_1shape)
206225

207226
fail:
208227
pango_glyph_string_free(glyphString);
228+
SAFE_FREE(glyphs);
229+
SAFE_FREE(widths);
230+
SAFE_FREE(cluster);
209231
return result;
210232
}
211233

‎modules/javafx.media/src/main/native/jfxmedia/jni/NativeAudioSpectrum.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -55,6 +55,10 @@ Java_com_sun_media_jfxmediaimpl_NativeAudioSpectrum_nativeSetBands(JNIEnv *env,
5555
{
5656
CAudioSpectrum *pSpectrum = (CAudioSpectrum*)jlong_to_ptr(nativeRef);
5757
CJavaBandsHolder *pHolder = new (std::nothrow) CJavaBandsHolder();
58+
if (pHolder == NULL) {
59+
return;
60+
}
61+
5862
if (!pHolder->Init(env, bands, magnitudes, phases)) {
5963
delete pHolder;
6064
pHolder = NULL;

‎modules/javafx.media/src/main/native/jfxmedia/jni/NativeVideoBuffer.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,14 @@ JNIEXPORT jintArray JNICALL Java_com_sun_media_jfxmediaimpl_NativeVideoBuffer_na
206206
}
207207

208208
jintArray strides = env->NewIntArray(count);
209-
jint *strideArray = new jint[count];
209+
if (strides == NULL) {
210+
return NULL;
211+
}
212+
213+
jint *strideArray = new (std::nothrow) jint[count];
214+
if (strideArray == NULL) {
215+
return NULL;
216+
}
210217

211218
for (int ii=0; ii < count; ii++) {
212219
strideArray[ii] = frame->GetStrideForPlane(ii);

‎modules/javafx.web/src/main/native/Source/WTF/wtf/Platform.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,6 @@
158158
#endif
159159

160160
/* FIXME: This is used to "turn on a specific feature of WebKit", so should be converted to an ENABLE macro. */
161-
#if (PLATFORM(COCOA) || PLATFORM(GTK) || PLATFORM(WPE)) && ENABLE(ACCESSIBILITY)
161+
#if (PLATFORM(COCOA) || PLATFORM(GTK) || PLATFORM(JAVA) || PLATFORM(WPE)) && ENABLE(ACCESSIBILITY)
162162
#define USE_ACCESSIBILITY_CONTEXT_MENUS 1
163163
#endif

‎modules/javafx.web/src/main/native/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ String MediaControlsHost::layoutTraitsClassName() const
127127
return "IOSLayoutTraits"_s;
128128
#elif PLATFORM(WATCHOS)
129129
return "WatchOSLayoutTraits"_s;
130-
#elif PLATFORM(GTK) || PLATFORM(WPE) || PLATFORM(WIN_CAIRO)
130+
#elif PLATFORM(GTK) || PLATFORM(WPE) || PLATFORM(WIN_CAIRO) || PLATFORM(JAVA)
131131
return "AdwaitaLayoutTraits"_s;
132132
#else
133133
ASSERT_NOT_REACHED();

‎modules/javafx.web/src/main/native/Source/WebCore/SourcesJava.txt

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ platform/java/PluginInfoStoreJava.cpp
5757
platform/java/PluginViewJava.cpp
5858
platform/java/PluginWidgetJava.cpp
5959
platform/java/RenderThemeJava.cpp
60+
platform/java/ModernMediaControlResource.cpp
6061
platform/java/ScrollbarThemeJava.cpp
6162
platform/java/SharedBufferJava.cpp
6263
platform/java/MainThreadSharedTimerJava.cpp

‎modules/javafx.web/src/main/native/Source/WebCore/platform/java/ModernMediaControlResource.cpp

+60
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
#pragma once
27+
28+
#include <map>
29+
#include <string>
30+
#include <wtf/text/WTFString.h>
31+
#include <wtf/HashMap.h>
32+
33+
class MediaControlResource {
34+
public:
35+
virtual String getValue(const String &key) = 0;
36+
virtual ~MediaControlResource() { }
37+
};
38+
39+
class ModernMediaControlResource : public MediaControlResource {
40+
private:
41+
HashMap<String, String> imageMap;
42+
public:
43+
ModernMediaControlResource();
44+
String getValue(const String &resource_key) override;
45+
};
46+
47+
// Factory for creating MediaControlResource objects
48+
class MediaControlResourceFactory {
49+
public:
50+
static std::unique_ptr<MediaControlResource> createResource() {
51+
return std::make_unique<ModernMediaControlResource>();
52+
}
53+
};

‎modules/javafx.web/src/main/native/Source/WebCore/platform/java/RenderThemeJava.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ RenderTheme& RenderTheme::singleton()
6767
return sm_defaultInstance;
6868
}
6969

70-
RenderThemeJava::RenderThemeJava()
70+
RenderThemeJava::RenderThemeJava() : mediaResource(MediaControlResourceFactory::createResource())
7171
{
7272
}
7373

@@ -494,8 +494,7 @@ Vector<String, 2> RenderThemeJava::mediaControlsScripts()
494494

495495
String RenderThemeJava::extraMediaControlsStyleSheet()
496496
{
497-
498-
return String(ModernMediaControlsUserAgentStyleSheet, sizeof(ModernMediaControlsUserAgentStyleSheet));
497+
return emptyString();
499498

500499
}
501500

@@ -553,7 +552,15 @@ bool RenderThemeJava::paintMediaControl(jint type, const RenderObject&, const Pa
553552
return true;
554553
}
555554

555+
String RenderThemeJava::mediaControlsStyleSheet()
556+
{
557+
return String(ModernMediaControlsUserAgentStyleSheet, sizeof(ModernMediaControlsUserAgentStyleSheet));
558+
}
556559

560+
String RenderThemeJava::mediaControlsBase64StringForIconNameAndType(const String& iconName, const String& iconType)
561+
{
562+
return mediaResource->getValue(iconName);
563+
}
557564
#undef JNI_EXPAND_MEDIA
558565

559566
#endif // ENABLE(VIDEO)

‎modules/javafx.web/src/main/native/Source/WebCore/platform/java/RenderThemeJava.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#pragma once
2727

2828
#include "RenderTheme.h"
29+
#include "ModernMediaControlResource.h"
2930
#include "GraphicsContext.h"
3031
#include "StyleResolver.h"
3132

@@ -107,7 +108,8 @@ class RenderThemeJava final : public RenderTheme {
107108

108109
void adjustSliderTrackStyle(RenderStyle&, const Element*) const override;
109110
bool paintSliderTrack(const RenderObject&, const PaintInfo&, const IntRect&) override;
110-
111+
String mediaControlsBase64StringForIconNameAndType(const String&, const String&);
112+
String mediaControlsStyleSheet();
111113

112114
private:
113115
int createWidgetState(const RenderObject& o);
@@ -116,6 +118,7 @@ class RenderThemeJava final : public RenderTheme {
116118
bool paintWidget(int widgetIndex, const RenderObject& o,
117119
const PaintInfo& i, const FloatRect& rect);
118120
Color getSelectionColor(int index) const;
121+
std::unique_ptr<MediaControlResource> mediaResource;
119122
#if ENABLE(VIDEO)
120123
bool paintMediaControl(jint type, const RenderObject&, const PaintInfo&, const IntRect&);
121124
#endif

‎modules/javafx.web/src/main/native/Source/cmake/OptionsJava.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_PUBLIC_SUFFIX_LIST PRIVATE OFF)
110110
WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_FTL_JIT PUBLIC OFF)
111111
WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_WEBASSEMBLY PRIVATE OFF)
112112
WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MODERN_MEDIA_CONTROLS PRIVATE ON)
113+
WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MEDIA_CONTROLS_CONTEXT_MENUS PRIVATE ON)
113114
WEBKIT_OPTION_DEFAULT_PORT_VALUE(USE_AVIF PRIVATE OFF)
114115

115116

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env python3
2+
3+
'''
4+
/*
5+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
6+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7+
*
8+
* This code is free software; you can redistribute it and/or modify it
9+
* under the terms of the GNU General Public License version 2 only, as
10+
* published by the Free Software Foundation. Oracle designates this
11+
* particular file as subject to the "Classpath" exception as provided
12+
* by Oracle in the LICENSE file that accompanied this code.
13+
*
14+
* This code is distributed in the hope that it will be useful, but WITHOUT
15+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17+
* version 2 for more details (a copy is included in the LICENSE file that
18+
* accompanied this code).
19+
*
20+
* You should have received a copy of the GNU General Public License version
21+
* 2 along with this work; if not, write to the Free Software Foundation,
22+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23+
*
24+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
25+
* or visit www.oracle.com if you need additional information or have any
26+
* questions.
27+
*/
28+
'''
29+
'''
30+
Tool to generate base64 code
31+
'''
32+
import os
33+
import base64
34+
import sys
35+
36+
class ImageProcessor:
37+
def __init__(self, directory_path):
38+
self.directory_path = directory_path
39+
40+
def read_images(self):
41+
image_data = {}
42+
for filename in os.listdir(self.directory_path):
43+
if filename.lower().endswith(('.png', '.svg')):
44+
with open(os.path.join(self.directory_path, filename), 'rb') as image_file:
45+
image_data[filename] = image_file.read()
46+
return image_data
47+
48+
def generate_base64(self, image_data):
49+
base64_images = {}
50+
for filename, data in image_data.items():
51+
base64_images[filename] = base64.b64encode(data).decode('utf-8')
52+
return base64_images
53+
54+
if __name__ == "__main__":
55+
if len(sys.argv) != 2:
56+
print("Usage: python script_name.py directory_path")
57+
sys.exit(1)
58+
59+
image_directory = sys.argv[1]
60+
61+
if not os.path.isdir(image_directory):
62+
print("Invalid directory path.")
63+
sys.exit(1)
64+
65+
image_processor = ImageProcessor(image_directory)
66+
67+
images = image_processor.read_images()
68+
base64_images = image_processor.generate_base64(images)
69+
size_of_list = len(images)
70+
print("imageMap = {")
71+
for filename, base64_code in base64_images.items():
72+
file_name_without_extension = os.path.splitext(filename)[0]
73+
print("{"+file_name_without_extension +"_s, " + base64_code + "_s},")
74+
print("};")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
import javafx.application.Application;
27+
import javafx.scene.Scene;
28+
import javafx.scene.control.Label;
29+
import javafx.scene.layout.VBox;
30+
import javafx.scene.web.WebView;
31+
import javafx.stage.Stage;
32+
33+
public class HTML5VideoControlTest extends Application {
34+
@Override
35+
public void start(Stage primaryStage) {
36+
WebView webView = new WebView();
37+
webView.getEngine().loadContent(
38+
"<video width=\"320\" height=\"240\" controls>\n" +
39+
" <source src=\"https://download.oracle.com/otndocs/products/javafx/oow2010-2.mp4\">\n" +
40+
" Your browser does not support the video tag.\n" +
41+
"</video>"
42+
);
43+
44+
VBox root = new VBox();
45+
root.setSpacing(20);
46+
47+
root.getChildren().addAll(createInstructionsBox(), webView);
48+
49+
Scene scene = new Scene(root, 800, 400);
50+
primaryStage.setScene(scene);
51+
primaryStage.setTitle("HTML5 Video Player with Instructions");
52+
primaryStage.show();
53+
}
54+
55+
private VBox createInstructionsBox() {
56+
VBox instructionsBox = new VBox();
57+
instructionsBox.setStyle("-fx-background-color: #f0f0f0;");
58+
instructionsBox.setPrefWidth(400);
59+
60+
instructionsBox.getChildren().addAll(
61+
new Label("Instructions:"),
62+
new Label("1. Click 'Play' to start the video."),
63+
new Label("2. The media controls should be visible once the video starts playing."),
64+
new Label("3. Use the media controls to play/pause/seek the video.")
65+
);
66+
67+
return instructionsBox;
68+
}
69+
70+
public static void main(String[] args) {
71+
launch(args);
72+
}
73+
}

0 commit comments

Comments
 (0)
Please sign in to comment.