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.

docman.h 74KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759
  1. /* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4; c-file-style:"stroustrup" -*-
  2. **
  3. ** Copyright (C) 1995-2012 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_DOCMAN_H
  9. #define DOCHAND_DOCMAN_H
  10. #include "modules/doc/doctypes.h"
  11. #include "modules/doc/css_mode.h"
  12. #include "modules/doc/documentorigin.h"
  13. #include "modules/dochand/documentreferrer.h"
  14. #include "modules/hardcore/unicode/unicode.h"
  15. #include "modules/prefs/prefsmanager/prefstypes.h"
  16. #include "modules/viewers/viewers.h"
  17. #include "modules/url/url2.h"
  18. #include "modules/url/url_loading.h"
  19. #include "modules/util/simset.h"
  20. #include "modules/util/opfile/unistream.h"
  21. #include "modules/dom/domenvironment.h"
  22. #include "modules/ecmascript_utils/esthread.h"
  23. #include "modules/security_manager/include/security_manager.h"
  24. #include "modules/idle/idle_detector.h"
  25. #include "modules/windowcommander/OpViewportController.h"
  26. class OpHistoryUserData;
  27. #ifdef TRUST_RATING
  28. #include "modules/dochand/fraud_check.h"
  29. #endif // TRUST_RATING
  30. class FramesDocElm;
  31. class FramesDocument;
  32. class VisualDevice;
  33. class PrintDevice;
  34. class DocListElm;
  35. class HTML_Element;
  36. class URL;
  37. class Viewer;
  38. #ifdef CLIENTSIDE_STORAGE_SUPPORT
  39. class OpStorageManager;
  40. #endif // CLIENTSIDE_STORAGE_SUPPORT
  41. class ES_Thread;
  42. class ES_OpenURLAction;
  43. class ES_Runtime;
  44. class DOM_ProxyEnvironment;
  45. class DOM_Object;
  46. class ES_PersistentValue;
  47. #ifdef _WML_SUPPORT_
  48. class WML_Context;
  49. #endif // _WML_SUPPORT_
  50. #ifdef WIC_USE_DOWNLOAD_CALLBACK
  51. class TransferManagerDownloadCallback;
  52. #endif //WIC_USE_DOWNLOAD_CALLBACK
  53. #if defined _SSL_SUPPORT_ && !defined _EXTERNAL_SSL_SUPPORT_ && !defined _CERTICOM_SSL_SUPPORT_
  54. struct SSL_dialog_config;
  55. class SSL_Certificate_Installer_Base;
  56. #endif // _SSL_SUPPORT_ && !_EXTERNAL_SSL_SUPPORT_ && !_CERTICOM_SSL_SUPPORT_
  57. #ifdef SCOPE_PROFILER
  58. class OpProbeTimeline;
  59. class OpProfilingSession;
  60. #endif // SCOPE_PROFILER
  61. #define UNITE_WARNING_PAGE_URL "uniteadminwarning"
  62. #define OPERA_CLICKJACK_BLOCK_URL "opera:clickjackingblock"
  63. #define OPERA_CLICKJACK_BLOCK_URL_PATH "clickjackingblock"
  64. /** Loading states for a DocumentManager. */
  65. enum DM_LoadStat
  66. {
  67. NOT_LOADING = 0,
  68. /**< State when nothing is being loaded. */
  69. WAIT_FOR_HEADER,
  70. /**< First state when loading a URL: set when the URL is requested and
  71. remains set until a MSG_HEADER_LOADED message is received. */
  72. WAIT_FOR_ACTION,
  73. /**< Optional state set after WAIT_FOR_HEADER if the information in the
  74. response headers was inconclusive (not enough to determine how to
  75. process the resource.) When (more) data is receieved, we use it to
  76. try to figure out what to do. */
  77. WAIT_FOR_LOADING_FINISHED,
  78. /**< Optional state set when the loaded resource will not be loaded as a
  79. document, but will be handled by us in some way once it has finished
  80. loading. */
  81. WAIT_FOR_USER,
  82. /**< Set if we display some sort of dialog asking the user what to do, for
  83. the duration of that dialog. */
  84. WAIT_FOR_ECMASCRIPT,
  85. /**< Set if the resource being loaded will replace the current document,
  86. while we process unload events in that document. */
  87. DOC_CREATED,
  88. /**< Set once we've created a document for the resource being loaded.
  89. From now on, that document is in charge of handling the loading, and
  90. we just wait for it to finish. */
  91. WAIT_MULTIPART_RELOAD
  92. /**< A MSG_MULTIPART_RELOAD has been received, and we're now waiting for
  93. messages relating to the next body part. Much like WAIT_FOR_HEADER,
  94. but with some special handling for the case that there isn't another
  95. body part after all. */
  96. };
  97. /**
  98. * Checks if the url is about:blank (or in case of selftests opera:blanker).
  99. */
  100. BOOL IsAboutBlankURL(const URL& url);
  101. /**
  102. * Checks if an URL has enough information in itself to build a security context from it or not. If this returns TRUE then it has
  103. * enough information to let it be the security context. If it returns FALSE then it's a data: url or javascript: url or about:blank
  104. * and need to inherit security from someone else unless there is nobody else.
  105. */
  106. BOOL IsURLSuitableSecurityContext(URL url);
  107. /** Local history element. DocListElm objects represent the different states a
  108. window, frame or iframe can shift between as part of history navigation.
  109. Each history element begins at a certain window global history number
  110. (DocListElm::number) and continues to the next element's number minus one,
  111. or, if it is the last element its history list, to the last number that its
  112. parent document exists at, or, if it has no parent document, to the end of
  113. the history as determined by Window::GetHistoryMax(). This means that any
  114. DocListElm can be active at any number of history positions, and that
  115. navigation between two global history positions might not affect which is
  116. the active history element in a local history list. */
  117. class DocListElm
  118. : public Link
  119. {
  120. private:
  121. URL url;
  122. DocumentReferrer referrer_url;
  123. const int m_id;
  124. /**< The ID for this DocListElm. */
  125. BOOL send_to_server;
  126. FramesDocument* doc;
  127. int number;
  128. int last_scale;
  129. LayoutMode last_layout_mode;
  130. OpRect visual_viewport;
  131. BOOL has_visual_viewport;
  132. #ifdef PAGED_MEDIA_SUPPORT
  133. int current_page;
  134. #endif
  135. BOOL owns_doc;
  136. BOOL replaceable;
  137. BOOL precreated;
  138. OpStringS title;
  139. BOOL script_generated_doc;
  140. BOOL replaced_empty_position;
  141. #ifdef _WML_SUPPORT_
  142. WML_Context* wml_context;
  143. #endif // _WML_SUPPORT_
  144. friend class DocumentManager;
  145. BOOL MaybeReassignDocOwnership();
  146. /**< If this history position owns its document but shares it with a later
  147. history position, reset 'doc' to NULL and assign ownership to the other
  148. history position. This is only valid if this history position is about
  149. to be removed (called from Out()) or is about to have its document
  150. replaced by another (called from ReplaceDoc().)
  151. @return TRUE if this history owned its document and reassigned that
  152. ownership to another history position, FALSE otherwise. */
  153. ES_PersistentValue *m_data;
  154. OpHistoryUserData* m_user_data;
  155. /**< User data, owned by this DocListElm. */
  156. public:
  157. DocListElm(const URL& doc_url, FramesDocument* d, BOOL own, int n, UINT32 id);
  158. ~DocListElm();
  159. int GetID() const { return m_id; }
  160. /**< Returns the ID for this DocListElm. */
  161. DocListElm* Suc() const { return (DocListElm*) Link::Suc(); }
  162. /**< Returns the previous local history element or NULL if there is none.
  163. This is the element that would be activated next in this document
  164. manager during backwards history navigation (but many history steps
  165. might be required for that to happen.) */
  166. DocListElm* Pred() const { return (DocListElm*) Link::Pred(); }
  167. /**< Returns the next local history element or NULL if there is none. This
  168. is the element that would be activated next in this document manager
  169. during forwards history navigation (but many history steps might be
  170. required for that to happen.) */
  171. FramesDocument* Doc() const { return doc; }
  172. /**< Returns the active document at this local history element. Never
  173. returns NULL. Note that several consecutive history elements can share
  174. the same document, representing different scroll positions or states of
  175. that document. */
  176. int Number() const { return number; }
  177. /**< Returns the first window history number at which this local history
  178. element is used. If this is the same as the following local history
  179. element's number, this local history element is dead and will be purged
  180. by the next call to DocumentManager::HistoryCleanup(). */
  181. const uni_char* Title() const { return title.CStr(); }
  182. /**< Returns the title of the document at this history position. */
  183. URL& GetUrl() { return url; }
  184. /**< Returns the URL of the document at this history position.*/
  185. DocumentReferrer GetReferrerUrl() { return referrer_url; }
  186. /**< Returns the referrer URL used to load this document (which will also be
  187. used if the URL is loaded again in order to activate this history
  188. position.) */
  189. BOOL GetOwnsDoc() { return owns_doc; }
  190. /**< Returns TRUE if this history element owns its document. The first
  191. element in the list that has a given document always owns it. */
  192. BOOL IsReplaceable() { return replaceable; }
  193. /**< Returns TRUE if this history element should be replaced if succeeded by
  194. another one (that is, if this element should only exist as the last
  195. element.) */
  196. void SetIsReplaceable() { replaceable = TRUE; }
  197. /**< See IsReplaceable(). */
  198. BOOL IsPreCreated() { return precreated; }
  199. /**< Returns TRUE if this history position and its document was precreated,
  200. that is, it was created before we knew that we actually wanted to
  201. create it. When we "discover" that we want to create a document, we
  202. should probably reuse this. */
  203. void SetIsPreCreated(BOOL value) { precreated = value; }
  204. /**< Called when we determine that a precreated document either won't be
  205. used or when it has been used. */
  206. int GetLastScale() const { return last_scale; }
  207. /**< Returns the scale level used last time this document was displayed. */
  208. void SetLastScale(int scale) { last_scale = scale; }
  209. /**< Sets the scale level currently used to display this document. */
  210. LayoutMode GetLastLayoutMode() const { return last_layout_mode; }
  211. /**< Returns the layout mode used last time this document was displayed. */
  212. void SetLastLayoutMode(LayoutMode mode) { last_layout_mode = mode; }
  213. /**< Set the layout mode that was used when this document was displayed. */
  214. BOOL HasVisualViewport() const { return has_visual_viewport; }
  215. /**< Returns TRUE if a visual viewport rectangle has been set for this history element. */
  216. void ClearVisualViewport() { has_visual_viewport = FALSE; }
  217. /**< Make the visual viewport rectangle invalid. */
  218. const OpRect& GetVisualViewport() const { return visual_viewport; }
  219. /**< Returns the visual viewport stored in this history element.
  220. Not relevant (that is, not kept up-to-date) for the current element. */
  221. void SetVisualViewport(const OpRect& viewport) { visual_viewport = viewport; has_visual_viewport = TRUE; }
  222. /**< Sets the visual viewport rectangle for this history element. */
  223. void SetUserData(OpHistoryUserData* user_data);
  224. /**< Associate user data with this DocListElm. This object assumes ownership of the user_data. */
  225. OpHistoryUserData* GetUserData() const;
  226. /**< Return user data associated with this DocListElm. */
  227. #ifdef PAGED_MEDIA_SUPPORT
  228. int GetCurrentPage() { return current_page; }
  229. /**< Returns the current page displayed at this history position, if in
  230. paged media mode. Much like an extra scroll position dimension. */
  231. void SetCurrentPage(int page) { current_page = page; }
  232. /**< Set the current page displayed at this history position. */
  233. #endif // PAGED_MEDIA_SUPPORT
  234. OP_STATUS SetTitle(const uni_char* val);
  235. /**< Sets the title of the document at this history position. */
  236. void SetUrl(const URL &new_url) { url = new_url; }
  237. /**< Sets the URL displayed at this history position. */
  238. BOOL ShouldSendReferrer() { return send_to_server; }
  239. /**< Returns FALSE if the referrer URL should not be sent to the server
  240. * when loading the URL. */
  241. void SetReferrerUrl(const DocumentReferrer& ref_url, BOOL isend_to_server = TRUE) { referrer_url = ref_url; send_to_server = isend_to_server; }
  242. /**< Sets the referrer URL used to load the URL displayed at this history
  243. * position.
  244. * @param isend_to_server Set to FALSE if it should not be sent to the
  245. * server when loading the URL. */
  246. void SetOwnsDoc(BOOL val) { owns_doc = val; }
  247. /**< Sets the flag that determines whether this history position owns its
  248. document (meaning it deletes the document when its destroyed) or if
  249. it shares it with some other history position that owns it.
  250. The history position that owns a document is always the first one in
  251. the list that has that particular document. The flag is only to be
  252. modified when the list is modified (for instance when the previous
  253. owner position is removed while other positions sharing the document
  254. remain.) Use with care. */
  255. void SetNumber(int num) { number = num; }
  256. /**< Updates the history number of this history position. The history
  257. number determines where in the global history this position begins.
  258. Use with extreme care! Setting an invalid history number on a history
  259. position causes history bugs and quite possibly crashes. */
  260. void Out();
  261. /**< Removes this history position from the history list it is in. If this
  262. history position owns its document but shares it with another history
  263. position in the list, it reassigns ownership of the document to that
  264. history position and resets the document pointer to NULL. */
  265. void ReplaceDoc(FramesDocument* d);
  266. /**< Replace the document at this history position with 'd' (or set it )*/
  267. BOOL IsScriptGeneratedDocument() { return script_generated_doc; }
  268. /**< Returns TRUE if this document was generated a script (either via
  269. document.open or via returning a string from a javascript: URL.)
  270. Script generated documents have URL:s that define their security
  271. context but aren't necessarily the origin of the actual contents, so
  272. such history positions are never ever reloaded during history
  273. navigation and not automatically replaced even though their URL is
  274. a javascript: URL, about:blank or an empty URL. */
  275. void SetScriptGeneratedDocument(BOOL value = TRUE) { script_generated_doc = value; }
  276. /**< Sets the flag that determines that this is a script generated
  277. document. */
  278. BOOL ReplacedEmptyPosition() { return replaced_empty_position; }
  279. /**< Returns TRUE if this history position replaced an empty history
  280. position when it was added to the history list. An empty history
  281. position is defined as one having the URL about:blank, or a javascript:
  282. URL, or an empty URL, and that is the first history position in the
  283. history list. The information is used to replace this history position
  284. as well, when an inline script or 'load' event handler loads another
  285. document, even if this history position wouldn't be considered empty
  286. otherwise. */
  287. void SetReplacedEmptyPosition() { replaced_empty_position = TRUE; }
  288. /**< Sets the flag that determines that this document position replaced an
  289. empty history position. */
  290. BOOL HasPreceding();
  291. /**< Returns TRUE if there is a history position before this one in the
  292. list. Simply checking 'Pred() != NULL' is not necessarily accurate,
  293. since if the immediately preceding element(s) has the same number as
  294. this one, they are dead and will be removed in the near future by a
  295. call to DocumentManager::HistoryCleanup(). */
  296. #ifdef _WML_SUPPORT_
  297. WML_Context* GetWmlContext() { return wml_context; }
  298. /**< Returns this history position's WML context or NULL if none has been
  299. set. */
  300. void SetWmlContext(WML_Context *new_ctx);
  301. /**< Sets this history position's WML context. If the new context is not
  302. the same as the old one, its reference counter is incremented and the
  303. old context's is decremented. The reference is released when this
  304. history position is destroyed. */
  305. #endif // _WML_SUPPORT_
  306. void SetData(ES_PersistentValue *data);
  307. /**< Sets the history element state's data.
  308. The history element becomes the owner of the data. */
  309. ES_PersistentValue *GetData() { return m_data; }
  310. /**< Returns the history element state's data */
  311. };
  312. /** A big class that mostly manages documents.
  313. There is one DocumentManager instance for each Window object, and one for
  314. each frame and iframe displayed in documents. (There are also
  315. DocumentManager objects owned by FramesDocElm objects that represent
  316. FRAMESET elements; these DocumentManager objects are unused and supposedly
  317. always empty.) The DocumentManager is responsible for initially requesting
  318. URL:s loaded in windows (or frames or iframes,) handling the loading up
  319. until (in the common case) a document is created (after which the document
  320. loads on its own with the DocumentManager mostly waiting around for it to
  321. finish) and for history management.
  322. @section loading Loading
  323. Loading is started by a call to the function OpenURL(), usually called from
  324. Window::OpenURL() (when the request comes directly from the UI) or
  325. DocumentManager::LoadPendingUrl via DocumentManager::SetUrlLoadOnCommand
  326. called from WindowManager::OpenURLNamedWindow (when the request comes from
  327. inside the document complex, such as when following a link in a web page) or
  328. from ES_OpenURLAction::PerformBeforeUnload() (when the request comes from a
  329. script, or when a previous call to OpenURL() was delayed pending some script
  330. thread's execution.)
  331. For URL schemes that produce data directly (http:, file:, ftp: and data:,
  332. but not mailto: or telnet:, for instance) OpenURL() usually ends up calling
  333. URL::LoadDocument() to initiate the request, and setting the 'load_stat'
  334. member variable to WAIT_FOR_HEADER, indicating we're now waiting for the
  335. request to return something.
  336. For the javascript: URL scheme, the request to open it is simply redirected
  337. to the current document's scripting environment, after first creating an
  338. empty one if there was no current document.
  339. For other supported URL schemes, such as mailto: or telnet:, OpenURL()
  340. contains special code for handling each scheme. For unsupported URL schemes
  341. OpDocumentListener::OnUnknownProtocol() is called, and if it doesn't claim
  342. to have handled the request, an error page is generated, or a console error
  343. message is posted, if the URL was not entered by the user and the request
  344. was not user initiated.
  345. @subsection headers When headers are loaded
  346. When the URL module reports that all response headers from the request have
  347. been processed (which, for non-HTTP(S) URL:s mostly means the URL request
  348. was successful and has started returning data) HandleHeadersLoaded() is
  349. called to inspect the URL:s content type to decide what to do. Most of the
  350. actual inspection and decision making is left to the Viewers class in the
  351. viewers module, called from UpdateAction().
  352. If no decision can be made without inspecting the actual data returned by
  353. the request, the 'load_stat' member variable is set to WAIT_FOR_ACTION,
  354. which has the effect that HandleHeadersLoaded() is called again when more
  355. data is received, until a decision has been made.
  356. If a decision is made, and the action chosen was either VIEWER_OPERA (the
  357. default for content types handled internally by Opera) or VIEWER_PLUGIN,
  358. HandleByOpera() is called to continue with the handling. HandleByOpera()
  359. determines what to do depending on the type of the content (which is set by
  360. the Viewers system as well) and generally either calls other parts of Opera
  361. to handle the content, or creates a new FramesDocument for loading the
  362. content as a document, or, if the request was some sort of reload, tells the
  363. current document to reload itself from the new content, or if the URL loaded
  364. ended up being redirected to the same URL as the current document with a
  365. fragment identifier, scrolls the current document to that fragment
  366. identifier. If a document (the current document) is now in charge of
  367. handling the loading, HandleByOpera() sets the 'load_stat' member variable
  368. to DOC_CREATED. In other cases, loading is either stopped now, or the
  369. 'load_stat' member variable is set to WAIT_FOR_LOADING_FINISHED which means
  370. that we simply wait for the loading to finish to do something at that time
  371. instead.
  372. @subsection unload The unload event
  373. The previous section's description of what happens when HandleByOpera()
  374. decides to create a new document is somewhat over-simplified. If there is a
  375. previous document and it has a scripting environment with an unload event
  376. handler registered, an unload event is fired at this pointer. Since
  377. processing of that event is asynchronous, and must be completed before a new
  378. document is created, instead of setting the 'load_stat' member to
  379. DOC_CREATED, HandleByOpera() may set it to WAIT_FOR_ECMASCRIPT.
  380. In that case, ES_OpenURLAction::PerformAfterUnload posts a message to the
  381. DocumentManager (MSG_HANDLE_BY_OPERA) that, when received by the
  382. DocumentManager, repeats the call to HandleByOpera(), which then creates a
  383. FramesDocument object and sets the 'load_stat' member variable to
  384. DOC_CREATED.
  385. @subsection finish When loading finished
  386. If the URL request resulted in a document being loaded or reloaded, not much
  387. is done by the DocumentManager once the loading finishes. The 'load_stat'
  388. member variable is reset to NOT_LOADING to indicate that the DocumentManager
  389. is now idle. If all DocumentManagers in the window are now idle, the
  390. appropriate window-level loading finished actions are initiated via a call
  391. to Window::EndProgressDisplay().
  392. If the URL request did not result in a document being loaded and the loading
  393. was not abandoned as soon as that was decided, the function
  394. HandleAllLoaded() performs the necessary post-processing actions once the
  395. URL has finished loading. This includes for instance performing certificate
  396. installation if a X.509 certificate is loaded, or executing an external
  397. application with an argument containing path of the URL:s cache file.
  398. @subsection notmodified Conditional reload not reloading
  399. Another special case loading result is if a conditional reload ("check if
  400. modified") is performed and the URL hadn't changed (the server returns a
  401. "304 Not modified" answer.) In such a case, the function
  402. HandleDocumentNotModifed() is called. It will essentially either call
  403. HandleAllLoaded() to finish this up, or redirect to HandleHeaderLoaded() if
  404. a new document should be created anyway (thus ignoring the fact that a
  405. request to the server resulted in no data, instead loading the document from
  406. the already cached resource.)
  407. @section history History
  408. On the window level, the history is simply a sequential list of numbers, one
  409. per history position, starting with Window::GetHistoryMin() and ending with
  410. Window::GetHistoryMax() (both included.) The current history position is
  411. Window::GetCurrentHistoryPos() (same as Window::GetCurrentHistoryNumber().)
  412. In each DocumentManager, the history is instead a list of DocListElm
  413. objects. Each DocListElm has a pointer to the document to make active when
  414. DocListElm is the current element, and some extra state information (scroll
  415. position, current spatial navigation state and such.) A DocListElm can
  416. cover any number of (sequential) history numbers. That is, when navigating
  417. between two top-level history positions (two different history numbers) it
  418. is possible that the same DocListElm object is selected as the current
  419. history position in a DocumentManager, and thus that the navigation has no
  420. effect in the location the DocumentManager represents (the top-level
  421. document, or a frame or iframe.) Typically, history navigation will affect
  422. at least one DocumentManager, and possibly several, or even all.
  423. DocListElm objects in DocumentManagers are selected top-down when a new
  424. history number becomes the current. That is, first the Window's
  425. DocumentManager is told to activate its DocListElm for that history number.
  426. Then the document pointed to by that DocListElm is asked to propagate the
  427. history number down into any frames or iframes that it has, and the
  428. DocumentManagers in them activate their DocListElms for that history number,
  429. and so on. This propagation continues through the whole active document
  430. tree even if some DocumentManagers along the way do not change which
  431. DocListElm is the current, since descendant DocumentManagers may be
  432. affacted even if their ancestors are not.
  433. @subsection setcurrenthistorypos SetCurrentHistoryPos()
  434. The function in DocumentManager that is called to activate the correct
  435. DocListElm for a given history number is SetCurrentHistoryPos(). It finds
  436. the right DocListElm by searching backwards in the list of DocListElm
  437. objects for the last one with a history number greater than or equal to the
  438. history number being activated. If there is no current DocListElm (happens
  439. when restoring a session, for instance) or if the found DocListElm has a
  440. different document, or if the document isn't loaded, SetCurrentNew() is
  441. called to activate and/or load the new document. */
  442. class DocumentManager
  443. : private MessageObject
  444. , public DOM_ProxyEnvironment::RealWindowProvider
  445. {
  446. public:
  447. /** Indication of what sort of history navigation the current document
  448. loading process is part of. */
  449. enum HistoryDirection
  450. {
  451. DM_NOT_HIST = 0,
  452. /**< No history navigation (normal document load.) */
  453. DM_HIST_BACK = 1,
  454. /**< Backward history navigation. */
  455. DM_HIST_FORW = 2
  456. /**< Forward history navigation. */
  457. };
  458. private:
  459. Window* window;
  460. /**< The window in which this document manager lives. Same (obviously) for
  461. all document managers in the window, including those in frames and
  462. iframes. Set by the constructor, and never changed. Never NULL. */
  463. MessageHandler* mh;
  464. /**< Message handler specific to this document manager. Used for all URL
  465. loads performed by this document manager and documents that live in it.
  466. Created by second stage construction and destroyed together with the
  467. document manager. Never NULL (except during construction.) */
  468. FramesDocElm* frame;
  469. /**< The frame or iframe that this document manager belongs to. That is,
  470. the frame or iframe whose documents this document manager manages.
  471. Only NULL for the top-level document manager, so can be used to
  472. determine whether this is the top-level document manager. */
  473. FramesDocument* parent_doc;
  474. /**< The document that contains 'frame'. Only NULL for the top-level
  475. document manager, so can be used to determine whether this is the
  476. top-level document manager. */
  477. VisualDevice* vis_dev;
  478. /**< Visual device owned either by 'window' (if this is the top-level
  479. document manager) or 'frame'. */
  480. Head doc_list;
  481. /**< List of history positions (DocListElm objects.) Can be empty. */
  482. Head unlinked_doc_list;
  483. /**< List of history positions removed from 'doc_list' and not immediately
  484. destroyed. May be reinsterted into 'doc_list' at a later time. */
  485. DocListElm* current_doc_elm;
  486. /**< The current history position. Can be NULL. Always an element from
  487. 'doc_list' when not NULL. */
  488. int GetNextDocListElmId();
  489. /**< Get the ID to use when creating a new DocListElm. */
  490. int history_len;
  491. /**< Pointless waste of space^A^K Maintenance nightmare^A^K Number of
  492. history positions in 'doc_list'. */
  493. Head queued_messages;
  494. /**< List of messages queued (received but not processed) while in a call to
  495. a function that reenters the message loop. A workaround for use of
  496. blocking dialogs that will be removed when that problems is solved. */
  497. BOOL queue_messages;
  498. /**< If TRUE, any messages received will be queued for later processing.
  499. Set to TRUE before a call to a function that reenters the message loop,
  500. and back to FALSE again when the queue has been flushed. That is, it
  501. remains TRUE after the troublesome function call has ended, until all
  502. the message that were queued during it (and after it) has been
  503. processed. */
  504. DM_LoadStat load_stat;
  505. /**< Current load status. */
  506. URL current_url;
  507. /**< While not loading, the URL of the current document. While loading, the
  508. URL we're loading. */
  509. BOOL current_url_is_inline_feed;
  510. /**< Whether the current URL is an webfeed to be displayed with the generated
  511. feed viewer page. */
  512. DocumentOrigin* current_loading_origin;
  513. /**< The origin for the document we are loading or NULL. */
  514. URL initial_request_url;
  515. /**< Set by OpenURL() to the same value it sets to current_url. When the
  516. loading URL is redirected, current_url is updated, but
  517. initial_request_url remains referencing the URL we initially
  518. requested. */
  519. URL_InUse current_url_used;
  520. /**< Use reference for 'current_url'. Set when 'load_stat' is/becomes not
  521. NOT_LOADING and unset when 'load_stat' is/becomes NOT_LOADING. */
  522. IAmLoadingThisURL current_url_reserved;
  523. /**< Loading reference for 'current_url'. Set once the URL has successfully
  524. been requested and unset when 'load_stat' becomes NOT_LOADING. */
  525. DocumentReferrer referrer_url;
  526. /**< Referrer URL to use/used when requesting 'current_url'. */
  527. BOOL send_to_server;
  528. /**< FALSE if the referrer URL should not be sent to the server when
  529. * loading the URL. */
  530. ViewAction current_action;
  531. /**< What to do with the URL currently being loaded. Is VIEWER_NOT_DEFINED
  532. while not loading. Primarily set by UpdateAction(), which asks the
  533. viewers database. */
  534. ViewActionFlag current_action_flag; // To overide flags on the viewer (which would be default)
  535. /**< Modification flags for 'current_action'. Typically modifies what
  536. VIEWER_SAVE means. */
  537. uni_char* current_application;
  538. /**< Application to call to handle the current URL. Only relevant when
  539. 'current_action' is VIEWER_APPLICATION. */
  540. URL url_load_on_command;
  541. /**< URL to request with a delay. Set by SetUrlLoadOnCommand(), and
  542. requested by LoadPendingUrl() which is typically called when a
  543. MSG_URL_LOAD_NOW message is received. */
  544. BOOL url_replace_on_command;
  545. /**< If TRUE, then LoadPendingUrl() will replace the current history
  546. position when it loads 'url_load_on_command'. */
  547. BOOL user_auto_reload;
  548. /**< User auto reload flag (the "Reload every" context menu choice, I
  549. think.) */
  550. BOOL reload;
  551. /**< Reload flag. TRUE while loading during any kind of reload (F5, META
  552. refresh, user auto reload, history navigation to non-cached document
  553. and probably others.) */
  554. BOOL was_reloaded;
  555. /**< Last-load-reloaded-document flag. TRUE after finishing any kind of
  556. reload (F5, META refresh, user auto reload, history navigation to
  557. non-cached document and probably others.) Set after the initial
  558. loading is finished and the normal state flags reset. */
  559. BOOL were_inlines_reloaded;
  560. /**< Last-load-reloaded-inlines flag. TRUE after finishing any kind of
  561. reload where the reload_inlines flag was set. Set after the initial
  562. loading is finished and the normal state flags reset. */
  563. BOOL were_inlines_requested_conditionally;
  564. /**< Last-load-requested-inlines-conditionally flag. TRUE after finishing
  565. any kind of reload where the request_inlines_conditionally flag was
  566. set. Set after the initial loading is finished and the normal state
  567. flags reset. */
  568. BOOL redirect;
  569. /**< Redirect flag. TRUE while loading caused by a META refresh that
  570. redirected to another URL. Not related to HTTP redirects. */
  571. BOOL replace;
  572. /**< Replace flag. If TRUE when a new history position is created, the
  573. current history position is replaced. */
  574. BOOL scroll_to_fragment_in_document_finished;
  575. /**< After loading a document we register the url fragment, but we should
  576. only scroll to it if it's an initial load, not if it's history navigation
  577. or reloads. */
  578. BOOL load_image_only;
  579. /**< If TRUE, the current load was started in response to a
  580. OpInputAction::ACTION_OPEN_IMAGE and will refuse to do anything if the
  581. loaded URL turns out not to be an image. */
  582. BOOL save_image_only;
  583. /**< If TRUE, the current load was started in response to a
  584. OpInputAction::ACTION_SAVE_IMAGE and will refuse to do anything if the
  585. loaded URL turns out not to be an image. */
  586. BOOL is_handling_message;
  587. /**< TRUE while in a call to HandleLoading() handling a loading related
  588. message. HandleLoading() does nothing if set when it's called, to
  589. protect against recursive calls. */
  590. BOOL is_clearing;
  591. /**< TRUE while in a call to Clear(), to avoid doing unnecessary things in
  592. other functions while clearing the document manager. */
  593. BOOL has_posted_history_cleanup;
  594. /**< TRUE if a MSG_HISTORY_CLEANUP message has been posted and not yet
  595. received, to avoid having more than posted at a time. */
  596. BOOL has_set_callbacks;
  597. /**< TRUE if the various message callbacks have been set. */
  598. BOOL error_page_shown;
  599. /**< TRUE if the document currently displayed is a generated error page. */
  600. int use_history_number;
  601. /**< Normally -1. If >= 0, this number is used for the next history
  602. position created. Typically used to replace a specific history
  603. position when loading a document. */
  604. BOOL use_current_doc;
  605. /**< Flag that makes HandleByOpera() call UpdateCurrentDoc() instead of
  606. SetCurrentDoc(), makes SetCurrentDoc() go ahead instead of reporting
  607. errors in error situations, and makes UpdateCurrentDoc() just update
  608. the URL of the current document instead of reloading it. Only set to
  609. TRUE immediately before calls to SetCurrentDoc(), so the rest is
  610. probably irrelevant. */
  611. BOOL reload_document;
  612. BOOL conditionally_request_document;
  613. BOOL reload_inlines;
  614. BOOL conditionally_request_inlines;
  615. CheckExpiryType check_expiry; // Controls whether to check expiry of inline urls, including frames.
  616. // Will be updated each time history is walked or new url is loaded.
  617. HistoryDirection history_walk; // This flag is set to DM_HIST_BACK or
  618. // DM_HIST_FORW when activating a new
  619. // document in history.
  620. URL_ID pending_refresh_id; // refresh id received while in preview mode
  621. URL_ID waiting_for_refresh_id; // refresh id to load when receiving next
  622. // refresh message (MSG_START_REFRESH_LOADING),
  623. // if match.
  624. unsigned long waiting_for_refresh_delay;
  625. double start_navigation_time_ms; //< The time in GetRuntimeMS scale that the navigation started.
  626. BOOL restart_parsing; // if decoding with wrong character set
  627. BOOL pending_viewport_restore;
  628. #ifdef _PRINT_SUPPORT_
  629. FramesDocument* print_doc;
  630. FramesDocument* print_preview_doc;
  631. VisualDevice* print_vd;
  632. VisualDevice* print_preview_vd;
  633. #endif // _PRINT_SUPPORT_
  634. BOOL pending_url_user_initiated;
  635. /** TRUE if the user manually entered the url that is loading. */
  636. BOOL user_started_loading;
  637. /** TRUE if the user performed some action that initiated this load. Clicked on a link for instance. */
  638. BOOL user_initiated_loading;
  639. /** TRUE if the url access should be checked */
  640. BOOL check_url_access;
  641. #ifdef _WML_SUPPORT_
  642. WML_Context* wml_context;
  643. #endif // _WML_SUPPORT_
  644. DOM_ProxyEnvironment *dom_environment;
  645. BOOL es_pending_unload;
  646. ES_OpenURLAction* es_terminating_action;
  647. ES_ThreadInfo request_thread_info;
  648. /** The history element storing the latest state provided by history.pushState/history.replaceState.
  649. * It's only saved when pushState/replaceState is called while document is still loading. It's needed to set the document manager's
  650. * url after the loading is finished (changing the url while the document is still being loaded would break the loading).
  651. * Note that the url is updated only if history_state_doc_elm == current_doc_elm.
  652. */
  653. DocListElm* history_state_doc_elm;
  654. /** Pending history delta (a sum of all deltas) to be applied when doing the history navigation which is *always* async */
  655. int history_traverse_pending_delta;
  656. URL* m_waiting_for_online_url;
  657. #ifdef WIC_USE_DOWNLOAD_CALLBACK
  658. friend class TransferManagerDownloadCallback;
  659. OpVector <TransferManagerDownloadCallback> current_download_vector;
  660. void AddCurrentDownloadRequest(TransferManagerDownloadCallback *request) { current_download_vector.Add(request); }
  661. void RemoveCurrentDownloadRequest(TransferManagerDownloadCallback *request) { current_download_vector.RemoveByItem(request); }
  662. #endif // WIC_USE_DOWNLOAD_CALLBACK
  663. #if defined _SSL_SUPPORT_ && !defined _EXTERNAL_SSL_SUPPORT_ && !defined _CERTICOM_SSL_SUPPORT_
  664. SSL_Certificate_Installer_Base *ssl_certificate_installer;
  665. #endif // _SSL_SUPPORT_ && !_EXTERNAL_SSL_SUPPORT_ && !_CERTICOM_SSL_SUPPORT_
  666. BOOL is_delayed_action_msg_posted;
  667. double target_time_for_delayed_action_msg;
  668. #ifdef TRUST_RATING
  669. Head m_active_trust_checks;
  670. UINT m_next_checker_id;
  671. #endif // TRUST_RATING
  672. #ifdef CLIENTSIDE_STORAGE_SUPPORT
  673. OpStorageManager *m_storage_manager;
  674. #endif // CLIENTSIDE_STORAGE_SUPPORT
  675. /** Keeps a local 'is-active' state for doc_manager. Used to detect if opera is idle, important for testing */
  676. OpActivity activity_loading;
  677. OpActivity activity_refresh;
  678. #ifdef SCOPE_PROFILER
  679. OpProbeTimeline *m_timeline;
  680. #endif // SCOPE_PROFILER
  681. #ifdef WEB_HANDLERS_SUPPORT
  682. /** If set an action is not allowed to be changed */
  683. BOOL action_locked;
  684. /** If set the check if some web protocol handler should handle a url is skipped when opening the url */
  685. BOOL skip_protocol_handler_check;
  686. #endif // WEB_HANDLERS_SUPPORT
  687. /** TRUE if OnNewPage has been sent, and OnNewPageReady should be
  688. * sent when the document is ready to be displayed. */
  689. BOOL waiting_for_document_ready;
  690. #ifdef _PRINT_SUPPORT_
  691. OP_STATUS CreatePrintDoc(BOOL preview);
  692. #endif // _PRINT_SUPPORT_
  693. void FlushHTTPSFromHistory(DocListElm* &prev_doc_elm, DocListElm* current_doc_elm);
  694. /// Notifies the WindowCommander of a changed URL early for empty windows
  695. void NotifyUrlChangedIfAppropriate(URL& url);
  696. void HandleCallback(OpMessage msg, MH_PARAM_1 par1, MH_PARAM_2 par2);
  697. void SetLoadStat(DM_LoadStat value);
  698. int GetNextHistoryNumber(BOOL is_replace, BOOL &replaced_empty);
  699. void InsertHistoryElement(DocListElm *element);
  700. /**
  701. * Removes duplicate (same number) entries in the
  702. * history list caused by
  703. * a document replacing an existing document in the history.
  704. */
  705. void HistoryCleanup();
  706. /** DecRefs and sets the current_loading_origin pointer to NULL if it's currently set. */
  707. void DropCurrentLoadingOrigin();
  708. /**
  709. * Uses current_loading_origin, referrer and current_url to determine a suitable DocumentOrigin
  710. * for a document loaded from current_url.
  711. *
  712. * current_loading_origin will be unset when this returns regardless of return value.
  713. *
  714. * @returns A DocumentOrigin pointer that is already referenced (the caller should not call IncRef).
  715. */
  716. DocumentOrigin* CreateOriginFromLoadingState();
  717. #ifndef NO_EXTERNAL_APPLICATIONS
  718. OP_STATUS SetTempDownloadFolder();
  719. #endif // NO_EXTERNAL_APPLICATIONS
  720. OP_STATUS SetSaveDirect(Viewer * viewer, BOOL &can_do);
  721. #ifdef OPERA_CONSOLE
  722. void PostURLErrorToConsole(URL& url, Str::LocaleString error_message);
  723. #endif // OPERA_CONSOLE
  724. BOOL IsRelativeJump(URL url);
  725. BOOL DisplayContentIfAvailable(URL &url, URL_ID id, MH_PARAM_2 load_status);
  726. /**
  727. * Request to signal OpViewportController::OnNewPage() to the UI.
  728. *
  729. * OnNewPage might not be sent for some reasons, e.g. if this is
  730. * not the DocumentManager for the top document.
  731. *
  732. * @param reason reason for the new page displayed
  733. * @return TRUE if OnNewPage was sent
  734. */
  735. BOOL SignalOnNewPage(OpViewportChangeReason reason);
  736. public:
  737. DocumentManager(Window* win, FramesDocElm* frm, FramesDocument* pdoc);
  738. virtual ~DocumentManager();
  739. OP_STATUS Construct();
  740. void Clear();
  741. VisualDevice* GetVisualDevice() const
  742. {
  743. return
  744. #ifdef _PRINT_SUPPORT_
  745. (print_vd) ? print_vd : (print_preview_vd) ? print_preview_vd :
  746. #endif
  747. vis_dev;
  748. }
  749. void SetVisualDevice(VisualDevice* vd) { vis_dev = vd; }
  750. /**
  751. * @returns Window that contains this DocumentManager. Never NULL.
  752. */
  753. Window* GetWindow() const { return window; }
  754. MessageHandler* GetMessageHandler() { return mh; }
  755. FramesDocElm* GetFrame() const { return frame; }
  756. FramesDocument* GetParentDoc() const { return parent_doc; }
  757. FramesDocument* GetCurrentDoc() const;
  758. #ifdef _PRINT_SUPPORT_
  759. VisualDevice* GetPrintPreviewVD() { return print_vd ? print_vd : print_preview_vd; }
  760. FramesDocument* GetPrintDoc() const { return print_doc ? print_doc : print_preview_doc; }
  761. #endif
  762. /**
  763. * Get the document that's currently visible.
  764. *
  765. * This is either the "regular" document returned by GetCurrentDoc(), or
  766. * the print preview document.
  767. */
  768. FramesDocument* GetCurrentVisibleDoc() const;
  769. #ifdef CLIENTSIDE_STORAGE_SUPPORT
  770. /**
  771. * Returns the OpStorageManager used for web storage.
  772. *
  773. * @param create if the OpStorageManager has not been set,
  774. * a new one is allocated if 'create' is TRUE,
  775. * else NULL is returned.
  776. */
  777. OpStorageManager* GetStorageManager(BOOL create);
  778. /**
  779. * Sets the OpStorageManager that the documents
  780. * contained shall use. OpStorageManagers are shared
  781. * because some volatile data, like sessionStorage, is
  782. * only kept in memory, or when privacy mode is enabled.
  783. *
  784. * @param new_mgr The new storage manager
  785. */
  786. void SetStorageManager(OpStorageManager* new_mgr);
  787. #endif // CLIENTSIDE_STORAGE_SUPPORT
  788. DocumentManager*
  789. GetDocManagerById(int sub_win_id) const;
  790. OP_STATUS UpdateAction(const uni_char* &app);
  791. /**
  792. * @param[in] create_document TRUE if the FramesDocument should be
  793. * force created now rather than created during loading later. Be
  794. * careful with this. FALSE is the suggested value.
  795. * @param[in] is_user_initiated If the history traversal was caused
  796. * due to user interaction. Else would be for cases initiated by scripts.
  797. */
  798. OP_STATUS SetCurrentDoc(BOOL check_if_inline_expired, BOOL use_plugin, BOOL create_document, BOOL is_user_initiated);
  799. OP_STATUS UpdateCurrentDoc(BOOL use_plugin, BOOL parsing_restarted, BOOL is_user_initiated);
  800. void SetCurrentNew(DocListElm* prev_doc_elm, BOOL is_user_initiated);
  801. int GetUseHistoryNumber() const { return use_history_number; }
  802. void SetUseHistoryNumber(int number) { use_history_number = number; }
  803. int GetPendingHistoryDelta() { return history_traverse_pending_delta; }
  804. void AddPendingHistoryDelta(int delta) { history_traverse_pending_delta += delta; }
  805. void ClearPendingHistoryDelta() { history_traverse_pending_delta = 0; }
  806. void RemoveFromHistory(int from, BOOL unlink = FALSE);
  807. void RemoveUptoHistory(int to, BOOL unlink = FALSE);
  808. void CheckHistory(int decrement, int& minhist, int& maxhist);
  809. void RemoveElementFromHistory(int pos, BOOL unlink = TRUE);
  810. void RemoveElementFromHistory(DocListElm *dle, BOOL unlink = TRUE, BOOL update_current_history_pos = TRUE);
  811. #ifdef DOCHAND_HISTORY_MANIPULATION_SUPPORT
  812. void InsertElementInHistory(int pos, DocListElm * doc_elm);
  813. #endif // DOCHAND_HISTORY_MANIPULATION_SUPPORT
  814. OP_STATUS UpdateCallbacks(BOOL is_active);
  815. /**
  816. * Store current visual viewports into the specified DocListElm. In paged
  817. * media, store page number instead.
  818. *
  819. * This is done recursively for all descendant framesets, frames and
  820. * iframes.
  821. */
  822. void StoreViewport(DocListElm* doc_elm);
  823. /**
  824. * Set current visual viewports from the current DocListElm. In paged
  825. * media, restore page number instead.
  826. *
  827. * @param only_pending_restoration If TRUE, the viewport will only be
  828. * restored if doing that earlier failed. Restoration fails if
  829. * RestoreViewport() is called while the document isn't fully loaded, and
  830. * the viewport was outside the bounds of the document.
  831. *
  832. * @param recurse If TRUE, this is done recursively for all descendant
  833. * framesets, frames and iframes.
  834. *
  835. * @param make_fit If the viewport is outside the bounds of the document,
  836. * change it so that it fits. For paged media, if the stored page number is
  837. * larger than the number of pages in the document, go to the last page.
  838. */
  839. void RestoreViewport(BOOL only_pending_restoration, BOOL recurse, BOOL make_fit);
  840. /**
  841. * Cancels pending viewport restoration. See RestoreViewport().
  842. */
  843. void CancelPendingViewportRestoration() { pending_viewport_restore = FALSE; }
  844. /**
  845. * Add new history element.
  846. *
  847. * @param url history element's url
  848. * @param ref_url history element's referrer
  849. * @param history_num position the new element is supposed to be added at. -1 means use th next position.
  850. * @param doc_title history element's title.
  851. * @param make_current If TRUE the inserted history element become current one.
  852. * @param is_plugin If TRUE the url leads to a content handler by plugin.
  853. * @param existing_doc a document to be put in the history. If NULL a new one will be created.
  854. * @param scale the zoom level.
  855. *
  856. * @return OpStatus::ERR_NO_MEMORY in case of OOM. OpStatus::OK otherwise.
  857. */
  858. OP_STATUS AddNewHistoryPosition(URL& url, const DocumentReferrer& ref_url, int history_num, const uni_char* doc_title, BOOL make_current = FALSE, BOOL is_plugin = FALSE, FramesDocument * existing_doc = NULL, int scale = 100);
  859. /**
  860. * This is used to foresee if navigating to a new position will still reuse
  861. * the same document, for instance when just changing the rel part of a url
  862. *
  863. * @param position history position
  864. */
  865. BOOL IsCurrentDocTheSameAt(int position);
  866. /**
  867. * Traverses this documentmanager's history to the position.
  868. * @param num history position
  869. * @param is_user_initiated TRUE if this history traversal was
  870. * initiated by the user, like when
  871. * clicking the back or forward buttons
  872. * in the browser UI
  873. */
  874. void SetCurrentHistoryPos(int num, BOOL parent_doc_changed, BOOL is_user_initiated);
  875. void UnloadCurrentDoc();
  876. int GetHistoryLen() { return history_len; }
  877. FramesDocument* GetHistoryNext() const;
  878. FramesDocument* GetHistoryPrev() const;
  879. /**
  880. * Associate user data with a specific DocListElm.
  881. *
  882. * Set user data for the DocListElm with the specified ID, that
  883. * can be reached from a history position within the Window that
  884. * this DocListElm belongs to.
  885. *
  886. * Should only be called on the top level DocumentManager.
  887. *
  888. * @param history_ID the ID of the DocListElm to set user data for
  889. * @param user_data user data to associate. The DocumentManager
  890. * assumes ownership of this object on success.
  891. * @retval OpStatus::OK if operation was successful.
  892. * @retval OpStatus::ERR if operation failed, for example if the history_ID could not be found
  893. */
  894. OP_STATUS SetHistoryUserData(int history_ID, OpHistoryUserData* user_data);
  895. /**
  896. * Return user data previously associated with a specific DocListElm.
  897. *
  898. * Get user data for the DocListElm with the specified ID, that
  899. * can be reached from a history position within the Window that
  900. * this DocListElm belongs to.
  901. *
  902. * Should only be called on the top level DocumentManager.
  903. *
  904. * @param history_ID the ID of the DocListElm to get user data for
  905. * @param[out] user_data where to fill in the pointer to the user
  906. * data. If no user data had previously been set, it is filled
  907. * with NULL. The returned instance is still owned by the
  908. * callee.
  909. * @retval OpStatus::OK if operation was successful
  910. * @retval OpStatus::ERR if an error occured, for example if the history_ID could not be found
  911. */
  912. OP_STATUS GetHistoryUserData(int history_ID, OpHistoryUserData** user_data) const;
  913. void SetShowImg(BOOL val);
  914. OP_STATUS ReformatCurrentDoc();
  915. OP_STATUS ReformatDoc(FramesDocument* doc);
  916. DocListElm* CurrentDocListElm() const { return current_doc_elm; }
  917. DocListElm* FirstDocListElm() const { return (DocListElm*)doc_list.First(); }
  918. DocListElm* LastDocListElm() const { return (DocListElm*)doc_list.Last(); }
  919. DocListElm* FindDocListElm(FramesDocument *doc) const;
  920. void UpdateVisitedLinks(const URL& url);
  921. void Refresh(URL_ID id);
  922. void Reload(EnteredByUser entered_by_user, BOOL conditionally_request_document = FALSE, BOOL conditionally_request_inlines = TRUE, BOOL is_user_auto_reload = FALSE);
  923. URL& GetCurrentURL() { return current_url; }
  924. /**
  925. * Sets the current URL.
  926. * @param moved Set to TRUE if the URL is moved or redirected.
  927. */
  928. void SetCurrentURL(const URL& url, BOOL moved);
  929. URL GetCurrentDocURL();
  930. /**
  931. * Returns URL to use as referer when loading elements from this document
  932. * The referrer is used for security checks so it's important that it represents
  933. * the true loader of resources
  934. */
  935. DocumentReferrer GenerateReferrerURL();
  936. BOOL ShouldSendReferrer();
  937. /**< Returns FALSE if the referrer URL should not be sent to the server
  938. * when loading the URL. */
  939. void SetReferrerURL(const DocumentReferrer& new_referrer, BOOL isend_to_server = TRUE) { referrer_url = new_referrer; send_to_server = isend_to_server; }
  940. /**< Sets the referrer URL used to load the URL displayed at this history
  941. * position.
  942. * @param isend_to_server Set to FALSE if it should not be sent to the
  943. * server when loading the URL of the current document. */
  944. void SetUrlLoadOnCommand(const URL& url, const DocumentReferrer& ref_url, BOOL replace_document = FALSE, BOOL was_user_initiated = FALSE, ES_Thread *origin_thread = NULL);
  945. BOOL GetUserAutoReload() const { return user_auto_reload; }
  946. void SetUserAutoReload(BOOL val) { user_auto_reload = val; }
  947. BOOL GetReload() const { return reload; }
  948. void SetReload(BOOL value);
  949. /**< Sets the reload flags for the loading of the current url.
  950. * @param value If TRUE, the main url will be reloaded.
  951. */
  952. BOOL MustReloadScripts() { return reload || was_reloaded; }
  953. BOOL MustReloadInlines() { return reload_inlines || were_inlines_reloaded; }
  954. BOOL MustConditionallyRequestInlines() { return conditionally_request_inlines || were_inlines_requested_conditionally; }
  955. BOOL GetRedirect() const { return redirect; }
  956. void SetRedirect(BOOL val) { redirect = val; }
  957. BOOL GetReplace() const { return replace; }
  958. void SetReplace(BOOL val) { replace = val; }
  959. BOOL GetUserStartedLoading() { return user_started_loading; }
  960. BOOL IsClearing() { return is_clearing; }
  961. BOOL ErrorPageShown() { return error_page_shown; }
  962. void SetErrorPageShown(BOOL shown) { error_page_shown = shown; }
  963. #ifdef WEB_HANDLERS_SUPPORT
  964. void SetActionLocked(BOOL val) { action_locked = val;}
  965. void SetSkipProtocolHandlerCheck() { skip_protocol_handler_check = TRUE; }
  966. #endif // WEB_HANDLERS_SUPPORT
  967. void SetAction(ViewAction act);
  968. ViewAction GetAction() { return current_action; }
  969. void SetActionFlag(ViewActionFlag::ViewActionFlagType flag) { current_action_flag.Set(flag); }
  970. void UnsetActionFlag(ViewActionFlag::ViewActionFlagType flag) { current_action_flag.Unset(flag); }
  971. void ResetActionFlag(ViewActionFlag::ViewActionFlagType flag) { current_action_flag.Reset(); }
  972. const uni_char* GetApplication() { return current_application; }
  973. void SetApplication(const uni_char* str);
  974. void SetReloadFlags(BOOL reload_document, BOOL conditionally_request_document, BOOL reload_inlines, BOOL conditionally_request_inlines);
  975. BOOL GetReloadDocument() { return reload_document; }
  976. BOOL GetConditionallyRequestDocument() { return conditionally_request_document; }
  977. BOOL GetReloadInlines() { return reload_inlines; }
  978. BOOL GetConditionallyRequestInlines() { return conditionally_request_inlines; }
  979. /** Optional arguments to OpenURL(). */
  980. class OpenURLOptions
  981. {
  982. public:
  983. OpenURLOptions();
  984. /**< Constructor. Sets all members to their documented default
  985. values. */
  986. BOOL user_initiated;
  987. /**< TRUE if the request was directly initiated by the user.
  988. Default: FALSE.
  989. FIXME: It is unclear exactly what this means or what effects it
  990. has. */
  991. BOOL create_doc_now;
  992. /**< If TRUE, a new current document will be created immediately (on
  993. success.) Normally, a new current document isn't created until a
  994. response has been received, and the loaded resource has been
  995. identified as something that actually should be loaded as a new
  996. document. Only use this if you must have a reference to the new
  997. document immediately after the call.
  998. Default: FALSE. */
  999. EnteredByUser entered_by_user;
  1000. /**< WasEnteredByUser if the URL came from the user via the UI (entered
  1001. into the address field, loaded via a bookmark or similar.) The
  1002. effect is that the URL is "trusted" since the user was completely
  1003. in control of how it was specified. This allows javascript: URLs
  1004. to be loaded in any document.
  1005. NotEnteredByUser means the URL didn't come directly from the user,
  1006. and can't be completely trusted.
  1007. Default: NotEnteredByUser. */
  1008. BOOL is_walking_in_history;
  1009. /**< TRUE if this call loads a URL as part of navigating in history.
  1010. Used for instance when a document containing frames or iframes is
  1011. navigated to and reloaded from cache because it was not in the
  1012. document cache, when loading the documents in the frames or
  1013. iframes. Affects which set of cache policies used.
  1014. Default: FALSE. */
  1015. BOOL es_terminated;
  1016. /**< TRUE if this call continues a previous call to OpenURL that was
  1017. suspended while waiting for scripts in the document to finish.
  1018. Default: FALSE. */
  1019. BOOL called_externally;
  1020. /**< TRUE if the mailto: URL was sent to Opera from an external
  1021. application. Used by Quick/M2 to avoid call-out loops.
  1022. Default: FALSE. */
  1023. BOOL bypass_url_access_check;
  1024. /**< Bypasses the security checks that limit access to file: URLs to
  1025. other file: URLs and certain opera: URLs, and that prevents
  1026. loading opera: URLs other than opera:blank in frames or iframes.
  1027. Use with care, obviously.
  1028. Default: FALSE. */
  1029. BOOL ignore_fragment_id;
  1030. /**< Disables the direct handling of the URLs fragment identifier when
  1031. the URL ignoring the fragment identifier is identical to the URL of
  1032. the current document. Normally, opening such a URL results in
  1033. nothing more than the document being scrolled to the identified
  1034. anchor.
  1035. Default: FALSE. */
  1036. BOOL is_inline_feed;
  1037. /**< Open the URL as a webfeed with in the generated feed viewer page.
  1038. Default: FALSE */
  1039. ES_Thread *origin_thread;
  1040. /**< The thread that opened the url.
  1041. Default: NULL. */
  1042. BOOL from_html_attribute;
  1043. /**< This will change an internal policy that it is allowed to
  1044. load a url recursively. By setting this to TRUE it will
  1045. not be allowed.
  1046. Default: FALSE. */
  1047. };
  1048. void OpenURL(URL url, DocumentReferrer referrer, BOOL check_if_expired, BOOL reload, const OpenURLOptions &options);
  1049. /**< Open URL. If the URL is identical to the current document's URL, has a
  1050. fragment identifier and 'reload' is FALSE, the document will just be
  1051. scrolled (but see OpenURLOptions::ignore_fragment_id.) If the URL's
  1052. scheme is a special one (such as mailto: or javascript:) the URL will
  1053. be specially handled according to the scheme. Otherwise, a request to
  1054. load the URL will be issued using the appropriate reload policy.
  1055. The appropriate reload policy is determined by quite a few interacting
  1056. factors, but most importantly the arguments 'check_if_expired' and
  1057. 'reload'. If 'reload' is TRUE, the URL will be reloaded conditionally
  1058. (if 'check_if_expired' is TRUE) or unconditionally. If 'reload' is
  1059. FALSE, the URL will not be reloaded, unless cache policies dictates
  1060. otherwise, or 'check_if_expired' is TRUE, in which case a conditional
  1061. request will typically be issued.
  1062. Note that the exact behaviour when 'reload' is TRUE can also be
  1063. overridden by a prior call to SetReloadFlags(), that all conditional
  1064. requests will typically be affected by expiry checking preferences and
  1065. the HTTP cache controlling headers, and that the "must-revalidate"
  1066. value to a Cache-Control header overrides almost everything else.
  1067. @param url URL to load.
  1068. @param referrer_url Referrer URL to use if/when the URL is reloaded.
  1069. Also used to determine whether to allow the access.
  1070. @param check_if_expired See function's main documentation.
  1071. @param reload See function's main documentation.
  1072. @param options Optional arguments. */
  1073. void OpenURL(URL& url, const DocumentReferrer& referrer, BOOL check_if_expired, BOOL reload, BOOL user_initiated=FALSE, BOOL create_doc_now=FALSE, EnteredByUser entered_by_user=NotEnteredByUser, BOOL is_walking_in_history=FALSE, BOOL es_terminated=FALSE, BOOL called_externally=FALSE, BOOL bypass_url_access_check=FALSE);
  1074. /**< Open URL. See OpenURL(URL, URL, BOOL, BOOL, const OpenURLOptions &)
  1075. for details. This function is equivalent except in how arguments are
  1076. passed. Please use the other variant. This function will be
  1077. deprecated and removed in time. */
  1078. void LoadPendingUrl(URL_ID url_id, BOOL user_initiated);
  1079. void OpenImageURL(URL url, const DocumentReferrer& referrer, BOOL save, BOOL new_page = FALSE, BOOL in_background = FALSE);
  1080. /**< Like OpenURL, but does nothing if the URL is not an image. */
  1081. BOOL HandleByOpera(BOOL check_if_inline_expired, BOOL use_plugin, BOOL is_user_initiated, BOOL *out_of_memory = NULL);
  1082. BOOL NeedsProgressBar();
  1083. /**< Returns TRUE if a progress bar should be displayed in the window
  1084. because we are currently loading, and FALSE otherwise. Traverses the
  1085. document tree and calls FramesDocument::NeedsProgressBar() for each
  1086. document. */
  1087. void EndProgressDisplay(BOOL force = FALSE);
  1088. void HandleErrorUrl();
  1089. OP_STATUS HandleDocFinished();
  1090. OP_STATUS UpdateWindowHistoryAndTitle();
  1091. OP_STATUS HandleDataLoaded(URL_ID url_id);
  1092. OP_STATUS HandleHeaderLoaded(URL_ID url_id, BOOL check_if_inline_expired);
  1093. void HandleMultipartReload(URL_ID url_id, BOOL internal_reload);
  1094. void HandleAllLoaded(URL_ID url_id, BOOL multipart_reload = FALSE);
  1095. void HandleDocumentNotModified(URL_ID url_id);
  1096. /**
  1097. * Checks if OpViewportController::OnNewPageReady should be called
  1098. * and calls it if so.
  1099. *
  1100. * OnNewPageReady should be called iff OnNewPage has previously
  1101. * been called, and the document is now ready to be
  1102. * displayed. Normally, the VisualDevice notifies when the
  1103. * document is ready via its lock mechanism, but extra checks
  1104. * should be made explicitly whenever there is a risk that the
  1105. * VisualDevice was not locked, after OnNewPage was called.
  1106. *
  1107. * @see OpViewportController::OnNewPage
  1108. * @see OpViewportController::OnNewPageReady
  1109. * @see VisualDevice::LockUpdate
  1110. */
  1111. void CheckOnNewPageReady();
  1112. /**
  1113. * Sends an error from the network layer to the appropriate windowcommander listener.
  1114. */
  1115. void SendNetworkErrorCode(Window* window, MH_PARAM_2 user_data);
  1116. void HandleLoadingFailed(URL_ID url_id, MH_PARAM_2 user_data);
  1117. void HandleUrlMoved(URL_ID url_id, URL_ID moved_to_id);
  1118. OP_STATUS HandleLoading(OpMessage msg, URL_ID url_id, MH_PARAM_2 user_data);
  1119. BOOL IsCurrentDocLoaded(BOOL inlines_loaded = TRUE);
  1120. /**
  1121. * Stops the document loading
  1122. *
  1123. * @param format Load and parse already buffered outstanding data.
  1124. * @param force_end_progress Signal that the progress bar should be removed immediately.
  1125. * @param abort Puts the document in the aborted state. It prevents aborted/unloaded inlines from being (re)loaded when going back to the page in history.
  1126. * Normally TRUE when the stop is user invoked (e.g. by pressing the stop button).
  1127. */
  1128. void StopLoading(BOOL format, BOOL force_end_progress = FALSE, BOOL abort = FALSE);
  1129. void ResetStateFlags();
  1130. int GetSubWinId();
  1131. OP_BOOLEAN LoadAllImages();
  1132. DM_LoadStat GetLoadStatus() { return load_stat; }
  1133. void SetLoadStatus(DM_LoadStat lstat) { SetLoadStat(lstat); }
  1134. #ifdef _PRINT_SUPPORT_
  1135. OP_STATUS UpdatePrintPreview();
  1136. OP_BOOLEAN SetPrintMode(BOOL on, FramesDocElm* copy_fde, BOOL preview);
  1137. void SetPrintPreviewVD(VisualDevice* vd) { print_preview_vd = vd; }
  1138. OP_DOC_STATUS PrintPage(PrintDevice* pd, int page_num, BOOL print_selected_only, BOOL only_probe=FALSE);
  1139. #endif // _PRINT_SUPPORT_
  1140. void SetScale(int scale);
  1141. #if defined SAVE_DOCUMENT_AS_TEXT_SUPPORT
  1142. OP_STATUS SaveCurrentDocAsText(UnicodeOutputStream* stream, const uni_char* fname=NULL, const char *force_encoding=NULL);
  1143. //OP_STATUS SaveCurrentDocAsTextToMemory(uni_char *&buf, long& size);
  1144. #endif // SAVE_DOCUMENT_AS_TEXT_SUPPORT
  1145. void ClearHistory();
  1146. BOOL GetRestartParsing() { return restart_parsing; }
  1147. void SetRestartParsing(BOOL val) { restart_parsing = val; }
  1148. OP_STATUS RestartParsing();
  1149. void UpdateSecurityState(BOOL include_loading_docs);
  1150. #ifdef _WML_SUPPORT_
  1151. OP_STATUS WMLInit();
  1152. BOOL WMLHasWML() { return(wml_context != NULL); }
  1153. WML_Context* WMLGetContext() { return wml_context; }
  1154. OP_STATUS WMLSetContext(WML_Context *new_context);
  1155. void WMLDeleteContext();
  1156. void WMLDeWmlifyHistory(BOOL delete_all = FALSE);
  1157. #endif // _WML_SUPPORT_
  1158. /**
  1159. * Schedules a refresh to happen after a specified delay (i.e. load a URL again)
  1160. * @param url_id Id of URL to refresh
  1161. * @param delay How long to wait before refreshing (in milliseconds)
  1162. */
  1163. void SetRefreshDocument(URL_ID url_id, unsigned long delay);
  1164. /** Cancels next scheduled refresh (if any) */
  1165. void CancelRefresh();
  1166. CheckExpiryType GetCheckExpiryType() { return check_expiry; }
  1167. void SetCheckExpiryType(CheckExpiryType ce_type) { check_expiry = ce_type; }
  1168. BOOL IsWalkingInHistory() { return history_walk != DM_NOT_HIST; }
  1169. HistoryDirection GetHistoryDirection() { return history_walk; }
  1170. void ESGeneratingDocument(ES_Thread *generating_thread, BOOL is_reload, DocumentOrigin* origin);
  1171. void ESGeneratingDocumentFinished();
  1172. /* From DOM_ProxyEnvironment::RealWindowProvider. */
  1173. virtual OP_STATUS GetRealWindow(DOM_Object *&window);
  1174. OP_STATUS GetJSWindow(DOM_Object *&window, ES_Runtime *origining_runtime);
  1175. BOOL HasJSWindow();
  1176. void UpdateCurrentJSWindow();
  1177. void ESSetPendingUnload(ES_OpenURLAction *action);
  1178. OP_STATUS ESSendPendingUnload(BOOL check_if_inline_expired, BOOL use_plugin);
  1179. OP_STATUS ESCancelPendingUnload();
  1180. DOM_ProxyEnvironment *GetDOMEnvironment() { return dom_environment; }
  1181. /**
  1182. * Creates the proxy environment if it doesn't exist, else does nothing.
  1183. * If this returns OpStatus::OK, then GetDOMEnvironment will return
  1184. * something.
  1185. */
  1186. OP_STATUS ConstructDOMProxyEnvironment();
  1187. /**
  1188. * Pushes (or replaces) the history element's state as described in
  1189. * http://www.whatwg.org/specs/web-apps/current-work/#dom-history-pushstate
  1190. *
  1191. * @param data - data of the history element's state
  1192. * @param title - history element's title
  1193. * @param url - history element's url
  1194. * @param create_new - the flog indicating it this is push or replace operation
  1195. */
  1196. OP_STATUS PutHistoryState(ES_PersistentValue *data, const uni_char *title, URL &url, BOOL create_new = TRUE);
  1197. /**
  1198. * dochand internal method. Don't touch if you're not coming from
  1199. * inside dochand.
  1200. *
  1201. * @param for_javascript_url TRUE to indicate that the new document is
  1202. * purely for running a javascript url.
  1203. * @param prevent_early_onload If TRUE then do not initiate onload delivery for
  1204. * about:blank while the document is constructed.
  1205. * @param use_opera_blanker If TRUE, use opera:blanker instead of
  1206. * about:blank.
  1207. */
  1208. OP_STATUS CreateInitialEmptyDocument(BOOL for_javascript_url, BOOL prevent_early_onload, BOOL use_opera_blanker = FALSE);
  1209. void RaiseCondition(OP_STATUS status);
  1210. void SetWaitingForOnlineUrl(URL &url);
  1211. OP_STATUS OnlineModeChanged();
  1212. static BOOL IsTrustedExternalURLProtocol(const OpStringC &URLname);
  1213. #if defined WEB_HANDLERS_SUPPORT || defined QUICK
  1214. /**
  1215. * Checks if the protocol the url uses should be handled by some application e.g. a system application or a web service
  1216. *
  1217. * @return OpBoolean::IS_FALSE in case the url should be continued loading by Opera
  1218. * OpBoolean::IS_TRUE if loading should not be continued as the protocol is handled by some other application.
  1219. * In case of error the error code is returned.
  1220. */
  1221. OP_BOOLEAN AttemptExecuteURLsRecognizedByOpera(URL& url, DocumentReferrer referrer, BOOL user_initiated, BOOL user_started);
  1222. #endif // WEB_HANDLERS_SUPPORT || QUICK
  1223. OP_BOOLEAN JumpToRelativePosition(const URL &url, BOOL reuse_history_entry = FALSE);
  1224. /**
  1225. * Checks if loading |url| would be a recursive load, i.e. would load an url
  1226. * already in a parent document. That would start an infinite loop using up all
  1227. * the computer's resources and might hang opera.
  1228. */
  1229. BOOL IsRecursiveDocumentOpening(const URL& url, BOOL from_html_attribute);
  1230. void StoreRequestThreadInfo(ES_Thread *thread);
  1231. void ResetRequestThreadInfo();
  1232. BOOL IgnoreURLRequest(URL url, ES_Thread *thread = NULL);
  1233. enum SecCheckRes
  1234. {
  1235. SEC_CHECK_DENIED, // Access denied
  1236. SEC_CHECK_STARTED, // An asynchronous security check was started.
  1237. SEC_CHECK_ALLOWED, // Access allowed
  1238. };
  1239. /**
  1240. * Initiates a security check for a redirected URL.
  1241. *
  1242. * @param url The url to check.
  1243. * @param source The url from which the access was attempted.
  1244. *
  1245. * @return Result indicating denied/allowed or if an asynchronous check was started.
  1246. */
  1247. SecCheckRes InitiateSecurityCheck(URL url, const DocumentReferrer& source);
  1248. /**
  1249. * Performs the error handling needed when URL access has been denied.
  1250. *
  1251. * @param url The url that was denied.
  1252. * @param source The url from which the access was attempted.
  1253. */
  1254. void HandleURLAccessDenied(URL url, URL source);
  1255. static BOOL IsSpecialURL(URL target);
  1256. BOOL IsLoadOrSaveImageOnly() { return load_image_only || save_image_only; }
  1257. /**
  1258. * Some internal actions we don't want to do directly and instead
  1259. * register information about the action and posts a delayed
  1260. * message to do them later. Use this to post such a message. If a
  1261. * message is already queued nothing will be done.
  1262. *
  1263. * @param[in] delay_ms How long to delay the message. Normally
  1264. * 0 would be a good number, but if it is something that is
  1265. * unlikely to work in a while (for instance because we wait
  1266. * for message loops to unnest), then a bigger delay might be
  1267. * appropriate.
  1268. */
  1269. void PostDelayedActionMessage(int delay_ms);
  1270. /**
  1271. * Call when a "delayed action message" is received so that DocumentManager
  1272. * knows that it has to send a new such message the next time
  1273. * PostDelayedActionMessage() is called. This should be called by
  1274. * anyone receiving a MSG_DOC_DELAYED_ACTION message originating
  1275. * from the MessageHandler in this DocumentManager.
  1276. *
  1277. * @see PostDelayedActionMessage
  1278. */
  1279. void OnDelayedActionMessageReceived() { is_delayed_action_msg_posted = FALSE; }
  1280. #ifdef TRUST_RATING
  1281. /**
  1282. * Checks current trust rating of the url.
  1283. * @return OpStatus::OK if url is trusted.
  1284. * OpStatus::ERR_NO_ACCESS if url is fraudulent, and the error page was generated.
  1285. * Other errors like OpStatus::ERR_NO_MEMORY.
  1286. */
  1287. OP_STATUS CheckTrustRating(URL url, BOOL offline_check_only=FALSE, BOOL force_check=FALSE);
  1288. OP_STATUS AddTrustCheck(URL url, BOOL need_ip_resolve);
  1289. OP_STATUS GenerateAndShowFraudWarningPage(const URL& url, TrustInfoParser::Advisory *advisory = NULL);
  1290. #endif // TRUST_RATING
  1291. #ifdef ERROR_PAGE_SUPPORT
  1292. /**
  1293. * Generate a cross domain error page.
  1294. *
  1295. * @param url The url that the error refers to.
  1296. * @param error An enum value for a string containing the cross
  1297. * domain error message.
  1298. */
  1299. OP_STATUS GenerateAndShowCrossNetworkErrorPage(const URL& url, Str::LocaleString error);
  1300. /**
  1301. * Displays a warning that this frame/iframe can't be loaded
  1302. * here.
  1303. *
  1304. * @param[in] url The url that was attemped to load.
  1305. */
  1306. OP_STATUS GenerateAndShowClickJackingBlock(const URL& url);
  1307. /**
  1308. * Processes a url load coming from a click-through page, like
  1309. * opera:crossnetworkwarning or opera:site-warning.
  1310. * The document url and referrer passed as arguments are changed
  1311. * to point to the new final urls.
  1312. *
  1313. * @param url the url to navigate to
  1314. * @param ref_url referrer, the url of the click through page
  1315. * @return OpStatus::OK if everything is ok and the url should keep loading.
  1316. * Opstatus::ERR if the url should not continue loading.
  1317. * OpStatus::ERR_NO_MEMORY if OOM.
  1318. */
  1319. OP_STATUS HandleClickThroughUrl(URL& url, DocumentReferrer& ref_url);
  1320. #endif // ERROR_PAGE_SUPPORT
  1321. #ifdef WEBSERVER_SUPPORT
  1322. /**
  1323. * Displays a warning that this unite page can't be opened this way.
  1324. *
  1325. * @param[in] url The url that was attemped to load.
  1326. *
  1327. * @param[in] source The url of the page that tried to load the unite url.
  1328. */
  1329. OP_STATUS GenerateAndShowUniteWarning(URL &url, URL& source);
  1330. #endif // WEBSERVER_SUPPORT
  1331. #ifdef WEB_TURBO_MODE
  1332. /**
  1333. * Must be called when the Web Turbo Mode changes for the
  1334. * current window.
  1335. */
  1336. OP_STATUS UpdateTurboMode();
  1337. #endif // WEB_TURBO_MODE
  1338. #ifdef SCOPE_PROFILER
  1339. /**
  1340. * Start profiling using the specified timeline.
  1341. *
  1342. * @param timeline Object to store profiling data in. Owned by caller.
  1343. * The pointer must point to a valid object at least until
  1344. * the next call to StopProfiling().
  1345. *
  1346. * @return OpStatus::OK if profiling begun, or OpStatus::ERR if profiling
  1347. * already was in progress.
  1348. */
  1349. OP_STATUS StartProfiling(OpProfilingSession *session);
  1350. /**
  1351. * Stop profiling. If this document manager is not currently
  1352. * profiled, nothing happens.
  1353. */
  1354. void StopProfiling();
  1355. /**
  1356. * Called when an immediate child is added to this DocumentManager.
  1357. *
  1358. * @param child The child DocumentManager about to be added.
  1359. */
  1360. void OnAddChild(DocumentManager *child);
  1361. /**
  1362. * Called when an immediate child is removed from this DocumentManager.
  1363. *
  1364. * @param child The child DocumentManager about to be added.
  1365. */
  1366. void OnRemoveChild(DocumentManager *child);
  1367. /**
  1368. * Get the OpProbeTimeline for this document manager.
  1369. *
  1370. * @return The timeline if this document manager is currently
  1371. * profiled, otherwise NULL.
  1372. */
  1373. OpProbeTimeline *GetTimeline() const { return m_timeline; }
  1374. /**
  1375. * Check whether this document manager is currently profiled.
  1376. *
  1377. * @return TRUE if profiling, FALSE if not.
  1378. */
  1379. BOOL IsProfiling() const { return (m_timeline != NULL); }
  1380. #endif // SCOPE_PROFILER
  1381. #ifdef DOM_LOAD_TV_APP
  1382. /** Set a list of urls that are allowed to be opened by this DocumentManager.
  1383. *
  1384. * The whitelist is the vector of strings. The vector and all strings are
  1385. * owned by DocumentManager and will be freed when the DocumentManager
  1386. * is destroyed or if new whitelist it set.
  1387. * The vector and each string must be allocated by OP_NEWA().
  1388. *
  1389. * If a white-list is set, each URL that is opened via OpenURL() will be
  1390. * compared against the white-list. If any entry in the white-list is a prefix
  1391. * of the URL to open, the operation is allowed, otherwise the request to open
  1392. * the URL is ignored, and OpTVAppMessageListener::OnOpenForbiddenUrl()
  1393. * is called to signal to the UI that it happened.
  1394. *
  1395. * If the whitelist it set to NULL, or SetWhitelist is not called,
  1396. * DocumentManager will not block anything.
  1397. *
  1398. * @param new_whitelist list of strings
  1399. * */
  1400. void SetWhitelist(OpAutoVector<OpString>* new_whitelist);
  1401. #endif // DOM_LOAD_TV_APP
  1402. private:
  1403. class SecurityCheckCallback : public OpSecurityCheckCallback, public ES_ThreadListener
  1404. {
  1405. public:
  1406. SecurityCheckCallback(DocumentManager *docman)
  1407. : m_docman(docman),
  1408. m_done(FALSE),
  1409. m_suspended(FALSE),
  1410. m_redirect(FALSE),
  1411. m_allowed(FALSE),
  1412. m_referrer(),
  1413. m_check_if_expired(FALSE),
  1414. m_reload(FALSE),
  1415. m_invalidated(FALSE) {}
  1416. virtual void OnSecurityCheckSuccess(BOOL allowed, ChoicePersistenceType type = PERSISTENCE_NONE);
  1417. virtual void OnSecurityCheckError(OP_STATUS error);
  1418. void SetURLs(URL& url, const DocumentReferrer& referrer);
  1419. void PrepareForSuspending(BOOL check_if_expired, BOOL reload, const OpenURLOptions& options);
  1420. void PrepareForSuspendingRedirect();
  1421. void Invalidate() { m_invalidated = TRUE; };
  1422. void Reset();
  1423. /** Call when a suspended security check finishes regardless of its result. */
  1424. void SecurityCheckFinished();
  1425. virtual OP_STATUS Signal(ES_Thread *thread, ES_ThreadSignal signal);
  1426. DocumentManager *m_docman;
  1427. BOOL m_done;
  1428. BOOL m_suspended;
  1429. BOOL m_redirect;
  1430. BOOL m_allowed;
  1431. URL m_url;
  1432. DocumentReferrer m_referrer;
  1433. BOOL m_check_if_expired;
  1434. BOOL m_reload;
  1435. BOOL m_invalidated;
  1436. OpenURLOptions m_options;
  1437. };
  1438. friend class SecurityCheckCallback;
  1439. SecurityCheckCallback *security_check_callback;
  1440. #ifdef DOM_LOAD_TV_APP
  1441. OpAutoVector<OpString>* whitelist;
  1442. /**< The list of urls that this documentmanager is allowed to load, or NULL. */
  1443. #endif
  1444. };
  1445. class DocumentTreeIterator
  1446. {
  1447. protected:
  1448. const DocumentManager *start;
  1449. DocumentManager *current;
  1450. BOOL include_this, include_iframes, include_empty;
  1451. FramesDocElm* NextLeaf(FramesDocElm* frame) const;
  1452. /**< Find the next leaf node that follows 'frame' in the document tree, but
  1453. confine search to the subtree defined by the 'start' member. */
  1454. public:
  1455. DocumentTreeIterator();
  1456. DocumentTreeIterator(Window *window);
  1457. DocumentTreeIterator(DocumentManager *docman);
  1458. DocumentTreeIterator(FramesDocElm *frame);
  1459. DocumentTreeIterator(FramesDocument *document);
  1460. void SetIncludeThis();
  1461. /**< Include the DocumentManager/FramesDocElm/FramesDocument object that the
  1462. iterator was constructed with in the iteration. If not called, that
  1463. object is not included. */
  1464. void SetExcludeIFrames();
  1465. /**< Exclude DocumentManager/FramesDocElm/FramesDocument objects that belong
  1466. to iframes. If not called, such objects are included. */
  1467. void SetIncludeEmpty();
  1468. /**< Include DocumentManager/FramesDocElm objects that are empty, that is,
  1469. that have no current document. If not called, such objects are not
  1470. included. */
  1471. BOOL Next(BOOL skip_children = FALSE);
  1472. /**< Moves the iterator to the next position. If there was a next position,
  1473. TRUE is returned, otherwise FALSE is returned. If 'skip_children' is
  1474. TRUE, children of the current position (frames or iframes in the
  1475. current document and their children, that is) are skipped. */
  1476. DocumentManager *GetDocumentManager();
  1477. /**< Returns the current DocumentManager. Can only be called after a call to
  1478. Next() that returned TRUE. */
  1479. FramesDocElm *GetFramesDocElm();
  1480. /**< Returns the current FramesDocElm. Note: if the current document is
  1481. the top document in a window, this function returns NULL. Can only be
  1482. called after a call to Next() that returned TRUE. */
  1483. FramesDocument *GetFramesDocument();
  1484. /**< Returns the current FramesDocument. Note: if SetIncludeEmpty() has been
  1485. called, this function may return NULL. Can only be called after a call
  1486. to Next() that returned TRUE. */
  1487. void SkipTo(DocumentManager* doc_man);
  1488. /**< Allows the user to set the position of the iterator. Useful to skip a
  1489. portion of the iteration. It's the caller's job to make sure that
  1490. doc_man and the element the iterator was initialised with
  1491. are consistant. */
  1492. };
  1493. #endif // DOCHAND_DOCMAN_H