1/*
2 * Copyright (C) 2007 Ryan Leavengood <leavengood@gmail.com>
3 * Copyright (C) 2009 Maxime Simon <simon.maxime@gmail.com>
4 * Copyright (C) 2010 Stephan A��mus <superstippi@gmx.de>
5 * Copyright 2013-2014 Haiku, Inc. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28#ifndef BROWSER_WINDOW_H
29#define BROWSER_WINDOW_H
30
31
32#include "WebWindow.h"
33
34#include <Messenger.h>
35#include <String.h>
36#include <UrlContext.h>
37
38class BButton;
39class BCheckBox;
40class BDirectory;
41class BFile;
42class BFilePanel;
43class BGroupLayout;
44class BLayoutItem;
45class BMenu;
46class BMenuItem;
47class BMessageRunner;
48class BPath;
49class BStatusBar;
50class BStringView;
51class BTextControl;
52class BWebView;
53
54class BookmarkBar;
55class SettingsMessage;
56class TabManager;
57class URLInputGroup;
58
59namespace BPrivate {
60	class BIconButton;
61}
62
63using BPrivate::BIconButton;
64
65enum {
66	INTERFACE_ELEMENT_MENU			= 1 << 0,
67	INTERFACE_ELEMENT_TABS			= 1 << 1,
68	INTERFACE_ELEMENT_NAVIGATION	= 1 << 2,
69	INTERFACE_ELEMENT_STATUS		= 1 << 3,
70
71	INTERFACE_ELEMENT_ALL			= 0xffff
72};
73
74enum NewPagePolicy {
75	OpenBlankPage					= 0,
76	OpenStartPage					= 1,
77	OpenSearchPage					= 2,
78	CloneCurrentPage				= 3
79};
80
81enum StartUpPolicy {
82	ResumePriorSession				= 0,
83	StartNewSession					= 1
84};
85
86enum {
87	NEW_WINDOW						= 'nwnd',
88	NEW_TAB							= 'ntab',
89	WINDOW_OPENED					= 'wndo',
90	WINDOW_CLOSED					= 'wndc',
91	SHOW_DOWNLOAD_WINDOW			= 'sdwd',
92	SHOW_SETTINGS_WINDOW			= 'sswd',
93	SHOW_CONSOLE_WINDOW				= 'scwd',
94	SHOW_COOKIE_WINDOW				= 'skwd'
95};
96
97
98class BrowserWindow : public BWebWindow {
99public:
100								BrowserWindow(BRect frame,
101									SettingsMessage* appSettings,
102									const BString& url,
103									BPrivate::Network::BUrlContext* context,
104									uint32 interfaceElements
105										= INTERFACE_ELEMENT_ALL,
106									BWebView* webView = NULL);
107	virtual						~BrowserWindow();
108
109	virtual	void				DispatchMessage(BMessage* message,
110									BHandler* target);
111	virtual	void				MessageReceived(BMessage* message);
112	virtual	status_t			Archive(BMessage* archive, bool deep =true) const;
113	virtual	bool				QuitRequested();
114	virtual	void				MenusBeginning();
115	virtual	void				MenusEnded();
116
117	virtual void				ScreenChanged(BRect screenSize,
118									color_space format);
119	virtual void				WorkspacesChanged(uint32 oldWorkspaces,
120									uint32 newWorkspaces);
121
122	virtual	void				SetCurrentWebView(BWebView* view);
123
124			bool				IsBlankTab() const;
125			void				CreateNewTab(const BString& url, bool select,
126									BWebView* webView = 0);
127
128			BRect				WindowFrame() const;
129
130			void				ToggleFullscreen();
131
132private:
133	// WebPage notification API implementations
134	virtual	void				NavigationRequested(const BString& url,
135									BWebView* view);
136	virtual	void				NewWindowRequested(const BString& url,
137									bool primaryAction);
138	virtual	void				CloseWindowRequested(BWebView* view);
139	virtual	void				NewPageCreated(BWebView* view,
140									BRect windowFrame, bool modalDialog,
141									bool resizable, bool activate);
142	virtual	void				LoadNegotiating(const BString& url,
143									BWebView* view);
144	virtual	void				LoadCommitted(const BString& url,
145									BWebView* view);
146	virtual	void				LoadProgress(float progress, BWebView* view);
147	virtual	void				LoadFailed(const BString& url, BWebView* view);
148	virtual	void				LoadFinished(const BString& url,
149									BWebView* view);
150	virtual	void				MainDocumentError(const BString& failingURL,
151									const BString& localizedDescription,
152									BWebView* view);
153	virtual	void				TitleChanged(const BString& title,
154									BWebView* view);
155	virtual	void				IconReceived(const BBitmap* icon,
156									BWebView* view);
157	virtual	void				ResizeRequested(float width, float height,
158									BWebView* view);
159	virtual	void				SetToolBarsVisible(bool flag, BWebView* view);
160	virtual	void				SetStatusBarVisible(bool flag, BWebView* view);
161	virtual	void				SetMenuBarVisible(bool flag, BWebView* view);
162	virtual	void				SetResizable(bool flag, BWebView* view);
163	virtual	void				StatusChanged(const BString& status,
164									BWebView* view);
165	virtual	void				NavigationCapabilitiesChanged(
166									bool canGoBackward, bool canGoForward,
167									bool canStop, BWebView* view);
168	virtual	void				UpdateGlobalHistory(const BString& url);
169	virtual	bool				AuthenticationChallenge(BString message,
170									BString& inOutUser, BString& inOutPassword,
171									bool& inOutRememberCredentials,
172									uint32 failureCount, BWebView* view);
173
174private:
175			void				_UpdateTitle(const BString &title);
176			void				_UpdateTabGroupVisibility();
177			bool				_TabGroupShouldBeVisible() const;
178			void				_ShutdownTab(int32 index);
179			void				_TabChanged(int32 index);
180
181			status_t			_BookmarkPath(BPath& path) const;
182			void				_CreateBookmark(const BPath& path,
183									BString fileName, const BString& title,
184									const BString& url,	const BBitmap* miniIcon,
185									const BBitmap* largeIcon);
186			void				_CreateBookmark(BMessage* message);
187			void				_CreateBookmark();
188			void				_ShowBookmarks();
189			bool				_CheckBookmarkExists(BDirectory& directory,
190									const BString& fileName,
191									const BString& url) const;
192			bool				_ReadURLAttr(BFile& bookmarkFile,
193									BString& url) const;
194			void				_AddBookmarkURLsRecursively(
195									BDirectory& directory,
196									BMessage* message,
197									uint32& addedCount) const;
198
199			void				_SetPageIcon(BWebView* view,
200									const BBitmap* icon);
201
202			void				_UpdateHistoryMenu();
203			void				_UpdateClipboardItems();
204
205			bool				_ShowPage(BWebView* view);
206
207			void				_ToggleFullscreen();
208			void				_ResizeToScreen();
209			void				_SetAutoHideInterfaceInFullscreen(bool doIt);
210			void				_CheckAutoHideInterface();
211			void				_ShowInterface(bool show);
212			void				_ShowProgressBar(bool);
213			void				_InvokeButtonVisibly(BButton* button);
214
215			BString				_NewTabURL(bool isNewWindow) const;
216
217			BString				_EncodeURIComponent(const BString& search);
218			void				_VisitURL(const BString& url);
219			void				_VisitSearchEngine(const BString& search);
220	inline 	bool				_IsValidDomainChar(char ch);
221			void 				_SmartURLHandler(const BString& url);
222
223			void				_HandlePageSourceResult(
224									const BMessage* message);
225
226			void				_ShowBookmarkBar(bool show);
227
228private:
229			BMenu*				fHistoryMenu;
230			int32				fHistoryMenuFixedItemCount;
231
232			BMenuItem*			fCutMenuItem;
233			BMenuItem*			fCopyMenuItem;
234			BMenuItem*			fPasteMenuItem;
235			BMenuItem*			fFindPreviousMenuItem;
236			BMenuItem*			fFindNextMenuItem;
237			BMenuItem*			fZoomTextOnlyMenuItem;
238			BMenuItem*			fFullscreenItem;
239			BMenuItem*			fBackMenuItem;
240			BMenuItem*			fForwardMenuItem;
241
242			BIconButton*		fBackButton;
243			BIconButton*		fForwardButton;
244			BIconButton*		fStopButton;
245			BIconButton*		fHomeButton;
246			URLInputGroup*		fURLInputGroup;
247			BStringView*		fStatusText;
248			BStatusBar*			fLoadingProgressBar;
249
250			BGroupLayout*		fMenuGroup;
251			BLayoutItem*		fTabGroup;
252			BLayoutItem*		fNavigationGroup;
253			BLayoutItem*		fFindGroup;
254			BLayoutItem*		fStatusGroup;
255			BLayoutItem*		fToggleFullscreenButton;
256
257			BTextControl*		fFindTextControl;
258			BButton*			fFindPreviousButton;
259			BButton*			fFindNextButton;
260			BButton*			fFindCloseButton;
261			BCheckBox*			fFindCaseSensitiveCheckBox;
262			TabManager*			fTabManager;
263
264			bool				fIsFullscreen;
265			bool				fInterfaceVisible;
266			bool				fMenusRunning;
267			BRect				fNonFullscreenWindowFrame;
268			BMessageRunner*		fPulseRunner;
269			uint32				fVisibleInterfaceElements;
270			bigtime_t			fLastMouseMovedTime;
271			BPoint				fLastMousePos;
272
273			BReference<BPrivate::Network::BUrlContext>	fContext;
274
275			// cached settings
276			SettingsMessage*	fAppSettings;
277			bool				fZoomTextOnly;
278			bool				fShowTabsIfSinglePageOpen;
279			bool				fAutoHideInterfaceInFullscreenMode;
280			bool				fAutoHidePointer;
281			uint32				fNewWindowPolicy;
282			uint32				fNewTabPolicy;
283			BString				fStartPageURL;
284			BString				fSearchPageURL;
285
286			BMenuItem*			fBookmarkBarMenuItem;
287			BookmarkBar*		fBookmarkBar;
288			BFilePanel*			fSavePanel;
289};
290
291
292#endif // BROWSER_WINDOW_H
293