Last active
August 29, 2015 14:10
-
-
Save mjgp2/1879dc0e1428b90c56ab to your computer and use it in GitHub Desktop.
Show that SWT allows unsafe chrome calls from evaluate.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************************* | |
* Copyright (c) 2007 IBM Corporation and others. All rights reserved. This program and the | |
* accompanying materials are made available under the terms of the Eclipse Public License v1.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* | |
* Contributors: IBM Corporation - initial API and implementation | |
*******************************************************************************/ | |
/* | |
* Mozilla in a Browser | |
* | |
* The requirements for using Mozilla-based Browsers are described at | |
* http://www.eclipse.org/swt/faq.php#howusemozilla | |
* | |
* For a list of all SWT example snippets see http://www.eclipse.org/swt/snippets/ | |
* | |
* @since 3.3 | |
*/ | |
import org.eclipse.swt.SWT; | |
import org.eclipse.swt.SWTError; | |
import org.eclipse.swt.browser.Browser; | |
import org.eclipse.swt.browser.LocationEvent; | |
import org.eclipse.swt.browser.LocationListener; | |
import org.eclipse.swt.browser.MozillaEvaluator; | |
import org.eclipse.swt.layout.FillLayout; | |
import org.eclipse.swt.widgets.Display; | |
import org.eclipse.swt.widgets.MessageBox; | |
import org.eclipse.swt.widgets.Shell; | |
public class Snippet260 { | |
public static void main(String[] args) { | |
Display display = new Display(); | |
final Shell shell = new Shell(display); | |
shell.setLayout(new FillLayout()); | |
shell.setText("Mozilla"); | |
final Browser browser; | |
try { | |
browser = new Browser(shell, SWT.MOZILLA); | |
} catch (SWTError e) { | |
System.out.println("Could not instantiate Browser: " + e.getMessage()); | |
display.dispose(); | |
return; | |
} | |
shell.open(); | |
browser.setUrl("http://mozilla.org"); | |
browser.addLocationListener(new LocationListener() { | |
public void changing(LocationEvent event) { | |
} | |
public void changed(LocationEvent event) { | |
MessageBox messageBox = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK); | |
Object outerWindowId; | |
try { | |
outerWindowId = MozillaEvaluator.evaluateAsChrome(browser, "return window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils).outerWindowID;"); | |
messageBox.setMessage(outerWindowId.toString()); | |
messageBox.setText(""); | |
messageBox.open(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
}); | |
while (!shell.isDisposed()) { | |
if (!display.readAndDispatch()) | |
display.sleep(); | |
} | |
display.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment