1 /* 2 * Copyright (c) 2011, 2018, 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.sun.javafx.webkit.drt; 27 28 import com.sun.webkit.LoadListenerClient; 29 import com.sun.webkit.UIClient; 30 import com.sun.webkit.WebPage; 31 import com.sun.webkit.graphics.WCImage; 32 import com.sun.webkit.graphics.WCRectangle; 33 34 import java.util.ArrayList; 35 import java.util.Iterator; 36 import java.util.List; 37 38 /** 39 * {@link UIClient} implementation for DRT tests. 40 */ 41 final class UIClientImpl implements UIClient { 42 43 private WebPage webPage; 44 private final List<UIClient> clients = new ArrayList<UIClient>(); 45 46 private WCRectangle bounds = new WCRectangle(0, 0, 800, 600); 47 48 UIClientImpl() { 49 } 50 51 void setWebPage(WebPage webPage) { 52 this.webPage = webPage; 53 } 54 55 /** 56 * {@inheritDoc} 57 */ 58 @Override 59 public WebPage createPage(boolean menu, boolean status, boolean toolbar, 60 boolean resizable) 61 { 62 UIClientImpl client = new UIClientImpl(); 63 final WebPage page = new WebPage(null, client, null, null, new DumpRenderTree.ThemeClientImplStub(), false); 64 client.setWebPage(page); 65 66 page.setBounds(0, 0, 800, 600); 67 // webPage.setUsePageCache(true); 68 69 page.addLoadListenerClient(new LoadListenerClient() { 70 @Override 71 public void dispatchLoadEvent(long frame, int state, String url, String contentType, double progress, int errorCode) { 72 if (state == DOCUMENT_AVAILABLE) { 73 DumpRenderTree.drt.dumpUnloadListeners(page, frame); 74 } 75 } 76 @Override 77 public void dispatchResourceLoadEvent(long frame, int state, String url, String contentType, double progress, int errorCode) { 78 } 79 }); 80 81 // This call is needed to add the main frame to WebPage.frames list. 82 // TODO: investigate why it's not added automatically (via WebPage.fwkFrameCreated) and fix. 83 page.getMainFrame(); 84 85 clients.add(client); 86 return client.webPage; 87 } 88 89 /** 90 * {@inheritDoc} 91 */ 92 @Override 93 public void closePage() { 94 Iterator<UIClient> it = clients.iterator(); 95 while (it.hasNext()) { 96 it.next().closePage(); 97 it.remove(); 98 } 99 if (webPage.getMainFrame() != 0) { 100 webPage.dispose(); 101 } 102 } 103 104 /** 105 * {@inheritDoc} 106 */ 107 @Override 108 public void showView() { 109 // look, I'm showing! 110 } 111 112 /** 113 * {@inheritDoc} 114 */ 115 @Override 116 public WCRectangle getViewBounds() { 117 return bounds; 118 } 119 120 /** 121 * {@inheritDoc} 122 */ 123 @Override 124 public void setViewBounds(WCRectangle bounds) { 125 this.bounds = bounds; 126 } 127 128 /** 129 * {@inheritDoc} 130 */ 131 @Override 132 public void setStatusbarText(String text) { 133 } 134 135 /** 136 * {@inheritDoc} 137 */ 138 @Override 139 public void alert(String text) { 140 if (!DumpRenderTree.drt.complete()) { 141 DumpRenderTree.out.printf("ALERT: %s\n", text); 142 } 143 } 144 145 /** 146 * {@inheritDoc} 147 */ 148 @Override 149 public boolean confirm(String text) { 150 if (!DumpRenderTree.drt.complete()) { 151 DumpRenderTree.out.printf("CONFIRM: %s\n", text); 152 } 153 return false; 154 } 155 156 /** 157 * {@inheritDoc} 158 */ 159 @Override 160 public String prompt(String text, String defaultValue) { 161 if (!DumpRenderTree.drt.complete()) { 162 DumpRenderTree.out.printf("PROMPT: %s, default text: %s\n", text, defaultValue); 163 } 164 return defaultValue; 165 } 166 167 @Override 168 public boolean canRunBeforeUnloadConfirmPanel() { 169 return true; 170 } 171 172 @Override 173 public boolean runBeforeUnloadConfirmPanel(String message) { 174 if (!DumpRenderTree.drt.complete()) { 175 DumpRenderTree.out.printf("CONFIRM NAVIGATION: %s\n", message); 176 } 177 return !DumpRenderTree.drt.shouldStayOnPageAfterHandlingBeforeUnload(); 178 } 179 180 /** 181 * {@inheritDoc} 182 */ 183 @Override 184 public String[] chooseFile(String initialFileName, boolean multiple, String mimeFilters) { 185 throw new UnsupportedOperationException("Not supported yet"); 186 } 187 188 /** 189 * {@inheritDoc} 190 */ 191 @Override 192 public void print() { 193 throw new UnsupportedOperationException("Not supported yet"); 194 } 195 196 /** 197 * {@inheritDoc} 198 */ 199 @Override 200 public void startDrag(WCImage frame, int imageOffsetX, int imageOffsetY, 201 int eventPosX, int eventPosY, String[] mimeTypes, Object[] values, boolean isImageSource) 202 { 203 throw new UnsupportedOperationException("Not supported yet"); 204 } 205 206 /** 207 * {@inheritDoc} 208 */ 209 @Override 210 public void confirmStartDrag() { 211 throw new UnsupportedOperationException("Not supported yet."); 212 } 213 214 /** 215 * {@inheritDoc} 216 */ 217 @Override 218 public boolean isDragConfirmed() { 219 return false; 220 } 221 }