Opera 12.15 Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

winman.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
  2. **
  3. ** Copyright (C) 1995-2011 Opera Software ASA. All rights reserved.
  4. **
  5. ** This file is part of the Opera web browser. It may not be distributed
  6. ** under any circumstances.
  7. */
  8. #ifndef DOCHAND_WINMAN_H
  9. #define DOCHAND_WINMAN_H
  10. #include "modules/dochand/winman_constants.h"
  11. #include "modules/dochand/win.h"
  12. #include "modules/prefs/prefsmanager/prefstypes.h"
  13. #include "modules/url/url2.h"
  14. #include "modules/util/simset.h"
  15. #include "modules/prefs/prefsmanager/opprefslistener.h"
  16. #include "modules/hardcore/mh/messobj.h"
  17. #include "modules/hardcore/timer/optimer.h"
  18. class OpWindowCommander;
  19. class FramesDocument;
  20. class DocumentManager;
  21. class MessageHandler;
  22. class DocumentWindow;
  23. class Window;
  24. class OpWindow;
  25. class ES_Thread;
  26. class WindowManager
  27. : public OpPrefsListener,
  28. public MessageObject
  29. {
  30. private:
  31. ST_MESSAGETYPE messageStringType;
  32. Head win_list;
  33. uni_char current_popup_message[4096]; /* ARRAY OK 2008-02-28 jl */
  34. BOOL current_popup_message_statusline_only;
  35. Window* curr_clicked_window;
  36. URL curr_clicked_url;
  37. URL empty_url;
  38. unsigned idcounter;
  39. public:
  40. WindowManager();
  41. // Doesn't really need to be virtual, but the class has virtual functions
  42. // so GCC will warn if the destructor isn't. And it doesn't really matter
  43. // anyway. (jl@opera.com)
  44. virtual ~WindowManager();
  45. void ConstructL();
  46. void Clear();
  47. #if defined(_MACINTOSH_)
  48. // Fix to take care of issues of values being set before window
  49. // is fully initiallized
  50. Window* FirstWindow() const { if(this) return (Window*)win_list.First(); else return 0; }
  51. Window* LastWindow() const { if(this) return (Window*)win_list.Last(); else return 0; }
  52. #else // _MACINTOSH_
  53. Window* FirstWindow() const { return static_cast<Window*>(win_list.First()); }
  54. Window* LastWindow() const { return static_cast<Window*>(win_list.Last()); }
  55. #endif // _MACINTOSH_
  56. Window* GetWindow(unsigned long nid);
  57. void Insert(Window* window, Window* precede);
  58. Window* AddWindow(OpWindow* opWindow, OpWindowCommander* opWindowCommander);
  59. void DeleteWindow(Window* window);
  60. void RemoveInvalidWindows ();
  61. const uni_char* GetPopupMessage(ST_MESSAGETYPE *strType = NULL);
  62. void SetPopupMessage(const uni_char *msg, BOOL fStatusLineOnly=FALSE, ST_MESSAGETYPE strType=ST_ASTRING);
  63. BOOL IsPopupMessageForStatusLineOnly() const { return current_popup_message_statusline_only; }
  64. OP_STATUS UpdateWindows(BOOL unused = FALSE);
  65. OP_STATUS UpdateWindowsAllDocuments(BOOL unused = FALSE);
  66. OP_STATUS UpdateAllWindowDefaults(BOOL scroll, BOOL progress, BOOL news, WORD scale, BOOL size);
  67. Window* SignalNewWindow(Window* opener, int width=0, int height=0, BOOL3 scrollbars=MAYBE, BOOL3 toolbars=MAYBE,
  68. BOOL3 focus_document=MAYBE, BOOL3 open_background=MAYBE,
  69. BOOL opened_by_script = FALSE);
  70. /**
  71. * Request the closing of a Window from the platform (UiWindowListener). Window closing
  72. * is asynchronous, and your request may be ignored or denied. For instance, the page
  73. * may display a confirmation dialog to the user, and the user may choose to cancel.
  74. *
  75. * @param[in] window The Window to close. Can not be NULL.
  76. */
  77. void CloseWindow(Window *window);
  78. public:
  79. /**
  80. * Creates a new Window with the help of the platform.
  81. *
  82. * @param[in] new_window YES or MAYBE, if MAYBE it might reuse a window instead
  83. * of creating a new one, in case there is a suitable window to reuse and the
  84. * user preferences are set to not create new windows.
  85. *
  86. * @todo document and clean up arguments
  87. */
  88. Window* GetAWindow(BOOL unused1, BOOL3 new_window, BOOL3 background, int width=0, int height=0, BOOL unused2=FALSE, BOOL3 scrollbars=MAYBE, BOOL3 toolbars=MAYBE,
  89. const uni_char* unused3 = NULL,const uni_char* unused4 = NULL, BOOL unused5 = FALSE, Window* opener = NULL);
  90. #if defined(MSWIN)
  91. Window* GetADDEIdWindow(DWORD id, BOOL &tile_now);
  92. #endif // MSWIN
  93. void SetGlobalImagesSetting(SHOWIMAGESTATE set);
  94. #ifdef _AUTO_WIN_RELOAD_SUPPORT_
  95. void OnTimer() {} // Called 10 times a second
  96. #endif // _AUTO_WIN_RELOAD_SUPPORT_
  97. void SetMaxWindowHistory(int len);
  98. Window* OpenURLNewWindow(const char* url_name, BOOL check_if_expired = TRUE, BOOL3 open_in_new_window = YES, EnteredByUser entered_by_user = NotEnteredByUser);
  99. Window* OpenURLNewWindow(const uni_char* url_name, BOOL check_if_expired = TRUE, BOOL3 open_in_new_window = YES, EnteredByUser entered_by_user = NotEnteredByUser);
  100. static BOOL CheckTargetSecurity(FramesDocument *source_doc, FramesDocument *target_doc);
  101. /**
  102. * @param[in] open_in_other_window If the url is requested to be
  103. * loaded in another window than the current. Depending
  104. * on preferences and other settings it might still b
  105. * loaded in the current window. When this is TRUE,
  106. * open_in_background controls whether the new window
  107. * should be brought to front or not.
  108. * @param[in] open_in_background ignored if open_in_other_window is FALSE.
  109. * If open_in_other_window and open_in_background are both TRUE
  110. * then the new page will, if possible, load in a background
  111. * window, leaving focus on the current window.
  112. */
  113. OP_STATUS OpenURLNamedWindow(URL url, Window* load_window, FramesDocument* doc, int sub_win_id, const uni_char* window_name, BOOL user_initiated, BOOL open_in_other_window = FALSE, BOOL open_in_background = FALSE, BOOL delay_open = FALSE, BOOL open_in_page = FALSE, ES_Thread *thread = NULL, BOOL plugin_unrequested_popup = FALSE);
  114. Window* GetNamedWindow(Window* from_window, const uni_char* window_name, int &sub_win_id, BOOL open_new_window = TRUE);
  115. /**
  116. * @deprecated Old hack hopefully not used much longer. The action that needs the url also needs to keep track of the url itself. This was prone to race conditions and was magic and undocumented.
  117. */
  118. URL GetCurrentClickedURL() const { return curr_clicked_url; }
  119. /**
  120. * @deprecated Old hack hopefully not used much longer. The action that needs the url also needs to keep track of the url itself. This was prone to race conditions and was magic and undocumented.
  121. */
  122. void SetCurrentClickedURL(URL url) { curr_clicked_url = url; }
  123. Window* GetCurrentClickedWindow() const { return curr_clicked_window; }
  124. void SetCurrentClickedWindow(Window* window) { curr_clicked_window = window; }
  125. void ResetCurrentClickedURLAndWindow() { curr_clicked_url = URL(); curr_clicked_window = NULL; }
  126. void UpdateVisitedLinks(const URL& url, Window* exclude_window);
  127. void ReloadAll();
  128. void RefreshAll();
  129. void ShowHistory(BOOL bShow);
  130. //void HandleNewViewers();
  131. /// @deprecated, use Window::OpenURL* or DocumentManager::OpenURL() instead
  132. DEPRECATED(OP_STATUS SetUrlToOpen(const char *url)) { return OpStatus::OK; }
  133. // OpPrefsListener interface
  134. void PrefChanged(OpPrefsCollection::Collections id, int pref, int newvalue);
  135. // Ignore changed strings
  136. void PrefChanged(OpPrefsCollection::Collections, int, const OpStringC &) {}
  137. void HandleCallback(OpMessage msg, MH_PARAM_1 par1, MH_PARAM_2 par2);
  138. /**
  139. * This must be called once and exactly once by a document that has
  140. * blink tags to ensure that it gets Blink calls. When there are no
  141. * document that have called AddDocumentWithBlink then there are no
  142. * calls to Blink.
  143. */
  144. void AddDocumentWithBlink();
  145. /**
  146. * A document that has called AddDocumentWithBlink must call this, at the
  147. * last when it's about to be destroyed. This will remove it from the
  148. * count of objects that are needed Blink calls.
  149. */
  150. void RemoveDocumentWithBlink();
  151. #ifdef _OPERA_DEBUG_DOC_
  152. /**
  153. * Returns the total number of FramesDocuments alive. This includes all Windows and all history.
  154. */
  155. unsigned GetDocumentCount() { return g_opera->doc_module.m_total_document_count; }
  156. /**
  157. * Returns a count of documents currently being active, i.e. current in their tabs, including all
  158. * active sub documents. Documents in history are not included. This will do an active
  159. * count operation so it's not suitable for performance sensitive operations.
  160. */
  161. unsigned GetActiveDocumentCount();
  162. #endif // _OPERA_DEBUG_DOC_
  163. OP_STATUS OnlineModeChanged();
  164. /**< Tells all windows that there has been a change in online mode. The
  165. preference PrefsCollectionNetwork::OfflineMode should already have the
  166. value we're updating too (e.g., when this function is called as we go
  167. online, it should already the TRUE.)
  168. @return OpStatus::OK or OpStatus::ERR_NO_MEMORY (on failure, all
  169. windows will have been told, but any number of them might have
  170. failed.) */
  171. #ifdef AB_ERROR_SEARCH_FORM
  172. /**
  173. * Returns the last text the user typed, set by SetLastTypeduserText()
  174. */
  175. const uni_char* GetLastTypedUserText() { return m_last_typed_user_text ? m_last_typed_user_text->CStr() : NULL; }
  176. /**
  177. * Sets the last text the user input on the address bar.
  178. * This value will only be held during the Window::OpenURL call
  179. * As it's necessary to workaround the nested calls within the
  180. * URL APIs. This information will be used in the OpIllegalHost
  181. * page to present a neatly built search form with what the user
  182. * input
  183. */
  184. void SetLastTypedUserText(OpString* user_text) { m_last_typed_user_text = user_text; }
  185. #endif //AB_ERROR_SEARCH_FORM
  186. /**
  187. * Tells window_manager that a window should use the privacy mode
  188. * network context. This means that the window's cache, cookies etc
  189. * will be separated from regular browsing, so that regular windows
  190. * won't have access to data loaded in the private context.
  191. *
  192. * WindowCommander counts how many windows use the context and deletes
  193. * it when no one are using it anymore. It's therefor important that
  194. * Windows call this function only once (when entering privacy mode),
  195. * and also calls RemoveWindowFromPrivacyModeContext exactly once (when
  196. * being deleted or exiting privacy mode).
  197. *
  198. * @return the ID of the context to use.
  199. */
  200. URL_CONTEXT_ID AddWindowToPrivacyModeContext();
  201. /**
  202. * Call this once when a window exits privacy mode or closes.
  203. * @see AddWindowToPrivacyModeContext()
  204. */
  205. void RemoveWindowFromPrivacyModeContext();
  206. /**
  207. * Get context id to use for all URLs loaded in windows in privacy
  208. * mode (and only for windows in privacy mode)
  209. */
  210. URL_CONTEXT_ID GetPrivacyModeContextId() { return m_privacy_mode_context_id; }
  211. /**
  212. * Get number of windows/tabs currently in privacy mode.
  213. */
  214. int GetNumberOfWindowsInPrivacyMode() { return m_number_of_windows_in_privacy_mode; }
  215. private:
  216. /**
  217. * Call this as last window in privacy mode is closed or disables privacy mode.
  218. * It will clean up the private data.
  219. */
  220. void ExitPrivacyMode();
  221. #ifdef WEB_TURBO_MODE
  222. public:
  223. /**
  224. * Call this function to make sure the special turbo mode network
  225. * context is created before using it. The first time in a browser
  226. * session this function is called the network context will be
  227. * created. The context will remain intact until the browser session
  228. * ends.
  229. *
  230. * The context MUST be used for all URLs loaded from windows with
  231. * turbo mode enabled. Doing so will ensure that the window's cache
  232. * will be separated from regular browsing, so that regular windows
  233. * won't have access to data loaded in the private context.
  234. *
  235. * @return OpStatus::OK on success. OpStatus::ERR or OpStatus::ERR_NO_MEMORY on failure.
  236. */
  237. OP_STATUS CheckTuboModeContext();
  238. /**
  239. * @return The context ID to use for all URLs loaded in windows using turbo mode
  240. */
  241. URL_CONTEXT_ID GetTurboModeContextId() { return m_turbo_mode_context_id; }
  242. #endif // WEB_TURBO_MODE
  243. private:
  244. class BlinkTimerListener : public OpTimerListener
  245. {
  246. private:
  247. void PostNewTimerMessage();
  248. BOOL m_is_active;
  249. BOOL m_message_in_queue;
  250. OpTimer* m_timer;
  251. public:
  252. BlinkTimerListener();
  253. ~BlinkTimerListener();
  254. virtual void OnTimeOut(OpTimer* timer);
  255. void SetEnabled(BOOL enable);
  256. };
  257. BlinkTimerListener m_blink_timer_listener;
  258. int m_documents_having_blink;
  259. URL_CONTEXT_ID m_privacy_mode_context_id; // context id to use for URLs loaded in windows with privacy mode
  260. int m_number_of_windows_in_privacy_mode; // how many windows are currently in privacy mode
  261. #ifdef WEB_TURBO_MODE
  262. URL_CONTEXT_ID m_turbo_mode_context_id; // context id to use for URLs loaded in turbo mode
  263. #endif //WEB_TURBO_MODE
  264. #ifdef AB_ERROR_SEARCH_FORM
  265. OpString* m_last_typed_user_text;
  266. #endif //AB_ERROR_SEARCH_FORM
  267. };
  268. #endif // DOCHAND_WINMAN_H