# HG changeset patch # User Eugene Ostroukhov # Date 1264702684 28800 # Node ID bb6160d0b6f2c8269bae74ff671fc6f90ee935d6 # Parent 5a2cfa9bc74343310fbefc5e31f7606a0882af1d Added fallback to default browser if platform is Mac or XULRunner is not available diff -r 5a2cfa9bc743 -r bb6160d0b6f2 org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/ChromeDebugUtils.java --- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/ChromeDebugUtils.java Wed Jan 27 17:54:14 2010 -0800 +++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/ChromeDebugUtils.java Thu Jan 28 10:18:04 2010 -0800 @@ -20,9 +20,7 @@ import java.io.File; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.Platform; -import org.symbian.tools.wrttools.util.ProjectUtils; +import org.symbian.tools.wrttools.util.CoreUtil; public final class ChromeDebugUtils { public static String getExecutablePath(String folder) { @@ -38,9 +36,9 @@ private static String getExecutable() { // Add more ifs as we add support for new platforms - if (isMac()) { + if (CoreUtil.isMac()) { return "Google Chrome.app/Contents/MacOS/Google Chrome"; - } if (isLinux()) { + } else if (CoreUtil.isLinux()) { return "chrome"; } else { return "chrome.exe"; @@ -55,15 +53,4 @@ return getExecutablePath(Activator.getDefault().getPreferenceStore().getString(IConstants.PREF_NAME_CHROME_LOCATION)); } - public static boolean isWindows() { - return "windows".equals(Platform.getOS()); - } - - public static boolean isMac() { - return "macosx".equals(Platform.getOS()); - } - - public static boolean isLinux() { - return "linux".equals(Platform.getOS()); - } } diff -r 5a2cfa9bc743 -r bb6160d0b6f2 org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/PreferenceInitializer.java --- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/PreferenceInitializer.java Wed Jan 27 17:54:14 2010 -0800 +++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/PreferenceInitializer.java Thu Jan 28 10:18:04 2010 -0800 @@ -22,6 +22,7 @@ import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; import org.eclipse.jface.preference.IPreferenceStore; +import org.symbian.tools.wrttools.util.CoreUtil; public class PreferenceInitializer extends AbstractPreferenceInitializer { private final static String DEFAULT_CHROME_LOCATION = "Local Settings/Application Data/Google/Chrome/Application"; @@ -37,9 +38,9 @@ } private File getDefaultFolder() { - if (ChromeDebugUtils.isMac()) { + if (CoreUtil.isMac()) { return new File("/Applications"); - } else if (ChromeDebugUtils.isLinux()) { + } else if (CoreUtil.isLinux()) { return new File("/opt/google/chrome"); } String property = System.getProperty("user.home"); diff -r 5a2cfa9bc743 -r bb6160d0b6f2 org.symbian.tools.wrttools.previewer/META-INF/MANIFEST.MF --- a/org.symbian.tools.wrttools.previewer/META-INF/MANIFEST.MF Wed Jan 27 17:54:14 2010 -0800 +++ b/org.symbian.tools.wrttools.previewer/META-INF/MANIFEST.MF Thu Jan 28 10:18:04 2010 -0800 @@ -8,11 +8,12 @@ org.eclipse.core.runtime, org.eclipse.core.resources;bundle-version="3.5.0", org.eclipse.core.net;bundle-version="1.2.0", - org.mozilla.xpcom;bundle-version="1.9.1", + org.mozilla.xpcom;bundle-version="1.9.1";resolution:=optional, org.eclipse.equinox.http.jetty;bundle-version="2.0.0", org.eclipse.wst.jsdt.core;bundle-version="1.0.201", org.eclipse.wst.jsdt.ui;bundle-version="1.0.200", - org.symbian.tools.wrttools;bundle-version="1.0.0" + org.symbian.tools.wrttools;bundle-version="1.0.0", + org.mozilla.xulrunner;bundle-version="1.9.1";resolution:=optional Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Export-Package: org.symbian.tools.wrttools.previewer, diff -r 5a2cfa9bc743 -r bb6160d0b6f2 org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java Thu Jan 28 10:18:04 2010 -0800 @@ -0,0 +1,178 @@ +package org.symbian.tools.wrttools.previewer.preview; + +import java.net.URI; +import java.util.Collection; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.part.IPageSite; +import org.eclipse.ui.part.Page; +import org.symbian.tools.wrttools.previewer.Images; +import org.symbian.tools.wrttools.previewer.PreviewerPlugin; + +public abstract class AbstractPreviewPage extends Page implements IPreviewPage, ISelectionProvider { + private final IAction refreshAction = new Action("Refresh") { + public void run() { + refresh(); + }; + }; + private final IAction toggleRefresh = new Action("Toggle Refresh", IAction.AS_RADIO_BUTTON) { + public void run() { + toggleRefresh(); + }; + }; + + private final IProject project; + private Browser browser; + private boolean toggleState = true; + private final PreviewView previewView; + private boolean needsRefresh = false; + + public AbstractPreviewPage(IProject project, PreviewView previewView) { + this.project = project; + this.previewView = previewView; + } + + protected void toggleRefresh() { + toggleState = !toggleState; + toggleRefresh.setChecked(toggleState); + previewView.setProjectAutorefresh(project, toggleState); + toggleRefresh.setToolTipText(getToggleActionTooltip()); + if (toggleState && needsRefresh) { + refresh(); + } + } + + + @Override + public void createControl(Composite parent) { + browser = createBrowser(parent); + browser.setUrl(getURI().toASCIIString()); + } + + protected abstract Browser createBrowser(Composite parent); + + private URI getURI() { + return PreviewerPlugin.getDefault().getHttpPreviewer().previewProject(project); + } + + @Override + public Control getControl() { + return browser; + } + + @Override + public void setFocus() { + browser.setFocus(); + } + + private boolean refreshScheduled = false; + + public synchronized void process(Collection files) { + if (!refreshScheduled && needsRefresh(files)) { + asyncExec(new Runnable() { + @Override + public void run() { + if (toggleState) { + refresh(); + } else { + needsRefresh = true; + refreshAction.setImageDescriptor(PreviewerPlugin.getImageDescriptor(Images.RED_SYNC)); + refreshAction.setToolTipText("Refresh the preview browser (there are updated files)"); + } + } + }); + refreshScheduled = true; + } + } + + private void asyncExec(Runnable runnable) { + getControl().getDisplay().asyncExec(runnable); + } + + private boolean needsRefresh(Collection files) { + for (IFile iFile : files) { + if (iFile.getProject().equals(project)) { + return true; + } + } + return false; + } + + protected synchronized void refresh() { + try { + final Control focusControl = browser.getDisplay().getFocusControl(); + browser.refresh(); + refreshAction.setImageDescriptor(PreviewerPlugin + .getImageDescriptor(Images.GREEN_SYNC)); + if (focusControl != null) { + asyncExec(new Runnable() { + @Override + public void run() { + focusControl.setFocus(); + } + }); + } + refreshAction.setToolTipText("Refresh the preview browser"); + needsRefresh = false; + } finally { + refreshScheduled = false; + } + } + + @Override + public void init(IPageSite pageSite) { + super.init(pageSite); + IToolBarManager toolBar = pageSite.getActionBars().getToolBarManager(); + refreshAction.setImageDescriptor(PreviewerPlugin.getImageDescriptor(Images.GREEN_SYNC)); + refreshAction.setToolTipText("Refresh the preview browser"); + toolBar.add(refreshAction); + + toggleState = previewView.getProjectAutorefresh(project); + + toggleRefresh.setImageDescriptor(PreviewerPlugin.getImageDescriptor(Images.YELLOW_SYNC)); + toggleRefresh.setToolTipText(getToggleActionTooltip()); + toggleRefresh.setChecked(toggleState); + toolBar.add(toggleRefresh); + + pageSite.getActionBars().setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction); + getSite().setSelectionProvider(this); + } + + private String getToggleActionTooltip() { + return toggleState ? "Disable preview autorefresh" : "Enable preview autorefresh"; + } + + @Override + public void addSelectionChangedListener(ISelectionChangedListener listener) { + // Do nothing + } + + @Override + public ISelection getSelection() { + return new StructuredSelection(project); + } + + @Override + public void removeSelectionChangedListener( + ISelectionChangedListener listener) { + // Do nothing + } + + @Override + public void setSelection(ISelection selection) { + // Do nothing + } + +} diff -r 5a2cfa9bc743 -r bb6160d0b6f2 org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/IPreviewPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/IPreviewPage.java Thu Jan 28 10:18:04 2010 -0800 @@ -0,0 +1,10 @@ +package org.symbian.tools.wrttools.previewer.preview; + +import java.util.Collection; + +import org.eclipse.core.resources.IFile; +import org.eclipse.ui.part.IPageBookViewPage; + +public interface IPreviewPage extends IPageBookViewPage { + void process(Collection files); +} diff -r 5a2cfa9bc743 -r bb6160d0b6f2 org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/MozillaPreviewPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/MozillaPreviewPage.java Thu Jan 28 10:18:04 2010 -0800 @@ -0,0 +1,148 @@ +package org.symbian.tools.wrttools.previewer.preview; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; + +import org.eclipse.core.net.proxy.IProxyData; +import org.eclipse.core.net.proxy.IProxyService; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Platform; +import org.eclipse.swt.SWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.widgets.Composite; +import org.mozilla.interfaces.nsIPrefBranch; +import org.mozilla.interfaces.nsIServiceManager; +import org.mozilla.xpcom.Mozilla; +import org.osgi.framework.Bundle; +import org.symbian.tools.wrttools.previewer.PreviewerPlugin; +import org.symbian.tools.wrttools.previewer.http.WebAppInterface; +import org.symbian.tools.wrttools.previewer.http.WebappManager; + +public class MozillaPreviewPage extends AbstractPreviewPage { + public static final String XUL_RUNNER_BUNDLE = "org.mozilla.xulrunner"; + + private static final String XUL_RUNNER_PATH_PARAMETER = "org.eclipse.swt.browser.XULRunnerPath"; + private nsIPrefBranch mozillaPrefs; + + public MozillaPreviewPage(IProject project, PreviewView previewView) { + super(project, previewView); + } + + + private synchronized void initMozilla() { + if (System.getProperty(XUL_RUNNER_PATH_PARAMETER) == null) { + Bundle bundle = Platform.getBundle(XUL_RUNNER_BUNDLE); //$NON-NLS-1$ + if (bundle != null) { + URL resourceUrl = bundle.getResource("xulrunner"); //$NON-NLS-1$ + if (resourceUrl != null) { + try { + URL fileUrl = FileLocator.toFileURL(resourceUrl); + File file = new File(fileUrl.toURI()); + System.setProperty(XUL_RUNNER_PATH_PARAMETER, file + .getAbsolutePath()); //$NON-NLS-1$ + } catch (IOException e) { + // log the exception + } catch (URISyntaxException e) { + // log the exception + } + } + } + } + } + + @Override + protected Browser createBrowser(Composite parent) { + initMozilla(); + final Browser browser = new Browser(parent, SWT.MOZILLA); + bypassSameOriginPolicy(); + applyProxySettings(); + return browser; + } + + private void applyProxySettings() { + IProxyService px = PreviewerPlugin.getDefault().getProxyService(); + if(px != null){ + boolean proxyEnabled = px.isProxiesEnabled(); + + boolean systemProxy = px.isSystemProxiesEnabled(); + if( proxyEnabled && !systemProxy){ + IProxyData pd = px.getProxyData(IProxyData.HTTP_PROXY_TYPE); + if (pd !=null &&mozillaPrefs != null) { + String host= pd.getHost(); + int port = pd.getPort(); + if(host !=null && port != -1){ + mozillaPrefs.setIntPref("network.proxy.type", 1); + mozillaPrefs.setCharPref("network.proxy.http", host); + mozillaPrefs.setIntPref("network.proxy.http_port", port); + } + } + } + } + else{ + Exception e= new Exception(); + PreviewerPlugin.log("Proxy service returned null", e); + } + } + + private void bypassSameOriginPolicy() { + WebAppInterface.getInstance(); + try{ + nsIServiceManager servMgr = null; + try { + servMgr = Mozilla.getInstance().getServiceManager(); + if (servMgr == null) return; + } catch (Exception x) { + // known to throw NullPointException on Mac OS when you're not using + // Mozilla. We don't want to pollute the error log with this + return; + } + + mozillaPrefs = (nsIPrefBranch) servMgr.getServiceByContractID( + "@mozilla.org/preferences-service;1", + nsIPrefBranch.NS_IPREFBRANCH_IID ); + + mozillaPrefs.setBoolPref("signed.applets.codebase_principal_support", 1); + + mozillaPrefs.setCharPref("capability.policy.default.XMLDocument.getElementsByTagName", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.CDATASection.nodeValue", "allAccess"); + + mozillaPrefs.setCharPref("capability.policy.default.HTMLCollection.length", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.HTMLCollection.item", "allAccess"); + + mozillaPrefs.setCharPref("capability.policy.default.*.nodeValue", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.*.nodeType", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.*.nodeName", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.*.nextSibling", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.*.previousSibling", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.*.attributes", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.*.childNodes", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.*.firstChild", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.*.getAttribute", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.*.getElementsByTagName", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.*.lastChild", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.*.parentNode", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.*.tagName", "allAccess"); + + mozillaPrefs.setCharPref("capability.policy.default.XMLDocument.documentElement", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.XMLDocument.getElementsByTagName", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.XMLHttpRequest.channel", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.XMLHttpRequest.open", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.XMLHttpRequest.responseText", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.XMLHttpRequest.responseXML", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.XMLHttpRequest.send", "allAccess"); + mozillaPrefs.setCharPref("capability.policy.default.XMLHttpRequest.setRequestHeader", "allAccess"); + /* to over-ride the internet security dialog when preview browser tries to access local hard drive */ + mozillaPrefs.setCharPref("capability.principal.codebase.p0.granted", "UniversalXPConnect UniversalBrowserRead"); + String location = "http://127.0.0.1:" + WebappManager.getPort(); + mozillaPrefs.setCharPref("capability.principal.codebase.p0.id", location); + mozillaPrefs.setBoolPref("security.fileuri.strict_origin_policy", 0); + } catch (Exception e) { + PreviewerPlugin.log("Error getting preferences", e); + } + } + + +} diff -r 5a2cfa9bc743 -r bb6160d0b6f2 org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewPage.java --- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewPage.java Wed Jan 27 17:54:14 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,301 +0,0 @@ -package org.symbian.tools.wrttools.previewer.preview; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.Collection; - -import org.eclipse.core.net.proxy.IProxyData; -import org.eclipse.core.net.proxy.IProxyService; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.browser.Browser; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.part.IPageBookViewPage; -import org.eclipse.ui.part.IPageSite; -import org.eclipse.ui.part.Page; -import org.mozilla.interfaces.nsIPrefBranch; -import org.mozilla.interfaces.nsIServiceManager; -import org.mozilla.xpcom.Mozilla; -import org.osgi.framework.Bundle; -import org.symbian.tools.wrttools.previewer.PreviewerPlugin; -import org.symbian.tools.wrttools.previewer.Images; -import org.symbian.tools.wrttools.previewer.http.WebAppInterface; -import org.symbian.tools.wrttools.previewer.http.WebappManager; - -public class PreviewPage extends Page implements IPageBookViewPage, ISelectionProvider { - private static final String XUL_RUNNER_PATH_PARAMETER = "org.eclipse.swt.browser.XULRunnerPath"; - private nsIPrefBranch mozillaPrefs; - - private final IAction refreshAction = new Action("Refresh") { - public void run() { - refresh(); - }; - }; - private final IAction toggleRefresh = new Action("Toggle Refresh", IAction.AS_RADIO_BUTTON) { - public void run() { - toggleRefresh(); - }; - }; - - private final IProject project; - private Browser browser; - private boolean toggleState = true; - private final PreviewView previewView; - private boolean needsRefresh = false; - - public PreviewPage(IProject project, PreviewView previewView) { - this.project = project; - this.previewView = previewView; - } - - protected void toggleRefresh() { - toggleState = !toggleState; - toggleRefresh.setChecked(toggleState); - previewView.setProjectAutorefresh(project, toggleState); - toggleRefresh.setToolTipText(getToggleActionTooltip()); - if (toggleState && needsRefresh) { - refresh(); - } - } - - private synchronized void initMozilla() { - if (System.getProperty(XUL_RUNNER_PATH_PARAMETER) == null) { - Bundle bundle = Platform.getBundle("org.mozilla.xulrunner"); //$NON-NLS-1$ - if (bundle != null) { - URL resourceUrl = bundle.getResource("xulrunner"); //$NON-NLS-1$ - if (resourceUrl != null) { - try { - URL fileUrl = FileLocator.toFileURL(resourceUrl); - File file = new File(fileUrl.toURI()); - System.setProperty(XUL_RUNNER_PATH_PARAMETER, file - .getAbsolutePath()); //$NON-NLS-1$ - } catch (IOException e) { - // log the exception - } catch (URISyntaxException e) { - // log the exception - } - } - } - } - } - - - @Override - public void createControl(Composite parent) { - initMozilla(); - browser = new Browser(parent, SWT.MOZILLA); - bypassSameOriginPolicy(); - applyProxySettings(); - browser.setUrl(getURI().toASCIIString()); - } - - private URI getURI() { - return PreviewerPlugin.getDefault().getHttpPreviewer().previewProject(project); - } - - @Override - public Control getControl() { - return browser; - } - - @Override - public void setFocus() { - browser.setFocus(); - } - - private boolean refreshScheduled = false; - - public synchronized void process(Collection files) { - if (!refreshScheduled && needsRefresh(files)) { - asyncExec(new Runnable() { - @Override - public void run() { - if (toggleState) { - refresh(); - } else { - needsRefresh = true; - refreshAction.setImageDescriptor(PreviewerPlugin.getImageDescriptor(Images.RED_SYNC)); - refreshAction.setToolTipText("Refresh the preview browser (there are updated files)"); - } - } - }); - refreshScheduled = true; - } - } - - private void asyncExec(Runnable runnable) { - getControl().getDisplay().asyncExec(runnable); - } - - private boolean needsRefresh(Collection files) { - for (IFile iFile : files) { - if (iFile.getProject().equals(project)) { - return true; - } - } - return false; - } - - protected synchronized void refresh() { - try { - final Control focusControl = browser.getDisplay().getFocusControl(); - browser.refresh(); - refreshAction.setImageDescriptor(PreviewerPlugin - .getImageDescriptor(Images.GREEN_SYNC)); - if (focusControl != null) { - asyncExec(new Runnable() { - @Override - public void run() { - focusControl.setFocus(); - } - }); - } - refreshAction.setToolTipText("Refresh the preview browser"); - needsRefresh = false; - } finally { - refreshScheduled = false; - } - } - - @Override - public void init(IPageSite pageSite) { - super.init(pageSite); - IToolBarManager toolBar = pageSite.getActionBars().getToolBarManager(); - refreshAction.setImageDescriptor(PreviewerPlugin.getImageDescriptor(Images.GREEN_SYNC)); - refreshAction.setToolTipText("Refresh the preview browser"); - toolBar.add(refreshAction); - - toggleState = previewView.getProjectAutorefresh(project); - - toggleRefresh.setImageDescriptor(PreviewerPlugin.getImageDescriptor(Images.YELLOW_SYNC)); - toggleRefresh.setToolTipText(getToggleActionTooltip()); - toggleRefresh.setChecked(toggleState); - toolBar.add(toggleRefresh); - - pageSite.getActionBars().setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction); - getSite().setSelectionProvider(this); - } - - private String getToggleActionTooltip() { - return toggleState ? "Disable preview autorefresh" : "Enable preview autorefresh"; - } - - @Override - public void addSelectionChangedListener(ISelectionChangedListener listener) { - // Do nothing - } - - @Override - public ISelection getSelection() { - return new StructuredSelection(project); - } - - @Override - public void removeSelectionChangedListener( - ISelectionChangedListener listener) { - // Do nothing - } - - @Override - public void setSelection(ISelection selection) { - // Do nothing - } - - private void applyProxySettings() { - IProxyService px = PreviewerPlugin.getDefault().getProxyService(); - if(px != null){ - boolean proxyEnabled = px.isProxiesEnabled(); - - boolean systemProxy = px.isSystemProxiesEnabled(); - if( proxyEnabled && !systemProxy){ - IProxyData pd = px.getProxyData(IProxyData.HTTP_PROXY_TYPE); - if (pd !=null &&mozillaPrefs != null) { - String host= pd.getHost(); - int port = pd.getPort(); - if(host !=null && port != -1){ - mozillaPrefs.setIntPref("network.proxy.type", 1); - mozillaPrefs.setCharPref("network.proxy.http", host); - mozillaPrefs.setIntPref("network.proxy.http_port", port); - } - } - } - } - else{ - Exception e= new Exception(); - PreviewerPlugin.log("Proxy service returned null", e); - } - } - - private void bypassSameOriginPolicy() { - WebAppInterface.getInstance(); - try{ - nsIServiceManager servMgr = null; - try { - servMgr = Mozilla.getInstance().getServiceManager(); - if (servMgr == null) return; - } catch (Exception x) { - // known to throw NullPointException on Mac OS when you're not using - // Mozilla. We don't want to pollute the error log with this - return; - } - - mozillaPrefs = (nsIPrefBranch) servMgr.getServiceByContractID( - "@mozilla.org/preferences-service;1", - nsIPrefBranch.NS_IPREFBRANCH_IID ); - - mozillaPrefs.setBoolPref("signed.applets.codebase_principal_support", 1); - - mozillaPrefs.setCharPref("capability.policy.default.XMLDocument.getElementsByTagName", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.CDATASection.nodeValue", "allAccess"); - - mozillaPrefs.setCharPref("capability.policy.default.HTMLCollection.length", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.HTMLCollection.item", "allAccess"); - - mozillaPrefs.setCharPref("capability.policy.default.*.nodeValue", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.*.nodeType", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.*.nodeName", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.*.nextSibling", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.*.previousSibling", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.*.attributes", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.*.childNodes", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.*.firstChild", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.*.getAttribute", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.*.getElementsByTagName", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.*.lastChild", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.*.parentNode", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.*.tagName", "allAccess"); - - mozillaPrefs.setCharPref("capability.policy.default.XMLDocument.documentElement", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.XMLDocument.getElementsByTagName", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.XMLHttpRequest.channel", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.XMLHttpRequest.open", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.XMLHttpRequest.responseText", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.XMLHttpRequest.responseXML", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.XMLHttpRequest.send", "allAccess"); - mozillaPrefs.setCharPref("capability.policy.default.XMLHttpRequest.setRequestHeader", "allAccess"); - /* to over-ride the internet security dialog when preview browser tries to access local hard drive */ - mozillaPrefs.setCharPref("capability.principal.codebase.p0.granted", "UniversalXPConnect UniversalBrowserRead"); - String location = "http://127.0.0.1:" + WebappManager.getPort(); - mozillaPrefs.setCharPref("capability.principal.codebase.p0.id", location); - mozillaPrefs.setBoolPref("security.fileuri.strict_origin_policy", 0); - } catch (Exception e) { - PreviewerPlugin.log("Error getting preferences", e); - } - } - -} diff -r 5a2cfa9bc743 -r bb6160d0b6f2 org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewView.java --- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewView.java Wed Jan 27 17:54:14 2010 -0800 +++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewView.java Thu Jan 28 10:18:04 2010 -0800 @@ -24,6 +24,7 @@ import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jface.preference.IPreferenceStore; @@ -36,6 +37,7 @@ import org.eclipse.ui.part.PageBookView; import org.symbian.tools.wrttools.previewer.PreviewerPlugin; import org.symbian.tools.wrttools.previewer.IWrtEditingPreferences; +import org.symbian.tools.wrttools.util.CoreUtil; import org.symbian.tools.wrttools.util.ProjectUtils; public class PreviewView extends PageBookView { @@ -71,7 +73,7 @@ } }; - private Map projectToPage = new HashMap(); + private Map projectToPage = new HashMap(); private boolean preferencesLoaded = false; private final Map autorefresh = new HashMap(); @@ -105,10 +107,10 @@ .getAdapter(IResource.class); IProject project = resource.getProject(); - PreviewPage page = projectToPage.get(project); + IPreviewPage page = projectToPage.get(project); if (page == null) { - page = new PreviewPage(project, this); + page = createPreviewPage(project); initPage(page); page.createControl(getPageBook()); projectToPage.put(project, page); @@ -117,6 +119,14 @@ return new PageRec(part, page); } + private IPreviewPage createPreviewPage(IProject project) { + if (!CoreUtil.isMac() && Platform.getBundle(MozillaPreviewPage.XUL_RUNNER_BUNDLE) != null) { + return new MozillaPreviewPage(project, this); + } else { + return new SwtBrowserPreviewPage(project, this); + } + } + @Override protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) { // We do not need to delete the page @@ -221,8 +231,8 @@ } protected void refreshPages(Collection files) { - Collection values = projectToPage.values(); - for (PreviewPage page : values) { + Collection values = projectToPage.values(); + for (IPreviewPage page : values) { page.process(files); } } diff -r 5a2cfa9bc743 -r bb6160d0b6f2 org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/SwtBrowserPreviewPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/SwtBrowserPreviewPage.java Thu Jan 28 10:18:04 2010 -0800 @@ -0,0 +1,20 @@ +package org.symbian.tools.wrttools.previewer.preview; + +import org.eclipse.core.resources.IProject; +import org.eclipse.swt.SWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.widgets.Composite; + +public class SwtBrowserPreviewPage extends AbstractPreviewPage implements + IPreviewPage { + + public SwtBrowserPreviewPage(IProject project, PreviewView previewView) { + super(project, previewView); + } + + @Override + protected Browser createBrowser(Composite parent) { + return new Browser(parent, SWT.NONE); + } + +} diff -r 5a2cfa9bc743 -r bb6160d0b6f2 org.symbian.tools.wrttools.product/launch/WRT IDE (Product).launch --- a/org.symbian.tools.wrttools.product/launch/WRT IDE (Product).launch Wed Jan 27 17:54:14 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r 5a2cfa9bc743 -r bb6160d0b6f2 org.symbian.tools.wrttools.product/launch/WRT IDE Product (Mac OS X).launch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools.product/launch/WRT IDE Product (Mac OS X).launch Thu Jan 28 10:18:04 2010 -0800 @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 5a2cfa9bc743 -r bb6160d0b6f2 org.symbian.tools.wrttools.product/launch/WRT IDE Product (Windows).launch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools.product/launch/WRT IDE Product (Windows).launch Thu Jan 28 10:18:04 2010 -0800 @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 5a2cfa9bc743 -r bb6160d0b6f2 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/CoreUtil.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/CoreUtil.java Thu Jan 28 10:18:04 2010 -0800 @@ -0,0 +1,18 @@ +package org.symbian.tools.wrttools.util; + +import org.eclipse.core.runtime.Platform; + +public class CoreUtil { + + public static boolean isWindows() { + return "windows".equals(Platform.getOS()); + } + + public static boolean isMac() { + return "macosx".equals(Platform.getOS()); + } + + public static boolean isLinux() { + return "linux".equals(Platform.getOS()); + } +}