2003-07-30 17:06:22 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2003 Rob Jackson <jacko@xms.ms>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-07-30 17:06:22 +04:00
|
|
|
*/
|
|
|
|
|
2008-07-27 03:42:24 +04:00
|
|
|
#include "utils/config.h"
|
|
|
|
|
2004-04-02 04:41:10 +04:00
|
|
|
#include <stdbool.h>
|
2003-07-30 17:06:22 +04:00
|
|
|
#include <stdio.h>
|
2004-08-08 15:39:31 +04:00
|
|
|
#include <stdlib.h>
|
2003-07-30 17:06:22 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include "oslib/uri.h"
|
|
|
|
#include "oslib/wimp.h"
|
2014-10-16 12:50:55 +04:00
|
|
|
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/nsurl.h"
|
|
|
|
#include "utils/utils.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/fetch.h"
|
|
|
|
#include "desktop/browser.h"
|
2014-10-16 12:50:55 +04:00
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/gui.h"
|
2008-07-27 03:42:24 +04:00
|
|
|
#include "riscos/uri.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/url_protocol.h"
|
2003-07-30 17:06:22 +04:00
|
|
|
|
2008-07-27 03:42:24 +04:00
|
|
|
void ro_uri_message_received(wimp_message *msg)
|
2003-07-30 17:06:22 +04:00
|
|
|
{
|
2008-07-27 03:42:24 +04:00
|
|
|
uri_full_message_process *uri_message = (uri_full_message_process *)msg;
|
2005-01-02 06:58:21 +03:00
|
|
|
uri_h uri_handle;
|
|
|
|
char* uri_requested;
|
|
|
|
int uri_length;
|
2013-02-14 22:21:11 +04:00
|
|
|
nsurl *url;
|
|
|
|
nserror error;
|
2003-07-30 17:06:22 +04:00
|
|
|
|
2005-01-02 06:58:21 +03:00
|
|
|
uri_handle = uri_message->handle;
|
2003-07-30 17:06:22 +04:00
|
|
|
|
2013-02-18 16:24:49 +04:00
|
|
|
if (nsurl_create(uri_message->uri, &url) != NSERROR_OK) {
|
2011-09-27 16:02:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-18 16:24:49 +04:00
|
|
|
if (!fetch_can_fetch(url)) {
|
|
|
|
nsurl_unref(url);
|
2011-09-27 16:02:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-18 16:24:49 +04:00
|
|
|
nsurl_unref(url);
|
2003-07-30 17:06:22 +04:00
|
|
|
|
2005-01-02 06:58:21 +03:00
|
|
|
uri_message->your_ref = uri_message->my_ref;
|
|
|
|
uri_message->action = message_URI_PROCESS_ACK;
|
2003-07-30 17:06:22 +04:00
|
|
|
|
2005-01-02 06:58:21 +03:00
|
|
|
xwimp_send_message(wimp_USER_MESSAGE, (wimp_message*)uri_message,
|
|
|
|
uri_message->sender);
|
2003-07-30 17:06:22 +04:00
|
|
|
|
2005-01-02 06:58:21 +03:00
|
|
|
xuri_request_uri(0, 0, 0, uri_handle, &uri_length);
|
|
|
|
uri_requested = calloc((unsigned int)uri_length, sizeof(char));
|
|
|
|
if (uri_requested == NULL)
|
|
|
|
return;
|
2003-07-30 17:06:22 +04:00
|
|
|
|
2005-01-02 06:58:21 +03:00
|
|
|
xuri_request_uri(0, uri_requested, uri_length, uri_handle, NULL);
|
2003-07-30 17:06:22 +04:00
|
|
|
|
2013-02-14 22:21:11 +04:00
|
|
|
error = nsurl_create(uri_requested, &url);
|
2005-01-02 06:58:21 +03:00
|
|
|
free(uri_requested);
|
2013-02-14 22:21:11 +04:00
|
|
|
if (error == NSERROR_OK) {
|
2014-02-10 18:08:45 +04:00
|
|
|
error = browser_window_create(BW_CREATE_HISTORY,
|
2013-02-14 22:21:11 +04:00
|
|
|
url,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
warn_user(messages_get_errorcode(error), 0);
|
|
|
|
}
|
2003-07-30 17:06:22 +04:00
|
|
|
}
|
2004-04-02 04:41:10 +04:00
|
|
|
|
2009-07-01 16:05:51 +04:00
|
|
|
bool ro_uri_launch(const char *uri)
|
2005-01-02 06:58:21 +03:00
|
|
|
{
|
2004-04-02 04:41:10 +04:00
|
|
|
uri_h uri_handle;
|
|
|
|
wimp_t handle_task;
|
|
|
|
uri_dispatch_flags returned;
|
|
|
|
os_error *e;
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2004-06-29 03:57:26 +04:00
|
|
|
e = xuri_dispatch(uri_DISPATCH_INFORM_CALLER, uri, task_handle,
|
2005-01-02 06:58:21 +03:00
|
|
|
&returned, &handle_task, &uri_handle);
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2004-04-02 04:41:10 +04:00
|
|
|
if (e || returned & 1) {
|
|
|
|
return false;
|
|
|
|
}
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2004-04-02 04:41:10 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-07-27 03:42:24 +04:00
|
|
|
void ro_uri_bounce(wimp_message *msg)
|
2005-01-02 06:58:21 +03:00
|
|
|
{
|
2008-07-27 03:42:24 +04:00
|
|
|
uri_full_message_process *message = (uri_full_message_process *)msg;
|
2009-07-01 16:05:51 +04:00
|
|
|
int size;
|
|
|
|
char *uri_buf;
|
2004-04-02 04:41:10 +04:00
|
|
|
os_error *e;
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2008-07-27 03:42:24 +04:00
|
|
|
if ((message->flags & 1) == 0)
|
|
|
|
return;
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2009-07-01 16:05:51 +04:00
|
|
|
/* Get required buffer size */
|
|
|
|
e = xuri_request_uri(0, NULL, 0, message->handle, &size);
|
2004-06-29 03:57:26 +04:00
|
|
|
if (e) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xuri_request_uri: %d: %s", e->errnum, e->errmess);
|
2005-01-02 06:58:21 +03:00
|
|
|
return;
|
2004-06-29 03:57:26 +04:00
|
|
|
}
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2009-07-01 16:05:51 +04:00
|
|
|
uri_buf = malloc(size);
|
|
|
|
if (uri_buf == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Get URI */
|
|
|
|
e = xuri_request_uri(0, uri_buf, size, message->handle, 0);
|
|
|
|
if (e) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xuri_request_uri: %d: %s", e->errnum, e->errmess);
|
2009-07-01 16:05:51 +04:00
|
|
|
free(uri_buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-04-02 04:41:10 +04:00
|
|
|
ro_url_load(uri_buf);
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2009-07-01 16:05:51 +04:00
|
|
|
free(uri_buf);
|
|
|
|
|
2004-04-02 04:41:10 +04:00
|
|
|
return;
|
|
|
|
}
|