From 4717f5373a55cd2403ff2f574cf0c7d6f2bdc6d2 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 10 Sep 2012 17:30:45 +0400 Subject: [PATCH] IDEA-91258 --- .../src/com/intellij/ide/BrowserUtil.java | 18 ------ .../ide/browsers/BrowsersConfiguration.java | 8 +-- .../ide/browsers/chrome/ChromeSettings.java | 38 +------------ .../chrome/ChromeSettingsConfigurable.form | 20 +------ .../chrome/ChromeSettingsConfigurable.java | 26 +-------- .../ide/browsers/impl/UrlOpenerImpl.java | 57 +++++++++++-------- 6 files changed, 39 insertions(+), 128 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ide/BrowserUtil.java b/platform/platform-api/src/com/intellij/ide/BrowserUtil.java index 143736b1788b..9b383ab1e219 100644 --- a/platform/platform-api/src/com/intellij/ide/BrowserUtil.java +++ b/platform/platform-api/src/com/intellij/ide/BrowserUtil.java @@ -227,24 +227,6 @@ public class BrowserUtil { return command; } - public static void addLaunchArgs(List command, String[] launchArgs) { - if (launchArgs.length == 0) { - return; - } - - if (SystemInfo.isMac && ExecUtil.getOpenCommandPath().equals(command.get(0))) { - if (isOpenCommandSupportArgs()) { - command.add("--args"); - } - else { - LOG.warn("'open' command doesn't allow to pass command line arguments so they will be ignored: " + Arrays.toString(launchArgs)); - return; - } - } - - Collections.addAll(command, launchArgs); - } - public static List getOpenBrowserCommand(final @NonNls @NotNull String browserPath) { if (SystemInfo.isMac && !new File(browserPath).isFile()) { ArrayList command = new ArrayList(); diff --git a/xml/impl/src/com/intellij/ide/browsers/BrowsersConfiguration.java b/xml/impl/src/com/intellij/ide/browsers/BrowsersConfiguration.java index 4cdc0bd04d9e..b103b3e144ec 100644 --- a/xml/impl/src/com/intellij/ide/browsers/BrowsersConfiguration.java +++ b/xml/impl/src/com/intellij/ide/browsers/BrowsersConfiguration.java @@ -25,7 +25,6 @@ import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Conditions; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.SystemProperties; import com.intellij.util.containers.HashMap; import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters; @@ -215,7 +214,7 @@ public class BrowsersConfiguration implements PersistentStateComponent } public static void launchBrowser(final @NotNull BrowserFamily family, - @NotNull final String url, + @Nullable final String url, final boolean forceOpenNewInstanceOnMac, String... parameters) { UrlOpenerImpl.doLaunchBrowser(family, url, parameters, Conditions.alwaysTrue(), forceOpenNewInstanceOnMac); @@ -229,11 +228,6 @@ public class BrowsersConfiguration implements PersistentStateComponent UrlOpenerImpl.doLaunchBrowser(family, url, parameters, browserSpecificParametersFilter, forceOpenNewInstanceOnMac); } - @Nullable - public static String checkPath(BrowserFamily family, String path) { - return StringUtil.isEmpty(path) ? XmlBundle.message("browser.path.not.specified", family.getName()) : null; - } - @Nullable public static BrowserFamily findFamilyByName(@Nullable String name) { for (BrowserFamily family : BrowserFamily.values()) { diff --git a/xml/impl/src/com/intellij/ide/browsers/chrome/ChromeSettings.java b/xml/impl/src/com/intellij/ide/browsers/chrome/ChromeSettings.java index 8f7b70d539ca..81f90446f820 100644 --- a/xml/impl/src/com/intellij/ide/browsers/chrome/ChromeSettings.java +++ b/xml/impl/src/com/intellij/ide/browsers/chrome/ChromeSettings.java @@ -28,14 +28,10 @@ import org.jetbrains.annotations.Nullable; * @author nik */ public class ChromeSettings extends BrowserSpecificSettings { - @NonNls public static final String REMOTE_DEBUGGING_PORT_ARG = "--remote-debugging-port="; @NonNls public static final String USER_DATA_DIR_ARG = "--user-data-dir="; - public static final int DEFAULT_REMOTE_SHELL_PORT = 7930; private String myCommandLineOptions = ""; private String myUserDataDirectoryPath; private boolean myUseCustomProfile; - private boolean myEnableRemoteDebug; - private int myRemoteShellPort = DEFAULT_REMOTE_SHELL_PORT; public ChromeSettings() { } @@ -51,16 +47,6 @@ public class ChromeSettings extends BrowserSpecificSettings { return myUseCustomProfile; } - @Tag("enable-remote-debug") - public boolean isEnableRemoteDebug() { - return myEnableRemoteDebug; - } - - @Tag("remote-shell-port") - public int getRemoteShellPort() { - return myRemoteShellPort; - } - @Tag("command-line-options") public String getCommandLineOptions() { return myCommandLineOptions; @@ -70,14 +56,6 @@ public class ChromeSettings extends BrowserSpecificSettings { myCommandLineOptions = commandLineOptions; } - public void setEnableRemoteDebug(boolean enableRemoteDebug) { - myEnableRemoteDebug = enableRemoteDebug; - } - - public void setRemoteShellPort(int remoteShellPort) { - myRemoteShellPort = remoteShellPort; - } - public void setUserDataDirectoryPath(String userDataDirectoryPath) { myUserDataDirectoryPath = userDataDirectoryPath; } @@ -89,23 +67,13 @@ public class ChromeSettings extends BrowserSpecificSettings { @NotNull @Override public String[] getAdditionalParameters() { - String[] customProfileArg; + String[] cliOptions = ParametersList.parse(myCommandLineOptions); if (myUseCustomProfile && myUserDataDirectoryPath != null) { - customProfileArg = new String[]{USER_DATA_DIR_ARG + FileUtil.toSystemDependentName(myUserDataDirectoryPath)}; + return ArrayUtil.mergeArrays(cliOptions, USER_DATA_DIR_ARG + FileUtil.toSystemDependentName(myUserDataDirectoryPath)); } else { - customProfileArg = ArrayUtil.EMPTY_STRING_ARRAY; + return cliOptions; } - - String[] remoteShellArg; - if (myEnableRemoteDebug) { - remoteShellArg = new String[]{REMOTE_DEBUGGING_PORT_ARG + myRemoteShellPort}; - } - else { - remoteShellArg = ArrayUtil.EMPTY_STRING_ARRAY; - } - - return ArrayUtil.mergeArrays(ParametersList.parse(myCommandLineOptions), ArrayUtil.mergeArrays(customProfileArg, remoteShellArg)); } @Override diff --git a/xml/impl/src/com/intellij/ide/browsers/chrome/ChromeSettingsConfigurable.form b/xml/impl/src/com/intellij/ide/browsers/chrome/ChromeSettingsConfigurable.form index f3013409e001..12051d9b93a4 100644 --- a/xml/impl/src/com/intellij/ide/browsers/chrome/ChromeSettingsConfigurable.form +++ b/xml/impl/src/com/intellij/ide/browsers/chrome/ChromeSettingsConfigurable.form @@ -1,6 +1,6 @@
- + @@ -18,7 +18,7 @@ - + @@ -29,22 +29,6 @@ - - - - - - - - - - - - - - - - diff --git a/xml/impl/src/com/intellij/ide/browsers/chrome/ChromeSettingsConfigurable.java b/xml/impl/src/com/intellij/ide/browsers/chrome/ChromeSettingsConfigurable.java index adec612ba7e7..9e8b681b1b1d 100644 --- a/xml/impl/src/com/intellij/ide/browsers/chrome/ChromeSettingsConfigurable.java +++ b/xml/impl/src/com/intellij/ide/browsers/chrome/ChromeSettingsConfigurable.java @@ -39,8 +39,6 @@ public class ChromeSettingsConfigurable implements Configurable { private JPanel myMainPanel; private JCheckBox myUseCustomProfileCheckBox; private TextFieldWithBrowseButton myUserDataDirField; - private JCheckBox myEnableRemoteDebugCheckBox; - private JTextField myPortField; private JLabel myCommandLineOptionsLabel; private RawCommandLineEditor myCommandLineOptionsEditor; private final String myDefaultUserDirPath; @@ -56,12 +54,6 @@ public class ChromeSettingsConfigurable implements Configurable { } }); myDefaultUserDirPath = getDefaultUserDataPath(); - myEnableRemoteDebugCheckBox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - myPortField.setEnabled(myEnableRemoteDebugCheckBox.isSelected()); - } - }); myCommandLineOptionsEditor.setDialogCaption("Chrome Command Line Options"); myCommandLineOptionsLabel.setLabelFor(myCommandLineOptionsEditor.getTextField()); } @@ -73,9 +65,7 @@ public class ChromeSettingsConfigurable implements Configurable { @Override public boolean isModified() { - if (myEnableRemoteDebugCheckBox.isSelected() != mySettings.isEnableRemoteDebug() - || !myPortField.getText().equals(String.valueOf(mySettings.getRemoteShellPort())) - || myUseCustomProfileCheckBox.isSelected() != mySettings.isUseCustomProfile() + if (myUseCustomProfileCheckBox.isSelected() != mySettings.isUseCustomProfile() || !myCommandLineOptionsEditor.getText().equals(mySettings.getCommandLineOptions())) { return true; } @@ -93,24 +83,13 @@ public class ChromeSettingsConfigurable implements Configurable { @Override public void apply() throws ConfigurationException { - try { - mySettings.setRemoteShellPort(Integer.parseInt(myPortField.getText())); - } - catch (NumberFormatException ignored) { - throw new ConfigurationException("Port is not integer!"); - } mySettings.setCommandLineOptions(myCommandLineOptionsEditor.getText()); mySettings.setUseCustomProfile(myUseCustomProfileCheckBox.isSelected()); mySettings.setUserDataDirectoryPath(getConfiguredUserDataDirPath()); - mySettings.setEnableRemoteDebug(myEnableRemoteDebugCheckBox.isSelected()); } @Override public void reset() { - myEnableRemoteDebugCheckBox.setSelected(mySettings.isEnableRemoteDebug()); - myPortField.setText(String.valueOf(mySettings.getRemoteShellPort())); - myPortField.setEnabled(mySettings.isEnableRemoteDebug()); - myCommandLineOptionsEditor.setText(mySettings.getCommandLineOptions()); myUseCustomProfileCheckBox.setSelected(mySettings.isUseCustomProfile()); myUserDataDirField.setEnabled(mySettings.isUseCustomProfile()); @@ -127,9 +106,6 @@ public class ChromeSettingsConfigurable implements Configurable { if (!myUseCustomProfileCheckBox.isSelected()) { myUseCustomProfileCheckBox.doClick(0); } - if (!myEnableRemoteDebugCheckBox.isSelected()) { - myEnableRemoteDebugCheckBox.doClick(0); - } } private static String getDefaultUserDataPath() { diff --git a/xml/impl/src/com/intellij/ide/browsers/impl/UrlOpenerImpl.java b/xml/impl/src/com/intellij/ide/browsers/impl/UrlOpenerImpl.java index c885b8693279..ad9b1b60c6df 100644 --- a/xml/impl/src/com/intellij/ide/browsers/impl/UrlOpenerImpl.java +++ b/xml/impl/src/com/intellij/ide/browsers/impl/UrlOpenerImpl.java @@ -31,6 +31,7 @@ import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; import com.intellij.xml.XmlBundle; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.ArrayList; @@ -47,39 +48,48 @@ public class UrlOpenerImpl extends UrlOpener { } public static void doLaunchBrowser(final BrowsersConfiguration.BrowserFamily family, - @NotNull String url, + @Nullable String url, @NotNull String[] additionalParameters, @NotNull Condition browserSpecificParametersFilter, final boolean forceOpenNewInstanceOnMac) { final WebBrowserSettings settings = BrowsersConfiguration.getInstance().getBrowserSettings(family); final String path = settings.getPath(); - String pathCheckResult = BrowsersConfiguration.checkPath(family, path); - if (pathCheckResult == null) { - try { - BrowserSpecificSettings specificSettings = settings.getBrowserSpecificSettings(); - List parameters = specificSettings == null - ? (additionalParameters.length == 0 ? Collections.emptyList() : new ArrayList()) - : ContainerUtil.findAll(specificSettings.getAdditionalParameters(), browserSpecificParametersFilter); - Collections.addAll(parameters, additionalParameters); - launchBrowser(path, BrowserUtil.escapeUrl(url), forceOpenNewInstanceOnMac, parameters); - } - catch (IOException e) { - Messages.showErrorDialog(e.getMessage(), XmlBundle.message("browser.error")); - } + if (StringUtil.isEmpty(path)) { + Messages.showErrorDialog(XmlBundle.message("browser.path.not.specified", family.getName()), XmlBundle.message("browser.path.not.specified.title")); + return; } - else { - Messages.showErrorDialog(pathCheckResult, XmlBundle.message("browser.path.not.specified.title")); + + try { + BrowserSpecificSettings specificSettings = settings.getBrowserSpecificSettings(); + List parameters = specificSettings == null + ? (additionalParameters.length == 0 ? Collections.emptyList() : new ArrayList()) + : ContainerUtil.findAll(specificSettings.getAdditionalParameters(), browserSpecificParametersFilter); + Collections.addAll(parameters, additionalParameters); + launchBrowser(path, url == null ? null : BrowserUtil.escapeUrl(url), forceOpenNewInstanceOnMac, parameters); + } + catch (IOException e) { + Messages.showErrorDialog(e.getMessage(), XmlBundle.message("browser.error")); } } - private static void launchBrowser(String browserPath, String url, boolean forceOpenNewInstanceOnMac, List browserArgs) + private static void launchBrowser(String browserPath, @Nullable String url, boolean forceOpenNewInstanceOnMac, List browserArgs) throws IOException { - final List command = BrowserUtil.getOpenBrowserCommand(browserPath); + List command = BrowserUtil.getOpenBrowserCommand(browserPath); + addArgs(command, browserArgs, url, forceOpenNewInstanceOnMac); + if (LOG.isDebugEnabled()) { + LOG.debug("Launching browser: " + StringUtil.join(browserArgs, " ")); + } + new ProcessBuilder(command).start(); + } + + private static void addArgs(List command, List browserArgs, @Nullable String url, boolean forceOpenNewInstanceOnMac) { if (SystemInfo.isMac && ExecUtil.getOpenCommandPath().equals(command.get(0))) { if (forceOpenNewInstanceOnMac) { command.add("-n"); } - command.add(url); + if (url != null) { + command.add(url); + } if (!browserArgs.isEmpty()) { if (BrowserUtil.isOpenCommandSupportArgs()) { @@ -93,13 +103,10 @@ public class UrlOpenerImpl extends UrlOpener { } } else { - command.add(url); + if (url != null) { + command.add(url); + } command.addAll(browserArgs); } - - if (LOG.isDebugEnabled()) { - LOG.debug("Launching browser: " + StringUtil.join(browserArgs, " ")); - } - new ProcessBuilder(command).start(); } }