diff options
author | Grant Gayed | 2007-08-23 20:12:50 +0000 |
---|---|---|
committer | Grant Gayed | 2007-08-23 20:12:50 +0000 |
commit | 3a4282e8770b58da28b274b0451679251e5b2409 (patch) | |
tree | 621b9a9e1c055dd896e89efb46257ca4c5b2665b | |
parent | 3feb25c9be6892625725914de5f111a8c4757fd5 (diff) | |
download | eclipse.platform.swt-3a4282e8770b58da28b274b0451679251e5b2409.tar.gz eclipse.platform.swt-3a4282e8770b58da28b274b0451679251e5b2409.tar.xz eclipse.platform.swt-3a4282e8770b58da28b274b0451679251e5b2409.zip |
107142
4 files changed, 110 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Browser/carbon/org/eclipse/swt/browser/Safari.java b/bundles/org.eclipse.swt/Eclipse SWT Browser/carbon/org/eclipse/swt/browser/Safari.java index 7c7089152f..2122e757e7 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Browser/carbon/org/eclipse/swt/browser/Safari.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Browser/carbon/org/eclipse/swt/browser/Safari.java @@ -299,6 +299,23 @@ public boolean forward() { return Cocoa.objc_msgSend(webView, Cocoa.S_goForward) != 0; } +public String getText() { + int webView = Cocoa.HIWebViewGetWebView(webViewHandle); + int mainFrame = Cocoa.objc_msgSend(webView, Cocoa.S_mainFrame); + int dataSource = Cocoa.objc_msgSend(mainFrame, Cocoa.S_dataSource); + if (dataSource == 0) return ""; //$NON-NLS-1$ + int representation = Cocoa.objc_msgSend(dataSource, Cocoa.S_representation); + if (representation == 0) return ""; //$NON-NLS-1$ + int source = Cocoa.objc_msgSend(representation, Cocoa.S_documentSource); + if (source == 0) return ""; //$NON-NLS-1$ + int length = OS.CFStringGetLength(source); + char[] buffer = new char[length]; + CFRange range = new CFRange(); + range.length = length; + OS.CFStringGetCharacters(source, range, buffer); + return new String(buffer); +} + public String getUrl() { return url; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/IE.java b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/IE.java index 89b8f9fd70..6d1d71287f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/IE.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/IE.java @@ -650,6 +650,38 @@ public boolean forward() { return pVarResult != null && pVarResult.getType() == OLE.VT_EMPTY; } +public String getText() { + /* get the document object */ + int[] rgdispid = auto.getIDsOfNames(new String[]{"Document"}); //$NON-NLS-1$ + Variant pVarResult = auto.getProperty(rgdispid[0]); + if (pVarResult == null || pVarResult.getType() == COM.VT_EMPTY) return ""; //$NON-NLS-1$ + OleAutomation document = pVarResult.getAutomation(); + pVarResult.dispose(); + + /* get the html object */ + rgdispid = document.getIDsOfNames(new String[] {"documentElement"}); //$NON-NLS-1$ + if (rgdispid == null) { + /* implies that the browser is displaying non-HTML content */ + document.dispose(); + return ""; //$NON-NLS-1$ + } + pVarResult = document.getProperty(rgdispid[0]); + document.dispose(); + if (pVarResult == null || pVarResult.getType() == COM.VT_EMPTY) return ""; //$NON-NLS-1$ + OleAutomation element = pVarResult.getAutomation(); + pVarResult.dispose(); + + /* get its outerHTML property */ + rgdispid = element.getIDsOfNames(new String[] {"outerHTML"}); //$NON-NLS-1$ + pVarResult = element.getProperty(rgdispid[0]); + element.dispose(); + if (pVarResult == null || pVarResult.getType() == COM.VT_EMPTY) return ""; //$NON-NLS-1$ + String result = pVarResult.getString(); + pVarResult.dispose(); + + return result; +} + public String getUrl() { int[] rgdispid = auto.getIDsOfNames(new String[] { "LocationURL" }); //$NON-NLS-1$ Variant pVarResult = auto.getProperty(rgdispid[0]); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java index 1c38a42d16..46f3fd3f93 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java @@ -1213,6 +1213,65 @@ public boolean forward () { return rc == XPCOM.NS_OK; } +public String getText () { + int /*long*/[] result = new int /*long*/[1]; + int rc = webBrowser.GetContentDOMWindow (result); + if (rc != XPCOM.NS_OK) error (rc); + if (result[0] == 0) error (XPCOM.NS_NOINTERFACE); + + nsIDOMWindow window = new nsIDOMWindow (result[0]); + result[0] = 0; + rc = window.GetDocument (result); + if (rc != XPCOM.NS_OK) error (rc); + if (result[0] == 0) error (XPCOM.NS_NOINTERFACE); + window.Release (); + + int /*long*/ document = result[0]; + result[0] = 0; + rc = XPCOM.NS_GetComponentManager (result); + if (rc != XPCOM.NS_OK) error (rc); + if (result[0] == 0) error (XPCOM.NS_NOINTERFACE); + + nsIComponentManager componentManager = new nsIComponentManager (result[0]); + result[0] = 0; + byte[] contractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_DOMSERIALIZER_CONTRACTID, true); + char[] chars = null; + + rc = componentManager.CreateInstanceByContractID (contractID, 0, nsIDOMSerializer_1_7.NS_IDOMSERIALIZER_IID, result); + if (rc == XPCOM.NS_OK) { /* mozilla >= 1.7 */ + if (result[0] == 0) error (XPCOM.NS_NOINTERFACE); + + nsIDOMSerializer_1_7 serializer = new nsIDOMSerializer_1_7 (result[0]); + result[0] = 0; + int /*long*/ string = XPCOM.nsEmbedString_new (); + rc = serializer.SerializeToString (document, string); + serializer.Release (); + + int length = XPCOM.nsEmbedString_Length (string); + int /*long*/ buffer = XPCOM.nsEmbedString_get (string); + chars = new char[length]; + XPCOM.memmove (chars, buffer, length * 2); + XPCOM.nsEmbedString_delete (string); + } else { /* mozilla < 1.7 */ + rc = componentManager.CreateInstanceByContractID (contractID, 0, nsIDOMSerializer.NS_IDOMSERIALIZER_IID, result); + if (rc != XPCOM.NS_OK) error (rc); + if (result[0] == 0) error (XPCOM.NS_NOINTERFACE); + + nsIDOMSerializer serializer = new nsIDOMSerializer (result[0]); + result[0] = 0; + rc = serializer.SerializeToString (document, result); + serializer.Release (); + + int length = XPCOM.strlen_PRUnichar (result[0]); + chars = new char[length]; + XPCOM.memmove (chars, result[0], length * 2); + } + + componentManager.Release (); + new nsISupports (document).Release (); + return new String (chars); +} + public String getUrl () { int /*long*/[] result = new int /*long*/[1]; int rc = webBrowser.QueryInterface (nsIWebNavigation.NS_IWEBNAVIGATION_IID, result); diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/cocoa/Cocoa.java b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/cocoa/Cocoa.java index c5a8c865a5..3d28207af7 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/cocoa/Cocoa.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/cocoa/Cocoa.java @@ -55,6 +55,7 @@ public static final int S_cut = Cocoa.sel_registerName("cut:"); //$NON-NLS-1$ public static final int S_dataSource = Cocoa.sel_registerName("dataSource"); //$NON-NLS-1$ public static final int S_defaultCenter = Cocoa.sel_registerName("defaultCenter"); //$NON-NLS-1$ public static final int S_deleteCookie = Cocoa.sel_registerName("deleteCookie:"); //$NON-NLS-1$ +public static final int S_documentSource = Cocoa.sel_registerName("documentSource"); //$NON-NLS-1$ public static final int S_download = Cocoa.sel_registerName("download"); //$NON-NLS-1$ public static final int S_goBack = Cocoa.sel_registerName("goBack:"); //$NON-NLS-1$ public static final int S_goForward = Cocoa.sel_registerName("goForward:"); //$NON-NLS-1$ @@ -77,6 +78,7 @@ public static final int S_reload = Cocoa.sel_registerName("reload:"); //$NON-NLS public static final int S_retain = Cocoa.sel_registerName("retain"); //$NON-NLS-1$ public static final int S_removeObserver_name_object = Cocoa.sel_registerName("removeObserver:name:object:"); //$NON-NLS-1$ public static final int S_removeObserver = Cocoa.sel_registerName("removeObserver:"); //$NON-NLS-1$ +public static final int S_representation = Cocoa.sel_registerName("representation"); //$NON-NLS-1$ public static final int S_requestWithURL = Cocoa.sel_registerName("requestWithURL:"); //$NON-NLS-1$ public static final int S_request = Cocoa.sel_registerName("request"); //$NON-NLS-1$ public static final int S_retainCount = Cocoa.sel_registerName("retainCount"); //$NON-NLS-1$ |