(text)
| 173 | } |
| 174 | |
| 175 | function tryNavigate(text) { |
| 176 | try { |
| 177 | var uriParser = new URL(text); |
| 178 | |
| 179 | // URL creation succeeded, verify protocol is allowed |
| 180 | switch (uriParser.protocol) { |
| 181 | case 'http:': |
| 182 | case 'https:': |
| 183 | case 'file:': |
| 184 | case 'ftp:': |
| 185 | // Allowed protocol, navigate |
| 186 | navigateActiveTab(uriParser.href, false); |
| 187 | break; |
| 188 | default: |
| 189 | // Protocol not allowed, search Bing |
| 190 | navigateActiveTab(getSearchURI(text), true); |
| 191 | break; |
| 192 | } |
| 193 | } catch (e) { |
| 194 | // URL creation failed, check for invalid characters |
| 195 | if (containsIlegalCharacters(text) || isSingleWord(text)) { |
| 196 | // Search Bing |
| 197 | navigateActiveTab(getSearchURI(text), true); |
| 198 | } else { |
| 199 | // Try with HTTP |
| 200 | if (!hasScheme(text)) { |
| 201 | tryNavigate(`http:${text}`); |
| 202 | } else { |
| 203 | navigateActiveTab(getSearchURI(text), true); |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | function navigateActiveTab(uri, isSearch) { |
| 210 | var message = { |
no test coverage detected