/*
 * Name:		uri_entered_cb
 * Input arguments:'entry'-address bar where the url was entered
 *			 'data'-auxiliary data sent along with the event
 * Output arguments:void
 * Function:	When the user hits the enter after entering the url
 *			in the address bar, 'activate' event is generated
 *			for the Widget Entry, for which 'uri_entered_cb'
 *			callback is called. Controller-tab captures this event
 *			and sends the browsing request to the router(/parent)
 *			process.
 */
void uri_entered_cb(GtkWidget* entry, gpointer data)
{
	if(data == NULL){	
		return;
	}
	browser_window* b_window = (browser_window*)data;
	comm_channel channel = b_window->channel;
	
	// Get the tab index where the URL is to be rendered
	int tab_index = query_tab_id_for_request(entry, data);
	if(tab_index < 0){
		fprintf(stderr, "uri_entered_cb@43: Invalid tab index\n");
        return;
	}
	// Get the URL.
	char* uri = get_entered_uri(entry);

	// Send request to router
	child_req_to_parent req;
	req.type = NEW_URI_ENTERED;
	strcpy(req.req.uri_req.uri, uri);
	req.req.uri_req.render_in_tab = tab_index;
	
	if (write(channel.child_to_parent_fd[1], &req, sizeof(child_req_to_parent)) == -1)
		perror("uri_entered_cb@55: Controller write request in pipe");
}
Esempio n. 2
0
/*
 * Name:		uri_entered_cb
 * Input arguments:'entry'-address bar where the url was entered
 *			 'data'-auxiliary data sent along with the event
 * Output arguments:void
 * Function:	When the user hits the enter after entering the url
 *			in the address bar, 'activate' event is generated
 *			for the Widget Entry, for which 'uri_entered_cb'
 *			callback is called. Controller-tab captures this event
 *			and sends the browsing request to the router(/parent)
 *			process.
 */
void uri_entered_cb(GtkWidget* entry, gpointer data)
{
	if(data == NULL) // Error Handling
	{	
		perror("Null data in uri_entered_cb function\n");		
		return;
	}

	browser_window* b_window = (browser_window*)data;
	comm_channel channel = b_window->channel;
	
	// Get the tab index where the URL is to be rendered
	int tab_index = query_tab_id_for_request(entry, data);

	if(tab_index < 0) // Error handling (Invalid tab)
	{
		perror("Invalid tab in uri_entered_cb function\n");
                return;
	}

	// Get the URL.
	char* uri = get_entered_uri(entry);
	if(uri == NULL || uri[0] != 'h' || uri[1] != 't' || uri[2] != 't' || uri[3] != 'p' || uri[4] != ':' || uri[5] != '/' || uri[6] != '/' ) // Error handling(Invalid URI)
	{
		perror("Invalid URI in uri_entered_cb function\n");
		return;
	}
	
	// Now you get the URI from the controller.
		
	// NEW_URI_ENTERED request declarations
	child_req_to_parent new_req;
	new_uri_req uri_req;
	child_request child_req;

	// NEW_URI_ENTERED request field assignment
	uri_req.render_in_tab = tab_index;
	strcpy(uri_req.uri, uri);
	child_req.uri_req = uri_req;
	new_req.type = NEW_URI_ENTERED;
	new_req.req = child_req;
	
	// Write req to controller end of pipe so router can read from pipe
	write(channel.child_to_parent_fd[1], &new_req, sizeof (child_req_to_parent));	
}
void uri_entered_cb(GtkWidget* entry, gpointer data)
{
	if(!data)
		return;
	browser_window* b_window = (browser_window*)data;
        comm_channel channel = b_window->channel;
	// Get the tab index where the URL is to be rendered
	int tab_index = query_tab_id_for_request(entry, data);
	if(tab_index <= 0)
	{
		//Append code for error handling
	}

	// Get the URL.
	char* uri = get_entered_uri(entry);

	// Prepare 'request' packet to send to router (/parent) process.
	// Append your code here
}