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.

win.cpp 138KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304
  1. /* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4; c-file-style:"stroustrup" -*-
  2. *
  3. * Copyright (C) 1995-2011 Opera Software ASA. All rights reserved.
  4. *
  5. * This file is part of the Opera web browser.
  6. * It may not be distributed under any circumstances.
  7. */
  8. #include "core/pch.h"
  9. // FIXME: clean up these == 96 includes!
  10. #include "modules/dochand/win.h"
  11. #include "modules/dochand/winman.h"
  12. #include "modules/dochand/docman.h"
  13. #include "modules/dochand/viewportcontroller.h"
  14. #include "modules/doc/html_doc.h"
  15. #include "modules/doc/documentorigin.h"
  16. #include "modules/url/url2.h"
  17. #include "modules/url/url_man.h"
  18. #include "modules/encodings/detector/charsetdetector.h"
  19. #include "modules/inputmanager/inputaction.h"
  20. #include "modules/inputmanager/inputmanager.h"
  21. #include "modules/logdoc/urlimgcontprov.h"
  22. #include "modules/logdoc/savewithinline.h"
  23. #include "modules/forms/formmanager.h"
  24. #ifdef USE_OP_THREAD_TOOLS
  25. #include "modules/pi/OpThreadTools.h"
  26. #endif
  27. #include "modules/hardcore/mh/messages.h"
  28. #include "modules/locale/oplanguagemanager.h"
  29. #include "modules/locale/locale-enum.h"
  30. #include "modules/util/timecache.h"
  31. #include "modules/prefs/prefsmanager/collections/pc_core.h"
  32. #include "modules/prefs/prefsmanager/collections/pc_display.h"
  33. #include "modules/prefs/prefsmanager/collections/pc_doc.h"
  34. #include "modules/prefs/prefsmanager/collections/pc_network.h"
  35. #include "modules/prefs/prefsmanager/collections/pc_ui.h"
  36. #include "modules/prefs/prefsmanager/collections/pc_print.h"
  37. #include "modules/prefs/prefsmanager/collections/pc_fontcolor.h"
  38. #include "modules/display/prn_info.h"
  39. #include "modules/ecmascript/ecmascript.h"
  40. #include "modules/ecmascript_utils/essched.h"
  41. #include "modules/layout/layout_workplace.h"
  42. #include "modules/logdoc/htm_elm.h"
  43. #include "modules/logdoc/htm_ldoc.h"
  44. #include "modules/doc/frm_doc.h"
  45. #include "modules/util/gen_str.h"
  46. #include "modules/util/winutils.h"
  47. #include "modules/util/filefun.h"
  48. #include "modules/display/vis_dev.h"
  49. #include "modules/display/coreview/coreview.h"
  50. #include "modules/util/handy.h"
  51. #ifdef QUICK
  52. # include "adjunct/quick/Application.h"
  53. # include "adjunct/quick/managers/KioskManager.h"
  54. # include "adjunct/quick/dialogs/DownloadDialog.h"
  55. # include "adjunct/quick/hotlist/HotlistManager.h"
  56. #endif
  57. #include "modules/windowcommander/OpWindowCommander.h"
  58. #include "modules/windowcommander/src/WindowCommander.h"
  59. #ifdef DRAG_SUPPORT
  60. #include "modules/dragdrop/dragdrop_manager.h"
  61. #endif
  62. #include "modules/history/OpHistoryModel.h"
  63. #include "modules/display/prn_dev.h"
  64. #include "modules/pi/OpWindow.h"
  65. #include "modules/dochand/windowlistener.h"
  66. #include "modules/windowcommander/OpWindowCommanderManager.h"
  67. #if defined(_MACINTOSH_)
  68. # include "platforms/mac/File/FileUtils_Mac.h"
  69. #endif // macintosh latest
  70. #ifdef _PLUGIN_SUPPORT_
  71. #include "modules/ns4plugins/opns4pluginhandler.h"
  72. #endif // _PLUGIN_SUPPORT_
  73. #include "modules/display/VisDevListeners.h"
  74. #ifdef GTK_DOWNLOAD_EXTENSION
  75. # include <gtk/gtk.h>
  76. # include "base/gdk/GdkOpWindow.h"
  77. # include "product/sdk/src/documentwindow.h"
  78. # include "product/sdk/src/bookmarkitemmanager.h"
  79. #endif // GTK_DOWNLOAD_EXTENSION
  80. #include "modules/url/protocols/comm.h"
  81. #ifdef LINK_SUPPORT
  82. #include "modules/logdoc/link.h"
  83. #endif // LINK_SUPPORT
  84. #ifdef NEARBY_ELEMENT_DETECTION
  85. # include "modules/widgets/finger_touch/element_of_interest.h"
  86. #endif // NEARBY_ELEMENT_DETECTION
  87. #ifndef _NO_GLOBALS_
  88. extern HTML_Element *curr_img_element;
  89. #endif
  90. #include "modules/olddebug/timing.h"
  91. #ifdef OBML_COMM_FORCE_CONFIG_FILE
  92. #include "modules/obml_comm/obml_config.h"
  93. #endif // OBML_COMM_FORCE_CONFIG_FILE
  94. extern BOOL ScrollDocument(FramesDocument* doc, OpInputAction::Action action, int times = 1, OpInputAction::ActionMethod method = OpInputAction::METHOD_OTHER);
  95. #ifdef _SPAT_NAV_SUPPORT_
  96. #include "modules/spatial_navigation/sn_handler.h"
  97. #endif // _SPAT_NAV_SUPPORT_
  98. #ifdef SVG_SUPPORT
  99. #include "modules/svg/svg_workplace.h"
  100. #include "modules/svg/svg_image.h"
  101. #endif // SVG_SUPPORT
  102. #ifdef SEARCH_MATCHES_ALL
  103. # include "modules/doc/searchinfo.h"
  104. #endif
  105. #ifdef SEARCH_ENGINES
  106. #include "modules/searchmanager/searchmanager.h"
  107. #endif // SEARCH_ENGINES
  108. #ifdef WAND_SUPPORT
  109. #include "modules/wand/wandmanager.h"
  110. #endif // WAND_SUPPORT
  111. #ifndef HAS_NOTEXTSELECTION
  112. # include "modules/dochand/fdelm.h"
  113. # include "modules/documentedit/OpDocumentEdit.h"
  114. #endif //!HAS_NOTEXTSELECTION
  115. #ifdef CORE_BOOKMARKS_SUPPORT
  116. #include "modules/bookmarks/bookmark_item.h"
  117. #include "modules/bookmarks/bookmark_manager.h"
  118. #endif // CORE_BOOKMARKS_SUPPORT
  119. #define DOC_WINDOW_MAX_TITLE_LENGTH 128
  120. #ifdef SCOPE_WINDOW_MANAGER_SUPPORT
  121. # include "modules/scope/scope_window_listener.h"
  122. #endif // SCOPE_WINDOW_MANAGER_SUPPORT
  123. #ifdef GADGET_SUPPORT
  124. # include "modules/gadgets/OpGadget.h"
  125. #endif // GADGET_SUPPORT
  126. #ifdef APPLICATION_CACHE_SUPPORT
  127. # include "modules/applicationcache/application_cache_manager.h"
  128. #endif // APPLICATION_CACHE_SUPPORT
  129. #ifdef CSS_VIEWPORT_SUPPORT
  130. # include "modules/style/css_viewport.h"
  131. #endif // CSS_VIEWPORT_SUPPORT
  132. #ifdef DEBUG_LOAD_STATUS
  133. # include "modules/olddebug/tstdump.h"
  134. #endif
  135. #ifdef USE_OP_CLIPBOARD
  136. # include "modules/pi/OpClipboard.h"
  137. # ifdef SVG_SUPPORT
  138. # include "modules/svg/SVGManager.h"
  139. # endif // SVG_SUPPORT
  140. # include "modules/forms/piforms.h"
  141. # include "modules/widgets/OpWidget.h"
  142. #endif // USE_OP_CLIPBOARD
  143. OpenUrlInNewWindowInfo::OpenUrlInNewWindowInfo(URL& url, DocumentReferrer refurl, const uni_char* win_name, BOOL open_in_bg_win, BOOL user_init, unsigned long open_win_id,
  144. int open_sub_win_id, BOOL open_in_new_page)
  145. : new_url(url),
  146. ref_url(refurl),
  147. open_in_background_window(open_in_bg_win),
  148. user_initiated(user_init),
  149. opener_id(open_win_id),
  150. opener_sub_win_id(open_sub_win_id),
  151. open_in_page(open_in_new_page)
  152. {
  153. window_name = UniSetNewStr(win_name);//FIXME:OOM
  154. }
  155. const OpMessage g_Window_messages[] =
  156. {
  157. MSG_PROGRESS_START,
  158. MSG_PROGRESS_END,
  159. #ifdef _PRINT_SUPPORT_
  160. DOC_START_PRINTING,
  161. DOC_PRINT_FORMATTED,
  162. DOC_PAGE_PRINTED,
  163. DOC_PRINTING_FINISHED,
  164. DOC_PRINTING_ABORTED,
  165. #endif // _PRINT_SUPPORT_
  166. MSG_SELECTION_SCROLL,
  167. MSG_ES_CLOSE_WINDOW,
  168. MSG_UPDATE_PROGRESS_TEXT,
  169. MSG_UPDATE_WINDOW_TITLE,
  170. MSG_HISTORY_CLEANUP,
  171. WM_OPERA_SCALEDOC,
  172. MSG_HISTORY_BACK
  173. };
  174. void Window::ConstructL()
  175. {
  176. forceEncoding.SetL(g_pcdisplay->GetForceEncoding());
  177. homePage.Empty();
  178. doc_manager = OP_NEW_L(DocumentManager, (this, NULL, NULL)); // must be set before VisualDevice constructor
  179. LEAVE_IF_ERROR(doc_manager->Construct());
  180. msg_handler = OP_NEW_L(MessageHandler, (this));
  181. LEAVE_IF_ERROR(msg_handler->SetCallBackList(this, 0, g_Window_messages, sizeof g_Window_messages / sizeof g_Window_messages[0]));
  182. #ifdef EPOC
  183. // Fix for 'hidden' transfer window.
  184. if (type==WIN_TYPE_DOWNLOAD)
  185. return;
  186. #endif
  187. vis_device = VisualDevice::Create(m_opWindow, doc_manager,
  188. bShowScrollbars ? VisualDevice::VD_SCROLLING_AUTO : VisualDevice::VD_SCROLLING_NO);
  189. if (!vis_device)
  190. LEAVE(OpStatus::ERR_NO_MEMORY);
  191. doc_manager->SetVisualDevice(vis_device);
  192. UINT32 rendering_width, rendering_height;
  193. m_opWindow->GetRenderingBufferSize(&rendering_width, &rendering_height);
  194. vis_device->SetRenderingViewGeometryScreenCoords(OpRect(0, 0, rendering_width, rendering_height));
  195. viewportcontroller = OP_NEW_L(ViewportController, (this));
  196. windowlistener = OP_NEW_L(WindowListener, (this));
  197. m_opWindow->SetWindowListener(windowlistener);
  198. }
  199. Window::Window(unsigned long nid, OpWindow* opWindow, OpWindowCommander* opWindowCommander)
  200. : m_features(0)
  201. , m_online_mode(Window::ONLINE)
  202. , m_frames_policy(FRAMES_POLICY_DEFAULT)
  203. #ifdef SUPPORT_VISUAL_ADBLOCK
  204. , m_content_block_edit_mode(FALSE)
  205. , m_content_block_enabled(TRUE)
  206. , m_content_block_server_name(NULL)
  207. #endif // SUPPORT_VISUAL_ADBLOCK
  208. , m_windowCommander(static_cast<WindowCommander*>(opWindowCommander))
  209. , vis_device(NULL)
  210. , doc_manager(NULL)
  211. , msg_handler(NULL)
  212. , current_message(NULL)
  213. , current_default_message(NULL)
  214. , progress_state(WAITING)
  215. , state(NOT_BUSY)
  216. #ifndef MOUSELESS
  217. , current_cursor(CURSOR_DEFAULT_ARROW)
  218. , m_pending_cursor(CURSOR_AUTO)
  219. , cursor_set_by_doc(CURSOR_DEFAULT_ARROW)
  220. , has_cursor_set_by_doc(FALSE)
  221. #endif // !MOUSELESS
  222. // active_link_url unset
  223. , m_fullscreen_state(OpWindowCommander::FULLSCREEN_NONE)
  224. // m_previous_fullscreen_state
  225. , m_is_background_transparent(FALSE)
  226. // m_old_* unset
  227. // m_* others: see function body
  228. , m_is_explicit_suppress_window(FALSE)
  229. , m_is_implicit_suppress_window(FALSE)
  230. , m_is_scriptable_window(TRUE)
  231. , m_is_visible_on_screen(TRUE)
  232. #ifdef _SPAT_NAV_SUPPORT_
  233. , sn_handler(0)
  234. #endif /* _SPAT_NAV_SUPPORT */
  235. # if defined SN_LEAVE_SUPPORT
  236. , sn_listener(0)
  237. # endif // SN_LEAVE_SUPPORT
  238. , m_draw_highlight_rects(TRUE)
  239. , bCanSelfClose(TRUE) // JS is known to close windows that are in use by others
  240. #ifdef SELFTEST
  241. , m_is_about_to_close(FALSE)
  242. #endif // SELFTEST
  243. , m_url_came_from_address_field(FALSE)
  244. , show_img(FALSE) // may be adjusted in body
  245. #ifdef FIT_LARGE_IMAGES_TO_WINDOW_WIDTH
  246. , fit_img(FALSE) // may be adjusted in body
  247. #endif // FIT_LARGE_IMAGES_TO_WINDOW_WIDTH
  248. , load_img(FALSE) // may be adjusted in body
  249. // is_ssr_mode, era_mode, layout_mode: see body
  250. , limit_paragraph_width(g_pcdisplay->GetIntegerPref(PrefsCollectionDisplay::LimitParagraphWidth))
  251. , flex_root_max_width(0)
  252. , scale(100)
  253. , m_text_scale(100)
  254. , progress_count(0)
  255. , doc_progress_count(0)
  256. , upload_total_bytes(0) // Uploading watch
  257. , phase_uploading(FALSE)
  258. , start_time(0)
  259. // progress_mess* arrays - see function body
  260. , OutputAssociatedWindow(0)
  261. , bShowScrollbars(g_pcdoc->GetIntegerPref(PrefsCollectionDoc::ShowScrollbars))
  262. // bShow* - see function body
  263. , id(nid)
  264. , loading(FALSE)
  265. , end_progress_message_sent(TRUE)
  266. , history_cleanup_message_sent(FALSE)
  267. , user_load_from_cache(FALSE)
  268. , pending_unlock_all_painting(FALSE)
  269. //, name(NULL)
  270. , CSSMode((CSSMODE) g_pcdisplay->GetIntegerPref(PrefsCollectionDisplay::DocumentMode))
  271. , forceColors(FALSE)
  272. , truezoom(FALSE)
  273. , truezoom_base_scale(100)
  274. , is_something_hovered(FALSE)
  275. , ecmascript_disabled(FALSE)
  276. , ecmascript_paused(NOT_PAUSED)
  277. , viewportcontroller(NULL)
  278. , SecurityState(SECURITY_STATE_UNKNOWN)
  279. , SecurityState_signalled(SECURITY_STATE_UNKNOWN)
  280. , SecurityState_changed_by_inline(FALSE)
  281. , SecurityState_signal_delayed(FALSE)
  282. , m_privacy_mode(FALSE)
  283. // SecurityTextName unset
  284. #ifdef TRUST_RATING
  285. , m_trust_rating(Not_Set)
  286. #endif
  287. #ifdef WEB_TURBO_MODE
  288. , m_turbo_mode(FALSE)
  289. #endif // WEB_TURBO_MODE
  290. , currWinHistoryLength(0)
  291. , current_history_number(0)
  292. , min_history_number(1)
  293. , max_history_number(0)
  294. , check_history(FALSE)
  295. , is_canceling_loading(FALSE)
  296. , title_update_title_posted(FALSE)
  297. // , title(NULL)
  298. , generated_title(FALSE)
  299. #ifdef SHORTCUT_ICON_SUPPORT
  300. , shortcut_icon_provider(NULL)
  301. #endif // SHORTCUT_ICON_SUPPORT
  302. , lastUserName(NULL)
  303. , lastProxyUserName(NULL)
  304. , type(WIN_TYPE_NORMAL)
  305. , default_background_color(USE_DEFAULT_COLOR)
  306. #ifdef _PRINT_SUPPORT_
  307. , printer_info(NULL)
  308. , preview_printer_info(NULL)
  309. , preview_mode(FALSE)
  310. , print_mode(FALSE)
  311. , frames_print_type(PRINT_ALL_FRAMES)
  312. , is_formatting_print_doc(FALSE)
  313. , is_printing(FALSE)
  314. #endif // _PRINT_SUPPORT_
  315. // m_userAutoReload unset
  316. #ifdef _AUTO_WIN_RELOAD_SUPPORT_
  317. , m_userAutoReload(this)
  318. #endif // _AUTO_WIN_RELOAD_SUPPORT_
  319. , opener(NULL)
  320. , opener_sub_win_id(-1)
  321. , is_available_to_script(FALSE)
  322. , opener_origin(NULL)
  323. , can_be_closed_by_script(FALSE)
  324. #if defined SEARCH_MATCHES_ALL
  325. , m_search_data(NULL)
  326. #endif // SEARCH_MATCHES_ALL
  327. , always_load_from_cache(FALSE)
  328. #ifdef LIBOPERA
  329. , m_lastReqUserInitiated(FALSE)
  330. #endif
  331. , m_opWindow(opWindow)
  332. , windowlistener(0)
  333. // m_bWasInFullscreen unset
  334. #ifdef ACCESS_KEYS_SUPPORT
  335. // FIXME: Change this when/if your platform has the ability to change this value
  336. , in_accesskey_mode(FALSE)
  337. #endif // ACCESS_KEYS_SUPPORT
  338. , window_locked(0)
  339. , window_closed(FALSE)
  340. , use_already_requested_urls(TRUE)
  341. , forced_java_disabled(FALSE)
  342. , forced_plugins_disabled(FALSE)
  343. , document_word_wrap_forced(FALSE)
  344. #ifdef WAND_SUPPORT
  345. , m_wand_in_progress_count(0)
  346. #endif // WAND_SUPPORT
  347. #ifdef HISTORY_SUPPORT
  348. , m_global_history_enabled(TRUE)
  349. #endif // HISTORY_SUPPORT
  350. #ifdef NEARBY_ELEMENT_DETECTION
  351. , element_expander(NULL)
  352. #endif // NEARBY_ELEMENT_DETECTION
  353. #ifdef GRAB_AND_SCROLL
  354. , scroll_is_pan_overridden(FALSE)
  355. , scroll_is_pan(FALSE)
  356. #endif // GRAB_AND_SCROLL
  357. , recently_cancelled_keydown(OP_KEY_INVALID)
  358. , has_shown_unsolicited_download_dialog(FALSE)
  359. #ifdef DOM_JIL_API_SUPPORT
  360. , m_screen_props_listener(NULL)
  361. #endif // DOM_JIL_API_SUPPORT
  362. , m_oom_occurred(FALSE)
  363. , m_next_doclistelm_id(1)
  364. #ifdef SCOPE_PROFILER
  365. , m_profiling_session(NULL)
  366. #endif // SCOPE_PROFILER
  367. #ifdef KEYBOARD_SELECTION_SUPPORT
  368. , m_current_keyboard_selection_mode(FALSE)
  369. #endif // KEYBOARD_SELECTION_SUPPORT
  370. {
  371. OP_ASSERT(opWindowCommander);
  372. switch ((SHOWIMAGESTATE) g_pcdoc->GetIntegerPref(PrefsCollectionDoc::ShowImageState))
  373. {
  374. case FIGS_OFF: break;
  375. case FIGS_ON: load_img = TRUE; /* fall through */
  376. case FIGS_SHOW: show_img = TRUE; break;
  377. }
  378. int rm = g_pcdoc->GetIntegerPref(PrefsCollectionDoc::RenderingMode);
  379. if (rm < 0)
  380. {
  381. era_mode = TRUE;
  382. rm = 0;
  383. }
  384. else
  385. era_mode = FALSE;
  386. layout_mode = (LayoutMode) rm;
  387. is_ssr_mode = layout_mode == LAYOUT_SSR;
  388. SetFlexRootMaxWidth(g_pcdisplay->GetIntegerPref(PrefsCollectionDisplay::FlexRootMaxWidth), FALSE);
  389. progress_mess[0] = 0;
  390. progress_mess_low[0] = 0;
  391. SetFeatures(type);
  392. default_background_color = colorManager->GetBackgroundColor();
  393. }
  394. BOOL Window::Close()
  395. {
  396. if (window_locked)
  397. {
  398. window_closed = TRUE;
  399. #ifdef SELFTEST
  400. // Signal to the selftest system that this window is about to close and
  401. // shouldn't be reused.
  402. SetIsAboutToClose(TRUE);
  403. #endif // SELFTEST
  404. }
  405. else
  406. {
  407. m_windowCommander->GetDocumentListener()->OnClose(m_windowCommander);
  408. g_windowCommanderManager->GetUiWindowListener()->CloseUiWindow(m_windowCommander);
  409. }
  410. return TRUE;
  411. }
  412. void Window::SetOpener(Window* opened_by, int sub_win_id, BOOL make_available_to_script, BOOL from_window_open)
  413. {
  414. opener = opened_by;
  415. opener_sub_win_id = sub_win_id;
  416. is_available_to_script = make_available_to_script;
  417. if (!can_be_closed_by_script && from_window_open)
  418. can_be_closed_by_script = TRUE;
  419. if (FramesDocument *document = GetOpener())
  420. {
  421. OP_ASSERT(!opener_origin);
  422. opener_origin = document->GetMutableOrigin();
  423. opener_origin->IncRef();
  424. }
  425. #ifdef CLIENTSIDE_STORAGE_SUPPORT
  426. if (opened_by)
  427. DocManager()->SetStorageManager(opened_by->DocManager()->GetStorageManager(FALSE));
  428. #endif // CLIENTSIDE_STORAGE_SUPPORT
  429. }
  430. FramesDocument* Window::GetOpener(BOOL is_script/*=TRUE*/)
  431. {
  432. FramesDocument* doc = NULL;
  433. if (opener && (is_available_to_script || !is_script))
  434. {
  435. DocumentManager* doc_man = opener->GetDocManagerById(opener_sub_win_id);
  436. if (!doc_man)
  437. doc_man = opener->DocManager();
  438. doc = doc_man->GetCurrentDoc();
  439. }
  440. return doc;
  441. }
  442. URL Window::GetOpenerSecurityContext()
  443. {
  444. if (opener_origin)
  445. return opener_origin->security_context;
  446. return URL();
  447. }
  448. #ifndef MOUSELESS
  449. CursorType Window::GetCurrentCursor()
  450. {
  451. if (has_cursor_set_by_doc)
  452. return cursor_set_by_doc;
  453. switch (state)
  454. {
  455. case BUSY:
  456. return IsNormalWindow() ? CURSOR_WAIT : CURSOR_DEFAULT_ARROW;
  457. case CLICKABLE:
  458. return IsNormalWindow() ? CURSOR_ARROW_WAIT : CURSOR_DEFAULT_ARROW;
  459. default: // There should be no other states.
  460. OP_ASSERT(0);
  461. /* fall through */
  462. case NOT_BUSY:
  463. case RESERVED: // The RESERVED state is currently unused.
  464. return CURSOR_DEFAULT_ARROW;
  465. }
  466. }
  467. CursorType Window::GetCurrentArrowCursor()
  468. {
  469. // Disable the doc cursor and ask what the cursor would be in that case
  470. BOOL doc_cursor = has_cursor_set_by_doc;
  471. has_cursor_set_by_doc = FALSE;
  472. CursorType arrow_cursor = GetCurrentCursor();
  473. has_cursor_set_by_doc = doc_cursor;
  474. return arrow_cursor;
  475. }
  476. #endif // !MOUSELESS
  477. void Window::SetState(WinState s)
  478. {
  479. state = s;
  480. #ifndef MOUSELESS
  481. SetCursor(GetCurrentCursor());
  482. #endif // !MOUSELESS
  483. }
  484. Window::~Window()
  485. {
  486. #if defined _PRINT_SUPPORT_
  487. if (is_printing)
  488. StopPrinting();
  489. #endif // _PRINT_SUPPORT_
  490. #ifdef NEARBY_ELEMENT_DETECTION
  491. SetElementExpander(NULL);
  492. #endif // NEARBY_ELEMENT_DETECTION
  493. #ifdef WAND_SUPPORT
  494. if (m_wand_in_progress_count)
  495. {
  496. g_wand_manager->UnreferenceWindow(this);
  497. OP_ASSERT(m_wand_in_progress_count == 0);
  498. }
  499. #endif // WAND_SUPPORT
  500. if (opener_origin)
  501. {
  502. opener_origin->DecRef();
  503. opener_origin = NULL;
  504. }
  505. if (GetPrivacyMode())
  506. g_windowManager->RemoveWindowFromPrivacyModeContext();
  507. // Remove all references to msg_handler from urlManager
  508. // Must be done before deleting the doc_manager because it may call back to our listener where we use it.
  509. if (urlManager && msg_handler)
  510. urlManager->RemoveMessageHandler(msg_handler);
  511. loading = FALSE;
  512. if (doc_manager) // Can be NULL if Construct failed and we're deleting a half-created object
  513. {
  514. doc_manager->Clear();
  515. OP_DELETE(doc_manager);
  516. }
  517. if (vis_device)
  518. {
  519. vis_device->SetDocumentManager(NULL);
  520. OP_DELETE(vis_device);
  521. }
  522. if (msg_handler)
  523. {
  524. msg_handler->UnsetCallBacks(this);
  525. OP_DELETE(msg_handler);
  526. }
  527. OP_DELETEA(current_default_message);
  528. OP_DELETEA(current_message);
  529. if (urlManager)
  530. urlManager->FreeUnusedResources(FALSE);
  531. if (m_opWindow)
  532. m_opWindow->SetWindowListener(NULL);
  533. OP_DELETE(windowlistener); windowlistener=NULL;
  534. #ifdef _SPAT_NAV_SUPPORT_
  535. OP_DELETE(sn_handler); sn_handler=NULL;
  536. #endif // _SPAT_NAV_SUPPORT_
  537. #ifdef SHORTCUT_ICON_SUPPORT
  538. if (shortcut_icon_provider)
  539. shortcut_icon_provider->DecRef(NULL);
  540. #endif
  541. #if defined SEARCH_MATCHES_ALL
  542. OP_DELETE(m_search_data);
  543. #endif // SEARCH_MATCHES_ALL
  544. #ifdef FONTCACHE_PER_WINDOW
  545. g_font_cache->ClearForWindow(this);
  546. #endif // FONTCACHE_PER_WINDOW
  547. OP_DELETE(viewportcontroller);
  548. #ifdef USE_OP_CLIPBOARD
  549. g_clipboard_manager->UnregisterListener(this);
  550. #endif // USE_OP_CLIPBOARD
  551. }
  552. void Window::EnsureHistoryLimits()
  553. {
  554. if (GetHistoryLen() > g_pccore->GetIntegerPref(PrefsCollectionCore::MaxWindowHistory))
  555. SetMaxHistory(g_pccore->GetIntegerPref(PrefsCollectionCore::MaxWindowHistory));
  556. }
  557. OP_STATUS Window::UpdateTitle(BOOL delay)
  558. {
  559. if (delay)
  560. {
  561. if (!title_update_title_posted)
  562. {
  563. msg_handler->PostMessage(MSG_UPDATE_WINDOW_TITLE, 0 , 0);
  564. title_update_title_posted = TRUE;
  565. }
  566. return OpStatus::OK;
  567. }
  568. URL url = GetCurrentURL();
  569. FramesDocument* doc = doc_manager->GetCurrentDoc();
  570. if (!doc)
  571. return OpStatus::ERR;
  572. OpString title;
  573. BOOL generated = FALSE;
  574. TempBuffer buffer;
  575. const uni_char* str = doc->Title(&buffer);
  576. URL& origurl = url;
  577. if (str && *str)
  578. RETURN_IF_ERROR(title.Set(str));
  579. else
  580. {
  581. // Might be nice to send an unescaped string to the UI but then we have to know the charset
  582. // and decode it correctly. Bug 250545.
  583. RETURN_IF_ERROR(origurl.GetAttribute(URL::KUniName_Username_Password_Hidden_Escaped,title));
  584. generated = TRUE;
  585. }
  586. RETURN_IF_ERROR(SetWindowTitle(title, FALSE, generated));
  587. RETURN_IF_ERROR(SetProgressText(url));
  588. #ifdef HISTORY_SUPPORT
  589. // Update the title in the entry in global history
  590. if (doc_manager->GetCurrentDoc())
  591. RETURN_IF_ERROR(AddToGlobalHistory(doc_manager->GetCurrentDoc()->GetURL(), title.CStr()));
  592. #endif // HISTORY_SUPPORT
  593. #ifdef CPUUSAGETRACKING
  594. TempBuffer cpuusage_display_name;
  595. switch (type)
  596. {
  597. case WIN_TYPE_NORMAL:
  598. case WIN_TYPE_GADGET:
  599. {
  600. OpString prefix;
  601. OpStatus::Ignore(g_languageManager->GetString(
  602. type == WIN_TYPE_NORMAL ? Str::S_OPERACPU_WINDOW_SOURCE_PREFIX : Str::S_OPERACPU_WIDGET_SOURCE_PREFIX,
  603. prefix));
  604. OpStatus::Ignore(cpuusage_display_name.Append(prefix.CStr(), prefix.Length()));
  605. OpStatus::Ignore(cpuusage_display_name.Append(' '));
  606. break;
  607. }
  608. default:
  609. ; // No prefix
  610. }
  611. OpStatus::Ignore(cpuusage_display_name.Append(title.CStr()));
  612. OpStatus::Ignore(cpu_usage_tracker.SetDisplayName(cpuusage_display_name.GetStorage()));
  613. if (type == WIN_TYPE_NORMAL)
  614. cpu_usage_tracker.SetActivatable();
  615. #endif // CPUUSAGETRACKING
  616. return OpStatus::OK;
  617. }
  618. void Window::SetLoading(BOOL set)
  619. {
  620. loading = set;
  621. }
  622. OP_STATUS Window::StartProgressDisplay(BOOL bReset, BOOL bResetSecurityState, BOOL bSubResourcesOnly)
  623. {
  624. if (!end_progress_message_sent)
  625. {
  626. // If we start loading a document, make sure UI is told about it.
  627. if (!m_loading_information.hasRequestedDocument && !bSubResourcesOnly)
  628. {
  629. m_loading_information.hasRequestedDocument = TRUE;
  630. m_windowCommander->GetLoadingListener()->OnLoadingProgress(m_windowCommander, &m_loading_information);
  631. }
  632. return OpStatus::OK;
  633. }
  634. start_time = g_timecache->CurrentTime();
  635. if (bResetSecurityState)
  636. ResetSecurityStateToUnknown();
  637. if (bReset)
  638. ResetProgressDisplay();
  639. m_loading_information.hasRequestedDocument |= !bSubResourcesOnly;
  640. #ifdef DOCHAND_CLEAR_RAMCACHE_ON_STARTPROGRESS
  641. if( bReset )
  642. urlManager->CheckRamCacheSize( 0 );
  643. #endif
  644. msg_handler->PostMessage(MSG_PROGRESS_START, 0, 0);
  645. end_progress_message_sent = FALSE; // If there was one earlier, that will be for an earlier progress and we should not care more about that one
  646. return OpStatus::OK;
  647. }
  648. void Window::EndProgressDisplay()
  649. {
  650. SetState(NOT_BUSY);
  651. CSSCollection* coll = GetCSSCollection();
  652. CSS* css = NULL;
  653. if (coll)
  654. {
  655. CSSCollection::Iterator iter(coll, CSSCollection::Iterator::STYLESHEETS);
  656. do {
  657. css = static_cast<CSS *>(iter.Next());
  658. } while (css && css->GetKind() == CSS::STYLE_PERSISTENT);
  659. }
  660. if (css != NULL)
  661. {
  662. m_windowCommander->GetLinkListener()->OnAlternateCssAvailable(m_windowCommander);
  663. }
  664. #ifdef LINK_SUPPORT
  665. const LinkElement* linkElt = GetLinkList();
  666. if (linkElt != NULL)
  667. {
  668. m_windowCommander->GetLinkListener()->OnLinkElementAvailable(m_windowCommander);
  669. }
  670. #endif // LINK_SUPPORT
  671. if (!end_progress_message_sent)
  672. {
  673. URL url = doc_manager->GetCurrentURL();
  674. OpLoadingListener::LoadingFinishStatus status;
  675. // FIXME: backstrom, are there more status to report?
  676. if (doc_manager->ErrorPageShown()) // If we've shown an error page instead of the page itself loading failed
  677. status = OpLoadingListener::LOADING_COULDNT_CONNECT;
  678. else if(url.Status(TRUE) == URL_LOADED)
  679. status = OpLoadingListener::LOADING_SUCCESS;
  680. else if(url.Status(TRUE) == URL_LOADING_FAILURE)
  681. status = OpLoadingListener::LOADING_COULDNT_CONNECT;
  682. else
  683. status = OpLoadingListener::LOADING_UNKNOWN;
  684. msg_handler->PostMessage(MSG_PROGRESS_END, 0, status);
  685. end_progress_message_sent = TRUE;
  686. pending_unlock_all_painting = TRUE;
  687. }
  688. else if (!pending_unlock_all_painting)
  689. {
  690. // Normally this is done on the MSG_PROGRESS_END message (and changing that
  691. // causes performance regressions which are not fully understood yet) but in case
  692. // we locked painting and then never started a progress bar (think javascript
  693. // urls and bookmarklets) we need to unlock it somewhere else, i.e. here.
  694. UnlockPaintLock();
  695. }
  696. #ifdef HTTP_BENCHMARK
  697. EndBenchmark();
  698. #endif
  699. }
  700. void Window::ResetProgressDisplay()
  701. {
  702. SetProgressCount(0);
  703. SetDocProgressCount(0);
  704. m_loading_information.Reset();
  705. SetProgressState(WAITING, NULL, NULL, 0, NULL);
  706. SetUploadTotal(0);
  707. }
  708. void Window::SetTrueZoom(BOOL status)
  709. {
  710. truezoom = status;
  711. if (scale != 100)
  712. SetScale(scale);
  713. }
  714. void Window::SetTrueZoomBaseScale(UINT32 scale)
  715. {
  716. if (scale == truezoom_base_scale)
  717. return;
  718. truezoom_base_scale = scale;
  719. DocumentTreeIterator it(doc_manager);
  720. it.SetIncludeThis();
  721. it.SetIncludeEmpty();
  722. while (it.Next())
  723. {
  724. VisualDevice* vd = it.GetDocumentManager()->GetVisualDevice();
  725. FramesDocument* doc = it.GetFramesDocument();
  726. #ifdef CSS_VIEWPORT_SUPPORT
  727. if (doc && doc->GetHLDocProfile())
  728. {
  729. doc->RecalculateLayoutViewSize(TRUE);
  730. if (doc->IsTopDocument())
  731. doc->RequestSetViewportToInitialScale(VIEWPORT_CHANGE_REASON_BASE_SCALE);
  732. }
  733. #endif // CSS_VIEWPORT_SUPPORT
  734. // Can it be null?
  735. if (vd)
  736. {
  737. vd->SetLayoutScale(scale);
  738. if (doc && doc->GetDocRoot())
  739. doc->GetDocRoot()->RemoveCachedTextInfo(doc);
  740. }
  741. }
  742. OpViewportInfoListener* info_listener = viewportcontroller->GetViewportInfoListener();
  743. info_listener->OnTrueZoomBaseScaleChanged(viewportcontroller, scale);
  744. }
  745. void Window::SetScale(INT32 sc)
  746. {
  747. if (sc < DOCHAND_MIN_DOC_ZOOM)
  748. sc = DOCHAND_MIN_DOC_ZOOM;
  749. else if (sc > DOCHAND_MAX_DOC_ZOOM)
  750. sc = DOCHAND_MAX_DOC_ZOOM;
  751. BOOL changed = (scale != sc);
  752. scale = sc;
  753. #ifdef PAGED_MEDIA_SUPPORT
  754. if (changed && IsFullScreen())
  755. if (FramesDocument *current_doc = GetCurrentDoc())
  756. if (LogicalDocument* logdoc = current_doc->GetLogicalDocument())
  757. current_doc->SetRestoreCurrentPageNumber(logdoc->GetLayoutWorkplace()->GetCurrentPageNumber());
  758. #endif // PAGED_MEDIA_SUPPORT
  759. doc_manager->SetScale( scale );
  760. // A subdocument may now have individual scalefactor. That's why we call doc_manager->SetScale always. But we don't tell windowcommander
  761. // if the window scale didn't change.
  762. if (!changed)
  763. return;
  764. m_windowCommander->GetDocumentListener()->OnScaleChanged(m_windowCommander, scale);
  765. }
  766. void Window::SetTextScale(int sc)
  767. {
  768. if (sc < DOCHAND_MIN_DOC_ZOOM)
  769. sc = DOCHAND_MIN_DOC_ZOOM;
  770. else if (sc > DOCHAND_MAX_DOC_ZOOM)
  771. sc = DOCHAND_MAX_DOC_ZOOM;
  772. m_text_scale = sc;
  773. if (doc_manager->GetCurrentDoc())
  774. doc_manager->GetCurrentDoc()->SetTextScale(m_text_scale);
  775. if (doc_manager->GetVisualDevice())
  776. doc_manager->GetVisualDevice()->SetTextScale(m_text_scale);
  777. }
  778. #ifdef PIXEL_SCALE_RENDERING_SUPPORT
  779. int Window::GetPixelScale()
  780. {
  781. return m_opWindow->GetPixelScale();
  782. }
  783. #endif // PIXEL_SCALE_RENDERING_SUPPORT
  784. const uni_char* Window::GetProgressMessage()
  785. {
  786. if(progress_mess[0] == 0)
  787. {
  788. uni_strcpy(progress_mess, progress_mess_low);
  789. progress_mess_low[0] = 0;
  790. }
  791. return progress_mess;
  792. }
  793. void Window::SetUploadTotal(OpFileLength progress_info1)
  794. {
  795. upload_total_bytes = progress_info1;
  796. }
  797. void Window::SetUploadFileCount(int total, int loaded)
  798. {
  799. upload_file_count = total;
  800. upload_file_loaded_count = loaded;
  801. }
  802. void Window::SetProgressState(ProgressState state, const uni_char* extrainfo, MessageHandler *mh, long bytes, URL *loading_url)
  803. {
  804. OP_MEMORY_VAR BOOL upload_started = FALSE;
  805. OP_MEMORY_VAR BOOL upload_ended = FALSE;
  806. if (state == REQUEST_FINISHED)
  807. {
  808. msg_handler->PostMessage(MSG_REFRESH_PROGRESS, 0 , 0);
  809. if (*progress_mess_low)
  810. return;
  811. progress_mess[0] = 0;
  812. }
  813. if (state != progress_state || extrainfo)
  814. {
  815. progress_state = state;
  816. Str::LocaleString string_number = Str::NOT_A_STRING;
  817. OP_MEMORY_VAR BOOL use_numeric_syntax = FALSE; /* Use %1 %2 instead of %s etc. */
  818. switch (state)
  819. {
  820. case WAITING_FOR_COOKIES:
  821. string_number = Str::SI_MPAR_URL_WAITING_FOR_COOKIES;
  822. break;
  823. case WAITING_FOR_COOKIES_DNS:
  824. string_number = Str::SI_MPAR_URL_WAITING_FOR_COOKIES_DNS;
  825. break;
  826. case REQUEST_QUEUED:
  827. string_number = Str::SI_MPAR_URL_REQUEST_QUEUED_STRING;
  828. break;
  829. case START_NAME_LOOKUP:
  830. string_number = Str::SI_MPAR_URL_START_NAME_LOOKUP_STRING;
  831. break;
  832. case START_NAME_COMPLETION:
  833. string_number = Str::SI_MPAR_URL_START_NAME_COMPLETION_STRING;
  834. break;
  835. case START_SECURE_CONNECTION:
  836. string_number = Str::SI_MPAR_URL_START_SECURE_CONNECTION_STRING;
  837. break;
  838. case START_CONNECT_PROXY:
  839. string_number = Str::SI_MPAR_URL_START_CONNECT_PROXY_STRING;
  840. break;
  841. case WAITING_FOR_CONNECTION:
  842. string_number = Str::SI_MPAR_URL_WAITING_FOR_CONNECTION_STRING;
  843. use_numeric_syntax = TRUE;
  844. break;
  845. case START_CONNECT:
  846. string_number = Str::SI_MPAR_URL_START_CONNECT_STRING;
  847. break;
  848. case START_REQUEST:
  849. string_number = Str::SI_MPAR_URL_START_REQUEST_STRING;
  850. break;
  851. case STARTED_40SECOND_TIMEOUT:
  852. string_number = Str::SI_MPAR_URL_STARTED_40SECOND_TIMEOUT;
  853. break;
  854. case UPLOADING_FILES:
  855. upload_started = TRUE;
  856. string_number = Str::SI_UPLOADING_FILES_STRING;
  857. #ifdef PROGRESS_EVENTS_SUPPORT
  858. if (mh && loading_url && bytes > 0)
  859. UpdateUploadProgress(mh, *loading_url, static_cast<unsigned long>(bytes));
  860. #endif // PROGRESS_EVENTS_SUPPORT
  861. break;
  862. case FETCHING_DOCUMENT:
  863. string_number = Str::SI_FETCHING_DOCUMENT_STRING;
  864. break;
  865. case EXECUTING_ECMASCRIPT:
  866. string_number = Str::SI_EXECUTING_ECMASCRIPT_STRING;
  867. break;
  868. case REQUEST_FINISHED:
  869. string_number = Str::SI_MPAR_URL_REQUEST_FINISHED_STRING;
  870. break;
  871. case UPLOADING_FINISHED:
  872. upload_ended = TRUE;
  873. break;
  874. }
  875. if (state == WAITING || string_number == Str::NOT_A_STRING)
  876. {
  877. ClearMessage();
  878. progress_mess_low[0] = '\0';
  879. progress_mess[0] = '\0';
  880. }
  881. else
  882. {
  883. OpString extra;
  884. OpString string;
  885. OpString message;
  886. TRAPD(err, message.ReserveL(MAX_PROGRESS_MESS_LENGTH));
  887. if (OpStatus::IsMemoryError(err))
  888. {
  889. RaiseCondition(err);
  890. return;
  891. }
  892. TRAP(err, g_languageManager->GetStringL(string_number, string));
  893. if (OpStatus::IsMemoryError(err))
  894. {
  895. RaiseCondition(err);
  896. return;
  897. }
  898. if (extrainfo)
  899. OpStatus::Ignore(extra.Set(extrainfo));
  900. if (string.CStr())
  901. {
  902. if (!use_numeric_syntax)
  903. {
  904. uni_snprintf(message.CStr(), message.Capacity(), string.CStr(), (extra.Length() ? extra.CStr() : UNI_L("")));
  905. }
  906. else //Uses %1
  907. {
  908. uni_snprintf_si(message.CStr(), message.Capacity(), string.CStr(), (extra.Length() ? extra.CStr() : UNI_L("")),
  909. (state == WAITING_FOR_CONNECTION ? Comm::CountWaitingComm(COMM_WAIT_STATUS_LOAD) : 0)
  910. );
  911. }
  912. }
  913. if (uni_strncmp(progress_mess, message.CStr(), MAX_PROGRESS_MESS_LENGTH) == 0)
  914. return;
  915. if(state == REQUEST_FINISHED)
  916. {
  917. uni_strlcpy(progress_mess_low, message.CStr(), MAX_PROGRESS_MESS_LENGTH);
  918. }
  919. else
  920. {
  921. uni_strlcpy(progress_mess, message.CStr(), MAX_PROGRESS_MESS_LENGTH);
  922. }
  923. }
  924. #ifdef EPOC
  925. // Certain windows are not prepared for interaction with WindowCommander.
  926. if (type==WIN_TYPE_DOWNLOAD)
  927. return;
  928. #endif
  929. m_loading_information.loadingMessage = GetProgressMessage();
  930. FramesDocument* doc = GetCurrentDoc();
  931. if (doc &&
  932. (doc_manager->GetLoadStatus() == NOT_LOADING || doc_manager->GetLoadStatus() == DOC_CREATED) &&
  933. !upload_started &&
  934. !phase_uploading)
  935. {
  936. DocLoadingInfo info;
  937. doc->GetDocLoadingInfo(info);
  938. m_loading_information.loadedImageCount = info.images.loaded_count;
  939. m_loading_information.totalImageCount = info.images.total_count;
  940. m_loading_information.loadedBytes = info.loaded_size;
  941. m_loading_information.totalBytes = info.total_size;
  942. m_loading_information.loadedBytesRootDocument = GetDocProgressCount();
  943. m_loading_information.totalBytesRootDocument = DocManager()->GetCurrentURL().GetContentSize();
  944. #ifdef WEB_TURBO_MODE
  945. m_loading_information.turboTransferredBytes = info.turbo_transferred_bytes + info.images.turbo_transferred_bytes;
  946. m_loading_information.turboOriginalTransferredBytes = info.turbo_original_transferred_bytes + info.images.turbo_original_transferred_bytes;
  947. #endif // WEB_TURBO_MODE
  948. }
  949. m_loading_information.isUploading = ((state == UPLOADING_FILES) || (state == UPLOADING_FINISHED));
  950. if(upload_started && !phase_uploading)
  951. {
  952. OpFileLength upload_total;
  953. DocManager()->GetCurrentURL().GetAttribute(URL::KHTTP_Upload_TotalBytes, &upload_total, URL::KFollowRedirect);
  954. SetUploadTotal(upload_total);
  955. phase_uploading = TRUE;
  956. m_loading_information.totalBytes = upload_total_bytes;
  957. m_windowCommander->GetLoadingListener()->OnStartUploading(m_windowCommander);
  958. }
  959. if (m_loading_information.isUploading)
  960. {
  961. m_loading_information.totalImageCount = upload_file_count;
  962. m_loading_information.loadedImageCount = upload_file_loaded_count;
  963. }
  964. m_windowCommander->GetLoadingListener()->OnLoadingProgress(m_windowCommander, &m_loading_information);
  965. if(upload_ended && phase_uploading)
  966. {
  967. phase_uploading = FALSE;
  968. m_windowCommander->GetLoadingListener()->OnUploadingFinished(m_windowCommander, OpLoadingListener::LOADING_SUCCESS);
  969. #ifdef PROGRESS_EVENTS_SUPPORT
  970. if (mh && loading_url)
  971. UpdateUploadProgress(mh, *loading_url, 0);
  972. #endif // PROGRESS_EVENTS_SUPPORT
  973. }
  974. }
  975. }
  976. #ifdef PROGRESS_EVENTS_SUPPORT
  977. void Window::UpdateUploadProgress(MessageHandler *mh, const URL &loading_url, unsigned long bytes)
  978. {
  979. mh->PostMessage(MSG_DOCHAND_UPLOAD_PROGRESS, loading_url.Id(), bytes);
  980. }
  981. #endif // PROGRESS_EVENTS_SUPPORT
  982. Window* Window::GetOutputAssociatedWindow()
  983. {
  984. return g_windowManager->GetWindow(OutputAssociatedWindow);
  985. }
  986. void Window::SetFeature(Window_Feature feature)
  987. {
  988. m_features |= feature;
  989. }
  990. void Window::SetFeatures(Window_Type type)
  991. {
  992. m_features = 0;
  993. switch (type)
  994. {
  995. case WIN_TYPE_JS_CONSOLE:
  996. case WIN_TYPE_HISTORY:
  997. case WIN_TYPE_NORMAL:
  998. case WIN_TYPE_CACHE:
  999. case WIN_TYPE_PLUGINS:
  1000. case WIN_TYPE_NORMAL_HIDDEN:
  1001. SetFeature(WIN_FEATURE_ALERTS);
  1002. SetFeature(WIN_FEATURE_PROGRESS);
  1003. SetFeature(WIN_FEATURE_NAVIGABLE);
  1004. SetFeature(WIN_FEATURE_PRINTABLE);
  1005. SetFeature(WIN_FEATURE_RELOADABLE);
  1006. SetFeature(WIN_FEATURE_FOCUSABLE);
  1007. SetFeature(WIN_FEATURE_HOMEABLE);
  1008. SetFeature(WIN_FEATURE_BOOKMARKABLE);
  1009. break;
  1010. #ifndef _NO_HELP_
  1011. case WIN_TYPE_HELP:
  1012. SetFeature(WIN_FEATURE_NAVIGABLE);
  1013. SetFeature(WIN_FEATURE_PRINTABLE);
  1014. SetFeature(WIN_FEATURE_RELOADABLE);
  1015. SetFeature(WIN_FEATURE_FOCUSABLE);
  1016. SetFeature(WIN_FEATURE_OUTSIDE);
  1017. SetFeature(WIN_FEATURE_BOOKMARKABLE);
  1018. break;
  1019. #endif // !_NO_HELP_
  1020. case WIN_TYPE_DOWNLOAD:
  1021. SetFeature(WIN_FEATURE_FOCUSABLE); // NOT for mswin
  1022. break;
  1023. case WIN_TYPE_MAIL_COMPOSE:
  1024. SetFeature(WIN_FEATURE_FOCUSABLE);
  1025. break;
  1026. case WIN_TYPE_MAIL_VIEW:
  1027. case WIN_TYPE_NEWSFEED_VIEW:
  1028. SetFeature(WIN_FEATURE_PRINTABLE);
  1029. SetFeature(WIN_FEATURE_FOCUSABLE);
  1030. break;
  1031. case WIN_TYPE_IM_VIEW:
  1032. SetFeature(WIN_FEATURE_PRINTABLE);
  1033. SetFeature(WIN_FEATURE_FOCUSABLE);
  1034. break;
  1035. case WIN_TYPE_BRAND_VIEW:
  1036. SetFeature(WIN_FEATURE_FOCUSABLE);
  1037. SetFeature(WIN_FEATURE_BOOKMARKABLE);
  1038. SetFeature(WIN_FEATURE_RELOADABLE);
  1039. break;
  1040. case WIN_TYPE_GADGET:
  1041. case WIN_TYPE_CONTROLLER:
  1042. SetFeature(WIN_FEATURE_FOCUSABLE);
  1043. SetFeature(WIN_FEATURE_RELOADABLE);
  1044. break;
  1045. case WIN_TYPE_INFO:
  1046. // no features
  1047. break;
  1048. #ifdef _PRINT_SUPPORT_
  1049. case WIN_TYPE_PRINT_SELECTION:
  1050. SetFeature(WIN_FEATURE_PRINTABLE);
  1051. break;
  1052. #endif // _PRINT_SUPPORT_
  1053. case WIN_TYPE_DIALOG:
  1054. SetFeature(WIN_FEATURE_NAVIGABLE);
  1055. SetFeature(WIN_FEATURE_FOCUSABLE);
  1056. break;
  1057. case WIN_TYPE_THUMBNAIL:
  1058. SetFeature(WIN_FEATURE_RELOADABLE);
  1059. break;
  1060. case WIN_TYPE_DEVTOOLS:
  1061. SetFeature(WIN_FEATURE_ALERTS);
  1062. SetFeature(WIN_FEATURE_PRINTABLE);
  1063. SetFeature(WIN_FEATURE_RELOADABLE);
  1064. SetFeature(WIN_FEATURE_FOCUSABLE);
  1065. break;
  1066. default:
  1067. // if this happens, add more window types or correct your code!
  1068. OP_ASSERT(true == false);
  1069. }
  1070. }
  1071. void Window::RemoveFeature(Window_Feature feature)
  1072. {
  1073. m_features &= ~feature;
  1074. }
  1075. BOOL Window::HasFeature(Window_Feature feature)
  1076. {
  1077. if (m_features & feature)
  1078. return TRUE;
  1079. else
  1080. return FALSE;
  1081. }
  1082. BOOL Window::HasAllFeatures(Window_Feature feature)
  1083. {
  1084. if ((m_features & feature) == (unsigned long) feature)
  1085. return TRUE;
  1086. else
  1087. return FALSE;
  1088. }
  1089. OP_STATUS Window::SetFullScreenState(OpWindowCommander::FullScreenState state)
  1090. {
  1091. if (m_fullscreen_state == state)
  1092. return OpStatus::OK;
  1093. FramesDocument *doc = doc_manager->GetCurrentDoc();
  1094. /* Store the new state before calling DOMExitFullscreen() so it does not notify the platform
  1095. * about turning fullscreen off (the platform is the one which turned it off).
  1096. */
  1097. m_fullscreen_state = state;
  1098. if (doc)
  1099. {
  1100. #ifdef DOM_FULLSCREEN_MODE
  1101. if (state == OpWindowCommander::FULLSCREEN_NONE)
  1102. {
  1103. // Fullscreen was disabled.
  1104. RETURN_IF_MEMORY_ERROR(doc->DOMExitFullscreen(NULL));
  1105. }
  1106. #endif // DOM_FULLSCREEN_MODE
  1107. // Try to keep the scroll positions
  1108. doc_manager->StoreViewport(doc_manager->CurrentDocListElm());
  1109. }
  1110. vis_device->SetScrollType(m_fullscreen_state != OpWindowCommander::FULLSCREEN_PROJECTION && bShowScrollbars ? VisualDevice::VD_SCROLLING_AUTO : VisualDevice::VD_SCROLLING_NO);
  1111. if (doc)
  1112. {
  1113. RETURN_IF_MEMORY_ERROR(UpdateWindow()); // cause reformat because stylesheets may be different
  1114. BOOL make_fit = doc->IsLocalDocFinished();
  1115. doc_manager->RestoreViewport(TRUE, TRUE, make_fit);
  1116. }
  1117. return OpStatus::OK;
  1118. }
  1119. void Window::SetOutputAssociatedWindow(Window* ass)
  1120. {
  1121. OutputAssociatedWindow = ass ? ass->Id() : 0;
  1122. }
  1123. void Window::SetShowScrollbars(BOOL show)
  1124. {
  1125. bShowScrollbars = show;
  1126. vis_device->SetScrollType(bShowScrollbars ? VisualDevice::VD_SCROLLING_AUTO : VisualDevice::VD_SCROLLING_NO);
  1127. if (FramesDocument *doc = doc_manager->GetCurrentDoc())
  1128. {
  1129. doc->RecalculateScrollbars();
  1130. doc->RecalculateLayoutViewSize(TRUE);
  1131. }
  1132. }
  1133. void Window::SetName(const uni_char *n)
  1134. {
  1135. OP_STATUS ret = name.Set(n);
  1136. if (OpStatus::IsError(ret))
  1137. {
  1138. RaiseCondition(ret);
  1139. }
  1140. }
  1141. void Window::SetNextCSSMode()
  1142. {
  1143. switch (CSSMode)
  1144. {
  1145. case CSS_FULL:
  1146. SetCSSMode(CSS_NONE);
  1147. break;
  1148. default:
  1149. SetCSSMode(CSS_FULL);
  1150. break;
  1151. }
  1152. }
  1153. void Window::SetCSSMode(CSSMODE f)
  1154. {
  1155. CSSMode = f;
  1156. OpDocumentListener::CssDisplayMode mode;
  1157. if (CSSMode == CSS_FULL)
  1158. {
  1159. mode = OpDocumentListener::CSS_AUTHOR_MODE;
  1160. }
  1161. else
  1162. {
  1163. mode = OpDocumentListener::CSS_USER_MODE;
  1164. }
  1165. m_windowCommander->GetDocumentListener()->OnCssModeChanged(m_windowCommander, mode);
  1166. OP_STATUS ret = UpdateWindow();
  1167. if (OpStatus::IsMemoryError(ret))
  1168. {
  1169. RaiseCondition(ret);//FIXME:OOM - Can't return OOM err.
  1170. }
  1171. }
  1172. void Window::SetForceEncoding(const char *encoding, BOOL isnewwin)
  1173. {
  1174. OP_STATUS ret = forceEncoding.Set(encoding);
  1175. if (OpStatus::IsMemoryError(ret))
  1176. {
  1177. RaiseCondition(ret);//FIXME:OOM - Can't return OOM err.
  1178. }
  1179. // Update document in window
  1180. if (!isnewwin)
  1181. {
  1182. ret = doc_manager->UpdateCurrentDoc(FALSE, FALSE, FALSE);
  1183. if (OpStatus::IsMemoryError(ret))
  1184. {
  1185. RaiseCondition(ret);//FIXME:OOM - Can't return OOM err.
  1186. }
  1187. }
  1188. }
  1189. void Window::UpdateVisitedLinks(const URL& url)
  1190. {
  1191. doc_manager->UpdateVisitedLinks(url);
  1192. }
  1193. #ifdef SHORTCUT_ICON_SUPPORT
  1194. # ifdef ASYNC_IMAGE_DECODERS
  1195. void Window::OnPortionDecoded()
  1196. {
  1197. if (shortcut_icon_provider && shortcut_icon_provider->GetImage().ImageDecoded())
  1198. {
  1199. m_windowCommander->GetDocumentListener()->OnDocumentIconAdded(m_windowCommander);
  1200. }
  1201. }
  1202. # endif // ASYNC_IMAGE_DECODERS
  1203. #ifdef SVG_SUPPORT
  1204. OP_STATUS Window::SetSVGAsWindowIcon(SVGImageRef* ref)
  1205. {
  1206. if(!shortcut_icon_provider)
  1207. {
  1208. URL* url = ref->GetUrl();
  1209. shortcut_icon_provider = UrlImageContentProvider::FindImageContentProvider(*url);
  1210. if (shortcut_icon_provider == NULL)
  1211. {
  1212. shortcut_icon_provider = OP_NEW(UrlImageContentProvider, (*url));
  1213. if (shortcut_icon_provider == NULL)
  1214. return OpStatus::ERR_NO_MEMORY;
  1215. }
  1216. }
  1217. shortcut_icon_provider->SetSVGImageRef(ref);
  1218. shortcut_icon_provider->IncRef(NULL);
  1219. return OpStatus::OK;
  1220. }
  1221. void Window::RemoveSVGWindowIcon(SVGImageRef* ref)
  1222. {
  1223. if (shortcut_icon_provider && shortcut_icon_provider->GetSVGImageRef() == ref)
  1224. {
  1225. shortcut_icon_provider->DecRef(NULL);
  1226. shortcut_icon_provider = NULL;
  1227. }
  1228. }
  1229. #endif // SVG_SUPPORT
  1230. OP_STATUS Window::SetWindowIcon(URL* url)
  1231. {
  1232. // proposal:
  1233. // make core passive and let ui query document (via Window) each
  1234. // time a page is loaded?
  1235. if (url)
  1236. {
  1237. if (url->Status(TRUE) != URL_LOADED)
  1238. {
  1239. url = NULL;
  1240. if (FramesDocument *frm_doc = GetCurrentDoc())
  1241. {
  1242. URL *icon = frm_doc->Icon();
  1243. HTML_Element *he = frm_doc->GetDocRoot();
  1244. if (icon && he)
  1245. {
  1246. OP_BOOLEAN loading = frm_doc->LoadIcon(icon, he);
  1247. if (OpStatus::IsMemoryError(loading))
  1248. return loading;
  1249. }
  1250. return OpStatus::OK;
  1251. }
  1252. }
  1253. else if (url->Type() == URL_HTTP || url->Type() == URL_HTTPS)
  1254. {
  1255. int response = url->GetAttribute(URL::KHTTP_Response_Code);
  1256. if (response != HTTP_OK && response != HTTP_NOT_MODIFIED)
  1257. url = NULL;
  1258. }
  1259. }
  1260. #ifdef SVG_SUPPORT
  1261. SVGImageRef* ref = NULL;
  1262. if (url && url->ContentType() == URL_SVG_CONTENT)
  1263. {
  1264. ref = shortcut_icon_provider ? shortcut_icon_provider->GetSVGImageRef() : NULL;
  1265. if(ref)
  1266. {
  1267. shortcut_icon_provider->SetSVGImageRef(NULL); // detach for a moment
  1268. }
  1269. else
  1270. {
  1271. OP_STATUS status = OpStatus::ERR;
  1272. if (FramesDocument* frm_doc = GetCurrentDoc())
  1273. if (LogicalDocument* logdoc = frm_doc->GetLogicalDocument())
  1274. {
  1275. status = logdoc->GetSVGWorkplace()->GetSVGImageRef(*url, &ref);
  1276. if (OpStatus::IsSuccess(status))
  1277. SetSVGAsWindowIcon(ref);
  1278. }
  1279. return status;
  1280. }
  1281. }
  1282. // Need to render the SVG icon if we have a ref parameter...
  1283. if(!ref)
  1284. #endif // SVG_SUPPORT
  1285. {
  1286. if (url ? *url == m_shortcut_icon_url : m_shortcut_icon_url.IsEmpty())
  1287. return OpStatus::OK;
  1288. }
  1289. if (url)
  1290. m_shortcut_icon_url = URL(*url);
  1291. else
  1292. m_shortcut_icon_url = URL();
  1293. #ifndef ASYNC_IMAGE_DECODERS
  1294. if (shortcut_icon_provider)
  1295. {
  1296. // shortcut_icon_provider->GetImage().DecVisible(null_image_listener);
  1297. shortcut_icon_provider->DecRef(NULL);
  1298. shortcut_icon_provider = NULL;
  1299. }
  1300. #else // !ASYNC_IMAGE_DECODERS
  1301. if (shortcut_icon_provider && (shortcut_icon_provider->GetImage().ImageDecoded() || !url))
  1302. {
  1303. shortcut_icon_provider->GetImage().DecVisible(this);
  1304. shortcut_icon_provider->DecRef(NULL);
  1305. shortcut_icon_provider = NULL;
  1306. }
  1307. #endif // ASYNC_IMAGE_DECODERS
  1308. if (url)
  1309. {
  1310. shortcut_icon_provider = UrlImageContentProvider::FindImageContentProvider(*url);
  1311. if (shortcut_icon_provider == NULL)
  1312. {
  1313. shortcut_icon_provider = OP_NEW(UrlImageContentProvider, (*url));
  1314. if (shortcut_icon_provider == NULL)
  1315. {
  1316. #ifdef SVG_SUPPORT
  1317. if (ref != NULL)
  1318. OpStatus::Ignore(ref->Free());
  1319. #endif // SVG_SUPPORT
  1320. return OpStatus::ERR_NO_MEMORY;
  1321. }
  1322. // Changing contenttype to an image - if it seems like it is a favicon
  1323. if(!url->GetAttribute(URL::KIsImage))
  1324. {
  1325. OpString ext;
  1326. OP_STATUS ret_val = url->GetAttribute(URL::KSuggestedFileNameExtension_L, ext);
  1327. if (OpStatus::IsSuccess(ret_val))
  1328. {
  1329. const char* data;
  1330. INT32 data_len;
  1331. BOOL more;
  1332. ret_val = shortcut_icon_provider->GetData(data, data_len, more);
  1333. // If it contains the magic sequence (copied from modules/img/src/decoderfactoryico.cpp
  1334. // method DecoderFactoryIco::CheckType) and if urls suggested extension is ico :
  1335. // Force content type to be image/x-icon
  1336. // This will result in it being accepted as an image by the image module. [psmaas 27-01-2006]
  1337. if (OpStatus::IsSuccess(ret_val) && data_len >= 4 && op_memcmp(data, "\0\0\1\0", 4) == 0 && ext.Compare("ico") == 0)
  1338. {
  1339. ret_val = url->SetAttribute(URL::KMIME_ForceContentType, "image/x-icon");
  1340. }
  1341. }
  1342. if(OpStatus::IsMemoryError(ret_val))
  1343. {
  1344. #ifdef SVG_SUPPORT
  1345. if (ref != NULL)
  1346. OpStatus::Ignore(ref->Free());
  1347. #endif // SVG_SUPPORT
  1348. OP_DELETE(shortcut_icon_provider);
  1349. shortcut_icon_provider = NULL;
  1350. return OpStatus::ERR_NO_MEMORY;
  1351. }
  1352. }
  1353. }
  1354. #ifdef SVG_SUPPORT
  1355. if (ref && url->ContentType() == URL_SVG_CONTENT)
  1356. {
  1357. int desired_width = 16; // FIXME: Is 16x16 a good default?
  1358. int desired_height = 16;
  1359. #ifdef PIXEL_SCALE_RENDERING_SUPPORT
  1360. const PixelScaler& scaler = vis_device->GetVPScale();
  1361. desired_width = TO_DEVICE_PIXEL(scaler, desired_width);
  1362. desired_height = TO_DEVICE_PIXEL(scaler, desired_height);
  1363. #endif // PIXEL_SCALE_RENDERING_SUPPORT
  1364. SVGImage* svgimage = ref->GetSVGImage();
  1365. if (!svgimage)
  1366. {
  1367. #ifdef SVG_SUPPORT
  1368. OpStatus::Ignore(ref->Free());
  1369. #endif // SVG_SUPPORT
  1370. OP_DELETE(shortcut_icon_provider);
  1371. shortcut_icon_provider = NULL;
  1372. return OpStatus::OK;
  1373. }
  1374. Image img = shortcut_icon_provider->GetImage();
  1375. if (img.IsFailed() ||
  1376. img.Width() != (unsigned int) desired_width ||
  1377. img.Height() != (unsigned int) desired_height)
  1378. {
  1379. OpBitmap* res;
  1380. if (OpStatus::IsSuccess(svgimage->PaintToBuffer(res, 0, desired_width, desired_height)))
  1381. {
  1382. if(OpStatus::IsError(img.ReplaceBitmap(res)))
  1383. {
  1384. OP_DELETE(res);
  1385. }
  1386. else
  1387. {
  1388. shortcut_icon_provider->SetSVGImageRef(ref);
  1389. ref = NULL;
  1390. }
  1391. }
  1392. }
  1393. if (ref)
  1394. {
  1395. OpStatus::Ignore(ref->Free());
  1396. OP_DELETE(shortcut_icon_provider);
  1397. shortcut_icon_provider = NULL;
  1398. return OpStatus::OK;
  1399. }
  1400. }
  1401. #endif // SVG_SUPPORT
  1402. shortcut_icon_provider->IncRef(NULL);
  1403. #ifdef ASYNC_IMAGE_DECODERS
  1404. shortcut_icon_provider->GetImage().IncVisible(this);
  1405. #endif
  1406. }
  1407. Image icon;
  1408. if (shortcut_icon_provider)
  1409. icon = shortcut_icon_provider->GetImage();
  1410. // to force loading
  1411. #ifndef ASYNC_IMAGE_DECODERS
  1412. RETURN_IF_ERROR(icon.IncVisible(null_image_listener));
  1413. if (shortcut_icon_provider)
  1414. icon.OnMoreData(shortcut_icon_provider);
  1415. #endif // ASYNC_IMAGE_DECODERS
  1416. // We need this call when running ASYNC_IMAGE_DECODERS as well in order
  1417. // to get notified about it when doing a reload..
  1418. m_windowCommander->GetDocumentListener()->OnDocumentIconAdded(m_windowCommander);
  1419. #ifndef ASYNC_IMAGE_DECODERS
  1420. icon.DecVisible(null_image_listener);
  1421. #endif
  1422. return OpStatus::OK;
  1423. }
  1424. Image Window::GetWindowIcon() const
  1425. {
  1426. if (shortcut_icon_provider)
  1427. return shortcut_icon_provider->GetImage(); // CAN BE DANGEROUS IF KEEPT WHILE shortcut_icon_provider is deleted.
  1428. return Image();
  1429. }
  1430. BOOL Window::HasWindowIcon() const
  1431. {
  1432. if (shortcut_icon_provider)
  1433. return !shortcut_icon_provider->GetImage().IsEmpty();
  1434. return FALSE;
  1435. }
  1436. OP_STATUS Window::DecodeWindowIcon()
  1437. {
  1438. if (!HasWindowIcon() || shortcut_icon_provider->GetImage().ImageDecoded())
  1439. return OpStatus::OK;
  1440. Image icon = shortcut_icon_provider->GetImage();
  1441. RETURN_IF_ERROR(icon.IncVisible(null_image_listener));
  1442. icon.OnMoreData(shortcut_icon_provider);
  1443. icon.DecVisible(null_image_listener);
  1444. return OpStatus::OK;
  1445. }
  1446. #endif // SHORTCUT_ICON_SUPPORT
  1447. #ifdef HISTORY_SUPPORT
  1448. OP_STATUS Window::AddToGlobalHistory(URL& url, const uni_char *title)
  1449. {
  1450. if (g_globalHistory && !m_privacy_mode && m_global_history_enabled && g_url_api->GlobalHistoryPermitted(url) )
  1451. if (HasFeature(WIN_FEATURE_NAVIGABLE))
  1452. {
  1453. OpString url_string;
  1454. RETURN_IF_ERROR(url.GetAttribute(URL::KUniName_With_Fragment_Username, url_string));
  1455. return g_globalHistory->Add(url_string, title, g_timecache->CurrentTime());
  1456. }
  1457. return OpStatus::OK;
  1458. }
  1459. #endif // HISTORY_SUPPORT
  1460. /* Limited length of window titles. Apparently there's a Internet
  1461. Explorer extension that can't handle long window titles. This
  1462. patch works around the problem, and at the same time looks nice. */
  1463. OP_STATUS Window::SetWindowTitle(const OpString& nstr, BOOL force, BOOL generated)
  1464. {
  1465. generated_title = generated;
  1466. const uni_char *str = nstr.CStr();
  1467. if (!str)
  1468. str = UNI_L("...");
  1469. BOOL titleChanged = title.IsEmpty() || !uni_str_eq(str, title.CStr());
  1470. // Reset defaultStatus only when title changes and force is not set
  1471. if(titleChanged && !force)
  1472. {
  1473. RETURN_IF_ERROR(SetDefaultMessage(UNI_L("")));
  1474. }
  1475. // Only set window title if it changed or we are forced to do an update
  1476. if (titleChanged || force)
  1477. {
  1478. if (titleChanged)
  1479. RETURN_IF_ERROR(title.Set(str));
  1480. int strLen = uni_strlen(str) + 1;
  1481. uni_char *newTitle = OP_NEWA(uni_char, strLen);
  1482. if (newTitle == NULL)
  1483. {
  1484. return OpStatus::ERR_NO_MEMORY;
  1485. }
  1486. uni_strcpy(newTitle, str);
  1487. if (strLen > DOC_WINDOW_MAX_TITLE_LENGTH)
  1488. uni_strcpy(newTitle + DOC_WINDOW_MAX_TITLE_LENGTH - 4, UNI_L("..."));
  1489. m_windowCommander->GetDocumentListener()->OnTitleChanged(m_windowCommander, newTitle);
  1490. #ifdef SCOPE_WINDOW_MANAGER_SUPPORT
  1491. OpScopeWindowListener::OnWindowTitleChanged(this);
  1492. #endif // SCOPE_WINDOW_MANAGER_SUPPORT
  1493. OP_DELETEA(newTitle);
  1494. }
  1495. return OpStatus::OK;
  1496. }
  1497. void Window::SignalSecurityState(BOOL changed)
  1498. {
  1499. switch (doc_manager->GetLoadStatus())
  1500. {
  1501. case NOT_LOADING:
  1502. case DOC_CREATED:
  1503. case WAIT_MULTIPART_RELOAD:
  1504. break;
  1505. default:
  1506. /* Don't signal new security state to UI while loading URL until we've
  1507. created a new document. If we do, we'll be reporting a security
  1508. state that doesn't match the currently displayed document in the
  1509. window, which could possibly be the cause of spoofing bugs.
  1510. One exception though: if we for some reason have already reported a
  1511. specific security state and are now about to lower it we don't want
  1512. to delay the lowering. */
  1513. if (!(SecurityState < SecurityState_signalled && SecurityState_signalled != SECURITY_STATE_UNKNOWN || SecurityState == SECURITY_STATE_UNKNOWN))
  1514. {
  1515. if (changed)
  1516. SecurityState_signal_delayed = TRUE;
  1517. return;
  1518. }
  1519. }
  1520. if (changed || SecurityState_signal_delayed)
  1521. {
  1522. OpDocumentListener::SecurityMode mode = m_windowCommander->GetSecurityModeFromState(SecurityState);
  1523. m_windowCommander->GetDocumentListener()->OnSecurityModeChanged(m_windowCommander, mode, SecurityState_changed_by_inline);
  1524. SecurityState_signalled = SecurityState;
  1525. SecurityState_signal_delayed = FALSE;
  1526. }
  1527. }
  1528. void Window::ResetSecurityStateToUnknown()
  1529. {
  1530. LowLevelSetSecurityState(SECURITY_STATE_UNKNOWN, FALSE, NULL);
  1531. }
  1532. void Window::SetSecurityState(BYTE sec, BOOL is_inline, const uni_char *name, URL *url)
  1533. {
  1534. if (sec != SECURITY_STATE_UNKNOWN)
  1535. LowLevelSetSecurityState(sec, is_inline, name, url);
  1536. }
  1537. void Window::LowLevelSetSecurityState(BYTE sec, BOOL is_inline, const uni_char *name, URL *url)
  1538. {
  1539. if (sec < SecurityState || sec == SECURITY_STATE_UNKNOWN)
  1540. {
  1541. BOOL state_changed = FALSE;
  1542. if (SecurityState != sec)
  1543. {
  1544. // Before core-2.3 we didn't let the UI know about changes between UNKNOWN and NONE
  1545. // but as always it turned out to be better to tell the whole truth.
  1546. state_changed = TRUE;
  1547. #ifdef SSL_CHECK_EXT_VALIDATION_POLICY
  1548. if(SecurityState >= SECURITY_STATE_SOME_EXTENDED &&
  1549. SecurityState <= SECURITY_STATE_FULL_EXTENDED &&
  1550. sec >= SECURITY_STATE_FULL && sec <SECURITY_STATE_FULL_EXTENDED &&
  1551. !(BOOL) g_pcnet->GetIntegerPref(PrefsCollectionNetwork::StrictEVMode))
  1552. {
  1553. if (SecurityState == SECURITY_STATE_SOME_EXTENDED && SecurityTextName.Compare(name) == 0)
  1554. return;
  1555. else
  1556. sec = SECURITY_STATE_SOME_EXTENDED;
  1557. }
  1558. #endif // SSL_CHECK_EXT_VALIDATION_POLICY
  1559. }
  1560. SecurityState = sec;
  1561. if (SecurityTextName.Set(sec && sec != SECURITY_STATE_UNKNOWN ? name : NULL) == OpStatus::ERR_NO_MEMORY)
  1562. RaiseCondition(OpStatus::ERR_NO_MEMORY);
  1563. if (state_changed)
  1564. {
  1565. SecurityState_changed_by_inline = is_inline;
  1566. SignalSecurityState(TRUE);
  1567. }
  1568. }
  1569. }
  1570. #ifdef TRUST_RATING
  1571. void Window::SetTrustRating(TrustRating rating, BOOL force)
  1572. {
  1573. OP_ASSERT(rating != Untrusted_Ask_Advisory);
  1574. if (force || m_trust_rating < rating)
  1575. {
  1576. m_trust_rating = rating;
  1577. m_windowCommander->GetDocumentListener()->OnTrustRatingChanged(m_windowCommander, rating);
  1578. }
  1579. }
  1580. OP_STATUS Window::CheckTrustRating(BOOL force, BOOL offline)
  1581. {
  1582. DocumentTreeIterator iter(doc_manager);
  1583. iter.SetIncludeThis();
  1584. while (iter.Next())
  1585. {
  1586. if (FramesDocument* doc = iter.GetFramesDocument())
  1587. RETURN_IF_MEMORY_ERROR(iter.GetDocumentManager()->CheckTrustRating(doc->GetURL(), offline, force));
  1588. }
  1589. return OpStatus::OK;
  1590. }
  1591. #endif // TRUST_RATING
  1592. void Window::SetType(DocType doc_type)
  1593. {
  1594. /* Not entirely sure this function serves much of a purpose anymore. */
  1595. if (type != WIN_TYPE_DOWNLOAD && IsCustomWindow())
  1596. return;
  1597. if (type == WIN_TYPE_JS_CONSOLE ) // console is a custom window (maybe it should not be that)
  1598. return;
  1599. SetType(WIN_TYPE_NORMAL);
  1600. }
  1601. BOOL Window::CloneWindow(Window**return_window,BOOL open_in_background)
  1602. {
  1603. if (IsCustomWindow())
  1604. return FALSE;
  1605. BOOL3 open_in_new_window = YES;
  1606. BOOL3 in_background = open_in_background?YES:NO;
  1607. Window* new_window = g_windowManager->GetAWindow(TRUE, open_in_new_window, in_background);
  1608. if (!new_window)
  1609. return FALSE;
  1610. new_window->SetCSSMode(CSSMode);
  1611. new_window->SetScale(GetScale());
  1612. new_window->SetTextScale(GetTextScale());
  1613. new_window->SetForceEncoding(GetForceEncoding(), TRUE);
  1614. if (load_img && show_img)
  1615. {
  1616. new_window->SetImagesSetting(FIGS_ON);
  1617. }
  1618. else if (show_img)
  1619. {
  1620. new_window->SetImagesSetting(FIGS_SHOW);
  1621. }
  1622. else
  1623. {
  1624. new_window->SetImagesSetting(FIGS_OFF);
  1625. }
  1626. #ifdef FIT_LARGE_IMAGES_TO_WINDOW_WIDTH
  1627. new_window->fit_img = fit_img;
  1628. #endif // FIT_LARGE_IMAGES_TO_WINDOW_WIDTH
  1629. DocumentManager* doc_man1 = DocManager();
  1630. DocumentManager* doc_man2 = new_window->DocManager();
  1631. short pos = GetCurrentHistoryNumber();
  1632. DocListElm* doc_elm = doc_man1->FirstDocListElm();
  1633. while (doc_elm)
  1634. {
  1635. FramesDocument* doc = doc_elm->Doc();
  1636. if (doc)
  1637. {
  1638. URL docurl = doc->GetURL();
  1639. DocumentReferrer referrer(doc->GetRefURL());
  1640. RAISE_IF_MEMORY_ERROR(doc_man2->AddNewHistoryPosition(docurl, referrer, doc_elm->Number(), doc_elm->Title(), FALSE, doc->IsPluginDoc()));
  1641. }
  1642. doc_elm = doc_elm->Suc();
  1643. }
  1644. new_window->min_history_number = min_history_number;
  1645. new_window->max_history_number = max_history_number;
  1646. new_window->current_history_number = pos;
  1647. new_window->SetCurrentHistoryPos(pos, TRUE, TRUE);
  1648. if(return_window)
  1649. *return_window=new_window;
  1650. return FALSE;
  1651. }
  1652. // Returns NULL on OOM
  1653. uni_char* Window::ComposeLinkInformation(const uni_char* hlink, const uni_char* rel_name)
  1654. {
  1655. const uni_char *empty = UNI_L("");
  1656. uni_char* link = NULL;
  1657. if (!hlink)
  1658. hlink = empty;
  1659. // FIXME(?): The non-configurable DisplayRelativeLink() has been removed
  1660. if (rel_name)
  1661. {
  1662. unsigned int len = uni_strlen(hlink) + uni_strlen(rel_name) + 2;
  1663. link = OP_NEWA(uni_char, len);
  1664. if (link)
  1665. uni_snprintf(link, len, UNI_L("%s#%s"), hlink, rel_name);
  1666. }
  1667. else
  1668. OpStatus::Ignore(UniSetStr_NotEmpty(link, hlink)); // link remains NULL if it fails
  1669. return link;
  1670. }
  1671. OP_STATUS Window::SetProgressText(URL& url, BOOL unused /* = FALSE */)
  1672. {
  1673. // In case we have a URL that is redirecting to another page, we have to call Access to mark it visited.
  1674. // Otherwise the original link won't be marked as visited (since the redirecting url isn't a document)
  1675. if (!GetPrivacyMode())
  1676. url.Access(TRUE);
  1677. return OpStatus::OK;
  1678. }
  1679. BOOL Window::HandleMessage(UINT message, int id, long user_data)
  1680. {
  1681. return FALSE;
  1682. }
  1683. OP_STATUS Window::OpenURL(const char* in_url_str, BOOL check_if_expired, BOOL user_initiated, BOOL reload, BOOL is_hotlist_url, BOOL open_in_background, EnteredByUser entered_by_user, BOOL called_externally)
  1684. {
  1685. OpString16 tmp_str;
  1686. RETURN_IF_ERROR(tmp_str.SetFromUTF8(in_url_str));
  1687. return OpenURL(tmp_str.CStr(), check_if_expired, user_initiated, reload, is_hotlist_url,open_in_background,entered_by_user, called_externally);
  1688. }
  1689. OP_STATUS Window::OpenURL(const uni_char* in_url_str, BOOL check_if_expired, BOOL user_initiated, BOOL reload, BOOL is_hotlist_url, BOOL open_in_background, EnteredByUser entered_by_user, BOOL called_externally, URL_CONTEXT_ID context_id)
  1690. {
  1691. if (!in_url_str)
  1692. return OpStatus::OK;
  1693. OpString search_url;
  1694. #ifdef AB_ERROR_SEARCH_FORM
  1695. //The following text will be used to present back to the user
  1696. //in the search field in error pages. More than a few hundred
  1697. //chars is already information overload
  1698. if(entered_by_user == WasEnteredByUser)
  1699. OpStatus::Ignore(m_typed_in_url.Set(in_url_str, 200));
  1700. #endif // AB_ERROR_SEARCH_FORM
  1701. #ifdef SEARCH_ENGINES
  1702. if (uni_isalpha(in_url_str[0]) && uni_isspace(in_url_str[1]) && in_url_str[2])
  1703. {
  1704. OpString key;
  1705. key.Set(in_url_str, 1);
  1706. SearchElement* search_element = g_search_manager->GetSearchByKey(key);
  1707. if (search_element)
  1708. {
  1709. OpString search_query;
  1710. OpString post_query;
  1711. search_query.Set(in_url_str+2);
  1712. if (search_element->MakeSearchString(search_url, post_query, search_query) != OpStatus::OK)
  1713. search_url.Empty();
  1714. }
  1715. }
  1716. #endif // SEARCH_ENGINES
  1717. const uni_char* new_in_url_str=in_url_str;
  1718. while (uni_isspace(*new_in_url_str))
  1719. new_in_url_str++;
  1720. OpString acpUrlStr;
  1721. #ifdef SLASHDOT_EASTEREGG
  1722. if (uni_strcmp(new_in_url_str, "/.") == 0)
  1723. {
  1724. RETURN_IF_ERROR(acpUrlStr.Set(UNI_L("http://slashdot.org/")));
  1725. }
  1726. else
  1727. #endif // SLASHDOT_EASTEREGG
  1728. {
  1729. if (search_url.HasContent())
  1730. {
  1731. RETURN_IF_ERROR(acpUrlStr.Set(search_url));
  1732. }
  1733. else
  1734. RETURN_IF_ERROR(acpUrlStr.Set(new_in_url_str));
  1735. }
  1736. #ifdef CORE_BOOKMARKS_SUPPORT
  1737. // Nickname ?
  1738. if (!uni_strpbrk((const OpChar *) acpUrlStr.CStr(), UNI_L(".:/?\\")))
  1739. {
  1740. BookmarkAttribute attr;
  1741. RETURN_IF_ERROR(attr.SetTextValue(acpUrlStr.CStr()));
  1742. BookmarkItem *bookmark = g_bookmark_manager->GetFirstByAttribute(BOOKMARK_SHORTNAME, &attr);
  1743. if (bookmark && bookmark->GetFolderType() == FOLDER_NO_FOLDER)
  1744. {
  1745. RETURN_IF_ERROR(bookmark->GetAttribute(BOOKMARK_URL, &attr));
  1746. RETURN_IF_ERROR(attr.GetTextValue(acpUrlStr));
  1747. }
  1748. }
  1749. #endif // CORE_BOOKMARKS_SUPPORT
  1750. OpString acpUrlNameResolved;
  1751. OP_STATUS r;
  1752. BOOL res = FALSE;
  1753. TRAP(r,res=g_url_api->ResolveUrlNameL(acpUrlStr, acpUrlNameResolved, entered_by_user == WasEnteredByUser));
  1754. RETURN_IF_ERROR(r);
  1755. if (!res)
  1756. return OpStatus::OK;
  1757. if (acpUrlNameResolved.CStr() == NULL)
  1758. return OpStatus::OK;
  1759. URL url;
  1760. #ifdef AB_ERROR_SEARCH_FORM
  1761. //set for OpIllegalHost page to have access to the raw text
  1762. g_windowManager->SetLastTypedUserText(&m_typed_in_url);
  1763. #endif // AB_ERROR_SEARCH_FORM
  1764. URL_CONTEXT_ID id = 0;
  1765. # ifdef GADGET_SUPPORT
  1766. /* Checking for the gadget context id first was seemingly done on purpose here, so i left it
  1767. * like that when i moved the search for a suitable context id to GetUrlContextId(), if the
  1768. * order is not really important the GADGET_SUPPORT section here can be safely removed
  1769. * since this case is covered in GetUrlContextId() */
  1770. if (GetGadget())
  1771. id = GetGadget()->UrlContextId();
  1772. else
  1773. # endif // GADGET_SUPPORT
  1774. id = (context_id != static_cast<URL_CONTEXT_ID>(-1)) ? context_id : GetUrlContextId(acpUrlNameResolved.CStr());
  1775. url = g_url_api->GetURL(acpUrlNameResolved.CStr(), id);
  1776. #ifdef SUPPORT_VISUAL_ADBLOCK
  1777. // cache the server name so it's faster to do a lookup to check if the content blocker is enabled or not
  1778. m_content_block_server_name = url.GetServerName();
  1779. if(m_content_block_server_name)
  1780. m_content_block_enabled = g_pcnet->GetIntegerPref(PrefsCollectionNetwork::EnableContentBlocker, m_content_block_server_name) != 0;
  1781. #endif // SUPPORT_VISUAL_ADBLOCK
  1782. if (!url.IsEmpty())
  1783. {
  1784. URL dummy;
  1785. if(is_hotlist_url && (url.Type() == URL_HTTP || url.Type() == URL_HTTPS))
  1786. {
  1787. OpStringC8 name = url.GetAttribute(URL::KUserName).CStr();
  1788. if(name.CStr() == NULL && url.GetAttribute(URL::KPassWord).CStr() != NULL)
  1789. name = "";
  1790. ServerName *sn = (ServerName *) url.GetAttribute(URL::KServerName, NULL);
  1791. if(name.CStr() != NULL && !sn->GetPassUserNameURLsAutomatically(name))
  1792. {
  1793. RETURN_IF_ERROR(sn->SetPassUserNameURLsAutomatically(name));
  1794. }
  1795. }
  1796. #ifdef REDIRECT_ON_ERROR
  1797. //This partially resolved url will be used to redirect the user directly to a search engine
  1798. //See PrefsCollectionNetwork::HostNameWebLookupAddress
  1799. //The typed url value being set above in this same function, if any,
  1800. //was used in the call to g_url_api->GetURL(acpUrlNameResolved.CStr());
  1801. //which could have generated an OpIllegalHostPage in case the url was malformed.
  1802. //This would present the url in a clearly visible text field to the user
  1803. //Now the url is sabed again, this time to be used for the automatic redirect.
  1804. //The new url needs to be stored because any username and password info have been removed
  1805. //and we cannot automatically upload that information to a 3rd party server
  1806. if(entered_by_user == WasEnteredByUser &&
  1807. g_pcnet->GetIntegerPref(PrefsCollectionNetwork::EnableHostNameWebLookup))
  1808. m_typed_in_url.Set(in_url_str);
  1809. #endif // REDIRECT_ON_ERROR
  1810. SetFlexRootMaxWidth(g_pcdisplay->GetIntegerPref(PrefsCollectionDisplay::FlexRootMaxWidth, url));
  1811. r = OpenURL(url, DocumentReferrer(dummy), check_if_expired, reload, -1, user_initiated, open_in_background, entered_by_user, called_externally);
  1812. }
  1813. #ifdef AB_ERROR_SEARCH_FORM
  1814. g_windowManager->SetLastTypedUserText(NULL);
  1815. #endif // AB_ERROR_SEARCH_FORM
  1816. return r;
  1817. }
  1818. OP_STATUS Window::OpenURL
  1819. (
  1820. OpenUrlInNewWindowInfo *info,
  1821. BOOL check_if_expired,
  1822. BOOL reload,
  1823. EnteredByUser entered_by_user,
  1824. BOOL called_externally
  1825. )
  1826. {
  1827. return OpenURL(info->new_url,
  1828. info->ref_url,
  1829. check_if_expired,
  1830. reload,
  1831. info->opener_sub_win_id,
  1832. info->user_initiated,
  1833. #if defined(QUICK)
  1834. KioskManager::GetInstance()->GetEnabled() && !KioskManager::GetInstance()->GetKioskWindows() ? FALSE :
  1835. #endif
  1836. info->open_in_background_window,
  1837. entered_by_user,
  1838. called_externally);
  1839. }
  1840. OP_STATUS Window::OpenURL(URL& url, DocumentReferrer ref_url, BOOL check_if_expired, BOOL reload, short sub_win_id,
  1841. BOOL user_initiated, BOOL open_in_background, EnteredByUser entered_by_user, BOOL called_externally)
  1842. {
  1843. DocumentManager* doc_man = GetDocManagerById(sub_win_id);
  1844. if (doc_man)
  1845. {
  1846. doc_man->ResetRequestThreadInfo();
  1847. #if defined REDIRECT_ON_ERROR || defined AB_ERROR_SEARCH_FORM
  1848. if(entered_by_user != WasEnteredByUser)
  1849. {
  1850. //it's better to wipe from memory because one never knows if
  1851. //some bug could criple in and store an url with username+password here
  1852. m_typed_in_url.Wipe();
  1853. m_typed_in_url.Empty();
  1854. }
  1855. #endif // defined REDIRECT_ON_ERROR || defined AB_ERROR_SEARCH_FORM
  1856. #ifdef _PRINT_SUPPORT_
  1857. if (print_mode)
  1858. StopPrinting();
  1859. #endif // _PRINT_SUPPORT_
  1860. DocumentManager::OpenURLOptions options;
  1861. options.user_initiated = user_initiated;
  1862. options.entered_by_user = entered_by_user;
  1863. options.called_externally = called_externally;
  1864. doc_man->OpenURL(url, DocumentReferrer(ref_url), check_if_expired, reload, options);
  1865. }
  1866. return OpStatus::OK;
  1867. }
  1868. void Window::HandleDocumentProgress(long bytes_read)
  1869. {
  1870. URL url = doc_manager->GetCurrentURL();
  1871. SetDocProgressCount(url.ContentLoaded());
  1872. m_loading_information.totalBytes = url.GetContentSize();
  1873. m_loading_information.loadedBytes = GetProgressCount();
  1874. m_loading_information.totalBytesRootDocument = m_loading_information.totalBytes;
  1875. m_loading_information.loadedBytesRootDocument = GetDocProgressCount();
  1876. FramesDocument* doc = GetCurrentDoc();
  1877. if (doc)
  1878. {
  1879. if (doc_manager->GetLoadStatus() == NOT_LOADING ||
  1880. doc_manager->GetLoadStatus() == DOC_CREATED)
  1881. {
  1882. DocLoadingInfo info;
  1883. doc->GetDocLoadingInfo(info);
  1884. m_loading_information.loadedImageCount = info.images.loaded_count;
  1885. m_loading_information.totalImageCount = info.images.total_count;
  1886. m_loading_information.loadedBytes = info.loaded_size;
  1887. m_loading_information.totalBytes = info.total_size;
  1888. #ifdef WEB_TURBO_MODE
  1889. m_loading_information.turboTransferredBytes = info.turbo_transferred_bytes + info.images.turbo_transferred_bytes;
  1890. m_loading_information.turboOriginalTransferredBytes = info.turbo_original_transferred_bytes + info.images.turbo_original_transferred_bytes;
  1891. #endif // WEB_TURBO_MODE
  1892. }
  1893. }
  1894. m_loading_information.loadingMessage = GetProgressMessage();
  1895. m_loading_information.isUploading = FALSE;
  1896. m_windowCommander->GetLoadingListener()->OnLoadingProgress(m_windowCommander, &m_loading_information);
  1897. }
  1898. void Window::HandleDataProgress(long bytes, BOOL upload_progress, const uni_char* extrainfo, MessageHandler *mh, URL *url)
  1899. {
  1900. // Since the same counter is used for both uploading and downloading we need to reset it
  1901. // when the direction changes
  1902. if (GetProgressState() == UPLOADING_FINISHED && !upload_progress)
  1903. SetProgressCount(0);
  1904. SetProgressCount(progress_count+bytes);
  1905. m_loading_information.loadedBytes = progress_count;
  1906. m_loading_information.isUploading = upload_progress;
  1907. // We need this to avoid calling OnLoadingProgress() before OnStartUploading().
  1908. // Both OnStartUploading() and OnLoadingProgress() will be called in SetProgressState().
  1909. if ( !upload_progress || phase_uploading )
  1910. m_windowCommander->GetLoadingListener()->OnLoadingProgress(m_windowCommander, &m_loading_information);
  1911. SetProgressState(upload_progress ? UPLOADING_FILES : FETCHING_DOCUMENT, extrainfo, mh, bytes, url);
  1912. }
  1913. void Window::UpdateLoadingInformation(int loaded_inlines, int total_inlines)
  1914. {
  1915. m_loading_information.loadedImageCount = loaded_inlines;
  1916. m_loading_information.totalImageCount = total_inlines;
  1917. m_loading_information.loadedBytesRootDocument = GetProgressCount();
  1918. m_loading_information.totalBytesRootDocument = DocManager()->GetCurrentURL().GetContentSize();
  1919. FramesDocument* doc = GetCurrentDoc();
  1920. if (doc && (doc_manager->GetLoadStatus() == NOT_LOADING || doc_manager->GetLoadStatus() == DOC_CREATED))
  1921. {
  1922. DocLoadingInfo info;
  1923. doc->GetDocLoadingInfo(info);
  1924. m_loading_information.loadedImageCount = info.images.loaded_count;
  1925. m_loading_information.totalImageCount = info.images.total_count;
  1926. m_loading_information.loadedBytes = info.loaded_size;
  1927. m_loading_information.totalBytes = info.total_size;
  1928. #ifdef WEB_TURBO_MODE
  1929. m_loading_information.turboTransferredBytes = info.turbo_transferred_bytes + info.images.turbo_transferred_bytes;
  1930. m_loading_information.turboOriginalTransferredBytes = info.turbo_original_transferred_bytes + info.images.turbo_original_transferred_bytes;
  1931. #endif // WEB_TURBO_MODE
  1932. }
  1933. m_loading_information.isUploading = FALSE;
  1934. m_windowCommander->GetLoadingListener()->OnLoadingProgress(m_windowCommander, &m_loading_information);
  1935. }
  1936. void Window::LoadPendingUrl(URL_ID url_id, int sub_win_id, BOOL user_initiated)
  1937. {
  1938. if (sub_win_id == -2)
  1939. {
  1940. // "LoadPendingURL with sub_win_id == -2 *cannot* work"
  1941. BOOL3 open_in_new_window = MAYBE;
  1942. BOOL3 open_in_background = MAYBE;
  1943. g_windowManager->GetAWindow(TRUE, open_in_new_window, open_in_background)->LoadPendingUrl(url_id, -1, user_initiated);
  1944. return;
  1945. }
  1946. DocumentManager* doc_man = GetDocManagerById(sub_win_id);
  1947. if (doc_man)
  1948. doc_man->LoadPendingUrl(url_id, user_initiated);
  1949. }
  1950. BOOL Window::HandleLoadingFailed(Str::LocaleString msg_id, URL url)
  1951. {
  1952. OpString url_name;
  1953. if (OpStatus::IsMemoryError(url.GetAttribute(URL::KUniName_Username_Password_Hidden_Escaped, url_name, FALSE)))
  1954. RaiseCondition(OpStatus::ERR_NO_MEMORY);
  1955. else if (m_windowCommander->GetLoadingListener()->OnLoadingFailed(m_windowCommander, msg_id, url_name.CStr()))
  1956. /* Event was handled by the listener. */
  1957. return TRUE;
  1958. return FALSE;
  1959. }
  1960. #ifndef NO_EXTERNAL_APPLICATIONS
  1961. BOOL Window::RunApplication(const OpStringC& application,const OpStringC& filename)
  1962. {
  1963. RETURN_VALUE_IF_ERROR(Execute(application.CStr(), filename.CStr()), FALSE);
  1964. return TRUE;
  1965. }
  1966. #endif // !NO_EXTERNAL_APPLICATIONS
  1967. #ifndef NO_EXTERNAL_APPLICATIONS
  1968. BOOL Window::ShellExecute(const uni_char* filename)
  1969. {
  1970. if (filename && *filename)
  1971. g_op_system_info->ExecuteApplication(filename, NULL);
  1972. return FALSE;
  1973. }
  1974. #endif // !NO_EXTERNAL_APPLICATIONS
  1975. ////////////////////////////////////////////////////
  1976. void Window::AskAboutUnknownDoc(URL& url, int sub_win_id)
  1977. {
  1978. #ifndef WIC_USE_DOWNLOAD_CALLBACK
  1979. #ifdef USE_DOWNLOAD_API
  1980. TRAPD(err, g_DownloadManager->DelegateL(url, m_windowCommander));
  1981. if( OpStatus::IsMemoryError(err) )
  1982. RaiseCondition(OpStatus::ERR_NO_MEMORY);
  1983. #elif defined(DOCHAND_USE_ONDOWNLOADREQUEST)
  1984. OpString suggested_filename;
  1985. OpString8 mimetype_str;
  1986. if (OpStatus::IsMemoryError(url.GetAttribute(URL::KSuggestedFileName_L, suggested_filename)) ||
  1987. OpStatus::IsMemoryError(url.GetAttribute(URL::KMIME_Type, mimetype_str, TRUE)) )
  1988. {
  1989. RaiseCondition(OpStatus::ERR_NO_MEMORY);
  1990. return;
  1991. }
  1992. char *mimetype = mimetype_str.CStr();
  1993. OpFileLength size = url.GetContentSize();
  1994. m_windowCommander->GetDocumentListener()->OnDownloadRequest(m_windowCommander, url.GetAttribute(URL::KUniName_Username_Password_Hidden_Escaped).CStr(), suggested_filename.CStr(),
  1995. mimetype, size, OpDocumentListener::UNKNOWN);
  1996. #elif defined(QUICK)
  1997. BOOL no_download_dialog = KioskManager::GetInstance()->GetNoDownload();
  1998. if(no_download_dialog || IsThumbnailWindow())
  1999. {
  2000. url.StopLoading(NULL);
  2001. url.Unload();
  2002. return;
  2003. }
  2004. DownloadDialog* dialog = OP_NEW(DownloadDialog, (&url, this));
  2005. #ifdef QUICK
  2006. dialog->Init(g_application->GetDesktopWindowFromWindow(this), sub_win_id);
  2007. #else // QUICK
  2008. dialog->Init(g_application->GetDesktopWindowFromWindow(this));
  2009. #endif // QUICK
  2010. #elif defined(LIBOPERA)
  2011. OpString suggested_filename_str;
  2012. OpString8 mimetype_str;
  2013. if (OpStatus::IsMemoryError(url.GetAttribute(URL::KSuggestedFileName_L, suggested_filename_str, TRUE)) || OpStatus::IsMemoryError(mimetype_str.Set(url.GetAttribute(URL::KMIME_Type))))
  2014. {
  2015. RaiseCondition(OpStatus::ERR_NO_MEMORY);
  2016. return;
  2017. }
  2018. uni_char *suggested_filename = suggested_filename_str.CStr();
  2019. char *mimetype = mimetype_str.CStr();
  2020. OpFileLength size = url.GetContentSize();
  2021. #ifdef TCP_PAUSE_DOWNLOAD_EXTENSION
  2022. url.PauseLoading();
  2023. #endif // TCP_PAUSE_DOWNLOAD_EXTENSION
  2024. #if !defined GTK_DOWNLOAD_EXTENSION && !defined TCP_PAUSE_DOWNLOAD_EXTENSION
  2025. url.StopLoading(NULL);
  2026. url.Unload();
  2027. #endif // !GTK_DOWNLOAD_EXTENSION && !TCP_PAUSE_DOWNLOAD_EXTENSION
  2028. # ifdef _OPL_
  2029. // OPL: IMPLEMENTME
  2030. # elif defined(SDK) || defined(POWERPARTS)
  2031. # ifdef GTK_DOWNLOAD_EXTENSION
  2032. url.PauseLoading();
  2033. OP_STATUS status = GetWindowCommander()->InitiateTransfer(doc_manager, url, OpTransferItem::ACTION_SAVE, NULL);
  2034. if (OpStatus::IsError(status))
  2035. {
  2036. if (status == OpStatus::ERR_NO_MEMORY)
  2037. {
  2038. RaiseCondition(status);
  2039. }
  2040. return;
  2041. }
  2042. # endif // GTK_DOWNLOAD_EXTENSION
  2043. # else // _OPL_
  2044. OperaEmbeddedInternal::instance->signalDownloadFile(url.GetUniName(FALSE, PASSWORD_HIDDEN), suggested_filename,
  2045. mimetype, size);
  2046. # endif // _OPL_
  2047. #endif // misc platforms
  2048. #endif // !WIC_USE_DOWNLOAD_CALLBACK
  2049. }
  2050. int Window::SetNewHistoryNumber()
  2051. {
  2052. doc_manager->RemoveFromHistory(current_history_number + 1);
  2053. current_history_number++;
  2054. max_history_number = current_history_number;
  2055. if (!history_cleanup_message_sent)
  2056. {
  2057. msg_handler->PostMessage(MSG_HISTORY_CLEANUP, 0, 0);
  2058. history_cleanup_message_sent = TRUE;
  2059. }
  2060. return current_history_number;
  2061. }
  2062. void Window::SetLastHistoryPos(int pos)
  2063. {
  2064. if (pos < min_history_number || pos > max_history_number)
  2065. return;
  2066. current_history_number = pos;
  2067. max_history_number = current_history_number;
  2068. doc_manager->RemoveFromHistory(current_history_number + 1);
  2069. FramesDocument* doc = GetCurrentDoc();
  2070. if (doc)
  2071. doc->RemoveFromHistory(current_history_number + 1);
  2072. }
  2073. void Window::SetCurrentHistoryPos(int pos, BOOL update_doc_man, BOOL is_user_initiated)
  2074. {
  2075. if (pos < min_history_number)
  2076. pos = min_history_number;
  2077. else if (pos > max_history_number)
  2078. pos = max_history_number;
  2079. current_history_number = pos;
  2080. if (update_doc_man)
  2081. {
  2082. doc_manager->SetCurrentHistoryPos(pos, FALSE, is_user_initiated);
  2083. UpdateWindowIfLayoutChanged();
  2084. }
  2085. }
  2086. int Window::GetNextDocListElmId()
  2087. {
  2088. return m_next_doclistelm_id++;
  2089. }
  2090. OP_STATUS Window::SetHistoryUserData(int history_ID, OpHistoryUserData* user_data)
  2091. {
  2092. return doc_manager->SetHistoryUserData(history_ID, user_data);
  2093. }
  2094. OP_STATUS Window::GetHistoryUserData(int history_ID, OpHistoryUserData** user_data) const
  2095. {
  2096. return doc_manager->GetHistoryUserData(history_ID, user_data);
  2097. }
  2098. void Window::SetMaxHistory(int len)
  2099. {
  2100. int remove_len = GetHistoryLen() - len - 1;
  2101. if (remove_len > 0)
  2102. {
  2103. if (current_history_number - min_history_number > remove_len)
  2104. min_history_number += remove_len;
  2105. else
  2106. min_history_number = current_history_number;
  2107. doc_manager->RemoveUptoHistory(min_history_number);
  2108. }
  2109. remove_len = GetHistoryLen() - len - 1;
  2110. if (remove_len > 0)
  2111. {
  2112. if (max_history_number - current_history_number > remove_len)
  2113. max_history_number += remove_len;
  2114. else
  2115. max_history_number = current_history_number;
  2116. doc_manager->RemoveFromHistory(max_history_number+1);
  2117. }
  2118. }
  2119. #ifdef DOCHAND_HISTORY_MANIPULATION_SUPPORT
  2120. void Window::RemoveElementFromHistory(int pos)
  2121. {
  2122. if((pos < min_history_number) || (pos > max_history_number))
  2123. return;
  2124. if(pos == current_history_number)
  2125. {
  2126. if(current_history_number > min_history_number)
  2127. SetCurrentHistoryPos(current_history_number - 1, TRUE, FALSE);
  2128. else if(current_history_number < max_history_number)
  2129. SetCurrentHistoryPos(current_history_number + 1, TRUE, FALSE);
  2130. }
  2131. if(pos == max_history_number)
  2132. {
  2133. doc_manager->RemoveElementFromHistory(max_history_number--, TRUE); // Unlink from history list
  2134. //doc_manager->RemoveFromHistory(max_history_number--, TRUE); // Unlink from history list
  2135. if(min_history_number > max_history_number)
  2136. {
  2137. min_history_number = 1;
  2138. max_history_number = current_history_number = 0;
  2139. }
  2140. }
  2141. else if(pos == min_history_number)
  2142. {
  2143. doc_manager->RemoveUptoHistory(++min_history_number, TRUE); // Unlink from history list
  2144. }
  2145. else
  2146. doc_manager->RemoveElementFromHistory(pos);
  2147. CheckHistory();
  2148. }
  2149. void Window::InsertElementInHistory(int pos, DocListElm * elm)
  2150. {
  2151. if (pos < min_history_number)
  2152. pos = min_history_number;
  2153. else if (pos > (max_history_number+1))
  2154. pos = max_history_number+1;
  2155. doc_manager->InsertElementInHistory(pos, elm);
  2156. max_history_number += 1;
  2157. if(pos <= current_history_number)
  2158. SetCurrentHistoryPos(current_history_number + 1, TRUE, FALSE);
  2159. CheckHistory();
  2160. }
  2161. void Window::RemoveAllElementsFromHistory(BOOL unlink)
  2162. {
  2163. int pos = min_history_number;
  2164. while (pos <= max_history_number)
  2165. doc_manager->RemoveElementFromHistory(pos++, unlink);
  2166. CheckHistory();
  2167. }
  2168. #endif // DOCHAND_HISTORY_MANIPULATION_SUPPORT
  2169. void Window::RemoveAllElementsExceptCurrent()
  2170. {
  2171. doc_manager->RemoveFromHistory(current_history_number+1);
  2172. doc_manager->RemoveUptoHistory(current_history_number);
  2173. CheckHistory();
  2174. }
  2175. // Handles OOM locally by setting the flag on the window.
  2176. void Window::GetClickedURL(URL url, DocumentReferrer& ref_url, short sub_win_id, BOOL user_initiated, BOOL open_in_background_window)
  2177. {
  2178. DocumentManager* doc_man = GetDocManagerById(sub_win_id);
  2179. if (!doc_man)
  2180. return;
  2181. URL current_url = doc_man->GetCurrentURL();
  2182. if (sub_win_id == -2 &&
  2183. (!g_pcdoc->GetIntegerPref(PrefsCollectionDoc::IgnoreTarget) &&
  2184. !g_pcdoc->GetIntegerPref(PrefsCollectionDoc::SingleWindowBrowsing)))
  2185. {
  2186. BOOL3 open_in_new_window = MAYBE;
  2187. BOOL3 open_in_background = open_in_background_window?YES:MAYBE;
  2188. Window* window = g_windowManager->GetAWindow(TRUE, open_in_new_window, open_in_background);
  2189. if (window)
  2190. {
  2191. if (window->OpenURL(url, ref_url, TRUE, FALSE, -1, user_initiated, open_in_background==YES) == OpStatus::ERR_NO_MEMORY)
  2192. window->RaiseCondition( OpStatus::ERR_NO_MEMORY );
  2193. }
  2194. }
  2195. else
  2196. {
  2197. doc_man->StopLoading(FALSE, FALSE, FALSE);
  2198. if (OpenURL(url, ref_url, !(url==current_url), FALSE, sub_win_id, user_initiated, open_in_background_window) == OpStatus::ERR_NO_MEMORY)
  2199. g_memory_manager->RaiseCondition( OpStatus::ERR_NO_MEMORY );
  2200. }
  2201. }
  2202. #ifdef LINK_SUPPORT
  2203. const LinkElement*
  2204. Window::GetLinkList() const
  2205. {
  2206. FramesDocument* frames_doc = doc_manager->GetCurrentDoc();
  2207. if (frames_doc)
  2208. {
  2209. HLDocProfile* profile = frames_doc->GetHLDocProfile();
  2210. if (profile)
  2211. return profile->GetLinkList();
  2212. }
  2213. return NULL;
  2214. }
  2215. const LinkElementDatabase*
  2216. Window::GetLinkDatabase() const
  2217. {
  2218. if (FramesDocument* frames_doc = doc_manager->GetCurrentDoc())
  2219. {
  2220. if (HLDocProfile* profile = frames_doc->GetHLDocProfile())
  2221. return profile->GetLinkDatabase();
  2222. }
  2223. return NULL;
  2224. }
  2225. #endif // LINK_SUPPORT
  2226. /** Return the CSSCollection object for the current document. */
  2227. CSSCollection* Window::GetCSSCollection() const
  2228. {
  2229. FramesDocument* frames_doc = doc_manager->GetCurrentVisibleDoc();
  2230. if (frames_doc)
  2231. {
  2232. HLDocProfile* profile = frames_doc->GetHLDocProfile();
  2233. if (profile)
  2234. return profile->GetCSSCollection();
  2235. }
  2236. return NULL;
  2237. }
  2238. URL Window::GetCurrentShownURL()
  2239. {
  2240. return doc_manager->GetCurrentDocURL();
  2241. }
  2242. URL Window::GetCurrentLoadingURL()
  2243. {
  2244. switch (doc_manager->GetLoadStatus())
  2245. {
  2246. case NOT_LOADING:
  2247. case DOC_CREATED:
  2248. case WAIT_MULTIPART_RELOAD:
  2249. return doc_manager->GetCurrentDocURL();
  2250. default:
  2251. URL url = doc_manager->GetCurrentURL();
  2252. URL target = url.GetAttribute(URL::KMovedToURL, TRUE);
  2253. if (!target.IsEmpty())
  2254. return target;
  2255. else
  2256. return url;
  2257. }
  2258. }
  2259. URL Window::GetCurrentURL()
  2260. {
  2261. return doc_manager->GetCurrentDocURL();
  2262. }
  2263. URL_CONTEXT_ID Window::GetMainUrlContextId(URL_CONTEXT_ID base_id)
  2264. {
  2265. // If you edit this, please see Window::GetUrlContextId()
  2266. #if defined WEB_TURBO_MODE || defined APPLICATION_CACHE_SUPPORT
  2267. if (base_id != 0 && (
  2268. # ifdef WEB_TURBO_MODE
  2269. base_id == g_windowManager->GetTurboModeContextId() ||
  2270. # endif // WEB_TURBO_MODE
  2271. # ifdef APPLICATION_CACHE_SUPPORT
  2272. g_application_cache_manager->GetCacheFromContextId(base_id) != NULL ||
  2273. # endif // APPLICATION_CACHE_SUPPORT
  2274. FALSE))
  2275. {
  2276. #ifdef GADGET_SUPPORT
  2277. if (GetGadget())
  2278. return GetGadget()->UrlContextId();
  2279. else
  2280. #endif // GADGET_SUPPORT
  2281. if (GetPrivacyMode())
  2282. return g_windowManager->GetPrivacyModeContextId();
  2283. else
  2284. return 0;
  2285. }
  2286. else
  2287. #endif // defined WEB_TURBO_MODE || defined APPLICATION_CACHE_SUPPORT
  2288. return base_id;
  2289. }
  2290. URL_CONTEXT_ID Window::GetUrlContextId(const uni_char *url)
  2291. {
  2292. // If you edit this, please see Window::GetMainUrlContextId()
  2293. URL_CONTEXT_ID id = 0;
  2294. #ifdef GADGET_SUPPORT
  2295. if (GetGadget())
  2296. id = GetGadget()->UrlContextId();
  2297. else
  2298. #endif // GADGET_SUPPORT
  2299. if (GetPrivacyMode())
  2300. {
  2301. id = g_windowManager->GetPrivacyModeContextId();
  2302. OP_ASSERT(id);
  2303. }
  2304. #ifdef WEB_TURBO_MODE
  2305. else if (GetTurboMode())
  2306. {
  2307. id = g_windowManager->GetTurboModeContextId();
  2308. OP_ASSERT(id);
  2309. }
  2310. #endif // WEB_TURBO_MODE
  2311. #ifdef APPLICATION_CACHE_SUPPORT
  2312. else if (url && g_application_cache_manager)
  2313. {
  2314. URL_CONTEXT_ID appcache_context_id = g_application_cache_manager->GetMostAppropriateCache(url);
  2315. if (appcache_context_id)
  2316. id = appcache_context_id;
  2317. }
  2318. #endif // APPLICATION_CACHE_SUPPORT
  2319. return id;
  2320. }
  2321. DocumentManager* Window::GetDocManagerById(int sub_win_id)
  2322. {
  2323. if (sub_win_id < 0)
  2324. return doc_manager;
  2325. else
  2326. return doc_manager->GetDocManagerById(sub_win_id);
  2327. }
  2328. void Window::CheckHistory()
  2329. {
  2330. check_history = FALSE;
  2331. int minhist = current_history_number;
  2332. int maxhist = current_history_number;
  2333. doc_manager->CheckHistory(0, minhist, maxhist);
  2334. if (minhist > min_history_number)
  2335. min_history_number = minhist;
  2336. if (maxhist < max_history_number)
  2337. max_history_number = maxhist;
  2338. }
  2339. void Window::UpdateWindowIfLayoutChanged()
  2340. {
  2341. // The session handling in desktop can change
  2342. // the history position on an empty doc_manager. Don't ask.
  2343. if (!doc_manager->GetCurrentDoc())
  2344. return;
  2345. LayoutMode doc_layout_mode = doc_manager->GetCurrentDoc()->GetLayoutMode();
  2346. LayoutMode& win_layout_mode = layout_mode;
  2347. BOOL doc_era_mode = doc_manager->GetCurrentDoc()->GetERA_Mode();
  2348. BOOL& win_era_mode = era_mode;
  2349. if (!win_era_mode && (doc_layout_mode != win_layout_mode ||
  2350. doc_manager->GetCurrentDoc()->GetMediaHandheldResponded()) ||
  2351. win_era_mode && !doc_era_mode)
  2352. {
  2353. // the ssr status of window and doc were not in sync
  2354. UpdateWindow();
  2355. }
  2356. }
  2357. void Window::UnlockPaintLock()
  2358. {
  2359. DocumentTreeIterator iterator(this);
  2360. iterator.SetIncludeThis();
  2361. while (iterator.Next())
  2362. iterator.GetDocumentManager()->GetVisualDevice()->StopLoading();
  2363. }
  2364. void Window::SetHistoryNext(BOOL /* unused = FALSE */)
  2365. {
  2366. if (HasFeature(WIN_FEATURE_NAVIGABLE))
  2367. {
  2368. // Assuming user initiated (or we'll have to tweak this code). Allow a new download dialog after the user has moved in history
  2369. SetHasShownUnsolicitedDownloadDialog(FALSE);
  2370. if (current_history_number < max_history_number)
  2371. doc_manager->SetCurrentHistoryPos(++current_history_number, FALSE, TRUE);
  2372. UpdateWindowIfLayoutChanged();
  2373. }
  2374. }
  2375. void Window::SetHistoryPrev(BOOL /* unused = FALSE */)
  2376. {
  2377. if (HasFeature(WIN_FEATURE_NAVIGABLE))
  2378. {
  2379. if (current_history_number > min_history_number)
  2380. {
  2381. // Assuming user initiated (or we'll have to tweak this code). Allow a new download dialog after the user has moved in history
  2382. SetHasShownUnsolicitedDownloadDialog(FALSE);
  2383. FramesDocument* doc = GetCurrentDoc();
  2384. URL url;
  2385. if (doc)
  2386. {
  2387. url = GetCurrentDoc()->GetURL();
  2388. }
  2389. doc_manager->SetCurrentHistoryPos(--current_history_number, FALSE, TRUE);
  2390. if (doc)
  2391. {
  2392. UpdateVisitedLinks(url);
  2393. UpdateWindowIfLayoutChanged();
  2394. }
  2395. }
  2396. }
  2397. }
  2398. BOOL Window::IsLoading() const
  2399. {
  2400. return loading && !doc_manager->IsCurrentDocLoaded();
  2401. }
  2402. void Window::DisplayLinkInformation(const URL &link_url, ST_MESSAGETYPE msType/* = ST_ASTRING*/, const uni_char *title/* = NULL*/)
  2403. {
  2404. OpString link_str;
  2405. OpStatus::Ignore(link_url.GetAttribute(URL::KUniName_With_Fragment_Username_Password_Hidden_Escaped, link_str));
  2406. DisplayLinkInformation(link_str.CStr(), msType, title);
  2407. }
  2408. void Window::DisplayLinkInformation(const uni_char* link, ST_MESSAGETYPE mt/*=ST_ASTRING*/, const uni_char *title/*=NULL*/)
  2409. {
  2410. if (!link)
  2411. link = UNI_L("");
  2412. if (*link || (title && *title))
  2413. {
  2414. m_windowCommander->GetDocumentListener()->OnHover(m_windowCommander, link, title, FALSE);
  2415. is_something_hovered = TRUE;
  2416. }
  2417. else
  2418. {
  2419. if (is_something_hovered)
  2420. {
  2421. m_windowCommander->GetDocumentListener()->OnNoHover(m_windowCommander);
  2422. is_something_hovered = FALSE;
  2423. }
  2424. m_windowCommander->GetDocumentListener()->OnStatusText(m_windowCommander, current_message ? current_message : current_default_message);
  2425. }
  2426. g_windowManager->SetPopupMessage(link, FALSE, mt);
  2427. }
  2428. void Window::DisplayLinkInformation(const uni_char* hlink, const uni_char* rel_name, ST_MESSAGETYPE msType/* = ST_ASTRING*/, const uni_char *title/* = NULL*/)
  2429. {
  2430. uni_char* full_tag = Window::ComposeLinkInformation(hlink, rel_name);
  2431. DisplayLinkInformation(full_tag, msType, title);
  2432. OP_DELETEA(full_tag);
  2433. }
  2434. #ifdef _PRINT_SUPPORT_
  2435. OP_STATUS Window::SetFramesPrintType(DM_PrintType fptype, BOOL update)
  2436. {
  2437. FramesDocument* doc = GetCurrentDoc();
  2438. if (doc && (!doc->IsFrameDoc() || (fptype == PRINT_ACTIVE_FRAME && !doc->GetActiveDocManager())))
  2439. fptype = PRINT_ALL_FRAMES;
  2440. if (frames_print_type != fptype)
  2441. {
  2442. frames_print_type = fptype;
  2443. if (update)
  2444. return doc_manager->UpdatePrintPreview();
  2445. }
  2446. return OpStatus::OK;
  2447. }
  2448. BOOL Window::TogglePrintMode(BOOL preview)
  2449. {
  2450. PrintDevice* tmpPrintDev = NULL;
  2451. if (preview)
  2452. preview_mode = !preview_mode;
  2453. else
  2454. print_mode = !print_mode;
  2455. if (preview_mode || print_mode)
  2456. ecmascript_paused |= PAUSED_PRINTING;
  2457. else
  2458. {
  2459. ecmascript_paused &= ~PAUSED_PRINTING;
  2460. ResumeEcmaScriptIfNotPaused();
  2461. }
  2462. OP_STATUS result = OpStatus::OK;
  2463. if (!preview_printer_info && !print_mode && preview_mode)
  2464. {
  2465. preview_printer_info = OP_NEW(PrinterInfo, ());
  2466. if (!preview_printer_info)
  2467. result = OpStatus::ERR_NO_MEMORY;
  2468. else
  2469. #ifdef PRINT_SELECTION_USING_DUMMY_WINDOW
  2470. result = preview_printer_info->GetPrintDevice(tmpPrintDev, preview, FALSE, this, NULL); //if this fails, we don't have any printer device to work towards
  2471. #else // !PRINT_SELECTION_USING_DUMMY_WINDOW
  2472. result = preview_printer_info->GetPrintDevice(tmpPrintDev, preview, FALSE, this); //if this fails, we don't have any printer device to work towards
  2473. #endif // !PRINT_SELECTION_USING_DUMMY_WINDOW
  2474. }
  2475. else
  2476. if (!preview)
  2477. #ifdef PRINT_SELECTION_USING_DUMMY_WINDOW
  2478. result = printer_info->GetPrintDevice(tmpPrintDev, preview, FALSE, this, NULL);
  2479. #else // !PRINT_SELECTION_USING_DUMMY_WINDOW
  2480. result = printer_info->GetPrintDevice(tmpPrintDev, preview, FALSE, this);
  2481. #endif
  2482. if (result == OpStatus::ERR)
  2483. {
  2484. /* We could for example not get a connection to the printer.
  2485. We're not necessarily out of memory, though. */
  2486. if (preview)
  2487. preview_mode = !preview_mode;
  2488. else
  2489. print_mode = !print_mode;
  2490. }
  2491. else
  2492. if (result == OpStatus::ERR_NO_MEMORY ||
  2493. (result = doc_manager->SetPrintMode(print_mode || preview_mode, NULL, preview)) != OpBoolean::IS_TRUE)
  2494. {
  2495. // undo
  2496. if (preview)
  2497. preview_mode = !preview_mode;
  2498. else
  2499. print_mode = !print_mode;
  2500. if (result == OpStatus::ERR_NO_MEMORY)
  2501. {
  2502. RaiseCondition(result);
  2503. if (preview)
  2504. {
  2505. OP_DELETE(preview_printer_info);
  2506. preview_printer_info = NULL;
  2507. }
  2508. else
  2509. {
  2510. OP_DELETE(printer_info);
  2511. printer_info = NULL;
  2512. }
  2513. vis_device->Show(NULL);
  2514. vis_device->SetFocus(FOCUS_REASON_OTHER);
  2515. return FALSE;
  2516. }
  2517. }
  2518. #ifdef KEYBOARD_SELECTION_SUPPORT
  2519. if (preview_mode || print_mode)
  2520. {
  2521. DocumentTreeIterator it(this);
  2522. while (it.Next())
  2523. it.GetFramesDocument()->SetKeyboardSelectable(FALSE);
  2524. }
  2525. #endif // KEYBOARD_SELECTION_SUPPORT
  2526. if (printer_info && !print_mode)
  2527. {
  2528. OP_DELETE(printer_info);
  2529. printer_info = NULL;
  2530. }
  2531. if (preview_printer_info && !preview_mode)
  2532. {
  2533. OP_DELETE(preview_printer_info);
  2534. preview_printer_info = NULL;
  2535. }
  2536. if (preview)
  2537. {
  2538. OpDocumentListener::PrintPreviewMode mode;
  2539. if (preview_mode)
  2540. mode = OpDocumentListener::PRINT_PREVIEW_ON;
  2541. else
  2542. mode = OpDocumentListener::PRINT_PREVIEW_OFF;
  2543. m_windowCommander->GetDocumentListener()->OnPrintPreviewModeChanged(m_windowCommander, mode);
  2544. }
  2545. return tmpPrintDev ? TRUE : FALSE;
  2546. }
  2547. BOOL Window::StartPrinting(PrinterInfo* pinfo, int from_page, BOOL selected_only)
  2548. {
  2549. if (!print_mode)
  2550. LockWindow();
  2551. //rg this variable is uses to save the state of the global flag that shows if we are in full screen.
  2552. // we have to temporarily reset the flag (not the fullscreen mode state, though) to make documents print even
  2553. // though we are in fullscreen mode. I'm not saying it's beautiful -- m_fullscreen_state is mis-used!
  2554. m_previous_fullscreen_state = m_fullscreen_state;
  2555. m_fullscreen_state = OpWindowCommander::FULLSCREEN_NONE;
  2556. /* if (GetPreviewMode())
  2557. {
  2558. // check printer_info
  2559. }
  2560. else */
  2561. {
  2562. printer_info = pinfo;
  2563. OP_NEW_DBG("Window::StartPrinting", "async_print");
  2564. OP_DBG(("SetPrinting(TRUE)"));
  2565. SetPrinting(TRUE);
  2566. TogglePrintMode(FALSE); // Will delete printer_info/pinfo if failing
  2567. if (!printer_info)
  2568. {
  2569. // TogglePrintMode failed & printer_info invalid, better quit now...
  2570. StopPrinting();
  2571. return FALSE;
  2572. }
  2573. }
  2574. OP_ASSERT(printer_info == pinfo);
  2575. print_mode = TRUE;
  2576. #ifndef _MACINTOSH_
  2577. printer_info->next_page = from_page;
  2578. #endif
  2579. printer_info->print_selected_only = selected_only;
  2580. FramesDocument* doc = doc_manager->GetPrintDoc();
  2581. if (!doc)
  2582. {
  2583. StopPrinting();
  2584. OP_ASSERT(!printer_info);
  2585. return FALSE;
  2586. }
  2587. PrintDevice* pd = printer_info->GetPrintDevice();
  2588. pd->StartOutput();
  2589. return TRUE;
  2590. }
  2591. void Window::PrintNextPage(PrinterInfo* pinfo)
  2592. {
  2593. PrintDevice* pd = pinfo->GetPrintDevice();
  2594. OP_STATUS ret_val = doc_manager->PrintPage(pd, pinfo->next_page, pinfo->print_selected_only);
  2595. pinfo->next_page++;
  2596. if (ret_val != DocStatus::DOC_CANNOT_PRINT &&
  2597. ret_val != DocStatus::DOC_PAGE_OUT_OF_RANGE &&
  2598. (!pinfo->print_selected_only ||
  2599. ret_val != DocStatus::DOC_PRINTED) &&
  2600. pinfo->next_page <= pinfo->last_page &&
  2601. // Check if there are more pages left to print before advancing to the next page:
  2602. doc_manager->PrintPage(pd, pinfo->next_page, pinfo->print_selected_only, TRUE) == OpStatus::OK)
  2603. {
  2604. BOOL cont = pd->NewPage();
  2605. if (cont)
  2606. {
  2607. #if defined (GENERIC_PRINTING)
  2608. msg_handler->PostDelayedMessage(DOC_PAGE_PRINTED, 0, pinfo->next_page - 1, 100);
  2609. #else // !GENERIC_PRINTING
  2610. msg_handler->PostMessage(DOC_PAGE_PRINTED, 0, pinfo->next_page - 1);
  2611. #endif // !GENERIC_PRINTING
  2612. }
  2613. else
  2614. {
  2615. #if defined (GENERIC_PRINTING)
  2616. msg_handler->PostDelayedMessage(DOC_PRINTING_ABORTED, 0, 0, 100);
  2617. #else // !GENERIC_PRINTING
  2618. msg_handler->PostMessage(DOC_PRINTING_ABORTED, 0, 0);
  2619. StopPrinting();
  2620. #endif // !GENERIC_PRINTING
  2621. }
  2622. }
  2623. else
  2624. {
  2625. #if defined (GENERIC_PRINTING)
  2626. msg_handler->PostDelayedMessage(DOC_PRINTING_FINISHED, 0, 0, 100);
  2627. #else // !GENERIC_PRINTING
  2628. msg_handler->PostMessage(DOC_PRINTING_FINISHED, 0, 0);
  2629. StopPrinting();
  2630. #endif // !GENERIC_PRINTING
  2631. }
  2632. }
  2633. void Window::StopPrinting()
  2634. {
  2635. m_fullscreen_state = m_previous_fullscreen_state;
  2636. if (print_mode)
  2637. {
  2638. OpStatus::Ignore(doc_manager->SetPrintMode(FALSE, NULL, FALSE));
  2639. if (!preview_mode)
  2640. TogglePrintMode(FALSE);
  2641. ecmascript_paused &= ~PAUSED_PRINTING;
  2642. ResumeEcmaScriptIfNotPaused();
  2643. }
  2644. if (!preview_mode)
  2645. {
  2646. #if defined (GENERIC_PRINTING)
  2647. OP_DELETE(printer_info);
  2648. #endif // GENERIC_PRINTING
  2649. printer_info = NULL;
  2650. }
  2651. if (print_mode)
  2652. UnlockWindow();
  2653. print_mode = FALSE;
  2654. }
  2655. #endif // _PRINT_SUPPORT_
  2656. void Window::GenericMailToAction(const URL& url, BOOL called_externally, BOOL mailto_from_form, const OpStringC8& servername)
  2657. {
  2658. m_windowCommander->GetDocumentListener()->OnMailTo(m_windowCommander, url.GetAttribute(URL::KName_With_Fragment_Escaped, URL::KNoRedirect), called_externally, mailto_from_form, servername);
  2659. if (doc_manager->GetCurrentURL().IsEmpty())
  2660. Close();
  2661. }
  2662. void Window::ToggleImageState()
  2663. {
  2664. BOOL load_images = LoadImages();
  2665. BOOL show_images = ShowImages();
  2666. if (show_images)
  2667. if (load_images)
  2668. SetImagesSetting(FIGS_OFF);
  2669. else
  2670. SetImagesSetting(FIGS_ON);
  2671. else
  2672. SetImagesSetting(FIGS_SHOW);
  2673. }
  2674. #ifdef _AUTO_WIN_RELOAD_SUPPORT_
  2675. // ___________________________________________________________________________
  2676. //
  2677. // AutoWinReloadParam
  2678. // ___________________________________________________________________________
  2679. AutoWinReloadParam::AutoWinReloadParam(Window* win)
  2680. : m_fEnabled(FALSE),
  2681. m_secUserSetting(0),
  2682. m_secRemaining(0),
  2683. m_fOnlyIfExpired(FALSE),
  2684. m_timer(NULL),
  2685. m_win(win)
  2686. {
  2687. if (g_pcdoc)
  2688. m_secUserSetting = g_pcdoc->GetIntegerPref(PrefsCollectionDoc::LastUsedAutoWindowReloadTimeout);
  2689. if (m_secUserSetting<=0)
  2690. m_secUserSetting = 5;
  2691. }
  2692. AutoWinReloadParam::~AutoWinReloadParam()
  2693. {
  2694. OP_DELETE(m_timer);
  2695. }
  2696. // ----------------------------------------------------------------------------
  2697. void AutoWinReloadParam::Enable( BOOL fEnable)
  2698. {
  2699. m_fEnabled = fEnable;
  2700. if (fEnable)
  2701. {
  2702. if (!m_timer)
  2703. {
  2704. OP_STATUS status = OpStatus::OK;
  2705. m_timer = OP_NEW(OpTimer, ());
  2706. if (!m_timer)
  2707. status = OpStatus::ERR_NO_MEMORY;
  2708. if (OpStatus::IsError(status))
  2709. {
  2710. OP_ASSERT(FALSE);
  2711. // Now the page won't reload automatically
  2712. g_memory_manager->RaiseCondition(status);//FIXME:OOM At least we can
  2713. //tell the memory manager
  2714. m_timer = NULL;
  2715. }
  2716. else
  2717. m_timer->SetTimerListener(this);
  2718. }
  2719. if (m_timer)
  2720. m_timer->Start(1000); // Every second. This is not optimal
  2721. // but is the same as it was when
  2722. // this code piggy backed on the
  2723. // comm cleaner.
  2724. m_secRemaining = m_secUserSetting;
  2725. m_win->DocManager()->CancelRefresh();
  2726. }
  2727. else if (m_timer)
  2728. {
  2729. m_timer->Stop();
  2730. // document refresh has been disabeled as long as user defined reload is
  2731. // active, but now we have to activate refresh again (in all sub documents)
  2732. DocumentTreeIterator iter(m_win);
  2733. iter.SetIncludeThis();
  2734. while (iter.Next())
  2735. iter.GetFramesDocument()->CheckRefresh();
  2736. }
  2737. }
  2738. void AutoWinReloadParam::Toggle( )
  2739. {
  2740. Enable(!m_fEnabled);
  2741. }
  2742. void AutoWinReloadParam::SetSecUserSetting ( int secUserSetting)
  2743. {
  2744. SetParams( m_fEnabled, secUserSetting, m_fOnlyIfExpired, TRUE);
  2745. }
  2746. void AutoWinReloadParam::SetParams( BOOL fEnable, int secUserSetting, BOOL fOnlyIfExpired, BOOL fUpdatePrefsManager)
  2747. {
  2748. m_secUserSetting = secUserSetting;
  2749. if (m_secUserSetting<=0)
  2750. m_secUserSetting = 1;
  2751. m_fOnlyIfExpired = fOnlyIfExpired;
  2752. Enable( fEnable);
  2753. if (fUpdatePrefsManager)
  2754. {
  2755. TRAPD(err, g_pcdoc->WriteIntegerL(PrefsCollectionDoc::LastUsedAutoWindowReloadTimeout, m_secUserSetting));
  2756. }
  2757. }
  2758. BOOL AutoWinReloadParam::OnSecTimer()
  2759. {
  2760. BOOL fReload = FALSE;
  2761. if (m_fEnabled)
  2762. {
  2763. if (m_secUserSetting > 0)
  2764. {
  2765. --m_secRemaining;
  2766. OP_ASSERT(m_secRemaining >= 0);
  2767. if (m_secRemaining <= 0)
  2768. {
  2769. m_secRemaining = m_secUserSetting;
  2770. fReload = TRUE;
  2771. }
  2772. }
  2773. }
  2774. return fReload;
  2775. }
  2776. /* virtual */
  2777. void AutoWinReloadParam::OnTimeOut(OpTimer* timer)
  2778. {
  2779. OP_ASSERT(timer);
  2780. OP_ASSERT(timer == m_timer);
  2781. if (m_fEnabled)
  2782. {
  2783. //
  2784. // Auto user reload ?
  2785. //
  2786. DocumentManager *doc_manager = m_win->DocManager();
  2787. if (doc_manager->GetLoadStatus() == NOT_LOADING
  2788. && OnSecTimer())
  2789. {
  2790. // DEBUG_Beep();
  2791. doc_manager->Reload(NotEnteredByUser, GetOptOnlyIfExpired(), TRUE, TRUE);
  2792. }
  2793. m_timer->Start(1000); // Every second. Not optimal. See code in Enable()
  2794. }
  2795. }
  2796. #endif // _AUTO_WIN_RELOAD_SUPPORT_
  2797. FramesDocument* Window::GetActiveFrameDoc()
  2798. {
  2799. FramesDocument* activeDoc = NULL;
  2800. FramesDocument* currentDoc = GetCurrentDoc();
  2801. if (currentDoc)
  2802. {
  2803. // The active frame document can always be found through the root
  2804. // document (GetCurrentDoc) because all frame activations are done
  2805. // directly on that document.
  2806. DocumentManager* activeDocMan = currentDoc->GetActiveDocManager();
  2807. if (!activeDocMan)
  2808. activeDocMan = DocManager();
  2809. activeDoc = activeDocMan->GetCurrentDoc();
  2810. }
  2811. return activeDoc;
  2812. }
  2813. OP_STATUS Window::SetLastUserName(const char *_name)
  2814. {
  2815. return SetStr(lastUserName, _name);
  2816. }
  2817. OP_STATUS Window::SetLastProxyUserName(const char *_name)
  2818. {
  2819. return SetStr(lastProxyUserName, _name);
  2820. }
  2821. OP_STATUS Window::SetHomePage(const OpStringC& url)
  2822. {
  2823. return homePage.Set(url);
  2824. }
  2825. void Window::SetAlwaysLoadFromCache(BOOL from_cache)
  2826. {
  2827. always_load_from_cache = from_cache;
  2828. }
  2829. #ifndef HAS_NO_SEARCHTEXT
  2830. BOOL Window::SearchText(const uni_char* key, BOOL forward, BOOL matchcase, BOOL word, BOOL next, BOOL wrap, BOOL only_links)
  2831. {
  2832. if( !key )
  2833. {
  2834. return FALSE;
  2835. }
  2836. FramesDocument* doc = doc_manager->GetCurrentVisibleDoc();
  2837. if (doc && doc->IsFrameDoc())
  2838. doc = doc->GetActiveSubDoc();
  2839. if (!doc)
  2840. return FALSE;
  2841. int left_x, right_x;
  2842. long top_y, bottom_y;
  2843. OP_BOOLEAN result = doc->SearchText(key, uni_strlen(key), forward, matchcase, word, next, wrap,
  2844. left_x, top_y, right_x, bottom_y, only_links);
  2845. if (result == OpStatus::ERR_NO_MEMORY)
  2846. RaiseCondition(result);
  2847. else if (result == OpBoolean::IS_TRUE)
  2848. {
  2849. doc->RequestScrollIntoView(
  2850. OpRect(left_x, top_y, right_x - left_x + 1, bottom_y - top_y + 1),
  2851. SCROLL_ALIGN_CENTER, FALSE, VIEWPORT_CHANGE_REASON_FIND_IN_PAGE);
  2852. return TRUE;
  2853. }
  2854. return FALSE;
  2855. }
  2856. # ifdef SEARCH_MATCHES_ALL
  2857. void
  2858. Window::ResetSearch()
  2859. {
  2860. if (m_search_data)
  2861. {
  2862. m_search_data->SetIsNewSearch(TRUE);
  2863. m_search_data->SetMatchingDoc(NULL);
  2864. }
  2865. }
  2866. BOOL
  2867. Window::HighlightNextMatch(const uni_char* key,
  2868. BOOL match_case, BOOL match_words,
  2869. BOOL links_only, BOOL forward, BOOL wrap,
  2870. BOOL &wrapped, OpRect& rect)
  2871. {
  2872. wrapped = FALSE;
  2873. FramesDocument* doc = doc_manager->GetCurrentVisibleDoc();
  2874. if (!doc)
  2875. return FALSE;
  2876. if (!m_search_data)
  2877. {
  2878. m_search_data = OP_NEW(SearchData, (match_case, match_words, links_only, forward, wrap));
  2879. if (!m_search_data || OpStatus::IsMemoryError(m_search_data->SetSearchText(key)))
  2880. return FALSE;
  2881. }
  2882. else
  2883. {
  2884. m_search_data->SetMatchCase(match_case);
  2885. m_search_data->SetMatchWords(match_words);
  2886. m_search_data->SetLinksOnly(links_only);
  2887. m_search_data->SetForward(forward);
  2888. m_search_data->SetWrap(wrap);
  2889. m_search_data->SetSearchText(key);
  2890. }
  2891. SetState(BUSY);
  2892. OP_BOOLEAN found = doc->HighlightNextMatch(m_search_data, rect);
  2893. if (wrap && m_search_data->GetMatchingDoc() == NULL && !m_search_data->IsNewSearch())
  2894. {
  2895. found = doc->HighlightNextMatch(m_search_data, rect);
  2896. wrapped = TRUE;
  2897. }
  2898. if (found == OpBoolean::IS_TRUE)
  2899. {
  2900. if (!doc->IsTopDocument())
  2901. {
  2902. FramesDocElm* frame = doc->GetDocManager() ? doc->GetDocManager()->GetFrame() : NULL;
  2903. if (frame && doc->GetVisualDevice())
  2904. {
  2905. rect.x += frame->GetAbsX() - doc->GetVisualDevice()->GetRenderingViewX();
  2906. rect.y += frame->GetAbsY() - doc->GetVisualDevice()->GetRenderingViewY();
  2907. }
  2908. }
  2909. }
  2910. SetState(NOT_BUSY);
  2911. m_search_data->SetIsNewSearch(FALSE);
  2912. return m_search_data->GetMatchingDoc() != NULL;
  2913. }
  2914. void Window::EndSearch(BOOL activate_current_match, int modifiers)
  2915. {
  2916. if (activate_current_match && m_search_data)
  2917. {
  2918. if (FramesDocument *match_doc = m_search_data->GetMatchingDoc())
  2919. {
  2920. HTML_Document *html_doc = match_doc->GetHtmlDocument();
  2921. if (html_doc)
  2922. html_doc->ActivateElement(html_doc->GetNavigationElement(), modifiers);
  2923. }
  2924. }
  2925. }
  2926. # endif // SEARCH_MATCHES_ALL
  2927. #endif // !HAS_NO_SEARCHTEXT
  2928. #ifdef ABSTRACT_CERTIFICATES
  2929. const OpCertificate *Window::GetCertificate()
  2930. {
  2931. return static_cast <const OpCertificate *> (doc_manager->GetCurrentURL().GetAttribute(URL::KRequestedCertificate, NULL));
  2932. }
  2933. #endif // ABSTRACT_CERTIFICATES
  2934. void Window::Activate( BOOL fActivate/*=TRUE*/)
  2935. {
  2936. }
  2937. void Window::GotoHistoryPos()
  2938. {
  2939. if (current_history_number < max_history_number && current_history_number >= 0)
  2940. SetCurrentHistoryPos(current_history_number, TRUE, FALSE);
  2941. else
  2942. SetCurrentHistoryPos(max_history_number, TRUE, FALSE);
  2943. }
  2944. /** Flushes pending drawoperations so that things wouldn't lag behind, if we do something agressive. */
  2945. void Window::Sync()
  2946. {
  2947. VisualDev()->view->Sync();
  2948. }
  2949. void Window::SetWindowSize(int wWin, int hWin)
  2950. {
  2951. m_windowCommander->GetDocumentListener()->OnOuterSizeRequest(m_windowCommander, wWin, hWin);
  2952. }
  2953. void Window::SetWindowPos(int xWin, int yWin)
  2954. {
  2955. m_windowCommander->GetDocumentListener()->OnMoveRequest(m_windowCommander, xWin, yWin);
  2956. }
  2957. void Window::GetWindowSize(int& wWin, int& hWin)
  2958. {
  2959. m_windowCommander->GetDocumentListener()->OnGetOuterSize(m_windowCommander, (UINT32*) &wWin, (UINT32*) &hWin);
  2960. }
  2961. void Window::GetWindowPos(int& xWin, int& yWin)
  2962. {
  2963. m_windowCommander->GetDocumentListener()->OnGetPosition(m_windowCommander, &xWin, &yWin);
  2964. }
  2965. // Set the size of the client area (space available for doc content)
  2966. void Window::SetClientSize ( int cx, int cy)
  2967. {
  2968. m_windowCommander->GetDocumentListener()->OnInnerSizeRequest(m_windowCommander, cx, cy);
  2969. }
  2970. void Window::GetClientSize(int &cx, int &cy)
  2971. {
  2972. UINT32 tmpw=0, tmph=0;
  2973. m_windowCommander->GetDocumentListener()->OnGetInnerSize(m_windowCommander, &tmpw, &tmph);
  2974. cx = tmpw;
  2975. cy = tmph;
  2976. }
  2977. void Window::GetCSSViewportSize(unsigned int& viewport_width, unsigned int& viewport_height)
  2978. {
  2979. UINT32 tmpw = 0;
  2980. UINT32 tmph = 0;
  2981. m_windowCommander->GetDocumentListener()->OnGetInnerSize(m_windowCommander, &tmpw, &tmph);
  2982. if (GetTrueZoom())
  2983. {
  2984. viewport_width = VisualDev()->LayoutScaleToDoc(tmpw);
  2985. viewport_height = VisualDev()->LayoutScaleToDoc(tmph);
  2986. }
  2987. else
  2988. {
  2989. viewport_width = VisualDev()->ScaleToDoc(tmpw);
  2990. viewport_height = VisualDev()->ScaleToDoc(tmph);
  2991. }
  2992. }
  2993. void Window::HandleNewWindowSize(unsigned int width, unsigned int height)
  2994. {
  2995. VisualDevice* normal_vis_dev = VisualDev();
  2996. FramesDocument* doc;
  2997. #ifdef _PRINT_SUPPORT_
  2998. VisualDevice* print_preview_vis_dev = NULL;
  2999. if (GetPreviewMode())
  3000. {
  3001. print_preview_vis_dev = doc_manager->GetPrintPreviewVD();
  3002. doc = doc_manager->GetPrintDoc();
  3003. }
  3004. else
  3005. #endif // _PRINT_SUPPORT_
  3006. doc = doc_manager->GetCurrentDoc();
  3007. // Update with new rendering buffer size as well.
  3008. UINT32 rendering_width, rendering_height;
  3009. OpRect rendering_rect;
  3010. m_opWindow->GetRenderingBufferSize(&rendering_width, &rendering_height);
  3011. rendering_rect.width = rendering_width;
  3012. rendering_rect.height = rendering_height;
  3013. normal_vis_dev->SetRenderingViewGeometryScreenCoords(rendering_rect);
  3014. #ifdef DEBUG
  3015. // We assume that OpWindow tells us the correct (new) window size. Let's verify it's true.
  3016. {
  3017. UINT32 window_width, window_height;
  3018. m_opWindow->GetInnerSize(&window_width, &window_height);
  3019. OP_ASSERT(window_width == width && window_height == height);
  3020. }
  3021. #endif // DEBUG
  3022. #ifdef _PRINT_SUPPORT_
  3023. if (print_preview_vis_dev)
  3024. print_preview_vis_dev->SetRenderingViewGeometryScreenCoords(rendering_rect);
  3025. #endif // _PRINT_SUPPORT_
  3026. if (doc)
  3027. {
  3028. doc->RecalculateScrollbars();
  3029. doc->RecalculateLayoutViewSize(TRUE);
  3030. doc->RequestSetViewportToInitialScale(VIEWPORT_CHANGE_REASON_WINDOW_SIZE);
  3031. }
  3032. #if defined SCROLL_TO_ACTIVE_ELM_ON_RESIZE && defined SCROLL_TO_ACTIVE_ELM
  3033. if (FramesDocument* active_frame = GetActiveFrameDoc())
  3034. active_frame->ScrollToActiveElement();
  3035. #endif // SCROLL_TO_ACTIVE_ELM_ON_RESIZE && SCROLL_TO_ACTIVE_ELM
  3036. }
  3037. OP_STATUS Window::UpdateWindow(BOOL /* unused = FALSE */)
  3038. {
  3039. // Set expirytype temporary to never, and then change back after the UpdateWindow.
  3040. // Prevents expired images from getting reloaded when we change layoutmode.
  3041. CheckExpiryType old_expiry_type = doc_manager->GetCheckExpiryType();
  3042. doc_manager->SetCheckExpiryType(CHECK_EXPIRY_NEVER);
  3043. if (doc_manager->ReformatCurrentDoc() == OpStatus::ERR_NO_MEMORY)
  3044. return OpStatus::ERR_NO_MEMORY;
  3045. doc_manager->SetCheckExpiryType(old_expiry_type);
  3046. return OpStatus::OK;
  3047. }
  3048. OP_STATUS Window::UpdateWindowAllDocuments(BOOL /* unused = FALSE */)
  3049. {
  3050. if (doc_manager)
  3051. {
  3052. // Set expirytype temporary to never, and then change back after the UpdateWindowAllDocuments.
  3053. // Prevents expired images from getting reloaded when we change layoutmode.
  3054. CheckExpiryType old_expiry_type = doc_manager->GetCheckExpiryType();
  3055. doc_manager->SetCheckExpiryType(CHECK_EXPIRY_NEVER);
  3056. DocListElm* elm = doc_manager->FirstDocListElm();
  3057. while (elm)
  3058. {
  3059. FramesDocument* frm_doc = elm->Doc();
  3060. if (frm_doc)
  3061. doc_manager->ReformatDoc(frm_doc);
  3062. elm = elm->Suc();
  3063. }
  3064. doc_manager->SetCheckExpiryType(old_expiry_type);
  3065. }
  3066. return OpStatus::OK;
  3067. }
  3068. OP_STATUS Window::UpdateWindowDefaults(BOOL scroll, BOOL progress, BOOL news, WORD scale, BOOL size)
  3069. {
  3070. SetShowScrollbars(scroll);
  3071. SetScale(scale);
  3072. return SetWindowTitle(title, TRUE, generated_title);
  3073. }
  3074. #ifndef MOUSELESS
  3075. void
  3076. Window::UseDefaultCursor()
  3077. {
  3078. has_cursor_set_by_doc = FALSE;
  3079. current_cursor = GetCurrentCursor();
  3080. SetCurrentCursor();
  3081. }
  3082. void
  3083. Window::CommitPendingCursor()
  3084. {
  3085. if(m_pending_cursor == CURSOR_AUTO)
  3086. UseDefaultCursor();
  3087. else
  3088. SetCursor(m_pending_cursor, TRUE);
  3089. m_pending_cursor = CURSOR_AUTO;
  3090. }
  3091. void
  3092. Window::SetCurrentCursor()
  3093. {
  3094. m_opWindow->SetCursor(current_cursor);
  3095. }
  3096. void Window::SetCursor(CursorType cursor, BOOL set_by_document/*=FALSE*/)
  3097. {
  3098. if (set_by_document)
  3099. {
  3100. has_cursor_set_by_doc = TRUE;
  3101. cursor_set_by_doc = cursor;
  3102. }
  3103. // Only allow cursor changes in case the cursor either comes from
  3104. // a trusted source (page load) or the window currently has
  3105. // no page load cursor.
  3106. if (!set_by_document || !IsNormalWindow() || state != BUSY)
  3107. {
  3108. if (cursor != current_cursor)
  3109. {
  3110. current_cursor = cursor;
  3111. SetCurrentCursor();
  3112. }
  3113. }
  3114. }
  3115. #endif // !MOUSELESS
  3116. void Window::ClearMessage()
  3117. {
  3118. OP_DELETEA(current_message);
  3119. current_message = NULL;
  3120. m_windowCommander->GetDocumentListener()->OnNoHover(m_windowCommander);
  3121. }
  3122. void Window::SetMessageInternal()
  3123. {
  3124. m_windowCommander->GetDocumentListener()->OnStatusText(m_windowCommander, current_message ? current_message : current_default_message);
  3125. }
  3126. OP_STATUS Window::SetMessage(const uni_char* msg)
  3127. {
  3128. if (!msg)
  3129. {
  3130. OP_DELETEA(current_message);
  3131. current_message = NULL;
  3132. }
  3133. else if (current_message && uni_strcmp(current_message, msg) == 0)
  3134. {
  3135. // Nothing changed, bail out
  3136. if (current_default_message)
  3137. {
  3138. g_windowManager->SetPopupMessage(current_message);
  3139. }
  3140. return OpStatus::OK;
  3141. }
  3142. else
  3143. {
  3144. RETURN_IF_ERROR(UniSetStr(current_message, msg));
  3145. }
  3146. SetMessageInternal();
  3147. return OpStatus::OK;
  3148. }
  3149. OP_STATUS Window::SetDefaultMessage(const uni_char* msg)
  3150. {
  3151. if (!msg)
  3152. {
  3153. OP_DELETEA(current_default_message);
  3154. current_default_message = NULL;
  3155. }
  3156. else
  3157. if (current_default_message && uni_strcmp(current_default_message, msg) == 0)
  3158. // Nothing changed, bail out
  3159. return OpStatus::OK;
  3160. else
  3161. RETURN_IF_ERROR(UniSetStr(current_default_message, msg));
  3162. m_windowCommander->GetDocumentListener()->OnStatusText(m_windowCommander, current_message ? current_message : current_default_message);
  3163. return OpStatus::OK;
  3164. }
  3165. void Window::SetActiveLinkURL(const URL& url, HTML_Document* doc)
  3166. {
  3167. const uni_char* title = NULL;
  3168. if (g_pcdoc->GetIntegerPref(PrefsCollectionDoc::DisplayLinkTitle) && doc)
  3169. {
  3170. // Find the title string for this link.
  3171. HTML_Element *el = doc->GetActiveHTMLElement();
  3172. for (; el; el = el->Parent())
  3173. {
  3174. title = el->GetStringAttr(ATTR_TITLE);
  3175. if (title || el->Type() == HE_A) break;
  3176. }
  3177. }
  3178. if (title)
  3179. DisplayLinkInformation(url, ST_ATITLE, title);
  3180. else
  3181. DisplayLinkInformation(url, ST_ALINK);
  3182. #ifndef MOUSELESS
  3183. SetCursor(CURSOR_CUR_POINTER);
  3184. #endif // !MOUSELESS
  3185. active_link_url = url;
  3186. }
  3187. void Window::ClearActiveLinkURL()
  3188. {
  3189. ClearMessage();
  3190. SetState(GetState()); // Reset the mouse cursor.
  3191. URL empty;
  3192. active_link_url = empty;
  3193. }
  3194. void Window::SetImagesSetting(SHOWIMAGESTATE set)
  3195. {
  3196. #ifdef GADGET_SUPPORT
  3197. if (GetGadget())
  3198. {
  3199. load_img = TRUE;
  3200. show_img = TRUE;
  3201. }
  3202. else
  3203. #endif
  3204. {
  3205. switch (set)
  3206. {
  3207. case FIGS_OFF:
  3208. load_img = FALSE;
  3209. show_img = FALSE;
  3210. break;
  3211. case FIGS_SHOW:
  3212. load_img = FALSE;
  3213. show_img = TRUE;
  3214. break;
  3215. default:
  3216. load_img = TRUE;
  3217. show_img = TRUE;
  3218. break;
  3219. }
  3220. }
  3221. doc_manager->SetShowImg(show_img);
  3222. /*{
  3223. FramesDocument *doc = doc_manager->GetCurrentDoc();
  3224. if (doc)
  3225. {
  3226. doc->SetShowImg(show_img);
  3227. / *if (doc->SetShowImg(show_img) == DOC_NEED_IMAGE_RELOAD)
  3228. {
  3229. if (load_img)
  3230. {
  3231. StartProgressDisplay(TRUE, TRUE, TRUE);
  3232. SetState(BUSY);
  3233. SetState(CLICKABLE);
  3234. }
  3235. }* /
  3236. }
  3237. }*/
  3238. OpDocumentListener::ImageDisplayMode mode;
  3239. #ifdef GADGET_SUPPORT
  3240. if (GetGadget())
  3241. {
  3242. mode = OpDocumentListener::ALL_IMAGES;
  3243. }
  3244. else
  3245. #endif
  3246. {
  3247. switch (set)
  3248. {
  3249. case FIGS_OFF:
  3250. mode = OpDocumentListener::NO_IMAGES;
  3251. break;
  3252. case FIGS_SHOW:
  3253. mode = OpDocumentListener::LOADED_IMAGES;
  3254. break;
  3255. default:
  3256. mode = OpDocumentListener::ALL_IMAGES;
  3257. break;
  3258. }
  3259. }
  3260. m_windowCommander->GetDocumentListener()->OnImageModeChanged(m_windowCommander, mode);
  3261. }
  3262. LayoutMode Window::GetLayoutMode() const
  3263. {
  3264. if (era_mode)
  3265. if (FramesDocument* doc = GetCurrentDoc())
  3266. return doc->GetLayoutMode();
  3267. return layout_mode;
  3268. }
  3269. void Window::SetLayoutMode(LayoutMode mode)
  3270. {
  3271. if (layout_mode != mode)
  3272. {
  3273. LayoutMode old_layout_mode = layout_mode;
  3274. layout_mode = mode;
  3275. is_ssr_mode = (mode == LAYOUT_SSR || mode == LAYOUT_CSSR); // use handheld until obsolete
  3276. FramesDocument* frames_doc = doc_manager->GetCurrentDoc();
  3277. int old_iframe_policy = SHOW_IFRAMES_ALL;
  3278. if (frames_doc)
  3279. old_iframe_policy = frames_doc->GetShowIFrames();
  3280. HLDocProfile *hldoc = frames_doc ? frames_doc->GetHLDocProfile() : NULL;
  3281. if (hldoc && old_layout_mode == LAYOUT_SSR)
  3282. hldoc->LoadAllCSS();
  3283. OP_STATUS ret = UpdateWindow(); // cause reformat because stylesheets may be different
  3284. if (OpStatus::IsError(ret))
  3285. {
  3286. RaiseCondition(ret);
  3287. }
  3288. if (frames_doc)
  3289. {
  3290. int iframe_policy = frames_doc->GetShowIFrames();
  3291. if (iframe_policy != SHOW_IFRAMES_NONE && old_iframe_policy != iframe_policy)
  3292. {
  3293. //FIXME SHOW_IFRAMES_SOME
  3294. frames_doc->LoadAllIFrames();
  3295. }
  3296. frames_doc->RecalculateLayoutViewSize(TRUE);
  3297. }
  3298. }
  3299. }
  3300. void Window::SetFramesPolicy(INT32 value)
  3301. {
  3302. if (m_frames_policy != value)
  3303. {
  3304. m_frames_policy = value;
  3305. UpdateWindow();
  3306. }
  3307. }
  3308. void Window::SetERA_Mode(BOOL value)
  3309. {
  3310. #ifdef GADGET_SUPPORT
  3311. if (GetGadget() && value == TRUE)
  3312. return;
  3313. #endif
  3314. if (era_mode != value)
  3315. {
  3316. era_mode = value;
  3317. DocumentTreeIterator iter(this);
  3318. iter.SetIncludeThis();
  3319. while (iter.Next())
  3320. iter.GetFramesDocument()->ERA_ModeChanged();
  3321. UpdateWindow(); // reformat
  3322. }
  3323. }
  3324. void Window::Reload(EnteredByUser entered_by_user, BOOL conditionally_request_document, BOOL conditionally_request_inlines)
  3325. {
  3326. #ifdef _PRINT_SUPPORT_
  3327. if (print_mode)
  3328. StopPrinting();
  3329. #endif // _PRINT_SUPPORT_
  3330. doc_manager->Reload(entered_by_user, conditionally_request_document, conditionally_request_inlines, FALSE);
  3331. }
  3332. BOOL Window::CancelLoad(BOOL oom)
  3333. {
  3334. is_canceling_loading = TRUE;
  3335. doc_manager->StopLoading(!oom, TRUE, TRUE);
  3336. if (oom)
  3337. SetOOMOccurred(TRUE);
  3338. SetState(NOT_BUSY);
  3339. EndProgressDisplay();
  3340. EnsureHistoryLimits();
  3341. phase_uploading = FALSE;
  3342. is_canceling_loading = FALSE;
  3343. return TRUE;
  3344. }
  3345. void Window::Raise()
  3346. {
  3347. m_windowCommander->GetDocumentListener()->OnRaiseRequest(m_windowCommander);
  3348. }
  3349. void Window::Lower()
  3350. {
  3351. m_windowCommander->GetDocumentListener()->OnLowerRequest(m_windowCommander);
  3352. }
  3353. FramesDocument *Window::GetCurrentDoc() const
  3354. {
  3355. return doc_manager->GetCurrentDoc();
  3356. }
  3357. void Window::HighlightURL(BOOL forward)
  3358. {
  3359. FramesDocument* doc = GetActiveFrameDoc();
  3360. if (doc)
  3361. {
  3362. if (doc->HighlightNextElm(HE_A, HE_A, forward, TRUE /*ignore lower/upper - get next anchor elm */))
  3363. {
  3364. #ifdef DISPLAY_CLICKINFO_SUPPORT
  3365. // Save link title for bookmark purposes
  3366. MouseListener::GetClickInfo().SetTitleElement(doc, doc->GetCurrentHTMLElement());
  3367. #endif // DISPLAY_CLICKINFO_SUPPORT
  3368. const uni_char* window_name = 0;
  3369. URL url = doc->GetCurrentURL(window_name);
  3370. if (!url.IsEmpty())
  3371. {
  3372. // Eventually it would be nice to unescape the url to make it more readable, but then we need to
  3373. // get the decoding to do it correctly with respect to charset encodings. See bug 250545
  3374. OpStringC hlink = url.GetAttribute(URL::KUniName_With_Fragment_Escaped);
  3375. if (hlink.HasContent())
  3376. g_windowManager->SetPopupMessage(hlink.CStr(), FALSE, ST_ALINK);
  3377. }
  3378. }
  3379. }
  3380. }
  3381. #ifdef _SPAT_NAV_SUPPORT_
  3382. /**
  3383. * Returns a pointer to the Window's Spatial Navigation handler.
  3384. * If the handler does not exist it is constructed and initialized.
  3385. * If memory allocation fails, then the function returns 0.
  3386. *
  3387. * @return Pointer to the SnHandler or 0 on failure.
  3388. *
  3389. */
  3390. OpSnHandler* Window::GetSnHandlerConstructIfNeeded ()
  3391. {
  3392. if (sn_handler == NULL)
  3393. {
  3394. #ifdef PHONE_SN_HANDLER
  3395. sn_handler = OP_NEW(PhoneSnHandler, ());
  3396. #else
  3397. sn_handler = OP_NEW(SnHandler, ());
  3398. #endif
  3399. if (sn_handler == NULL) // Out om memory!
  3400. {
  3401. return 0;
  3402. }
  3403. if (OpStatus::IsError(sn_handler->Init(this)))
  3404. {
  3405. OP_DELETE(sn_handler);
  3406. sn_handler = NULL;
  3407. return 0;
  3408. }
  3409. }
  3410. return sn_handler;
  3411. }
  3412. BOOL Window::MarkNextLinkInDirection(INT32 direction, POINT* startingPoint, BOOL scroll)
  3413. {
  3414. OpSnHandler* handler = GetSnHandlerConstructIfNeeded();
  3415. if (handler && handler->MarkNextLinkInDirection(direction, startingPoint, scroll))
  3416. return TRUE;
  3417. #ifdef SN_LEAVE_SUPPORT
  3418. else
  3419. LeaveInDirection(direction);
  3420. #endif // SN_LEAVE_SUPPORT
  3421. return FALSE;
  3422. }
  3423. BOOL Window::MarkNextImageInDirection(INT32 direction, POINT* startingPoint, BOOL scroll)
  3424. {
  3425. OpSnHandler* handler = GetSnHandlerConstructIfNeeded();
  3426. if (handler)
  3427. return handler->MarkNextImageInDirection(direction, startingPoint, scroll);
  3428. return FALSE;
  3429. }
  3430. BOOL Window::MarkNextItemInDirection(INT32 direction, POINT* startingPoint, BOOL scroll)
  3431. {
  3432. OpSnHandler* handler = GetSnHandlerConstructIfNeeded();
  3433. #ifdef SN_LEAVE_SUPPORT
  3434. if (!handler || !handler->MarkNextItemInDirection(direction, startingPoint, scroll))
  3435. LeaveInDirection(direction);
  3436. return TRUE;
  3437. #else // SN_LEAVE_SUPPORT
  3438. if (handler)
  3439. {
  3440. BOOL state = handler->MarkNextItemInDirection(direction, startingPoint, scroll);
  3441. #ifdef DISPLAY_CLICKINFO_SUPPORT
  3442. FramesDocument* doc = GetActiveFrameDoc();
  3443. if (doc)
  3444. {
  3445. // Save link title for bookmark purposes
  3446. MouseListener::GetClickInfo().SetTitleElement(doc, doc->GetCurrentHTMLElement());
  3447. }
  3448. #endif // DISPLAY_CLICKINFO_SUPPORT
  3449. return state;
  3450. }
  3451. return FALSE;
  3452. #endif // SN_LEAVE_SUPPORT
  3453. }
  3454. #ifdef SN_LEAVE_SUPPORT
  3455. //OBS! This is a temporary hack!
  3456. // It should probably be moved to some better place.
  3457. void Window::LeaveInDirection(INT32 direction)
  3458. {
  3459. if (sn_listener == NULL) return;
  3460. FramesDocument *doc = GetActiveFrameDoc();
  3461. if (!doc)
  3462. {
  3463. sn_listener->LeaveInDirection(direction);
  3464. return;
  3465. }
  3466. HTML_Document *hdoc = doc->GetHtmlDocument();
  3467. if (!hdoc)
  3468. {
  3469. sn_listener->LeaveInDirection(direction);
  3470. return;
  3471. }
  3472. HTML_Element *helm = hdoc->GetNavigationElement();
  3473. if (!helm)
  3474. {
  3475. sn_listener->LeaveInDirection(direction);
  3476. return;
  3477. }
  3478. LogicalDocument *logdoc = doc->GetLogicalDocument();
  3479. if (!logdoc)
  3480. {
  3481. sn_listener->LeaveInDirection(direction);
  3482. return;
  3483. }
  3484. RECT rect;
  3485. if (!logdoc->GetBoxRect(helm, rect))
  3486. {
  3487. sn_listener->LeaveInDirection(direction);
  3488. return;
  3489. }
  3490. VisualDevice *visdev = doc->GetVisualDevice();
  3491. if (visdev == NULL)
  3492. {
  3493. sn_listener->LeaveInDirection(direction);
  3494. return;
  3495. }
  3496. // Calculate the "leave point"
  3497. int x = 0;
  3498. int y = 0;
  3499. switch ((direction % 360) / 90)
  3500. {
  3501. case 0: // Right
  3502. x = rect.right;
  3503. y = (rect.top + rect.bottom) / 2;
  3504. break;
  3505. case 1: // Up
  3506. x = (rect.right + rect.left) / 2;
  3507. y = rect.top;
  3508. break;
  3509. case 2: // Left
  3510. x = rect.left;
  3511. y = (rect.top + rect.bottom) / 2;
  3512. break;
  3513. case 3: // Down
  3514. x = (rect.right + rect.left) / 2;
  3515. y = rect.bottom;
  3516. break;
  3517. }
  3518. sn_listener->LeaveInDirection(direction, x, y, visdev->GetOpView());
  3519. return;
  3520. }
  3521. void Window::SetSnLeaveListener(SnLeaveListener *listener)
  3522. {
  3523. sn_listener = listener;
  3524. }
  3525. void Window::SnMarkSelection()
  3526. {
  3527. SnHandler* handler = static_cast<SnHandler *>(GetSnHandler());
  3528. if (handler) handler->HighlightCurrentElement();
  3529. }
  3530. #endif //SN_LEAVE_SUPPORTED
  3531. #endif // _SPAT_NAV_SUPPORT_
  3532. void Window::HighlightHeading(BOOL forward)
  3533. {
  3534. if (FramesDocument* doc = GetActiveFrameDoc())
  3535. doc->HighlightNextElm(HE_H1, HE_H6, forward, FALSE);
  3536. }
  3537. void Window::HighlightItem(BOOL forward)
  3538. {
  3539. if (FramesDocument* doc = GetActiveFrameDoc())
  3540. doc->HighlightNextElm(Markup::HTE_FIRST, Markup::HTE_LAST, forward, FALSE);
  3541. }
  3542. OP_STATUS Window::GetHighlightedURL(uint16 key, BOOL bNewWindow, BOOL bOpenInBackground)
  3543. {
  3544. FramesDocument* doc = GetCurrentDoc();
  3545. if (doc)
  3546. {
  3547. FramesDocument *sub_doc = doc->GetActiveSubDoc();
  3548. {
  3549. #ifdef _WML_SUPPORT_
  3550. if (doc->GetDocManager()->WMLHasWML())
  3551. {
  3552. if (!FormManager::ValidateWMLForm(doc))
  3553. return OpStatus::OK;
  3554. }
  3555. #endif // _WML_SUPPORT_
  3556. int sub_win_id = -1;
  3557. const uni_char* window_name = NULL;
  3558. URL url = doc->GetCurrentURL(window_name);
  3559. if (!url.IsEmpty())
  3560. return g_windowManager->OpenURLNamedWindow(url, this, doc, sub_doc ? sub_doc->GetSubWinId() : sub_win_id, window_name, TRUE, bNewWindow, bOpenInBackground, TRUE);
  3561. else if (key==OP_KEY_SPACE)
  3562. {
  3563. if (doc->IsFrameDoc())
  3564. doc = doc->GetActiveSubDoc();
  3565. ScrollDocument(doc, bNewWindow ? (bOpenInBackground? OpInputAction::ACTION_GO_TO_START : OpInputAction::ACTION_PAGE_UP)
  3566. : (bOpenInBackground? OpInputAction::ACTION_GO_TO_END : OpInputAction::ACTION_PAGE_DOWN));
  3567. }
  3568. }
  3569. }
  3570. return OpStatus::OK;
  3571. }
  3572. void Window::RaiseCondition( OP_STATUS type )
  3573. {
  3574. if (type == OpStatus::ERR_NO_MEMORY)
  3575. GetMessageHandler()->PostOOMCondition(TRUE);
  3576. else if (type == OpStatus::ERR_SOFT_NO_MEMORY)
  3577. GetMessageHandler()->PostOOMCondition(FALSE);
  3578. else if (type == OpStatus::ERR_NO_DISK)
  3579. GetMessageHandler()->PostOODCondition();
  3580. else
  3581. OP_ASSERT(0);
  3582. }
  3583. Window::OnlineMode Window::GetOnlineMode()
  3584. {
  3585. if (m_online_mode == Window::ONLINE || m_online_mode == Window::OFFLINE)
  3586. m_online_mode = g_pcnet->GetIntegerPref(PrefsCollectionNetwork::OfflineMode) ? OFFLINE : ONLINE;
  3587. return m_online_mode;
  3588. }
  3589. OP_STATUS Window::QueryGoOnline(URL *url)
  3590. {
  3591. if (m_online_mode == Window::OFFLINE)
  3592. {
  3593. OpString url_name;
  3594. OpString message;
  3595. RETURN_IF_ERROR(url->GetAttribute(URL::KUniName_Username_Password_Hidden, url_name, TRUE));
  3596. if (url_name.Length() > 100)
  3597. url_name.Delete(90).Append(UNI_L("..."));
  3598. OpString warning;
  3599. TRAPD(err, g_languageManager->GetStringL(Str::SI_MSG_OFFLINE_WARNING, warning));
  3600. if (OpStatus::IsMemoryError(err))
  3601. {
  3602. return err;
  3603. }
  3604. RETURN_IF_ERROR(message.AppendFormat(warning.CStr(), url_name.CStr()));
  3605. m_online_mode = Window::USER_RESPONDING;
  3606. WindowCommander* wc = GetWindowCommander();
  3607. OP_ASSERT(wc);
  3608. OpDocumentListener *listener = wc->GetDocumentListener();
  3609. listener->OnQueryGoOnline(wc, message.CStr(), this);
  3610. }
  3611. return OpStatus::OK;
  3612. }
  3613. void Window::OnDialogReply(DialogCallback::Reply reply)
  3614. {
  3615. if (reply == DialogCallback::REPLY_YES)
  3616. {
  3617. m_online_mode = Window::ONLINE;
  3618. if (UpdateOfflineMode(FALSE) == OpBoolean::IS_TRUE)
  3619. UpdateOfflineMode(TRUE);
  3620. }
  3621. else
  3622. {
  3623. m_online_mode = Window::DENIED;
  3624. if (OpStatus::IsMemoryError(DocManager()->OnlineModeChanged()))
  3625. RaiseCondition(OpStatus::ERR_NO_MEMORY);
  3626. }
  3627. }
  3628. void
  3629. Window::LockWindow()
  3630. {
  3631. window_locked++;
  3632. }
  3633. void
  3634. Window::UnlockWindow()
  3635. {
  3636. OP_ASSERT(window_locked);
  3637. window_locked--;
  3638. if (window_locked == 0 && window_closed)
  3639. {
  3640. g_main_message_handler->PostMessage(MSG_ES_CLOSE_WINDOW, 0, id);
  3641. window_closed = FALSE;
  3642. }
  3643. }
  3644. BOOL
  3645. Window::IsURLAlreadyRequested(const URL &url)
  3646. {
  3647. return loading && use_already_requested_urls && already_requested_urls.Contains(url.Id());
  3648. }
  3649. void
  3650. Window::SetURLAlreadyRequested(const URL &url)
  3651. {
  3652. if (loading && use_already_requested_urls)
  3653. if (OpStatus::IsMemoryError(already_requested_urls.Add(url.Id())))
  3654. {
  3655. already_requested_urls.RemoveAll();
  3656. use_already_requested_urls = FALSE;
  3657. }
  3658. }
  3659. void
  3660. Window::HandleCallback(OpMessage msg, MH_PARAM_1 par1, MH_PARAM_2 par2)
  3661. {
  3662. #ifdef LOCALE_CONTEXTS
  3663. if (doc_manager && doc_manager->GetCurrentDoc())
  3664. g_languageManager->SetContext(doc_manager->GetCurrentDoc()->GetURL().GetContextId());
  3665. #endif
  3666. switch (msg)
  3667. {
  3668. case MSG_PROGRESS_START:
  3669. if (!loading)
  3670. {
  3671. #ifdef DEBUG_LOAD_STATUS
  3672. PrintfTofile("loading.txt","================================%lu\n", (unsigned long) g_op_time_info->GetWallClockMS());
  3673. #endif
  3674. SetLoading(TRUE);
  3675. already_requested_urls.RemoveAll();
  3676. use_already_requested_urls = TRUE;
  3677. #if defined(EPOC)
  3678. if (m_windowCommander) // Check in case this Window is the "hidden transfer window"
  3679. {
  3680. Window* epocWindow = m_windowCommander ? m_windowCommander->GetWindow() : 0;
  3681. if((epocWindow->m_loading_information).isUploading)
  3682. m_windowCommander->GetLoadingListener()->OnStartUploading(m_windowCommander);
  3683. else
  3684. m_windowCommander->GetLoadingListener()->OnStartLoading(m_windowCommander);
  3685. }
  3686. #else // EPOC
  3687. m_windowCommander->GetLoadingListener()->OnStartLoading(m_windowCommander);
  3688. #endif // EPOC
  3689. }
  3690. break;
  3691. case MSG_PROGRESS_END:
  3692. if (loading)
  3693. {
  3694. #ifdef DEBUG_LOAD_STATUS
  3695. PrintfTofile("loading.txt","================================%lu\n", (unsigned long) g_op_time_info->GetWallClockMS());
  3696. #endif
  3697. SetLoading(FALSE);
  3698. UnlockPaintLock();
  3699. pending_unlock_all_painting = FALSE;
  3700. already_requested_urls.RemoveAll();
  3701. use_already_requested_urls = TRUE;
  3702. OpLoadingListener::LoadingFinishStatus status = static_cast<OpLoadingListener::LoadingFinishStatus>(par2);
  3703. m_windowCommander->GetLoadingListener()->OnLoadingFinished(m_windowCommander, status);
  3704. if (m_online_mode == Window::DENIED)
  3705. m_online_mode = Window::OFFLINE;
  3706. #ifdef _SPAT_NAV_SUPPORT_
  3707. OpSnHandler* handler = GetSnHandlerConstructIfNeeded();
  3708. if (handler)
  3709. handler->OnLoadingFinished();
  3710. #endif // _SPAT_NAV_SUPPORT_
  3711. OP_STATUS oom = doc_manager->UpdateWindowHistoryAndTitle();
  3712. if (OpStatus::IsMemoryError(oom))
  3713. RaiseCondition(oom);
  3714. }
  3715. break;
  3716. #ifdef _PRINT_SUPPORT_
  3717. case DOC_START_PRINTING:
  3718. # ifdef GENERIC_PRINTING
  3719. {
  3720. PrinterInfo * prnInfo = OP_NEW(PrinterInfo, ());
  3721. int start_page = 1;
  3722. if (prnInfo == NULL)
  3723. {
  3724. RaiseCondition(OpStatus::ERR_NO_MEMORY);
  3725. break;
  3726. }
  3727. PrintDevice * printDevice;
  3728. # ifdef PRINT_SELECTION_USING_DUMMY_WINDOW
  3729. Window * selection_window = 0;
  3730. OP_STATUS result = prnInfo->GetPrintDevice(printDevice, FALSE, FALSE, this, &selection_window);
  3731. # else
  3732. OP_STATUS result = prnInfo->GetPrintDevice(printDevice, FALSE, FALSE, this);
  3733. # endif
  3734. if (OpStatus::IsError(result) || !printDevice->StartPage())
  3735. {
  3736. OP_DELETE(prnInfo);
  3737. break;
  3738. }
  3739. SetFramesPrintType((DM_PrintType)g_pcprint->GetIntegerPref(PrefsCollectionPrint::DefaultFramesPrintType), TRUE);
  3740. Window * window = this;
  3741. # ifdef PRINT_SELECTION_USING_DUMMY_WINDOW
  3742. if (selection_window != 0)
  3743. window = selection_window;
  3744. # endif
  3745. window->StartPrinting(prnInfo, start_page, FALSE);
  3746. }
  3747. # endif // GENERIC_PRINTING
  3748. break;
  3749. case DOC_PRINT_FORMATTED:
  3750. # if defined GENERIC_PRINTING
  3751. if (printer_info)
  3752. printer_info->GetPrintDevice()->GetPrinterController()->PrintDocFormatted(printer_info);
  3753. else if (preview_printer_info)
  3754. preview_printer_info->GetPrintDevice()->GetPrinterController()->PrintDocFormatted(preview_printer_info);
  3755. {
  3756. OpPrintingListener::PrintInfo info; //rg fixme
  3757. info.status = OpPrintingListener::PrintInfo::PRINTING_STARTED;
  3758. m_windowCommander->GetPrintingListener()->OnPrintStatus(m_windowCommander, &info);
  3759. }
  3760. # elif defined MSWIN
  3761. {
  3762. OP_NEW_DBG("Window::HandleMessage", "async_print");
  3763. OP_DBG(("Will enter ucPrintFormatted"));
  3764. ucPrintDocFormatted();
  3765. }
  3766. # elif defined _X11_ || defined _MACINTOSH_
  3767. PrintNextPage(printer_info ? printer_info : preview_printer_info);
  3768. # endif // GENERIC_PRINTING
  3769. break;
  3770. case DOC_PAGE_PRINTED:
  3771. # if defined GENERIC_PRINTING
  3772. if (printer_info)
  3773. printer_info->GetPrintDevice()->GetPrinterController()->PrintPagePrinted(printer_info);
  3774. else if (preview_printer_info)
  3775. preview_printer_info->GetPrintDevice()->GetPrinterController()->PrintPagePrinted(preview_printer_info);
  3776. {
  3777. OpPrintingListener::PrintInfo info; //rg fixme
  3778. info.status = OpPrintingListener::PrintInfo::PAGE_PRINTED;
  3779. info.currentPage = par2;
  3780. m_windowCommander->GetPrintingListener()->OnPrintStatus(m_windowCommander, &info);
  3781. }
  3782. # else // GENERIC_PRINTING
  3783. {
  3784. OpPrintingListener::PrintInfo info; //rg fixme
  3785. info.status = OpPrintingListener::PrintInfo::PAGE_PRINTED;
  3786. info.currentPage = par2;
  3787. m_windowCommander->GetPrintingListener()->OnPrintStatus(m_windowCommander, &info);
  3788. }
  3789. # endif // GENERIC_PRINTING
  3790. break;
  3791. case DOC_PRINTING_FINISHED:
  3792. # ifdef GENERIC_PRINTING
  3793. if (printer_info)
  3794. printer_info->GetPrintDevice()->GetPrinterController()->PrintDocFinished();
  3795. else if (preview_printer_info)
  3796. preview_printer_info->GetPrintDevice()->GetPrinterController()->PrintDocFinished();
  3797. StopPrinting();
  3798. {
  3799. OpPrintingListener::PrintInfo info;
  3800. info.status = OpPrintingListener::PrintInfo::PRINTING_DONE;
  3801. m_windowCommander->GetPrintingListener()->OnPrintStatus(m_windowCommander, &info);
  3802. }
  3803. # else // GENERIC_PRINTING
  3804. {
  3805. OpPrintingListener::PrintInfo info;
  3806. info.status = OpPrintingListener::PrintInfo::PRINTING_DONE;
  3807. m_windowCommander->GetPrintingListener()->OnPrintStatus(m_windowCommander, &info);
  3808. }
  3809. # endif // GENERIC_PRINTING
  3810. break;
  3811. case DOC_PRINTING_ABORTED:
  3812. # ifdef GENERIC_PRINTING
  3813. if (printer_info)
  3814. printer_info->GetPrintDevice()->GetPrinterController()->PrintDocAborted();
  3815. else if (preview_printer_info)
  3816. preview_printer_info->GetPrintDevice()->GetPrinterController()->PrintDocAborted();
  3817. StopPrinting();
  3818. {
  3819. OpPrintingListener::PrintInfo info; //rg fixme
  3820. info.status = OpPrintingListener::PrintInfo::PRINTING_ABORTED;
  3821. m_windowCommander->GetPrintingListener()->OnPrintStatus(m_windowCommander, &info);
  3822. }
  3823. # else // GENERIC_PRINTING
  3824. {
  3825. OpPrintingListener::PrintInfo info; //rg fixme
  3826. info.status = OpPrintingListener::PrintInfo::PRINTING_ABORTED;
  3827. m_windowCommander->GetPrintingListener()->OnPrintStatus(m_windowCommander, &info);
  3828. }
  3829. # endif // GENERIC_PRINTING
  3830. break;
  3831. #endif // _PRINTING_SUPPORT_
  3832. #if !defined MOUSELESS && !defined HAS_NOTEXTSELECTION
  3833. case MSG_SELECTION_SCROLL:
  3834. #ifdef DRAG_SUPPORT
  3835. if (!g_drag_manager->IsDragging())
  3836. #endif
  3837. {
  3838. if (!selection_scroll_active)
  3839. break;
  3840. const int fudge = 5;
  3841. BOOL button_pressed = FALSE;
  3842. OpInputContext* ic = NULL;
  3843. FramesDocument* doc = GetActiveFrameDoc();
  3844. while(doc)
  3845. {
  3846. VisualDevice* vis_dev = doc->GetVisualDevice();
  3847. CoreView *view = vis_dev->GetView();
  3848. BOOL retry = FALSE;
  3849. if (view)
  3850. {
  3851. OpRect bounding_rect(doc->GetVisualViewport());
  3852. if (!ic && g_input_manager->GetKeyboardInputContext())
  3853. {
  3854. ic = g_input_manager->GetKeyboardInputContext();
  3855. // First try with the focused inputcontext. It may be a scrollable container in page layout.
  3856. if (ic->GetBoundingRect(bounding_rect))
  3857. {
  3858. bounding_rect.x += vis_dev->GetRenderingViewX();
  3859. bounding_rect.y += vis_dev->GetRenderingViewY();
  3860. }
  3861. // Retry, scrolling the document (if not the document).
  3862. retry = ic != vis_dev;
  3863. }
  3864. else
  3865. ic = vis_dev;
  3866. INT32 xpos, ypos;
  3867. if(!view->GetMouseButton(MOUSE_BUTTON_1) &&
  3868. !view->GetMouseButton(MOUSE_BUTTON_2) &&
  3869. !view->GetMouseButton(MOUSE_BUTTON_3))
  3870. break;
  3871. button_pressed = TRUE;
  3872. view->GetMousePos(&xpos, &ypos);
  3873. xpos = vis_dev->GetRenderingViewX() + vis_dev->ScaleToDoc(xpos);
  3874. ypos = vis_dev->GetRenderingViewY() + vis_dev->ScaleToDoc(ypos);
  3875. BOOL handled = FALSE;
  3876. if(xpos < bounding_rect.x + fudge)
  3877. {
  3878. OpInputAction action(OpInputAction::ACTION_SCROLL_LEFT);
  3879. handled |= ic->OnInputAction(&action);
  3880. }
  3881. else if(xpos > bounding_rect.x + bounding_rect.width - fudge)
  3882. {
  3883. OpInputAction action(OpInputAction::ACTION_SCROLL_RIGHT);
  3884. handled |= ic->OnInputAction(&action);
  3885. }
  3886. if(ypos < bounding_rect.y + fudge)
  3887. {
  3888. OpInputAction action(OpInputAction::ACTION_SCROLL_UP);
  3889. handled |= ic->OnInputAction(&action);
  3890. }
  3891. else if(ypos > bounding_rect.y + bounding_rect.height - fudge)
  3892. {
  3893. OpInputAction action(OpInputAction::ACTION_SCROLL_DOWN);
  3894. handled |= ic->OnInputAction(&action);
  3895. }
  3896. if (handled)
  3897. break;
  3898. }
  3899. if (!retry)
  3900. doc = doc->GetParentDoc();
  3901. }
  3902. if (button_pressed)
  3903. //Keep the scroll running...
  3904. if (!GetMessageHandler()->PostDelayedMessage(MSG_SELECTION_SCROLL, 0, 0, 75))
  3905. g_memory_manager->RaiseCondition(OpStatus::ERR_NO_MEMORY);
  3906. }
  3907. break;
  3908. #endif // !MOUSELESS && !HAS_NOTEXTSELECTION
  3909. case MSG_ES_CLOSE_WINDOW:
  3910. g_main_message_handler->PostMessage(MSG_ES_CLOSE_WINDOW, 0, Id());
  3911. break;
  3912. case MSG_UPDATE_PROGRESS_TEXT:
  3913. {
  3914. OP_STATUS ret = SetProgressText(doc_manager->GetCurrentURL(), TRUE);
  3915. if (ret == OpStatus::ERR_NO_MEMORY)
  3916. {
  3917. RaiseCondition(ret);
  3918. }
  3919. }
  3920. break;
  3921. case MSG_UPDATE_WINDOW_TITLE:
  3922. {
  3923. title_update_title_posted = FALSE;
  3924. OP_STATUS ret = UpdateTitle(FALSE);
  3925. if (ret == OpStatus::ERR_NO_MEMORY)
  3926. {
  3927. RaiseCondition(ret);
  3928. }
  3929. }
  3930. break;
  3931. case WM_OPERA_SCALEDOC:
  3932. {
  3933. // wParam = Window to scale.
  3934. // HIWORD( lParam) = (BOOL) bIsAbsolute
  3935. // LOWORD( lParam) = New scale or adjustment (depending on the highword)
  3936. short scale;
  3937. if (HIWORD(par2)) // absolute (=TRUE) or relative (=FALSE)
  3938. scale = LOWORD(par2);
  3939. else
  3940. scale = GetScale() + static_cast<short>(LOWORD(par2));
  3941. ViewportController* controller = GetViewportController();
  3942. controller->GetViewportRequestListener()->
  3943. OnZoomLevelChangeRequest(controller, (MIN((short)DOCHAND_MAX_DOC_ZOOM, scale)) / 100.0
  3944. // don't specify a priority rectangle, though the input action might
  3945. // have had one:
  3946. // TODO: pass the priority rectangle in the message parameter as well.
  3947. , 0,
  3948. // this message is a result of an input action (e.g. CTRL+mouse-wheel
  3949. // or definition in input.ini):
  3950. VIEWPORT_CHANGE_REASON_INPUT_ACTION
  3951. );
  3952. }
  3953. break;
  3954. case MSG_URL_MOVED:
  3955. {
  3956. URL cu = doc_manager->GetCurrentURL();
  3957. if (cu.Id(TRUE) == static_cast<URL_ID>(par2))
  3958. {
  3959. URL moved_to = cu.GetAttribute(URL::KMovedToURL, TRUE);
  3960. if (!moved_to.IsEmpty())
  3961. {
  3962. URLLink *url_ref = OP_NEW(URLLink, (moved_to));
  3963. url_ref->Into(&moved_urls);
  3964. }
  3965. }
  3966. }
  3967. break;
  3968. case MSG_HISTORY_BACK:
  3969. if (HasHistoryPrev())
  3970. SetHistoryPrev(FALSE);
  3971. break;
  3972. case MSG_HISTORY_CLEANUP:
  3973. history_cleanup_message_sent = FALSE;
  3974. EnsureHistoryLimits();
  3975. break;
  3976. }
  3977. if (check_history)
  3978. CheckHistory();
  3979. }
  3980. BOOL Window::GetLimitParagraphWidth()
  3981. {
  3982. return limit_paragraph_width
  3983. #ifndef LIMIT_PARA_WIDTH_IGNORE_MODES
  3984. && !era_mode && (GetLayoutMode() == LAYOUT_NORMAL)
  3985. #endif
  3986. ;
  3987. }
  3988. void Window::SetLimitParagraphWidth(BOOL set)
  3989. {
  3990. limit_paragraph_width = set;
  3991. if (FramesDocument *frm_doc = doc_manager->GetCurrentDoc())
  3992. frm_doc->MarkContainersDirty();
  3993. }
  3994. void Window::SetFlexRootMaxWidth(int max_width, BOOL reformat)
  3995. {
  3996. if (flex_root_max_width != max_width)
  3997. {
  3998. // max_width == 0 means disable flex-root
  3999. flex_root_max_width = max_width;
  4000. if (doc_manager)
  4001. if (FramesDocument* doc = doc_manager->GetCurrentDoc())
  4002. doc->RecalculateLayoutViewSize(TRUE);
  4003. if (reformat)
  4004. UpdateWindow();
  4005. }
  4006. }
  4007. void Window::ResumeEcmaScriptIfNotPaused()
  4008. {
  4009. if (ecmascript_paused == NOT_PAUSED)
  4010. {
  4011. DocumentTreeIterator iterator(this);
  4012. iterator.SetIncludeThis();
  4013. while (iterator.Next())
  4014. {
  4015. if (ES_ThreadScheduler *scheduler = iterator.GetFramesDocument()->GetESScheduler())
  4016. scheduler->ResumeIfNeeded();
  4017. }
  4018. }
  4019. }
  4020. void Window::SetEcmaScriptPaused(BOOL value)
  4021. {
  4022. if (value)
  4023. ecmascript_paused |= PAUSED_OTHER;
  4024. else
  4025. {
  4026. ecmascript_paused &= ~PAUSED_OTHER;
  4027. ResumeEcmaScriptIfNotPaused();
  4028. }
  4029. }
  4030. void Window::CancelAllEcmaScriptTimeouts()
  4031. {
  4032. DocumentTreeIterator iterator(this);
  4033. iterator.SetIncludeThis();
  4034. while (iterator.Next())
  4035. if (ES_ThreadScheduler *scheduler = iterator.GetFramesDocument()->GetESScheduler())
  4036. scheduler->CancelAllTimeouts(TRUE, TRUE);
  4037. }
  4038. #if defined GRAB_AND_SCROLL
  4039. BOOL Window::GetScrollIsPan() const
  4040. {
  4041. return scroll_is_pan_overridden ? scroll_is_pan : g_pcdisplay->GetIntegerPref(PrefsCollectionDisplay::ScrollIsPan);
  4042. }
  4043. void Window::OverrideScrollIsPan()
  4044. {
  4045. if (scroll_is_pan_overridden)
  4046. scroll_is_pan = scroll_is_pan ? FALSE : TRUE;
  4047. else
  4048. {
  4049. scroll_is_pan_overridden = TRUE;
  4050. scroll_is_pan = g_pcdisplay->GetIntegerPref(PrefsCollectionDisplay::ScrollIsPan) ? FALSE : TRUE;
  4051. }
  4052. }
  4053. #endif // GRAB_AND_SCROLL
  4054. #ifdef SAVE_SUPPORT
  4055. void Window::GetSuggestedSaveFileName(URL *url, uni_char *szName, int maxSize)
  4056. {
  4057. }
  4058. OP_BOOLEAN Window::SaveAs(URL& url, BOOL load_to_file, BOOL save_inline, BOOL frames_only)
  4059. {
  4060. return OpBoolean::IS_FALSE;
  4061. }
  4062. OP_BOOLEAN Window::SaveAs(URL& url, BOOL load_to_file, BOOL save_inline, const uni_char* szSaveToFolder, BOOL fCreateDirectory, BOOL fExecute, BOOL hasfilename, const uni_char* handlerapplication, BOOL frames_only)
  4063. {
  4064. return OpBoolean::IS_FALSE;
  4065. }
  4066. #endif // SAVE_SUPPORT
  4067. #ifdef NEARBY_ELEMENT_DETECTION
  4068. void Window::SetElementExpander(ElementExpander* expander)
  4069. {
  4070. ElementExpander* old_element_expander = element_expander;
  4071. // Assign expander member variable before deleting old_element_expander because
  4072. // ElementExpander destructor may call WindowCommander::HideFingertouchElements, and then Window::SetElementExpander
  4073. // that can lead to a double free (crash)
  4074. element_expander = expander;
  4075. OP_DELETE(old_element_expander);
  4076. }
  4077. #endif // NEARBY_ELEMENT_DETECTION
  4078. void Window::SetPrivacyMode(BOOL privacy_mode)
  4079. {
  4080. if (privacy_mode != m_privacy_mode)
  4081. {
  4082. m_privacy_mode = privacy_mode;
  4083. if (m_privacy_mode)
  4084. g_windowManager->AddWindowToPrivacyModeContext();
  4085. else
  4086. {
  4087. g_windowManager->RemoveWindowFromPrivacyModeContext();
  4088. doc_manager->UnloadCurrentDoc();
  4089. RemoveAllElementsExceptCurrent();
  4090. }
  4091. }
  4092. }
  4093. #ifdef WEB_TURBO_MODE
  4094. void Window::SetTurboMode(BOOL turbo_mode)
  4095. {
  4096. if (turbo_mode)
  4097. {
  4098. if (type != WIN_TYPE_NORMAL) // Turbo Mode only available for normal windows.
  4099. return;
  4100. #ifdef GADGET_SUPPORT
  4101. if(GetGadget())
  4102. return;
  4103. #endif // GADGET_SUPPORT
  4104. #ifdef OBML_COMM_FORCE_CONFIG_FILE
  4105. if (g_obml_config->GetExpired()) // Absence of correct and valid config file means no Turbo support
  4106. {
  4107. urlManager->SetWebTurboAvailable(FALSE);
  4108. return;
  4109. }
  4110. #endif // OBML_COMM_FORCE_CONFIG_FILE
  4111. }
  4112. if (turbo_mode != m_turbo_mode)
  4113. {
  4114. if (turbo_mode)
  4115. {
  4116. if (OpStatus::IsSuccess(g_windowManager->CheckTuboModeContext()))
  4117. m_turbo_mode = turbo_mode;
  4118. }
  4119. else
  4120. m_turbo_mode = turbo_mode;
  4121. if (turbo_mode == m_turbo_mode)
  4122. {
  4123. if (doc_manager)
  4124. doc_manager->UpdateTurboMode();
  4125. }
  4126. }
  4127. }
  4128. #endif // WEB_TURBO_MODE
  4129. void Window::ScreenPropertiesHaveChanged(){
  4130. //iter all doc-managers, and inform visual devices that
  4131. //the screen properties have changed
  4132. DocumentTreeIterator it(this);
  4133. it.SetIncludeThis();
  4134. while (it.Next())
  4135. {
  4136. if(it.GetDocumentManager()->GetVisualDevice())
  4137. {
  4138. it.GetDocumentManager()->GetVisualDevice()->ScreenPropertiesHaveChanged();
  4139. if (FramesDocument* doc = it.GetFramesDocument())
  4140. doc->RecalculateDeviceMediaQueries();
  4141. }
  4142. }
  4143. #ifdef DOM_JIL_API_SUPPORT
  4144. if(m_screen_props_listener)
  4145. m_screen_props_listener->OnScreenPropsChanged();
  4146. #endif // DOM_JIL_API_SUPPORT
  4147. }
  4148. #ifdef GADGET_SUPPORT
  4149. void Window::SetGadget(OpGadget* gadget)
  4150. {
  4151. m_windowCommander->SetGadget(gadget);
  4152. era_mode = FALSE;
  4153. show_img = TRUE;
  4154. load_img = TRUE;
  4155. }
  4156. OpGadget* Window::GetGadget() const
  4157. {
  4158. return m_windowCommander->GetGadget();
  4159. }
  4160. #endif // GADGET_SUPPORT
  4161. WindowViewMode Window::GetViewMode()
  4162. {
  4163. #ifdef GADGET_SUPPORT
  4164. if (GetType() == WIN_TYPE_GADGET)
  4165. return GetGadget()->GetMode();
  4166. #endif // GADGET_SUPPORT
  4167. if (IsThumbnailWindow())
  4168. return WINDOW_VIEW_MODE_MINIMIZED;
  4169. if (IsFullScreen())
  4170. return WINDOW_VIEW_MODE_FULLSCREEN;
  4171. return WINDOW_VIEW_MODE_WINDOWED;
  4172. }
  4173. #ifdef SCOPE_PROFILER
  4174. OP_STATUS
  4175. Window::StartProfiling(OpProfilingSession *session)
  4176. {
  4177. if (m_profiling_session != NULL)
  4178. return OpStatus::ERR;
  4179. m_profiling_session = session;
  4180. DocumentTreeIterator i(this);
  4181. i.SetIncludeThis();
  4182. i.SetIncludeEmpty();
  4183. while (i.Next())
  4184. {
  4185. DocumentManager *docman = i.GetDocumentManager();
  4186. OP_STATUS status = docman->StartProfiling(session);
  4187. if (OpStatus::IsMemoryError(status))
  4188. {
  4189. StopProfiling();
  4190. m_profiling_session = NULL;
  4191. return status;
  4192. }
  4193. }
  4194. return OpStatus::OK;
  4195. }
  4196. void
  4197. Window::StopProfiling()
  4198. {
  4199. if (m_profiling_session == NULL)
  4200. return;
  4201. m_profiling_session = NULL;
  4202. DocumentTreeIterator i(this);
  4203. i.SetIncludeThis();
  4204. i.SetIncludeEmpty();
  4205. while (i.Next())
  4206. i.GetDocumentManager()->StopProfiling();
  4207. }
  4208. #endif // SCOPE_PROFILER
  4209. #ifdef GEOLOCATION_SUPPORT
  4210. void
  4211. Window::NotifyGeolocationAccess()
  4212. {
  4213. DocumentTreeIterator it(DocManager());
  4214. it.SetIncludeThis();
  4215. OpAutoStringHashSet hosts_set;
  4216. OpVector<uni_char> hosts;
  4217. while (it.Next())
  4218. {
  4219. if (FramesDocument* doc = it.GetFramesDocument())
  4220. {
  4221. if (doc->GetGeolocationUseCount() == 0)
  4222. continue;
  4223. const uni_char* hostname = OpSecurityManager::GetHostName(doc->GetURL());
  4224. uni_char* hostname_copy = UniSetNewStr(hostname); // Copy because this might use temporary URL buffers.
  4225. if (!hostname_copy)
  4226. return;
  4227. OP_STATUS status = hosts_set.Add(hostname_copy);
  4228. if (OpStatus::IsError(status))
  4229. {
  4230. OP_DELETEA(hostname_copy);
  4231. if (status != OpStatus::ERR)
  4232. return;
  4233. }
  4234. }
  4235. }
  4236. RETURN_VOID_IF_ERROR(hosts_set.CopyAllToVector(hosts));
  4237. GetWindowCommander()->GetDocumentListener()->OnGeolocationAccess(GetWindowCommander(), static_cast<OpVector<uni_char>*>(&hosts));
  4238. }
  4239. #endif // GEOLOCATION_SUPPORT
  4240. #ifdef MEDIA_CAMERA_SUPPORT
  4241. void
  4242. Window::NotifyCameraAccess()
  4243. {
  4244. DocumentTreeIterator it(DocManager());
  4245. it.SetIncludeThis();
  4246. OpAutoStringHashSet hosts_set;
  4247. OpVector<uni_char> hosts;
  4248. while (it.Next())
  4249. {
  4250. if (FramesDocument* doc = it.GetFramesDocument())
  4251. {
  4252. if (doc->GetCameraUseCount() == 0)
  4253. continue;
  4254. const uni_char* hostname = OpSecurityManager::GetHostName(doc->GetURL());
  4255. uni_char* hostname_copy = UniSetNewStr(hostname); // Copy because this might use temporary URL buffers.
  4256. if (!hostname_copy)
  4257. return;
  4258. OP_STATUS status = hosts_set.Add(hostname_copy);
  4259. if (OpStatus::IsError(status))
  4260. {
  4261. OP_DELETEA(hostname_copy);
  4262. if (status != OpStatus::ERR)
  4263. return;
  4264. }
  4265. }
  4266. }
  4267. RETURN_VOID_IF_ERROR(hosts_set.CopyAllToVector(hosts));
  4268. GetWindowCommander()->GetDocumentListener()->OnCameraAccess(GetWindowCommander(), static_cast<OpVector<uni_char>*>(&hosts));
  4269. }
  4270. #endif // MEDIA_CAMERA_SUPPORT
  4271. #ifdef USE_OP_CLIPBOARD
  4272. void Window::OnCopy(OpClipboard* clipboard)
  4273. {
  4274. FramesDocument* doc = GetActiveFrameDoc();
  4275. if (doc)
  4276. {
  4277. HTML_Document* html_doc = doc->GetHtmlDocument();
  4278. #ifdef DOCUMENT_EDIT_SUPPORT
  4279. OpDocumentEdit* docedit = doc->GetDocumentEdit();
  4280. #endif // DOCUMENT_EDIT_SUPPORT
  4281. if (html_doc)
  4282. {
  4283. if (HTML_Element* elm_with_sel = html_doc->GetElementWithSelection())
  4284. {
  4285. if (elm_with_sel->IsFormElement())
  4286. {
  4287. if (FormObject* form_object = elm_with_sel->GetFormObject())
  4288. form_object->GetWidget()->OnCopy(clipboard);
  4289. }
  4290. #ifdef SVG_SUPPORT
  4291. else
  4292. {
  4293. g_svg_manager->Copy(elm_with_sel, clipboard);
  4294. }
  4295. #endif // SVG_SUPPORT
  4296. }
  4297. #ifdef DOCUMENT_EDIT_SUPPORT
  4298. else if (docedit && docedit->IsFocused())
  4299. docedit->OnCopy(clipboard);
  4300. #endif // DOCUMENT_EDIT_SUPPORT
  4301. else
  4302. {
  4303. #ifndef HAS_NOTEXTSELECTION
  4304. INT32 sel_text_len = html_doc->GetSelectedTextLen();
  4305. if (sel_text_len > 0)
  4306. {
  4307. uni_char* text = OP_NEWA(uni_char, sel_text_len + 1);
  4308. if (text && doc->GetSelectedText(text, sel_text_len + 1))
  4309. {
  4310. clipboard->PlaceText(text, GetUrlContextId());
  4311. }
  4312. OP_DELETEA(text);
  4313. return;
  4314. }
  4315. #endif // HAS_NOTEXTSELECTION
  4316. #ifdef SVG_SUPPORT
  4317. if (LogicalDocument* logdoc = doc->GetLogicalDocument())
  4318. {
  4319. SVGWorkplace* svg_wp = logdoc->GetSVGWorkplace();
  4320. if (svg_wp->HasSelectedText())
  4321. {
  4322. SelectionBoundaryPoint start, end;
  4323. if (svg_wp->GetSelection(start, end) && start.GetElement())
  4324. {
  4325. TempBuffer buffer;
  4326. if (g_svg_manager->GetTextSelection(start.GetElement()->ParentActual(), buffer))
  4327. {
  4328. clipboard->PlaceText(buffer.GetStorage(), GetUrlContextId());
  4329. }
  4330. }
  4331. }
  4332. }
  4333. #endif // SVG_SUPPORT
  4334. }
  4335. }
  4336. }
  4337. }
  4338. void Window::OnCut(OpClipboard* clipboard)
  4339. {
  4340. FramesDocument* doc = GetActiveFrameDoc();
  4341. if (doc)
  4342. {
  4343. HTML_Document* html_doc = doc->GetHtmlDocument();
  4344. if (html_doc)
  4345. {
  4346. if (HTML_Element* elm_with_sel = html_doc->GetElementWithSelection())
  4347. {
  4348. if (elm_with_sel->IsFormElement())
  4349. {
  4350. if (FormObject* form_object = elm_with_sel->GetFormObject())
  4351. form_object->GetWidget()->OnCut(clipboard);
  4352. }
  4353. #ifdef SVG_SUPPORT
  4354. else
  4355. {
  4356. g_svg_manager->Cut(elm_with_sel, clipboard);
  4357. }
  4358. #endif // SVG_SUPPORT
  4359. }
  4360. #ifdef DOCUMENT_EDIT_SUPPORT
  4361. else if (OpDocumentEdit* docedit = doc->GetDocumentEdit())
  4362. docedit->OnCut(clipboard);
  4363. #endif // DOCUMENT_EDIT_SUPPORT
  4364. }
  4365. }
  4366. }
  4367. void Window::OnPaste(OpClipboard* clipboard)
  4368. {
  4369. FramesDocument* doc = GetActiveFrameDoc();
  4370. if (doc)
  4371. {
  4372. HTML_Document* html_doc = doc->GetHtmlDocument();
  4373. if (html_doc)
  4374. {
  4375. if (HTML_Element* elm_with_sel = html_doc->GetElementWithSelection())
  4376. {
  4377. if (elm_with_sel->IsFormElement())
  4378. {
  4379. if (FormObject* form_object = elm_with_sel->GetFormObject())
  4380. form_object->GetWidget()->OnPaste(clipboard);
  4381. }
  4382. #ifdef SVG_SUPPORT
  4383. else
  4384. {
  4385. g_svg_manager->Paste(elm_with_sel, clipboard);
  4386. }
  4387. #endif // SVG_SUPPORT
  4388. }
  4389. #ifdef DOCUMENT_EDIT_SUPPORT
  4390. else if (OpDocumentEdit* docedit = doc->GetDocumentEdit())
  4391. docedit->OnPaste(clipboard);
  4392. #endif // DOCUMENT_EDIT_SUPPORT
  4393. }
  4394. }
  4395. }
  4396. void Window::OnEnd()
  4397. {
  4398. FramesDocument* doc = GetActiveFrameDoc();
  4399. if (doc)
  4400. {
  4401. HTML_Document* html_doc = doc->GetHtmlDocument();
  4402. if (html_doc)
  4403. {
  4404. if (HTML_Element* elm_with_sel = html_doc->GetElementWithSelection())
  4405. {
  4406. if (elm_with_sel->IsFormElement())
  4407. {
  4408. if (FormObject* form_object = elm_with_sel->GetFormObject())
  4409. form_object->GetWidget()->OnEnd();
  4410. }
  4411. #ifdef SVG_SUPPORT
  4412. else
  4413. {
  4414. g_svg_manager->ClipboardOperationEnd(elm_with_sel);
  4415. }
  4416. #endif // SVG_SUPPORT
  4417. }
  4418. #ifdef DOCUMENT_EDIT_SUPPORT
  4419. else if (OpDocumentEdit* docedit = doc->GetDocumentEdit())
  4420. docedit->OnEnd();
  4421. #endif // DOCUMENT_EDIT_SUPPORT
  4422. }
  4423. }
  4424. }
  4425. #endif // USE_OP_CLIPBOARD
  4426. #ifdef KEYBOARD_SELECTION_SUPPORT
  4427. void Window::UpdateKeyboardSelectionMode(BOOL enabled)
  4428. {
  4429. if (enabled != m_current_keyboard_selection_mode)
  4430. {
  4431. GetWindowCommander()->GetDocumentListener()->OnKeyboardSelectionModeChanged(GetWindowCommander(), enabled);
  4432. m_current_keyboard_selection_mode = enabled;
  4433. }
  4434. }
  4435. #endif // KEYBOARD_SELECTION_SUPPORT
  4436. #ifdef EXTENSION_SUPPORT
  4437. OP_STATUS
  4438. Window::GetDisallowedScreenshotVisualDevices(FramesDocument* target_document, FramesDocument* source_document, OpVector<VisualDevice>& visdevs_to_hide)
  4439. {
  4440. OpGadget* source_gadget = source_document->GetWindow()->GetGadget();
  4441. OP_ASSERT(source_gadget); // only extensions have access to taking a screenshot atm.
  4442. DocumentTreeIterator it(target_document);
  4443. for (BOOL have_more = it.Next(); have_more; have_more = it.Next())
  4444. {
  4445. FramesDocElm* elem = it.GetFramesDocElm();
  4446. VisualDevice* visdev = elem->GetVisualDevice();
  4447. BOOL allowed;
  4448. OpSecurityState state;
  4449. RETURN_IF_ERROR(g_secman_instance->CheckSecurity(OpSecurityManager::DOM_EXTENSION_ALLOW,
  4450. OpSecurityContext(elem->GetCurrentDoc()),
  4451. OpSecurityContext(elem->GetCurrentDoc()->GetSecurityContext(), source_gadget),
  4452. allowed, state));
  4453. OP_ASSERT(!state.suspended);
  4454. if (!allowed)
  4455. RETURN_IF_ERROR(visdevs_to_hide.Add(visdev));
  4456. }
  4457. return OpStatus::OK;
  4458. }
  4459. OP_STATUS
  4460. Window::PerformScreenshot(FramesDocument* target_document, FramesDocument* source_document, OpBitmap*& out_bitmap)
  4461. {
  4462. VisualDevice* vis_dev = target_document->GetVisualDevice();
  4463. if (!vis_dev)
  4464. return OpStatus::ERR;
  4465. OpVector<VisualDevice> visdevs_to_hide;
  4466. RETURN_IF_ERROR(GetDisallowedScreenshotVisualDevices(target_document, source_document, visdevs_to_hide));
  4467. OpRect rendering_rect = OpRect(0, 0, vis_dev->GetRenderingViewWidth(), vis_dev->GetRenderingViewHeight());
  4468. OpBitmap* bitmap = NULL;
  4469. RETURN_IF_ERROR(OpBitmap::Create(&bitmap, rendering_rect.width, rendering_rect.height,
  4470. FALSE, FALSE, 0, 0, TRUE));
  4471. OpPainter* painter = bitmap->GetPainter();
  4472. if (painter)
  4473. {
  4474. painter->SetColor(0, 0, 0, 0);
  4475. painter->ClearRect(rendering_rect);
  4476. vis_dev->PaintWithExclusion(painter, rendering_rect, visdevs_to_hide);
  4477. bitmap->ReleasePainter();
  4478. out_bitmap = bitmap;
  4479. return OpStatus::OK;
  4480. }
  4481. else
  4482. {
  4483. OP_DELETE(bitmap);
  4484. return OpStatus::ERR;
  4485. }
  4486. }
  4487. #endif // EXTENSION_SUPPORT