@@ -8,11 +8,11 @@ import { AboutPage } from "../pages/AboutPage";
88import { HistoryPage } from "../pages/HistoryPage" ;
99import { SettingsPage } from "../pages/SettingsPage" ;
1010import { DownloadsPage } from "../pages/DownloadsPage" ;
11- import { ProxyFrame } from "../proxy/ProxyFrame" ;
1211import { uuid } from "../util" ;
1312import { mountedPromise } from "../App" ;
1413import { tabsService } from ".." ;
1514import { CDPConnection } from "../CDP" ;
15+ import { TabSession } from "./TabSession" ;
1616// const requestInspectElement = createDelegate<[HTMLElement, Tab]>();
1717
1818export type SerializedTab = {
@@ -25,10 +25,7 @@ export type SerializedTab = {
2525
2626export class Tab extends StatefulClass {
2727 title : string | null = null ;
28- frame : ProxyFrame ;
29- devtoolsFrame : HTMLIFrameElement = (
30- < iframe src = "/front_end/inspexctor.html" > </ iframe >
31- ) ;
28+ session : TabSession ;
3229 screenshot : string | null = null ;
3330
3431 url : URL ;
@@ -62,20 +59,7 @@ export class Tab extends StatefulClass {
6259 this . url ??= new URL ( `${ INTERNAL_URL_PROTOCOL } //newtab` ) ;
6360 this . id ??= uuid ( "tab-" ) ;
6461
65- // this.devtoolsFrame.onload = () => {
66- // let session = new CDPConnection((msh) => {
67- // this.devtoolsFrame.contentWindow.InspectorFrontendAPI.dispatchMessage(
68- // msh
69- // );
70- // });
71- // this.devtoolsFrame.contentWindow.InspectorFrontendHost.sendMessageToBackend =
72- // (message) => {
73- // console.warn(message);
74- // session.sendMessage(message);
75- // };
76- // };
77-
78- this . frame = new ProxyFrame ( ) ;
62+ this . session = new TabSession ( ) ;
7963 this . history = new History ( this , history ) ;
8064 this . own ( this . history ) ;
8165 this . waitForInit = new Promise ( ( resolve ) => {
@@ -158,50 +142,26 @@ export class Tab extends StatefulClass {
158142 if ( url . protocol == INTERNAL_URL_PROTOCOL ) {
159143 this . icon = null ;
160144 this . history . current ( ) . favicon = "/icon.png" ;
161- switch ( url . host ) {
162- case "newtab" :
163- this . history . current ( ) . title = this . title = "New Tab" ;
164- this . internalpage = < NewTabPage tab = { this } /> ;
165- break ;
166- case "playground" :
167- this . history . current ( ) . title = this . title = "Scramjet Playground" ;
168- this . internalpage = < PlaygroundPage tab = { this } /> ;
169- break ;
170- case "history" :
171- this . history . current ( ) . title = this . title = "Browser History" ;
172- this . internalpage = < HistoryPage tab = { this } > </ HistoryPage > ;
173- break ;
174- case "version" :
175- this . history . current ( ) . title = this . title = "About Version" ;
176- this . internalpage = < AboutPage tab = { this } /> ;
177- break ;
178- case "settings" :
179- this . history . current ( ) . title = this . title = "Settings" ;
180- this . internalpage = (
181- < SettingsPage
182- tab = { this }
183- selected = {
184- url . pathname . length > 1 ? url . pathname . slice ( 1 ) : "general"
185- }
186- />
187- ) ;
188- break ;
189- case "downloads" :
190- this . history . current ( ) . title = this . title = "Downloads" ;
191- this . internalpage = < DownloadsPage tab = { this } /> ;
145+ const page = createInternalPage ( url , this ) ;
146+ if ( page ) {
147+ this . internalpage = page . page ;
148+ this . history . current ( ) . title = this . title = page . title ;
149+ } else {
150+ // TODO: make this better
151+ this . internalpage = (
152+ < div style = { { padding : "20px" } } >
153+ < h1 > 404 Not Found</ h1 >
154+ < p > No internal page found for { url . href } </ p >
155+ </ div >
156+ ) ;
157+ this . history . current ( ) . title = this . title = "404 Not Found" ;
192158 }
193159 } else {
194160 // placeholder title until the page fills in
195161 this . history . current ( ) . title = this . title = url . href ;
196162
197- // if (!navigator.serviceWorker.controller) {
198- // serviceWorkerReady.then(() => {
199163 console . warn ( "navigating to" , url ) ;
200- this . frame . go ( url ) ;
201- // });
202- // } else {
203- // this.frame.go(url);
204- // }
164+ this . session . go ( url ) ;
205165 }
206166 }
207167
@@ -231,7 +191,54 @@ export class Tab extends StatefulClass {
231191 if ( this . internalpage ) {
232192 this . _directnavigate ( this . url ) ;
233193 } else {
234- this . frame . reload ( ) ;
194+ this . session . reload ( ) ;
235195 }
236196 }
237197}
198+
199+ function createInternalPage (
200+ url : URL ,
201+ tab : Tab
202+ ) : { title : string ; page : HTMLElement } | null {
203+ switch ( url . host ) {
204+ case "newtab" :
205+ return {
206+ title : "New Tab" ,
207+ page : < NewTabPage tab = { tab } /> ,
208+ } ;
209+ case "playground" :
210+ return {
211+ title : "Scramjet Playground" ,
212+ page : < PlaygroundPage tab = { tab } /> ,
213+ } ;
214+ case "history" :
215+ return {
216+ title : "Browser History" ,
217+ page : < HistoryPage tab = { tab } /> ,
218+ } ;
219+ case "version" :
220+ return {
221+ title : "About Version" ,
222+ page : < AboutPage tab = { tab } /> ,
223+ } ;
224+ case "settings" :
225+ return {
226+ title : "Settings" ,
227+ page : (
228+ < SettingsPage
229+ tab = { tab }
230+ selected = {
231+ url . pathname . length > 1 ? url . pathname . slice ( 1 ) : "general"
232+ }
233+ > </ SettingsPage >
234+ ) ,
235+ } ;
236+ case "downloads" :
237+ return {
238+ title : "Downloads" ,
239+ page : < DownloadsPage tab = { tab } /> ,
240+ } ;
241+ default :
242+ return null ;
243+ }
244+ }
0 commit comments