ContentParent.cpp 139 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "mozilla/DebugOnly.h"
  6. #include "base/basictypes.h"
  7. #include "ContentParent.h"
  8. #include "TabParent.h"
  9. #if defined(LINUX)
  10. # include <sys/time.h>
  11. # include <sys/resource.h>
  12. #endif
  13. #include "chrome/common/process_watcher.h"
  14. #include "mozilla/a11y/PDocAccessible.h"
  15. #include "AppProcessChecker.h"
  16. #include "AudioChannelService.h"
  17. #include "BlobParent.h"
  18. #include "GMPServiceParent.h"
  19. #include "HandlerServiceParent.h"
  20. #include "IHistory.h"
  21. #include "imgIContainer.h"
  22. #include "mozIApplication.h"
  23. #if defined(XP_WIN) && defined(ACCESSIBILITY)
  24. #include "mozilla/a11y/AccessibleWrap.h"
  25. #endif
  26. #include "mozilla/ClearOnShutdown.h"
  27. #include "mozilla/StyleSheetInlines.h"
  28. #include "mozilla/DataStorage.h"
  29. #include "mozilla/devtools/HeapSnapshotTempFileHelperParent.h"
  30. #include "mozilla/docshell/OfflineCacheUpdateParent.h"
  31. #include "mozilla/dom/DataTransfer.h"
  32. #include "mozilla/dom/DOMStorageIPC.h"
  33. #include "mozilla/dom/Element.h"
  34. #include "mozilla/dom/File.h"
  35. #include "mozilla/dom/FileSystemSecurity.h"
  36. #include "mozilla/dom/ExternalHelperAppParent.h"
  37. #include "mozilla/dom/GetFilesHelper.h"
  38. #include "mozilla/dom/GeolocationBinding.h"
  39. #include "mozilla/dom/Notification.h"
  40. #include "mozilla/dom/PContentBridgeParent.h"
  41. #include "mozilla/dom/PContentPermissionRequestParent.h"
  42. #include "mozilla/dom/PCycleCollectWithLogsParent.h"
  43. #include "mozilla/dom/PMemoryReportRequestParent.h"
  44. #include "mozilla/dom/ServiceWorkerRegistrar.h"
  45. #include "mozilla/dom/power/PowerManagerService.h"
  46. #include "mozilla/dom/Permissions.h"
  47. #include "mozilla/dom/PushNotifier.h"
  48. #include "mozilla/dom/quota/QuotaManagerService.h"
  49. #include "mozilla/dom/time/DateCacheCleaner.h"
  50. #include "mozilla/embedding/printingui/PrintingParent.h"
  51. #include "mozilla/gfx/gfxVars.h"
  52. #include "mozilla/gfx/GPUProcessManager.h"
  53. #include "mozilla/hal_sandbox/PHalParent.h"
  54. #include "mozilla/ipc/BackgroundChild.h"
  55. #include "mozilla/ipc/BackgroundParent.h"
  56. #include "mozilla/ipc/FileDescriptorUtils.h"
  57. #include "mozilla/ipc/PSendStreamParent.h"
  58. #include "mozilla/ipc/TestShellParent.h"
  59. #include "mozilla/ipc/InputStreamUtils.h"
  60. #include "mozilla/jsipc/CrossProcessObjectWrappers.h"
  61. #include "mozilla/layers/PAPZParent.h"
  62. #include "mozilla/layers/CompositorThread.h"
  63. #include "mozilla/layers/ImageBridgeParent.h"
  64. #include "mozilla/layers/LayerTreeOwnerTracker.h"
  65. #include "mozilla/layout/RenderFrameParent.h"
  66. #include "mozilla/LookAndFeel.h"
  67. #include "mozilla/media/MediaParent.h"
  68. #include "mozilla/Move.h"
  69. #include "mozilla/net/NeckoParent.h"
  70. #include "mozilla/plugins/PluginBridge.h"
  71. #include "mozilla/Preferences.h"
  72. #include "mozilla/ProcessHangMonitor.h"
  73. #include "mozilla/ProcessHangMonitorIPC.h"
  74. #include "mozilla/ScopeExit.h"
  75. #include "mozilla/Services.h"
  76. #include "mozilla/StaticPtr.h"
  77. #include "mozilla/WebBrowserPersistDocumentParent.h"
  78. #include "mozilla/Unused.h"
  79. #include "nsAnonymousTemporaryFile.h"
  80. #include "nsAppRunner.h"
  81. #include "nsCDefaultURIFixup.h"
  82. #include "nsCExternalHandlerService.h"
  83. #include "nsCOMPtr.h"
  84. #include "nsChromeRegistryChrome.h"
  85. #include "nsConsoleMessage.h"
  86. #include "nsConsoleService.h"
  87. #include "nsContentUtils.h"
  88. #include "nsDebugImpl.h"
  89. #include "nsFrameMessageManager.h"
  90. #include "nsHashPropertyBag.h"
  91. #include "nsIAlertsService.h"
  92. #include "nsIAppsService.h"
  93. #include "nsIClipboard.h"
  94. #include "nsContentPermissionHelper.h"
  95. #include "nsICycleCollectorListener.h"
  96. #include "nsIDocShellTreeOwner.h"
  97. #include "nsIDocument.h"
  98. #include "nsIDOMGeoGeolocation.h"
  99. #include "nsIDOMGeoPositionError.h"
  100. #include "nsIDragService.h"
  101. #include "mozilla/dom/WakeLock.h"
  102. #include "nsIDOMWindow.h"
  103. #include "nsIExternalProtocolService.h"
  104. #include "nsIFormProcessor.h"
  105. #include "nsIFrameLoader.h"
  106. #include "nsIGfxInfo.h"
  107. #include "nsIIdleService.h"
  108. #include "nsIInterfaceRequestorUtils.h"
  109. #include "nsIMemoryInfoDumper.h"
  110. #include "nsIMemoryReporter.h"
  111. #include "nsIMozBrowserFrame.h"
  112. #include "nsIMutable.h"
  113. #include "nsINSSU2FToken.h"
  114. #include "nsIObserverService.h"
  115. #include "nsIParentChannel.h"
  116. #include "nsIPresShell.h"
  117. #include "nsIRemoteWindowContext.h"
  118. #include "nsIScriptError.h"
  119. #include "nsIScriptSecurityManager.h"
  120. #include "nsISiteSecurityService.h"
  121. #include "nsISpellChecker.h"
  122. #include "nsISupportsPrimitives.h"
  123. #include "nsITimer.h"
  124. #include "nsIURIFixup.h"
  125. #include "nsIDocShellTreeOwner.h"
  126. #include "nsIXULWindow.h"
  127. #include "nsIDOMChromeWindow.h"
  128. #include "nsIWindowWatcher.h"
  129. #include "nsPIWindowWatcher.h"
  130. #include "nsWindowWatcher.h"
  131. #include "nsIXULRuntime.h"
  132. #include "mozilla/dom/nsMixedContentBlocker.h"
  133. #include "nsMemoryInfoDumper.h"
  134. #include "nsMemoryReporterManager.h"
  135. #include "nsServiceManagerUtils.h"
  136. #include "nsStyleSheetService.h"
  137. #include "nsThreadUtils.h"
  138. #include "nsToolkitCompsCID.h"
  139. #include "nsWidgetsCID.h"
  140. #include "PreallocatedProcessManager.h"
  141. #include "ProcessPriorityManager.h"
  142. #include "SandboxHal.h"
  143. #include "ScreenManagerParent.h"
  144. #include "SourceSurfaceRawData.h"
  145. #include "TabParent.h"
  146. #include "URIUtils.h"
  147. #include "nsIWebBrowserChrome.h"
  148. #include "nsIDocShell.h"
  149. #include "nsDocShell.h"
  150. #include "nsOpenURIInFrameParams.h"
  151. #include "mozilla/net/NeckoMessageUtils.h"
  152. #include "gfxPrefs.h"
  153. #include "prio.h"
  154. #include "private/pprio.h"
  155. #include "ContentProcessManager.h"
  156. #include "mozilla/dom/ipc/StructuredCloneData.h"
  157. #include "mozilla/psm/PSMContentListener.h"
  158. #include "nsPluginHost.h"
  159. #include "nsPluginTags.h"
  160. #include "nsIBlocklistService.h"
  161. #include "mozilla/StyleSheet.h"
  162. #include "mozilla/StyleSheetInlines.h"
  163. #include "nsHostObjectProtocolHandler.h"
  164. #include "nsICaptivePortalService.h"
  165. #include "nsIBidiKeyboard.h"
  166. #include "nsLayoutStylesheetCache.h"
  167. #ifdef MOZ_WEBRTC
  168. #include "signaling/src/peerconnection/WebrtcGlobalParent.h"
  169. #endif
  170. #if defined(LINUX)
  171. #include "nsSystemInfo.h"
  172. #endif
  173. #if defined(XP_LINUX)
  174. #include "mozilla/Hal.h"
  175. #endif
  176. #ifdef MOZ_PERMISSIONS
  177. # include "nsPermissionManager.h"
  178. #endif
  179. #ifdef MOZ_WIDGET_GTK
  180. #include <gdk/gdk.h>
  181. #endif
  182. #include "mozilla/RemoteSpellCheckEngineParent.h"
  183. #include "Crypto.h"
  184. #ifdef MOZ_WEBSPEECH
  185. #include "mozilla/dom/SpeechSynthesisParent.h"
  186. #endif
  187. #ifdef MOZ_TOOLKIT_SEARCH
  188. #include "nsIBrowserSearchService.h"
  189. #endif
  190. #ifdef XP_WIN
  191. #include "mozilla/widget/AudioSession.h"
  192. #endif
  193. #ifdef ACCESSIBILITY
  194. #include "nsAccessibilityService.h"
  195. #endif
  196. // For VP9Benchmark::sBenchmarkFpsPref
  197. #include "Benchmark.h"
  198. static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
  199. using base::ChildPrivileges;
  200. using base::KillProcess;
  201. using namespace mozilla::dom;
  202. using namespace mozilla::dom::power;
  203. using namespace mozilla::media;
  204. using namespace mozilla::embedding;
  205. using namespace mozilla::gfx;
  206. using namespace mozilla::gmp;
  207. using namespace mozilla::hal;
  208. using namespace mozilla::ipc;
  209. using namespace mozilla::layers;
  210. using namespace mozilla::layout;
  211. using namespace mozilla::net;
  212. using namespace mozilla::jsipc;
  213. using namespace mozilla::psm;
  214. using namespace mozilla::widget;
  215. // XXX Workaround for bug 986973 to maintain the existing broken semantics
  216. template<>
  217. struct nsIConsoleService::COMTypeInfo<nsConsoleService, void> {
  218. static const nsIID kIID;
  219. };
  220. const nsIID nsIConsoleService::COMTypeInfo<nsConsoleService, void>::kIID = NS_ICONSOLESERVICE_IID;
  221. namespace mozilla {
  222. namespace dom {
  223. #define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline"
  224. #define NS_IPC_IOSERVICE_SET_CONNECTIVITY_TOPIC "ipc:network:set-connectivity"
  225. class MemoryReportRequestParent : public PMemoryReportRequestParent
  226. {
  227. public:
  228. explicit MemoryReportRequestParent(uint32_t aGeneration);
  229. virtual ~MemoryReportRequestParent();
  230. virtual void ActorDestroy(ActorDestroyReason aWhy) override;
  231. virtual bool RecvReport(const MemoryReport& aReport) override;
  232. virtual bool Recv__delete__() override;
  233. private:
  234. const uint32_t mGeneration;
  235. // Non-null if we haven't yet called EndProcessReport() on it.
  236. RefPtr<nsMemoryReporterManager> mReporterManager;
  237. ContentParent* Owner()
  238. {
  239. return static_cast<ContentParent*>(Manager());
  240. }
  241. };
  242. MemoryReportRequestParent::MemoryReportRequestParent(uint32_t aGeneration)
  243. : mGeneration(aGeneration)
  244. {
  245. MOZ_COUNT_CTOR(MemoryReportRequestParent);
  246. mReporterManager = nsMemoryReporterManager::GetOrCreate();
  247. NS_WARNING_ASSERTION(mReporterManager, "GetOrCreate failed");
  248. }
  249. bool
  250. MemoryReportRequestParent::RecvReport(const MemoryReport& aReport)
  251. {
  252. if (mReporterManager) {
  253. mReporterManager->HandleChildReport(mGeneration, aReport);
  254. }
  255. return true;
  256. }
  257. bool
  258. MemoryReportRequestParent::Recv__delete__()
  259. {
  260. // Notifying the reporter manager is done in ActorDestroy, because
  261. // it needs to happen even if the child process exits mid-report.
  262. // (The reporter manager will time out eventually, but let's avoid
  263. // that if possible.)
  264. return true;
  265. }
  266. void
  267. MemoryReportRequestParent::ActorDestroy(ActorDestroyReason aWhy)
  268. {
  269. if (mReporterManager) {
  270. mReporterManager->EndProcessReport(mGeneration, aWhy == Deletion);
  271. mReporterManager = nullptr;
  272. }
  273. }
  274. MemoryReportRequestParent::~MemoryReportRequestParent()
  275. {
  276. MOZ_ASSERT(!mReporterManager);
  277. MOZ_COUNT_DTOR(MemoryReportRequestParent);
  278. }
  279. // IPC receiver for remote GC/CC logging.
  280. class CycleCollectWithLogsParent final : public PCycleCollectWithLogsParent
  281. {
  282. public:
  283. ~CycleCollectWithLogsParent()
  284. {
  285. MOZ_COUNT_DTOR(CycleCollectWithLogsParent);
  286. }
  287. static bool AllocAndSendConstructor(ContentParent* aManager,
  288. bool aDumpAllTraces,
  289. nsICycleCollectorLogSink* aSink,
  290. nsIDumpGCAndCCLogsCallback* aCallback)
  291. {
  292. CycleCollectWithLogsParent *actor;
  293. FILE* gcLog;
  294. FILE* ccLog;
  295. nsresult rv;
  296. actor = new CycleCollectWithLogsParent(aSink, aCallback);
  297. rv = actor->mSink->Open(&gcLog, &ccLog);
  298. if (NS_WARN_IF(NS_FAILED(rv))) {
  299. delete actor;
  300. return false;
  301. }
  302. return aManager->
  303. SendPCycleCollectWithLogsConstructor(actor,
  304. aDumpAllTraces,
  305. FILEToFileDescriptor(gcLog),
  306. FILEToFileDescriptor(ccLog));
  307. }
  308. private:
  309. virtual bool RecvCloseGCLog() override
  310. {
  311. Unused << mSink->CloseGCLog();
  312. return true;
  313. }
  314. virtual bool RecvCloseCCLog() override
  315. {
  316. Unused << mSink->CloseCCLog();
  317. return true;
  318. }
  319. virtual bool Recv__delete__() override
  320. {
  321. // Report completion to mCallback only on successful
  322. // completion of the protocol.
  323. nsCOMPtr<nsIFile> gcLog, ccLog;
  324. mSink->GetGcLog(getter_AddRefs(gcLog));
  325. mSink->GetCcLog(getter_AddRefs(ccLog));
  326. Unused << mCallback->OnDump(gcLog, ccLog, /* parent = */ false);
  327. return true;
  328. }
  329. virtual void ActorDestroy(ActorDestroyReason aReason) override
  330. {
  331. // If the actor is unexpectedly destroyed, we deliberately
  332. // don't call Close[GC]CLog on the sink, because the logs may
  333. // be incomplete. See also the nsCycleCollectorLogSinkToFile
  334. // implementaiton of those methods, and its destructor.
  335. }
  336. CycleCollectWithLogsParent(nsICycleCollectorLogSink *aSink,
  337. nsIDumpGCAndCCLogsCallback *aCallback)
  338. : mSink(aSink), mCallback(aCallback)
  339. {
  340. MOZ_COUNT_CTOR(CycleCollectWithLogsParent);
  341. }
  342. nsCOMPtr<nsICycleCollectorLogSink> mSink;
  343. nsCOMPtr<nsIDumpGCAndCCLogsCallback> mCallback;
  344. };
  345. // A memory reporter for ContentParent objects themselves.
  346. class ContentParentsMemoryReporter final : public nsIMemoryReporter
  347. {
  348. ~ContentParentsMemoryReporter() {}
  349. public:
  350. NS_DECL_ISUPPORTS
  351. NS_DECL_NSIMEMORYREPORTER
  352. };
  353. NS_IMPL_ISUPPORTS(ContentParentsMemoryReporter, nsIMemoryReporter)
  354. NS_IMETHODIMP
  355. ContentParentsMemoryReporter::CollectReports(
  356. nsIHandleReportCallback* aHandleReport,
  357. nsISupports* aData,
  358. bool aAnonymize)
  359. {
  360. AutoTArray<ContentParent*, 16> cps;
  361. ContentParent::GetAllEvenIfDead(cps);
  362. for (uint32_t i = 0; i < cps.Length(); i++) {
  363. ContentParent* cp = cps[i];
  364. MessageChannel* channel = cp->GetIPCChannel();
  365. nsString friendlyName;
  366. cp->FriendlyName(friendlyName, aAnonymize);
  367. cp->AddRef();
  368. nsrefcnt refcnt = cp->Release();
  369. const char* channelStr = "no channel";
  370. uint32_t numQueuedMessages = 0;
  371. if (channel) {
  372. if (channel->Unsound_IsClosed()) {
  373. channelStr = "closed channel";
  374. } else {
  375. channelStr = "open channel";
  376. }
  377. numQueuedMessages = channel->Unsound_NumQueuedMessages();
  378. }
  379. nsPrintfCString path("queued-ipc-messages/content-parent"
  380. "(%s, pid=%d, %s, 0x%p, refcnt=%d)",
  381. NS_ConvertUTF16toUTF8(friendlyName).get(),
  382. cp->Pid(), channelStr,
  383. static_cast<nsIContentParent*>(cp), refcnt);
  384. NS_NAMED_LITERAL_CSTRING(desc,
  385. "The number of unset IPC messages held in this ContentParent's "
  386. "channel. A large value here might indicate that we're leaking "
  387. "messages. Similarly, a ContentParent object for a process that's no "
  388. "longer running could indicate that we're leaking ContentParents.");
  389. aHandleReport->Callback(/* process */ EmptyCString(), path,
  390. KIND_OTHER, UNITS_COUNT,
  391. numQueuedMessages, desc, aData);
  392. }
  393. return NS_OK;
  394. }
  395. nsDataHashtable<nsStringHashKey, ContentParent*>* ContentParent::sAppContentParents;
  396. nsTArray<ContentParent*>* ContentParent::sNonAppContentParents;
  397. nsTArray<ContentParent*>* ContentParent::sLargeAllocationContentParents;
  398. nsTArray<ContentParent*>* ContentParent::sPrivateContent;
  399. StaticAutoPtr<LinkedList<ContentParent> > ContentParent::sContentParents;
  400. // This is true when subprocess launching is enabled. This is the
  401. // case between StartUp() and ShutDown() or JoinAllSubprocesses().
  402. static bool sCanLaunchSubprocesses;
  403. // Set to true if the DISABLE_UNSAFE_CPOW_WARNINGS environment variable is
  404. // set.
  405. static bool sDisableUnsafeCPOWWarnings = false;
  406. // The first content child has ID 1, so the chrome process can have ID 0.
  407. static uint64_t gContentChildID = 1;
  408. // We want the prelaunched process to know that it's for apps, but not
  409. // actually for any app in particular. Use a magic manifest URL.
  410. // Can't be a static constant.
  411. #define MAGIC_PREALLOCATED_APP_MANIFEST_URL NS_LITERAL_STRING("{{template}}")
  412. static const char* sObserverTopics[] = {
  413. "xpcom-shutdown",
  414. "profile-before-change",
  415. NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC,
  416. NS_IPC_IOSERVICE_SET_CONNECTIVITY_TOPIC,
  417. NS_IPC_CAPTIVE_PORTAL_SET_STATE,
  418. "memory-pressure",
  419. "child-gc-request",
  420. "child-cc-request",
  421. "child-mmu-request",
  422. "last-pb-context-exited",
  423. "file-watcher-update",
  424. #ifdef ACCESSIBILITY
  425. "a11y-init-or-shutdown",
  426. #endif
  427. "cacheservice:empty-cache",
  428. };
  429. // PreallocateAppProcess is called by the PreallocatedProcessManager.
  430. // ContentParent then takes this process back within
  431. // GetNewOrPreallocatedAppProcess.
  432. /*static*/ already_AddRefed<ContentParent>
  433. ContentParent::PreallocateAppProcess()
  434. {
  435. RefPtr<ContentParent> process =
  436. new ContentParent(/* app = */ nullptr,
  437. /* aOpener = */ nullptr,
  438. /* isForBrowserElement = */ false,
  439. /* isForPreallocated = */ true);
  440. if (!process->LaunchSubprocess(PROCESS_PRIORITY_PREALLOC)) {
  441. return nullptr;
  442. }
  443. process->Init();
  444. return process.forget();
  445. }
  446. /*static*/ already_AddRefed<ContentParent>
  447. ContentParent::GetNewOrPreallocatedAppProcess(mozIApplication* aApp,
  448. ProcessPriority aInitialPriority,
  449. ContentParent* aOpener,
  450. /*out*/ bool* aTookPreAllocated)
  451. {
  452. MOZ_ASSERT(aApp);
  453. RefPtr<ContentParent> process = PreallocatedProcessManager::Take();
  454. if (process) {
  455. if (!process->SetPriorityAndCheckIsAlive(aInitialPriority)) {
  456. // Kill the process just in case it's not actually dead; we don't want
  457. // to "leak" this process!
  458. process->KillHard("GetNewOrPreallocatedAppProcess");
  459. }
  460. else {
  461. nsAutoString manifestURL;
  462. if (NS_FAILED(aApp->GetManifestURL(manifestURL))) {
  463. NS_ERROR("Failed to get manifest URL");
  464. return nullptr;
  465. }
  466. process->TransformPreallocatedIntoApp(aOpener, manifestURL);
  467. process->ForwardKnownInfo();
  468. if (aTookPreAllocated) {
  469. *aTookPreAllocated = true;
  470. }
  471. return process.forget();
  472. }
  473. }
  474. NS_WARNING("Unable to use pre-allocated app process");
  475. process = new ContentParent(aApp,
  476. /* aOpener = */ aOpener,
  477. /* isForBrowserElement = */ false,
  478. /* isForPreallocated = */ false);
  479. if (!process->LaunchSubprocess(aInitialPriority)) {
  480. return nullptr;
  481. }
  482. process->Init();
  483. process->ForwardKnownInfo();
  484. if (aTookPreAllocated) {
  485. *aTookPreAllocated = false;
  486. }
  487. return process.forget();
  488. }
  489. /*static*/ void
  490. ContentParent::StartUp()
  491. {
  492. // We could launch sub processes from content process
  493. // FIXME Bug 1023701 - Stop using ContentParent static methods in
  494. // child process
  495. sCanLaunchSubprocesses = true;
  496. if (!XRE_IsParentProcess()) {
  497. return;
  498. }
  499. // Note: This reporter measures all ContentParents.
  500. RegisterStrongMemoryReporter(new ContentParentsMemoryReporter());
  501. mozilla::dom::time::InitializeDateCacheCleaner();
  502. BlobParent::Startup(BlobParent::FriendKey());
  503. BackgroundChild::Startup();
  504. // Try to preallocate a process that we can transform into an app later.
  505. PreallocatedProcessManager::AllocateAfterDelay();
  506. sDisableUnsafeCPOWWarnings = PR_GetEnv("DISABLE_UNSAFE_CPOW_WARNINGS");
  507. }
  508. /*static*/ void
  509. ContentParent::ShutDown()
  510. {
  511. // No-op for now. We rely on normal process shutdown and
  512. // ClearOnShutdown() to clean up our state.
  513. sCanLaunchSubprocesses = false;
  514. }
  515. /*static*/ void
  516. ContentParent::JoinProcessesIOThread(const nsTArray<ContentParent*>* aProcesses,
  517. Monitor* aMonitor, bool* aDone)
  518. {
  519. const nsTArray<ContentParent*>& processes = *aProcesses;
  520. for (uint32_t i = 0; i < processes.Length(); ++i) {
  521. if (GeckoChildProcessHost* process = processes[i]->mSubprocess) {
  522. process->Join();
  523. }
  524. }
  525. {
  526. MonitorAutoLock lock(*aMonitor);
  527. *aDone = true;
  528. lock.Notify();
  529. }
  530. // Don't touch any arguments to this function from now on.
  531. }
  532. /*static*/ void
  533. ContentParent::JoinAllSubprocesses()
  534. {
  535. MOZ_ASSERT(NS_IsMainThread());
  536. AutoTArray<ContentParent*, 8> processes;
  537. GetAll(processes);
  538. if (processes.IsEmpty()) {
  539. printf_stderr("There are no live subprocesses.");
  540. return;
  541. }
  542. printf_stderr("Subprocesses are still alive. Doing emergency join.\n");
  543. bool done = false;
  544. Monitor monitor("mozilla.dom.ContentParent.JoinAllSubprocesses");
  545. XRE_GetIOMessageLoop()->PostTask(NewRunnableFunction(
  546. &ContentParent::JoinProcessesIOThread,
  547. &processes, &monitor, &done));
  548. {
  549. MonitorAutoLock lock(monitor);
  550. while (!done) {
  551. lock.Wait();
  552. }
  553. }
  554. sCanLaunchSubprocesses = false;
  555. }
  556. /*static*/ already_AddRefed<ContentParent>
  557. ContentParent::GetNewOrUsedBrowserProcess(bool aForBrowserElement,
  558. ProcessPriority aPriority,
  559. ContentParent* aOpener,
  560. bool aLargeAllocationProcess)
  561. {
  562. nsTArray<ContentParent*>* contentParents;
  563. int32_t maxContentParents;
  564. // Decide which pool of content parents we are going to be pulling from based
  565. // on the aLargeAllocationProcess flag.
  566. if (aLargeAllocationProcess) {
  567. if (!sLargeAllocationContentParents) {
  568. sLargeAllocationContentParents = new nsTArray<ContentParent*>();
  569. }
  570. contentParents = sLargeAllocationContentParents;
  571. maxContentParents = Preferences::GetInt("dom.ipc.dedicatedProcessCount", 2);
  572. } else {
  573. if (!sNonAppContentParents) {
  574. sNonAppContentParents = new nsTArray<ContentParent*>();
  575. }
  576. contentParents = sNonAppContentParents;
  577. maxContentParents = Preferences::GetInt("dom.ipc.processCount", 1);
  578. }
  579. if (maxContentParents < 1) {
  580. maxContentParents = 1;
  581. }
  582. if (contentParents->Length() >= uint32_t(maxContentParents)) {
  583. uint32_t maxSelectable = std::min(static_cast<uint32_t>(contentParents->Length()),
  584. static_cast<uint32_t>(maxContentParents));
  585. uint32_t startIdx = rand() % maxSelectable;
  586. uint32_t currIdx = startIdx;
  587. do {
  588. RefPtr<ContentParent> p = (*contentParents)[currIdx];
  589. NS_ASSERTION(p->IsAlive(), "Non-alive contentparent in sNonAppContntParents?");
  590. if (p->mOpener == aOpener) {
  591. return p.forget();
  592. }
  593. currIdx = (currIdx + 1) % maxSelectable;
  594. } while (currIdx != startIdx);
  595. }
  596. // Try to take and transform the preallocated process into browser.
  597. RefPtr<ContentParent> p = PreallocatedProcessManager::Take();
  598. if (p) {
  599. p->TransformPreallocatedIntoBrowser(aOpener);
  600. } else {
  601. // Failed in using the preallocated process: fork from the chrome process.
  602. p = new ContentParent(/* app = */ nullptr,
  603. aOpener,
  604. aForBrowserElement,
  605. /* isForPreallocated = */ false);
  606. if (!p->LaunchSubprocess(aPriority)) {
  607. return nullptr;
  608. }
  609. p->Init();
  610. }
  611. p->mLargeAllocationProcess = aLargeAllocationProcess;
  612. p->ForwardKnownInfo();
  613. contentParents->AppendElement(p);
  614. return p.forget();
  615. }
  616. /*static*/ ProcessPriority
  617. ContentParent::GetInitialProcessPriority(Element* aFrameElement)
  618. {
  619. // Frames with mozapptype == critical which are expecting a system message
  620. // get FOREGROUND_HIGH priority.
  621. if (!aFrameElement) {
  622. return PROCESS_PRIORITY_FOREGROUND;
  623. }
  624. if (aFrameElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::mozapptype,
  625. NS_LITERAL_STRING("inputmethod"), eCaseMatters)) {
  626. return PROCESS_PRIORITY_FOREGROUND_KEYBOARD;
  627. } else if (!aFrameElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::mozapptype,
  628. NS_LITERAL_STRING("critical"), eCaseMatters)) {
  629. return PROCESS_PRIORITY_FOREGROUND;
  630. }
  631. nsCOMPtr<nsIMozBrowserFrame> browserFrame = do_QueryInterface(aFrameElement);
  632. if (!browserFrame) {
  633. return PROCESS_PRIORITY_FOREGROUND;
  634. }
  635. return PROCESS_PRIORITY_FOREGROUND;
  636. }
  637. #if defined(XP_WIN)
  638. extern const wchar_t* kPluginWidgetContentParentProperty;
  639. /*static*/ void
  640. ContentParent::SendAsyncUpdate(nsIWidget* aWidget)
  641. {
  642. if (!aWidget || aWidget->Destroyed()) {
  643. return;
  644. }
  645. // Fire off an async request to the plugin to paint its window
  646. HWND hwnd = (HWND)aWidget->GetNativeData(NS_NATIVE_WINDOW);
  647. NS_ASSERTION(hwnd, "Expected valid hwnd value.");
  648. ContentParent* cp = reinterpret_cast<ContentParent*>(
  649. ::GetPropW(hwnd, kPluginWidgetContentParentProperty));
  650. if (cp && !cp->IsDestroyed()) {
  651. Unused << cp->SendUpdateWindow((uintptr_t)hwnd);
  652. }
  653. }
  654. #endif // defined(XP_WIN)
  655. bool
  656. ContentParent::PreallocatedProcessReady()
  657. {
  658. return true;
  659. }
  660. bool
  661. ContentParent::RecvCreateChildProcess(const IPCTabContext& aContext,
  662. const hal::ProcessPriority& aPriority,
  663. const TabId& aOpenerTabId,
  664. ContentParentId* aCpId,
  665. bool* aIsForApp,
  666. bool* aIsForBrowser,
  667. TabId* aTabId)
  668. {
  669. #if 0
  670. if (!CanOpenBrowser(aContext)) {
  671. return false;
  672. }
  673. #endif
  674. RefPtr<ContentParent> cp;
  675. MaybeInvalidTabContext tc(aContext);
  676. if (!tc.IsValid()) {
  677. NS_ERROR(nsPrintfCString("Received an invalid TabContext from "
  678. "the child process. (%s)",
  679. tc.GetInvalidReason()).get());
  680. return false;
  681. }
  682. nsCOMPtr<mozIApplication> ownApp = tc.GetTabContext().GetOwnApp();
  683. if (ownApp) {
  684. cp = GetNewOrPreallocatedAppProcess(ownApp, aPriority, this);
  685. }
  686. else {
  687. cp = GetNewOrUsedBrowserProcess(/* isBrowserElement = */ true,
  688. aPriority, this);
  689. }
  690. if (!cp) {
  691. *aCpId = 0;
  692. *aIsForApp = false;
  693. *aIsForBrowser = false;
  694. return true;
  695. }
  696. *aCpId = cp->ChildID();
  697. *aIsForApp = cp->IsForApp();
  698. *aIsForBrowser = cp->IsForBrowser();
  699. ContentProcessManager *cpm = ContentProcessManager::GetSingleton();
  700. cpm->AddContentProcess(cp, this->ChildID());
  701. if (cpm->AddGrandchildProcess(this->ChildID(), cp->ChildID())) {
  702. // Pre-allocate a TabId here to save one time IPC call at app startup.
  703. *aTabId = AllocateTabId(aOpenerTabId, aContext, cp->ChildID());
  704. return (*aTabId != 0);
  705. }
  706. return false;
  707. }
  708. bool
  709. ContentParent::RecvBridgeToChildProcess(const ContentParentId& aCpId)
  710. {
  711. ContentProcessManager *cpm = ContentProcessManager::GetSingleton();
  712. ContentParent* cp = cpm->GetContentProcessById(aCpId);
  713. if (cp) {
  714. ContentParentId parentId;
  715. if (cpm->GetParentProcessId(cp->ChildID(), &parentId) &&
  716. parentId == this->ChildID()) {
  717. return NS_SUCCEEDED(PContentBridge::Bridge(this, cp));
  718. }
  719. }
  720. // You can't bridge to a process you didn't open!
  721. KillHard("BridgeToChildProcess");
  722. return false;
  723. }
  724. static nsIDocShell* GetOpenerDocShellHelper(Element* aFrameElement)
  725. {
  726. // Propagate the private-browsing status of the element's parent
  727. // docshell to the remote docshell, via the chrome flags.
  728. nsCOMPtr<Element> frameElement = do_QueryInterface(aFrameElement);
  729. MOZ_ASSERT(frameElement);
  730. nsPIDOMWindowOuter* win = frameElement->OwnerDoc()->GetWindow();
  731. if (!win) {
  732. NS_WARNING("Remote frame has no window");
  733. return nullptr;
  734. }
  735. nsIDocShell* docShell = win->GetDocShell();
  736. if (!docShell) {
  737. NS_WARNING("Remote frame has no docshell");
  738. return nullptr;
  739. }
  740. return docShell;
  741. }
  742. bool
  743. ContentParent::RecvCreateGMPService()
  744. {
  745. return PGMPService::Open(this);
  746. }
  747. bool
  748. ContentParent::RecvLoadPlugin(const uint32_t& aPluginId, nsresult* aRv, uint32_t* aRunID)
  749. {
  750. *aRv = NS_OK;
  751. return mozilla::plugins::SetupBridge(aPluginId, this, false, aRv, aRunID);
  752. }
  753. bool
  754. ContentParent::RecvUngrabPointer(const uint32_t& aTime)
  755. {
  756. #if !defined(MOZ_WIDGET_GTK)
  757. NS_RUNTIMEABORT("This message only makes sense on GTK platforms");
  758. return false;
  759. #else
  760. gdk_pointer_ungrab(aTime);
  761. return true;
  762. #endif
  763. }
  764. bool
  765. ContentParent::RecvRemovePermission(const IPC::Principal& aPrincipal,
  766. const nsCString& aPermissionType,
  767. nsresult* aRv) {
  768. *aRv = Permissions::RemovePermission(aPrincipal, aPermissionType.get());
  769. return true;
  770. }
  771. bool
  772. ContentParent::RecvConnectPluginBridge(const uint32_t& aPluginId, nsresult* aRv)
  773. {
  774. *aRv = NS_OK;
  775. // We don't need to get the run ID for the plugin, since we already got it
  776. // in the first call to SetupBridge in RecvLoadPlugin, so we pass in a dummy
  777. // pointer and just throw it away.
  778. uint32_t dummy = 0;
  779. return mozilla::plugins::SetupBridge(aPluginId, this, true, aRv, &dummy);
  780. }
  781. bool
  782. ContentParent::RecvGetBlocklistState(const uint32_t& aPluginId,
  783. uint32_t* aState)
  784. {
  785. *aState = nsIBlocklistService::STATE_BLOCKED;
  786. RefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
  787. if (!pluginHost) {
  788. NS_WARNING("Plugin host not found");
  789. return false;
  790. }
  791. nsPluginTag* tag = pluginHost->PluginWithId(aPluginId);
  792. if (!tag) {
  793. // Default state is blocked anyway
  794. NS_WARNING("Plugin tag not found. This should never happen, but to avoid a crash we're forcibly blocking it");
  795. return true;
  796. }
  797. return NS_SUCCEEDED(tag->GetBlocklistState(aState));
  798. }
  799. bool
  800. ContentParent::RecvFindPlugins(const uint32_t& aPluginEpoch,
  801. nsresult* aRv,
  802. nsTArray<PluginTag>* aPlugins,
  803. uint32_t* aNewPluginEpoch)
  804. {
  805. *aRv = mozilla::plugins::FindPluginsForContent(aPluginEpoch, aPlugins, aNewPluginEpoch);
  806. return true;
  807. }
  808. /*static*/ TabParent*
  809. ContentParent::CreateBrowserOrApp(const TabContext& aContext,
  810. Element* aFrameElement,
  811. ContentParent* aOpenerContentParent,
  812. bool aFreshProcess)
  813. {
  814. PROFILER_LABEL_FUNC(js::ProfileEntry::Category::OTHER);
  815. if (!sCanLaunchSubprocesses) {
  816. return nullptr;
  817. }
  818. if (TabParent* parent = TabParent::GetNextTabParent()) {
  819. parent->SetOwnerElement(aFrameElement);
  820. return parent;
  821. }
  822. ProcessPriority initialPriority = GetInitialProcessPriority(aFrameElement);
  823. bool isInContentProcess = !XRE_IsParentProcess();
  824. TabId tabId;
  825. nsIDocShell* docShell = GetOpenerDocShellHelper(aFrameElement);
  826. TabId openerTabId;
  827. if (docShell) {
  828. openerTabId = TabParent::GetTabIdFrom(docShell);
  829. }
  830. if (aContext.IsMozBrowserElement() || !aContext.HasOwnApp()) {
  831. RefPtr<nsIContentParent> constructorSender;
  832. if (isInContentProcess) {
  833. MOZ_ASSERT(aContext.IsMozBrowserElement());
  834. constructorSender = CreateContentBridgeParent(aContext, initialPriority,
  835. openerTabId, &tabId);
  836. } else {
  837. if (aOpenerContentParent) {
  838. constructorSender = aOpenerContentParent;
  839. } else {
  840. constructorSender =
  841. GetNewOrUsedBrowserProcess(aContext.IsMozBrowserElement(),
  842. initialPriority,
  843. nullptr,
  844. aFreshProcess);
  845. if (!constructorSender) {
  846. return nullptr;
  847. }
  848. }
  849. tabId = AllocateTabId(openerTabId,
  850. aContext.AsIPCTabContext(),
  851. constructorSender->ChildID());
  852. }
  853. if (constructorSender) {
  854. nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
  855. docShell->GetTreeOwner(getter_AddRefs(treeOwner));
  856. if (!treeOwner) {
  857. return nullptr;
  858. }
  859. nsCOMPtr<nsIWebBrowserChrome> wbc = do_GetInterface(treeOwner);
  860. if (!wbc) {
  861. return nullptr;
  862. }
  863. uint32_t chromeFlags = 0;
  864. wbc->GetChromeFlags(&chromeFlags);
  865. nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
  866. if (loadContext && loadContext->UsePrivateBrowsing()) {
  867. chromeFlags |= nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW;
  868. }
  869. if (docShell->GetAffectPrivateSessionLifetime()) {
  870. chromeFlags |= nsIWebBrowserChrome::CHROME_PRIVATE_LIFETIME;
  871. }
  872. if (tabId == 0) {
  873. return nullptr;
  874. }
  875. RefPtr<TabParent> tp(new TabParent(constructorSender, tabId,
  876. aContext, chromeFlags));
  877. tp->SetInitedByParent();
  878. PBrowserParent* browser =
  879. constructorSender->SendPBrowserConstructor(
  880. // DeallocPBrowserParent() releases this ref.
  881. tp.forget().take(), tabId,
  882. aContext.AsIPCTabContext(),
  883. chromeFlags,
  884. constructorSender->ChildID(),
  885. constructorSender->IsForApp(),
  886. constructorSender->IsForBrowser());
  887. if (aFreshProcess) {
  888. Unused << browser->SendSetFreshProcess();
  889. }
  890. if (browser) {
  891. RefPtr<TabParent> constructedTabParent = TabParent::GetFrom(browser);
  892. constructedTabParent->SetOwnerElement(aFrameElement);
  893. return constructedTabParent;
  894. }
  895. }
  896. return nullptr;
  897. }
  898. // If we got here, we have an app and we're not a browser element. ownApp
  899. // shouldn't be null, because we otherwise would have gone into the
  900. // !HasOwnApp() branch above.
  901. RefPtr<nsIContentParent> parent;
  902. bool reused = false;
  903. bool tookPreallocated = false;
  904. nsAutoString manifestURL;
  905. if (isInContentProcess) {
  906. parent = CreateContentBridgeParent(aContext,
  907. initialPriority,
  908. openerTabId,
  909. &tabId);
  910. }
  911. else {
  912. nsCOMPtr<mozIApplication> ownApp = aContext.GetOwnApp();
  913. if (!sAppContentParents) {
  914. sAppContentParents =
  915. new nsDataHashtable<nsStringHashKey, ContentParent*>();
  916. }
  917. // Each app gets its own ContentParent instance unless it shares it with
  918. // a parent app.
  919. if (NS_FAILED(ownApp->GetManifestURL(manifestURL))) {
  920. NS_ERROR("Failed to get manifest URL");
  921. return nullptr;
  922. }
  923. RefPtr<ContentParent> p = sAppContentParents->Get(manifestURL);
  924. if (!p && Preferences::GetBool("dom.ipc.reuse_parent_app")) {
  925. nsAutoString parentAppManifestURL;
  926. aFrameElement->GetAttr(kNameSpaceID_None,
  927. nsGkAtoms::parentapp, parentAppManifestURL);
  928. nsAdoptingString systemAppManifestURL =
  929. Preferences::GetString("b2g.system_manifest_url");
  930. nsCOMPtr<nsIAppsService> appsService =
  931. do_GetService(APPS_SERVICE_CONTRACTID);
  932. if (!parentAppManifestURL.IsEmpty() &&
  933. !parentAppManifestURL.Equals(systemAppManifestURL) &&
  934. appsService) {
  935. nsCOMPtr<mozIApplication> parentApp;
  936. nsCOMPtr<mozIApplication> app;
  937. appsService->GetAppByManifestURL(parentAppManifestURL,
  938. getter_AddRefs(parentApp));
  939. appsService->GetAppByManifestURL(manifestURL,
  940. getter_AddRefs(app));
  941. // Only let certified apps re-use the same process.
  942. unsigned short parentAppStatus = 0;
  943. unsigned short appStatus = 0;
  944. if (app &&
  945. NS_SUCCEEDED(app->GetAppStatus(&appStatus)) &&
  946. appStatus == nsIPrincipal::APP_STATUS_CERTIFIED &&
  947. parentApp &&
  948. NS_SUCCEEDED(parentApp->GetAppStatus(&parentAppStatus)) &&
  949. parentAppStatus == nsIPrincipal::APP_STATUS_CERTIFIED) {
  950. // Check if we can re-use the process of the parent app.
  951. p = sAppContentParents->Get(parentAppManifestURL);
  952. }
  953. }
  954. }
  955. if (p) {
  956. // Check that the process is still alive and set its priority.
  957. // Hopefully the process won't die after this point, if this call
  958. // succeeds.
  959. if (!p->SetPriorityAndCheckIsAlive(initialPriority)) {
  960. p = nullptr;
  961. }
  962. }
  963. reused = !!p;
  964. if (!p) {
  965. p = GetNewOrPreallocatedAppProcess(ownApp, initialPriority, nullptr,
  966. &tookPreallocated);
  967. MOZ_ASSERT(p);
  968. sAppContentParents->Put(manifestURL, p);
  969. }
  970. tabId = AllocateTabId(openerTabId, aContext.AsIPCTabContext(),
  971. p->ChildID());
  972. parent = static_cast<nsIContentParent*>(p);
  973. }
  974. if (!parent || (tabId == 0)) {
  975. return nullptr;
  976. }
  977. uint32_t chromeFlags = 0;
  978. RefPtr<TabParent> tp = new TabParent(parent, tabId, aContext, chromeFlags);
  979. tp->SetInitedByParent();
  980. PBrowserParent* browser = parent->SendPBrowserConstructor(
  981. // DeallocPBrowserParent() releases this ref.
  982. RefPtr<TabParent>(tp).forget().take(),
  983. tabId,
  984. aContext.AsIPCTabContext(),
  985. chromeFlags,
  986. parent->ChildID(),
  987. parent->IsForApp(),
  988. parent->IsForBrowser());
  989. if (aFreshProcess) {
  990. Unused << browser->SendSetFreshProcess();
  991. }
  992. if (browser) {
  993. RefPtr<TabParent> constructedTabParent = TabParent::GetFrom(browser);
  994. constructedTabParent->SetOwnerElement(aFrameElement);
  995. }
  996. if (isInContentProcess) {
  997. // Just return directly without the following check in content process.
  998. return TabParent::GetFrom(browser);
  999. }
  1000. if (!browser) {
  1001. // We failed to actually start the PBrowser. This can happen if the
  1002. // other process has already died.
  1003. if (!reused) {
  1004. // Don't leave a broken ContentParent in the hashtable.
  1005. parent->AsContentParent()->KillHard("CreateBrowserOrApp");
  1006. sAppContentParents->Remove(manifestURL);
  1007. parent = nullptr;
  1008. }
  1009. // If we took the preallocated process and it was already dead, try
  1010. // again with a non-preallocated process. We can be sure this won't
  1011. // loop forever, because the next time through there will be no
  1012. // preallocated process to take.
  1013. if (tookPreallocated) {
  1014. return ContentParent::CreateBrowserOrApp(aContext, aFrameElement,
  1015. aOpenerContentParent);
  1016. }
  1017. // Otherwise just give up.
  1018. return nullptr;
  1019. }
  1020. return TabParent::GetFrom(browser);
  1021. }
  1022. /*static*/ ContentBridgeParent*
  1023. ContentParent::CreateContentBridgeParent(const TabContext& aContext,
  1024. const hal::ProcessPriority& aPriority,
  1025. const TabId& aOpenerTabId,
  1026. /*out*/ TabId* aTabId)
  1027. {
  1028. MOZ_ASSERT(aTabId);
  1029. ContentChild* child = ContentChild::GetSingleton();
  1030. ContentParentId cpId;
  1031. bool isForApp;
  1032. bool isForBrowser;
  1033. if (!child->SendCreateChildProcess(aContext.AsIPCTabContext(),
  1034. aPriority,
  1035. aOpenerTabId,
  1036. &cpId,
  1037. &isForApp,
  1038. &isForBrowser,
  1039. aTabId)) {
  1040. return nullptr;
  1041. }
  1042. if (cpId == 0) {
  1043. return nullptr;
  1044. }
  1045. if (!child->SendBridgeToChildProcess(cpId)) {
  1046. return nullptr;
  1047. }
  1048. ContentBridgeParent* parent = child->GetLastBridge();
  1049. parent->SetChildID(cpId);
  1050. parent->SetIsForApp(isForApp);
  1051. parent->SetIsForBrowser(isForBrowser);
  1052. return parent;
  1053. }
  1054. void
  1055. ContentParent::GetAll(nsTArray<ContentParent*>& aArray)
  1056. {
  1057. aArray.Clear();
  1058. for (auto* cp : AllProcesses(eLive)) {
  1059. aArray.AppendElement(cp);
  1060. }
  1061. }
  1062. void
  1063. ContentParent::GetAllEvenIfDead(nsTArray<ContentParent*>& aArray)
  1064. {
  1065. aArray.Clear();
  1066. for (auto* cp : AllProcesses(eAll)) {
  1067. aArray.AppendElement(cp);
  1068. }
  1069. }
  1070. void
  1071. ContentParent::Init()
  1072. {
  1073. nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
  1074. if (obs) {
  1075. size_t length = ArrayLength(sObserverTopics);
  1076. for (size_t i = 0; i < length; ++i) {
  1077. obs->AddObserver(this, sObserverTopics[i], false);
  1078. }
  1079. }
  1080. Preferences::AddStrongObserver(this, "");
  1081. if (obs) {
  1082. nsAutoString cpId;
  1083. cpId.AppendInt(static_cast<uint64_t>(this->ChildID()));
  1084. obs->NotifyObservers(static_cast<nsIObserver*>(this), "ipc:content-created", cpId.get());
  1085. }
  1086. #ifdef ACCESSIBILITY
  1087. // If accessibility is running in chrome process then start it in content
  1088. // process.
  1089. if (nsIPresShell::IsAccessibilityActive()) {
  1090. #if !defined(XP_WIN)
  1091. Unused << SendActivateA11y(0);
  1092. #endif
  1093. }
  1094. #endif
  1095. RefPtr<GeckoMediaPluginServiceParent> gmps(GeckoMediaPluginServiceParent::GetSingleton());
  1096. gmps->UpdateContentProcessGMPCapabilities();
  1097. }
  1098. void
  1099. ContentParent::ForwardKnownInfo()
  1100. {
  1101. MOZ_ASSERT(mMetamorphosed);
  1102. if (!mMetamorphosed) {
  1103. return;
  1104. }
  1105. }
  1106. namespace {
  1107. class RemoteWindowContext final : public nsIRemoteWindowContext
  1108. , public nsIInterfaceRequestor
  1109. {
  1110. public:
  1111. explicit RemoteWindowContext(TabParent* aTabParent)
  1112. : mTabParent(aTabParent)
  1113. {
  1114. }
  1115. NS_DECL_ISUPPORTS
  1116. NS_DECL_NSIINTERFACEREQUESTOR
  1117. NS_DECL_NSIREMOTEWINDOWCONTEXT
  1118. private:
  1119. ~RemoteWindowContext();
  1120. RefPtr<TabParent> mTabParent;
  1121. };
  1122. NS_IMPL_ISUPPORTS(RemoteWindowContext, nsIRemoteWindowContext, nsIInterfaceRequestor)
  1123. RemoteWindowContext::~RemoteWindowContext()
  1124. {
  1125. }
  1126. NS_IMETHODIMP
  1127. RemoteWindowContext::GetInterface(const nsIID& aIID, void** aSink)
  1128. {
  1129. return QueryInterface(aIID, aSink);
  1130. }
  1131. NS_IMETHODIMP
  1132. RemoteWindowContext::OpenURI(nsIURI* aURI)
  1133. {
  1134. mTabParent->LoadURL(aURI);
  1135. return NS_OK;
  1136. }
  1137. } // namespace
  1138. bool
  1139. ContentParent::SetPriorityAndCheckIsAlive(ProcessPriority aPriority)
  1140. {
  1141. ProcessPriorityManager::SetProcessPriority(this, aPriority);
  1142. return true;
  1143. }
  1144. // Helper for ContentParent::TransformPreallocatedIntoApp.
  1145. static void
  1146. TryGetNameFromManifestURL(const nsAString& aManifestURL,
  1147. nsAString& aName)
  1148. {
  1149. aName.Truncate();
  1150. if (aManifestURL.IsEmpty() ||
  1151. aManifestURL == MAGIC_PREALLOCATED_APP_MANIFEST_URL) {
  1152. return;
  1153. }
  1154. nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
  1155. NS_ENSURE_TRUE_VOID(appsService);
  1156. nsCOMPtr<mozIApplication> app;
  1157. appsService->GetAppByManifestURL(aManifestURL, getter_AddRefs(app));
  1158. if (!app) {
  1159. return;
  1160. }
  1161. app->GetName(aName);
  1162. }
  1163. void
  1164. ContentParent::TransformPreallocatedIntoApp(ContentParent* aOpener,
  1165. const nsAString& aAppManifestURL)
  1166. {
  1167. MOZ_ASSERT(IsPreallocated());
  1168. mMetamorphosed = true;
  1169. mOpener = aOpener;
  1170. mAppManifestURL = aAppManifestURL;
  1171. TryGetNameFromManifestURL(aAppManifestURL, mAppName);
  1172. }
  1173. void
  1174. ContentParent::TransformPreallocatedIntoBrowser(ContentParent* aOpener)
  1175. {
  1176. // Reset mAppManifestURL, mIsForBrowser and mOSPrivileges for browser.
  1177. mMetamorphosed = true;
  1178. mOpener = aOpener;
  1179. mAppManifestURL.Truncate();
  1180. mIsForBrowser = true;
  1181. }
  1182. void
  1183. ContentParent::ShutDownProcess(ShutDownMethod aMethod)
  1184. {
  1185. // Shutting down by sending a shutdown message works differently than the
  1186. // other methods. We first call Shutdown() in the child. After the child is
  1187. // ready, it calls FinishShutdown() on us. Then we close the channel.
  1188. if (aMethod == SEND_SHUTDOWN_MESSAGE) {
  1189. if (mIPCOpen && !mShutdownPending && SendShutdown()) {
  1190. mShutdownPending = true;
  1191. // Start the force-kill timer if we haven't already.
  1192. StartForceKillTimer();
  1193. }
  1194. // If call was not successful, the channel must have been broken
  1195. // somehow, and we will clean up the error in ActorDestroy.
  1196. return;
  1197. }
  1198. using mozilla::dom::quota::QuotaManagerService;
  1199. if (QuotaManagerService* quotaManagerService = QuotaManagerService::Get()) {
  1200. quotaManagerService->AbortOperationsForProcess(mChildID);
  1201. }
  1202. // If Close() fails with an error, we'll end up back in this function, but
  1203. // with aMethod = CLOSE_CHANNEL_WITH_ERROR.
  1204. if (aMethod == CLOSE_CHANNEL && !mCalledClose) {
  1205. // Close() can only be called once: It kicks off the destruction
  1206. // sequence.
  1207. mCalledClose = true;
  1208. Close();
  1209. }
  1210. const ManagedContainer<POfflineCacheUpdateParent>& ocuParents =
  1211. ManagedPOfflineCacheUpdateParent();
  1212. for (auto iter = ocuParents.ConstIter(); !iter.Done(); iter.Next()) {
  1213. RefPtr<mozilla::docshell::OfflineCacheUpdateParent> ocuParent =
  1214. static_cast<mozilla::docshell::OfflineCacheUpdateParent*>(iter.Get()->GetKey());
  1215. ocuParent->StopSendingMessagesToChild();
  1216. }
  1217. // NB: must MarkAsDead() here so that this isn't accidentally
  1218. // returned from Get*() while in the midst of shutdown.
  1219. MarkAsDead();
  1220. // A ContentParent object might not get freed until after XPCOM shutdown has
  1221. // shut down the cycle collector. But by then it's too late to release any
  1222. // CC'ed objects, so we need to null them out here, while we still can. See
  1223. // bug 899761.
  1224. ShutDownMessageManager();
  1225. }
  1226. bool
  1227. ContentParent::RecvFinishShutdown()
  1228. {
  1229. // At this point, we already called ShutDownProcess once with
  1230. // SEND_SHUTDOWN_MESSAGE. To actually close the channel, we call
  1231. // ShutDownProcess again with CLOSE_CHANNEL.
  1232. MOZ_ASSERT(mShutdownPending);
  1233. ShutDownProcess(CLOSE_CHANNEL);
  1234. return true;
  1235. }
  1236. void
  1237. ContentParent::ShutDownMessageManager()
  1238. {
  1239. if (!mMessageManager) {
  1240. return;
  1241. }
  1242. mMessageManager->ReceiveMessage(
  1243. static_cast<nsIContentFrameMessageManager*>(mMessageManager.get()), nullptr,
  1244. CHILD_PROCESS_SHUTDOWN_MESSAGE, false,
  1245. nullptr, nullptr, nullptr, nullptr);
  1246. mMessageManager->Disconnect();
  1247. mMessageManager = nullptr;
  1248. }
  1249. void
  1250. ContentParent::MarkAsDead()
  1251. {
  1252. if (!mAppManifestURL.IsEmpty()) {
  1253. if (sAppContentParents) {
  1254. sAppContentParents->Remove(mAppManifestURL);
  1255. if (!sAppContentParents->Count()) {
  1256. delete sAppContentParents;
  1257. sAppContentParents = nullptr;
  1258. }
  1259. }
  1260. } else {
  1261. if (sNonAppContentParents) {
  1262. sNonAppContentParents->RemoveElement(this);
  1263. if (!sNonAppContentParents->Length()) {
  1264. delete sNonAppContentParents;
  1265. sNonAppContentParents = nullptr;
  1266. }
  1267. }
  1268. if (sLargeAllocationContentParents) {
  1269. sLargeAllocationContentParents->RemoveElement(this);
  1270. if (!sLargeAllocationContentParents->Length()) {
  1271. delete sLargeAllocationContentParents;
  1272. sLargeAllocationContentParents = nullptr;
  1273. }
  1274. }
  1275. }
  1276. if (sPrivateContent) {
  1277. sPrivateContent->RemoveElement(this);
  1278. if (!sPrivateContent->Length()) {
  1279. delete sPrivateContent;
  1280. sPrivateContent = nullptr;
  1281. }
  1282. }
  1283. mIsAlive = false;
  1284. }
  1285. void
  1286. ContentParent::OnChannelError()
  1287. {
  1288. RefPtr<ContentParent> content(this);
  1289. PContentParent::OnChannelError();
  1290. }
  1291. void
  1292. ContentParent::OnChannelConnected(int32_t pid)
  1293. {
  1294. SetOtherProcessId(pid);
  1295. #if defined(LINUX)
  1296. // Check nice preference
  1297. int32_t nice = Preferences::GetInt("dom.ipc.content.nice", 0);
  1298. // Environment variable overrides preference
  1299. char* relativeNicenessStr = getenv("MOZ_CHILD_PROCESS_RELATIVE_NICENESS");
  1300. if (relativeNicenessStr) {
  1301. nice = atoi(relativeNicenessStr);
  1302. }
  1303. /* make the GUI thread have higher priority on single-cpu devices */
  1304. nsCOMPtr<nsIPropertyBag2> infoService = do_GetService(NS_SYSTEMINFO_CONTRACTID);
  1305. if (infoService) {
  1306. int32_t cpus;
  1307. nsresult rv = infoService->GetPropertyAsInt32(NS_LITERAL_STRING("cpucount"), &cpus);
  1308. if (NS_FAILED(rv)) {
  1309. cpus = 1;
  1310. }
  1311. if (nice != 0 && cpus == 1) {
  1312. setpriority(PRIO_PROCESS, pid, getpriority(PRIO_PROCESS, pid) + nice);
  1313. }
  1314. }
  1315. #endif
  1316. }
  1317. void
  1318. ContentParent::ProcessingError(Result aCode, const char* aReason)
  1319. {
  1320. if (MsgDropped == aCode) {
  1321. return;
  1322. }
  1323. // Other errors are big deals.
  1324. KillHard(aReason);
  1325. }
  1326. /* static */
  1327. bool
  1328. ContentParent::AllocateLayerTreeId(TabParent* aTabParent, uint64_t* aId)
  1329. {
  1330. return AllocateLayerTreeId(aTabParent->Manager()->AsContentParent(),
  1331. aTabParent, aTabParent->GetTabId(), aId);
  1332. }
  1333. /* static */
  1334. bool
  1335. ContentParent::AllocateLayerTreeId(ContentParent* aContent,
  1336. TabParent* aTopLevel, const TabId& aTabId,
  1337. uint64_t* aId)
  1338. {
  1339. GPUProcessManager* gpu = GPUProcessManager::Get();
  1340. *aId = gpu->AllocateLayerTreeId();
  1341. if (!aContent || !aTopLevel) {
  1342. return false;
  1343. }
  1344. gpu->MapLayerTreeId(*aId, aContent->OtherPid());
  1345. if (!gfxPlatform::AsyncPanZoomEnabled()) {
  1346. return true;
  1347. }
  1348. return aContent->SendNotifyLayerAllocated(aTabId, *aId);
  1349. }
  1350. bool
  1351. ContentParent::RecvAllocateLayerTreeId(const ContentParentId& aCpId,
  1352. const TabId& aTabId, uint64_t* aId)
  1353. {
  1354. // Protect against spoofing by a compromised child. aCpId must either
  1355. // correspond to the process that this ContentParent represents or be a
  1356. // child of it.
  1357. ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
  1358. if (ChildID() != aCpId) {
  1359. ContentParentId parent;
  1360. if (!cpm->GetParentProcessId(aCpId, &parent) ||
  1361. ChildID() != parent) {
  1362. return false;
  1363. }
  1364. }
  1365. // GetTopLevelTabParentByProcessAndTabId will make sure that aTabId
  1366. // lives in the process for aCpId.
  1367. RefPtr<ContentParent> contentParent = cpm->GetContentProcessById(aCpId);
  1368. RefPtr<TabParent> browserParent =
  1369. cpm->GetTopLevelTabParentByProcessAndTabId(aCpId, aTabId);
  1370. MOZ_ASSERT(contentParent && browserParent);
  1371. return AllocateLayerTreeId(contentParent, browserParent, aTabId, aId);
  1372. }
  1373. bool
  1374. ContentParent::RecvDeallocateLayerTreeId(const uint64_t& aId)
  1375. {
  1376. GPUProcessManager* gpu = GPUProcessManager::Get();
  1377. if (!gpu->IsLayerTreeIdMapped(aId, OtherPid()))
  1378. {
  1379. // You can't deallocate layer tree ids that you didn't allocate
  1380. KillHard("DeallocateLayerTreeId");
  1381. }
  1382. gpu->UnmapLayerTreeId(aId, OtherPid());
  1383. return true;
  1384. }
  1385. namespace {
  1386. void
  1387. DelayedDeleteSubprocess(GeckoChildProcessHost* aSubprocess)
  1388. {
  1389. RefPtr<DeleteTask<GeckoChildProcessHost>> task = new DeleteTask<GeckoChildProcessHost>(aSubprocess);
  1390. XRE_GetIOMessageLoop()->PostTask(task.forget());
  1391. }
  1392. // This runnable only exists to delegate ownership of the
  1393. // ContentParent to this runnable, until it's deleted by the event
  1394. // system.
  1395. struct DelayedDeleteContentParentTask : public Runnable
  1396. {
  1397. explicit DelayedDeleteContentParentTask(ContentParent* aObj) : mObj(aObj) { }
  1398. // No-op
  1399. NS_IMETHOD Run() override { return NS_OK; }
  1400. RefPtr<ContentParent> mObj;
  1401. };
  1402. } // namespace
  1403. void
  1404. ContentParent::ActorDestroy(ActorDestroyReason why)
  1405. {
  1406. if (mForceKillTimer) {
  1407. mForceKillTimer->Cancel();
  1408. mForceKillTimer = nullptr;
  1409. }
  1410. // Signal shutdown completion regardless of error state, so we can
  1411. // finish waiting in the xpcom-shutdown/profile-before-change observer.
  1412. mIPCOpen = false;
  1413. if (mHangMonitorActor) {
  1414. ProcessHangMonitor::RemoveProcess(mHangMonitorActor);
  1415. mHangMonitorActor = nullptr;
  1416. }
  1417. RefPtr<FileSystemSecurity> fss = FileSystemSecurity::Get();
  1418. if (fss) {
  1419. fss->Forget(ChildID());
  1420. }
  1421. if (why == NormalShutdown && !mCalledClose) {
  1422. // If we shut down normally but haven't called Close, assume somebody
  1423. // else called Close on us. In that case, we still need to call
  1424. // ShutDownProcess below to perform other necessary clean up.
  1425. mCalledClose = true;
  1426. }
  1427. // Make sure we always clean up.
  1428. ShutDownProcess(why == NormalShutdown ? CLOSE_CHANNEL
  1429. : CLOSE_CHANNEL_WITH_ERROR);
  1430. RefPtr<ContentParent> kungFuDeathGrip(this);
  1431. nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
  1432. if (obs) {
  1433. size_t length = ArrayLength(sObserverTopics);
  1434. for (size_t i = 0; i < length; ++i) {
  1435. obs->RemoveObserver(static_cast<nsIObserver*>(this),
  1436. sObserverTopics[i]);
  1437. }
  1438. }
  1439. // remove the global remote preferences observers
  1440. Preferences::RemoveObserver(this, "");
  1441. gfxVars::RemoveReceiver(this);
  1442. if (GPUProcessManager* gpu = GPUProcessManager::Get()) {
  1443. // Note: the manager could have shutdown already.
  1444. gpu->RemoveListener(this);
  1445. }
  1446. RecvRemoveGeolocationListener();
  1447. mConsoleService = nullptr;
  1448. if (obs) {
  1449. RefPtr<nsHashPropertyBag> props = new nsHashPropertyBag();
  1450. props->SetPropertyAsUint64(NS_LITERAL_STRING("childID"), mChildID);
  1451. if (AbnormalShutdown == why) {
  1452. props->SetPropertyAsBool(NS_LITERAL_STRING("abnormal"), true);
  1453. }
  1454. nsAutoString cpId;
  1455. cpId.AppendInt(static_cast<uint64_t>(this->ChildID()));
  1456. obs->NotifyObservers((nsIPropertyBag2*) props, "ipc:content-shutdown", cpId.get());
  1457. }
  1458. // Remove any and all idle listeners.
  1459. nsCOMPtr<nsIIdleService> idleService =
  1460. do_GetService("@mozilla.org/widget/idleservice;1");
  1461. MOZ_ASSERT(idleService);
  1462. RefPtr<ParentIdleListener> listener;
  1463. for (int32_t i = mIdleListeners.Length() - 1; i >= 0; --i) {
  1464. listener = static_cast<ParentIdleListener*>(mIdleListeners[i].get());
  1465. idleService->RemoveIdleObserver(listener, listener->mTime);
  1466. }
  1467. mIdleListeners.Clear();
  1468. MessageLoop::current()->
  1469. PostTask(NewRunnableFunction(DelayedDeleteSubprocess, mSubprocess));
  1470. mSubprocess = nullptr;
  1471. // IPDL rules require actors to live on past ActorDestroy, but it
  1472. // may be that the kungFuDeathGrip above is the last reference to
  1473. // |this|. If so, when we go out of scope here, we're deleted and
  1474. // all hell breaks loose.
  1475. //
  1476. // This runnable ensures that a reference to |this| lives on at
  1477. // least until after the current task finishes running.
  1478. NS_DispatchToCurrentThread(new DelayedDeleteContentParentTask(this));
  1479. ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
  1480. nsTArray<ContentParentId> childIDArray =
  1481. cpm->GetAllChildProcessById(this->ChildID());
  1482. // Destroy any processes created by this ContentParent
  1483. for(uint32_t i = 0; i < childIDArray.Length(); i++) {
  1484. ContentParent* cp = cpm->GetContentProcessById(childIDArray[i]);
  1485. MessageLoop::current()->PostTask(NewRunnableMethod
  1486. <ShutDownMethod>(cp,
  1487. &ContentParent::ShutDownProcess,
  1488. SEND_SHUTDOWN_MESSAGE));
  1489. }
  1490. cpm->RemoveContentProcess(this->ChildID());
  1491. if (mDriverCrashGuard) {
  1492. mDriverCrashGuard->NotifyCrashed();
  1493. }
  1494. // Unregister all the BlobURLs registered by the ContentChild.
  1495. for (uint32_t i = 0; i < mBlobURLs.Length(); ++i) {
  1496. nsHostObjectProtocolHandler::RemoveDataEntry(mBlobURLs[i]);
  1497. }
  1498. mBlobURLs.Clear();
  1499. #if defined(XP_WIN32) && defined(ACCESSIBILITY)
  1500. a11y::AccessibleWrap::ReleaseContentProcessIdFor(ChildID());
  1501. #endif
  1502. }
  1503. void
  1504. ContentParent::NotifyTabDestroying(const TabId& aTabId,
  1505. const ContentParentId& aCpId)
  1506. {
  1507. if (XRE_IsParentProcess()) {
  1508. // There can be more than one PBrowser for a given app process
  1509. // because of popup windows. PBrowsers can also destroy
  1510. // concurrently. When all the PBrowsers are destroying, kick off
  1511. // another task to ensure the child process *really* shuts down,
  1512. // even if the PBrowsers themselves never finish destroying.
  1513. ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
  1514. ContentParent* cp = cpm->GetContentProcessById(aCpId);
  1515. if (!cp) {
  1516. return;
  1517. }
  1518. ++cp->mNumDestroyingTabs;
  1519. nsTArray<TabId> tabIds = cpm->GetTabParentsByProcessId(aCpId);
  1520. if (static_cast<size_t>(cp->mNumDestroyingTabs) != tabIds.Length()) {
  1521. return;
  1522. }
  1523. uint32_t numberOfParents = sNonAppContentParents ? sNonAppContentParents->Length() : 0;
  1524. int32_t processesToKeepAlive = Preferences::GetInt("dom.ipc.keepProcessesAlive", 0);
  1525. if (!cp->mLargeAllocationProcess && static_cast<int32_t>(numberOfParents) <= processesToKeepAlive) {
  1526. return;
  1527. }
  1528. // We're dying now, so prevent this content process from being
  1529. // recycled during its shutdown procedure.
  1530. cp->MarkAsDead();
  1531. cp->StartForceKillTimer();
  1532. } else {
  1533. ContentChild::GetSingleton()->SendNotifyTabDestroying(aTabId, aCpId);
  1534. }
  1535. }
  1536. void
  1537. ContentParent::StartForceKillTimer()
  1538. {
  1539. if (mForceKillTimer || !mIPCOpen) {
  1540. return;
  1541. }
  1542. int32_t timeoutSecs = Preferences::GetInt("dom.ipc.tabs.shutdownTimeoutSecs", 5);
  1543. if (timeoutSecs > 0) {
  1544. mForceKillTimer = do_CreateInstance("@mozilla.org/timer;1");
  1545. MOZ_ASSERT(mForceKillTimer);
  1546. mForceKillTimer->InitWithFuncCallback(ContentParent::ForceKillTimerCallback,
  1547. this,
  1548. timeoutSecs * 1000,
  1549. nsITimer::TYPE_ONE_SHOT);
  1550. }
  1551. }
  1552. void
  1553. ContentParent::NotifyTabDestroyed(const TabId& aTabId,
  1554. bool aNotifiedDestroying)
  1555. {
  1556. if (aNotifiedDestroying) {
  1557. --mNumDestroyingTabs;
  1558. }
  1559. nsTArray<PContentPermissionRequestParent*> parentArray =
  1560. nsContentPermissionUtils::GetContentPermissionRequestParentById(aTabId);
  1561. // Need to close undeleted ContentPermissionRequestParents before tab is closed.
  1562. for (auto& permissionRequestParent : parentArray) {
  1563. Unused << PContentPermissionRequestParent::Send__delete__(permissionRequestParent);
  1564. }
  1565. // There can be more than one PBrowser for a given app process
  1566. // because of popup windows. When the last one closes, shut
  1567. // us down.
  1568. ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
  1569. nsTArray<TabId> tabIds = cpm->GetTabParentsByProcessId(this->ChildID());
  1570. // We might want to keep alive some content processes for testing, because of performance
  1571. // reasons, but we don't want to alter behavior if the pref is not set.
  1572. uint32_t numberOfParents = sNonAppContentParents ? sNonAppContentParents->Length() : 0;
  1573. int32_t processesToKeepAlive = Preferences::GetInt("dom.ipc.keepProcessesAlive", 0);
  1574. bool shouldKeepAliveAny = !mLargeAllocationProcess && processesToKeepAlive > 0;
  1575. bool shouldKeepAliveThis = shouldKeepAliveAny && static_cast<int32_t>(numberOfParents) <= processesToKeepAlive;
  1576. if (tabIds.Length() == 1 && !shouldKeepAliveThis) {
  1577. // In the case of normal shutdown, send a shutdown message to child to
  1578. // allow it to perform shutdown tasks.
  1579. MessageLoop::current()->PostTask(NewRunnableMethod
  1580. <ShutDownMethod>(this,
  1581. &ContentParent::ShutDownProcess,
  1582. SEND_SHUTDOWN_MESSAGE));
  1583. }
  1584. }
  1585. jsipc::CPOWManager*
  1586. ContentParent::GetCPOWManager()
  1587. {
  1588. if (PJavaScriptParent* p = LoneManagedOrNullAsserts(ManagedPJavaScriptParent())) {
  1589. return CPOWManagerFor(p);
  1590. }
  1591. return nullptr;
  1592. }
  1593. TestShellParent*
  1594. ContentParent::CreateTestShell()
  1595. {
  1596. return static_cast<TestShellParent*>(SendPTestShellConstructor());
  1597. }
  1598. bool
  1599. ContentParent::DestroyTestShell(TestShellParent* aTestShell)
  1600. {
  1601. return PTestShellParent::Send__delete__(aTestShell);
  1602. }
  1603. TestShellParent*
  1604. ContentParent::GetTestShellSingleton()
  1605. {
  1606. PTestShellParent* p = LoneManagedOrNullAsserts(ManagedPTestShellParent());
  1607. return static_cast<TestShellParent*>(p);
  1608. }
  1609. void
  1610. ContentParent::InitializeMembers()
  1611. {
  1612. mSubprocess = nullptr;
  1613. mChildID = gContentChildID++;
  1614. mGeolocationWatchID = -1;
  1615. mNumDestroyingTabs = 0;
  1616. mIsAlive = true;
  1617. mMetamorphosed = false;
  1618. mSendPermissionUpdates = false;
  1619. mCalledClose = false;
  1620. mCalledKillHard = false;
  1621. mCreatedPairedMinidumps = false;
  1622. mShutdownPending = false;
  1623. mIPCOpen = true;
  1624. mHangMonitorActor = nullptr;
  1625. }
  1626. bool
  1627. ContentParent::LaunchSubprocess(ProcessPriority aInitialPriority /* = PROCESS_PRIORITY_FOREGROUND */)
  1628. {
  1629. PROFILER_LABEL_FUNC(js::ProfileEntry::Category::OTHER);
  1630. std::vector<std::string> extraArgs;
  1631. if (gSafeMode) {
  1632. extraArgs.push_back("-safeMode");
  1633. }
  1634. if (!mSubprocess->LaunchAndWaitForProcessHandle(extraArgs)) {
  1635. MarkAsDead();
  1636. return false;
  1637. }
  1638. Open(mSubprocess->GetChannel(),
  1639. base::GetProcId(mSubprocess->GetChildProcessHandle()));
  1640. InitInternal(aInitialPriority,
  1641. true, /* Setup off-main thread compositing */
  1642. true /* Send registered chrome */);
  1643. ContentProcessManager::GetSingleton()->AddContentProcess(this);
  1644. ProcessHangMonitor::AddProcess(this);
  1645. // Set a reply timeout for CPOWs.
  1646. SetReplyTimeoutMs(Preferences::GetInt("dom.ipc.cpow.timeout", 0));
  1647. return true;
  1648. }
  1649. ContentParent::ContentParent(mozIApplication* aApp,
  1650. ContentParent* aOpener,
  1651. bool aIsForBrowser,
  1652. bool aIsForPreallocated)
  1653. : nsIContentParent()
  1654. , mOpener(aOpener)
  1655. , mIsForBrowser(aIsForBrowser)
  1656. , mLargeAllocationProcess(false)
  1657. {
  1658. InitializeMembers(); // Perform common initialization.
  1659. // No more than one of !!aApp, aIsForBrowser, aIsForPreallocated should be
  1660. // true.
  1661. MOZ_ASSERT(!!aApp + aIsForBrowser + aIsForPreallocated <= 1);
  1662. mMetamorphosed = true;
  1663. // Insert ourselves into the global linked list of ContentParent objects.
  1664. if (!sContentParents) {
  1665. sContentParents = new LinkedList<ContentParent>();
  1666. }
  1667. sContentParents->insertBack(this);
  1668. if (aApp) {
  1669. aApp->GetManifestURL(mAppManifestURL);
  1670. aApp->GetName(mAppName);
  1671. } else if (aIsForPreallocated) {
  1672. mAppManifestURL = MAGIC_PREALLOCATED_APP_MANIFEST_URL;
  1673. }
  1674. // From this point on, NS_WARNING, NS_ASSERTION, etc. should print out the
  1675. // PID along with the warning.
  1676. nsDebugImpl::SetMultiprocessMode("Parent");
  1677. #if defined(XP_WIN)
  1678. // Request Windows message deferral behavior on our side of the PContent
  1679. // channel. Generally only applies to the situation where we get caught in
  1680. // a deadlock with the plugin process when sending CPOWs.
  1681. GetIPCChannel()->SetChannelFlags(MessageChannel::REQUIRE_DEFERRED_MESSAGE_PROTECTION);
  1682. #endif
  1683. NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
  1684. ChildPrivileges privs = base::PRIVILEGES_DEFAULT;
  1685. mSubprocess = new GeckoChildProcessHost(GeckoProcessType_Content, privs);
  1686. }
  1687. ContentParent::~ContentParent()
  1688. {
  1689. if (mForceKillTimer) {
  1690. mForceKillTimer->Cancel();
  1691. }
  1692. NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
  1693. // We should be removed from all these lists in ActorDestroy.
  1694. MOZ_ASSERT(!sPrivateContent || !sPrivateContent->Contains(this));
  1695. if (mAppManifestURL.IsEmpty()) {
  1696. MOZ_ASSERT((!sNonAppContentParents ||
  1697. !sNonAppContentParents->Contains(this)) &&
  1698. (!sLargeAllocationContentParents ||
  1699. !sLargeAllocationContentParents->Contains(this)));
  1700. } else {
  1701. // In general, we expect sAppContentParents->Get(mAppManifestURL) to be
  1702. // nullptr. But it could be that we created another ContentParent for
  1703. // this app after we did this->ActorDestroy(), so the right check is
  1704. // that sAppContentParents->Get(mAppManifestURL) != this.
  1705. MOZ_ASSERT(!sAppContentParents ||
  1706. sAppContentParents->Get(mAppManifestURL) != this);
  1707. }
  1708. }
  1709. void
  1710. ContentParent::InitInternal(ProcessPriority aInitialPriority,
  1711. bool aSetupOffMainThreadCompositing,
  1712. bool aSendRegisteredChrome)
  1713. {
  1714. if (aSendRegisteredChrome) {
  1715. nsCOMPtr<nsIChromeRegistry> registrySvc = nsChromeRegistry::GetService();
  1716. nsChromeRegistryChrome* chromeRegistry =
  1717. static_cast<nsChromeRegistryChrome*>(registrySvc.get());
  1718. chromeRegistry->SendRegisteredChrome(this);
  1719. }
  1720. if (gAppData) {
  1721. nsCString version(gAppData->version);
  1722. nsCString buildID(gAppData->buildID);
  1723. nsCString name(gAppData->name);
  1724. nsCString UAName(gAppData->UAName);
  1725. nsCString ID(gAppData->ID);
  1726. nsCString vendor(gAppData->vendor);
  1727. // Sending all information to content process.
  1728. Unused << SendAppInfo(version, buildID, name, UAName, ID, vendor);
  1729. }
  1730. // Initialize the message manager (and load delayed scripts) now that we
  1731. // have established communications with the child.
  1732. mMessageManager->InitWithCallback(this);
  1733. // Set the subprocess's priority. We do this early on because we're likely
  1734. // /lowering/ the process's CPU and memory priority, which it has inherited
  1735. // from this process.
  1736. //
  1737. // This call can cause us to send IPC messages to the child process, so it
  1738. // must come after the Open() call above.
  1739. ProcessPriorityManager::SetProcessPriority(this, aInitialPriority);
  1740. if (aSetupOffMainThreadCompositing) {
  1741. // NB: internally, this will send an IPC message to the child
  1742. // process to get it to create the CompositorBridgeChild. This
  1743. // message goes through the regular IPC queue for this
  1744. // channel, so delivery will happen-before any other messages
  1745. // we send. The CompositorBridgeChild must be created before any
  1746. // PBrowsers are created, because they rely on the Compositor
  1747. // already being around. (Creation is async, so can't happen
  1748. // on demand.)
  1749. bool useOffMainThreadCompositing = !!CompositorThreadHolder::Loop();
  1750. if (useOffMainThreadCompositing) {
  1751. GPUProcessManager* gpm = GPUProcessManager::Get();
  1752. Endpoint<PCompositorBridgeChild> compositor;
  1753. Endpoint<PImageBridgeChild> imageBridge;
  1754. Endpoint<PVideoDecoderManagerChild> videoManager;
  1755. DebugOnly<bool> opened = gpm->CreateContentBridges(
  1756. OtherPid(),
  1757. &compositor,
  1758. &imageBridge,
  1759. &videoManager);
  1760. MOZ_ASSERT(opened);
  1761. Unused << SendInitRendering(
  1762. Move(compositor),
  1763. Move(imageBridge),
  1764. Move(videoManager));
  1765. gpm->AddListener(this);
  1766. }
  1767. }
  1768. if (gAppData) {
  1769. // Sending all information to content process.
  1770. Unused << SendAppInit();
  1771. }
  1772. nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance();
  1773. if (sheetService) {
  1774. // This looks like a lot of work, but in a normal browser session we just
  1775. // send two loads.
  1776. for (StyleSheet* sheet : *sheetService->AgentStyleSheets()) {
  1777. URIParams uri;
  1778. SerializeURI(sheet->GetSheetURI(), uri);
  1779. Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AGENT_SHEET);
  1780. }
  1781. for (StyleSheet* sheet : *sheetService->UserStyleSheets()) {
  1782. URIParams uri;
  1783. SerializeURI(sheet->GetSheetURI(), uri);
  1784. Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::USER_SHEET);
  1785. }
  1786. for (StyleSheet* sheet : *sheetService->AuthorStyleSheets()) {
  1787. URIParams uri;
  1788. SerializeURI(sheet->GetSheetURI(), uri);
  1789. Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AUTHOR_SHEET);
  1790. }
  1791. }
  1792. #if defined(XP_WIN)
  1793. // Send the info needed to join the browser process's audio session.
  1794. nsID id;
  1795. nsString sessionName;
  1796. nsString iconPath;
  1797. if (NS_SUCCEEDED(mozilla::widget::GetAudioSessionData(id, sessionName,
  1798. iconPath))) {
  1799. Unused << SendSetAudioSessionData(id, sessionName, iconPath);
  1800. }
  1801. #endif
  1802. {
  1803. RefPtr<ServiceWorkerRegistrar> swr = ServiceWorkerRegistrar::Get();
  1804. MOZ_ASSERT(swr);
  1805. nsTArray<ServiceWorkerRegistrationData> registrations;
  1806. swr->GetRegistrations(registrations);
  1807. Unused << SendInitServiceWorkers(ServiceWorkerConfiguration(registrations));
  1808. }
  1809. {
  1810. nsTArray<BlobURLRegistrationData> registrations;
  1811. if (nsHostObjectProtocolHandler::GetAllBlobURLEntries(registrations,
  1812. this)) {
  1813. Unused << SendInitBlobURLs(registrations);
  1814. }
  1815. }
  1816. }
  1817. bool
  1818. ContentParent::IsAlive() const
  1819. {
  1820. return mIsAlive;
  1821. }
  1822. bool
  1823. ContentParent::IsForApp() const
  1824. {
  1825. return !mAppManifestURL.IsEmpty();
  1826. }
  1827. int32_t
  1828. ContentParent::Pid() const
  1829. {
  1830. if (!mSubprocess || !mSubprocess->GetChildProcessHandle()) {
  1831. return -1;
  1832. }
  1833. return base::GetProcId(mSubprocess->GetChildProcessHandle());
  1834. }
  1835. bool
  1836. ContentParent::RecvReadPrefsArray(InfallibleTArray<PrefSetting>* aPrefs)
  1837. {
  1838. Preferences::GetPreferences(aPrefs);
  1839. return true;
  1840. }
  1841. bool
  1842. ContentParent::RecvGetGfxVars(InfallibleTArray<GfxVarUpdate>* aVars)
  1843. {
  1844. // Ensure gfxVars is initialized (for xpcshell tests).
  1845. gfxVars::Initialize();
  1846. *aVars = gfxVars::FetchNonDefaultVars();
  1847. // Now that content has initialized gfxVars, we can start listening for
  1848. // updates.
  1849. gfxVars::AddReceiver(this);
  1850. return true;
  1851. }
  1852. void
  1853. ContentParent::OnCompositorUnexpectedShutdown()
  1854. {
  1855. GPUProcessManager* gpm = GPUProcessManager::Get();
  1856. Endpoint<PCompositorBridgeChild> compositor;
  1857. Endpoint<PImageBridgeChild> imageBridge;
  1858. Endpoint<PVideoDecoderManagerChild> videoManager;
  1859. DebugOnly<bool> opened = gpm->CreateContentBridges(
  1860. OtherPid(),
  1861. &compositor,
  1862. &imageBridge,
  1863. &videoManager);
  1864. MOZ_ASSERT(opened);
  1865. Unused << SendReinitRendering(
  1866. Move(compositor),
  1867. Move(imageBridge),
  1868. Move(videoManager));
  1869. }
  1870. void
  1871. ContentParent::OnVarChanged(const GfxVarUpdate& aVar)
  1872. {
  1873. if (!mIPCOpen) {
  1874. return;
  1875. }
  1876. Unused << SendVarUpdate(aVar);
  1877. }
  1878. bool
  1879. ContentParent::RecvReadFontList(InfallibleTArray<FontListEntry>* retValue)
  1880. {
  1881. return true;
  1882. }
  1883. bool
  1884. ContentParent::RecvReadDataStorageArray(const nsString& aFilename,
  1885. InfallibleTArray<DataStorageItem>* aValues)
  1886. {
  1887. // If we're shutting down, the DataStorage object may have been cleared
  1888. // already, and setting it up is pointless anyways since we're about to die.
  1889. if (mShutdownPending) {
  1890. return true;
  1891. }
  1892. // Ensure the SSS is initialized before we try to use its storage.
  1893. nsCOMPtr<nsISiteSecurityService> sss = do_GetService("@mozilla.org/ssservice;1");
  1894. RefPtr<DataStorage> storage = DataStorage::Get(aFilename);
  1895. storage->GetAll(aValues);
  1896. return true;
  1897. }
  1898. bool
  1899. ContentParent::RecvReadPermissions(InfallibleTArray<IPC::Permission>* aPermissions)
  1900. {
  1901. #ifdef MOZ_PERMISSIONS
  1902. nsCOMPtr<nsIPermissionManager> permissionManagerIface =
  1903. services::GetPermissionManager();
  1904. nsPermissionManager* permissionManager =
  1905. static_cast<nsPermissionManager*>(permissionManagerIface.get());
  1906. MOZ_ASSERT(permissionManager,
  1907. "We have no permissionManager in the Chrome process !");
  1908. nsCOMPtr<nsISimpleEnumerator> enumerator;
  1909. DebugOnly<nsresult> rv = permissionManager->GetEnumerator(getter_AddRefs(enumerator));
  1910. MOZ_ASSERT(NS_SUCCEEDED(rv), "Could not get enumerator!");
  1911. while(1) {
  1912. bool hasMore;
  1913. enumerator->HasMoreElements(&hasMore);
  1914. if (!hasMore)
  1915. break;
  1916. nsCOMPtr<nsISupports> supp;
  1917. enumerator->GetNext(getter_AddRefs(supp));
  1918. nsCOMPtr<nsIPermission> perm = do_QueryInterface(supp);
  1919. nsCOMPtr<nsIPrincipal> principal;
  1920. perm->GetPrincipal(getter_AddRefs(principal));
  1921. nsCString origin;
  1922. if (principal) {
  1923. principal->GetOrigin(origin);
  1924. }
  1925. nsCString type;
  1926. perm->GetType(type);
  1927. uint32_t capability;
  1928. perm->GetCapability(&capability);
  1929. uint32_t expireType;
  1930. perm->GetExpireType(&expireType);
  1931. int64_t expireTime;
  1932. perm->GetExpireTime(&expireTime);
  1933. aPermissions->AppendElement(IPC::Permission(origin, type,
  1934. capability, expireType,
  1935. expireTime));
  1936. }
  1937. // Ask for future changes
  1938. mSendPermissionUpdates = true;
  1939. #endif
  1940. return true;
  1941. }
  1942. bool
  1943. ContentParent::RecvSetClipboard(const IPCDataTransfer& aDataTransfer,
  1944. const bool& aIsPrivateData,
  1945. const IPC::Principal& aRequestingPrincipal,
  1946. const int32_t& aWhichClipboard)
  1947. {
  1948. nsresult rv;
  1949. nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
  1950. NS_ENSURE_SUCCESS(rv, true);
  1951. nsCOMPtr<nsITransferable> trans =
  1952. do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
  1953. NS_ENSURE_SUCCESS(rv, true);
  1954. trans->Init(nullptr);
  1955. rv = nsContentUtils::IPCTransferableToTransferable(aDataTransfer,
  1956. aIsPrivateData,
  1957. aRequestingPrincipal,
  1958. trans, this, nullptr);
  1959. NS_ENSURE_SUCCESS(rv, true);
  1960. clipboard->SetData(trans, nullptr, aWhichClipboard);
  1961. return true;
  1962. }
  1963. bool
  1964. ContentParent::RecvGetClipboard(nsTArray<nsCString>&& aTypes,
  1965. const int32_t& aWhichClipboard,
  1966. IPCDataTransfer* aDataTransfer)
  1967. {
  1968. nsresult rv;
  1969. nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
  1970. NS_ENSURE_SUCCESS(rv, true);
  1971. nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
  1972. NS_ENSURE_SUCCESS(rv, true);
  1973. trans->Init(nullptr);
  1974. for (uint32_t t = 0; t < aTypes.Length(); t++) {
  1975. trans->AddDataFlavor(aTypes[t].get());
  1976. }
  1977. clipboard->GetData(trans, aWhichClipboard);
  1978. nsContentUtils::TransferableToIPCTransferable(trans, aDataTransfer,
  1979. true, nullptr, this);
  1980. return true;
  1981. }
  1982. bool
  1983. ContentParent::RecvEmptyClipboard(const int32_t& aWhichClipboard)
  1984. {
  1985. nsresult rv;
  1986. nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
  1987. NS_ENSURE_SUCCESS(rv, true);
  1988. clipboard->EmptyClipboard(aWhichClipboard);
  1989. return true;
  1990. }
  1991. bool
  1992. ContentParent::RecvClipboardHasType(nsTArray<nsCString>&& aTypes,
  1993. const int32_t& aWhichClipboard,
  1994. bool* aHasType)
  1995. {
  1996. nsresult rv;
  1997. nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
  1998. NS_ENSURE_SUCCESS(rv, true);
  1999. const char** typesChrs = new const char *[aTypes.Length()];
  2000. for (uint32_t t = 0; t < aTypes.Length(); t++) {
  2001. typesChrs[t] = aTypes[t].get();
  2002. }
  2003. clipboard->HasDataMatchingFlavors(typesChrs, aTypes.Length(),
  2004. aWhichClipboard, aHasType);
  2005. delete [] typesChrs;
  2006. return true;
  2007. }
  2008. bool
  2009. ContentParent::RecvGetSystemColors(const uint32_t& colorsCount,
  2010. InfallibleTArray<uint32_t>* colors)
  2011. {
  2012. return true;
  2013. }
  2014. bool
  2015. ContentParent::RecvGetIconForExtension(const nsCString& aFileExt,
  2016. const uint32_t& aIconSize,
  2017. InfallibleTArray<uint8_t>* bits)
  2018. {
  2019. return true;
  2020. }
  2021. bool
  2022. ContentParent::RecvGetShowPasswordSetting(bool* showPassword)
  2023. {
  2024. // default behavior is to show the last password character
  2025. *showPassword = true;
  2026. return true;
  2027. }
  2028. bool
  2029. ContentParent::RecvFirstIdle()
  2030. {
  2031. // When the ContentChild goes idle, it sends us a FirstIdle message
  2032. // which we use as a good time to prelaunch another process. If we
  2033. // prelaunch any sooner than this, then we'll be competing with the
  2034. // child process and slowing it down.
  2035. PreallocatedProcessManager::AllocateAfterDelay();
  2036. return true;
  2037. }
  2038. bool
  2039. ContentParent::RecvAudioChannelChangeDefVolChannel(const int32_t& aChannel,
  2040. const bool& aHidden)
  2041. {
  2042. RefPtr<AudioChannelService> service = AudioChannelService::GetOrCreate();
  2043. MOZ_ASSERT(service);
  2044. service->SetDefaultVolumeControlChannelInternal(aChannel, aHidden, mChildID);
  2045. return true;
  2046. }
  2047. bool
  2048. ContentParent::RecvAudioChannelServiceStatus(
  2049. const bool& aTelephonyChannel,
  2050. const bool& aContentOrNormalChannel,
  2051. const bool& aAnyChannel)
  2052. {
  2053. RefPtr<AudioChannelService> service = AudioChannelService::GetOrCreate();
  2054. MOZ_ASSERT(service);
  2055. service->ChildStatusReceived(mChildID, aTelephonyChannel,
  2056. aContentOrNormalChannel, aAnyChannel);
  2057. return true;
  2058. }
  2059. // We want ContentParent to show up in CC logs for debugging purposes, but we
  2060. // don't actually cycle collect it.
  2061. NS_IMPL_CYCLE_COLLECTION_0(ContentParent)
  2062. NS_IMPL_CYCLE_COLLECTING_ADDREF(ContentParent)
  2063. NS_IMPL_CYCLE_COLLECTING_RELEASE(ContentParent)
  2064. NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ContentParent)
  2065. NS_INTERFACE_MAP_ENTRY(nsIContentParent)
  2066. NS_INTERFACE_MAP_ENTRY(nsIObserver)
  2067. NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionCallback)
  2068. NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionErrorCallback)
  2069. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
  2070. NS_INTERFACE_MAP_END
  2071. NS_IMETHODIMP
  2072. ContentParent::Observe(nsISupports* aSubject,
  2073. const char* aTopic,
  2074. const char16_t* aData)
  2075. {
  2076. if (mSubprocess && (!strcmp(aTopic, "profile-before-change") ||
  2077. !strcmp(aTopic, "xpcom-shutdown"))) {
  2078. // Okay to call ShutDownProcess multiple times.
  2079. ShutDownProcess(SEND_SHUTDOWN_MESSAGE);
  2080. // Wait for shutdown to complete, so that we receive any shutdown
  2081. // data (e.g. telemetry) from the child before we quit.
  2082. // This loop terminate prematurely based on mForceKillTimer.
  2083. while (mIPCOpen && !mCalledKillHard) {
  2084. NS_ProcessNextEvent(nullptr, true);
  2085. }
  2086. NS_ASSERTION(!mSubprocess, "Close should have nulled mSubprocess");
  2087. }
  2088. if (!mIsAlive || !mSubprocess)
  2089. return NS_OK;
  2090. // listening for memory pressure event
  2091. if (!strcmp(aTopic, "memory-pressure") &&
  2092. !StringEndsWith(nsDependentString(aData),
  2093. NS_LITERAL_STRING("-no-forward"))) {
  2094. Unused << SendFlushMemory(nsDependentString(aData));
  2095. }
  2096. // listening for remotePrefs...
  2097. else if (!strcmp(aTopic, "nsPref:changed")) {
  2098. // We know prefs are ASCII here.
  2099. NS_LossyConvertUTF16toASCII strData(aData);
  2100. PrefSetting pref(strData, null_t(), null_t());
  2101. Preferences::GetPreference(&pref);
  2102. if (!SendPreferenceUpdate(pref)) {
  2103. return NS_ERROR_NOT_AVAILABLE;
  2104. }
  2105. }
  2106. else if (!strcmp(aTopic, NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC)) {
  2107. NS_ConvertUTF16toUTF8 dataStr(aData);
  2108. const char *offline = dataStr.get();
  2109. if (!SendSetOffline(!strcmp(offline, "true") ? true : false)) {
  2110. return NS_ERROR_NOT_AVAILABLE;
  2111. }
  2112. }
  2113. else if (!strcmp(aTopic, NS_IPC_IOSERVICE_SET_CONNECTIVITY_TOPIC)) {
  2114. if (!SendSetConnectivity(NS_LITERAL_STRING("true").Equals(aData))) {
  2115. return NS_ERROR_NOT_AVAILABLE;
  2116. }
  2117. } else if (!strcmp(aTopic, NS_IPC_CAPTIVE_PORTAL_SET_STATE)) {
  2118. nsCOMPtr<nsICaptivePortalService> cps = do_QueryInterface(aSubject);
  2119. MOZ_ASSERT(cps, "Should QI to a captive portal service");
  2120. if (!cps) {
  2121. return NS_ERROR_FAILURE;
  2122. }
  2123. int32_t state;
  2124. cps->GetState(&state);
  2125. if (!SendSetCaptivePortalState(state)) {
  2126. return NS_ERROR_NOT_AVAILABLE;
  2127. }
  2128. }
  2129. // listening for alert notifications
  2130. else if (!strcmp(aTopic, "alertfinished") ||
  2131. !strcmp(aTopic, "alertclickcallback") ||
  2132. !strcmp(aTopic, "alertshow") ||
  2133. !strcmp(aTopic, "alertdisablecallback") ||
  2134. !strcmp(aTopic, "alertsettingscallback")) {
  2135. if (!SendNotifyAlertsObserver(nsDependentCString(aTopic),
  2136. nsDependentString(aData)))
  2137. return NS_ERROR_NOT_AVAILABLE;
  2138. }
  2139. else if (!strcmp(aTopic, "child-gc-request")){
  2140. Unused << SendGarbageCollect();
  2141. }
  2142. else if (!strcmp(aTopic, "child-cc-request")){
  2143. Unused << SendCycleCollect();
  2144. }
  2145. else if (!strcmp(aTopic, "child-mmu-request")){
  2146. Unused << SendMinimizeMemoryUsage();
  2147. }
  2148. else if (!strcmp(aTopic, "last-pb-context-exited")) {
  2149. Unused << SendLastPrivateDocShellDestroyed();
  2150. }
  2151. #ifdef ACCESSIBILITY
  2152. else if (aData && !strcmp(aTopic, "a11y-init-or-shutdown")) {
  2153. if (*aData == '1') {
  2154. // Make sure accessibility is running in content process when
  2155. // accessibility gets initiated in chrome process.
  2156. #if !defined(XP_WIN)
  2157. Unused << SendActivateA11y(0);
  2158. #endif
  2159. } else {
  2160. // If possible, shut down accessibility in content process when
  2161. // accessibility gets shutdown in chrome process.
  2162. Unused << SendShutdownA11y();
  2163. }
  2164. }
  2165. #endif
  2166. else if (!strcmp(aTopic, "cacheservice:empty-cache")) {
  2167. Unused << SendNotifyEmptyHTTPCache();
  2168. }
  2169. return NS_OK;
  2170. }
  2171. PGMPServiceParent*
  2172. ContentParent::AllocPGMPServiceParent(mozilla::ipc::Transport* aTransport,
  2173. base::ProcessId aOtherProcess)
  2174. {
  2175. return GMPServiceParent::Create(aTransport, aOtherProcess);
  2176. }
  2177. PBackgroundParent*
  2178. ContentParent::AllocPBackgroundParent(Transport* aTransport,
  2179. ProcessId aOtherProcess)
  2180. {
  2181. return BackgroundParent::Alloc(this, aTransport, aOtherProcess);
  2182. }
  2183. PProcessHangMonitorParent*
  2184. ContentParent::AllocPProcessHangMonitorParent(Transport* aTransport,
  2185. ProcessId aOtherProcess)
  2186. {
  2187. mHangMonitorActor = CreateHangMonitorParent(this, aTransport, aOtherProcess);
  2188. return mHangMonitorActor;
  2189. }
  2190. bool
  2191. ContentParent::RecvGetProcessAttributes(ContentParentId* aCpId,
  2192. bool* aIsForApp, bool* aIsForBrowser)
  2193. {
  2194. *aCpId = mChildID;
  2195. *aIsForApp = IsForApp();
  2196. *aIsForBrowser = mIsForBrowser;
  2197. return true;
  2198. }
  2199. bool
  2200. ContentParent::RecvGetXPCOMProcessAttributes(bool* aIsOffline,
  2201. bool* aIsConnected,
  2202. int32_t* aCaptivePortalState,
  2203. bool* aIsLangRTL,
  2204. bool* aHaveBidiKeyboards,
  2205. InfallibleTArray<nsString>* dictionaries,
  2206. ClipboardCapabilities* clipboardCaps,
  2207. DomainPolicyClone* domainPolicy,
  2208. StructuredCloneData* aInitialData,
  2209. OptionalURIParams* aUserContentCSSURL)
  2210. {
  2211. nsCOMPtr<nsIIOService> io(do_GetIOService());
  2212. MOZ_ASSERT(io, "No IO service?");
  2213. DebugOnly<nsresult> rv = io->GetOffline(aIsOffline);
  2214. MOZ_ASSERT(NS_SUCCEEDED(rv), "Failed getting offline?");
  2215. rv = io->GetConnectivity(aIsConnected);
  2216. MOZ_ASSERT(NS_SUCCEEDED(rv), "Failed getting connectivity?");
  2217. *aCaptivePortalState = nsICaptivePortalService::UNKNOWN;
  2218. nsCOMPtr<nsICaptivePortalService> cps = do_GetService(NS_CAPTIVEPORTAL_CONTRACTID);
  2219. if (cps) {
  2220. cps->GetState(aCaptivePortalState);
  2221. }
  2222. nsIBidiKeyboard* bidi = nsContentUtils::GetBidiKeyboard();
  2223. *aIsLangRTL = false;
  2224. *aHaveBidiKeyboards = false;
  2225. if (bidi) {
  2226. bidi->IsLangRTL(aIsLangRTL);
  2227. bidi->GetHaveBidiKeyboards(aHaveBidiKeyboards);
  2228. }
  2229. nsCOMPtr<nsISpellChecker> spellChecker(do_GetService(NS_SPELLCHECKER_CONTRACTID));
  2230. MOZ_ASSERT(spellChecker, "No spell checker?");
  2231. spellChecker->GetDictionaryList(dictionaries);
  2232. nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1"));
  2233. MOZ_ASSERT(clipboard, "No clipboard?");
  2234. rv = clipboard->SupportsSelectionClipboard(&clipboardCaps->supportsSelectionClipboard());
  2235. MOZ_ASSERT(NS_SUCCEEDED(rv));
  2236. rv = clipboard->SupportsFindClipboard(&clipboardCaps->supportsFindClipboard());
  2237. MOZ_ASSERT(NS_SUCCEEDED(rv));
  2238. // Let's copy the domain policy from the parent to the child (if it's active).
  2239. nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
  2240. NS_ENSURE_TRUE(ssm, false);
  2241. ssm->CloneDomainPolicy(domainPolicy);
  2242. if (nsFrameMessageManager* mm = nsFrameMessageManager::sParentProcessManager) {
  2243. AutoJSAPI jsapi;
  2244. if (NS_WARN_IF(!jsapi.Init(xpc::PrivilegedJunkScope()))) {
  2245. return false;
  2246. }
  2247. JS::RootedValue init(jsapi.cx());
  2248. nsresult result = mm->GetInitialProcessData(jsapi.cx(), &init);
  2249. if (NS_FAILED(result)) {
  2250. return false;
  2251. }
  2252. ErrorResult rv;
  2253. aInitialData->Write(jsapi.cx(), init, rv);
  2254. if (NS_WARN_IF(rv.Failed())) {
  2255. rv.SuppressException();
  2256. return false;
  2257. }
  2258. }
  2259. // Content processes have no permission to access profile directory, so we
  2260. // send the file URL instead.
  2261. StyleSheet* ucs = nsLayoutStylesheetCache::For(StyleBackendType::Gecko)->UserContentSheet();
  2262. if (ucs) {
  2263. SerializeURI(ucs->GetSheetURI(), *aUserContentCSSURL);
  2264. } else {
  2265. SerializeURI(nullptr, *aUserContentCSSURL);
  2266. }
  2267. return true;
  2268. }
  2269. mozilla::jsipc::PJavaScriptParent *
  2270. ContentParent::AllocPJavaScriptParent()
  2271. {
  2272. MOZ_ASSERT(ManagedPJavaScriptParent().IsEmpty());
  2273. return nsIContentParent::AllocPJavaScriptParent();
  2274. }
  2275. bool
  2276. ContentParent::DeallocPJavaScriptParent(PJavaScriptParent *parent)
  2277. {
  2278. return nsIContentParent::DeallocPJavaScriptParent(parent);
  2279. }
  2280. PBrowserParent*
  2281. ContentParent::AllocPBrowserParent(const TabId& aTabId,
  2282. const IPCTabContext& aContext,
  2283. const uint32_t& aChromeFlags,
  2284. const ContentParentId& aCpId,
  2285. const bool& aIsForApp,
  2286. const bool& aIsForBrowser)
  2287. {
  2288. return nsIContentParent::AllocPBrowserParent(aTabId,
  2289. aContext,
  2290. aChromeFlags,
  2291. aCpId,
  2292. aIsForApp,
  2293. aIsForBrowser);
  2294. }
  2295. bool
  2296. ContentParent::DeallocPBrowserParent(PBrowserParent* frame)
  2297. {
  2298. return nsIContentParent::DeallocPBrowserParent(frame);
  2299. }
  2300. PBlobParent*
  2301. ContentParent::AllocPBlobParent(const BlobConstructorParams& aParams)
  2302. {
  2303. return nsIContentParent::AllocPBlobParent(aParams);
  2304. }
  2305. bool
  2306. ContentParent::DeallocPBlobParent(PBlobParent* aActor)
  2307. {
  2308. return nsIContentParent::DeallocPBlobParent(aActor);
  2309. }
  2310. bool
  2311. ContentParent::RecvPBlobConstructor(PBlobParent* aActor,
  2312. const BlobConstructorParams& aParams)
  2313. {
  2314. const ParentBlobConstructorParams& params = aParams.get_ParentBlobConstructorParams();
  2315. if (params.blobParams().type() == AnyBlobConstructorParams::TKnownBlobConstructorParams) {
  2316. return aActor->SendCreatedFromKnownBlob();
  2317. }
  2318. return true;
  2319. }
  2320. mozilla::PRemoteSpellcheckEngineParent *
  2321. ContentParent::AllocPRemoteSpellcheckEngineParent()
  2322. {
  2323. mozilla::RemoteSpellcheckEngineParent *parent = new mozilla::RemoteSpellcheckEngineParent();
  2324. return parent;
  2325. }
  2326. bool
  2327. ContentParent::DeallocPRemoteSpellcheckEngineParent(PRemoteSpellcheckEngineParent *parent)
  2328. {
  2329. delete parent;
  2330. return true;
  2331. }
  2332. /* static */ void
  2333. ContentParent::ForceKillTimerCallback(nsITimer* aTimer, void* aClosure)
  2334. {
  2335. // We don't want to time out the content process during XPCShell tests. This
  2336. // is the easiest way to ensure that.
  2337. if (PR_GetEnv("XPCSHELL_TEST_PROFILE_DIR")) {
  2338. return;
  2339. }
  2340. auto self = static_cast<ContentParent*>(aClosure);
  2341. self->KillHard("ShutDownKill");
  2342. }
  2343. // WARNING: aReason appears in telemetry, so any new value passed in requires
  2344. // data review.
  2345. void
  2346. ContentParent::KillHard(const char* aReason)
  2347. {
  2348. PROFILER_LABEL_FUNC(js::ProfileEntry::Category::OTHER);
  2349. // On Windows, calling KillHard multiple times causes problems - the
  2350. // process handle becomes invalid on the first call, causing a second call
  2351. // to crash our process - more details in bug 890840.
  2352. if (mCalledKillHard) {
  2353. return;
  2354. }
  2355. mCalledKillHard = true;
  2356. mForceKillTimer = nullptr;
  2357. ProcessHandle otherProcessHandle;
  2358. if (!base::OpenProcessHandle(OtherPid(), &otherProcessHandle)) {
  2359. NS_ERROR("Failed to open child process when attempting kill.");
  2360. return;
  2361. }
  2362. if (!KillProcess(otherProcessHandle, base::PROCESS_END_KILLED_BY_USER,
  2363. false)) {
  2364. NS_WARNING("failed to kill subprocess!");
  2365. }
  2366. if (mSubprocess) {
  2367. mSubprocess->SetAlreadyDead();
  2368. }
  2369. // EnsureProcessTerminated has responsibilty for closing otherProcessHandle.
  2370. XRE_GetIOMessageLoop()->PostTask(
  2371. NewRunnableFunction(&ProcessWatcher::EnsureProcessTerminated,
  2372. otherProcessHandle, /*force=*/true));
  2373. }
  2374. bool
  2375. ContentParent::IsPreallocated() const
  2376. {
  2377. return mAppManifestURL == MAGIC_PREALLOCATED_APP_MANIFEST_URL;
  2378. }
  2379. void
  2380. ContentParent::FriendlyName(nsAString& aName, bool aAnonymize)
  2381. {
  2382. aName.Truncate();
  2383. if (IsPreallocated()) {
  2384. aName.AssignLiteral("(Preallocated)");
  2385. } else if (mIsForBrowser) {
  2386. aName.AssignLiteral("Browser");
  2387. } else if (aAnonymize) {
  2388. aName.AssignLiteral("<anonymized-name>");
  2389. } else if (!mAppName.IsEmpty()) {
  2390. aName = mAppName;
  2391. } else if (!mAppManifestURL.IsEmpty()) {
  2392. aName.AssignLiteral("Unknown app: ");
  2393. aName.Append(mAppManifestURL);
  2394. } else {
  2395. aName.AssignLiteral("???");
  2396. }
  2397. }
  2398. hal_sandbox::PHalParent*
  2399. ContentParent::AllocPHalParent()
  2400. {
  2401. return hal_sandbox::CreateHalParent();
  2402. }
  2403. bool
  2404. ContentParent::DeallocPHalParent(hal_sandbox::PHalParent* aHal)
  2405. {
  2406. delete aHal;
  2407. return true;
  2408. }
  2409. devtools::PHeapSnapshotTempFileHelperParent*
  2410. ContentParent::AllocPHeapSnapshotTempFileHelperParent()
  2411. {
  2412. return devtools::HeapSnapshotTempFileHelperParent::Create();
  2413. }
  2414. bool
  2415. ContentParent::DeallocPHeapSnapshotTempFileHelperParent(
  2416. devtools::PHeapSnapshotTempFileHelperParent* aHeapSnapshotHelper)
  2417. {
  2418. delete aHeapSnapshotHelper;
  2419. return true;
  2420. }
  2421. PMemoryReportRequestParent*
  2422. ContentParent::AllocPMemoryReportRequestParent(const uint32_t& aGeneration,
  2423. const bool &aAnonymize,
  2424. const bool &aMinimizeMemoryUsage,
  2425. const MaybeFileDesc &aDMDFile)
  2426. {
  2427. MemoryReportRequestParent* parent =
  2428. new MemoryReportRequestParent(aGeneration);
  2429. return parent;
  2430. }
  2431. bool
  2432. ContentParent::DeallocPMemoryReportRequestParent(PMemoryReportRequestParent* actor)
  2433. {
  2434. delete actor;
  2435. return true;
  2436. }
  2437. PCycleCollectWithLogsParent*
  2438. ContentParent::AllocPCycleCollectWithLogsParent(const bool& aDumpAllTraces,
  2439. const FileDescriptor& aGCLog,
  2440. const FileDescriptor& aCCLog)
  2441. {
  2442. MOZ_CRASH("Don't call this; use ContentParent::CycleCollectWithLogs");
  2443. }
  2444. bool
  2445. ContentParent::DeallocPCycleCollectWithLogsParent(PCycleCollectWithLogsParent* aActor)
  2446. {
  2447. delete aActor;
  2448. return true;
  2449. }
  2450. bool
  2451. ContentParent::CycleCollectWithLogs(bool aDumpAllTraces,
  2452. nsICycleCollectorLogSink* aSink,
  2453. nsIDumpGCAndCCLogsCallback* aCallback)
  2454. {
  2455. return CycleCollectWithLogsParent::AllocAndSendConstructor(this,
  2456. aDumpAllTraces,
  2457. aSink,
  2458. aCallback);
  2459. }
  2460. PTestShellParent*
  2461. ContentParent::AllocPTestShellParent()
  2462. {
  2463. return new TestShellParent();
  2464. }
  2465. bool
  2466. ContentParent::DeallocPTestShellParent(PTestShellParent* shell)
  2467. {
  2468. delete shell;
  2469. return true;
  2470. }
  2471. PNeckoParent*
  2472. ContentParent::AllocPNeckoParent()
  2473. {
  2474. return new NeckoParent();
  2475. }
  2476. bool
  2477. ContentParent::DeallocPNeckoParent(PNeckoParent* necko)
  2478. {
  2479. delete necko;
  2480. return true;
  2481. }
  2482. PPrintingParent*
  2483. ContentParent::AllocPPrintingParent()
  2484. {
  2485. #ifdef NS_PRINTING
  2486. MOZ_RELEASE_ASSERT(!mPrintingParent,
  2487. "Only one PrintingParent should be created per process.");
  2488. // Create the printing singleton for this process.
  2489. mPrintingParent = new PrintingParent();
  2490. // Take another reference for IPDL code.
  2491. mPrintingParent.get()->AddRef();
  2492. return mPrintingParent.get();
  2493. #else
  2494. MOZ_ASSERT_UNREACHABLE("Should never be created if no printing.");
  2495. return nullptr;
  2496. #endif
  2497. }
  2498. bool
  2499. ContentParent::DeallocPPrintingParent(PPrintingParent* printing)
  2500. {
  2501. #ifdef NS_PRINTING
  2502. MOZ_RELEASE_ASSERT(mPrintingParent == printing,
  2503. "Only one PrintingParent should have been created per process.");
  2504. // Release reference taken for IPDL code.
  2505. static_cast<PrintingParent*>(printing)->Release();
  2506. mPrintingParent = nullptr;
  2507. #else
  2508. MOZ_ASSERT_UNREACHABLE("Should never have been created if no printing.");
  2509. #endif
  2510. return true;
  2511. }
  2512. #ifdef NS_PRINTING
  2513. already_AddRefed<embedding::PrintingParent>
  2514. ContentParent::GetPrintingParent()
  2515. {
  2516. MOZ_ASSERT(mPrintingParent);
  2517. RefPtr<embedding::PrintingParent> printingParent = mPrintingParent;
  2518. return printingParent.forget();
  2519. }
  2520. #endif
  2521. PSendStreamParent*
  2522. ContentParent::AllocPSendStreamParent()
  2523. {
  2524. return nsIContentParent::AllocPSendStreamParent();
  2525. }
  2526. bool
  2527. ContentParent::DeallocPSendStreamParent(PSendStreamParent* aActor)
  2528. {
  2529. return nsIContentParent::DeallocPSendStreamParent(aActor);
  2530. }
  2531. PScreenManagerParent*
  2532. ContentParent::AllocPScreenManagerParent(uint32_t* aNumberOfScreens,
  2533. float* aSystemDefaultScale,
  2534. bool* aSuccess)
  2535. {
  2536. return new ScreenManagerParent(aNumberOfScreens, aSystemDefaultScale, aSuccess);
  2537. }
  2538. bool
  2539. ContentParent::DeallocPScreenManagerParent(PScreenManagerParent* aActor)
  2540. {
  2541. delete aActor;
  2542. return true;
  2543. }
  2544. PPSMContentDownloaderParent*
  2545. ContentParent::AllocPPSMContentDownloaderParent(const uint32_t& aCertType)
  2546. {
  2547. RefPtr<PSMContentDownloaderParent> downloader =
  2548. new PSMContentDownloaderParent(aCertType);
  2549. return downloader.forget().take();
  2550. }
  2551. bool
  2552. ContentParent::DeallocPPSMContentDownloaderParent(PPSMContentDownloaderParent* aListener)
  2553. {
  2554. auto* listener = static_cast<PSMContentDownloaderParent*>(aListener);
  2555. RefPtr<PSMContentDownloaderParent> downloader = dont_AddRef(listener);
  2556. return true;
  2557. }
  2558. PExternalHelperAppParent*
  2559. ContentParent::AllocPExternalHelperAppParent(const OptionalURIParams& uri,
  2560. const nsCString& aMimeContentType,
  2561. const nsCString& aContentDisposition,
  2562. const uint32_t& aContentDispositionHint,
  2563. const nsString& aContentDispositionFilename,
  2564. const bool& aForceSave,
  2565. const int64_t& aContentLength,
  2566. const bool& aWasFileChannel,
  2567. const OptionalURIParams& aReferrer,
  2568. PBrowserParent* aBrowser)
  2569. {
  2570. ExternalHelperAppParent *parent =
  2571. new ExternalHelperAppParent(uri, aContentLength, aWasFileChannel);
  2572. parent->AddRef();
  2573. parent->Init(this,
  2574. aMimeContentType,
  2575. aContentDisposition,
  2576. aContentDispositionHint,
  2577. aContentDispositionFilename,
  2578. aForceSave,
  2579. aReferrer,
  2580. aBrowser);
  2581. return parent;
  2582. }
  2583. bool
  2584. ContentParent::DeallocPExternalHelperAppParent(PExternalHelperAppParent* aService)
  2585. {
  2586. ExternalHelperAppParent *parent = static_cast<ExternalHelperAppParent *>(aService);
  2587. parent->Release();
  2588. return true;
  2589. }
  2590. PHandlerServiceParent*
  2591. ContentParent::AllocPHandlerServiceParent()
  2592. {
  2593. HandlerServiceParent* actor = new HandlerServiceParent();
  2594. actor->AddRef();
  2595. return actor;
  2596. }
  2597. bool
  2598. ContentParent::DeallocPHandlerServiceParent(PHandlerServiceParent* aHandlerServiceParent)
  2599. {
  2600. static_cast<HandlerServiceParent*>(aHandlerServiceParent)->Release();
  2601. return true;
  2602. }
  2603. media::PMediaParent*
  2604. ContentParent::AllocPMediaParent()
  2605. {
  2606. return media::AllocPMediaParent();
  2607. }
  2608. bool
  2609. ContentParent::DeallocPMediaParent(media::PMediaParent *aActor)
  2610. {
  2611. return media::DeallocPMediaParent(aActor);
  2612. }
  2613. PStorageParent*
  2614. ContentParent::AllocPStorageParent()
  2615. {
  2616. return new DOMStorageDBParent();
  2617. }
  2618. bool
  2619. ContentParent::DeallocPStorageParent(PStorageParent* aActor)
  2620. {
  2621. DOMStorageDBParent* child = static_cast<DOMStorageDBParent*>(aActor);
  2622. child->ReleaseIPDLReference();
  2623. return true;
  2624. }
  2625. PSpeechSynthesisParent*
  2626. ContentParent::AllocPSpeechSynthesisParent()
  2627. {
  2628. #ifdef MOZ_WEBSPEECH
  2629. return new mozilla::dom::SpeechSynthesisParent();
  2630. #else
  2631. return nullptr;
  2632. #endif
  2633. }
  2634. bool
  2635. ContentParent::DeallocPSpeechSynthesisParent(PSpeechSynthesisParent* aActor)
  2636. {
  2637. #ifdef MOZ_WEBSPEECH
  2638. delete aActor;
  2639. return true;
  2640. #else
  2641. return false;
  2642. #endif
  2643. }
  2644. bool
  2645. ContentParent::RecvPSpeechSynthesisConstructor(PSpeechSynthesisParent* aActor)
  2646. {
  2647. #ifdef MOZ_WEBSPEECH
  2648. return true;
  2649. #else
  2650. return false;
  2651. #endif
  2652. }
  2653. bool
  2654. ContentParent::RecvSpeakerManagerGetSpeakerStatus(bool* aValue)
  2655. {
  2656. return false;
  2657. }
  2658. bool
  2659. ContentParent::RecvSpeakerManagerForceSpeaker(const bool& aEnable)
  2660. {
  2661. return false;
  2662. }
  2663. bool
  2664. ContentParent::RecvStartVisitedQuery(const URIParams& aURI)
  2665. {
  2666. nsCOMPtr<nsIURI> newURI = DeserializeURI(aURI);
  2667. if (!newURI) {
  2668. return false;
  2669. }
  2670. nsCOMPtr<IHistory> history = services::GetHistoryService();
  2671. if (history) {
  2672. history->RegisterVisitedCallback(newURI, nullptr);
  2673. }
  2674. return true;
  2675. }
  2676. bool
  2677. ContentParent::RecvVisitURI(const URIParams& uri,
  2678. const OptionalURIParams& referrer,
  2679. const uint32_t& flags)
  2680. {
  2681. nsCOMPtr<nsIURI> ourURI = DeserializeURI(uri);
  2682. if (!ourURI) {
  2683. return false;
  2684. }
  2685. nsCOMPtr<nsIURI> ourReferrer = DeserializeURI(referrer);
  2686. nsCOMPtr<IHistory> history = services::GetHistoryService();
  2687. if (history) {
  2688. history->VisitURI(ourURI, ourReferrer, flags);
  2689. }
  2690. return true;
  2691. }
  2692. bool
  2693. ContentParent::RecvSetURITitle(const URIParams& uri,
  2694. const nsString& title)
  2695. {
  2696. nsCOMPtr<nsIURI> ourURI = DeserializeURI(uri);
  2697. if (!ourURI) {
  2698. return false;
  2699. }
  2700. nsCOMPtr<IHistory> history = services::GetHistoryService();
  2701. if (history) {
  2702. history->SetURITitle(ourURI, title);
  2703. }
  2704. return true;
  2705. }
  2706. bool
  2707. ContentParent::RecvNSSU2FTokenIsCompatibleVersion(const nsString& aVersion,
  2708. bool* aIsCompatible)
  2709. {
  2710. MOZ_ASSERT(aIsCompatible);
  2711. nsCOMPtr<nsINSSU2FToken> nssToken(do_GetService(NS_NSSU2FTOKEN_CONTRACTID));
  2712. if (NS_WARN_IF(!nssToken)) {
  2713. return false;
  2714. }
  2715. nsresult rv = nssToken->IsCompatibleVersion(aVersion, aIsCompatible);
  2716. return NS_SUCCEEDED(rv);
  2717. }
  2718. bool
  2719. ContentParent::RecvNSSU2FTokenIsRegistered(nsTArray<uint8_t>&& aKeyHandle,
  2720. bool* aIsValidKeyHandle)
  2721. {
  2722. MOZ_ASSERT(aIsValidKeyHandle);
  2723. nsCOMPtr<nsINSSU2FToken> nssToken(do_GetService(NS_NSSU2FTOKEN_CONTRACTID));
  2724. if (NS_WARN_IF(!nssToken)) {
  2725. return false;
  2726. }
  2727. nsresult rv = nssToken->IsRegistered(aKeyHandle.Elements(), aKeyHandle.Length(),
  2728. aIsValidKeyHandle);
  2729. return NS_SUCCEEDED(rv);
  2730. }
  2731. bool
  2732. ContentParent::RecvNSSU2FTokenRegister(nsTArray<uint8_t>&& aApplication,
  2733. nsTArray<uint8_t>&& aChallenge,
  2734. nsTArray<uint8_t>* aRegistration)
  2735. {
  2736. MOZ_ASSERT(aRegistration);
  2737. nsCOMPtr<nsINSSU2FToken> nssToken(do_GetService(NS_NSSU2FTOKEN_CONTRACTID));
  2738. if (NS_WARN_IF(!nssToken)) {
  2739. return false;
  2740. }
  2741. uint8_t* buffer;
  2742. uint32_t bufferlen;
  2743. nsresult rv = nssToken->Register(aApplication.Elements(), aApplication.Length(),
  2744. aChallenge.Elements(), aChallenge.Length(),
  2745. &buffer, &bufferlen);
  2746. if (NS_WARN_IF(NS_FAILED(rv))) {
  2747. return false;
  2748. }
  2749. MOZ_ASSERT(buffer);
  2750. aRegistration->ReplaceElementsAt(0, aRegistration->Length(), buffer, bufferlen);
  2751. free(buffer);
  2752. return NS_SUCCEEDED(rv);
  2753. }
  2754. bool
  2755. ContentParent::RecvNSSU2FTokenSign(nsTArray<uint8_t>&& aApplication,
  2756. nsTArray<uint8_t>&& aChallenge,
  2757. nsTArray<uint8_t>&& aKeyHandle,
  2758. nsTArray<uint8_t>* aSignature)
  2759. {
  2760. MOZ_ASSERT(aSignature);
  2761. nsCOMPtr<nsINSSU2FToken> nssToken(do_GetService(NS_NSSU2FTOKEN_CONTRACTID));
  2762. if (NS_WARN_IF(!nssToken)) {
  2763. return false;
  2764. }
  2765. uint8_t* buffer;
  2766. uint32_t bufferlen;
  2767. nsresult rv = nssToken->Sign(aApplication.Elements(), aApplication.Length(),
  2768. aChallenge.Elements(), aChallenge.Length(),
  2769. aKeyHandle.Elements(), aKeyHandle.Length(),
  2770. &buffer, &bufferlen);
  2771. if (NS_WARN_IF(NS_FAILED(rv))) {
  2772. return false;
  2773. }
  2774. MOZ_ASSERT(buffer);
  2775. aSignature->ReplaceElementsAt(0, aSignature->Length(), buffer, bufferlen);
  2776. free(buffer);
  2777. return NS_SUCCEEDED(rv);
  2778. }
  2779. bool
  2780. ContentParent::RecvGetLookAndFeelCache(nsTArray<LookAndFeelInt>* aLookAndFeelIntCache)
  2781. {
  2782. *aLookAndFeelIntCache = LookAndFeel::GetIntCache();
  2783. return true;
  2784. }
  2785. bool
  2786. ContentParent::RecvIsSecureURI(const uint32_t& type,
  2787. const URIParams& uri,
  2788. const uint32_t& flags,
  2789. bool* isSecureURI)
  2790. {
  2791. nsCOMPtr<nsISiteSecurityService> sss(do_GetService(NS_SSSERVICE_CONTRACTID));
  2792. if (!sss) {
  2793. return false;
  2794. }
  2795. nsCOMPtr<nsIURI> ourURI = DeserializeURI(uri);
  2796. if (!ourURI) {
  2797. return false;
  2798. }
  2799. nsresult rv = sss->IsSecureURI(type, ourURI, flags, nullptr, isSecureURI);
  2800. return NS_SUCCEEDED(rv);
  2801. }
  2802. bool
  2803. ContentParent::RecvLoadURIExternal(const URIParams& uri,
  2804. PBrowserParent* windowContext)
  2805. {
  2806. nsCOMPtr<nsIExternalProtocolService> extProtService(do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID));
  2807. if (!extProtService) {
  2808. return true;
  2809. }
  2810. nsCOMPtr<nsIURI> ourURI = DeserializeURI(uri);
  2811. if (!ourURI) {
  2812. return false;
  2813. }
  2814. RefPtr<RemoteWindowContext> context =
  2815. new RemoteWindowContext(static_cast<TabParent*>(windowContext));
  2816. extProtService->LoadURI(ourURI, context);
  2817. return true;
  2818. }
  2819. bool
  2820. ContentParent::RecvExtProtocolChannelConnectParent(const uint32_t& registrarId)
  2821. {
  2822. nsresult rv;
  2823. // First get the real channel created before redirect on the parent.
  2824. nsCOMPtr<nsIChannel> channel;
  2825. rv = NS_LinkRedirectChannels(registrarId, nullptr, getter_AddRefs(channel));
  2826. NS_ENSURE_SUCCESS(rv, true);
  2827. nsCOMPtr<nsIParentChannel> parent = do_QueryInterface(channel, &rv);
  2828. NS_ENSURE_SUCCESS(rv, true);
  2829. // The channel itself is its own (faked) parent, link it.
  2830. rv = NS_LinkRedirectChannels(registrarId, parent, getter_AddRefs(channel));
  2831. NS_ENSURE_SUCCESS(rv, true);
  2832. // Signal the parent channel that it's a redirect-to parent. This will
  2833. // make AsyncOpen on it do nothing (what we want).
  2834. // Yes, this is a bit of a hack, but I don't think it's necessary to invent
  2835. // a new interface just to set this flag on the channel.
  2836. parent->SetParentListener(nullptr);
  2837. return true;
  2838. }
  2839. bool
  2840. ContentParent::HasNotificationPermission(const IPC::Principal& aPrincipal)
  2841. {
  2842. return true;
  2843. }
  2844. bool
  2845. ContentParent::RecvShowAlert(const AlertNotificationType& aAlert)
  2846. {
  2847. nsCOMPtr<nsIAlertNotification> alert(dont_AddRef(aAlert));
  2848. if (NS_WARN_IF(!alert)) {
  2849. return true;
  2850. }
  2851. nsCOMPtr<nsIPrincipal> principal;
  2852. nsresult rv = alert->GetPrincipal(getter_AddRefs(principal));
  2853. if (NS_WARN_IF(NS_FAILED(rv)) ||
  2854. !HasNotificationPermission(IPC::Principal(principal))) {
  2855. return true;
  2856. }
  2857. nsCOMPtr<nsIAlertsService> sysAlerts(do_GetService(NS_ALERTSERVICE_CONTRACTID));
  2858. if (sysAlerts) {
  2859. sysAlerts->ShowAlert(alert, this);
  2860. }
  2861. return true;
  2862. }
  2863. bool
  2864. ContentParent::RecvCloseAlert(const nsString& aName,
  2865. const IPC::Principal& aPrincipal)
  2866. {
  2867. if (!HasNotificationPermission(aPrincipal)) {
  2868. return true;
  2869. }
  2870. nsCOMPtr<nsIAlertsService> sysAlerts(do_GetService(NS_ALERTSERVICE_CONTRACTID));
  2871. if (sysAlerts) {
  2872. sysAlerts->CloseAlert(aName, aPrincipal);
  2873. }
  2874. return true;
  2875. }
  2876. bool
  2877. ContentParent::RecvDisableNotifications(const IPC::Principal& aPrincipal)
  2878. {
  2879. if (HasNotificationPermission(aPrincipal)) {
  2880. Unused << Notification::RemovePermission(aPrincipal);
  2881. }
  2882. return true;
  2883. }
  2884. bool
  2885. ContentParent::RecvOpenNotificationSettings(const IPC::Principal& aPrincipal)
  2886. {
  2887. if (HasNotificationPermission(aPrincipal)) {
  2888. Unused << Notification::OpenSettings(aPrincipal);
  2889. }
  2890. return true;
  2891. }
  2892. bool
  2893. ContentParent::RecvSyncMessage(const nsString& aMsg,
  2894. const ClonedMessageData& aData,
  2895. InfallibleTArray<CpowEntry>&& aCpows,
  2896. const IPC::Principal& aPrincipal,
  2897. nsTArray<StructuredCloneData>* aRetvals)
  2898. {
  2899. return nsIContentParent::RecvSyncMessage(aMsg, aData, Move(aCpows),
  2900. aPrincipal, aRetvals);
  2901. }
  2902. bool
  2903. ContentParent::RecvRpcMessage(const nsString& aMsg,
  2904. const ClonedMessageData& aData,
  2905. InfallibleTArray<CpowEntry>&& aCpows,
  2906. const IPC::Principal& aPrincipal,
  2907. nsTArray<StructuredCloneData>* aRetvals)
  2908. {
  2909. return nsIContentParent::RecvRpcMessage(aMsg, aData, Move(aCpows), aPrincipal,
  2910. aRetvals);
  2911. }
  2912. bool
  2913. ContentParent::RecvAsyncMessage(const nsString& aMsg,
  2914. InfallibleTArray<CpowEntry>&& aCpows,
  2915. const IPC::Principal& aPrincipal,
  2916. const ClonedMessageData& aData)
  2917. {
  2918. return nsIContentParent::RecvAsyncMessage(aMsg, Move(aCpows), aPrincipal,
  2919. aData);
  2920. }
  2921. static int32_t
  2922. AddGeolocationListener(nsIDOMGeoPositionCallback* watcher,
  2923. nsIDOMGeoPositionErrorCallback* errorCallBack,
  2924. bool highAccuracy)
  2925. {
  2926. nsCOMPtr<nsIDOMGeoGeolocation> geo = do_GetService("@mozilla.org/geolocation;1");
  2927. if (!geo) {
  2928. return -1;
  2929. }
  2930. UniquePtr<PositionOptions> options = MakeUnique<PositionOptions>();
  2931. options->mTimeout = 0;
  2932. options->mMaximumAge = 0;
  2933. options->mEnableHighAccuracy = highAccuracy;
  2934. int32_t retval = 1;
  2935. geo->WatchPosition(watcher, errorCallBack, Move(options), &retval);
  2936. return retval;
  2937. }
  2938. bool
  2939. ContentParent::RecvAddGeolocationListener(const IPC::Principal& aPrincipal,
  2940. const bool& aHighAccuracy)
  2941. {
  2942. // To ensure no geolocation updates are skipped, we always force the
  2943. // creation of a new listener.
  2944. RecvRemoveGeolocationListener();
  2945. mGeolocationWatchID = AddGeolocationListener(this, this, aHighAccuracy);
  2946. return true;
  2947. }
  2948. bool
  2949. ContentParent::RecvRemoveGeolocationListener()
  2950. {
  2951. if (mGeolocationWatchID != -1) {
  2952. nsCOMPtr<nsIDOMGeoGeolocation> geo = do_GetService("@mozilla.org/geolocation;1");
  2953. if (!geo) {
  2954. return true;
  2955. }
  2956. geo->ClearWatch(mGeolocationWatchID);
  2957. mGeolocationWatchID = -1;
  2958. }
  2959. return true;
  2960. }
  2961. bool
  2962. ContentParent::RecvSetGeolocationHigherAccuracy(const bool& aEnable)
  2963. {
  2964. // This should never be called without a listener already present,
  2965. // so this check allows us to forgo securing privileges.
  2966. if (mGeolocationWatchID != -1) {
  2967. RecvRemoveGeolocationListener();
  2968. mGeolocationWatchID = AddGeolocationListener(this, this, aEnable);
  2969. }
  2970. return true;
  2971. }
  2972. NS_IMETHODIMP
  2973. ContentParent::HandleEvent(nsIDOMGeoPosition* postion)
  2974. {
  2975. Unused << SendGeolocationUpdate(GeoPosition(postion));
  2976. return NS_OK;
  2977. }
  2978. NS_IMETHODIMP
  2979. ContentParent::HandleEvent(nsIDOMGeoPositionError* postionError)
  2980. {
  2981. int16_t errorCode;
  2982. nsresult rv;
  2983. rv = postionError->GetCode(&errorCode);
  2984. NS_ENSURE_SUCCESS(rv,rv);
  2985. Unused << SendGeolocationError(errorCode);
  2986. return NS_OK;
  2987. }
  2988. nsConsoleService *
  2989. ContentParent::GetConsoleService()
  2990. {
  2991. if (mConsoleService) {
  2992. return mConsoleService.get();
  2993. }
  2994. // XXXkhuey everything about this is terrible.
  2995. // Get the ConsoleService by CID rather than ContractID, so that we
  2996. // can cast the returned pointer to an nsConsoleService (rather than
  2997. // just an nsIConsoleService). This allows us to call the non-idl function
  2998. // nsConsoleService::LogMessageWithMode.
  2999. NS_DEFINE_CID(consoleServiceCID, NS_CONSOLESERVICE_CID);
  3000. nsCOMPtr<nsIConsoleService> consoleService(do_GetService(consoleServiceCID));
  3001. mConsoleService = static_cast<nsConsoleService*>(consoleService.get());
  3002. return mConsoleService.get();
  3003. }
  3004. bool
  3005. ContentParent::RecvConsoleMessage(const nsString& aMessage)
  3006. {
  3007. RefPtr<nsConsoleService> consoleService = GetConsoleService();
  3008. if (!consoleService) {
  3009. return true;
  3010. }
  3011. RefPtr<nsConsoleMessage> msg(new nsConsoleMessage(aMessage.get()));
  3012. consoleService->LogMessageWithMode(msg, nsConsoleService::SuppressLog);
  3013. return true;
  3014. }
  3015. bool
  3016. ContentParent::RecvScriptError(const nsString& aMessage,
  3017. const nsString& aSourceName,
  3018. const nsString& aSourceLine,
  3019. const uint32_t& aLineNumber,
  3020. const uint32_t& aColNumber,
  3021. const uint32_t& aFlags,
  3022. const nsCString& aCategory)
  3023. {
  3024. RefPtr<nsConsoleService> consoleService = GetConsoleService();
  3025. if (!consoleService) {
  3026. return true;
  3027. }
  3028. nsCOMPtr<nsIScriptError> msg(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
  3029. nsresult rv = msg->Init(aMessage, aSourceName, aSourceLine,
  3030. aLineNumber, aColNumber, aFlags, aCategory.get());
  3031. if (NS_FAILED(rv))
  3032. return true;
  3033. consoleService->LogMessageWithMode(msg, nsConsoleService::SuppressLog);
  3034. return true;
  3035. }
  3036. bool
  3037. ContentParent::RecvPrivateDocShellsExist(const bool& aExist)
  3038. {
  3039. if (!sPrivateContent)
  3040. sPrivateContent = new nsTArray<ContentParent*>();
  3041. if (aExist) {
  3042. sPrivateContent->AppendElement(this);
  3043. } else {
  3044. sPrivateContent->RemoveElement(this);
  3045. // Only fire the notification if we have private and non-private
  3046. // windows: if privatebrowsing.autostart is true, all windows are
  3047. // private.
  3048. if (!sPrivateContent->Length() &&
  3049. !Preferences::GetBool("browser.privatebrowsing.autostart")) {
  3050. nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
  3051. obs->NotifyObservers(nullptr, "last-pb-context-exited", nullptr);
  3052. delete sPrivateContent;
  3053. sPrivateContent = nullptr;
  3054. }
  3055. }
  3056. return true;
  3057. }
  3058. bool
  3059. ContentParent::DoLoadMessageManagerScript(const nsAString& aURL,
  3060. bool aRunInGlobalScope)
  3061. {
  3062. MOZ_ASSERT(!aRunInGlobalScope);
  3063. return SendLoadProcessScript(nsString(aURL));
  3064. }
  3065. nsresult
  3066. ContentParent::DoSendAsyncMessage(JSContext* aCx,
  3067. const nsAString& aMessage,
  3068. StructuredCloneData& aHelper,
  3069. JS::Handle<JSObject *> aCpows,
  3070. nsIPrincipal* aPrincipal)
  3071. {
  3072. ClonedMessageData data;
  3073. if (!BuildClonedMessageDataForParent(this, aHelper, data)) {
  3074. return NS_ERROR_DOM_DATA_CLONE_ERR;
  3075. }
  3076. InfallibleTArray<CpowEntry> cpows;
  3077. jsipc::CPOWManager* mgr = GetCPOWManager();
  3078. if (aCpows && (!mgr || !mgr->Wrap(aCx, aCpows, &cpows))) {
  3079. return NS_ERROR_UNEXPECTED;
  3080. }
  3081. if (!SendAsyncMessage(nsString(aMessage), cpows, Principal(aPrincipal), data)) {
  3082. return NS_ERROR_UNEXPECTED;
  3083. }
  3084. return NS_OK;
  3085. }
  3086. bool
  3087. ContentParent::CheckPermission(const nsAString& aPermission)
  3088. {
  3089. return AssertAppProcessPermission(this, NS_ConvertUTF16toUTF8(aPermission).get());
  3090. }
  3091. bool
  3092. ContentParent::CheckManifestURL(const nsAString& aManifestURL)
  3093. {
  3094. return AssertAppProcessManifestURL(this, NS_ConvertUTF16toUTF8(aManifestURL).get());
  3095. }
  3096. bool
  3097. ContentParent::CheckAppHasPermission(const nsAString& aPermission)
  3098. {
  3099. return AssertAppHasPermission(this, NS_ConvertUTF16toUTF8(aPermission).get());
  3100. }
  3101. bool
  3102. ContentParent::CheckAppHasStatus(unsigned short aStatus)
  3103. {
  3104. return AssertAppHasStatus(this, aStatus);
  3105. }
  3106. bool
  3107. ContentParent::KillChild()
  3108. {
  3109. KillHard("KillChild");
  3110. return true;
  3111. }
  3112. PBlobParent*
  3113. ContentParent::SendPBlobConstructor(PBlobParent* aActor,
  3114. const BlobConstructorParams& aParams)
  3115. {
  3116. return PContentParent::SendPBlobConstructor(aActor, aParams);
  3117. }
  3118. PBrowserParent*
  3119. ContentParent::SendPBrowserConstructor(PBrowserParent* aActor,
  3120. const TabId& aTabId,
  3121. const IPCTabContext& aContext,
  3122. const uint32_t& aChromeFlags,
  3123. const ContentParentId& aCpId,
  3124. const bool& aIsForApp,
  3125. const bool& aIsForBrowser)
  3126. {
  3127. return PContentParent::SendPBrowserConstructor(aActor,
  3128. aTabId,
  3129. aContext,
  3130. aChromeFlags,
  3131. aCpId,
  3132. aIsForApp,
  3133. aIsForBrowser);
  3134. }
  3135. bool
  3136. ContentParent::RecvCreateFakeVolume(const nsString& fsName,
  3137. const nsString& mountPoint)
  3138. {
  3139. NS_WARNING("ContentParent::RecvCreateFakeVolume shouldn't be called");
  3140. return false;
  3141. }
  3142. bool
  3143. ContentParent::RecvSetFakeVolumeState(const nsString& fsName, const int32_t& fsState)
  3144. {
  3145. NS_WARNING("ContentParent::RecvSetFakeVolumeState shouldn't be called");
  3146. return false;
  3147. }
  3148. bool
  3149. ContentParent::RecvRemoveFakeVolume(const nsString& fsName)
  3150. {
  3151. NS_WARNING("ContentParent::RecvRemoveFakeVolume shouldn't be called");
  3152. return false;
  3153. }
  3154. bool
  3155. ContentParent::RecvKeywordToURI(const nsCString& aKeyword,
  3156. nsString* aProviderName,
  3157. OptionalInputStreamParams* aPostData,
  3158. OptionalURIParams* aURI)
  3159. {
  3160. *aPostData = void_t();
  3161. *aURI = void_t();
  3162. nsCOMPtr<nsIURIFixup> fixup = do_GetService(NS_URIFIXUP_CONTRACTID);
  3163. if (!fixup) {
  3164. return true;
  3165. }
  3166. nsCOMPtr<nsIInputStream> postData;
  3167. nsCOMPtr<nsIURIFixupInfo> info;
  3168. if (NS_FAILED(fixup->KeywordToURI(aKeyword, getter_AddRefs(postData),
  3169. getter_AddRefs(info)))) {
  3170. return true;
  3171. }
  3172. info->GetKeywordProviderName(*aProviderName);
  3173. nsTArray<mozilla::ipc::FileDescriptor> fds;
  3174. SerializeInputStream(postData, *aPostData, fds);
  3175. MOZ_ASSERT(fds.IsEmpty());
  3176. nsCOMPtr<nsIURI> uri;
  3177. info->GetPreferredURI(getter_AddRefs(uri));
  3178. SerializeURI(uri, *aURI);
  3179. return true;
  3180. }
  3181. bool
  3182. ContentParent::RecvNotifyKeywordSearchLoading(const nsString &aProvider,
  3183. const nsString &aKeyword)
  3184. {
  3185. #ifdef MOZ_TOOLKIT_SEARCH
  3186. nsCOMPtr<nsIBrowserSearchService> searchSvc = do_GetService("@mozilla.org/browser/search-service;1");
  3187. if (searchSvc) {
  3188. nsCOMPtr<nsISearchEngine> searchEngine;
  3189. searchSvc->GetEngineByName(aProvider, getter_AddRefs(searchEngine));
  3190. if (searchEngine) {
  3191. nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
  3192. if (obsSvc) {
  3193. // Note that "keyword-search" refers to a search via the url
  3194. // bar, not a bookmarks keyword search.
  3195. obsSvc->NotifyObservers(searchEngine, "keyword-search", aKeyword.get());
  3196. }
  3197. }
  3198. }
  3199. #endif
  3200. return true;
  3201. }
  3202. bool
  3203. ContentParent::RecvCopyFavicon(const URIParams& aOldURI,
  3204. const URIParams& aNewURI,
  3205. const IPC::Principal& aLoadingPrincipal,
  3206. const bool& aInPrivateBrowsing)
  3207. {
  3208. nsCOMPtr<nsIURI> oldURI = DeserializeURI(aOldURI);
  3209. if (!oldURI) {
  3210. return true;
  3211. }
  3212. nsCOMPtr<nsIURI> newURI = DeserializeURI(aNewURI);
  3213. if (!newURI) {
  3214. return true;
  3215. }
  3216. nsDocShell::CopyFavicon(oldURI, newURI, aLoadingPrincipal, aInPrivateBrowsing);
  3217. return true;
  3218. }
  3219. bool
  3220. ContentParent::ShouldContinueFromReplyTimeout()
  3221. {
  3222. RefPtr<ProcessHangMonitor> monitor = ProcessHangMonitor::Get();
  3223. return !monitor || !monitor->ShouldTimeOutCPOWs();
  3224. }
  3225. bool
  3226. ContentParent::RecvRecordingDeviceEvents(const nsString& aRecordingStatus,
  3227. const nsString& aPageURL,
  3228. const bool& aIsAudio,
  3229. const bool& aIsVideo)
  3230. {
  3231. nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
  3232. if (obs) {
  3233. // recording-device-ipc-events needs to gather more information from content process
  3234. RefPtr<nsHashPropertyBag> props = new nsHashPropertyBag();
  3235. props->SetPropertyAsUint64(NS_LITERAL_STRING("childID"), ChildID());
  3236. props->SetPropertyAsBool(NS_LITERAL_STRING("isApp"), IsForApp());
  3237. props->SetPropertyAsBool(NS_LITERAL_STRING("isAudio"), aIsAudio);
  3238. props->SetPropertyAsBool(NS_LITERAL_STRING("isVideo"), aIsVideo);
  3239. nsString requestURL = IsForApp() ? AppManifestURL() : aPageURL;
  3240. props->SetPropertyAsAString(NS_LITERAL_STRING("requestURL"), requestURL);
  3241. obs->NotifyObservers((nsIPropertyBag2*) props,
  3242. "recording-device-ipc-events",
  3243. aRecordingStatus.get());
  3244. } else {
  3245. NS_WARNING("Could not get the Observer service for ContentParent::RecvRecordingDeviceEvents.");
  3246. }
  3247. return true;
  3248. }
  3249. bool
  3250. ContentParent::RecvGetGraphicsFeatureStatus(const int32_t& aFeature,
  3251. int32_t* aStatus,
  3252. nsCString* aFailureId,
  3253. bool* aSuccess)
  3254. {
  3255. nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
  3256. if (!gfxInfo) {
  3257. *aSuccess = false;
  3258. return true;
  3259. }
  3260. *aSuccess = NS_SUCCEEDED(gfxInfo->GetFeatureStatus(aFeature, *aFailureId, aStatus));
  3261. return true;
  3262. }
  3263. bool
  3264. ContentParent::RecvAddIdleObserver(const uint64_t& aObserver,
  3265. const uint32_t& aIdleTimeInS)
  3266. {
  3267. nsresult rv;
  3268. nsCOMPtr<nsIIdleService> idleService =
  3269. do_GetService("@mozilla.org/widget/idleservice;1", &rv);
  3270. NS_ENSURE_SUCCESS(rv, false);
  3271. RefPtr<ParentIdleListener> listener =
  3272. new ParentIdleListener(this, aObserver, aIdleTimeInS);
  3273. rv = idleService->AddIdleObserver(listener, aIdleTimeInS);
  3274. NS_ENSURE_SUCCESS(rv, false);
  3275. mIdleListeners.AppendElement(listener);
  3276. return true;
  3277. }
  3278. bool
  3279. ContentParent::RecvRemoveIdleObserver(const uint64_t& aObserver,
  3280. const uint32_t& aIdleTimeInS)
  3281. {
  3282. RefPtr<ParentIdleListener> listener;
  3283. for (int32_t i = mIdleListeners.Length() - 1; i >= 0; --i) {
  3284. listener = static_cast<ParentIdleListener*>(mIdleListeners[i].get());
  3285. if (listener->mObserver == aObserver &&
  3286. listener->mTime == aIdleTimeInS) {
  3287. nsresult rv;
  3288. nsCOMPtr<nsIIdleService> idleService =
  3289. do_GetService("@mozilla.org/widget/idleservice;1", &rv);
  3290. NS_ENSURE_SUCCESS(rv, false);
  3291. idleService->RemoveIdleObserver(listener, aIdleTimeInS);
  3292. mIdleListeners.RemoveElementAt(i);
  3293. break;
  3294. }
  3295. }
  3296. return true;
  3297. }
  3298. bool
  3299. ContentParent::RecvBackUpXResources(const FileDescriptor& aXSocketFd)
  3300. {
  3301. #ifndef MOZ_X11
  3302. NS_RUNTIMEABORT("This message only makes sense on X11 platforms");
  3303. #else
  3304. MOZ_ASSERT(0 > mChildXSocketFdDup.get(),
  3305. "Already backed up X resources??");
  3306. if (aXSocketFd.IsValid()) {
  3307. auto rawFD = aXSocketFd.ClonePlatformHandle();
  3308. mChildXSocketFdDup.reset(rawFD.release());
  3309. }
  3310. #endif
  3311. return true;
  3312. }
  3313. bool
  3314. ContentParent::RecvOpenAnonymousTemporaryFile(FileDescOrError *aFD)
  3315. {
  3316. PRFileDesc *prfd;
  3317. nsresult rv = NS_OpenAnonymousTemporaryFile(&prfd);
  3318. if (NS_WARN_IF(NS_FAILED(rv))) {
  3319. // Returning false will kill the child process; instead
  3320. // propagate the error and let the child handle it.
  3321. *aFD = rv;
  3322. return true;
  3323. }
  3324. *aFD = FileDescriptor(FileDescriptor::PlatformHandleType(PR_FileDesc2NativeHandle(prfd)));
  3325. // The FileDescriptor object owns a duplicate of the file handle; we
  3326. // must close the original (and clean up the NSPR descriptor).
  3327. PR_Close(prfd);
  3328. return true;
  3329. }
  3330. static NS_DEFINE_CID(kFormProcessorCID, NS_FORMPROCESSOR_CID);
  3331. bool
  3332. ContentParent::RecvKeygenProcessValue(const nsString& oldValue,
  3333. const nsString& challenge,
  3334. const nsString& keytype,
  3335. const nsString& keyparams,
  3336. nsString* newValue)
  3337. {
  3338. nsCOMPtr<nsIFormProcessor> formProcessor =
  3339. do_GetService(kFormProcessorCID);
  3340. if (!formProcessor) {
  3341. newValue->Truncate();
  3342. return true;
  3343. }
  3344. formProcessor->ProcessValueIPC(oldValue, challenge, keytype, keyparams,
  3345. *newValue);
  3346. return true;
  3347. }
  3348. bool
  3349. ContentParent::RecvKeygenProvideContent(nsString* aAttribute,
  3350. nsTArray<nsString>* aContent)
  3351. {
  3352. nsCOMPtr<nsIFormProcessor> formProcessor =
  3353. do_GetService(kFormProcessorCID);
  3354. if (!formProcessor) {
  3355. return true;
  3356. }
  3357. formProcessor->ProvideContent(NS_LITERAL_STRING("SELECT"), *aContent,
  3358. *aAttribute);
  3359. return true;
  3360. }
  3361. PFileDescriptorSetParent*
  3362. ContentParent::AllocPFileDescriptorSetParent(const FileDescriptor& aFD)
  3363. {
  3364. return nsIContentParent::AllocPFileDescriptorSetParent(aFD);
  3365. }
  3366. bool
  3367. ContentParent::DeallocPFileDescriptorSetParent(PFileDescriptorSetParent* aActor)
  3368. {
  3369. return nsIContentParent::DeallocPFileDescriptorSetParent(aActor);
  3370. }
  3371. bool
  3372. ContentParent::IgnoreIPCPrincipal()
  3373. {
  3374. static bool sDidAddVarCache = false;
  3375. static bool sIgnoreIPCPrincipal = false;
  3376. if (!sDidAddVarCache) {
  3377. sDidAddVarCache = true;
  3378. Preferences::AddBoolVarCache(&sIgnoreIPCPrincipal,
  3379. "dom.testing.ignore_ipc_principal", false);
  3380. }
  3381. return sIgnoreIPCPrincipal;
  3382. }
  3383. void
  3384. ContentParent::NotifyUpdatedDictionaries()
  3385. {
  3386. nsCOMPtr<nsISpellChecker> spellChecker(do_GetService(NS_SPELLCHECKER_CONTRACTID));
  3387. MOZ_ASSERT(spellChecker, "No spell checker?");
  3388. InfallibleTArray<nsString> dictionaries;
  3389. spellChecker->GetDictionaryList(&dictionaries);
  3390. for (auto* cp : AllProcesses(eLive)) {
  3391. Unused << cp->SendUpdateDictionaryList(dictionaries);
  3392. }
  3393. }
  3394. /*static*/ TabId
  3395. ContentParent::AllocateTabId(const TabId& aOpenerTabId,
  3396. const IPCTabContext& aContext,
  3397. const ContentParentId& aCpId)
  3398. {
  3399. TabId tabId;
  3400. if (XRE_IsParentProcess()) {
  3401. ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
  3402. tabId = cpm->AllocateTabId(aOpenerTabId, aContext, aCpId);
  3403. }
  3404. else {
  3405. ContentChild::GetSingleton()->SendAllocateTabId(aOpenerTabId,
  3406. aContext,
  3407. aCpId,
  3408. &tabId);
  3409. }
  3410. return tabId;
  3411. }
  3412. /*static*/ void
  3413. ContentParent::DeallocateTabId(const TabId& aTabId,
  3414. const ContentParentId& aCpId,
  3415. bool aMarkedDestroying)
  3416. {
  3417. if (XRE_IsParentProcess()) {
  3418. ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
  3419. ContentParent* cp = cpm->GetContentProcessById(aCpId);
  3420. cp->NotifyTabDestroyed(aTabId, aMarkedDestroying);
  3421. ContentProcessManager::GetSingleton()->DeallocateTabId(aCpId, aTabId);
  3422. } else {
  3423. ContentChild::GetSingleton()->SendDeallocateTabId(aTabId, aCpId,
  3424. aMarkedDestroying);
  3425. }
  3426. }
  3427. bool
  3428. ContentParent::RecvAllocateTabId(const TabId& aOpenerTabId,
  3429. const IPCTabContext& aContext,
  3430. const ContentParentId& aCpId,
  3431. TabId* aTabId)
  3432. {
  3433. *aTabId = AllocateTabId(aOpenerTabId, aContext, aCpId);
  3434. if (!(*aTabId)) {
  3435. return false;
  3436. }
  3437. return true;
  3438. }
  3439. bool
  3440. ContentParent::RecvDeallocateTabId(const TabId& aTabId,
  3441. const ContentParentId& aCpId,
  3442. const bool& aMarkedDestroying)
  3443. {
  3444. DeallocateTabId(aTabId, aCpId, aMarkedDestroying);
  3445. return true;
  3446. }
  3447. bool
  3448. ContentParent::RecvNotifyTabDestroying(const TabId& aTabId,
  3449. const ContentParentId& aCpId)
  3450. {
  3451. NotifyTabDestroying(aTabId, aCpId);
  3452. return true;
  3453. }
  3454. nsTArray<TabContext>
  3455. ContentParent::GetManagedTabContext()
  3456. {
  3457. return Move(ContentProcessManager::GetSingleton()->
  3458. GetTabContextByContentProcess(this->ChildID()));
  3459. }
  3460. mozilla::docshell::POfflineCacheUpdateParent*
  3461. ContentParent::AllocPOfflineCacheUpdateParent(const URIParams& aManifestURI,
  3462. const URIParams& aDocumentURI,
  3463. const PrincipalInfo& aLoadingPrincipalInfo,
  3464. const bool& aStickDocument)
  3465. {
  3466. RefPtr<mozilla::docshell::OfflineCacheUpdateParent> update =
  3467. new mozilla::docshell::OfflineCacheUpdateParent();
  3468. // Use this reference as the IPDL reference.
  3469. return update.forget().take();
  3470. }
  3471. bool
  3472. ContentParent::RecvPOfflineCacheUpdateConstructor(POfflineCacheUpdateParent* aActor,
  3473. const URIParams& aManifestURI,
  3474. const URIParams& aDocumentURI,
  3475. const PrincipalInfo& aLoadingPrincipal,
  3476. const bool& aStickDocument)
  3477. {
  3478. MOZ_ASSERT(aActor);
  3479. RefPtr<mozilla::docshell::OfflineCacheUpdateParent> update =
  3480. static_cast<mozilla::docshell::OfflineCacheUpdateParent*>(aActor);
  3481. nsresult rv = update->Schedule(aManifestURI, aDocumentURI, aLoadingPrincipal, aStickDocument);
  3482. if (NS_FAILED(rv) && IsAlive()) {
  3483. // Inform the child of failure.
  3484. Unused << update->SendFinish(false, false);
  3485. }
  3486. return true;
  3487. }
  3488. bool
  3489. ContentParent::DeallocPOfflineCacheUpdateParent(POfflineCacheUpdateParent* aActor)
  3490. {
  3491. // Reclaim the IPDL reference.
  3492. RefPtr<mozilla::docshell::OfflineCacheUpdateParent> update =
  3493. dont_AddRef(static_cast<mozilla::docshell::OfflineCacheUpdateParent*>(aActor));
  3494. return true;
  3495. }
  3496. PWebrtcGlobalParent *
  3497. ContentParent::AllocPWebrtcGlobalParent()
  3498. {
  3499. #ifdef MOZ_WEBRTC
  3500. return WebrtcGlobalParent::Alloc();
  3501. #else
  3502. return nullptr;
  3503. #endif
  3504. }
  3505. bool
  3506. ContentParent::DeallocPWebrtcGlobalParent(PWebrtcGlobalParent *aActor)
  3507. {
  3508. #ifdef MOZ_WEBRTC
  3509. WebrtcGlobalParent::Dealloc(static_cast<WebrtcGlobalParent*>(aActor));
  3510. return true;
  3511. #else
  3512. return false;
  3513. #endif
  3514. }
  3515. bool
  3516. ContentParent::RecvSetOfflinePermission(const Principal& aPrincipal)
  3517. {
  3518. nsIPrincipal* principal = aPrincipal;
  3519. nsContentUtils::MaybeAllowOfflineAppByDefault(principal);
  3520. return true;
  3521. }
  3522. void
  3523. ContentParent::MaybeInvokeDragSession(TabParent* aParent)
  3524. {
  3525. nsCOMPtr<nsIDragService> dragService =
  3526. do_GetService("@mozilla.org/widget/dragservice;1");
  3527. if (dragService && dragService->MaybeAddChildProcess(this)) {
  3528. // We need to send transferable data to child process.
  3529. nsCOMPtr<nsIDragSession> session;
  3530. dragService->GetCurrentSession(getter_AddRefs(session));
  3531. if (session) {
  3532. nsTArray<IPCDataTransfer> dataTransfers;
  3533. nsCOMPtr<nsIDOMDataTransfer> domTransfer;
  3534. session->GetDataTransfer(getter_AddRefs(domTransfer));
  3535. nsCOMPtr<DataTransfer> transfer = do_QueryInterface(domTransfer);
  3536. if (!transfer) {
  3537. // Pass eDrop to get DataTransfer with external
  3538. // drag formats cached.
  3539. transfer = new DataTransfer(nullptr, eDrop, true, -1);
  3540. session->SetDataTransfer(transfer);
  3541. }
  3542. // Note, even though this fills the DataTransfer object with
  3543. // external data, the data is usually transfered over IPC lazily when
  3544. // needed.
  3545. transfer->FillAllExternalData();
  3546. nsCOMPtr<nsILoadContext> lc = aParent ?
  3547. aParent->GetLoadContext() : nullptr;
  3548. nsCOMPtr<nsIArray> transferables =
  3549. transfer->GetTransferables(lc);
  3550. nsContentUtils::TransferablesToIPCTransferables(transferables,
  3551. dataTransfers,
  3552. false,
  3553. nullptr,
  3554. this);
  3555. uint32_t action;
  3556. session->GetDragAction(&action);
  3557. mozilla::Unused << SendInvokeDragSession(dataTransfers, action);
  3558. }
  3559. }
  3560. }
  3561. bool
  3562. ContentParent::RecvUpdateDropEffect(const uint32_t& aDragAction,
  3563. const uint32_t& aDropEffect)
  3564. {
  3565. nsCOMPtr<nsIDragSession> dragSession = nsContentUtils::GetDragSession();
  3566. if (dragSession) {
  3567. dragSession->SetDragAction(aDragAction);
  3568. nsCOMPtr<nsIDOMDataTransfer> dt;
  3569. dragSession->GetDataTransfer(getter_AddRefs(dt));
  3570. if (dt) {
  3571. dt->SetDropEffectInt(aDropEffect);
  3572. }
  3573. dragSession->UpdateDragEffect();
  3574. }
  3575. return true;
  3576. }
  3577. PContentPermissionRequestParent*
  3578. ContentParent::AllocPContentPermissionRequestParent(const InfallibleTArray<PermissionRequest>& aRequests,
  3579. const IPC::Principal& aPrincipal,
  3580. const TabId& aTabId)
  3581. {
  3582. ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
  3583. RefPtr<TabParent> tp =
  3584. cpm->GetTopLevelTabParentByProcessAndTabId(this->ChildID(), aTabId);
  3585. if (!tp) {
  3586. return nullptr;
  3587. }
  3588. return nsContentPermissionUtils::CreateContentPermissionRequestParent(aRequests,
  3589. tp->GetOwnerElement(),
  3590. aPrincipal,
  3591. aTabId);
  3592. }
  3593. bool
  3594. ContentParent::DeallocPContentPermissionRequestParent(PContentPermissionRequestParent* actor)
  3595. {
  3596. nsContentPermissionUtils::NotifyRemoveContentPermissionRequestParent(actor);
  3597. delete actor;
  3598. return true;
  3599. }
  3600. PWebBrowserPersistDocumentParent*
  3601. ContentParent::AllocPWebBrowserPersistDocumentParent(PBrowserParent* aBrowser,
  3602. const uint64_t& aOuterWindowID)
  3603. {
  3604. return new WebBrowserPersistDocumentParent();
  3605. }
  3606. bool
  3607. ContentParent::DeallocPWebBrowserPersistDocumentParent(PWebBrowserPersistDocumentParent* aActor)
  3608. {
  3609. delete aActor;
  3610. return true;
  3611. }
  3612. bool
  3613. ContentParent::RecvCreateWindow(PBrowserParent* aThisTab,
  3614. PBrowserParent* aNewTab,
  3615. PRenderFrameParent* aRenderFrame,
  3616. const uint32_t& aChromeFlags,
  3617. const bool& aCalledFromJS,
  3618. const bool& aPositionSpecified,
  3619. const bool& aSizeSpecified,
  3620. const nsCString& aFeatures,
  3621. const nsCString& aBaseURI,
  3622. const DocShellOriginAttributes& aOpenerOriginAttributes,
  3623. const float& aFullZoom,
  3624. nsresult* aResult,
  3625. bool* aWindowIsNew,
  3626. InfallibleTArray<FrameScriptInfo>* aFrameScripts,
  3627. nsCString* aURLToLoad,
  3628. TextureFactoryIdentifier* aTextureFactoryIdentifier,
  3629. uint64_t* aLayersId)
  3630. {
  3631. // We always expect to open a new window here. If we don't, it's an error.
  3632. *aWindowIsNew = true;
  3633. *aResult = NS_OK;
  3634. // The content process should never be in charge of computing whether or
  3635. // not a window should be private or remote - the parent will do that.
  3636. const uint32_t badFlags =
  3637. nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW
  3638. | nsIWebBrowserChrome::CHROME_NON_PRIVATE_WINDOW
  3639. | nsIWebBrowserChrome::CHROME_PRIVATE_LIFETIME
  3640. | nsIWebBrowserChrome::CHROME_REMOTE_WINDOW;
  3641. if (!!(aChromeFlags & badFlags)) {
  3642. return false;
  3643. }
  3644. TabParent* thisTabParent = nullptr;
  3645. if (aThisTab) {
  3646. thisTabParent = TabParent::GetFrom(aThisTab);
  3647. }
  3648. if (NS_WARN_IF(thisTabParent && thisTabParent->IsMozBrowserOrApp())) {
  3649. return false;
  3650. }
  3651. TabParent* newTab = TabParent::GetFrom(aNewTab);
  3652. MOZ_ASSERT(newTab);
  3653. auto destroyNewTabOnError = MakeScopeExit([&] {
  3654. if (!*aWindowIsNew || NS_FAILED(*aResult)) {
  3655. if (newTab) {
  3656. newTab->Destroy();
  3657. }
  3658. }
  3659. });
  3660. // Content has requested that we open this new content window, so
  3661. // we must have an opener.
  3662. newTab->SetHasContentOpener(true);
  3663. nsCOMPtr<nsIContent> frame;
  3664. if (thisTabParent) {
  3665. frame = do_QueryInterface(thisTabParent->GetOwnerElement());
  3666. }
  3667. nsCOMPtr<nsPIDOMWindowOuter> parent;
  3668. if (frame) {
  3669. parent = frame->OwnerDoc()->GetWindow();
  3670. // If our chrome window is in the process of closing, don't try to open a
  3671. // new tab in it.
  3672. if (parent && parent->Closed()) {
  3673. parent = nullptr;
  3674. }
  3675. }
  3676. nsCOMPtr<nsIBrowserDOMWindow> browserDOMWin;
  3677. if (thisTabParent) {
  3678. browserDOMWin = thisTabParent->GetBrowserDOMWindow();
  3679. }
  3680. // If we haven't found a chrome window to open in, just use the most recently
  3681. // opened one.
  3682. if (!parent) {
  3683. parent = nsContentUtils::GetMostRecentNonPBWindow();
  3684. if (NS_WARN_IF(!parent)) {
  3685. *aResult = NS_ERROR_FAILURE;
  3686. return true;
  3687. }
  3688. nsCOMPtr<nsIDOMChromeWindow> rootChromeWin = do_QueryInterface(parent);
  3689. if (rootChromeWin) {
  3690. rootChromeWin->GetBrowserDOMWindow(getter_AddRefs(browserDOMWin));
  3691. }
  3692. }
  3693. int32_t openLocation =
  3694. nsWindowWatcher::GetWindowOpenLocation(parent, aChromeFlags, aCalledFromJS,
  3695. aPositionSpecified, aSizeSpecified);
  3696. MOZ_ASSERT(openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB ||
  3697. openLocation == nsIBrowserDOMWindow::OPEN_NEWWINDOW);
  3698. // Opening new tabs is the easy case...
  3699. if (openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB) {
  3700. if (NS_WARN_IF(!browserDOMWin)) {
  3701. *aResult = NS_ERROR_ABORT;
  3702. return true;
  3703. }
  3704. bool isPrivate = false;
  3705. if (thisTabParent) {
  3706. nsCOMPtr<nsILoadContext> loadContext = thisTabParent->GetLoadContext();
  3707. loadContext->GetUsePrivateBrowsing(&isPrivate);
  3708. }
  3709. nsCOMPtr<nsIOpenURIInFrameParams> params =
  3710. new nsOpenURIInFrameParams(aOpenerOriginAttributes);
  3711. params->SetReferrer(NS_ConvertUTF8toUTF16(aBaseURI));
  3712. params->SetIsPrivate(isPrivate);
  3713. TabParent::AutoUseNewTab aunt(newTab, aWindowIsNew, aURLToLoad);
  3714. nsCOMPtr<nsIFrameLoaderOwner> frameLoaderOwner;
  3715. browserDOMWin->OpenURIInFrame(nullptr, params,
  3716. openLocation,
  3717. nsIBrowserDOMWindow::OPEN_NEW,
  3718. getter_AddRefs(frameLoaderOwner));
  3719. if (!frameLoaderOwner) {
  3720. *aWindowIsNew = false;
  3721. }
  3722. newTab->SwapFrameScriptsFrom(*aFrameScripts);
  3723. RenderFrameParent* rfp = static_cast<RenderFrameParent*>(aRenderFrame);
  3724. if (!newTab->SetRenderFrame(rfp) ||
  3725. !newTab->GetRenderFrameInfo(aTextureFactoryIdentifier, aLayersId)) {
  3726. *aResult = NS_ERROR_FAILURE;
  3727. }
  3728. return true;
  3729. }
  3730. TabParent::AutoUseNewTab aunt(newTab, aWindowIsNew, aURLToLoad);
  3731. nsCOMPtr<nsPIWindowWatcher> pwwatch =
  3732. do_GetService(NS_WINDOWWATCHER_CONTRACTID, aResult);
  3733. if (NS_WARN_IF(NS_FAILED(*aResult))) {
  3734. return true;
  3735. }
  3736. nsCOMPtr<nsITabParent> newRemoteTab;
  3737. if (!thisTabParent) {
  3738. // Because we weren't passed an opener tab, the content process has asked us
  3739. // to open a new window that is unrelated to a pre-existing tab.
  3740. *aResult = pwwatch->OpenWindowWithoutParent(getter_AddRefs(newRemoteTab));
  3741. } else {
  3742. *aResult = pwwatch->OpenWindowWithTabParent(thisTabParent, aFeatures, aCalledFromJS,
  3743. aFullZoom, getter_AddRefs(newRemoteTab));
  3744. }
  3745. if (NS_WARN_IF(NS_FAILED(*aResult))) {
  3746. return true;
  3747. }
  3748. MOZ_ASSERT(TabParent::GetFrom(newRemoteTab) == newTab);
  3749. newTab->SwapFrameScriptsFrom(*aFrameScripts);
  3750. RenderFrameParent* rfp = static_cast<RenderFrameParent*>(aRenderFrame);
  3751. if (!newTab->SetRenderFrame(rfp) ||
  3752. !newTab->GetRenderFrameInfo(aTextureFactoryIdentifier, aLayersId)) {
  3753. *aResult = NS_ERROR_FAILURE;
  3754. }
  3755. return true;
  3756. }
  3757. bool
  3758. ContentParent::RecvGetGraphicsDeviceInitData(ContentDeviceData* aOut)
  3759. {
  3760. gfxPlatform::GetPlatform()->BuildContentDeviceData(aOut);
  3761. return true;
  3762. }
  3763. bool
  3764. ContentParent::RecvGraphicsError(const nsCString& aError)
  3765. {
  3766. gfx::LogForwarder* lf = gfx::Factory::GetLogForwarder();
  3767. if (lf) {
  3768. std::stringstream message;
  3769. message << "CP+" << aError.get();
  3770. lf->UpdateStringsVector(message.str());
  3771. }
  3772. return true;
  3773. }
  3774. bool
  3775. ContentParent::RecvBeginDriverCrashGuard(const uint32_t& aGuardType, bool* aOutCrashed)
  3776. {
  3777. // Only one driver crash guard should be active at a time, per-process.
  3778. MOZ_ASSERT(!mDriverCrashGuard);
  3779. UniquePtr<gfx::DriverCrashGuard> guard;
  3780. switch (gfx::CrashGuardType(aGuardType)) {
  3781. case gfx::CrashGuardType::D3D11Layers:
  3782. guard = MakeUnique<gfx::D3D11LayersCrashGuard>(this);
  3783. break;
  3784. case gfx::CrashGuardType::D3D9Video:
  3785. guard = MakeUnique<gfx::D3D9VideoCrashGuard>(this);
  3786. break;
  3787. case gfx::CrashGuardType::GLContext:
  3788. guard = MakeUnique<gfx::GLContextCrashGuard>(this);
  3789. break;
  3790. case gfx::CrashGuardType::D3D11Video:
  3791. guard = MakeUnique<gfx::D3D11VideoCrashGuard>(this);
  3792. break;
  3793. default:
  3794. MOZ_ASSERT_UNREACHABLE("unknown crash guard type");
  3795. return false;
  3796. }
  3797. if (guard->Crashed()) {
  3798. *aOutCrashed = true;
  3799. return true;
  3800. }
  3801. *aOutCrashed = false;
  3802. mDriverCrashGuard = Move(guard);
  3803. return true;
  3804. }
  3805. bool
  3806. ContentParent::RecvEndDriverCrashGuard(const uint32_t& aGuardType)
  3807. {
  3808. mDriverCrashGuard = nullptr;
  3809. return true;
  3810. }
  3811. bool
  3812. ContentParent::RecvGetAndroidSystemInfo(AndroidSystemInfo* aInfo)
  3813. {
  3814. MOZ_CRASH("wrong platform!");
  3815. return false;
  3816. }
  3817. bool
  3818. ContentParent::RecvNotifyBenchmarkResult(const nsString& aCodecName,
  3819. const uint32_t& aDecodeFPS)
  3820. {
  3821. if (aCodecName.EqualsLiteral("VP9")) {
  3822. Preferences::SetUint(VP9Benchmark::sBenchmarkFpsPref, aDecodeFPS);
  3823. Preferences::SetUint(VP9Benchmark::sBenchmarkFpsVersionCheck,
  3824. VP9Benchmark::sBenchmarkVersionID);
  3825. }
  3826. return true;
  3827. }
  3828. bool
  3829. ContentParent::RecvNotifyPushObservers(const nsCString& aScope,
  3830. const IPC::Principal& aPrincipal,
  3831. const nsString& aMessageId)
  3832. {
  3833. PushMessageDispatcher dispatcher(aScope, aPrincipal, aMessageId, Nothing());
  3834. Unused << NS_WARN_IF(NS_FAILED(dispatcher.NotifyObservers()));
  3835. return true;
  3836. }
  3837. bool
  3838. ContentParent::RecvNotifyPushObserversWithData(const nsCString& aScope,
  3839. const IPC::Principal& aPrincipal,
  3840. const nsString& aMessageId,
  3841. InfallibleTArray<uint8_t>&& aData)
  3842. {
  3843. PushMessageDispatcher dispatcher(aScope, aPrincipal, aMessageId, Some(aData));
  3844. Unused << NS_WARN_IF(NS_FAILED(dispatcher.NotifyObservers()));
  3845. return true;
  3846. }
  3847. bool
  3848. ContentParent::RecvNotifyPushSubscriptionChangeObservers(const nsCString& aScope,
  3849. const IPC::Principal& aPrincipal)
  3850. {
  3851. PushSubscriptionChangeDispatcher dispatcher(aScope, aPrincipal);
  3852. Unused << NS_WARN_IF(NS_FAILED(dispatcher.NotifyObservers()));
  3853. return true;
  3854. }
  3855. bool
  3856. ContentParent::RecvNotifyPushSubscriptionModifiedObservers(const nsCString& aScope,
  3857. const IPC::Principal& aPrincipal)
  3858. {
  3859. PushSubscriptionModifiedDispatcher dispatcher(aScope, aPrincipal);
  3860. Unused << NS_WARN_IF(NS_FAILED(dispatcher.NotifyObservers()));
  3861. return true;
  3862. }
  3863. bool
  3864. ContentParent::RecvNotifyLowMemory()
  3865. {
  3866. return true;
  3867. }
  3868. /* static */ void
  3869. ContentParent::BroadcastBlobURLRegistration(const nsACString& aURI,
  3870. BlobImpl* aBlobImpl,
  3871. nsIPrincipal* aPrincipal,
  3872. ContentParent* aIgnoreThisCP)
  3873. {
  3874. nsCString uri(aURI);
  3875. IPC::Principal principal(aPrincipal);
  3876. for (auto* cp : AllProcesses(eLive)) {
  3877. if (cp != aIgnoreThisCP) {
  3878. PBlobParent* blobParent = cp->GetOrCreateActorForBlobImpl(aBlobImpl);
  3879. if (blobParent) {
  3880. Unused << cp->SendBlobURLRegistration(uri, blobParent, principal);
  3881. }
  3882. }
  3883. }
  3884. }
  3885. /* static */ void
  3886. ContentParent::BroadcastBlobURLUnregistration(const nsACString& aURI,
  3887. ContentParent* aIgnoreThisCP)
  3888. {
  3889. nsCString uri(aURI);
  3890. for (auto* cp : AllProcesses(eLive)) {
  3891. if (cp != aIgnoreThisCP) {
  3892. Unused << cp->SendBlobURLUnregistration(uri);
  3893. }
  3894. }
  3895. }
  3896. bool
  3897. ContentParent::RecvStoreAndBroadcastBlobURLRegistration(const nsCString& aURI,
  3898. PBlobParent* aBlobParent,
  3899. const Principal& aPrincipal)
  3900. {
  3901. RefPtr<BlobImpl> blobImpl =
  3902. static_cast<BlobParent*>(aBlobParent)->GetBlobImpl();
  3903. if (NS_WARN_IF(!blobImpl)) {
  3904. return false;
  3905. }
  3906. if (NS_SUCCEEDED(nsHostObjectProtocolHandler::AddDataEntry(aURI, aPrincipal,
  3907. blobImpl))) {
  3908. BroadcastBlobURLRegistration(aURI, blobImpl, aPrincipal, this);
  3909. // We want to store this blobURL, so we can unregister it if the child
  3910. // crashes.
  3911. mBlobURLs.AppendElement(aURI);
  3912. }
  3913. BroadcastBlobURLRegistration(aURI, blobImpl, aPrincipal, this);
  3914. return true;
  3915. }
  3916. bool
  3917. ContentParent::RecvUnstoreAndBroadcastBlobURLUnregistration(const nsCString& aURI)
  3918. {
  3919. nsHostObjectProtocolHandler::RemoveDataEntry(aURI,
  3920. false /* Don't broadcast */);
  3921. BroadcastBlobURLUnregistration(aURI, this);
  3922. mBlobURLs.RemoveElement(aURI);
  3923. return true;
  3924. }
  3925. bool
  3926. ContentParent::RecvGetA11yContentId(uint32_t* aContentId)
  3927. {
  3928. #if defined(XP_WIN32) && defined(ACCESSIBILITY)
  3929. *aContentId = a11y::AccessibleWrap::GetContentProcessIdFor(ChildID());
  3930. MOZ_ASSERT(*aContentId);
  3931. return true;
  3932. #else
  3933. return false;
  3934. #endif
  3935. }
  3936. } // namespace dom
  3937. } // namespace mozilla
  3938. NS_IMPL_ISUPPORTS(ParentIdleListener, nsIObserver)
  3939. NS_IMETHODIMP
  3940. ParentIdleListener::Observe(nsISupports*, const char* aTopic, const char16_t* aData)
  3941. {
  3942. mozilla::Unused << mParent->SendNotifyIdleObserver(mObserver,
  3943. nsDependentCString(aTopic),
  3944. nsDependentString(aData));
  3945. return NS_OK;
  3946. }
  3947. bool
  3948. ContentParent::HandleWindowsMessages(const Message& aMsg) const
  3949. {
  3950. MOZ_ASSERT(aMsg.is_sync());
  3951. // a11y messages can be triggered by windows messages, which means if we
  3952. // allow handling windows messages while we wait for the response to a sync
  3953. // a11y message we can reenter the ipc message sending code.
  3954. if (a11y::PDocAccessible::PDocAccessibleStart < aMsg.type() &&
  3955. a11y::PDocAccessible::PDocAccessibleEnd > aMsg.type()) {
  3956. return false;
  3957. }
  3958. return true;
  3959. }
  3960. bool
  3961. ContentParent::RecvGetFilesRequest(const nsID& aUUID,
  3962. const nsString& aDirectoryPath,
  3963. const bool& aRecursiveFlag)
  3964. {
  3965. MOZ_ASSERT(!mGetFilesPendingRequests.GetWeak(aUUID));
  3966. if (!mozilla::Preferences::GetBool("dom.filesystem.pathcheck.disabled", false)) {
  3967. RefPtr<FileSystemSecurity> fss = FileSystemSecurity::Get();
  3968. if (NS_WARN_IF(!fss ||
  3969. !fss->ContentProcessHasAccessTo(ChildID(), aDirectoryPath))) {
  3970. return false;
  3971. }
  3972. }
  3973. ErrorResult rv;
  3974. RefPtr<GetFilesHelper> helper =
  3975. GetFilesHelperParent::Create(aUUID, aDirectoryPath, aRecursiveFlag, this,
  3976. rv);
  3977. if (NS_WARN_IF(rv.Failed())) {
  3978. return SendGetFilesResponse(aUUID,
  3979. GetFilesResponseFailure(rv.StealNSResult()));
  3980. }
  3981. mGetFilesPendingRequests.Put(aUUID, helper);
  3982. return true;
  3983. }
  3984. bool
  3985. ContentParent::RecvDeleteGetFilesRequest(const nsID& aUUID)
  3986. {
  3987. GetFilesHelper* helper = mGetFilesPendingRequests.GetWeak(aUUID);
  3988. if (helper) {
  3989. mGetFilesPendingRequests.Remove(aUUID);
  3990. }
  3991. return true;
  3992. }
  3993. void
  3994. ContentParent::SendGetFilesResponseAndForget(const nsID& aUUID,
  3995. const GetFilesResponseResult& aResult)
  3996. {
  3997. GetFilesHelper* helper = mGetFilesPendingRequests.GetWeak(aUUID);
  3998. if (helper) {
  3999. mGetFilesPendingRequests.Remove(aUUID);
  4000. Unused << SendGetFilesResponse(aUUID, aResult);
  4001. }
  4002. }
  4003. void
  4004. ContentParent::ForceTabPaint(TabParent* aTabParent, uint64_t aLayerObserverEpoch)
  4005. {
  4006. if (!mHangMonitorActor) {
  4007. return;
  4008. }
  4009. ProcessHangMonitor::ForcePaint(mHangMonitorActor, aTabParent, aLayerObserverEpoch);
  4010. }