Chromium Code Reviews| Index: lib/uri/uri.dart |
| diff --git a/lib/uri/uri.dart b/lib/uri/uri.dart |
| index ad396eb74d601a970d140a396e406de93ba636b7..3a4f0d6fc6b1aab34a7b5f4f35fcddf72026cacd 100644 |
| --- a/lib/uri/uri.dart |
| +++ b/lib/uri/uri.dart |
| @@ -167,6 +167,29 @@ class Uri { |
| return (userInfo != "") || (domain != "") || (port != 0); |
| } |
| + /** |
| + * Returns URI's origin: scheme://domain:port for http/https schemes |
| + * Throws IllegalArgumentException for all other schemes |
| + * See (http://www.w3.org/TR/2011/WD-html5-20110405/origin-0.html#origin) |
| + */ |
| + String get origin() { |
|
ahe
2012/08/07 06:32:36
Please add something like:
if (scheme == "") {
|
| + if (scheme != "http" && scheme != "https") { |
| + throw new IllegalArgumentException( |
|
ahe
2012/08/07 06:32:36
This should be a StateException which is coming so
|
| + "origin is applicable to http/https schemes only. Not \'$scheme\'"); |
| + } |
| + StringBuffer sb = new StringBuffer(); |
| + _addIfNonEmpty(sb, scheme, scheme, ':'); |
|
ahe
2012/08/07 06:32:36
scheme is never empty now.
|
| + if (domain != null || port != 0) { |
|
ahe
2012/08/07 06:32:36
Right now, the invariant is that domain is never n
|
| + sb.add("//"); |
| + sb.add(_emptyIfNull(domain)); |
| + if (port != 0) { |
| + sb.add(":"); |
| + sb.add(port.toString()); |
| + } |
| + } |
| + return sb.toString(); |
| + } |
| + |
| String toString() { |
| StringBuffer sb = new StringBuffer(); |
| _addIfNonEmpty(sb, scheme, scheme, ':'); |
| @@ -193,3 +216,4 @@ class Uri { |
| } |
| } |
| } |
| + |
|
ahe
2012/08/07 06:32:36
Extra line at end of file.
|