Question
Web browsers can do amazing things, but some of their functionality is as simple as maintaining a list. In this lab, you will build a
Web browsers can do amazing things, but some of their functionality is as simple as maintaining a list.
In this lab, you will build a mock web browser, read commands from a file that let you know what buttons are being pushed and what URLs are being navigated to, and you will track a List of Tabs. Each Tab will have its own browser history.
This is still a terminal program! You don't need to know any networking or actually write code for a web browser!
Updating LinkedList class
You can use your old LinkedList for this lab, but you'll need to update it be templated. That means you'll also have to update your Node to be templated as well. Both your Tab class and WebBrowser class will use Lists, but they'll need Lists of different types.
Tab class
Below is a header file for your Tab class. You can add constructors, destructors, operator overloads, and private helper methods. You may not add any other type of public method.
#include "LinkedList.h" #includeclass Tab { public: /** * @pre none * @post the browser navigate to the given url * @param url, a string representing a URL */ void navigateTo(std::string url); /** * @pre none * @post if possible, the browser navigates forward in the history otherwise it keeps focus * on the current URL */ void forward(); /** * @pre none * @post if possible, the browser navigates backwards in the history otherwise it keeps focus * on the current URL */ void back(); /** * @return the URL currently open in the tab */ std::string currentURL() const; /** * @pre The list being passed in is empty * @post The current browser history is copied into the given list * @param destination, an empty list of strings * @return the position in the list with focus (zero if there is no history) */ int copyCurrentHistory(LinkedList & destination); };
WebBrowser Class
You will also need design and implement a Browser class, which can manage several tabs. How many tabs? That's up to the file.
What can a browser do?
- Open new tab
- Close existing tab
- Switch focus to a particular tab
- Move a tab left or right in the List of tabs
- Note, when you move a tab, no tabs are lost, they only rearrange in order
Reading the from file
Commands to interact with your browser will come from a file. The file name will come in on the command line.
Any given line of the file will contain one of the following entries. Some commands pertain to the browser and some pertain to a tab. I've separated them into two tables, but a single file will contains commands from both tables.
Browser Command | Description |
---|---|
NEW_TAB | Creates a new tab at the end of the list of tab and immediately gives it focus. |
FOCUS | Switches focus to the tab at position 1 to total_num_tabs. |
CLOSE | Closes the tab at the indicated position. with focus |
MOVE_LEFT | Moves the tab with focus left amount times. If it reaches the front of the list it stops there. Focus remains on the moved tab. |
MOVE_RIGHT | Moves the tab with focus right amount times. If it reaches the back of the list it stops there. Focus remains on the moved tab. |
HISTORY | Prints the tab number and current URL history to the screen using the following format: Tab # =========== |
EXIT | End the simulation. No more commands need to be read in. |
Tab Command | Description |
---|---|
NAVIGATE | Navigates the browser to the given URL. NOTE navigating to a URL retains all URLs accessible from going BACK, but any URLs that would have accessible from going FORWARD are now lost |
BACK | A command indicating the web browser is redirected to the previous URL in the history. If there is no URL further back, then the browser stays on the current URL. |
FORWARD | A command indicating the web browser is redirected to the next URL in the history. If there is no URL that is next, then the browser stays on the current URL. |
Sample input file
NEW_TAB NAVIGATE http://google.com NAVIGATE http://reddit.com NAVIGATE http://facebook.com NAVIGATE http://myspace.com HISTORY NEW_TAB NAVIGATE http://ku.edu NAVIGATE http://youtube.com NAVIGATE http://bing.com BACK HISTORY MOVE_LEFT 1 FOCUS 2 BACK NAVIGATE http://amazon.com HISTORY EXIT
Output to screen:
Tab 1 =========== http://google.com http://reddit.com http://facebook.com http://myspace.com <==current =========== Newest Tab 2 =========== http://ku.edu http://youtube.com <===current http://bing.com =========== Newest Tab 2 =========== http://google.com http://reddit.com http://facebook.com http://amazon.com <==current =========== Newest
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started