diff --git a/platform/built-in-server/src/org/jetbrains/builtInWebServer/BuiltInWebBrowserUrlProvider.java b/platform/built-in-server/src/org/jetbrains/builtInWebServer/BuiltInWebBrowserUrlProvider.java index 97c561c0e086..61e5db5ca9c3 100644 --- a/platform/built-in-server/src/org/jetbrains/builtInWebServer/BuiltInWebBrowserUrlProvider.java +++ b/platform/built-in-server/src/org/jetbrains/builtInWebServer/BuiltInWebBrowserUrlProvider.java @@ -18,7 +18,6 @@ package org.jetbrains.builtInWebServer; import com.intellij.ide.browsers.OpenInBrowserRequest; import com.intellij.ide.browsers.WebBrowserService; import com.intellij.ide.browsers.WebBrowserUrlProvider; -import com.intellij.ide.util.PropertiesComponent; import com.intellij.lang.Language; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; @@ -70,11 +69,7 @@ public class BuiltInWebBrowserUrlProvider extends WebBrowserUrlProvider implemen urls.add(Urls.newHttpUrl(defaultAuthority, '/' + project.getName() + '/' + path2, query)); } } - - if (BuiltInWebServerKt.isActivatable()) { - PropertiesComponent.getInstance().setValue("ide.built.in.web.server.active", true); - } - + return urls; } diff --git a/xml/impl/src/com/intellij/ide/browsers/BrowserLauncherImpl.java b/xml/impl/src/com/intellij/ide/browsers/BrowserLauncherImpl.java index 65da7b30722c..7a62abe0b33f 100644 --- a/xml/impl/src/com/intellij/ide/browsers/BrowserLauncherImpl.java +++ b/xml/impl/src/com/intellij/ide/browsers/BrowserLauncherImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,22 +20,80 @@ import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.execution.util.ExecUtil; import com.intellij.ide.GeneralSettings; import com.intellij.ide.IdeBundle; +import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.AppUIUtil; import com.intellij.util.ArrayUtil; +import com.intellij.util.Url; +import com.intellij.util.Urls; +import com.intellij.util.net.NetUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.builtInWebServer.BuiltInServerOptions; +import org.jetbrains.ide.BuiltInServerManager; +import java.net.InetAddress; import java.net.URI; +import java.net.UnknownHostException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -final class BrowserLauncherImpl extends BrowserLauncherAppless { +public final class BrowserLauncherImpl extends BrowserLauncherAppless { + @Override + public void browse(@NotNull String url, @Nullable WebBrowser browser, @Nullable Project project) { + if (Registry.is("ide.built.in.web.server.activatable", false)) { + Url parsedUrl = Urls.parse(url, false); + if (parsedUrl != null && parsedUrl.getAuthority() != null && isOnBuiltInWebServerByAuthority(parsedUrl.getAuthority())) { + PropertiesComponent.getInstance().setValue("ide.built.in.web.server.active", true); + } + } + + super.browse(url, browser, project); + } + + public static boolean isOnBuiltInWebServerByAuthority(@NotNull String authority) { + int portIndex = authority.indexOf(':'); + if (portIndex < 0 || portIndex == authority.length() - 1) { + return false; + } + + int port; + try { + port = Integer.parseInt(authority.substring(portIndex + 1)); + } + catch (NumberFormatException ignored) { + return false; + } + + if (BuiltInServerOptions.getInstance().builtInServerPort != port && BuiltInServerManager.getInstance().getPort() != port) { + return false; + } + + String host = authority.substring(0, portIndex); + if (NetUtils.isLocalhost(host)) { + return true; + } + + InetAddress inetAddress; + try { + inetAddress = InetAddress.getByName(host); + } + catch (UnknownHostException ignored) { + return false; + } + + if (inetAddress == null) { + return false; + } + return inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress(); + } + @Override protected void browseUsingNotSystemDefaultBrowserPolicy(@NotNull URI uri, @NotNull GeneralSettings settings, @Nullable Project project) { WebBrowserManager browserManager = WebBrowserManager.getInstance(); diff --git a/xml/impl/xml.iml b/xml/impl/xml.iml index 2fb3ee7ea262..fb6c556fefcf 100644 --- a/xml/impl/xml.iml +++ b/xml/impl/xml.iml @@ -23,11 +23,11 @@ + - - + \ No newline at end of file