OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 | 14 |
15 package com.google.dart.tools.debug.ui.internal; | 15 package com.google.dart.tools.debug.ui.internal; |
16 | 16 |
| 17 import com.google.dart.tools.core.DartCore; |
17 import com.google.dart.tools.debug.core.DartDebugCorePlugin; | 18 import com.google.dart.tools.debug.core.DartDebugCorePlugin; |
18 import com.google.dart.tools.debug.core.IUserAgentManager; | 19 import com.google.dart.tools.debug.core.IUserAgentManager; |
19 | 20 |
20 import org.eclipse.jface.dialogs.IDialogConstants; | 21 import org.eclipse.jface.dialogs.IDialogConstants; |
21 import org.eclipse.jface.dialogs.MessageDialog; | 22 import org.eclipse.jface.dialogs.MessageDialog; |
22 import org.eclipse.swt.widgets.Display; | 23 import org.eclipse.swt.widgets.Display; |
23 import org.eclipse.swt.widgets.Shell; | 24 import org.eclipse.swt.widgets.Shell; |
24 import org.eclipse.ui.PlatformUI; | 25 import org.eclipse.ui.PlatformUI; |
25 | 26 |
26 import java.io.BufferedReader; | 27 import java.io.BufferedReader; |
(...skipping 11 matching lines...) Expand all Loading... |
38 * server. | 39 * server. |
39 */ | 40 */ |
40 public class DartDebugUserAgentManager implements IUserAgentManager { | 41 public class DartDebugUserAgentManager implements IUserAgentManager { |
41 | 42 |
42 private static class AgentData { | 43 private static class AgentData { |
43 String address; | 44 String address; |
44 String agentName; | 45 String agentName; |
45 boolean allowed; | 46 boolean allowed; |
46 } | 47 } |
47 | 48 |
48 private static boolean dialogOpen = false; | |
49 | |
50 static void install() { | 49 static void install() { |
51 DartDebugCorePlugin.getPlugin().setUserAgentManager(new DartDebugUserAgentMa
nager()); | 50 DartDebugCorePlugin.getPlugin().setUserAgentManager(new DartDebugUserAgentMa
nager()); |
52 } | 51 } |
53 | 52 |
54 private List<AgentData> agents = new ArrayList<AgentData>(); | 53 private List<AgentData> agents = new ArrayList<AgentData>(); |
55 | 54 |
56 private DartDebugUserAgentManager() { | 55 private DartDebugUserAgentManager() { |
57 loadSettings(); | 56 loadSettings(); |
58 } | 57 } |
59 | 58 |
60 @Override | 59 @Override |
61 public boolean allowUserAgent(InetAddress remoteAddress, String agentName) { | 60 public boolean allowUserAgent(InetAddress remoteAddress, String agentName) { |
62 // This handles things like port scanners, which can cause the editor to ope
n a lot of popups. | 61 // This handles things like port scanners, which can cause the editor to ope
n a lot of popups. |
63 if (agentName == null) { | 62 if (agentName == null) { |
64 return false; | 63 return false; |
65 } | 64 } |
66 | 65 |
67 // check if it's an existing agent | 66 // check if it's an existing agent |
68 if (isKnownAgent(remoteAddress.getHostAddress(), agentName)) { | 67 if (isKnownAgent(remoteAddress, agentName)) { |
69 return agentAllowed(remoteAddress, agentName); | 68 return agentAllowed(remoteAddress, agentName); |
70 } | 69 } |
71 | 70 |
72 // ask the user | 71 // ask the user |
73 if (dialogOpen) { | 72 if (DartCore.allowConnectionDialogOpen) { |
74 return false; | 73 return false; |
75 } | 74 } |
76 | 75 |
77 dialogOpen = true; | 76 DartCore.allowConnectionDialogOpen = true; |
78 boolean allowConnection = askUserAllows(remoteAddress, agentName); | 77 boolean allowConnection = askUserAllows(remoteAddress, agentName); |
79 | 78 |
| 79 addAgentData(remoteAddress, agentName, allowConnection); |
| 80 |
| 81 DartCore.allowConnectionDialogOpen = false; |
| 82 return allowConnection; |
| 83 |
| 84 } |
| 85 |
| 86 private void addAgentData(InetAddress remoteAddress, String agentName, boolean
allowConnection) { |
80 AgentData data = new AgentData(); | 87 AgentData data = new AgentData(); |
81 | 88 |
82 data.address = remoteAddress.getHostAddress(); | 89 data.address = remoteAddress.getHostAddress(); |
83 data.agentName = agentName; | 90 data.agentName = agentName; |
84 data.allowed = allowConnection; | 91 data.allowed = allowConnection; |
85 agents.add(data); | 92 agents.add(data); |
86 saveSettings(); | 93 saveSettings(); |
87 | |
88 dialogOpen = false; | |
89 return allowConnection; | |
90 | |
91 } | 94 } |
92 | 95 |
93 private boolean agentAllowed(InetAddress remoteAddress, String agent) { | 96 private boolean agentAllowed(InetAddress remoteAddress, String agent) { |
94 if (agent == null) { | 97 if (agent == null) { |
95 return false; | 98 return false; |
96 } | 99 } |
97 | 100 |
98 String address = remoteAddress.getHostAddress(); | 101 String address = remoteAddress.getHostAddress(); |
99 | 102 |
100 for (AgentData data : agents) { | 103 for (AgentData data : agents) { |
(...skipping 30 matching lines...) Expand all Loading... |
131 } | 134 } |
132 }); | 135 }); |
133 | 136 |
134 return result[0]; | 137 return result[0]; |
135 } | 138 } |
136 | 139 |
137 private File getDataFile() { | 140 private File getDataFile() { |
138 return DartDebugUIPlugin.getDefault().getStateLocation().append("agentdata.t
xt").toFile(); | 141 return DartDebugUIPlugin.getDefault().getStateLocation().append("agentdata.t
xt").toFile(); |
139 } | 142 } |
140 | 143 |
141 private boolean isKnownAgent(String address, String agent) { | 144 private boolean isKnownAgent(InetAddress remoteAddress, String agent) { |
| 145 String remoteAddressString = remoteAddress.getHostAddress(); |
142 for (AgentData data : agents) { | 146 for (AgentData data : agents) { |
143 if (address.equals(data.address) && agent.equals(data.agentName)) { | 147 if (remoteAddressString.equals(data.address) && agent.equals(data.agentNam
e)) { |
144 return true; | 148 return true; |
145 } | 149 } |
146 } | 150 } |
| 151 if (agent.equals("com.google.dart.editor.mobile.connection.service")) { |
| 152 for (AgentData data : agents) { |
| 153 if (remoteAddressString.equals(data.address)) { |
| 154 addAgentData(remoteAddress, agent, true); |
| 155 return true; |
| 156 } |
| 157 } |
| 158 } |
147 return false; | 159 return false; |
148 } | 160 } |
149 | 161 |
150 private void loadSettings() { | 162 private void loadSettings() { |
151 File file = getDataFile(); | 163 File file = getDataFile(); |
152 | 164 |
153 if (file.exists()) { | 165 if (file.exists()) { |
154 try { | 166 try { |
155 BufferedReader reader = new BufferedReader(new FileReader(file)); | 167 BufferedReader reader = new BufferedReader(new FileReader(file)); |
156 | 168 |
(...skipping 30 matching lines...) Expand all Loading... |
187 out.println(data.allowed); | 199 out.println(data.allowed); |
188 } | 200 } |
189 | 201 |
190 out.close(); | 202 out.close(); |
191 } catch (IOException ioe) { | 203 } catch (IOException ioe) { |
192 DartUtil.logError(ioe); | 204 DartUtil.logError(ioe); |
193 } | 205 } |
194 } | 206 } |
195 | 207 |
196 } | 208 } |
OLD | NEW |