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 38 class BButton; 39 class BCheckBox; 40 class BDirectory; 41 class BFile; 42 class BFilePanel; 43 class BLayoutItem; 44 class BMenu; 45 class BMenuItem; 46 class BMessageRunner; 47 class BPath; 48 class BStatusBar; 49 class BStringView; 50 class BTextControl; 51 class BWebView; 52 53 class BookmarkBar; 54 class SettingsMessage; 55 class TabManager; 56 class URLInputGroup; 57 58 namespace BPrivate { 59 class BIconButton; 60 } 61 62 using BPrivate::BIconButton; 63 64 enum { 65 INTERFACE_ELEMENT_MENU = 1 << 0, 66 INTERFACE_ELEMENT_TABS = 1 << 1, 67 INTERFACE_ELEMENT_NAVIGATION = 1 << 2, 68 INTERFACE_ELEMENT_STATUS = 1 << 3, 69 70 INTERFACE_ELEMENT_ALL = 0xffff 71 }; 72 73 enum NewPagePolicy { 74 OpenBlankPage = 0, 75 OpenStartPage = 1, 76 OpenSearchPage = 2, 77 CloneCurrentPage = 3 78 }; 79 80 enum StartUpPolicy { 81 ResumePriorSession = 0, 82 StartNewSession = 1 83 }; 84 85 enum { 86 NEW_WINDOW = 'nwnd', 87 NEW_TAB = 'ntab', 88 WINDOW_OPENED = 'wndo', 89 WINDOW_CLOSED = 'wndc', 90 SHOW_DOWNLOAD_WINDOW = 'sdwd', 91 SHOW_SETTINGS_WINDOW = 'sswd', 92 SHOW_CONSOLE_WINDOW = 'scwd', 93 SHOW_COOKIE_WINDOW = 'skwd' 94 }; 95 96 #define INTEGRATE_MENU_INTO_TAB_BAR 0 97 98 99 class BrowserWindow : public BWebWindow { 100 public: 101 BrowserWindow(BRect frame, 102 SettingsMessage* appSettings, 103 const BString& url, 104 BPrivate::Network::BUrlContext* context, 105 uint32 interfaceElements 106 = INTERFACE_ELEMENT_ALL, 107 BWebView* webView = NULL); 108 virtual ~BrowserWindow(); 109 110 virtual void DispatchMessage(BMessage* message, 111 BHandler* target); 112 virtual void MessageReceived(BMessage* message); 113 virtual status_t Archive(BMessage* archive, bool deep =true) const; 114 virtual bool QuitRequested(); 115 virtual void MenusBeginning(); 116 virtual void MenusEnded(); 117 118 virtual void ScreenChanged(BRect screenSize, 119 color_space format); 120 virtual void WorkspacesChanged(uint32 oldWorkspaces, 121 uint32 newWorkspaces); 122 123 virtual void SetCurrentWebView(BWebView* view); 124 125 bool IsBlankTab() const; 126 void CreateNewTab(const BString& url, bool select, 127 BWebView* webView = 0); 128 129 BRect WindowFrame() const; 130 131 void ToggleFullscreen(); 132 133 private: 134 // WebPage notification API implementations 135 virtual void NavigationRequested(const BString& url, 136 BWebView* view); 137 virtual void NewWindowRequested(const BString& url, 138 bool primaryAction); 139 virtual void CloseWindowRequested(BWebView* view); 140 virtual void NewPageCreated(BWebView* view, 141 BRect windowFrame, bool modalDialog, 142 bool resizable, bool activate); 143 virtual void LoadNegotiating(const BString& url, 144 BWebView* view); 145 virtual void LoadCommitted(const BString& url, 146 BWebView* view); 147 virtual void LoadProgress(float progress, BWebView* view); 148 virtual void LoadFailed(const BString& url, BWebView* view); 149 virtual void LoadFinished(const BString& url, 150 BWebView* view); 151 virtual void MainDocumentError(const BString& failingURL, 152 const BString& localizedDescription, 153 BWebView* view); 154 virtual void TitleChanged(const BString& title, 155 BWebView* view); 156 virtual void IconReceived(const BBitmap* icon, 157 BWebView* view); 158 virtual void ResizeRequested(float width, float height, 159 BWebView* view); 160 virtual void SetToolBarsVisible(bool flag, BWebView* view); 161 virtual void SetStatusBarVisible(bool flag, BWebView* view); 162 virtual void SetMenuBarVisible(bool flag, BWebView* view); 163 virtual void SetResizable(bool flag, BWebView* view); 164 virtual void StatusChanged(const BString& status, 165 BWebView* view); 166 virtual void NavigationCapabilitiesChanged( 167 bool canGoBackward, bool canGoForward, 168 bool canStop, BWebView* view); 169 virtual void UpdateGlobalHistory(const BString& url); 170 virtual bool AuthenticationChallenge(BString message, 171 BString& inOutUser, BString& inOutPassword, 172 bool& inOutRememberCredentials, 173 uint32 failureCount, BWebView* view); 174 175 private: 176 void _UpdateTitle(const BString &title); 177 void _UpdateTabGroupVisibility(); 178 bool _TabGroupShouldBeVisible() const; 179 void _ShutdownTab(int32 index); 180 void _TabChanged(int32 index); 181 182 status_t _BookmarkPath(BPath& path) const; 183 void _CreateBookmark(); 184 void _ShowBookmarks(); 185 bool _CheckBookmarkExists(BDirectory& directory, 186 const BString& fileName, 187 const BString& url) const; 188 bool _ReadURLAttr(BFile& bookmarkFile, 189 BString& url) const; 190 void _AddBookmarkURLsRecursively( 191 BDirectory& directory, 192 BMessage* message, 193 uint32& addedCount) const; 194 195 void _SetPageIcon(BWebView* view, 196 const BBitmap* icon); 197 198 void _UpdateHistoryMenu(); 199 void _UpdateClipboardItems(); 200 201 bool _ShowPage(BWebView* view); 202 203 void _ToggleFullscreen(); 204 void _ResizeToScreen(); 205 void _SetAutoHideInterfaceInFullscreen(bool doIt); 206 void _CheckAutoHideInterface(); 207 void _ShowInterface(bool show); 208 void _ShowProgressBar(bool); 209 void _InvokeButtonVisibly(BButton* button); 210 211 BString _NewTabURL(bool isNewWindow) const; 212 213 BString _EncodeURIComponent(const BString& search); 214 void _VisitURL(const BString& url); 215 void _VisitSearchEngine(const BString& search); 216 inline bool _IsValidDomainChar(char ch); 217 void _SmartURLHandler(const BString& url); 218 219 void _HandlePageSourceResult( 220 const BMessage* message); 221 222 void _ShowBookmarkBar(bool show); 223 224 private: 225 BMenu* fHistoryMenu; 226 int32 fHistoryMenuFixedItemCount; 227 228 BMenuItem* fCutMenuItem; 229 BMenuItem* fCopyMenuItem; 230 BMenuItem* fPasteMenuItem; 231 BMenuItem* fFindPreviousMenuItem; 232 BMenuItem* fFindNextMenuItem; 233 BMenuItem* fZoomTextOnlyMenuItem; 234 BMenuItem* fFullscreenItem; 235 BMenuItem* fBackMenuItem; 236 BMenuItem* fForwardMenuItem; 237 238 BIconButton* fBackButton; 239 BIconButton* fForwardButton; 240 BIconButton* fStopButton; 241 BIconButton* fHomeButton; 242 URLInputGroup* fURLInputGroup; 243 BStringView* fStatusText; 244 BStatusBar* fLoadingProgressBar; 245 246 BLayoutItem* fMenuGroup; 247 BLayoutItem* fTabGroup; 248 BLayoutItem* fNavigationGroup; 249 BLayoutItem* fFindGroup; 250 BLayoutItem* fStatusGroup; 251 BLayoutItem* fToggleFullscreenButton; 252 253 BTextControl* fFindTextControl; 254 BButton* fFindPreviousButton; 255 BButton* fFindNextButton; 256 BButton* fFindCloseButton; 257 BCheckBox* fFindCaseSensitiveCheckBox; 258 TabManager* fTabManager; 259 260 bool fIsFullscreen; 261 bool fInterfaceVisible; 262 bool fMenusRunning; 263 BRect fNonFullscreenWindowFrame; 264 BMessageRunner* fPulseRunner; 265 uint32 fVisibleInterfaceElements; 266 bigtime_t fLastMouseMovedTime; 267 BPoint fLastMousePos; 268 269 BPrivate::Network::BUrlContext* fContext; 270 271 // cached settings 272 SettingsMessage* fAppSettings; 273 bool fZoomTextOnly; 274 bool fShowTabsIfSinglePageOpen; 275 bool fAutoHideInterfaceInFullscreenMode; 276 bool fAutoHidePointer; 277 uint32 fNewWindowPolicy; 278 uint32 fNewTabPolicy; 279 BString fStartPageURL; 280 BString fSearchPageURL; 281 282 BMenuItem* fBookmarkBarMenuItem; 283 BookmarkBar* fBookmarkBar; 284 BFilePanel* fSavePanel; 285 }; 286 287 288 #endif // BROWSER_WINDOW_H 289