diff options
author | Grant Gayed <ggayed> | 2010-01-15 17:54:25 +0000 |
---|---|---|
committer | Grant Gayed <ggayed> | 2010-01-15 17:54:25 +0000 |
commit | 9837bb695405327b535c2924659cef1a3a71f994 (patch) | |
tree | 021ec13362159cf6042b725e71cbe53947f0a4c1 /bundles/org.eclipse.swt/Eclipse SWT Browser | |
parent | a3eda06a7a4c290420b73156206fa1800c9178ee (diff) | |
download | eclipse.platform.swt-9837bb695405327b535c2924659cef1a3a71f994.tar.gz eclipse.platform.swt-9837bb695405327b535c2924659cef1a3a71f994.tar.xz eclipse.platform.swt-9837bb695405327b535c2924659cef1a3a71f994.zip |
298473 - Safari and WebKit should navigate to about:blank in setText()
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT Browser')
-rwxr-xr-x | bundles/org.eclipse.swt/Eclipse SWT Browser/carbon/org/eclipse/swt/browser/Safari.java | 122 | ||||
-rwxr-xr-x | bundles/org.eclipse.swt/Eclipse SWT Browser/cocoa/org/eclipse/swt/browser/Safari.java | 96 |
2 files changed, 125 insertions, 93 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 dc32189123..b94fc3e7b4 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 @@ -31,7 +31,7 @@ class Safari extends WebBrowser { int windowBoundsHandler; int preferences; - boolean changingLocation, hasNewFocusElement, untrustedText; + boolean loadingText, hasNewFocusElement, untrustedText; String lastHoveredLinkURL, lastNavigateURL; String html; int identifier; @@ -759,47 +759,27 @@ public boolean isForwardEnabled() { } public void refresh() { + html = null; Cocoa.objc_msgSend(webView, Cocoa.S_reload, 0); } public boolean setText(String html, boolean trusted) { - untrustedText = !trusted; /* - * Bug in Safari. The web view segment faults in some circumstances - * when the text changes during the location changing callback. The - * fix is to defer the work until the callback is done. + * If this.html is not null then the about:blank page is already being loaded, + * so no navigate is required. Just set the html that is to be shown. */ - if (changingLocation) { - this.html = html; - } else { - _setText(html, trusted); - } - return true; -} - -void _setText(String html, boolean trusted) { - int string = createNSString(html); - int URLString; - if (trusted) { - URLString = createNSString(URI_FILEROOT); - } else { - URLString = createNSString(ABOUT_BLANK); - } + boolean blankLoading = this.html != null; + this.html = html; + untrustedText = !trusted; + if (blankLoading) return true; - /* - * Note. URLWithString uses autorelease. The resulting URL - * does not need to be released. - * URL = [NSURL URLWithString:(NSString *)URLString] - */ - int URL = Cocoa.objc_msgSend(Cocoa.C_NSURL, Cocoa.S_URLWithString, URLString); - OS.CFRelease(URLString); - - //mainFrame = [webView mainFrame]; + int str = createNSString(ABOUT_BLANK); + int inURL = Cocoa.objc_msgSend(Cocoa.C_NSURL, Cocoa.S_URLWithString, str); /* autoreleased */ + OS.CFRelease (str); + int request = Cocoa.objc_msgSend(Cocoa.C_NSURLRequest, Cocoa.S_requestWithURL, inURL); int mainFrame = Cocoa.objc_msgSend(webView, Cocoa.S_mainFrame); - - //[mainFrame loadHTMLString:(NSString *) string baseURL:(NSURL *)URL]; - Cocoa.objc_msgSend(mainFrame, Cocoa.S_loadHTMLStringbaseURL, string, URL); - OS.CFRelease(string); + Cocoa.objc_msgSend(mainFrame, Cocoa.S_loadRequest, request); + return true; } public boolean setUrl(String url, String postData, String[] headers) { @@ -979,21 +959,44 @@ void didFinishLoadForFrame(int frame) { } } - /* re-install registered functions */ - Enumeration elements = functions.elements (); - while (elements.hasMoreElements ()) { - BrowserFunction function = (BrowserFunction)elements.nextElement (); - execute (function.functionString); + /* + * If html is not null then there is html from a previous setText() call + * waiting to be set into the about:blank page once it has completed loading. + */ + if (html != null) { + if (url.startsWith(ABOUT_BLANK)) { + loadingText = true; + int htmlString = createNSString(html); + int urlString; + if (untrustedText) { + urlString = createNSString(ABOUT_BLANK); + } else { + urlString = createNSString(URI_FILEROOT); + } + int url = Cocoa.objc_msgSend(Cocoa.C_NSURL, Cocoa.S_URLWithString, urlString); /* autoreleased */ + int mainFrame = Cocoa.objc_msgSend(webView, Cocoa.S_mainFrame); + Cocoa.objc_msgSend(mainFrame, Cocoa.S_loadHTMLStringBaseURL, htmlString, url); + OS.CFRelease(urlString); + OS.CFRelease(htmlString); + html = null; + } } - - ProgressEvent progress = new ProgressEvent(browser); - progress.display = display; - progress.widget = browser; - progress.current = MAX_PROGRESS; - progress.total = MAX_PROGRESS; - for (int i = 0; i < progressListeners.length; i++) { - progressListeners[i].completed(progress); + /* + * The loadHTMLString() invocation above will trigger a second didFinishLoadForFrame + * callback when it is completed. Wait for this second callback to come before sending + * the completed event. + */ + if (!loadingText) { + ProgressEvent progress = new ProgressEvent(browser); + progress.display = display; + progress.widget = browser; + progress.current = MAX_PROGRESS; + progress.total = MAX_PROGRESS; + for (int i = 0; i < progressListeners.length; i++) { + progressListeners[i].completed(progress); + } } + loadingText = false; if (browser.isDisposed()) return; /* @@ -1148,7 +1151,13 @@ void didCommitLoadForFrame(int frame) { /* reset resource status variables */ resourceCount = 0; this.url = url2; - + + Enumeration elements = functions.elements (); + while (elements.hasMoreElements ()) { + BrowserFunction function = (BrowserFunction)elements.nextElement (); + execute (function.functionString); + } + final ProgressEvent progress = new ProgressEvent(browser); progress.display = display; progress.widget = browser; @@ -1696,6 +1705,15 @@ void decidePolicyForMIMEType(int type, int request, int frame, int listener) { void decidePolicyForNavigationAction(int actionInformation, int request, int frame, int listener) { int url = Cocoa.objc_msgSend(request, Cocoa.S_URL); + if (loadingText) { + /* + * Safari is auto-navigating to about:blank in response to a loadHTMLString() + * invocation. This navigate should always proceed without sending an event + * since it is preceded by an explicit navigate to about:blank in setText(). + */ + Cocoa.objc_msgSend(listener, Cocoa.S_use); + return; + } if (url == 0) { /* indicates that a URL with an invalid format was specified */ Cocoa.objc_msgSend(listener, Cocoa.S_ignore); @@ -1740,11 +1758,9 @@ void decidePolicyForNavigationAction(int actionInformation, int request, int fra newEvent.location = url2; newEvent.doit = true; if (locationListeners != null) { - changingLocation = true; for (int i = 0; i < locationListeners.length; i++) { locationListeners[i].changing(newEvent); } - changingLocation = false; } if (newEvent.doit) { if (jsEnabledChanged) { @@ -1760,12 +1776,6 @@ void decidePolicyForNavigationAction(int actionInformation, int request, int fra } Cocoa.objc_msgSend(listener, newEvent.doit ? Cocoa.S_use : Cocoa.S_ignore); } - - if (html != null && !browser.isDisposed()) { - String html = this.html; - this.html = null; - _setText(html, !untrustedText); - } } void decidePolicyForNewWindowAction(int actionInformation, int request, int frameName, int listener) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Browser/cocoa/org/eclipse/swt/browser/Safari.java b/bundles/org.eclipse.swt/Eclipse SWT Browser/cocoa/org/eclipse/swt/browser/Safari.java index 02c12a6b6c..535a0ac8df 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Browser/cocoa/org/eclipse/swt/browser/Safari.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Browser/cocoa/org/eclipse/swt/browser/Safari.java @@ -23,7 +23,7 @@ class Safari extends WebBrowser { WebView webView; WebPreferences preferences; SWTWebViewDelegate delegate; - boolean changingLocation, untrustedText; + boolean loadingText, untrustedText; String lastHoveredLinkURL, lastNavigateURL; String html; int /*long*/ identifier; @@ -491,35 +491,25 @@ public boolean isForwardEnabled() { } public void refresh() { + html = null; webView.reload(null); } public boolean setText(String html, boolean trusted) { - untrustedText = !trusted; /* - * Bug in Safari. The web view segment faults in some circumstances - * when the text changes during the location changing callback. The - * fix is to defer the work until the callback is done. + * If this.html is not null then the about:blank page is already being loaded, + * so no navigate is required. Just set the html that is to be shown. */ - if (changingLocation) { - this.html = html; - } else { - _setText(html, trusted); - } - return true; -} - -void _setText(String html, boolean trusted) { - NSString string = NSString.stringWith(html); - NSString URLString; - if (trusted) { - URLString = NSString.stringWith(URI_FILEROOT); - } else { - URLString = NSString.stringWith(ABOUT_BLANK); - } - NSURL URL = NSURL.URLWithString(URLString); + boolean blankLoading = this.html != null; + this.html = html; + untrustedText = !trusted; + if (blankLoading) return true; + + NSURL inURL = NSURL.URLWithString(NSString.stringWith (ABOUT_BLANK)); + NSURLRequest request = NSURLRequest.requestWithURL(inURL); WebFrame mainFrame = webView.mainFrame(); - mainFrame.loadHTMLString(string, URL); + mainFrame.loadRequest(request); + return true; } public boolean setUrl(String url, String postData, String[] headers) { @@ -698,14 +688,43 @@ void webView_didFinishLoadForFrame(int /*long*/ sender, int /*long*/ frameID) { if (browser.isDisposed()) return; } } - ProgressEvent progress = new ProgressEvent(browser); - progress.display = display; - progress.widget = browser; - progress.current = MAX_PROGRESS; - progress.total = MAX_PROGRESS; - for (int i = 0; i < progressListeners.length; i++) { - progressListeners[i].completed(progress); + + /* + * If html is not null then there is html from a previous setText() call + * waiting to be set into the about:blank page once it has completed loading. + */ + if (html != null) { + if (url.startsWith(ABOUT_BLANK)) { + loadingText = true; + NSString string = NSString.stringWith(html); + NSString URLString; + if (untrustedText) { + URLString = NSString.stringWith(ABOUT_BLANK); + } else { + URLString = NSString.stringWith(URI_FILEROOT); + } + NSURL URL = NSURL.URLWithString(URLString); + WebFrame mainFrame = webView.mainFrame(); + mainFrame.loadHTMLString(string, URL); + html = null; + } } + /* + * The loadHTMLString() invocation above will trigger a second webView_didFinishLoadForFrame + * callback when it is completed. Wait for this second callback to come before sending the + * completed event. + */ + if (!loadingText) { + ProgressEvent progress = new ProgressEvent(browser); + progress.display = display; + progress.widget = browser; + progress.current = MAX_PROGRESS; + progress.total = MAX_PROGRESS; + for (int i = 0; i < progressListeners.length; i++) { + progressListeners[i].completed(progress); + } + } + loadingText = false; if (browser.isDisposed()) return; /* @@ -1332,6 +1351,16 @@ void webView_decidePolicyForMIMEType_request_frame_decisionListener(int /*long*/ void webView_decidePolicyForNavigationAction_request_frame_decisionListener(int /*long*/ sender, int /*long*/ actionInformation, int /*long*/ request, int /*long*/ frame, int /*long*/ listenerID) { NSURL url = new NSURLRequest(request).URL(); WebPolicyDecisionListener listener = new WebPolicyDecisionListener(listenerID); + + if (loadingText) { + /* + * Safari is auto-navigating to about:blank in response to a loadHTMLString() + * invocation. This navigate should always proceed without sending an event + * since it is preceded by an explicit navigate to about:blank in setText(). + */ + listener.use(); + return; + } if (url == null) { /* indicates that a URL with an invalid format was specified */ listener.ignore(); @@ -1365,11 +1394,9 @@ void webView_decidePolicyForNavigationAction_request_frame_decisionListener(int newEvent.location = url2; newEvent.doit = true; if (locationListeners != null) { - changingLocation = true; for (int i = 0; i < locationListeners.length; i++) { locationListeners[i].changing(newEvent); } - changingLocation = false; } if (newEvent.doit) { if (jsEnabledChanged) { @@ -1385,11 +1412,6 @@ void webView_decidePolicyForNavigationAction_request_frame_decisionListener(int } else { listener.ignore(); } - if (html != null && !browser.isDisposed()) { - String html = this.html; - this.html = null; - _setText(html, !untrustedText); - } } void webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener(int /*long*/ sender, int /*long*/ actionInformation, int /*long*/ request, int /*long*/ frameName, int /*long*/ listenerID) { |