- try to handle .webloc internet shortcut files from OSX,

- build uri scheme mimetype from the actual protocol specifier in the url,
- fallback to calling ourselves if no prefered app is set.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36124 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol
2010-04-10 23:54:22 +00:00
parent 218aa6d9e8
commit 7883956881
2 changed files with 96 additions and 7 deletions
+95 -7
View File
@@ -34,6 +34,8 @@ const char* kBeShareSig = "application/x-vnd.Sugoi-BeShare";
const char* kIMSig = "application/x-vnd.m_eiman.sample_im_client";
const char* kVLCSig = "application/x-vnd.videolan-vlc";
const char* kURLHandlerSigBase = "application/x-vnd.Be.URL.";
UrlWrapper::UrlWrapper() : BApplication(kAppSig)
{
@@ -77,20 +79,25 @@ UrlWrapper::RefsReceived(BMessage* msg)
BFile f(&ref, B_READ_ONLY);
BNodeInfo ni(&f);
BString mimetype;
BString extension(ref.name);
extension.Remove(0, extension.FindLast('.') + 1);
printf("e:%s\n", extension.String());
if (f.InitCheck() == B_OK && ni.InitCheck() == B_OK) {
ni.GetType(mimetype.LockBuffer(B_MIME_TYPE_LENGTH));
mimetype.UnlockBuffer();
// Internet Explorer Shortcut
if (mimetype == "text/x-url") {
if (mimetype == "text/x-url" || extension == "url") {
// http://filext.com/file-extension/URL
// http://www.cyanwerks.com/file-format-url.html
off_t size;
if (f.GetSize(&size) < B_OK)
continue;
BString contents, url;
BString contents;
BString url;
if (f.ReadAt(0LL, contents.LockBuffer(size), size) < B_OK)
continue;
contents.UnlockBuffer();
while (contents.Length()) {
BString line;
int32 cr = contents.FindFirst('\n');
@@ -108,9 +115,85 @@ UrlWrapper::RefsReceived(BMessage* msg)
}
}
if (url.Length()) {
args[1] = (char*)url.String();
err = be_roster->Launch("application/x-vnd.Be.URL.http", 1,
args+1);
BPrivate::Support::BUrl u(url.String());
args[1] = (char*)u.String();
mimetype = kURLHandlerSigBase;
mimetype += u.Proto();
err = be_roster->Launch(mimetype.String(), 1, args+1);
if (err < B_OK)
err = be_roster->Launch(kAppSig, 1, args+1);
continue;
}
}
if (mimetype == "text/x-webloc" || extension == "webloc") {
// OSX url shortcuts
// XML file + resource fork
off_t size;
if (f.GetSize(&size) < B_OK)
continue;
BString contents;
BString url;
if (f.ReadAt(0LL, contents.LockBuffer(size), size) < B_OK)
continue;
contents.UnlockBuffer();
int state = 0;
while (contents.Length()) {
BString line;
int32 cr = contents.FindFirst('\n');
if (cr < 0)
cr = contents.Length();
//contents.MoveInto(line, 0, cr);
contents.CopyInto(line, 0, cr);
contents.Remove(0, cr+1);
line.RemoveAll("\r");
if (!line.Length())
continue;
int32 s, e;
switch (state) {
case 0:
if (!line.ICompare("<?xml", 5))
state = 1;
break;
case 1:
if (!line.ICompare("<plist", 6))
state = 2;
break;
case 2:
if (!line.ICompare("<dict>", 6))
state = 3;
break;
case 3:
if (line.IFindFirst("<key>URL</key>") > -1)
state = 4;
break;
case 4:
if ((s = line.IFindFirst("<string>")) > -1 && (e = line.IFindFirst("</string>")) > s) {
state = 5;
s += 8;
line.MoveInto(url, s, e - s);
break;
} else
state = 3;
break;
break;
default:
break;
}
if (state == 5) {
break;
}
}
if (url.Length()) {
BPrivate::Support::BUrl u(url.String());
args[1] = (char*)u.String();
mimetype = kURLHandlerSigBase;
mimetype += u.Proto();
printf("sig:'%s'\n", mimetype.String());
printf("url:'%s'\n", u.String());
err = be_roster->Launch(mimetype.String(), 1, args+1);
if (err < B_OK)
err = be_roster->Launch(kAppSig, 1, args+1);
continue;
}
}
@@ -118,8 +201,13 @@ UrlWrapper::RefsReceived(BMessage* msg)
// NetPositive Bookmark or any file with a META:url attribute
if (f.ReadAttr("META:url", B_STRING_TYPE, 0LL, buff,
B_PATH_NAME_LENGTH) > 0) {
err = be_roster->Launch("application/x-vnd.Be.URL.http", 1,
args+1);
BPrivate::Support::BUrl u(buff);
args[1] = (char*)u.String();
mimetype = kURLHandlerSigBase;
mimetype += u.Proto();
err = be_roster->Launch(mimetype.String(), 1, args+1);
if (err < B_OK)
err = be_roster->Launch(kAppSig, 1, args+1);
continue;
}
}
+1
View File
@@ -6,6 +6,7 @@ resource(1, "BEOS:FILE_TYPES") message
{
"types" = "application/x-vnd.Be-bookmark",
"types" = "text/x-url",
"types" = "text/x-webloc",
"types" = "application/x-vnd.Be.URL.file",
"types" = "application/x-vnd.Be.URL.http",
"types" = "application/x-vnd.Be.URL.query",