I'm writing a Chrome e开发者_JAVA技巧xtension, and would like to be able to clean up given urls, so that I get their security origin. Using location.host seems to do the job, but it's not always usable - if I'd like to get the origin of an IFrame element, for instance, the call will be blocked.
Looking at WebKit's source, this seems like a far from trivial task. I can use either JavaScript, C++ or Chrome's API (using WebKit's code is an overkill, as it will drag another ton of files).
Well, turns out the guys from Chromium offer just that: google-url. As described -
The Google URL Parsing and Canonicalization Library
This library is designed for Unix and Windows client and server programs that require URL parsing, canonicalization, or resolving.
Features
- Fast: hundreds of thousands of typical URLs can be parsed and canonicalized per second on a modern CPU.
- Compatible: When possible, this library has strived for IE7 compatability. It supports Unix-style file URLs, as well as the more complex rules for Window file URLs.
- Complete: This library is among the most complete implementations available.
- Easily embededable: Unlike most implementations of URL parsing and canonicalization, this library is designed to be embedded into another application.
HTH someone in the future.
精彩评论