Chromium Code Reviews| Index: lib/uri/uri.dart |
| diff --git a/lib/uri/uri.dart b/lib/uri/uri.dart |
| index ad396eb74d601a970d140a396e406de93ba636b7..965f691d320d2e1faffac4c80c0d17b7871ee03c 100644 |
| --- a/lib/uri/uri.dart |
| +++ b/lib/uri/uri.dart |
| @@ -167,6 +167,38 @@ class Uri { |
| return (userInfo != "") || (domain != "") || (port != 0); |
| } |
| + /** |
| + * Returns URI's origin: scheme://domain:port for http/https schemes |
|
ahe
2012/08/21 20:36:28
Comments should be proper sentences. That is, they
|
| + * Throws IllegalArgumentException for all other schemes |
|
ahe
2012/08/21 20:36:28
Not sure if you want a period or comma on the prev
|
| + * See (http://www.w3.org/TR/2011/WD-html5-20110405/origin-0.html#origin) |
|
ahe
2012/08/21 20:36:28
There is an example on lines 13-15 for how to incl
|
| + */ |
| + String get origin() { |
| + if (scheme == "") { |
| + // TODO(aprelev@gmail.com): Use StateException instead |
| + throw new IllegalArgumentException("Cannot use origin without a scheme"); |
| + } |
| + if (scheme != "http" && scheme != "https") { |
| + // TODO(aprelev@gmail.com): Use StateException instead |
| + throw new IllegalArgumentException( |
| + "origin is applicable to http/https schemes only. Not \'$scheme\'"); |
| + } |
| + StringBuffer sb = new StringBuffer(); |
| + sb.add(scheme); |
| + sb.add(":"); |
| + if (domain == null || domain == "") { |
| + // TODO(aprelev@gmail.com): Use StateException instead |
| + throw new IllegalArgumentException("Cannot use origin without a domain"); |
| + } |
| + |
| + sb.add("//"); |
| + sb.add(domain); |
| + if (port != 0) { |
| + sb.add(":"); |
| + sb.add(port.toString()); |
|
ahe
2012/08/21 20:36:28
I believe toString is no longer necessary.
|
| + } |
| + return sb.toString(); |
| + } |
| + |
| String toString() { |
| StringBuffer sb = new StringBuffer(); |
| _addIfNonEmpty(sb, scheme, scheme, ':'); |