├── dependency-docs ├── .settings ├── org.eclipse.wst.validation.prefs ├── org.eclipse.core.resources.prefs ├── org.eclipse.m2e.core.prefs ├── org.eclipse.wst.common.project.facet.core.xml ├── org.eclipse.wst.common.component └── org.eclipse.jdt.core.prefs ├── src ├── META-INF │ └── services │ │ └── org.openqa.selenium.remote.server.DriverProvider ├── com │ ├── sun │ │ └── glass │ │ │ └── ui │ │ │ └── accessible │ │ │ ├── AccessibleRoot.java │ │ │ └── AccessibleBaseProvider.java │ └── machinepublishers │ │ ├── jbrowserdriver │ │ ├── diagnostics │ │ │ ├── image.png │ │ │ ├── iframe.htm │ │ │ └── test.htm │ │ ├── HeartbeatRemote.java │ │ ├── LogsRemote.java │ │ ├── Job.java │ │ ├── AlertRemote.java │ │ ├── FileRemover.java │ │ ├── RemoteObject.java │ │ ├── StatusCode.java │ │ ├── KeyboardRemote.java │ │ ├── SocketLock.java │ │ ├── NavigationRemote.java │ │ ├── Point.java │ │ ├── ImeHandlerRemote.java │ │ ├── SeleniumProvider.java │ │ ├── TitleListener.java │ │ ├── Dimension.java │ │ ├── WindowRemote.java │ │ ├── PopupHandler.java │ │ ├── ElementId.java │ │ ├── MouseRemote.java │ │ ├── Entry.java │ │ ├── Rectangle.java │ │ ├── Entries.java │ │ ├── OptionsRemote.java │ │ ├── TargetLocatorRemote.java │ │ ├── LogHandler.java │ │ ├── ImeHandlerServer.java │ │ ├── Logs.java │ │ ├── HeartbeatServer.java │ │ ├── TimeoutsRemote.java │ │ ├── PortGroup.java │ │ ├── Alert.java │ │ ├── Keyboard.java │ │ ├── KeyboardServer.java │ │ ├── Coordinates.java │ │ ├── Navigation.java │ │ ├── ProxyAuth.java │ │ ├── ImeHandler.java │ │ ├── StreamHandler.java │ │ ├── Window.java │ │ ├── NavigationServer.java │ │ ├── W3CActions.java │ │ ├── OptionsLocal.java │ │ ├── JavascriptLog.java │ │ ├── TimeoutsServer.java │ │ ├── Mouse.java │ │ ├── ElementRemote.java │ │ ├── TargetLocatorServer.java │ │ ├── WireLog.java │ │ ├── Timeouts.java │ │ ├── JBrowserDriverRemote.java │ │ ├── TargetLocator.java │ │ ├── MouseServer.java │ │ ├── AjaxListener.java │ │ ├── ProxyConfig.java │ │ ├── StatusMonitor.java │ │ ├── SocketFactory.java │ │ ├── App.java │ │ └── Options.java │ │ └── glass │ │ └── ui │ │ └── monocle │ │ ├── MonocleTrace.java │ │ ├── HeadlessPlatformFactory.java │ │ ├── NullCursor.java │ │ ├── MonocleSettings.java │ │ ├── InputDeviceRegistry.java │ │ ├── HeadlessPlatform.java │ │ ├── MonocleClipboardDelegate.java │ │ ├── MonocleSystemClipboard.java │ │ ├── RunnableQueue.java │ │ ├── InputDevice.java │ │ ├── MonocleDnDClipboard.java │ │ ├── MonocleTimer.java │ │ ├── MonoclePlatformFactory.java │ │ ├── NativeCursor.java │ │ ├── MonoclePixels.java │ │ ├── NativeScreen.java │ │ ├── HeadlessScreen.java │ │ ├── KeyState.java │ │ └── NativePlatform.java └── org │ └── openqa │ └── selenium │ └── WindowType.java ├── NOTICE ├── .gitignore ├── PULL_REQUEST_TEMPLATE ├── ReadMe.txt ├── .classpath ├── .project └── CLA-rev2-digital.txt /dependency-docs: -------------------------------------------------------------------------------- 1 | mvn dependency:sources 2 | mvn dependency:resolve -Dclassifier=javadoc -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /src/META-INF/services/org.openqa.selenium.remote.server.DriverProvider: -------------------------------------------------------------------------------- 1 | com.machinepublishers.jbrowserdriver.SeleniumProvider -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | encoding/src=UTF-8 4 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | jBrowserDriver (TM) 2 | Copyright (C) 2014-2018 jBrowserDriver committers 3 | https://github.com/MachinePublishers/jBrowserDriver -------------------------------------------------------------------------------- /src/com/sun/glass/ui/accessible/AccessibleRoot.java: -------------------------------------------------------------------------------- 1 | package com.sun.glass.ui.accessible; 2 | 3 | public interface AccessibleRoot { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/com/sun/glass/ui/accessible/AccessibleBaseProvider.java: -------------------------------------------------------------------------------- 1 | package com.sun.glass.ui.accessible; 2 | 3 | public interface AccessibleBaseProvider { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/diagnostics/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hollingsworthd/jBrowserDriver/HEAD/src/com/machinepublishers/jbrowserdriver/diagnostics/image.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/bin/ 2 | .metadata/ 3 | **/screenslicer.config 4 | **/download_cache* 5 | **/media_cache* 6 | jbrowserdriver*.zip 7 | jBrowserDriver*.zip 8 | **/*.log.* 9 | **/pemfile_cached 10 | target/ 11 | 12 | .idea 13 | *.iml -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /PULL_REQUEST_TEMPLATE: -------------------------------------------------------------------------------- 1 | Thank you for contributing to this project! 2 | 3 | If you haven't already done so, please agree to the Contributor's License Agreement: https://github.com/MachinePublishers/jBrowserDriver/blob/master/CLA-rev2-digital.txt 4 | 5 | You can edit that file to add your digital signature to the bottom. -------------------------------------------------------------------------------- /ReadMe.txt: -------------------------------------------------------------------------------- 1 | jBrowserDriver (TM) 2 | Copyright (C) 2014-2018 jBrowserDriver committers 3 | https://github.com/MachinePublishers/jBrowserDriver 4 | 5 | 6 | INSTALLATION: 7 | Add the JARs in the 'dist' directory to your project's classpath, 8 | or alternatively install via Maven: 9 | 10 | 11 | com.machinepublishers 12 | jbrowserdriver 13 | 1.0.0 14 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/diagnostics/iframe.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | test iframe 6 | 7 | 8 | 9 | click 10 | 11 | 12 | 18 | 19 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/HeartbeatRemote.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2017 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.Remote; 21 | import java.rmi.RemoteException; 22 | 23 | public interface HeartbeatRemote extends Remote { 24 | 25 | void heartbeat() throws RemoteException; 26 | } 27 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jbrowserdriver 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/LogsRemote.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.Remote; 21 | import java.rmi.RemoteException; 22 | import java.util.Set; 23 | 24 | interface LogsRemote extends Remote { 25 | 26 | Entries getRemote(String type) throws RemoteException; 27 | 28 | Set getAvailableLogTypes() throws RemoteException; 29 | } 30 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/Job.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.util.concurrent.atomic.AtomicReference; 21 | 22 | class Job { 23 | 24 | final Settings settings; 25 | final AtomicReference portGroup; 26 | 27 | Job(Settings settings, AtomicReference portGroup) { 28 | this.settings = settings; 29 | this.portGroup = portGroup; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/AlertRemote.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.Remote; 21 | import java.rmi.RemoteException; 22 | 23 | interface AlertRemote extends Remote { 24 | void accept() throws RemoteException; 25 | 26 | void dismiss() throws RemoteException; 27 | 28 | String getText() throws RemoteException; 29 | 30 | void sendKeys(String arg0) throws RemoteException; 31 | } 32 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/FileRemover.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.File; 21 | 22 | import org.apache.commons.io.FileUtils; 23 | 24 | class FileRemover extends Thread { 25 | private final File toDelete; 26 | 27 | FileRemover(File toDelete) { 28 | this.toDelete = toDelete; 29 | } 30 | 31 | @Override 32 | public void run() { 33 | FileUtils.deleteQuietly(toDelete); 34 | } 35 | } -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/RemoteObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.RemoteException; 21 | import java.rmi.server.UnicastRemoteObject; 22 | 23 | class RemoteObject extends UnicastRemoteObject { 24 | 25 | protected RemoteObject() throws RemoteException { 26 | super(JBrowserDriverServer.childPort(), 27 | JBrowserDriverServer.socketFactory(), JBrowserDriverServer.socketFactory()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/StatusCode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.util.concurrent.atomic.AtomicInteger; 21 | 22 | class StatusCode { 23 | private final AtomicInteger statusCode = new AtomicInteger(-1); 24 | 25 | void reset() { 26 | statusCode.set(-1); 27 | } 28 | 29 | void set(int statusCode) { 30 | this.statusCode.set(statusCode); 31 | } 32 | 33 | int get() { 34 | return statusCode.get(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/KeyboardRemote.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.Remote; 21 | import java.rmi.RemoteException; 22 | 23 | interface KeyboardRemote extends Remote { 24 | void pressKey(CharSequence key) throws RemoteException; 25 | 26 | void releaseKey(CharSequence key) throws RemoteException; 27 | 28 | void sendKeys(CharSequence... keys) throws RemoteException; 29 | 30 | boolean isShiftPressed() throws RemoteException; 31 | } 32 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/SocketLock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.Serializable; 21 | import java.util.concurrent.atomic.AtomicBoolean; 22 | 23 | class SocketLock implements Serializable { 24 | final AtomicBoolean expired = new AtomicBoolean(); 25 | 26 | SocketLock validated() { 27 | if (expired.get()) { 28 | throw new IllegalStateException("Operation attempted, but browser already quit."); 29 | } 30 | return this; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/NavigationRemote.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.net.URL; 21 | import java.rmi.Remote; 22 | import java.rmi.RemoteException; 23 | 24 | interface NavigationRemote extends Remote { 25 | void back() throws RemoteException; 26 | 27 | void forward() throws RemoteException; 28 | 29 | void refresh() throws RemoteException; 30 | 31 | void to(String url) throws RemoteException; 32 | 33 | void to(URL url) throws RemoteException; 34 | } 35 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/Point.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.Serializable; 21 | 22 | class Point implements Serializable { 23 | private final int x; 24 | private final int y; 25 | 26 | Point(int x, int y) { 27 | this.x = x; 28 | this.y = y; 29 | } 30 | 31 | Point(org.openqa.selenium.Point point) { 32 | this.x = point.x; 33 | this.y = point.y; 34 | } 35 | 36 | org.openqa.selenium.Point toSelenium() { 37 | return new org.openqa.selenium.Point(x, y); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/ImeHandlerRemote.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.Remote; 21 | import java.rmi.RemoteException; 22 | import java.util.List; 23 | 24 | interface ImeHandlerRemote extends Remote { 25 | void activateEngine(String name) throws RemoteException; 26 | 27 | void deactivate() throws RemoteException; 28 | 29 | String getActiveEngine() throws RemoteException; 30 | 31 | List getAvailableEngines() throws RemoteException; 32 | 33 | boolean isActivated() throws RemoteException; 34 | } 35 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/SeleniumProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import org.openqa.selenium.Platform; 21 | import org.openqa.selenium.remote.DesiredCapabilities; 22 | import org.openqa.selenium.remote.server.DefaultDriverProvider; 23 | 24 | /** 25 | * Internal use only. 26 | * 27 | * @deprecated 28 | */ 29 | public class SeleniumProvider extends DefaultDriverProvider { 30 | public SeleniumProvider() { 31 | super(new DesiredCapabilities("jbrowserdriver", "1", Platform.ANY), JBrowserDriver.class); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/TitleListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import javafx.beans.value.ChangeListener; 21 | import javafx.beans.value.ObservableValue; 22 | import javafx.stage.Stage; 23 | 24 | class TitleListener implements ChangeListener { 25 | private final Stage stage; 26 | 27 | TitleListener(Stage stage) { 28 | this.stage = stage; 29 | } 30 | 31 | /** 32 | * {@inheritDoc} 33 | */ 34 | @Override 35 | public void changed(ObservableValue observable, 36 | String oldValue, final String newValue) { 37 | stage.setTitle(newValue); 38 | } 39 | } -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/Dimension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.Serializable; 21 | 22 | class Dimension implements Serializable { 23 | private final int width; 24 | private final int height; 25 | 26 | Dimension(int width, int height) { 27 | this.width = width; 28 | this.height = height; 29 | } 30 | 31 | Dimension(org.openqa.selenium.Dimension dimension) { 32 | this.width = dimension.width; 33 | this.height = dimension.height; 34 | } 35 | 36 | org.openqa.selenium.Dimension toSelenium() { 37 | return new org.openqa.selenium.Dimension(width, height); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/WindowRemote.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.Remote; 21 | import java.rmi.RemoteException; 22 | 23 | interface WindowRemote extends Remote { 24 | void close() throws RemoteException; 25 | 26 | Point remoteGetPosition() throws RemoteException; 27 | 28 | Dimension remoteGetSize() throws RemoteException; 29 | 30 | void maximize() throws RemoteException; 31 | 32 | void fullscreen() throws RemoteException; 33 | 34 | void remoteSetPosition(final Point point) throws RemoteException; 35 | 36 | void remoteSetSize(final Dimension dimension) throws RemoteException; 37 | } 38 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/PopupHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import javafx.scene.web.PopupFeatures; 21 | import javafx.scene.web.WebEngine; 22 | import javafx.util.Callback; 23 | 24 | class PopupHandler implements Callback { 25 | private final JBrowserDriverServer driver; 26 | private final Context context; 27 | 28 | PopupHandler(final JBrowserDriverServer driver, final Context context) { 29 | this.driver = driver; 30 | this.context = context; 31 | } 32 | 33 | /** 34 | * {@inheritDoc} 35 | */ 36 | @Override 37 | public WebEngine call(PopupFeatures features) { 38 | return context.spawn(driver).engine.get(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/ElementId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.Serializable; 21 | import java.util.concurrent.atomic.AtomicLong; 22 | 23 | class ElementId implements Serializable { 24 | private static final AtomicLong scriptParamCounter = new AtomicLong(); 25 | private final Long id = scriptParamCounter.incrementAndGet(); 26 | 27 | @Override 28 | public int hashCode() { 29 | return id.hashCode(); 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (obj instanceof ElementId) { 35 | return id.equals(((ElementId) obj).id); 36 | } 37 | return false; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return id.toString(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/MouseRemote.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.Remote; 21 | import java.rmi.RemoteException; 22 | 23 | interface MouseRemote extends Remote { 24 | void remoteClick(Coordinates coords) throws RemoteException; 25 | 26 | void remoteContextClick(Coordinates coords) throws RemoteException; 27 | 28 | void remoteDoubleClick(Coordinates coords) throws RemoteException; 29 | 30 | void remoteMouseDown(Coordinates coords) throws RemoteException; 31 | 32 | void remoteMouseMove(Coordinates coords) throws RemoteException; 33 | 34 | void remoteMouseMove(Coordinates coords, long xOffset, long yOffset) throws RemoteException; 35 | 36 | void remoteMouseUp(Coordinates coords) throws RemoteException; 37 | } 38 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/Entry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.Serializable; 21 | import java.util.logging.Level; 22 | 23 | import org.openqa.selenium.logging.LogEntry; 24 | 25 | class Entry implements Serializable { 26 | 27 | private final Level level; 28 | private final long timestamp; 29 | private final String message; 30 | 31 | Entry(Level level, long timestamp, String message) { 32 | this.level = level; 33 | this.timestamp = timestamp; 34 | this.message = message; 35 | } 36 | 37 | LogEntry toLogEntry() { 38 | return new LogEntry(level, timestamp, message); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | @Override 45 | public String toString() { 46 | return toLogEntry().toString(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/Rectangle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.Serializable; 21 | 22 | class Rectangle implements Serializable { 23 | 24 | private final int x; 25 | private final int y; 26 | private final int height; 27 | private final int width; 28 | 29 | Rectangle(int x, int y, int height, int width) { 30 | this.x = x; 31 | this.y = y; 32 | this.height = height; 33 | this.width = width; 34 | } 35 | 36 | Rectangle(org.openqa.selenium.Rectangle rect) { 37 | this.x = rect.x; 38 | this.y = rect.y; 39 | this.height = rect.height; 40 | this.width = rect.width; 41 | } 42 | 43 | org.openqa.selenium.Rectangle toSelenium() { 44 | return new org.openqa.selenium.Rectangle(x, y, height, width); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/Entries.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.Serializable; 21 | import java.util.ArrayList; 22 | import java.util.Iterator; 23 | import java.util.List; 24 | 25 | import org.openqa.selenium.logging.LogEntries; 26 | import org.openqa.selenium.logging.LogEntry; 27 | 28 | class Entries implements Serializable { 29 | 30 | private final List entries = new ArrayList(); 31 | 32 | Entries(Iterable iterable) { 33 | Iterator iter = iterable.iterator(); 34 | while (iter.hasNext()) { 35 | entries.add(iter.next()); 36 | } 37 | } 38 | 39 | LogEntries toLogEntries() { 40 | List list = new ArrayList(); 41 | for (Entry entry : entries) { 42 | list.add(entry.toLogEntry()); 43 | } 44 | return new LogEntries(list); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/OptionsRemote.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.Remote; 21 | import java.rmi.RemoteException; 22 | import java.util.Set; 23 | 24 | import org.openqa.selenium.Cookie; 25 | 26 | interface OptionsRemote extends Remote { 27 | void addCookie(Cookie cookie) throws RemoteException; 28 | 29 | void deleteAllCookies() throws RemoteException; 30 | 31 | void deleteCookie(Cookie cookie) throws RemoteException; 32 | 33 | void deleteCookieNamed(String name) throws RemoteException; 34 | 35 | Cookie getCookieNamed(String name) throws RemoteException; 36 | 37 | Set getCookies() throws RemoteException; 38 | 39 | ImeHandlerRemote ime() throws RemoteException; 40 | 41 | LogsRemote logs() throws RemoteException; 42 | 43 | TimeoutsRemote timeouts() throws RemoteException; 44 | 45 | WindowRemote window() throws RemoteException; 46 | } 47 | -------------------------------------------------------------------------------- /src/org/openqa/selenium/WindowType.java: -------------------------------------------------------------------------------- 1 | // Licensed to the Software Freedom Conservancy (SFC) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The SFC licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | /* 19 | * Copied here by jBrowserDriver to support Selenium 3 and 4. Selenium 4 does not have this file. 20 | */ 21 | 22 | package org.openqa.selenium; 23 | 24 | /** 25 | * Represents the type of a new browser window that may be created. 26 | */ 27 | public enum WindowType { 28 | 29 | WINDOW ("window"), 30 | TAB ("tab"), 31 | ; 32 | 33 | private String text; 34 | 35 | WindowType(String text) { 36 | this.text = text; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return String.valueOf(text); 42 | } 43 | 44 | public static WindowType fromString(String text) { 45 | if (text != null) { 46 | for (WindowType b : WindowType.values()) { 47 | if (text.equalsIgnoreCase(b.text)) { 48 | return b; 49 | } 50 | } 51 | } 52 | return null; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/TargetLocatorRemote.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.Remote; 21 | import java.rmi.RemoteException; 22 | 23 | import org.openqa.selenium.WebDriver; 24 | import org.openqa.selenium.WindowType; 25 | 26 | interface TargetLocatorRemote extends Remote { 27 | ElementRemote activeElement() throws RemoteException; 28 | 29 | AlertRemote alert() throws RemoteException; 30 | 31 | JBrowserDriverRemote defaultContent() throws RemoteException; 32 | 33 | JBrowserDriverRemote frame(int arg0) throws RemoteException; 34 | 35 | JBrowserDriverRemote frame(String arg0) throws RemoteException; 36 | 37 | JBrowserDriverRemote frame(ElementRemote arg0) throws RemoteException; 38 | 39 | JBrowserDriverRemote parentFrame() throws RemoteException; 40 | 41 | JBrowserDriverRemote window(String windowHandle) throws RemoteException; 42 | 43 | JBrowserDriverRemote newWindow(WindowType windowType) throws RemoteException; 44 | } 45 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/LogHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.text.SimpleDateFormat; 21 | import java.util.Date; 22 | import java.util.TimeZone; 23 | import java.util.logging.Handler; 24 | import java.util.logging.Level; 25 | import java.util.logging.LogRecord; 26 | 27 | class LogHandler extends Handler { 28 | private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); 29 | static { 30 | dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); 31 | } 32 | 33 | @Override 34 | public void publish(LogRecord record) { 35 | String message = "[" + dateFormat.format(new Date(record.getMillis())) + "]" + record.getMessage(); 36 | if (record.getLevel().intValue() >= Level.WARNING.intValue()) { 37 | System.err.println(message); 38 | } else { 39 | System.out.println(message); 40 | } 41 | } 42 | 43 | @Override 44 | public void flush() {} 45 | 46 | @Override 47 | public void close() throws SecurityException {} 48 | } 49 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/ImeHandlerServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.RemoteException; 21 | import java.util.Arrays; 22 | import java.util.List; 23 | 24 | class ImeHandlerServer extends RemoteObject implements ImeHandlerRemote, 25 | org.openqa.selenium.WebDriver.ImeHandler { 26 | 27 | protected ImeHandlerServer() throws RemoteException { 28 | super(); 29 | } 30 | 31 | /** 32 | * {@inheritDoc} 33 | */ 34 | @Override 35 | public void activateEngine(String name) {} 36 | 37 | /** 38 | * {@inheritDoc} 39 | */ 40 | @Override 41 | public void deactivate() {} 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | public String getActiveEngine() { 48 | return "default"; 49 | } 50 | 51 | /** 52 | * {@inheritDoc} 53 | */ 54 | @Override 55 | public List getAvailableEngines() { 56 | return Arrays.asList(new String[] { "default" }); 57 | } 58 | 59 | /** 60 | * {@inheritDoc} 61 | */ 62 | @Override 63 | public boolean isActivated() { 64 | return true; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /CLA-rev2-digital.txt: -------------------------------------------------------------------------------- 1 | The maintainers of jBrowserDriver request that You sign a 2 | Contributor License Agreement ("CLA") regarding any software code and/or 3 | documentation You desire to contribute to jBrowserDriver ("Contribution"). 4 | 5 | By submitting your Contribution to jBrowserDriver, You hereby agree to license 6 | your Contribution under the Apache License, Version 2.0, and to include the 7 | appropriate copyright notice required by the license. 8 | 9 | The following have accepted the terms above as evidenced by their digital 10 | signatures and information below. If a corporation name is listed, then this 11 | Contribution is being made on behalf of a corporation. 12 | 13 | [Full Name] [GitHub Profile URL] [YYYY-MM-DD] [Corporation Name--if applicable] 14 | 15 | Arseniy Skvortsov https://github.com/askvortsov/ 2016-07-19 16 | Valery Yatsynovich https://github.com/valfirst 2016-08-15 17 | Michael Pinnegar https://github.com/jazzepi 2016-09-12 18 | Thomas Cashman https://github.com/tomcashman 2016-09-26 19 | Alex Luketa https://github.com/aluketa 2016-10-14 20 | Trask Stalnaker https://github.com/trask 2017-02-08 21 | Petr Jerabek https://github.com/cikorka 2017-02-10 22 | Bodo Junglas https://github.com/untoldwind 2017-02-23 23 | Arya Farzan https://github.com/arya6000 2017-03-18 24 | Vitali Kepin https://github.com/vkepin 2017-05-16 25 | D. Hollingsworth https://github.com/hollingsworthd 2017-06-25 26 | Nicholas DiPiazza https://github.com/nddipiazza/ 2017-08-08 27 | Alena Liashenka https://github.com/eichhornchen27 2017-12-08 28 | Uladzislau Arlouski https://github.com/uarlouski 2017-12-11 29 | contributions by (Vincent Smith https://github.com/vosmith 2018-06-08) 30 | included by (Adam Howard https://github.com/medavox 2018-07-06) 31 | Luis Fernandes https://github.com/zipleen 2019-07-30 32 | Jeff Vincent https://github.com/PredatorVI 2019-09-24 33 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/Logs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.util.Set; 21 | 22 | import org.openqa.selenium.logging.LogEntries; 23 | 24 | class Logs implements org.openqa.selenium.logging.Logs { 25 | private final LogsRemote remote; 26 | private final SocketLock lock; 27 | 28 | Logs(LogsRemote remote, SocketLock lock) { 29 | this.remote = remote; 30 | this.lock = lock; 31 | } 32 | 33 | /** 34 | * {@inheritDoc} 35 | */ 36 | @Override 37 | public LogEntries get(String type) { 38 | try { 39 | synchronized (lock.validated()) { 40 | return remote.getRemote(type).toLogEntries(); 41 | } 42 | } catch (Throwable t) { 43 | Util.handleException(t); 44 | return null; 45 | } 46 | } 47 | 48 | /** 49 | * {@inheritDoc} 50 | */ 51 | @Override 52 | public Set getAvailableLogTypes() { 53 | try { 54 | synchronized (lock.validated()) { 55 | return remote.getAvailableLogTypes(); 56 | } 57 | } catch (Throwable t) { 58 | Util.handleException(t); 59 | return null; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/HeartbeatServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2017 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.RemoteException; 21 | import java.util.concurrent.Executors; 22 | 23 | public class HeartbeatServer extends RemoteObject implements HeartbeatRemote { 24 | 25 | private volatile long lastHeartbeat; 26 | 27 | public HeartbeatServer() throws RemoteException { 28 | Executors.newSingleThreadExecutor().execute(() -> { 29 | try { 30 | // give 60 seconds for initial heartbeat 31 | Thread.sleep(60000); 32 | } catch (InterruptedException e) {} 33 | 34 | while (true) { 35 | if (System.currentTimeMillis() - lastHeartbeat > 60000) { 36 | // no heartbeat received in the last 60 seconds 37 | System.exit(1); 38 | } 39 | 40 | try { 41 | // sleep a bit to avoid busy loop 42 | Thread.sleep(5000); 43 | } catch (InterruptedException e) {} 44 | } 45 | }); 46 | } 47 | 48 | // this is called every ~5 seconds by parent process 49 | @Override 50 | public void heartbeat() throws RemoteException { 51 | lastHeartbeat = System.currentTimeMillis(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/MonocleTrace.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, 2015, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | class MonocleTrace { 29 | 30 | static void traceEvent(String format, Object... args) { 31 | trace("traceEvent", format, args); 32 | } 33 | 34 | static void traceConfig(String format, Object... args) { 35 | trace("traceConfig", format, args); 36 | } 37 | 38 | private static void trace(String prefix, String format, Object[] args) { 39 | synchronized (System.out) { 40 | System.out.print(prefix); 41 | System.out.print(": "); 42 | System.out.format(format, args); 43 | System.out.println(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/TimeoutsRemote.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.Remote; 21 | import java.rmi.RemoteException; 22 | import java.util.concurrent.TimeUnit; 23 | import java.util.concurrent.atomic.AtomicLong; 24 | 25 | interface TimeoutsRemote extends Remote { 26 | TimeoutsRemote implicitlyWait(long duration, TimeUnit unit) 27 | throws RemoteException; 28 | 29 | TimeoutsRemote pageLoadTimeout(long duration, TimeUnit unit) 30 | throws RemoteException; 31 | 32 | TimeoutsRemote setScriptTimeout(long duration, TimeUnit unit) 33 | throws RemoteException; 34 | 35 | TimeoutsServer setAlertTimeout(long duration, TimeUnit unit) 36 | throws RemoteException; 37 | 38 | long getImplicitlyWaitMS() throws RemoteException; 39 | 40 | long getPageLoadTimeoutMS() throws RemoteException; 41 | 42 | long getScriptTimeoutMS() throws RemoteException; 43 | 44 | long getAlertTimeoutMS() throws RemoteException; 45 | 46 | AtomicLong getImplicitlyWaitObjMS() throws RemoteException; 47 | 48 | AtomicLong getPageLoadTimeoutObjMS() throws RemoteException; 49 | 50 | AtomicLong getScriptTimeoutObjMS() throws RemoteException; 51 | 52 | AtomicLong getAlertTimeoutObjMS() throws RemoteException; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/PortGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.Serializable; 21 | 22 | class PortGroup implements Serializable { 23 | static final int SIZE = 3; 24 | final long child; 25 | final long parent; 26 | final long parentAlt; 27 | private final long[] ports; 28 | private final String id; 29 | private final int hashCode; 30 | 31 | PortGroup(long child, long parent, long parentAlt) { 32 | this.child = child; 33 | this.parent = parent; 34 | this.parentAlt = parentAlt; 35 | this.ports = new long[] { child, parent, parentAlt }; 36 | this.id = String.valueOf(child) + "/" + parent + "/" + parentAlt; 37 | this.hashCode = id.hashCode(); 38 | } 39 | 40 | @Override 41 | public int hashCode() { 42 | return hashCode; 43 | } 44 | 45 | @Override 46 | public boolean equals(Object obj) { 47 | return obj instanceof PortGroup && ((PortGroup) obj).id.equals(id); 48 | } 49 | 50 | boolean conflicts(PortGroup other) { 51 | if (other != null) { 52 | for (long thisPort : ports) { 53 | for (long otherPort : other.ports) { 54 | if (thisPort == otherPort) { 55 | return true; 56 | } 57 | } 58 | } 59 | } 60 | return false; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/HeadlessPlatformFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, 2014, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import com.machinepublishers.glass.ui.monocle.HeadlessPlatform; 29 | import com.machinepublishers.glass.ui.monocle.NativePlatform; 30 | import com.machinepublishers.glass.ui.monocle.NativePlatformFactory; 31 | 32 | class HeadlessPlatformFactory extends NativePlatformFactory { 33 | 34 | @Override 35 | protected boolean matches() { 36 | return true; 37 | } 38 | 39 | @Override 40 | protected int getMajorVersion() { 41 | return 1; 42 | } 43 | 44 | @Override 45 | protected int getMinorVersion() { 46 | return 0; 47 | } 48 | 49 | @Override 50 | protected NativePlatform createNativePlatform() { 51 | return new HeadlessPlatform(); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/NullCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, 2014, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import com.sun.glass.ui.Size; 29 | import com.machinepublishers.glass.ui.monocle.NativeCursor; 30 | 31 | /** 32 | * Provides an implementation of NativeCursor that does nothing and does not 33 | * show a cursor on the screen. 34 | */ 35 | class NullCursor extends NativeCursor { 36 | 37 | @Override 38 | Size getBestSize() { 39 | return new Size(16, 16); 40 | } 41 | 42 | @Override 43 | void setVisibility(boolean visibility) { 44 | } 45 | 46 | @Override 47 | void setImage(byte[] cursorImage) { 48 | } 49 | 50 | @Override 51 | void setLocation(int x, int y) { 52 | } 53 | 54 | @Override 55 | void setHotSpot(int hotspotX, int hotspotY) { 56 | } 57 | 58 | @Override 59 | void shutdown() { 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/MonocleSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, 2015, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import java.security.AccessController; 29 | import java.security.PrivilegedAction; 30 | 31 | import com.machinepublishers.glass.ui.monocle.MonocleSettings; 32 | 33 | class MonocleSettings { 34 | 35 | static final MonocleSettings settings = AccessController.doPrivileged( 36 | (PrivilegedAction) () -> new MonocleSettings()); 37 | 38 | final boolean traceEvents; 39 | final boolean traceEventsVerbose; 40 | final boolean tracePlatformConfig; 41 | 42 | private MonocleSettings() { 43 | traceEventsVerbose = Boolean.getBoolean("monocle.input.traceEvents.verbose"); 44 | traceEvents = traceEventsVerbose || Boolean.getBoolean("monocle.input.traceEvents"); 45 | tracePlatformConfig = Boolean.getBoolean("monocle.platform.traceConfig"); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/InputDeviceRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, 2014, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import com.machinepublishers.glass.ui.monocle.InputDevice; 29 | 30 | import javafx.collections.FXCollections; 31 | import javafx.collections.ObservableSet; 32 | 33 | /** 34 | * InputDeviceRegistry maintains an observable set of input devices. The 35 | * InputDeviceRegistry is responsible for detecting what input devices are 36 | * attached and for generating input events from these devices. 37 | */ 38 | class InputDeviceRegistry { 39 | protected ObservableSet devices = 40 | FXCollections.observableSet(); 41 | 42 | /** Returns the set of currently available input devices. 43 | * 44 | * @return an ObservableSet of input devices. This set should not be modified. 45 | */ 46 | ObservableSet getInputDevices() { 47 | return devices; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/Alert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | class Alert implements org.openqa.selenium.Alert { 21 | 22 | private final AlertRemote remote; 23 | private final SocketLock lock; 24 | 25 | Alert(AlertRemote remote, SocketLock lock) { 26 | this.remote = remote; 27 | this.lock = lock; 28 | } 29 | 30 | /** 31 | * {@inheritDoc} 32 | */ 33 | @Override 34 | public void accept() { 35 | try { 36 | synchronized (lock.validated()) { 37 | remote.accept(); 38 | } 39 | } catch (Throwable t) { 40 | Util.handleException(t); 41 | } 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | @Override 48 | public void dismiss() { 49 | try { 50 | synchronized (lock.validated()) { 51 | remote.dismiss(); 52 | } 53 | } catch (Throwable t) { 54 | Util.handleException(t); 55 | } 56 | } 57 | 58 | /** 59 | * {@inheritDoc} 60 | */ 61 | @Override 62 | public String getText() { 63 | try { 64 | synchronized (lock.validated()) { 65 | return remote.getText(); 66 | } 67 | } catch (Throwable t) { 68 | Util.handleException(t); 69 | return null; 70 | } 71 | } 72 | 73 | /** 74 | * {@inheritDoc} 75 | */ 76 | @Override 77 | public void sendKeys(String text) { 78 | try { 79 | synchronized (lock.validated()) { 80 | remote.sendKeys(text); 81 | } 82 | } catch (Throwable t) { 83 | Util.handleException(t); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/Keyboard.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | class Keyboard implements org.openqa.selenium.interactions.Keyboard { 21 | 22 | private final KeyboardRemote remote; 23 | private final SocketLock lock; 24 | 25 | Keyboard(KeyboardRemote remote, SocketLock lock) { 26 | this.remote = remote; 27 | this.lock = lock; 28 | } 29 | 30 | /** 31 | * {@inheritDoc} 32 | */ 33 | @Override 34 | public void pressKey(CharSequence key) { 35 | try { 36 | synchronized (lock.validated()) { 37 | remote.pressKey(key); 38 | } 39 | } catch (Throwable t) { 40 | Util.handleException(t); 41 | } 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | @Override 48 | public void releaseKey(CharSequence key) { 49 | try { 50 | synchronized (lock.validated()) { 51 | remote.releaseKey(key); 52 | } 53 | } catch (Throwable t) { 54 | Util.handleException(t); 55 | } 56 | } 57 | 58 | /** 59 | * {@inheritDoc} 60 | */ 61 | @Override 62 | public void sendKeys(CharSequence... keys) { 63 | try { 64 | synchronized (lock.validated()) { 65 | remote.sendKeys(keys); 66 | } 67 | } catch (Throwable t) { 68 | Util.handleException(t); 69 | } 70 | } 71 | 72 | boolean isShiftPressed() { 73 | try { 74 | synchronized (lock.validated()) { 75 | return remote.isShiftPressed(); 76 | } 77 | } catch (Throwable t) { 78 | Util.handleException(t); 79 | return false; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/KeyboardServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.RemoteException; 21 | import java.util.concurrent.atomic.AtomicReference; 22 | 23 | import org.openqa.selenium.Keys; 24 | 25 | class KeyboardServer extends RemoteObject implements KeyboardRemote, 26 | org.openqa.selenium.interactions.Keyboard { 27 | 28 | private final AtomicReference robot; 29 | private boolean shiftPressed; 30 | private final Object lock = new Object(); 31 | 32 | KeyboardServer(final AtomicReference robot) throws RemoteException { 33 | this.robot = robot; 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | @Override 40 | public void pressKey(CharSequence key) { 41 | synchronized (lock) { 42 | if (!shiftPressed) { 43 | shiftPressed = Keys.SHIFT.equals(key) || Keys.LEFT_SHIFT.equals(key); 44 | } 45 | } 46 | robot.get().keysPress(key); 47 | } 48 | 49 | /** 50 | * {@inheritDoc} 51 | */ 52 | @Override 53 | public void releaseKey(CharSequence key) { 54 | synchronized (lock) { 55 | if (shiftPressed) { 56 | shiftPressed = !Keys.SHIFT.equals(key) && !Keys.LEFT_SHIFT.equals(key); 57 | } 58 | } 59 | robot.get().keysRelease(key); 60 | } 61 | 62 | /** 63 | * {@inheritDoc} 64 | */ 65 | @Override 66 | public void sendKeys(CharSequence... keys) { 67 | robot.get().keysType(keys); 68 | } 69 | 70 | /** 71 | * {@inheritDoc} 72 | */ 73 | @Override 74 | public boolean isShiftPressed() { 75 | synchronized (lock) { 76 | return shiftPressed; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/HeadlessPlatform.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, 2014, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import com.machinepublishers.glass.ui.monocle.HeadlessScreen; 29 | import com.machinepublishers.glass.ui.monocle.InputDeviceRegistry; 30 | import com.machinepublishers.glass.ui.monocle.NativeCursor; 31 | import com.machinepublishers.glass.ui.monocle.NativePlatform; 32 | import com.machinepublishers.glass.ui.monocle.NativeScreen; 33 | import com.machinepublishers.glass.ui.monocle.NullCursor; 34 | 35 | public class HeadlessPlatform extends NativePlatform { 36 | 37 | @Override 38 | protected InputDeviceRegistry createInputDeviceRegistry() { 39 | // use of a LinuxInputDeviceRegistry lets us simulate 40 | // Linux input devices on any system 41 | // return new LinuxInputDeviceRegistry(true); 42 | return null; 43 | } 44 | 45 | @Override 46 | protected NativeCursor createCursor() { 47 | return new NullCursor(); 48 | } 49 | 50 | @Override 51 | protected NativeScreen createScreen() { 52 | return new HeadlessScreen(); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/Coordinates.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.Serializable; 21 | 22 | class Coordinates implements org.openqa.selenium.interactions.Coordinates, Serializable { 23 | 24 | private final Point inViewport; 25 | private final ElementRemote remote; 26 | private final SocketLock lock; 27 | 28 | Coordinates(ElementRemote remote, SocketLock lock) { 29 | this.remote = remote; 30 | this.lock = lock; 31 | this.inViewport = null; 32 | } 33 | 34 | Coordinates(org.openqa.selenium.interactions.Coordinates coords) { 35 | this.inViewport = coords.inViewPort() == null ? null : new Point(coords.inViewPort()); 36 | this.remote = null; 37 | this.lock = null; 38 | } 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | @Override 44 | public org.openqa.selenium.Point onScreen() { 45 | return null; 46 | } 47 | 48 | /** 49 | * {@inheritDoc} 50 | */ 51 | @Override 52 | public org.openqa.selenium.Point inViewPort() { 53 | if (inViewport == null) { 54 | synchronized (lock.validated()) { 55 | try { 56 | return remote.locate().toSelenium(); 57 | } catch (Throwable t) { 58 | Util.handleException(t); 59 | } 60 | } 61 | } else if (inViewport != null) { 62 | return inViewport.toSelenium(); 63 | } 64 | return null; 65 | } 66 | 67 | /** 68 | * {@inheritDoc} 69 | */ 70 | @Override 71 | public org.openqa.selenium.Point onPage() { 72 | return null; 73 | } 74 | 75 | /** 76 | * {@inheritDoc} 77 | */ 78 | @Override 79 | public Object getAuxiliary() { 80 | return null; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/MonocleClipboardDelegate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, 2014, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import com.sun.glass.ui.Clipboard; 29 | import com.sun.glass.ui.delegate.ClipboardDelegate; 30 | import com.machinepublishers.glass.ui.monocle.MonocleDnDClipboard; 31 | import com.machinepublishers.glass.ui.monocle.MonocleSystemClipboard; 32 | 33 | final class MonocleClipboardDelegate implements ClipboardDelegate { 34 | 35 | @Override 36 | public Clipboard createClipboard(String clipboardName) { 37 | // Currently only DnD clipboards are supported. 38 | // System clipboards will probably will not be supported as embedded 39 | // platforms do not support this functionality 40 | // We might support Selection clipboard in the future, but other systems 41 | // do not seem to use it at this point 42 | if (Clipboard.DND.equals(clipboardName)) { 43 | return new MonocleDnDClipboard(); 44 | } else if (Clipboard.SYSTEM.equals(clipboardName)) { 45 | return new MonocleSystemClipboard(); 46 | } else { 47 | return null; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/MonocleSystemClipboard.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2014, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import com.sun.glass.ui.Clipboard; 29 | import com.sun.glass.ui.SystemClipboard; 30 | 31 | import java.util.HashMap; 32 | 33 | /** There is no system clipboard on embedded Linux systems using a 34 | * framebuffer. For X11 and Android a different implementation will 35 | * be needed. */ 36 | final class MonocleSystemClipboard extends SystemClipboard { 37 | 38 | MonocleSystemClipboard() { 39 | super(Clipboard.SYSTEM); 40 | } 41 | 42 | protected boolean isOwner() { 43 | return true; 44 | } 45 | 46 | protected void pushToSystem(HashMap cacheData, 47 | int supportedActions) { 48 | } 49 | 50 | protected void pushTargetActionToSystem(int actionDone) { 51 | } 52 | protected Object popFromSystem(String mimeType) { 53 | return null; 54 | } 55 | 56 | protected int supportedSourceActionsFromSystem() { 57 | return Clipboard.ACTION_NONE; 58 | } 59 | 60 | protected String[] mimesFromSystem() { 61 | return new String[0]; 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/Navigation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.net.URL; 21 | 22 | class Navigation implements org.openqa.selenium.WebDriver.Navigation { 23 | private final NavigationRemote remote; 24 | private final SocketLock lock; 25 | 26 | Navigation(NavigationRemote remote, SocketLock lock) { 27 | this.remote = remote; 28 | this.lock = lock; 29 | } 30 | 31 | /** 32 | * {@inheritDoc} 33 | */ 34 | @Override 35 | public void back() { 36 | try { 37 | synchronized (lock.validated()) { 38 | remote.back(); 39 | } 40 | } catch (Throwable t) { 41 | Util.handleException(t); 42 | } 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @Override 49 | public void forward() { 50 | try { 51 | synchronized (lock.validated()) { 52 | remote.forward(); 53 | } 54 | } catch (Throwable t) { 55 | Util.handleException(t); 56 | } 57 | } 58 | 59 | /** 60 | * {@inheritDoc} 61 | */ 62 | @Override 63 | public void refresh() { 64 | try { 65 | synchronized (lock.validated()) { 66 | remote.refresh(); 67 | } 68 | } catch (Throwable t) { 69 | Util.handleException(t); 70 | } 71 | } 72 | 73 | /** 74 | * {@inheritDoc} 75 | */ 76 | @Override 77 | public void to(String url) { 78 | try { 79 | synchronized (lock.validated()) { 80 | remote.to(url); 81 | } 82 | } catch (Throwable t) { 83 | Util.handleException(t); 84 | } 85 | } 86 | 87 | /** 88 | * {@inheritDoc} 89 | */ 90 | @Override 91 | public void to(URL url) { 92 | try { 93 | synchronized (lock.validated()) { 94 | remote.to(url); 95 | } 96 | } catch (Throwable t) { 97 | Util.handleException(t); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/ProxyAuth.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | import org.apache.http.auth.AuthScope; 24 | import org.apache.http.auth.Credentials; 25 | import org.apache.http.auth.UsernamePasswordCredentials; 26 | import org.apache.http.client.CredentialsProvider; 27 | 28 | class ProxyAuth implements CredentialsProvider { 29 | private static final ProxyAuth instance = new ProxyAuth(); 30 | private static final Map proxies = new HashMap(); 31 | private static final Object lock = new Object(); 32 | 33 | private ProxyAuth() {} 34 | 35 | static ProxyAuth instance() { 36 | return instance; 37 | } 38 | 39 | static void add(final ProxyConfig proxy) { 40 | if (proxy != null && !proxy.directConnection() && proxy.credentials()) { 41 | synchronized (lock) { 42 | proxies.put(proxy.hostAndPort(), 43 | new UsernamePasswordCredentials(proxy.user(), proxy.password())); 44 | } 45 | } 46 | } 47 | 48 | static void remove(final ProxyConfig proxy) { 49 | if (proxy != null && !proxy.directConnection() && proxy.credentials()) { 50 | synchronized (lock) { 51 | proxies.remove(proxy.hostAndPort()); 52 | } 53 | } 54 | } 55 | 56 | /** 57 | * {@inheritDoc} 58 | */ 59 | @Override 60 | public Credentials getCredentials(AuthScope authScope) { 61 | synchronized (lock) { 62 | return proxies.get(authScope.getHost() + ":" + authScope.getPort()); 63 | } 64 | } 65 | 66 | /** 67 | * {@inheritDoc} 68 | */ 69 | @Override 70 | public void setCredentials(AuthScope authscope, Credentials credentials) { 71 | throw new UnsupportedOperationException(); 72 | } 73 | 74 | /** 75 | * {@inheritDoc} 76 | */ 77 | @Override 78 | public void clear() { 79 | throw new UnsupportedOperationException(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/RunnableQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import java.util.Arrays; 29 | 30 | class RunnableQueue { 31 | 32 | private Runnable[] queue = new Runnable[32]; 33 | private int start; 34 | private int count; 35 | 36 | private int modulo(int index) { 37 | if (index >= queue.length) { 38 | index -= queue.length; 39 | } 40 | return index; 41 | } 42 | 43 | synchronized void postRunnable(Runnable r) { 44 | if (count == queue.length) { 45 | Runnable[] newQueue = new Runnable[(queue.length * 3) / 2]; 46 | System.arraycopy(queue, start, newQueue, 0, queue.length - start); 47 | System.arraycopy(queue, 0, newQueue, queue.length - start, start); 48 | queue = newQueue; 49 | start = 0; 50 | } 51 | queue[modulo(start + count)] = r; 52 | count ++; 53 | notifyAll(); 54 | } 55 | 56 | synchronized Runnable getNextRunnable() throws InterruptedException { 57 | while (count == 0) { 58 | wait(); 59 | } 60 | Runnable r = queue[start]; 61 | queue[start] = null; 62 | start = modulo(start + 1); 63 | count --; 64 | return r; 65 | } 66 | 67 | synchronized void clear() { 68 | Arrays.fill(queue, null); 69 | count = 0; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/InputDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, 2014, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | /** 29 | * Abstraction of an input device and its capabilities 30 | */ 31 | interface InputDevice { 32 | 33 | /** 34 | * @return true if the device provides touch input for at least one touch 35 | * point. 36 | */ 37 | boolean isTouch(); 38 | 39 | /** 40 | * @return true if the device provides touch input for more than one touch 41 | * point. 42 | */ 43 | boolean isMultiTouch(); 44 | 45 | /** 46 | * @return true if the device provides relative pointing events. Relative 47 | * pointing events are those received from devices where the event signifies 48 | * a relative change in cursor position on the screen. For example, a mouse, 49 | * trackball, trackpad or joystick is a relative pointing device. A touch 50 | * screen is an sbsolute pointing device. 51 | */ 52 | boolean isRelative(); 53 | 54 | /** 55 | * @return true if the device provides direction arrow keys (UP, DOWN, LEFT 56 | * and RIGHT) and a selection key. 57 | */ 58 | boolean is5Way(); 59 | 60 | /** 61 | * @return true if the device provides keys for the letters 'A' through 'Z', 62 | * the digits '0' through '9' and also SPACE, SHIFT and TAB keys in addition 63 | * to directional arrows and a selection key. 64 | */ 65 | boolean isFullKeyboard(); 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/ImeHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | class ImeHandler implements org.openqa.selenium.WebDriver.ImeHandler { 24 | private final ImeHandlerRemote remote; 25 | private final SocketLock lock; 26 | 27 | ImeHandler(ImeHandlerRemote remote, SocketLock lock) { 28 | this.remote = remote; 29 | this.lock = lock; 30 | } 31 | 32 | /** 33 | * {@inheritDoc} 34 | */ 35 | @Override 36 | public void activateEngine(String name) { 37 | try { 38 | synchronized (lock.validated()) { 39 | remote.activateEngine(name); 40 | } 41 | } catch (Throwable t) { 42 | Util.handleException(t); 43 | } 44 | } 45 | 46 | /** 47 | * {@inheritDoc} 48 | */ 49 | @Override 50 | public void deactivate() { 51 | try { 52 | synchronized (lock.validated()) { 53 | remote.deactivate(); 54 | } 55 | } catch (Throwable t) { 56 | Util.handleException(t); 57 | } 58 | } 59 | 60 | /** 61 | * {@inheritDoc} 62 | */ 63 | @Override 64 | public String getActiveEngine() { 65 | try { 66 | synchronized (lock.validated()) { 67 | return remote.getActiveEngine(); 68 | } 69 | } catch (Throwable t) { 70 | Util.handleException(t); 71 | return null; 72 | } 73 | } 74 | 75 | /** 76 | * {@inheritDoc} 77 | */ 78 | @Override 79 | public List getAvailableEngines() { 80 | try { 81 | synchronized (lock.validated()) { 82 | return remote.getAvailableEngines(); 83 | } 84 | } catch (Throwable t) { 85 | Util.handleException(t); 86 | return new ArrayList(); 87 | } 88 | } 89 | 90 | /** 91 | * {@inheritDoc} 92 | */ 93 | @Override 94 | public boolean isActivated() { 95 | try { 96 | synchronized (lock.validated()) { 97 | return remote.isActivated(); 98 | } 99 | } catch (Throwable t) { 100 | Util.handleException(t); 101 | return false; 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/MonocleDnDClipboard.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2014, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import com.sun.glass.ui.Application; 29 | import com.sun.glass.ui.Clipboard; 30 | import com.sun.glass.ui.SystemClipboard; 31 | import com.machinepublishers.glass.ui.monocle.MonocleApplication; 32 | import com.machinepublishers.glass.ui.monocle.MouseInput; 33 | 34 | import java.util.HashMap; 35 | 36 | final class MonocleDnDClipboard extends SystemClipboard { 37 | 38 | MonocleDnDClipboard() { 39 | super(Clipboard.DND); 40 | } 41 | 42 | @Override 43 | protected boolean isOwner() { 44 | return true; 45 | } 46 | 47 | /** 48 | * Here the magic happens. 49 | * When this method is called all input events should be grabbed and 50 | * appropriate drag notifications should be sent instead of regular input 51 | * events 52 | */ 53 | @Override 54 | protected void pushToSystem(HashMap cacheData, int supportedActions) { 55 | MouseInput.getInstance().notifyDragStart(); 56 | ((MonocleApplication) Application.GetApplication()).enterDnDEventLoop(); 57 | actionPerformed(Clipboard.ACTION_COPY_OR_MOVE); 58 | } 59 | 60 | @Override 61 | protected void pushTargetActionToSystem(int actionDone) { 62 | } 63 | 64 | @Override 65 | protected Object popFromSystem(String mimeType) { 66 | return null; 67 | } 68 | 69 | @Override 70 | protected int supportedSourceActionsFromSystem() { 71 | return Clipboard.ACTION_COPY_OR_MOVE; 72 | } 73 | 74 | @Override 75 | protected String[] mimesFromSystem() { 76 | return new String[0]; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/diagnostics/test.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 14 | 15 |
test1
16 |
test2
17 | anchor 18 | anchor 19 | anchor 20 | invisible anchor 21 | 22 |   23 | 24 | 25 | 26 |
Testing
invisible
text.
27 |
28 | 29 | 33 | 34 | 35 | 36 | 37 | 38 | 42 |
43 |
44 | 45 |
46 | 47 | 48 |
49 | 50 | 51 |
52 | 61 | 62 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/MonocleTimer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011, 2014, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import com.sun.glass.ui.Timer; 29 | 30 | /** 31 | * Monocle implementation class for Timer. 32 | */ 33 | final class MonocleTimer extends Timer { 34 | private static java.util.Timer timer; 35 | private java.util.TimerTask task; 36 | 37 | MonocleTimer(final Runnable runnable) { 38 | super(runnable); 39 | } 40 | 41 | static int getMinPeriod_impl() { 42 | return 0; 43 | } 44 | 45 | static int getMaxPeriod_impl() { 46 | return 1000000; 47 | } 48 | 49 | @Override protected long _start(final Runnable runnable, int period) { 50 | if (timer == null) { 51 | timer = new java.util.Timer(true); 52 | } 53 | 54 | task = new java.util.TimerTask() { 55 | 56 | @Override 57 | public void run() { 58 | runnable.run(); 59 | } 60 | }; 61 | 62 | timer.schedule(task, 0, (long)period); 63 | return 1; // need something non-zero to denote success. 64 | } 65 | 66 | @Override protected long _start(Runnable runnable) { 67 | throw new RuntimeException("vsync timer not supported"); 68 | } 69 | 70 | @Override protected void _stop(long timer) { 71 | if (task != null) { 72 | task.cancel(); 73 | task = null; 74 | } 75 | } 76 | 77 | //Override -- not an annotation so we maintain backward compatibility with things earlier than Java 8u212 78 | protected void _pause(long timer) {} 79 | 80 | //Override -- not an annotation so we maintain backward compatibility with things earlier than Java 8u212 81 | protected void _resume(long timer) {} 82 | } 83 | 84 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/StreamHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.IOException; 21 | import java.net.URL; 22 | import java.net.URLConnection; 23 | import java.net.URLStreamHandler; 24 | import java.net.URLStreamHandlerFactory; 25 | 26 | class StreamHandler implements URLStreamHandlerFactory { 27 | StreamHandler() {} 28 | 29 | private static class HttpHandler extends sun.net.www.protocol.http.Handler { 30 | @Override 31 | protected URLConnection openConnection(URL url) throws IOException { 32 | return new StreamConnection(url); 33 | } 34 | 35 | private URLConnection defaultConnection(URL url) throws IOException { 36 | return super.openConnection(url); 37 | } 38 | } 39 | 40 | private static class HttpsHandler extends sun.net.www.protocol.https.Handler { 41 | @Override 42 | protected URLConnection openConnection(URL url) throws IOException { 43 | return new StreamConnection(url); 44 | } 45 | 46 | private URLConnection defaultConnection(URL url) throws IOException { 47 | return super.openConnection(url); 48 | } 49 | } 50 | 51 | static URLConnection defaultConnection(URL url) throws IOException { 52 | return "https".equals(url.getProtocol()) 53 | ? new HttpsHandler().defaultConnection(url) : new HttpHandler().defaultConnection(url); 54 | } 55 | 56 | /** 57 | * {@inheritDoc} 58 | */ 59 | @Override 60 | public URLStreamHandler createURLStreamHandler(String protocol) { 61 | if ("http".equals(protocol)) { 62 | return new HttpHandler(); 63 | } 64 | if ("https".equals(protocol)) { 65 | return new HttpsHandler(); 66 | } 67 | if ("about".equals(protocol)) { 68 | return new com.sun.webkit.network.about.Handler(); 69 | } 70 | if ("data".equals(protocol)) { 71 | return new com.sun.webkit.network.data.Handler(); 72 | } 73 | if ("file".equals(protocol)) { 74 | return new sun.net.www.protocol.file.Handler(); 75 | } 76 | if ("ftp".equals(protocol)) { 77 | return new sun.net.www.protocol.ftp.Handler(); 78 | } 79 | if ("jar".equals(protocol)) { 80 | return new sun.net.www.protocol.jar.Handler(); 81 | } 82 | if ("mailto".equals(protocol)) { 83 | return new sun.net.www.protocol.mailto.Handler(); 84 | } 85 | return null; 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/MonoclePlatformFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, 2014, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import com.sun.glass.ui.Application; 29 | import com.sun.glass.ui.Menu; 30 | import com.sun.glass.ui.MenuBar; 31 | import com.sun.glass.ui.MenuItem; 32 | import com.sun.glass.ui.PlatformFactory; 33 | import com.sun.glass.ui.Window; 34 | import com.sun.glass.ui.accessible.AccessibleBaseProvider; 35 | import com.sun.glass.ui.accessible.AccessibleRoot; 36 | import com.sun.glass.ui.delegate.ClipboardDelegate; 37 | import com.sun.glass.ui.delegate.MenuBarDelegate; 38 | import com.sun.glass.ui.delegate.MenuDelegate; 39 | import com.sun.glass.ui.delegate.MenuItemDelegate; 40 | 41 | public class MonoclePlatformFactory extends PlatformFactory { 42 | @Override 43 | public Application createApplication() { 44 | return new MonocleApplication(); 45 | } 46 | 47 | @Override 48 | public MenuBarDelegate createMenuBarDelegate(MenuBar menubar) { 49 | throw new UnsupportedOperationException(); 50 | } 51 | 52 | @Override 53 | public MenuDelegate createMenuDelegate(Menu menu) { 54 | throw new UnsupportedOperationException(); 55 | } 56 | 57 | @Override 58 | public MenuItemDelegate createMenuItemDelegate(MenuItem menuItem) { 59 | throw new UnsupportedOperationException(); 60 | } 61 | 62 | @Override 63 | public ClipboardDelegate createClipboardDelegate() { 64 | return new MonocleClipboardDelegate(); 65 | } 66 | 67 | //@Override 68 | public AccessibleRoot createAccessibleRoot(Object node, Window window) { 69 | // TODO Auto-generated method stub 70 | return null; 71 | } 72 | 73 | //@Override 74 | public AccessibleBaseProvider createAccessibleProvider(Object node) { 75 | // TODO Auto-generated method stub 76 | return null; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/Window.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | class Window implements org.openqa.selenium.WebDriver.Window { 21 | private final WindowRemote remote; 22 | private final SocketLock lock; 23 | 24 | Window(WindowRemote remote, SocketLock lock) { 25 | this.remote = remote; 26 | this.lock = lock; 27 | } 28 | 29 | /** 30 | * {@inheritDoc} 31 | */ 32 | @Override 33 | public org.openqa.selenium.Point getPosition() { 34 | try { 35 | synchronized (lock.validated()) { 36 | return remote.remoteGetPosition().toSelenium(); 37 | } 38 | } catch (Throwable t) { 39 | Util.handleException(t); 40 | return null; 41 | } 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | @Override 48 | public org.openqa.selenium.Dimension getSize() { 49 | try { 50 | synchronized (lock.validated()) { 51 | return remote.remoteGetSize().toSelenium(); 52 | } 53 | } catch (Throwable t) { 54 | Util.handleException(t); 55 | return null; 56 | } 57 | } 58 | 59 | /** 60 | * {@inheritDoc} 61 | */ 62 | @Override 63 | public void maximize() { 64 | try { 65 | synchronized (lock.validated()) { 66 | remote.maximize(); 67 | } 68 | } catch (Throwable t) { 69 | Util.handleException(t); 70 | } 71 | } 72 | 73 | /** 74 | * {@inheritDoc} 75 | */ 76 | @Override 77 | public void setPosition(final org.openqa.selenium.Point point) { 78 | try { 79 | synchronized (lock.validated()) { 80 | remote.remoteSetPosition(new Point(point)); 81 | } 82 | } catch (Throwable t) { 83 | Util.handleException(t); 84 | } 85 | } 86 | 87 | /** 88 | * {@inheritDoc} 89 | */ 90 | @Override 91 | public void setSize(final org.openqa.selenium.Dimension dimension) { 92 | try { 93 | synchronized (lock.validated()) { 94 | remote.remoteSetSize(new Dimension(dimension)); 95 | } 96 | } catch (Throwable t) { 97 | Util.handleException(t); 98 | } 99 | } 100 | 101 | /** 102 | * {@inheritDoc} 103 | */ 104 | @Override 105 | public void fullscreen() { 106 | try { 107 | synchronized (lock.validated()) { 108 | remote.fullscreen(); 109 | } 110 | } catch (Throwable t) { 111 | Util.handleException(t); 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/NavigationServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.net.URL; 21 | import java.rmi.RemoteException; 22 | import java.util.concurrent.atomic.AtomicReference; 23 | 24 | import com.machinepublishers.jbrowserdriver.AppThread.Sync; 25 | 26 | class NavigationServer extends RemoteObject implements NavigationRemote, 27 | org.openqa.selenium.WebDriver.Navigation { 28 | private final AtomicReference driver; 29 | private final Context context; 30 | 31 | NavigationServer(final AtomicReference driver, final Context context) 32 | throws RemoteException { 33 | this.driver = driver; 34 | this.context = context; 35 | } 36 | 37 | /** 38 | * {@inheritDoc} 39 | */ 40 | @Override 41 | public void back() { 42 | AppThread.exec(context.item().statusCode, ((TimeoutsServer) driver.get().manage().timeouts()).getPageLoadTimeoutMS(), 43 | () -> { 44 | try { 45 | context.item().view.get().getEngine().getHistory().go(-1); 46 | } catch (IndexOutOfBoundsException e) { 47 | LogsServer.instance().exception(e); 48 | } 49 | return null; 50 | }); 51 | } 52 | 53 | /** 54 | * {@inheritDoc} 55 | */ 56 | @Override 57 | public void forward() { 58 | AppThread.exec(context.item().statusCode, ((TimeoutsServer) driver.get().manage().timeouts()).getPageLoadTimeoutMS(), 59 | () -> { 60 | try { 61 | context.item().view.get().getEngine().getHistory().go(1); 62 | } catch (IndexOutOfBoundsException e) { 63 | LogsServer.instance().exception(e); 64 | } 65 | return null; 66 | }); 67 | } 68 | 69 | /** 70 | * {@inheritDoc} 71 | */ 72 | @Override 73 | public void refresh() { 74 | AppThread.exec(context.item().statusCode, ((TimeoutsServer) driver.get().manage().timeouts()).getPageLoadTimeoutMS(), 75 | () -> { 76 | context.item().view.get().getEngine().reload(); 77 | return null; 78 | }); 79 | } 80 | 81 | /** 82 | * {@inheritDoc} 83 | */ 84 | @Override 85 | public void to(String url) { 86 | driver.get().get(url); 87 | } 88 | 89 | /** 90 | * {@inheritDoc} 91 | */ 92 | @Override 93 | public void to(URL url) { 94 | driver.get().get(url.toExternalForm()); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/W3CActions.java: -------------------------------------------------------------------------------- 1 | package com.machinepublishers.jbrowserdriver; 2 | 3 | import java.util.Arrays; 4 | import java.util.Map; 5 | 6 | import com.google.common.base.CaseFormat; 7 | 8 | import org.openqa.selenium.interactions.Keyboard; 9 | import org.openqa.selenium.interactions.Mouse; 10 | 11 | public enum W3CActions { 12 | PAUSE { 13 | @Override 14 | Element perform(Object actionExecutor, Element lastProcessedElement, Map descriptor) { 15 | try { 16 | Thread.sleep((long) descriptor.get("duration")); 17 | return lastProcessedElement; 18 | } catch (InterruptedException e) { 19 | throw new IllegalStateException(e); 20 | } 21 | } 22 | }, 23 | KEY_DOWN { 24 | @Override 25 | Element perform(Object actionExecutor, Element lastProcessedElement, Map descriptor) { 26 | ((Keyboard) actionExecutor).pressKey((CharSequence) descriptor.get("value")); 27 | return lastProcessedElement; 28 | } 29 | }, 30 | KEY_UP { 31 | @Override 32 | Element perform(Object actionExecutor, Element lastProcessedElement, Map descriptor) { 33 | ((Keyboard) actionExecutor).releaseKey((CharSequence) descriptor.get("value")); 34 | return lastProcessedElement; 35 | } 36 | }, 37 | POINTER_DOWN { 38 | @Override 39 | Element perform(Object actionExecutor, Element lastProcessedElement, Map descriptor) { 40 | ((Mouse) actionExecutor).mouseDown(getCoordinetes(lastProcessedElement)); 41 | return lastProcessedElement; 42 | } 43 | }, 44 | POINTER_UP { 45 | @Override 46 | Element perform(Object actionExecutor, Element lastProcessedElement, Map descriptor) { 47 | ((Mouse) actionExecutor).mouseUp(getCoordinetes(lastProcessedElement)); 48 | return lastProcessedElement; 49 | } 50 | }, 51 | POINTER_MOVE { 52 | @Override 53 | Element perform(Object actionExecutor, Element lastProcessedElement, Map descriptor) { 54 | int x = (int) descriptor.get("x"); 55 | int y = (int) descriptor.get("y"); 56 | Element currentElement = (Element) descriptor.get("origin"); 57 | ((Mouse) actionExecutor).mouseMove(currentElement.getCoordinates(), x, y); 58 | return currentElement; 59 | } 60 | }, 61 | POINTER_CANCEL { 62 | @Override 63 | Element perform(Object actionExecutor, Element lastProcessedElement, Map descriptor) { 64 | throw new UnsupportedOperationException("Action 'pointerCancel' is not supported"); 65 | } 66 | }; 67 | 68 | private final String type; 69 | 70 | private W3CActions() { 71 | this.type = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name()); 72 | } 73 | 74 | abstract Element perform(Object actionExecutor, Element lastProcessedElement, Map descriptor); 75 | 76 | Coordinates getCoordinetes(Element element) 77 | { 78 | return element == null ? null : element.getCoordinates(); 79 | } 80 | 81 | static W3CActions findActionByType(String type) { 82 | return Arrays.stream(W3CActions.values()).filter(v -> v.type.equals(type)).findFirst() 83 | .orElseThrow(() -> new IllegalArgumentException("There is no action with type " + type)); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/NativeCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, 2014, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import com.sun.glass.ui.Size; 29 | 30 | /** 31 | * Abstraction of a native cursor 32 | */ 33 | abstract class NativeCursor { 34 | 35 | /** 36 | * Is the cursor currently visible? 37 | */ 38 | protected boolean isVisible = false; 39 | 40 | /** 41 | * Returns the preferred size of a native cursor. 42 | */ 43 | abstract Size getBestSize(); 44 | 45 | /** 46 | * Sets whether or not the cursor is visible. The implementation should set 47 | * the isVisible field. On success the isVisible field is set to the 48 | * visibility parameter. 49 | * 50 | * @param visibility the new setting for the cursor's visibility. 51 | */ 52 | abstract void setVisibility(boolean visibility); 53 | 54 | /** 55 | * Queries whether or not the cursor is visible 56 | * 57 | * @return trueif the cursor is visible, false otherwise. 58 | */ 59 | boolean getVisiblity() { 60 | return isVisible; 61 | } 62 | 63 | /** 64 | * Sets the cursor image 65 | * 66 | * @param cursorImage the cursor image, in BYTE_BGRA_PRE format 67 | */ 68 | abstract void setImage(byte[] cursorImage); 69 | 70 | /** 71 | * Sets the location of the hot spot of the cursor on the screen 72 | * 73 | * @param x the new X location on the screen 74 | * @param y the new Y location on the screen 75 | */ 76 | abstract void setLocation(int x, int y); 77 | 78 | /** 79 | * Sets the offset of the cursor's hot spot within the cursor image The hot 80 | * spot offsets default to 0, 0. 81 | * 82 | * @param hotspotX the X offset of the hot spot 83 | * @param hotspotY the Y offset of the hot spot. 84 | */ 85 | abstract void setHotSpot(int hotspotX, int hotspotY); 86 | 87 | /** 88 | * Performs any necessary shutdown of the cursor infrastructure. Called only 89 | * once. 90 | */ 91 | abstract void shutdown(); 92 | } 93 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/OptionsLocal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.util.LinkedHashSet; 21 | import java.util.Set; 22 | 23 | import org.openqa.selenium.Cookie; 24 | import org.openqa.selenium.WebDriver.ImeHandler; 25 | import org.openqa.selenium.WebDriver.Window; 26 | import org.openqa.selenium.logging.Logs; 27 | 28 | class OptionsLocal implements org.openqa.selenium.WebDriver.Options { 29 | private final Set cookies; 30 | private final Logs logs; 31 | 32 | OptionsLocal(Set cookies, Logs logs) { 33 | this.cookies = cookies; 34 | this.logs = logs; 35 | } 36 | 37 | /** 38 | * {@inheritDoc} 39 | */ 40 | @Override 41 | public void addCookie(Cookie cookie) { 42 | cookies.add(cookie); 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @Override 49 | public void deleteCookieNamed(String name) { 50 | Cookie toRemove = null; 51 | for (Cookie cookie : cookies) { 52 | if (cookie.getName().equals(name)) { 53 | toRemove = cookie; 54 | break; 55 | } 56 | } 57 | if (toRemove != null) { 58 | cookies.remove(toRemove); 59 | } 60 | } 61 | 62 | /** 63 | * {@inheritDoc} 64 | */ 65 | @Override 66 | public void deleteCookie(Cookie cookie) { 67 | cookies.remove(cookie); 68 | 69 | } 70 | 71 | /** 72 | * {@inheritDoc} 73 | */ 74 | @Override 75 | public void deleteAllCookies() { 76 | cookies.clear(); 77 | } 78 | 79 | /** 80 | * {@inheritDoc} 81 | */ 82 | @Override 83 | public Set getCookies() { 84 | return new LinkedHashSet(cookies); 85 | } 86 | 87 | /** 88 | * {@inheritDoc} 89 | */ 90 | @Override 91 | public Cookie getCookieNamed(String name) { 92 | for (Cookie cookie : cookies) { 93 | if (cookie.getName().equals(name)) { 94 | return cookie; 95 | } 96 | } 97 | return null; 98 | } 99 | 100 | /** 101 | * {@inheritDoc} 102 | */ 103 | @Override 104 | public org.openqa.selenium.WebDriver.Timeouts timeouts() { 105 | return null; 106 | } 107 | 108 | /** 109 | * {@inheritDoc} 110 | */ 111 | @Override 112 | public ImeHandler ime() { 113 | return null; 114 | } 115 | 116 | /** 117 | * {@inheritDoc} 118 | */ 119 | @Override 120 | public Window window() { 121 | return null; 122 | } 123 | 124 | /** 125 | * {@inheritDoc} 126 | */ 127 | @Override 128 | public Logs logs() { 129 | return logs; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/JavascriptLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import com.machinepublishers.jbrowserdriver.AppThread.Sync; 21 | import com.sun.webkit.WebPage; 22 | 23 | import netscape.javascript.JSObject; 24 | 25 | class JavascriptLog { 26 | 27 | private static final String bridgeName = Util.randomPropertyName(); 28 | private static final Bridge bridge = new Bridge(); 29 | private static final String consoleScript; 30 | static { 31 | consoleScript = new StringBuilder() 32 | .append(consoleFunction("error")) 33 | .append(consoleFunction("warn")) 34 | .append(consoleFunction("log")) 35 | .append(consoleFunction("info")) 36 | .append(consoleFunction("assert")) 37 | .append("window.addEventListener('error',function(){") 38 | .append("try{") 39 | .append(bridgeName).append(".log(JSON.stringify(") 40 | .append("{window_onerror:arguments[0].message, filename:arguments[0].filename, lineno:arguments[0].lineno}") 41 | .append("));}catch(ex){") 42 | .append(bridgeName).append(".log(JSON.stringify({") 43 | .append("window_onerror:'WebDriver message could not be stringified.'}));}") 44 | .append("return false;});").toString(); 45 | } 46 | 47 | static void attach(WebPage page, long frameId) { 48 | AppThread.exec(() -> { 49 | JSObject window = (JSObject) page.executeScript(frameId, "(function(){return window;})();"); 50 | if (window != null) { 51 | window.setMember(bridgeName, bridge); 52 | page.executeScript(frameId, consoleScript); 53 | } 54 | return null; 55 | }); 56 | } 57 | 58 | private static final String consoleFunction(String jsName) { 59 | return new StringBuilder() 60 | .append("try{") 61 | .append("Object.defineProperty(console,'") 62 | .append(jsName).append("',{get: (function(){return function(){try{") 63 | .append("var arr = [];") 64 | .append("for(var i in arguments){") 65 | .append("arr.push(arguments[i]);") 66 | .append("}") 67 | .append(bridgeName).append(".log(JSON.stringify({console_").append(jsName).append(":arr}));") 68 | .append("}catch(ex){") 69 | .append(bridgeName).append(".").append("log(JSON.stringify({") 70 | .append("console_") 71 | .append(jsName).append(":'WebDriver message could not be stringified.'}));") 72 | .append("}};})});}catch(ex){}") 73 | .toString(); 74 | } 75 | 76 | private JavascriptLog() { 77 | 78 | } 79 | 80 | public static class Bridge { 81 | private Bridge() {} 82 | 83 | public void log(String message) { 84 | LogsServer.instance().javascript(message); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/TimeoutsServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.RemoteException; 21 | import java.util.concurrent.TimeUnit; 22 | import java.util.concurrent.atomic.AtomicLong; 23 | 24 | class TimeoutsServer extends RemoteObject implements TimeoutsRemote, 25 | org.openqa.selenium.WebDriver.Timeouts { 26 | private final AtomicLong implicit = new AtomicLong(); 27 | private final AtomicLong load = new AtomicLong(); 28 | private final AtomicLong script = new AtomicLong(); 29 | private final AtomicLong alert = new AtomicLong(); 30 | 31 | TimeoutsServer() throws RemoteException {} 32 | 33 | /** 34 | * {@inheritDoc} 35 | */ 36 | @Override 37 | public TimeoutsServer implicitlyWait(long duration, TimeUnit unit) { 38 | implicit.set(TimeUnit.MILLISECONDS.convert(duration, unit)); 39 | return this; 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | @Override 46 | public TimeoutsServer pageLoadTimeout(long duration, TimeUnit unit) { 47 | load.set(TimeUnit.MILLISECONDS.convert(duration, unit)); 48 | return this; 49 | } 50 | 51 | /** 52 | * {@inheritDoc} 53 | */ 54 | @Override 55 | public TimeoutsServer setScriptTimeout(long duration, TimeUnit unit) { 56 | script.set(TimeUnit.MILLISECONDS.convert(duration, unit)); 57 | return this; 58 | } 59 | 60 | /** 61 | * {@inheritDoc} 62 | */ 63 | @Override 64 | public TimeoutsServer setAlertTimeout(long duration, TimeUnit unit) { 65 | alert.set(TimeUnit.MILLISECONDS.convert(duration, unit)); 66 | return this; 67 | } 68 | 69 | /** 70 | * {@inheritDoc} 71 | */ 72 | @Override 73 | public long getImplicitlyWaitMS() { 74 | return implicit.get(); 75 | } 76 | 77 | /** 78 | * {@inheritDoc} 79 | */ 80 | @Override 81 | public long getPageLoadTimeoutMS() { 82 | return load.get(); 83 | } 84 | 85 | /** 86 | * {@inheritDoc} 87 | */ 88 | @Override 89 | public long getScriptTimeoutMS() { 90 | return script.get(); 91 | } 92 | 93 | /** 94 | * {@inheritDoc} 95 | */ 96 | @Override 97 | public long getAlertTimeoutMS() { 98 | return alert.get(); 99 | } 100 | 101 | /** 102 | * {@inheritDoc} 103 | */ 104 | @Override 105 | public AtomicLong getImplicitlyWaitObjMS() { 106 | return implicit; 107 | } 108 | 109 | /** 110 | * {@inheritDoc} 111 | */ 112 | @Override 113 | public AtomicLong getPageLoadTimeoutObjMS() { 114 | return load; 115 | } 116 | 117 | /** 118 | * {@inheritDoc} 119 | */ 120 | @Override 121 | public AtomicLong getScriptTimeoutObjMS() { 122 | return script; 123 | } 124 | 125 | /** 126 | * {@inheritDoc} 127 | */ 128 | @Override 129 | public AtomicLong getAlertTimeoutObjMS() { 130 | return alert; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/MonoclePixels.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2014, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import java.nio.Buffer; 29 | import java.nio.ByteBuffer; 30 | import java.nio.IntBuffer; 31 | 32 | import com.sun.glass.ui.Pixels; 33 | 34 | final class MonoclePixels extends Pixels { 35 | 36 | MonoclePixels(int width, int height, ByteBuffer data) { 37 | super(width, height, data); 38 | } 39 | 40 | MonoclePixels(int width, int height, IntBuffer data) { 41 | super(width, height, data); 42 | } 43 | 44 | MonoclePixels(int width, int height, IntBuffer data, float scale) { 45 | super(width, height, data);//Java 8 and Java 9 constructors conflict--work around: use a constructor they both have 46 | } 47 | 48 | MonoclePixels(int width, int height, IntBuffer data, float scalex, float scaley) { 49 | super(width, height, data);//Java 8 and Java 9 constructors conflict--work around: use a constructor they both have 50 | } 51 | 52 | private void _copyPixels(Buffer dst, Buffer src, int size) { 53 | throw new UnsupportedOperationException("not implemented"); 54 | } 55 | 56 | @Override 57 | protected void _fillDirectByteBuffer(ByteBuffer bb) { 58 | if (this.bytes != null) { 59 | this.bytes.rewind(); 60 | if (this.bytes.isDirect()) { 61 | _copyPixels(bb, this.bytes, getWidth() * getHeight()); 62 | } else { 63 | bb.put(this.bytes); 64 | } 65 | this.bytes.rewind(); 66 | } else { 67 | this.ints.rewind(); 68 | if (this.ints.isDirect()) { 69 | _copyPixels(bb, this.ints, getWidth() * getHeight()); 70 | } else { 71 | for (int i = 0; i < this.ints.capacity(); i++) { 72 | int data = this.ints.get(); 73 | bb.put((byte) ((data) & 0xff)); 74 | bb.put((byte) ((data >> 8) & 0xff)); 75 | bb.put((byte) ((data >> 16) & 0xff)); 76 | bb.put((byte) ((data >> 24) & 0xff)); 77 | } 78 | } 79 | this.ints.rewind(); 80 | } 81 | bb.rewind(); 82 | } 83 | 84 | @Override 85 | protected void _attachInt(long nativeWindowPointer, int w, int h, 86 | IntBuffer ints, int[] array, int offset) { 87 | throw new UnsupportedOperationException("not implemented"); 88 | } 89 | 90 | @Override 91 | protected void _attachByte(long ptr, int w, int h, ByteBuffer bytes, 92 | byte[] array, int offset) { 93 | 94 | throw new UnsupportedOperationException("not implemented"); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/Mouse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | class Mouse implements org.openqa.selenium.interactions.Mouse { 21 | private final MouseRemote remote; 22 | private final SocketLock lock; 23 | 24 | Mouse(MouseRemote remote, SocketLock lock) { 25 | this.remote = remote; 26 | this.lock = lock; 27 | } 28 | 29 | /** 30 | * {@inheritDoc} 31 | */ 32 | @Override 33 | public void click(org.openqa.selenium.interactions.Coordinates coords) { 34 | try { 35 | synchronized (lock.validated()) { 36 | remote.remoteClick(coords == null ? null : new Coordinates(coords)); 37 | } 38 | } catch (Throwable t) { 39 | Util.handleException(t); 40 | } 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | public void contextClick(org.openqa.selenium.interactions.Coordinates coords) { 48 | try { 49 | synchronized (lock.validated()) { 50 | remote.remoteContextClick(coords == null ? null : new Coordinates(coords)); 51 | } 52 | } catch (Throwable t) { 53 | Util.handleException(t); 54 | } 55 | } 56 | 57 | /** 58 | * {@inheritDoc} 59 | */ 60 | @Override 61 | public void doubleClick(org.openqa.selenium.interactions.Coordinates coords) { 62 | try { 63 | synchronized (lock.validated()) { 64 | remote.remoteDoubleClick(coords == null ? null : new Coordinates(coords)); 65 | } 66 | } catch (Throwable t) { 67 | Util.handleException(t); 68 | } 69 | } 70 | 71 | /** 72 | * {@inheritDoc} 73 | */ 74 | @Override 75 | public void mouseDown(org.openqa.selenium.interactions.Coordinates coords) { 76 | try { 77 | synchronized (lock.validated()) { 78 | remote.remoteMouseDown(coords == null ? null : new Coordinates(coords)); 79 | } 80 | } catch (Throwable t) { 81 | Util.handleException(t); 82 | } 83 | } 84 | 85 | /** 86 | * {@inheritDoc} 87 | */ 88 | @Override 89 | public void mouseMove(org.openqa.selenium.interactions.Coordinates coords) { 90 | try { 91 | synchronized (lock.validated()) { 92 | remote.remoteMouseMove(coords == null ? null : new Coordinates(coords)); 93 | } 94 | } catch (Throwable t) { 95 | Util.handleException(t); 96 | } 97 | } 98 | 99 | /** 100 | * {@inheritDoc} 101 | */ 102 | @Override 103 | public void mouseMove(org.openqa.selenium.interactions.Coordinates coords, long xOffset, long yOffset) { 104 | try { 105 | synchronized (lock.validated()) { 106 | remote.remoteMouseMove(coords == null ? null : new Coordinates(coords), xOffset, yOffset); 107 | } 108 | } catch (Throwable t) { 109 | Util.handleException(t); 110 | } 111 | } 112 | 113 | /** 114 | * {@inheritDoc} 115 | */ 116 | @Override 117 | public void mouseUp(org.openqa.selenium.interactions.Coordinates coords) { 118 | try { 119 | synchronized (lock.validated()) { 120 | remote.remoteMouseUp(coords == null ? null : new Coordinates(coords)); 121 | } 122 | } catch (Throwable t) { 123 | Util.handleException(t); 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/NativeScreen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, 2015, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import java.nio.Buffer; 29 | import java.nio.ByteBuffer; 30 | 31 | /** NativeScreen provides access to a device's screen */ 32 | public interface NativeScreen { 33 | 34 | /** 35 | * Returns the bit depth of the screen/ 36 | */ 37 | int getDepth(); 38 | 39 | /** 40 | * Returns the native format of the screen, as a constant from the Pixels 41 | * class. 42 | */ 43 | int getNativeFormat(); 44 | 45 | /** 46 | * Returns the pixel width of the screen. 47 | */ 48 | int getWidth(); 49 | 50 | /** 51 | * Returns the pixel height of the screen. 52 | */ 53 | int getHeight(); 54 | 55 | /** 56 | * Returns the number of pixels per inch in the screen. 57 | */ 58 | int getDPI(); 59 | 60 | /** 61 | * Returns a native handle for the screen. The handle is platform-specific. 62 | */ 63 | long getNativeHandle(); 64 | 65 | /** 66 | * Called during JavaFX shutdown to release the screen. Called only once. 67 | */ 68 | void shutdown(); 69 | 70 | /** Uploads a pixel buffer to the screen. Called on the JavaFX application thread. 71 | * 72 | * @param b Pixel data, in BYTE_BGRA_PRE format. The byte stride of the 73 | * data is equal to width * 4. 74 | * @param x The X offset of the pixel data on the screen 75 | * @param y The Y offset of the pixel data on the screen 76 | * @param width The pixel width of the data 77 | * @param height The pixel height of the data 78 | * @param alpha The alpha level to use to compose the data over existing 79 | * pixels 80 | */ 81 | void uploadPixels(Buffer b, 82 | int x, int y, int width, int height, float alpha); 83 | 84 | /** 85 | * Called on the JavaFX application thread when pixel data for all windows 86 | * has been uploaded. 87 | */ 88 | public void swapBuffers(); 89 | 90 | /** 91 | * Returns a read-only ByteBuffer in the native pixel format containing the screen contents. 92 | * @return ByteBuffer a read-only ByteBuffer containing the screen contents 93 | */ 94 | public ByteBuffer getScreenCapture(); 95 | 96 | /** 97 | * An Object to lock against when swapping screen buffers. 98 | */ 99 | public static final Object framebufferSwapLock = new Object(); 100 | 101 | /** 102 | * Return the scale factor between the physical pixels and the logical pixels 103 | * e.g. hdpi = 1.5, xhdpi = 2.0 104 | */ 105 | public float getScale(); 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/ElementRemote.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.Remote; 21 | import java.rmi.RemoteException; 22 | import java.util.List; 23 | 24 | import org.openqa.selenium.By; 25 | import org.openqa.selenium.WebDriverException; 26 | 27 | interface ElementRemote extends Remote { 28 | void activate() throws RemoteException; 29 | 30 | void scriptParam(ElementId id) throws RemoteException; 31 | 32 | void click() throws RemoteException; 33 | 34 | void submit() throws RemoteException; 35 | 36 | void sendKeys(final CharSequence... keys) throws RemoteException; 37 | 38 | void clear() throws RemoteException; 39 | 40 | String getAttribute(final String attrName) throws RemoteException; 41 | 42 | String getCssValue(final String name) throws RemoteException; 43 | 44 | Point remoteGetLocation() throws RemoteException; 45 | 46 | Dimension remoteGetSize() throws RemoteException; 47 | 48 | Rectangle remoteGetRect() throws RemoteException; 49 | 50 | String getTagName() throws RemoteException; 51 | 52 | String getText() throws RemoteException; 53 | 54 | boolean isDisplayed() throws RemoteException; 55 | 56 | boolean isEnabled() throws RemoteException; 57 | 58 | boolean isSelected() throws RemoteException; 59 | 60 | ElementRemote findElement(By by) throws RemoteException; 61 | 62 | List findElements(By by) throws RemoteException; 63 | 64 | ElementRemote findElementByXPath(final String expr) throws RemoteException; 65 | 66 | List findElementsByXPath(final String expr) throws RemoteException; 67 | 68 | ElementRemote findElementByTagName(String tagName) throws RemoteException; 69 | 70 | List findElementsByTagName(String tagName) throws RemoteException; 71 | 72 | ElementRemote findElementByCssSelector(final String expr) throws RemoteException; 73 | 74 | List findElementsByCssSelector(final String expr) throws RemoteException; 75 | 76 | ElementRemote findElementByName(String name) throws RemoteException; 77 | 78 | List findElementsByName(String name) throws RemoteException; 79 | 80 | ElementRemote findElementByLinkText(final String text) throws RemoteException; 81 | 82 | ElementRemote findElementByPartialLinkText(String text) throws RemoteException; 83 | 84 | List findElementsByLinkText(String text) throws RemoteException; 85 | 86 | List findElementsByPartialLinkText(String text) throws RemoteException; 87 | 88 | ElementRemote findElementByClassName(String cssClass) throws RemoteException; 89 | 90 | List findElementsByClassName(String cssClass) throws RemoteException; 91 | 92 | ElementRemote findElementById(final String id) throws RemoteException; 93 | 94 | List findElementsById(String id) throws RemoteException; 95 | 96 | Object executeAsyncScript(final String script, final Object... args) throws RemoteException; 97 | 98 | Object executeScript(final String script, final Object... args) throws RemoteException; 99 | 100 | Point locate() throws RemoteException; 101 | 102 | byte[] getScreenshot() throws WebDriverException, RemoteException; 103 | 104 | int remoteHashCode() throws RemoteException; 105 | 106 | boolean remoteEquals(ElementId id) throws RemoteException; 107 | } 108 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/TargetLocatorServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.RemoteException; 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | import org.openqa.selenium.WebDriver; 25 | import org.openqa.selenium.WebElement; 26 | import org.openqa.selenium.WindowType; 27 | 28 | class TargetLocatorServer extends RemoteObject implements TargetLocatorRemote, WebDriver.TargetLocator { 29 | 30 | private final JBrowserDriverServer driver; 31 | private final Context context; 32 | 33 | TargetLocatorServer(JBrowserDriverServer driver, Context context) throws RemoteException { 34 | this.driver = driver; 35 | this.context = context; 36 | } 37 | 38 | /** 39 | * {@inheritDoc} 40 | */ 41 | @Override 42 | public ElementServer activeElement() { 43 | ElementServer element = (ElementServer) driver.executeScript("return document.activeElement;"); 44 | context.item().selectFrame(element); 45 | return element; 46 | } 47 | 48 | /** 49 | * {@inheritDoc} 50 | */ 51 | @Override 52 | public AlertServer alert() { 53 | return context.alert.get(); 54 | } 55 | 56 | /** 57 | * {@inheritDoc} 58 | */ 59 | @Override 60 | public JBrowserDriverServer defaultContent() { 61 | context.item().deselectFrame(); 62 | return driver; 63 | } 64 | 65 | /** 66 | * {@inheritDoc} 67 | */ 68 | @Override 69 | public JBrowserDriverServer frame(int index) { 70 | context.item().selectFrame( 71 | (ElementServer) driver.executeScript( 72 | "return window.frames[arguments[0]].document;", new Object[] { index })); 73 | return driver; 74 | } 75 | 76 | /** 77 | * {@inheritDoc} 78 | */ 79 | @Override 80 | public JBrowserDriverServer frame(String nameOrId) { 81 | List byName = driver.findElementsByName(nameOrId); 82 | List byId = driver.findElementsById(nameOrId); 83 | List elements = new ArrayList(); 84 | elements.addAll(byName); 85 | elements.addAll(byId); 86 | for (ElementServer element : elements) { 87 | if (element.getTagName().equals("frame") 88 | || element.getTagName().equals("iframe")) { 89 | element.activate(); 90 | return driver; 91 | } 92 | } 93 | return driver; 94 | } 95 | 96 | /** 97 | * {@inheritDoc} 98 | */ 99 | @Override 100 | public JBrowserDriverServer frame(WebElement element) { 101 | throw new IllegalStateException(); 102 | } 103 | 104 | /** 105 | * {@inheritDoc} 106 | */ 107 | @Override 108 | public JBrowserDriverServer frame(ElementRemote element) { 109 | throw new IllegalStateException(); 110 | } 111 | 112 | /** 113 | * {@inheritDoc} 114 | */ 115 | @Override 116 | public JBrowserDriverServer parentFrame() { 117 | context.item().selectFrame( 118 | (ElementServer) driver.executeScript("return window.parent.document;")); 119 | return driver; 120 | } 121 | 122 | /** 123 | * {@inheritDoc} 124 | */ 125 | @Override 126 | public JBrowserDriverServer window(String windowHandle) { 127 | context.setCurrent(windowHandle); 128 | return driver; 129 | } 130 | 131 | //@Override -- commented out to be compatible with Selenium 3 which does not have this API 132 | public JBrowserDriverServer newWindow(WindowType windowType) { 133 | context.spawn(driver); 134 | return driver; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/WireLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.IOException; 21 | import java.io.Serializable; 22 | import java.util.concurrent.atomic.AtomicReference; 23 | import java.util.regex.Matcher; 24 | import java.util.regex.Pattern; 25 | 26 | import org.apache.commons.logging.Log; 27 | 28 | /** 29 | * Internal use only. 30 | * 31 | * @deprecated 32 | */ 33 | public class WireLog implements Log, Serializable { 34 | private static final Pattern request = Pattern.compile("^http-outgoing-[0-9]+\\s>>\\s\"(.+)\"$"); 35 | private static final Pattern response = Pattern.compile( 36 | "^http-outgoing-[0-9]+\\s<<\\s\"((?:HTTP/.+)|(?:[^:]+:\\s.+))\"$"); 37 | private static final int MAX_LEN = 500; 38 | private static final AtomicReference appender = new AtomicReference(); 39 | 40 | public static void setAppender(Appendable appender) { 41 | WireLog.appender.set(appender); 42 | } 43 | 44 | public WireLog(String s) {} 45 | 46 | @Override 47 | public void debug(Object objMessage) { 48 | if (objMessage != null) { 49 | String message = objMessage.toString(); 50 | if (message != null && message.length() < MAX_LEN) { 51 | Matcher matcher = request.matcher(message); 52 | if (matcher.matches()) { 53 | message = matcher.group(1).replace("[\\r]", "").replace("[\\n]", ""); 54 | if (!message.isEmpty()) { 55 | try { 56 | appender.get().append("----->> ").append(message); 57 | } catch (IOException e) { 58 | e.printStackTrace(); 59 | } 60 | } 61 | } else { 62 | matcher = response.matcher(message); 63 | if (matcher.matches()) { 64 | message = matcher.group(1).replace("[\\r]", "").replace("[\\n]", ""); 65 | if (!message.isEmpty()) { 66 | try { 67 | appender.get().append("<<----- ").append(message); 68 | } catch (IOException e) { 69 | e.printStackTrace(); 70 | } 71 | } 72 | } 73 | } 74 | } 75 | } 76 | } 77 | 78 | @Override 79 | public void debug(Object message, Throwable t) {} 80 | 81 | @Override 82 | public void error(Object message) {} 83 | 84 | @Override 85 | public void error(Object message, Throwable t) {} 86 | 87 | @Override 88 | public void fatal(Object message) {} 89 | 90 | @Override 91 | public void fatal(Object message, Throwable t) {} 92 | 93 | @Override 94 | public void info(Object message) {} 95 | 96 | @Override 97 | public void info(Object message, Throwable t) {} 98 | 99 | @Override 100 | public void trace(Object message) {} 101 | 102 | @Override 103 | public void trace(Object message, Throwable t) {} 104 | 105 | @Override 106 | public void warn(Object message) {} 107 | 108 | @Override 109 | public void warn(Object message, Throwable t) {} 110 | 111 | @Override 112 | public boolean isDebugEnabled() { 113 | return true; 114 | } 115 | 116 | @Override 117 | public boolean isErrorEnabled() { 118 | return false; 119 | } 120 | 121 | @Override 122 | public boolean isFatalEnabled() { 123 | return false; 124 | } 125 | 126 | @Override 127 | public boolean isInfoEnabled() { 128 | return false; 129 | } 130 | 131 | @Override 132 | public boolean isTraceEnabled() { 133 | return false; 134 | } 135 | 136 | @Override 137 | public boolean isWarnEnabled() { 138 | return false; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/Timeouts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.util.concurrent.TimeUnit; 21 | 22 | class Timeouts implements org.openqa.selenium.WebDriver.Timeouts { 23 | private final TimeoutsRemote remote; 24 | private final SocketLock lock; 25 | 26 | Timeouts(TimeoutsRemote remote, SocketLock lock) { 27 | this.remote = remote; 28 | this.lock = lock; 29 | } 30 | 31 | /** 32 | * {@inheritDoc} 33 | */ 34 | @Override 35 | public Timeouts implicitlyWait(long duration, TimeUnit unit) { 36 | try { 37 | synchronized (lock.validated()) { 38 | TimeoutsRemote timeouts = remote.implicitlyWait(duration, unit); 39 | if (timeouts == null) { 40 | return null; 41 | } 42 | return new Timeouts(timeouts, lock); 43 | } 44 | } catch (Throwable t) { 45 | Util.handleException(t); 46 | return null; 47 | } 48 | } 49 | 50 | /** 51 | * {@inheritDoc} 52 | */ 53 | @Override 54 | public Timeouts pageLoadTimeout(long duration, TimeUnit unit) { 55 | try { 56 | synchronized (lock.validated()) { 57 | TimeoutsRemote timeouts = remote.pageLoadTimeout(duration, unit); 58 | if (timeouts == null) { 59 | return null; 60 | } 61 | return new Timeouts(timeouts, lock); 62 | } 63 | } catch (Throwable t) { 64 | Util.handleException(t); 65 | return null; 66 | } 67 | } 68 | 69 | /** 70 | * {@inheritDoc} 71 | */ 72 | @Override 73 | public Timeouts setScriptTimeout(long duration, TimeUnit unit) { 74 | try { 75 | synchronized (lock.validated()) { 76 | TimeoutsRemote timeouts = remote.setScriptTimeout(duration, unit); 77 | if (timeouts == null) { 78 | return null; 79 | } 80 | return new Timeouts(timeouts, lock); 81 | } 82 | } catch (Throwable t) { 83 | Util.handleException(t); 84 | return null; 85 | } 86 | } 87 | 88 | public Timeouts setAlertTimeout(long duration, TimeUnit unit) { 89 | try { 90 | synchronized (lock.validated()) { 91 | TimeoutsRemote timeouts = remote.setAlertTimeout(duration, unit); 92 | if (timeouts == null) { 93 | return null; 94 | } 95 | return new Timeouts(timeouts, lock); 96 | } 97 | } catch (Throwable t) { 98 | Util.handleException(t); 99 | return null; 100 | } 101 | } 102 | 103 | long getImplicitlyWaitMS() { 104 | try { 105 | synchronized (lock.validated()) { 106 | return remote.getImplicitlyWaitMS(); 107 | } 108 | } catch (Throwable t) { 109 | Util.handleException(t); 110 | return -1; 111 | } 112 | } 113 | 114 | long getPageLoadTimeoutMS() { 115 | try { 116 | synchronized (lock.validated()) { 117 | return remote.getPageLoadTimeoutMS(); 118 | } 119 | } catch (Throwable t) { 120 | Util.handleException(t); 121 | return -1; 122 | } 123 | } 124 | 125 | long getScriptTimeoutMS() { 126 | try { 127 | synchronized (lock.validated()) { 128 | return remote.getScriptTimeoutMS(); 129 | } 130 | } catch (Throwable t) { 131 | Util.handleException(t); 132 | return -1; 133 | } 134 | } 135 | 136 | long getAlertTimeoutMS() { 137 | try { 138 | synchronized (lock.validated()) { 139 | return remote.getAlertTimeoutMS(); 140 | } 141 | } catch (Throwable t) { 142 | Util.handleException(t); 143 | return -1; 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/JBrowserDriverRemote.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.File; 21 | import java.rmi.Remote; 22 | import java.rmi.RemoteException; 23 | import java.util.List; 24 | import java.util.Set; 25 | 26 | import org.openqa.selenium.By; 27 | import org.openqa.selenium.Capabilities; 28 | import org.openqa.selenium.WebDriverException; 29 | 30 | interface JBrowserDriverRemote extends Remote { 31 | void setUp(final Settings settings) throws RemoteException; 32 | 33 | void storeCapabilities(Capabilities capabilities) throws RemoteException; 34 | 35 | void init() throws RemoteException; 36 | 37 | void reset(Settings settings) throws RemoteException; 38 | 39 | void reset() throws RemoteException; 40 | 41 | int getStatusCode() throws RemoteException; 42 | 43 | void pageWait() throws RemoteException; 44 | 45 | void kill() throws RemoteException; 46 | 47 | byte[] getScreenshot() throws WebDriverException, RemoteException; 48 | 49 | Capabilities getCapabilities() throws RemoteException; 50 | 51 | KeyboardRemote getKeyboard() throws RemoteException; 52 | 53 | MouseRemote getMouse() throws RemoteException; 54 | 55 | ElementRemote findElementByXPath(String using) throws RemoteException; 56 | 57 | List findElementsByXPath(String using) throws RemoteException; 58 | 59 | ElementRemote findElementByTagName(String using) throws RemoteException; 60 | 61 | List findElementsByTagName(String using) throws RemoteException; 62 | 63 | ElementRemote findElementByCssSelector(String using) throws RemoteException; 64 | 65 | List findElementsByCssSelector(String using) throws RemoteException; 66 | 67 | ElementRemote findElementByName(String using) throws RemoteException; 68 | 69 | List findElementsByName(String using) throws RemoteException; 70 | 71 | ElementRemote findElementByLinkText(String using) throws RemoteException; 72 | 73 | List findElementsByLinkText(String using) throws RemoteException; 74 | 75 | ElementRemote findElementByPartialLinkText(String using) throws RemoteException; 76 | 77 | List findElementsByPartialLinkText(String using) throws RemoteException; 78 | 79 | ElementRemote findElementByClassName(String using) throws RemoteException; 80 | 81 | List findElementsByClassName(String using) throws RemoteException; 82 | 83 | ElementRemote findElementById(String using) throws RemoteException; 84 | 85 | List findElementsById(String using) throws RemoteException; 86 | 87 | Object executeScript(String script, Object... args) throws RemoteException; 88 | 89 | Object executeAsyncScript(String script, Object... args) throws RemoteException; 90 | 91 | void get(String url) throws RemoteException; 92 | 93 | String getCurrentUrl() throws RemoteException; 94 | 95 | String getTitle() throws RemoteException; 96 | 97 | List findElements(By by) throws RemoteException; 98 | 99 | ElementRemote findElement(By by) throws RemoteException; 100 | 101 | String getPageSource() throws RemoteException; 102 | 103 | void close() throws RemoteException; 104 | 105 | void quit() throws RemoteException; 106 | 107 | Set getWindowHandles() throws RemoteException; 108 | 109 | String getWindowHandle() throws RemoteException; 110 | 111 | TargetLocatorRemote switchTo() throws RemoteException; 112 | 113 | NavigationRemote navigate() throws RemoteException; 114 | 115 | OptionsRemote manage() throws RemoteException; 116 | 117 | LogsRemote logs() throws RemoteException; 118 | 119 | File cacheDir() throws RemoteException; 120 | 121 | File attachmentsDir() throws RemoteException; 122 | 123 | File mediaDir() throws RemoteException; 124 | } 125 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/TargetLocator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import org.openqa.selenium.WebDriver; 21 | import org.openqa.selenium.WebElement; 22 | import org.openqa.selenium.WindowType; 23 | 24 | class TargetLocator implements WebDriver.TargetLocator { 25 | private final TargetLocatorRemote remote; 26 | private final JBrowserDriver driver; 27 | private final SocketLock lock; 28 | 29 | TargetLocator(TargetLocatorRemote remote, JBrowserDriver driver, SocketLock lock) { 30 | this.remote = remote; 31 | this.driver = driver; 32 | this.lock = lock; 33 | } 34 | 35 | /** 36 | * {@inheritDoc} 37 | */ 38 | @Override 39 | public WebElement activeElement() { 40 | try { 41 | synchronized (lock.validated()) { 42 | return Element.constructElement(remote.activeElement(), driver, lock); 43 | } 44 | } catch (Throwable t) { 45 | Util.handleException(t); 46 | return null; 47 | } 48 | } 49 | 50 | /** 51 | * {@inheritDoc} 52 | */ 53 | @Override 54 | public org.openqa.selenium.Alert alert() { 55 | try { 56 | synchronized (lock.validated()) { 57 | return new Alert(remote.alert(), lock); 58 | } 59 | } catch (Throwable t) { 60 | Util.handleException(t); 61 | return null; 62 | } 63 | } 64 | 65 | /** 66 | * {@inheritDoc} 67 | */ 68 | @Override 69 | public WebDriver defaultContent() { 70 | try { 71 | synchronized (lock.validated()) { 72 | remote.defaultContent(); 73 | } 74 | return driver; 75 | } catch (Throwable t) { 76 | Util.handleException(t); 77 | return null; 78 | } 79 | } 80 | 81 | /** 82 | * {@inheritDoc} 83 | */ 84 | @Override 85 | public WebDriver frame(int index) { 86 | try { 87 | synchronized (lock.validated()) { 88 | remote.frame(index); 89 | } 90 | return driver; 91 | } catch (Throwable t) { 92 | Util.handleException(t); 93 | return null; 94 | } 95 | } 96 | 97 | /** 98 | * {@inheritDoc} 99 | */ 100 | @Override 101 | public WebDriver frame(String nameOrId) { 102 | try { 103 | synchronized (lock.validated()) { 104 | remote.frame(nameOrId); 105 | } 106 | return driver; 107 | } catch (Throwable t) { 108 | Util.handleException(t); 109 | return null; 110 | } 111 | } 112 | 113 | /** 114 | * {@inheritDoc} 115 | */ 116 | @Override 117 | public WebDriver frame(WebElement element) { 118 | ((Element) Util.unwrap(element)).activate(); 119 | return driver; 120 | } 121 | 122 | /** 123 | * {@inheritDoc} 124 | */ 125 | @Override 126 | public WebDriver parentFrame() { 127 | try { 128 | synchronized (lock.validated()) { 129 | remote.parentFrame(); 130 | } 131 | return driver; 132 | } catch (Throwable t) { 133 | Util.handleException(t); 134 | return null; 135 | } 136 | } 137 | 138 | /** 139 | * {@inheritDoc} 140 | */ 141 | @Override 142 | public WebDriver window(String windowHandle) { 143 | try { 144 | synchronized (lock.validated()) { 145 | remote.window(windowHandle); 146 | } 147 | return driver; 148 | } catch (Throwable t) { 149 | Util.handleException(t); 150 | return null; 151 | } 152 | } 153 | 154 | //@Override -- commented out to be compatible with Selenium 3 which does not have this API 155 | public WebDriver newWindow(WindowType windowType) { 156 | try { 157 | synchronized (lock.validated()) { 158 | remote.newWindow(windowType); 159 | } 160 | return driver; 161 | } catch (Throwable t) { 162 | Util.handleException(t); 163 | return null; 164 | } 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/HeadlessScreen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, 2015, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import com.sun.glass.ui.Pixels; 29 | import com.machinepublishers.glass.ui.monocle.Framebuffer; 30 | import com.machinepublishers.glass.ui.monocle.NativeScreen; 31 | 32 | import java.nio.Buffer; 33 | import java.nio.ByteBuffer; 34 | import java.nio.ByteOrder; 35 | import java.security.AccessController; 36 | import java.security.PrivilegedAction; 37 | 38 | class HeadlessScreen implements NativeScreen { 39 | 40 | protected int depth; 41 | protected int width; 42 | protected int height; 43 | protected Framebuffer fb; 44 | 45 | HeadlessScreen() { 46 | this(1280, 800, 32); 47 | } 48 | 49 | protected HeadlessScreen(int defaultWidth, 50 | int defaultHeight, 51 | int defaultDepth) { 52 | this.width = defaultWidth; 53 | this.height = defaultHeight; 54 | this.depth = defaultDepth; 55 | String geometry = AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty("headless.geometry")); 56 | if (geometry != null && geometry.indexOf('x') > 0) { 57 | try { 58 | int i = geometry.indexOf("x"); 59 | width = Integer.parseInt(geometry.substring(0, i)); 60 | int j = geometry.indexOf("-", i + 1); 61 | if (j > 0) { 62 | depth = Integer.parseInt(geometry.substring(j + 1)); 63 | } else { 64 | j = geometry.length(); 65 | } 66 | height = Integer.parseInt(geometry.substring(i + 1, j)); 67 | } catch (NumberFormatException e) { 68 | System.err.println("Cannot parse geometry string: '" 69 | + geometry + "'"); 70 | } 71 | } 72 | ByteBuffer bb = ByteBuffer.allocate(width * height * (depth >>> 3)); 73 | bb.order(ByteOrder.nativeOrder()); 74 | fb = new Framebuffer(bb, width, height, depth, true); 75 | } 76 | 77 | @Override 78 | public int getDepth() { 79 | return depth; 80 | } 81 | 82 | @Override 83 | public int getNativeFormat() { 84 | return Pixels.Format.BYTE_BGRA_PRE; 85 | } 86 | 87 | @Override 88 | public int getWidth() { 89 | return width; 90 | } 91 | 92 | @Override 93 | public int getHeight() { 94 | return height; 95 | } 96 | 97 | @Override 98 | public float getScale() { 99 | return 1.0f; 100 | } 101 | 102 | @Override 103 | public long getNativeHandle() { 104 | return 1l; 105 | } 106 | 107 | @Override 108 | public int getDPI() { 109 | return 96; 110 | } 111 | 112 | @Override 113 | public void shutdown() { 114 | } 115 | 116 | @Override 117 | public void uploadPixels(Buffer b, 118 | int x, int y, int width, int height, 119 | float alpha) { 120 | fb.composePixels(b, x, y, width, height, alpha); 121 | } 122 | 123 | @Override 124 | public void swapBuffers() { 125 | fb.reset(); 126 | } 127 | 128 | @Override 129 | public ByteBuffer getScreenCapture() { 130 | return fb.getBuffer(); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/MouseServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.rmi.RemoteException; 21 | import java.util.concurrent.atomic.AtomicReference; 22 | 23 | import com.machinepublishers.jbrowserdriver.Robot.MouseButton; 24 | 25 | class MouseServer extends RemoteObject implements MouseRemote, 26 | org.openqa.selenium.interactions.Mouse { 27 | private final AtomicReference robot; 28 | 29 | MouseServer(final AtomicReference robot) throws RemoteException { 30 | this.robot = robot; 31 | } 32 | 33 | /** 34 | * {@inheritDoc} 35 | */ 36 | @Override 37 | public void click(org.openqa.selenium.interactions.Coordinates coords) { 38 | if (coords != null) { 39 | robot.get().mouseMove(coords.inViewPort()); 40 | } 41 | robot.get().mouseClick(MouseButton.LEFT); 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | @Override 48 | public void remoteClick(Coordinates coords) { 49 | click(coords); 50 | } 51 | 52 | /** 53 | * {@inheritDoc} 54 | */ 55 | @Override 56 | public void contextClick(org.openqa.selenium.interactions.Coordinates coords) { 57 | if (coords != null) { 58 | robot.get().mouseMove(coords.inViewPort()); 59 | } 60 | robot.get().mouseClick(MouseButton.RIGHT); 61 | } 62 | 63 | /** 64 | * {@inheritDoc} 65 | */ 66 | @Override 67 | public void remoteContextClick(Coordinates coords) { 68 | contextClick(coords); 69 | } 70 | 71 | /** 72 | * {@inheritDoc} 73 | */ 74 | @Override 75 | public void doubleClick(org.openqa.selenium.interactions.Coordinates coords) { 76 | if (coords != null) { 77 | robot.get().mouseMove(coords.inViewPort()); 78 | } 79 | robot.get().mouseClick(MouseButton.LEFT); 80 | robot.get().mouseClick(MouseButton.LEFT); 81 | } 82 | 83 | /** 84 | * {@inheritDoc} 85 | */ 86 | @Override 87 | public void remoteDoubleClick(Coordinates coords) { 88 | doubleClick(coords); 89 | } 90 | 91 | /** 92 | * {@inheritDoc} 93 | */ 94 | @Override 95 | public void mouseDown(org.openqa.selenium.interactions.Coordinates coords) { 96 | if (coords != null) { 97 | robot.get().mouseMove(coords.inViewPort()); 98 | } 99 | robot.get().mousePress(MouseButton.LEFT); 100 | } 101 | 102 | /** 103 | * {@inheritDoc} 104 | */ 105 | @Override 106 | public void remoteMouseDown(Coordinates coords) { 107 | mouseDown(coords); 108 | } 109 | 110 | /** 111 | * {@inheritDoc} 112 | */ 113 | @Override 114 | public void mouseMove(org.openqa.selenium.interactions.Coordinates coords) { 115 | robot.get().mouseMove(coords.inViewPort()); 116 | } 117 | 118 | /** 119 | * {@inheritDoc} 120 | */ 121 | @Override 122 | public void remoteMouseMove(Coordinates coords) { 123 | mouseMove(coords); 124 | } 125 | 126 | /** 127 | * {@inheritDoc} 128 | */ 129 | @Override 130 | public void mouseMove(org.openqa.selenium.interactions.Coordinates coords, long xOffset, long yOffset) { 131 | if (coords != null) { 132 | robot.get().mouseMove(coords.inViewPort()); 133 | } else { 134 | robot.get().mouseMoveBy(xOffset, yOffset); 135 | } 136 | } 137 | 138 | /** 139 | * {@inheritDoc} 140 | */ 141 | @Override 142 | public void remoteMouseMove(Coordinates coords, long xOffset, long yOffset) { 143 | mouseMove(coords, xOffset, yOffset); 144 | } 145 | 146 | /** 147 | * {@inheritDoc} 148 | */ 149 | @Override 150 | public void mouseUp(org.openqa.selenium.interactions.Coordinates coords) { 151 | if (coords != null) { 152 | robot.get().mouseMove(coords.inViewPort()); 153 | } 154 | robot.get().mouseRelease(MouseButton.LEFT); 155 | } 156 | 157 | /** 158 | * {@inheritDoc} 159 | */ 160 | @Override 161 | public void remoteMouseUp(Coordinates coords) { 162 | mouseUp(coords); 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/AjaxListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.util.HashSet; 21 | import java.util.Map; 22 | import java.util.Set; 23 | import java.util.concurrent.atomic.AtomicBoolean; 24 | import java.util.concurrent.atomic.AtomicInteger; 25 | import java.util.concurrent.atomic.AtomicLong; 26 | 27 | import javafx.application.Platform; 28 | 29 | class AjaxListener implements Runnable { 30 | private static final long MAX_WAIT_DEFAULT = 15000; 31 | private static final int IDLE_COUNT_TARGET = 3; 32 | private final AtomicBoolean started; 33 | private final AtomicInteger newStatusCode; 34 | private final StatusCode statusCode; 35 | private final Map resources; 36 | private final AtomicLong timeoutMS; 37 | 38 | AjaxListener(final AtomicBoolean started, final AtomicInteger newStatusCode, 39 | final StatusCode statusCode, 40 | final Map resources, final AtomicLong timeoutMS) { 41 | this.started = started; 42 | this.newStatusCode = newStatusCode; 43 | this.statusCode = statusCode; 44 | this.resources = resources; 45 | this.timeoutMS = timeoutMS; 46 | } 47 | 48 | /** 49 | * {@inheritDoc} 50 | */ 51 | @Override 52 | public void run() { 53 | while (true) { 54 | synchronized (statusCode) { 55 | while (statusCode.get() != 0) { 56 | try { 57 | statusCode.wait(); 58 | } catch (InterruptedException e) {} 59 | } 60 | } 61 | int size = 0; 62 | final long start = System.currentTimeMillis(); 63 | long time = start; 64 | final Settings settings = SettingsManager.settings(); 65 | final AtomicBoolean done = new AtomicBoolean(); 66 | Platform.runLater(() -> { 67 | synchronized (done) { 68 | done.set(true); 69 | done.notifyAll(); 70 | } 71 | }); 72 | synchronized (done) { 73 | while (!done.get()) { 74 | try { 75 | done.wait(); 76 | } catch (InterruptedException e) {} 77 | } 78 | } 79 | if (settings != null) { 80 | final long sleepMS = Math.max(settings.ajaxWait() / IDLE_COUNT_TARGET, 0); 81 | int idleCount = 0; 82 | int idleCountTarget = sleepMS == 0 ? 1 : IDLE_COUNT_TARGET; 83 | while (time - start < (timeoutMS.get() <= 0 ? MAX_WAIT_DEFAULT : timeoutMS.get())) { 84 | try { 85 | Thread.sleep(sleepMS); 86 | } catch (InterruptedException e) { 87 | return; 88 | } 89 | time = System.currentTimeMillis(); 90 | synchronized (statusCode) { 91 | if (Thread.interrupted()) { 92 | return; 93 | } 94 | final Set remove = new HashSet(); 95 | for (Map.Entry entry : resources.entrySet()) { 96 | if (time - entry.getValue() > settings.ajaxResourceTimeout()) { 97 | remove.add(entry.getKey()); 98 | } 99 | } 100 | for (String key : remove) { 101 | resources.remove(key); 102 | } 103 | size = resources.size(); 104 | } 105 | if (size == 0) { 106 | ++idleCount; 107 | } else { 108 | idleCount = 0; 109 | } 110 | if (idleCount == idleCountTarget) { 111 | break; 112 | } 113 | } 114 | } 115 | synchronized (statusCode) { 116 | if (Thread.interrupted()) { 117 | return; 118 | } 119 | int newStatusCodeVal = newStatusCode.getAndSet(0); 120 | newStatusCodeVal = newStatusCodeVal <= 0 ? (started.get() ? 0 : 200) : newStatusCodeVal; 121 | resources.clear(); 122 | StatusMonitor.instance().clear(); 123 | statusCode.set(newStatusCodeVal); 124 | statusCode.notifyAll(); 125 | } 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/ProxyConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.Serializable; 21 | import java.util.Collections; 22 | import java.util.Set; 23 | 24 | /** 25 | * Proxy server settings. 26 | */ 27 | public class ProxyConfig implements Serializable { 28 | private final Type type; 29 | private final String host; 30 | private final int port; 31 | private final String hostAndPort; 32 | private final String user; 33 | private final String password; 34 | private final boolean expectContinue; 35 | private final Set nonProxyHosts; 36 | 37 | /** 38 | * The proxy type. 39 | */ 40 | public static enum Type { 41 | /** 42 | * SOCKS proxy. 43 | */ 44 | SOCKS, 45 | /** 46 | * HTTP/HTTPS proxy. 47 | */ 48 | HTTP 49 | } 50 | 51 | /** 52 | * Creates a direct connection (no proxy). 53 | */ 54 | public ProxyConfig() { 55 | type = null; 56 | host = null; 57 | port = -1; 58 | hostAndPort = null; 59 | user = null; 60 | password = null; 61 | expectContinue = false; 62 | nonProxyHosts = Collections.emptySet(); 63 | } 64 | 65 | /** 66 | * Creates a proxy. 67 | * 68 | * @param type 69 | * @param host 70 | * @param port 71 | */ 72 | public ProxyConfig(Type type, String host, int port) { 73 | this(type, host, port, null, null, true, Collections.emptySet()); 74 | } 75 | 76 | /** 77 | * Creates a proxy. 78 | * 79 | * @param type 80 | * @param host 81 | * @param port 82 | * @param user 83 | * @param password 84 | */ 85 | public ProxyConfig(Type type, String host, int port, String user, String password) { 86 | this(type, host, port, user, password, true, Collections.emptySet()); 87 | } 88 | 89 | /** 90 | * Creates a proxy. 91 | * 92 | * @param type 93 | * @param host 94 | * @param port 95 | * @param user 96 | * @param password 97 | * @param expectContinue 98 | * Whether the proxy uses "Expect: 100-Continue" functionality 99 | */ 100 | public ProxyConfig(Type type, String host, int port, String user, String password, boolean expectContinue) { 101 | this(type, host, port, user, password, expectContinue, Collections.emptySet()); 102 | } 103 | 104 | /** 105 | * Creates a proxy. 106 | * 107 | * @param type 108 | * @param host 109 | * @param port 110 | * @param user 111 | * @param password 112 | * @param expectContinue 113 | * Whether the proxy uses "Expect: 100-Continue" functionality 114 | * @param nonProxyHosts 115 | * Set of hosts that should be reached directly, bypassing the proxy. 116 | */ 117 | public ProxyConfig(Type type, String host, int port, String user, String password, boolean expectContinue, Set nonProxyHosts) { 118 | this.type = type; 119 | this.host = host; 120 | this.port = port; 121 | this.hostAndPort = host + ":" + port; 122 | this.user = user; 123 | this.password = password; 124 | this.expectContinue = expectContinue; 125 | this.nonProxyHosts = nonProxyHosts; 126 | } 127 | 128 | boolean directConnection() { 129 | return type == null || host == null || host.isEmpty() || port == -1; 130 | } 131 | 132 | boolean credentials() { 133 | return user != null && !user.isEmpty() && password != null; 134 | } 135 | 136 | Type type() { 137 | return type; 138 | } 139 | 140 | String host() { 141 | return host; 142 | } 143 | 144 | int port() { 145 | return port; 146 | } 147 | 148 | String hostAndPort() { 149 | return hostAndPort; 150 | } 151 | 152 | String user() { 153 | return user == null ? "" : user; 154 | } 155 | 156 | String password() { 157 | return password == null ? "" : password; 158 | } 159 | 160 | boolean expectContinue() { 161 | return expectContinue; 162 | } 163 | 164 | Set nonProxyHosts() { 165 | return nonProxyHosts; 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/StatusMonitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.net.URL; 21 | import java.util.ArrayList; 22 | import java.util.HashMap; 23 | import java.util.HashSet; 24 | import java.util.List; 25 | import java.util.Map; 26 | import java.util.Set; 27 | 28 | class StatusMonitor { 29 | private static final StatusMonitor instance = new StatusMonitor(); 30 | private final Object lock = new Object(); 31 | private final Map connections = new HashMap(); 32 | private final Map primaryDocuments = new HashMap(); 33 | private final Set discarded = new HashSet(); 34 | private final Map redirects = new HashMap(); 35 | private final List startedUrls = new ArrayList(); 36 | 37 | static StatusMonitor instance() { 38 | return instance; 39 | } 40 | 41 | private static String canonicalUrl(String url) { 42 | if (url == null) { 43 | return null; 44 | } 45 | int fragmentIndex = url.indexOf("#"); 46 | url = fragmentIndex > -1 ? url.substring(0, fragmentIndex) : url; 47 | return url.endsWith("/") ? url : url + "/"; 48 | } 49 | 50 | boolean isPrimaryDocument(boolean requireMainFrame, String url) { 51 | synchronized (lock) { 52 | String canonicalUrl = canonicalUrl(url); 53 | return primaryDocuments.containsKey(canonicalUrl) 54 | && (!requireMainFrame || primaryDocuments.get(canonicalUrl)); 55 | } 56 | } 57 | 58 | boolean isDiscarded(String url) { 59 | synchronized (lock) { 60 | return discarded.contains(canonicalUrl(url)); 61 | } 62 | } 63 | 64 | void addRedirect(String original, String redirected) { 65 | String canonicalOriginal = canonicalUrl(original); 66 | String canonicalRedirected = canonicalUrl(redirected); 67 | if (canonicalOriginal != null 68 | && canonicalRedirected != null 69 | && !canonicalOriginal.equals(canonicalRedirected)) { 70 | synchronized (lock) { 71 | redirects.put(canonicalRedirected, original); 72 | } 73 | } 74 | } 75 | 76 | String originalFromRedirect(String redirected) { 77 | synchronized (lock) { 78 | return redirects.get(canonicalUrl(redirected)); 79 | } 80 | } 81 | 82 | void monitor(String url) { 83 | synchronized (lock) { 84 | startedUrls.add(canonicalUrl(url)); 85 | } 86 | } 87 | 88 | void addPrimaryDocument(boolean mainFrame, String url) { 89 | synchronized (lock) { 90 | primaryDocuments.put(canonicalUrl(url), mainFrame); 91 | } 92 | } 93 | 94 | void monitor(URL url, StreamConnection conn) { 95 | synchronized (lock) { 96 | connections.put(canonicalUrl(url.toExternalForm()), conn); 97 | } 98 | } 99 | 100 | void addDiscarded(String url) { 101 | synchronized (lock) { 102 | discarded.add(canonicalUrl(url)); 103 | } 104 | } 105 | 106 | int status(String url) { 107 | StreamConnection conn = null; 108 | synchronized (lock) { 109 | conn = connections.get(canonicalUrl(url)); 110 | for (int i = startedUrls.size() - 1; conn == null && i > -1; i--) { 111 | conn = connections.get(startedUrls.get(i)); 112 | } 113 | } 114 | int code = 499; 115 | if (conn != null) { 116 | try { 117 | code = conn.getResponseCode(); 118 | code = code <= 0 ? 499 : code; 119 | } catch (Throwable t) { 120 | LogsServer.instance().exception(t); 121 | } 122 | } 123 | return code; 124 | } 125 | 126 | void clear() { 127 | synchronized (lock) { 128 | for (StreamConnection conn : connections.values()) { 129 | Util.close(conn); 130 | } 131 | StreamConnection.cleanUp(); 132 | connections.clear(); 133 | primaryDocuments.clear(); 134 | discarded.clear(); 135 | redirects.clear(); 136 | startedUrls.clear(); 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/KeyState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import com.sun.glass.events.KeyEvent; 29 | import com.machinepublishers.glass.ui.monocle.IntSet; 30 | import com.machinepublishers.glass.ui.monocle.KeyState; 31 | import com.machinepublishers.glass.ui.monocle.MonocleWindow; 32 | import com.machinepublishers.glass.ui.monocle.MonocleWindowManager; 33 | 34 | /** 35 | * KeyState is a snapshot of pressed keys 36 | * KeyState is used both to store the current state of key input and to 37 | * describe changes to that state. 38 | */ 39 | class KeyState { 40 | 41 | private IntSet keysPressed = new IntSet(); 42 | private MonocleWindow window; 43 | private int modifiers; 44 | 45 | /** Removes all pressed keys from this state object. */ 46 | void clear() { 47 | keysPressed.clear(); 48 | modifiers = 0; 49 | } 50 | 51 | /** Adds a key to the set of pressed keys. */ 52 | void pressKey(int virtualKeyCode) { 53 | keysPressed.addInt(virtualKeyCode); 54 | modifiers |= getModifier(virtualKeyCode); 55 | } 56 | 57 | /** Removes a key from the set of pressed keys. */ 58 | void releaseKey(int virtualKeyCode) { 59 | keysPressed.removeInt(virtualKeyCode); 60 | modifiers &= ~getModifier(virtualKeyCode); 61 | } 62 | 63 | /** Copies the contents of this state object to another. 64 | * 65 | * @param target The KeyState to which to copy this state's data. 66 | */ 67 | void copyTo(KeyState target) { 68 | keysPressed.copyTo(target.keysPressed); 69 | target.window = window; 70 | target.modifiers = modifiers; 71 | } 72 | 73 | /** Returns the set of pressed key codes 74 | * 75 | * @return an IntSet containing the key codes of pressed keys 76 | */ 77 | IntSet getKeysPressed() { 78 | return keysPressed; 79 | } 80 | 81 | /** Returns the Glass window on which this event state is located . */ 82 | MonocleWindow getWindow(boolean recalculateCache) { 83 | if (window == null || recalculateCache) { 84 | window = (MonocleWindow) 85 | MonocleWindowManager.getInstance().getFocusedWindow(); 86 | } 87 | return window; 88 | } 89 | 90 | private static int getModifier(int virtualKeyCode) { 91 | switch (virtualKeyCode) { 92 | case KeyEvent.VK_SHIFT: return KeyEvent.MODIFIER_SHIFT; 93 | case KeyEvent.VK_CONTROL: return KeyEvent.MODIFIER_CONTROL; 94 | case KeyEvent.VK_ALT: return KeyEvent.MODIFIER_ALT; 95 | case KeyEvent.VK_COMMAND: return KeyEvent.MODIFIER_COMMAND; 96 | case KeyEvent.VK_WINDOWS: return KeyEvent.MODIFIER_WINDOWS; 97 | default: return KeyEvent.MODIFIER_NONE; 98 | } 99 | } 100 | 101 | /** Returns a mask of modifiers defined in KeyEvent for the keys pressed 102 | * in this state. 103 | * 104 | * @return a mask of KeyEvent modifiers 105 | */ 106 | int getModifiers() { 107 | return modifiers; 108 | } 109 | 110 | boolean isShiftPressed() { 111 | return (modifiers & KeyEvent.MODIFIER_SHIFT) != 0; 112 | } 113 | 114 | boolean isControlPressed() { 115 | return (modifiers & KeyEvent.MODIFIER_CONTROL) != 0; 116 | } 117 | 118 | public String toString() { 119 | return "KeyState[modifiers=" + modifiers + ",keys=" + keysPressed + "]"; 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/SocketFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.IOException; 21 | import java.io.Serializable; 22 | import java.net.InetAddress; 23 | import java.net.InetSocketAddress; 24 | import java.net.ServerSocket; 25 | import java.net.Socket; 26 | import java.net.UnknownHostException; 27 | import java.rmi.server.RMISocketFactory; 28 | import java.util.Set; 29 | import java.util.concurrent.atomic.AtomicReference; 30 | 31 | class SocketFactory extends RMISocketFactory implements Serializable { 32 | private final InetAddress host; 33 | private final int childPort; 34 | private final int parentPort; 35 | private final int parentAltPort; 36 | private final Set locks; 37 | private transient final AtomicReference clientSocket = new AtomicReference(new Socket()); 38 | private transient final AtomicReference clientAltSocket = new AtomicReference(new Socket()); 39 | 40 | SocketFactory(String host, PortGroup ports, final Set locks) { 41 | InetAddress hostTmp = null; 42 | try { 43 | hostTmp = InetAddress.getByName(host); 44 | } catch (UnknownHostException e) { 45 | Util.handleException(e); 46 | } 47 | this.host = hostTmp; 48 | this.childPort = (int) ports.child; 49 | this.parentPort = (int) ports.parent; 50 | this.parentAltPort = (int) ports.parentAlt; 51 | this.locks = locks; 52 | } 53 | 54 | private SocketFactory(SocketFactory other) { 55 | this.host = other.host; 56 | this.childPort = other.childPort; 57 | this.parentPort = other.parentPort; 58 | this.parentAltPort = other.parentAltPort; 59 | this.locks = other.locks; 60 | } 61 | 62 | private Object readResolve() { 63 | return new SocketFactory(this); 64 | } 65 | 66 | @Override 67 | public ServerSocket createServerSocket(int p) throws IOException { 68 | ServerSocket serverSocket = new ServerSocket(); 69 | serverSocket.setReuseAddress(true); 70 | serverSocket.bind(new InetSocketAddress(host, childPort), Integer.MAX_VALUE); 71 | return serverSocket; 72 | } 73 | 74 | @Override 75 | public Socket createSocket(String h, int p) throws IOException { 76 | if (holdsLock()) { 77 | return createSocket(clientSocket, parentPort, childPort, false); 78 | } 79 | return createSocket(clientAltSocket, parentAltPort, childPort, true); 80 | } 81 | 82 | private boolean holdsLock() { 83 | synchronized (locks) { 84 | for (SocketLock lock : locks) { 85 | if (Thread.holdsLock(lock)) { 86 | return true; 87 | } 88 | } 89 | } 90 | return false; 91 | } 92 | 93 | private Socket createSocket(AtomicReference socket, 94 | int localPort, int foreignPort, boolean background) throws IOException { 95 | final int retries = 15; 96 | for (int i = 1, sleep = 2; i <= retries; i++, sleep *= 2) { 97 | try { 98 | if (!background) { 99 | Util.close(socket.get()); 100 | } 101 | socket.set(new Socket()); 102 | socket.get().setReuseAddress(true); 103 | socket.get().setTcpNoDelay(true); 104 | socket.get().setKeepAlive(true); 105 | socket.get().bind(new InetSocketAddress(host, localPort)); 106 | socket.get().connect(new InetSocketAddress(host, foreignPort)); 107 | return socket.get(); 108 | } catch (IOException e) { 109 | try { 110 | if (background || i == retries) { 111 | throw e; 112 | } 113 | try { 114 | Thread.sleep(sleep); 115 | } catch (InterruptedException e2) {} 116 | } finally { 117 | Util.close(socket.get()); 118 | } 119 | } 120 | } 121 | throw new IOException(); 122 | } 123 | 124 | @Override 125 | public int hashCode() { 126 | return SocketFactory.class.getName().hashCode(); 127 | } 128 | 129 | @Override 130 | public boolean equals(Object obj) { 131 | return obj instanceof SocketFactory; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/App.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.io.File; 21 | import java.lang.reflect.Field; 22 | import java.lang.reflect.Method; 23 | import java.nio.file.Files; 24 | import java.util.List; 25 | 26 | import com.machinepublishers.glass.ui.monocle.NativePlatform; 27 | import com.machinepublishers.glass.ui.monocle.NativePlatformFactory; 28 | import com.sun.glass.ui.Screen; 29 | import com.sun.javafx.webkit.Accessor; 30 | 31 | import javafx.application.Application; 32 | import javafx.application.Platform; 33 | import javafx.scene.Scene; 34 | import javafx.scene.layout.StackPane; 35 | import javafx.scene.web.WebEngine; 36 | import javafx.scene.web.WebView; 37 | import javafx.stage.Stage; 38 | import javafx.stage.StageStyle; 39 | 40 | /** 41 | * Internal use only. 42 | * 43 | * @deprecated 44 | */ 45 | public class App extends Application { 46 | private static final int HISTORY_SIZE = 8; 47 | private static final Object lock = new Object(); 48 | private static Stage myStage; 49 | private static WebView myView; 50 | private int width; 51 | private int height; 52 | private boolean headless; 53 | 54 | /** 55 | * Internal use only. 56 | */ 57 | public App() { 58 | 59 | } 60 | 61 | static Stage getStage() { 62 | synchronized (lock) { 63 | while (myStage == null) { 64 | try { 65 | lock.wait(); 66 | } catch (InterruptedException e) {} 67 | } 68 | return myStage; 69 | } 70 | } 71 | 72 | static WebView getView() { 73 | synchronized (lock) { 74 | while (myView == null) { 75 | try { 76 | lock.wait(); 77 | } catch (InterruptedException e) {} 78 | } 79 | return myView; 80 | } 81 | } 82 | 83 | void init(int width, int height, boolean headless) { 84 | this.width = width; 85 | this.height = height; 86 | this.headless = headless; 87 | } 88 | 89 | /** 90 | * {@inheritDoc} 91 | */ 92 | @Override 93 | public void init() throws Exception { 94 | List params = getParameters().getRaw(); 95 | width = Integer.parseInt(params.get(0)); 96 | height = Integer.parseInt(params.get(1)); 97 | headless = Boolean.parseBoolean(params.get(2)); 98 | } 99 | 100 | void start() throws Exception { 101 | start(null); 102 | } 103 | 104 | /** 105 | * {@inheritDoc} 106 | */ 107 | @Override 108 | public void start(Stage stage) throws Exception { 109 | if (headless) { 110 | System.setProperty("headless.geometry", width + "x" + height); 111 | NativePlatform platform = NativePlatformFactory.getNativePlatform(); 112 | Field field = NativePlatform.class.getDeclaredField("screen"); 113 | field.setAccessible(true); 114 | field.set(platform, null); 115 | Method method = Screen.class.getDeclaredMethod("notifySettingsChanged"); 116 | method.setAccessible(true); //before Java 8u20 this method was private 117 | method.invoke(null); 118 | } 119 | if (stage == null) { 120 | stage = new Stage(); 121 | } 122 | Platform.setImplicitExit(false); 123 | WebView view = new WebView(); 124 | view.setCache(false); 125 | StackPane root = new StackPane(); 126 | root.setCache(false); 127 | if (headless) { 128 | stage.initStyle(StageStyle.UNDECORATED); 129 | } 130 | WebEngine engine = view.getEngine(); 131 | File style = File.createTempFile("jbd_style_", ".css"); 132 | style.deleteOnExit(); 133 | Files.write(style.toPath(), 134 | "body::-webkit-scrollbar {width: 0px !important;height:0px !important;}".getBytes("utf-8")); 135 | engine.setUserStyleSheetLocation(style.toPath().toUri().toURL().toExternalForm()); 136 | engine.getHistory().setMaxSize(HISTORY_SIZE); 137 | Accessor.getPageFor(engine).setDeveloperExtrasEnabled(false); 138 | Accessor.getPageFor(engine).setUsePageCache(false); 139 | root.getChildren().add(view); 140 | stage.setScene(new Scene(root, width, height)); 141 | stage.sizeToScene(); 142 | engine.titleProperty().addListener(new TitleListener(stage)); 143 | stage.show(); 144 | synchronized (lock) { 145 | myStage = stage; 146 | myView = view; 147 | lock.notifyAll(); 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/com/machinepublishers/glass/ui/monocle/NativePlatform.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, 2014, 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 | package com.machinepublishers.glass.ui.monocle; 27 | 28 | import com.machinepublishers.glass.ui.monocle.InputDeviceRegistry; 29 | import com.machinepublishers.glass.ui.monocle.NativeCursor; 30 | import com.machinepublishers.glass.ui.monocle.NativeScreen; 31 | import com.machinepublishers.glass.ui.monocle.RunnableProcessor; 32 | 33 | /** Abstract of a platform on which JavaFX can run. */ 34 | public abstract class NativePlatform { 35 | 36 | private static InputDeviceRegistry inputDeviceRegistry; 37 | private final RunnableProcessor runnableProcessor; 38 | private NativeCursor cursor; 39 | private NativeScreen screen; 40 | // protected AcceleratedScreen accScreen; 41 | 42 | protected NativePlatform() { 43 | runnableProcessor = new RunnableProcessor(); 44 | } 45 | 46 | /** 47 | * Called once during JavaFX shutdown to release platform resources. 48 | */ 49 | void shutdown() { 50 | runnableProcessor.shutdown(); 51 | if (cursor != null) { 52 | cursor.shutdown(); 53 | } 54 | if (screen != null) { 55 | screen.shutdown(); 56 | } 57 | } 58 | 59 | /** 60 | * @return the RunnableProcessor used to post events to the JavaFX event queue. 61 | */ 62 | RunnableProcessor getRunnableProcessor() { 63 | return runnableProcessor; 64 | } 65 | 66 | /** 67 | * @return the InputDeviceRegistry that maintains a list of input devices 68 | * for this platform. 69 | */ 70 | synchronized InputDeviceRegistry getInputDeviceRegistry() { 71 | if (inputDeviceRegistry == null) { 72 | inputDeviceRegistry = createInputDeviceRegistry(); 73 | } 74 | return inputDeviceRegistry; 75 | } 76 | 77 | /** 78 | * Creates the InputDeviceRegistry for this platform. Called once. 79 | * 80 | * @return a new InputDeviceRegistry 81 | */ 82 | protected abstract InputDeviceRegistry createInputDeviceRegistry(); 83 | 84 | /** 85 | * Creates the NativeCursor for this platform. Called once. 86 | * 87 | * @return a new NativeCursor 88 | */ 89 | protected abstract NativeCursor createCursor(); 90 | 91 | /** Obtains the singleton NativeCursor 92 | * 93 | * @return the NativeCursor 94 | */ 95 | synchronized NativeCursor getCursor() { 96 | if (cursor == null) { 97 | cursor = createCursor(); 98 | } 99 | return cursor; 100 | } 101 | 102 | /** 103 | * Creates the NativeScreen for this platform. Called once. 104 | * 105 | * @return a new NativeScreen 106 | */ 107 | protected abstract NativeScreen createScreen(); 108 | 109 | /** 110 | * Obtains the singleton NativeScreen 111 | * 112 | * @return the NativeScreen 113 | */ 114 | synchronized NativeScreen getScreen() { 115 | if (screen == null) { 116 | screen = createScreen(); 117 | } 118 | return screen; 119 | } 120 | 121 | // /** 122 | // * Gets the AcceleratedScreen for this platform 123 | // * 124 | // * @param attributes a sequence of pairs (GLAttibute, value) 125 | // * @return an AcceleratedScreen for rendering using OpenGL 126 | // * @throws GLException if no OpenGL surface could be created 127 | // * @throws UnsatisfiedLinkError if native graphics libraries could not be loaded for this platform. 128 | // */ 129 | // public synchronized AcceleratedScreen getAcceleratedScreen(int[] attributes) 130 | // throws GLException, UnsatisfiedLinkError { 131 | // if (accScreen == null) { 132 | // accScreen = new AcceleratedScreen(attributes); 133 | // } 134 | // return accScreen; 135 | // } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /src/com/machinepublishers/jbrowserdriver/Options.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jBrowserDriver (TM) 3 | * Copyright (C) 2014-2016 jBrowserDriver committers 4 | * https://github.com/MachinePublishers/jBrowserDriver 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package com.machinepublishers.jbrowserdriver; 19 | 20 | import java.util.Set; 21 | 22 | import org.openqa.selenium.Cookie; 23 | import org.openqa.selenium.WebDriver.ImeHandler; 24 | import org.openqa.selenium.WebDriver.Timeouts; 25 | import org.openqa.selenium.WebDriver.Window; 26 | import org.openqa.selenium.logging.Logs; 27 | 28 | class Options implements org.openqa.selenium.WebDriver.Options { 29 | private final OptionsRemote remote; 30 | private final com.machinepublishers.jbrowserdriver.Logs logs; 31 | private final SocketLock lock; 32 | 33 | Options(OptionsRemote remote, com.machinepublishers.jbrowserdriver.Logs logs, SocketLock lock) { 34 | this.remote = remote; 35 | this.logs = logs; 36 | this.lock = lock; 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | @Override 43 | public void addCookie(Cookie cookie) { 44 | try { 45 | synchronized (lock.validated()) { 46 | remote.addCookie(cookie); 47 | } 48 | } catch (Throwable t) { 49 | Util.handleException(t); 50 | } 51 | } 52 | 53 | /** 54 | * {@inheritDoc} 55 | */ 56 | @Override 57 | public void deleteAllCookies() { 58 | try { 59 | synchronized (lock.validated()) { 60 | remote.deleteAllCookies(); 61 | } 62 | } catch (Throwable t) { 63 | Util.handleException(t); 64 | } 65 | } 66 | 67 | /** 68 | * {@inheritDoc} 69 | */ 70 | @Override 71 | public void deleteCookie(Cookie cookie) { 72 | try { 73 | synchronized (lock.validated()) { 74 | remote.deleteCookie(cookie); 75 | } 76 | } catch (Throwable t) { 77 | Util.handleException(t); 78 | } 79 | } 80 | 81 | /** 82 | * {@inheritDoc} 83 | */ 84 | @Override 85 | public void deleteCookieNamed(String name) { 86 | try { 87 | synchronized (lock.validated()) { 88 | remote.deleteCookieNamed(name); 89 | } 90 | } catch (Throwable t) { 91 | Util.handleException(t); 92 | } 93 | } 94 | 95 | /** 96 | * {@inheritDoc} 97 | */ 98 | @Override 99 | public Cookie getCookieNamed(String name) { 100 | try { 101 | synchronized (lock.validated()) { 102 | return remote.getCookieNamed(name); 103 | } 104 | } catch (Throwable t) { 105 | Util.handleException(t); 106 | return null; 107 | } 108 | } 109 | 110 | /** 111 | * {@inheritDoc} 112 | */ 113 | @Override 114 | public Set getCookies() { 115 | try { 116 | synchronized (lock.validated()) { 117 | return remote.getCookies(); 118 | } 119 | } catch (Throwable t) { 120 | Util.handleException(t); 121 | return null; 122 | } 123 | } 124 | 125 | /** 126 | * {@inheritDoc} 127 | */ 128 | @Override 129 | public ImeHandler ime() { 130 | try { 131 | synchronized (lock.validated()) { 132 | ImeHandlerRemote imeHandler = remote.ime(); 133 | if (imeHandler == null) { 134 | return null; 135 | } 136 | return new com.machinepublishers.jbrowserdriver.ImeHandler(imeHandler, lock); 137 | } 138 | } catch (Throwable t) { 139 | Util.handleException(t); 140 | return null; 141 | } 142 | } 143 | 144 | /** 145 | * {@inheritDoc} 146 | */ 147 | @Override 148 | public Logs logs() { 149 | return logs; 150 | } 151 | 152 | /** 153 | * {@inheritDoc} 154 | */ 155 | @Override 156 | public Timeouts timeouts() { 157 | try { 158 | synchronized (lock.validated()) { 159 | TimeoutsRemote timeouts = remote.timeouts(); 160 | if (timeouts == null) { 161 | return null; 162 | } 163 | return new com.machinepublishers.jbrowserdriver.Timeouts(timeouts, lock); 164 | } 165 | } catch (Throwable t) { 166 | Util.handleException(t); 167 | return null; 168 | } 169 | } 170 | 171 | /** 172 | * {@inheritDoc} 173 | */ 174 | @Override 175 | public Window window() { 176 | try { 177 | synchronized (lock.validated()) { 178 | WindowRemote window = remote.window(); 179 | if (window == null) { 180 | return null; 181 | } 182 | return new com.machinepublishers.jbrowserdriver.Window(window, lock); 183 | } 184 | } catch (Throwable t) { 185 | Util.handleException(t); 186 | return null; 187 | } 188 | } 189 | } 190 | --------------------------------------------------------------------------------