12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743 |
- // Copyright (c) 2012 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "chrome/browser/chrome_content_browser_client.h"
- #include <iterator>
- #include <map>
- #include <memory>
- #include <set>
- #include <utility>
- #include <vector>
- #include "base/base_switches.h"
- #include "base/bind.h"
- #include "base/callback.h"
- #include "base/command_line.h"
- #include "base/dcheck_is_on.h"
- #include "base/i18n/base_i18n_switches.h"
- #include "base/i18n/character_encoding.h"
- #include "base/memory/raw_ptr.h"
- #include "base/metrics/field_trial_params.h"
- #include "base/metrics/histogram_macros.h"
- #include "base/no_destructor.h"
- #include "base/path_service.h"
- #include "base/strings/strcat.h"
- #include "base/strings/string_number_conversions.h"
- #include "base/strings/string_split.h"
- #include "base/strings/string_util.h"
- #include "base/strings/stringprintf.h"
- #include "base/values.h"
- #include "build/build_config.h"
- #include "build/chromeos_buildflags.h"
- #include "chrome/browser/accessibility/accessibility_labels_service.h"
- #include "chrome/browser/accessibility/accessibility_labels_service_factory.h"
- #include "chrome/browser/after_startup_task_utils.h"
- #include "chrome/browser/bluetooth/chrome_bluetooth_delegate_impl_client.h"
- #include "chrome/browser/browser_about_handler.h"
- #include "chrome/browser/browser_features.h"
- #include "chrome/browser/browser_process.h"
- #include "chrome/browser/browsing_topics/browsing_topics_service_factory.h"
- #include "chrome/browser/captive_portal/captive_portal_service_factory.h"
- #include "chrome/browser/chrome_content_browser_client_binder_policies.h"
- #include "chrome/browser/chrome_content_browser_client_parts.h"
- #include "chrome/browser/content_settings/cookie_settings_factory.h"
- #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
- #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
- #include "chrome/browser/data_saver/data_saver.h"
- #include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h"
- #include "chrome/browser/defaults.h"
- #include "chrome/browser/device_api/device_service_impl.h"
- #include "chrome/browser/device_api/managed_configuration_service.h"
- #include "chrome/browser/download/chrome_download_manager_delegate.h"
- #include "chrome/browser/download/download_prefs.h"
- #include "chrome/browser/enterprise/browser_management/management_service_factory.h"
- #include "chrome/browser/enterprise/connectors/connectors_service.h"
- #include "chrome/browser/enterprise/util/managed_browser_utils.h"
- #include "chrome/browser/extensions/chrome_extension_cookies.h"
- #include "chrome/browser/external_protocol/external_protocol_handler.h"
- #include "chrome/browser/favicon/favicon_utils.h"
- #include "chrome/browser/font_family_cache.h"
- #include "chrome/browser/gpu/chrome_browser_main_extra_parts_gpu.h"
- #include "chrome/browser/hid/chrome_hid_delegate.h"
- #include "chrome/browser/interstitials/enterprise_util.h"
- #include "chrome/browser/lifetime/browser_shutdown.h"
- #include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h"
- #include "chrome/browser/media/audio_service_util.h"
- #include "chrome/browser/media/router/media_router_feature.h"
- #include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h"
- #include "chrome/browser/media/webrtc/capture_policy_utils.h"
- #include "chrome/browser/media/webrtc/chrome_screen_enumerator.h"
- #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
- #include "chrome/browser/media/webrtc/webrtc_logging_controller.h"
- #include "chrome/browser/memory/chrome_browser_main_extra_parts_memory.h"
- #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
- #include "chrome/browser/metrics/chrome_feature_list_creator.h"
- #include "chrome/browser/net/chrome_network_delegate.h"
- #include "chrome/browser/net/profile_network_context_service.h"
- #include "chrome/browser/net/profile_network_context_service_factory.h"
- #include "chrome/browser/net/system_network_context_manager.h"
- #include "chrome/browser/payments/payment_request_display_manager_factory.h"
- #include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h"
- #include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h"
- #include "chrome/browser/performance_monitor/chrome_browser_main_extra_parts_performance_monitor.h"
- #include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h"
- #include "chrome/browser/plugins/plugin_utils.h"
- #include "chrome/browser/policy/profile_policy_connector.h"
- #include "chrome/browser/prefetch/prefetch_prefs.h"
- #include "chrome/browser/preloading/navigation_ablation_throttle.h"
- #include "chrome/browser/preloading/prefetch/no_state_prefetch/chrome_no_state_prefetch_contents_delegate.h"
- #include "chrome/browser/preloading/prefetch/no_state_prefetch/no_state_prefetch_manager_factory.h"
- #include "chrome/browser/preloading/prefetch/no_state_prefetch/no_state_prefetch_navigation_throttle.h"
- #include "chrome/browser/preloading/prefetch/prefetch_proxy/chrome_prefetch_service_delegate.h"
- #include "chrome/browser/preloading/prefetch/prefetch_proxy/chrome_speculation_host_delegate.h"
- #include "chrome/browser/preloading/prefetch/prefetch_proxy/prefetch_proxy_features.h"
- #include "chrome/browser/preloading/prefetch/prefetch_proxy/prefetch_proxy_service.h"
- #include "chrome/browser/preloading/prefetch/prefetch_proxy/prefetch_proxy_service_factory.h"
- #include "chrome/browser/preloading/prefetch/prefetch_proxy/prefetch_proxy_url_loader_interceptor.h"
- #include "chrome/browser/preloading/prefetch/search_prefetch/field_trial_settings.h"
- #include "chrome/browser/preloading/prefetch/search_prefetch/search_prefetch_url_loader.h"
- #include "chrome/browser/preloading/prefetch/search_prefetch/search_prefetch_url_loader_interceptor.h"
- #include "chrome/browser/privacy_sandbox/privacy_sandbox_settings_factory.h"
- #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
- #include "chrome/browser/profiles/profile.h"
- #include "chrome/browser/profiles/profile_io_data.h"
- #include "chrome/browser/profiles/profile_manager.h"
- #include "chrome/browser/profiles/renderer_updater.h"
- #include "chrome/browser/profiles/renderer_updater_factory.h"
- #include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h"
- #include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
- #include "chrome/browser/renderer_preferences_util.h"
- #include "chrome/browser/safe_browsing/certificate_reporting_service.h"
- #include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
- #include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
- #include "chrome/browser/safe_browsing/delayed_warning_navigation_throttle.h"
- #include "chrome/browser/safe_browsing/safe_browsing_service.h"
- #include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
- #include "chrome/browser/safe_browsing/url_lookup_service_factory.h"
- #include "chrome/browser/search/search.h"
- #include "chrome/browser/segmentation_platform/chrome_browser_main_extra_parts_segmentation_platform.h"
- #include "chrome/browser/sharing/sms/sms_remote_fetcher.h"
- #include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
- #include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
- #include "chrome/browser/signin/header_modification_delegate_impl.h"
- #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
- #include "chrome/browser/ssl/chrome_security_blocking_page_factory.h"
- #include "chrome/browser/ssl/https_defaulted_callbacks.h"
- #include "chrome/browser/ssl/https_only_mode_navigation_throttle.h"
- #include "chrome/browser/ssl/https_only_mode_upgrade_interceptor.h"
- #include "chrome/browser/ssl/sct_reporting_service.h"
- #include "chrome/browser/ssl/ssl_client_auth_metrics.h"
- #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
- #include "chrome/browser/ssl/typed_navigation_upgrade_throttle.h"
- #include "chrome/browser/tracing/chrome_tracing_delegate.h"
- #include "chrome/browser/translate/translate_service.h"
- #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
- #include "chrome/browser/ui/blocked_content/chrome_popup_navigation_delegate.h"
- #include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
- #include "chrome/browser/ui/browser_navigator.h"
- #include "chrome/browser/ui/browser_navigator_params.h"
- #include "chrome/browser/ui/chrome_select_file_policy.h"
- #include "chrome/browser/ui/login/login_handler.h"
- #include "chrome/browser/ui/login/login_navigation_throttle.h"
- #include "chrome/browser/ui/login/login_tab_helper.h"
- #include "chrome/browser/ui/passwords/password_manager_navigation_throttle.h"
- #include "chrome/browser/ui/passwords/well_known_change_password_navigation_throttle.h"
- #include "chrome/browser/ui/prefs/pref_watcher.h"
- #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
- #include "chrome/browser/ui/ui_features.h"
- #include "chrome/browser/ui/webid/identity_dialog_controller.h"
- #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
- #include "chrome/browser/ui/webui/log_web_ui_url.h"
- #include "chrome/browser/universal_web_contents_observers.h"
- #include "chrome/browser/usb/chrome_usb_delegate.h"
- #include "chrome/browser/vr/vr_tab_helper.h"
- #include "chrome/browser/webapps/web_app_offline.h"
- #include "chrome/browser/webauthn/webauthn_pref_names.h"
- #include "chrome/common/buildflags.h"
- #include "chrome/common/channel_info.h"
- #include "chrome/common/chrome_constants.h"
- #include "chrome/common/chrome_content_client.h"
- #include "chrome/common/chrome_features.h"
- #include "chrome/common/chrome_paths.h"
- #include "chrome/common/chrome_paths_internal.h"
- #include "chrome/common/chrome_switches.h"
- #include "chrome/common/env_vars.h"
- #include "chrome/common/google_url_loader_throttle.h"
- #include "chrome/common/logging_chrome.h"
- #include "chrome/common/pdf_util.h"
- #include "chrome/common/pref_names.h"
- #include "chrome/common/profiler/thread_profiler_configuration.h"
- #include "chrome/common/renderer_configuration.mojom.h"
- #include "chrome/common/secure_origin_allowlist.h"
- #include "chrome/common/url_constants.h"
- #include "chrome/common/webui_url_constants.h"
- #include "chrome/grit/generated_resources.h"
- #include "chrome/installer/util/google_update_settings.h"
- #include "components/autofill/core/common/autofill_switches.h"
- #include "components/blocked_content/popup_blocker.h"
- #include "components/browsing_topics/browsing_topics_service.h"
- #include "components/captive_portal/core/buildflags.h"
- #include "components/content_settings/browser/page_specific_content_settings.h"
- #include "components/content_settings/core/browser/cookie_settings.h"
- #include "components/content_settings/core/browser/host_content_settings_map.h"
- #include "components/content_settings/core/browser/private_network_settings.h"
- #include "components/content_settings/core/common/content_settings.h"
- #include "components/content_settings/core/common/content_settings_types.h"
- #include "components/custom_handlers/protocol_handler_registry.h"
- #include "components/custom_handlers/protocol_handler_throttle.h"
- #include "components/dom_distiller/core/dom_distiller_switches.h"
- #include "components/dom_distiller/core/url_constants.h"
- #include "components/embedder_support/content_settings_utils.h"
- #include "components/embedder_support/switches.h"
- #include "components/enterprise/content/clipboard_restriction_service.h"
- #include "components/enterprise/content/pref_names.h"
- #include "components/error_page/common/error.h"
- #include "components/error_page/common/error_page_switches.h"
- #include "components/error_page/common/localized_error.h"
- #include "components/error_page/content/browser/net_error_auto_reloader.h"
- #include "components/google/core/common/google_switches.h"
- #include "components/keep_alive_registry/keep_alive_types.h"
- #include "components/keep_alive_registry/scoped_keep_alive.h"
- #include "components/language/core/browser/pref_names.h"
- #include "components/live_caption/caption_util.h"
- #include "components/media_router/browser/presentation/presentation_service_delegate_impl.h"
- #include "components/media_router/browser/presentation/receiver_presentation_service_delegate_impl.h"
- #include "components/media_router/browser/presentation/web_contents_presentation_manager.h"
- #include "components/metrics/client_info.h"
- #include "components/metrics_services_manager/metrics_services_manager.h"
- #include "components/net_log/chrome_net_log.h"
- #include "components/no_state_prefetch/browser/no_state_prefetch_manager.h"
- #include "components/no_state_prefetch/common/no_state_prefetch_final_status.h"
- #include "components/no_state_prefetch/common/prerender_url_loader_throttle.h"
- #include "components/omnibox/common/omnibox_features.h"
- #include "components/page_load_metrics/browser/metrics_navigation_throttle.h"
- #include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
- #include "components/payments/content/payment_handler_navigation_throttle.h"
- #include "components/payments/content/payment_request_display_manager.h"
- #include "components/performance_manager/embedder/performance_manager_registry.h"
- #include "components/permissions/bluetooth_delegate_impl.h"
- #include "components/permissions/permission_context_base.h"
- #include "components/permissions/quota_permission_context_impl.h"
- #include "components/policy/content/policy_blocklist_navigation_throttle.h"
- #include "components/policy/content/policy_blocklist_service.h"
- #include "components/policy/core/common/management/management_service.h"
- #include "components/policy/core/common/policy_pref_names.h"
- #include "components/pref_registry/pref_registry_syncable.h"
- #include "components/prefs/pref_registry_simple.h"
- #include "components/prefs/pref_service.h"
- #include "components/prefs/scoped_user_pref_update.h"
- #include "components/privacy_sandbox/privacy_sandbox_settings.h"
- #include "components/safe_browsing/buildflags.h"
- #include "components/safe_browsing/content/browser/browser_url_loader_throttle.h"
- #include "components/safe_browsing/content/browser/password_protection/password_protection_commit_deferring_condition.h"
- #include "components/safe_browsing/content/browser/safe_browsing_navigation_throttle.h"
- #include "components/safe_browsing/core/browser/realtime/policy_engine.h"
- #include "components/safe_browsing/core/browser/realtime/url_lookup_service.h"
- #include "components/safe_browsing/core/browser/url_checker_delegate.h"
- #include "components/safe_browsing/core/common/features.h"
- #include "components/safe_browsing/core/common/safe_browsing_prefs.h"
- #include "components/security_interstitials/content/insecure_form_navigation_throttle.h"
- #include "components/security_interstitials/content/ssl_cert_reporter.h"
- #include "components/security_interstitials/content/ssl_error_handler.h"
- #include "components/security_interstitials/content/ssl_error_navigation_throttle.h"
- #include "components/services/storage/public/cpp/storage_prefs.h"
- #include "components/site_isolation/pref_names.h"
- #include "components/site_isolation/preloaded_isolated_origins.h"
- #include "components/site_isolation/site_isolation_policy.h"
- #include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
- #include "components/translate/core/common/translate_switches.h"
- #include "components/url_param_filter/content/url_param_filter_throttle.h"
- #include "components/variations/variations_associated_data.h"
- #include "components/variations/variations_switches.h"
- #include "content/public/browser/browser_child_process_host.h"
- #include "content/public/browser/browser_context.h"
- #include "content/public/browser/browser_main_parts.h"
- #include "content/public/browser/browser_ppapi_host.h"
- #include "content/public/browser/browser_task_traits.h"
- #include "content/public/browser/browser_thread.h"
- #include "content/public/browser/browser_url_handler.h"
- #include "content/public/browser/certificate_request_result_type.h"
- #include "content/public/browser/child_process_data.h"
- #include "content/public/browser/child_process_security_policy.h"
- #include "content/public/browser/client_certificate_delegate.h"
- #include "content/public/browser/file_url_loader.h"
- #include "content/public/browser/navigation_handle.h"
- #include "content/public/browser/navigation_throttle.h"
- #include "content/public/browser/overlay_window.h"
- #include "content/public/browser/permission_controller.h"
- #include "content/public/browser/render_frame_host.h"
- #include "content/public/browser/render_process_host.h"
- #include "content/public/browser/site_isolation_mode.h"
- #include "content/public/browser/sms_fetcher.h"
- #include "content/public/browser/tts_controller.h"
- #include "content/public/browser/tts_platform.h"
- #include "content/public/browser/url_loader_request_interceptor.h"
- #include "content/public/browser/vpn_service_proxy.h"
- #include "content/public/browser/weak_document_ptr.h"
- #include "content/public/browser/web_contents.h"
- #include "content/public/browser/web_contents_delegate.h"
- #include "content/public/browser/web_contents_view_delegate.h"
- #include "content/public/browser/web_ui_url_loader_factory.h"
- #include "content/public/browser/webui_config_map.h"
- #include "content/public/common/content_descriptors.h"
- #include "content/public/common/content_features.h"
- #include "content/public/common/content_switches.h"
- #include "content/public/common/url_constants.h"
- #include "content/public/common/window_container_type.mojom-shared.h"
- #include "device/vr/buildflags/buildflags.h"
- #include "extensions/buildflags/buildflags.h"
- #include "google_apis/gaia/gaia_urls.h"
- #include "google_apis/google_api_keys.h"
- #include "gpu/config/gpu_switches.h"
- #include "media/base/media_switches.h"
- #include "media/media_buildflags.h"
- #include "media/mojo/buildflags.h"
- #include "mojo/public/cpp/bindings/remote.h"
- #include "net/base/features.h"
- #include "net/cookies/site_for_cookies.h"
- #include "net/ssl/client_cert_store.h"
- #include "net/ssl/ssl_cert_request_info.h"
- #include "net/ssl/ssl_private_key.h"
- #include "pdf/buildflags.h"
- #include "ppapi/buildflags/buildflags.h"
- #include "printing/buildflags/buildflags.h"
- #include "sandbox/policy/mojom/sandbox.mojom.h"
- #include "sandbox/policy/switches.h"
- #include "services/metrics/public/cpp/ukm_source_id.h"
- #include "services/network/public/cpp/is_potentially_trustworthy.h"
- #include "services/network/public/cpp/network_switches.h"
- #include "services/network/public/cpp/resource_request.h"
- #include "services/network/public/cpp/self_deleting_url_loader_factory.h"
- #include "services/network/public/cpp/web_sandbox_flags.h"
- #include "services/network/public/mojom/web_transport.mojom.h"
- #include "third_party/blink/public/common/features.h"
- #include "third_party/blink/public/common/loader/url_loader_throttle.h"
- #include "third_party/blink/public/common/navigation/navigation_policy.h"
- #include "third_party/blink/public/common/permissions/permission_utils.h"
- #include "third_party/blink/public/common/permissions_policy/permissions_policy.h"
- #include "third_party/blink/public/common/switches.h"
- #include "third_party/blink/public/mojom/browsing_topics/browsing_topics.mojom.h"
- #include "third_party/blink/public/public_buildflags.h"
- #include "third_party/widevine/cdm/buildflags.h"
- #include "ui/base/clipboard/clipboard_format_type.h"
- #include "ui/base/l10n/l10n_util.h"
- #include "ui/base/page_transition_types.h"
- #include "ui/base/resource/resource_bundle.h"
- #include "ui/native_theme/native_theme.h"
- #include "url/gurl.h"
- #include "url/origin.h"
- #include "url/third_party/mozilla/url_parse.h"
- #include "url/url_constants.h"
- #if BUILDFLAG(IS_WIN)
- #include "base/files/file_util.h"
- #include "base/strings/string_tokenizer.h"
- #include "base/win/win_util.h"
- #include "base/win/windows_version.h"
- #include "chrome/browser/chrome_browser_main_win.h"
- #include "chrome/browser/lifetime/application_lifetime.h"
- #include "chrome/install_static/install_util.h"
- #include "chrome/services/util_win/public/mojom/util_win.mojom.h"
- #include "sandbox/win/src/sandbox_policy.h"
- #elif BUILDFLAG(IS_MAC)
- #include "chrome/browser/browser_process_platform_part_mac.h"
- #include "chrome/browser/chrome_browser_main_mac.h"
- #include "chrome/browser/mac/auth_session_request.h"
- #include "chrome/browser/mac/chrome_browser_main_extra_parts_mac.h"
- #include "components/soda/constants.h"
- #include "sandbox/mac/seatbelt_exec.h"
- #include "sandbox/policy/mac/params.h"
- #include "sandbox/policy/mac/sandbox_mac.h"
- #elif BUILDFLAG(IS_CHROMEOS_ASH)
- #include "ash/constants/ash_pref_names.h"
- #include "ash/constants/ash_switches.h"
- #include "ash/public/cpp/new_window_delegate.h"
- #include "ash/public/cpp/tablet_mode.h"
- #include "ash/webui/camera_app_ui/url_constants.h"
- #include "ash/webui/scanning/url_constants.h"
- #include "chrome/app/chrome_crash_reporter_client.h"
- #include "chrome/browser/ash/arc/fileapi/arc_content_file_system_backend_delegate.h"
- #include "chrome/browser/ash/arc/fileapi/arc_documents_provider_backend_delegate.h"
- #include "chrome/browser/ash/chrome_browser_main_parts_ash.h"
- #include "chrome/browser/ash/drive/fileapi/drivefs_file_system_backend_delegate.h"
- #include "chrome/browser/ash/file_manager/app_id.h"
- #include "chrome/browser/ash/file_system_provider/fileapi/backend_delegate.h"
- #include "chrome/browser/ash/login/signin/merge_session_navigation_throttle.h"
- #include "chrome/browser/ash/login/signin/merge_session_throttling_utils.h"
- #include "chrome/browser/ash/login/signin_partition_manager.h"
- #include "chrome/browser/ash/login/startup_utils.h"
- #include "chrome/browser/ash/net/system_proxy_manager.h"
- #include "chrome/browser/ash/profiles/profile_helper.h"
- #include "chrome/browser/ash/smb_client/fileapi/smbfs_file_system_backend_delegate.h"
- #include "chrome/browser/ash/system/input_device_settings.h"
- #include "chrome/browser/ash/system_extensions/system_extensions_profile_utils.h"
- #include "chrome/browser/ash/system_extensions/system_extensions_provider.h"
- #include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h"
- #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
- #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
- #include "chrome/browser/speech/tts_chromeos.h"
- #include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
- #include "chrome/browser/ui/browser_dialogs.h"
- #include "chromeos/crosapi/cpp/lacros_startup_state.h"
- #include "components/crash/core/app/breakpad_linux.h"
- #include "components/user_manager/user.h"
- #include "components/user_manager/user_manager.h"
- #include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
- #include "storage/browser/file_system/external_mount_points.h"
- #elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
- #include "chrome/browser/chrome_browser_main_linux.h"
- #elif BUILDFLAG(IS_ANDROID)
- #include "base/android/application_status_listener.h"
- #include "base/android/build_info.h"
- #include "base/feature_list.h"
- #include "chrome/android/features/dev_ui/buildflags.h"
- #include "chrome/browser/android/customtabs/client_data_header_web_contents_observer.h"
- #include "chrome/browser/android/devtools_manager_delegate_android.h"
- #include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
- #include "chrome/browser/android/service_tab_launcher.h"
- #include "chrome/browser/android/tab_android.h"
- #include "chrome/browser/android/tab_web_contents_delegate_android.h"
- #include "chrome/browser/chrome_browser_main_android.h"
- #include "chrome/browser/download/android/available_offline_content_provider.h"
- #include "chrome/browser/download/android/intercept_oma_download_navigation_throttle.h"
- #include "chrome/browser/flags/android/chrome_feature_list.h"
- #include "chrome/browser/ui/android/tab_model/tab_model_list.h"
- #include "chrome/common/chrome_descriptors.h"
- #include "components/autofill_assistant/content/common/switches.h"
- #include "components/browser_ui/accessibility/android/font_size_prefs_android.h"
- #include "components/cdm/browser/cdm_message_filter_android.h"
- #include "components/crash/content/browser/child_exit_observer_android.h"
- #include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
- #include "components/navigation_interception/intercept_navigation_delegate.h"
- #include "components/viz/common/features.h"
- #include "components/viz/common/viz_utils.h"
- #include "content/public/browser/android/java_interfaces.h"
- #include "services/service_manager/public/cpp/interface_provider.h"
- #include "ui/base/resource/resource_bundle_android.h"
- #include "ui/base/ui_base_paths.h"
- #include "ui/display/util/display_util.h"
- #if BUILDFLAG(DFMIFY_DEV_UI)
- #include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h"
- #endif // BUILDFLAG(DFMIFY_DEV_UI)
- #elif BUILDFLAG(IS_POSIX)
- #include "chrome/browser/chrome_browser_main_posix.h"
- #elif BUILDFLAG(IS_FUCHSIA)
- #include "chrome/browser/fuchsia/chrome_browser_main_parts_fuchsia.h"
- #endif
- #if !BUILDFLAG(IS_CHROMEOS_ASH)
- #include "ui/accessibility/accessibility_features.h"
- #endif // !BUILDFLAG(IS_CHROMEOS_ASH)
- #if BUILDFLAG(IS_CHROMEOS)
- #include "chrome/browser/chromeos/policy/dlp/dlp_scoped_file_access_delegate.h"
- #include "chrome/browser/chromeos/tablet_mode/chrome_content_browser_client_tablet_mode_part.h"
- #include "chrome/browser/policy/networking/policy_cert_service.h"
- #include "chrome/browser/policy/networking/policy_cert_service_factory.h"
- #include "chrome/common/chromeos/extensions/chromeos_system_extension_info.h"
- #include "third_party/cros_system_api/switches/chrome_switches.h"
- #endif
- #if !BUILDFLAG(IS_ANDROID)
- #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
- #include "chrome/browser/devtools/devtools_window.h"
- #include "chrome/browser/media/unified_autoplay_config.h"
- #include "chrome/browser/new_tab_page/new_tab_page_util.h"
- #include "chrome/browser/page_info/about_this_site_side_panel_throttle.h"
- #include "chrome/browser/search/instant_service.h"
- #include "chrome/browser/search/instant_service_factory.h"
- #include "chrome/browser/serial/chrome_serial_delegate.h"
- #include "chrome/browser/task_manager/task_manager_interface.h"
- #include "chrome/browser/ui/browser.h"
- #include "chrome/browser/ui/browser_dialogs.h"
- #include "chrome/browser/ui/browser_finder.h"
- #include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
- #include "chrome/browser/web_applications/policy/web_app_policy_manager.h"
- #include "chrome/browser/web_applications/web_app_helpers.h"
- #include "chrome/browser/web_applications/web_app_provider.h"
- #include "chrome/browser/web_applications/web_app_registrar.h"
- #include "chrome/browser/webauthn/authenticator_request_scheduler.h"
- #include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
- #include "chrome/grit/chrome_unscaled_resources.h" // nogncheck crbug.com/1125897
- #include "components/commerce/core/commerce_feature_list.h"
- #include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom.h"
- #endif // !BUILDFLAG(IS_ANDROID)
- // TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
- // of lacros-chrome is complete.
- #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || \
- (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
- #include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
- #endif
- #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
- #include "components/crash/core/app/crash_switches.h"
- #include "components/crash/core/app/crashpad.h"
- #endif
- #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
- #if !BUILDFLAG(IS_ANDROID)
- #include "base/debug/leak_annotations.h"
- #include "components/crash/core/app/breakpad_linux.h"
- #endif // !BUILDFLAG(IS_ANDROID)
- #include "components/crash/content/browser/crash_handler_host_linux.h"
- #endif
- #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
- #include "chrome/browser/ui/webui/app_settings/web_app_settings_navigation_throttle.h"
- #endif
- #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || \
- BUILDFLAG(IS_CHROMEOS_ASH)
- #include "chrome/browser/enterprise/connectors/device_trust/navigation_throttle.h"
- #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) ||
- // BUILDFLAG(IS_CHROMEOS_ASH)
- // TODO(crbug.com/939205): Once the upcoming App Service is available, use a
- // single navigation throttle to display the intent picker on all platforms.
- #if !BUILDFLAG(IS_ANDROID)
- #if BUILDFLAG(IS_CHROMEOS)
- #include "chrome/browser/apps/intent_helper/common_apps_navigation_throttle.h"
- #include "chrome/browser/policy/system_features_disable_list_policy_handler.h"
- #else
- #include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
- #endif
- #endif
- #if defined(TOOLKIT_VIEWS)
- #include "chrome/browser/ui/side_search/side_search_side_contents_helper.h"
- #include "chrome/browser/ui/side_search/side_search_utils.h"
- #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
- #endif
- // TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
- // of lacros-chrome is complete.
- #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
- #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
- #endif
- #if BUILDFLAG(IS_LINUX)
- #include "chrome/browser/chrome_browser_main_extra_parts_linux.h"
- #elif defined(USE_OZONE)
- #include "chrome/browser/chrome_browser_main_extra_parts_ozone.h"
- #endif
- #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
- #include "components/captive_portal/content/captive_portal_tab_helper.h"
- #include "components/captive_portal/content/captive_portal_url_loader_throttle.h"
- #endif
- #if BUILDFLAG(ENABLE_NACL)
- #include "components/nacl/browser/nacl_host_message_filter.h"
- #include "components/nacl/browser/nacl_process_host.h"
- #include "components/nacl/common/nacl_process_type.h"
- #include "components/nacl/common/nacl_switches.h"
- #endif
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- #include "chrome/browser/accessibility/animation_policy_prefs.h"
- #include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
- #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
- #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
- #include "chrome/browser/extensions/extension_util.h"
- #include "chrome/browser/extensions/user_script_listener.h"
- #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
- #include "chrome/browser/ui/web_applications/app_browser_controller.h"
- #include "chrome/browser/web_applications/isolation_prefs_utils.h"
- #include "chrome/browser/web_applications/web_app_utils.h"
- #include "content/public/browser/site_isolation_policy.h"
- #include "extensions/browser/api/web_request/web_request_api.h"
- #include "extensions/browser/api/web_request/web_request_proxying_webtransport.h"
- #include "extensions/browser/content_script_tracker.h"
- #include "extensions/browser/extension_navigation_throttle.h"
- #include "extensions/browser/extension_protocols.h"
- #include "extensions/browser/extension_registry.h"
- #include "extensions/browser/extension_util.h"
- #include "extensions/browser/guest_view/web_view/web_view_guest.h"
- #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
- #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
- #include "extensions/browser/process_map.h"
- #include "extensions/common/constants.h"
- #include "extensions/common/extension.h"
- #include "extensions/common/extension_set.h"
- #include "extensions/common/manifest_handlers/background_info.h"
- #include "extensions/common/permissions/permissions_data.h"
- #include "extensions/common/switches.h"
- #endif // BUILDFLAG(ENABLE_EXTENSIONS)
- #if BUILDFLAG(ENABLE_PLUGINS)
- #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
- #include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
- #endif
- #if BUILDFLAG(ENABLE_PDF)
- #include "chrome/browser/pdf/chrome_pdf_stream_delegate.h"
- #include "components/pdf/browser/pdf_navigation_throttle.h"
- #include "components/pdf/browser/pdf_url_loader_request_interceptor.h"
- #include "components/pdf/common/internal_plugin_helpers.h"
- #endif // BUILDFLAG(ENABLE_PDF)
- #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
- #include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
- #endif
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- #include "chrome/browser/chromeos/app_mode/kiosk_settings_navigation_throttle.h"
- #include "chrome/browser/speech/tts_controller_delegate_impl.h"
- #endif // BUILDFLAG(IS_CHROMEOS_ASH)
- #if BUILDFLAG(ENABLE_MEDIA_REMOTING)
- #include "chrome/browser/media/cast_remoting_connector.h"
- #endif
- #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
- #include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
- #endif
- #if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
- #include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
- #endif
- #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
- #include "chrome/browser/safe_browsing/chrome_enterprise_url_lookup_service.h" // nogncheck crbug.com/1125897
- #include "chrome/browser/safe_browsing/chrome_enterprise_url_lookup_service_factory.h" // nogncheck crbug.com/1125897
- #endif
- #if BUILDFLAG(ENABLE_OFFLINE_PAGES)
- #include "chrome/browser/offline_pages/offline_page_navigation_throttle.h"
- #include "chrome/browser/offline_pages/offline_page_tab_helper.h"
- #include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
- #endif
- #if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
- #include "chrome/browser/ui/webui/tab_strip/chrome_content_browser_client_tab_strip_part.h"
- #endif
- #if BUILDFLAG(FULL_SAFE_BROWSING)
- #include "chrome/browser/enterprise/connectors/analysis/content_analysis_delegate.h"
- #endif
- #if BUILDFLAG(ENABLE_VR)
- #include "chrome/browser/vr/chrome_xr_integration_client.h"
- #endif
- #if BUILDFLAG(IS_CHROMEOS_LACROS)
- #include "chrome/browser/chrome_browser_main_parts_lacros.h"
- #include "chrome/browser/lacros/chrome_browser_main_extra_parts_lacros.h"
- #include "chrome/browser/speech/tts_lacros.h"
- #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_lacros.h"
- #include "chromeos/constants/chromeos_features.h"
- #include "chromeos/lacros/lacros_service.h"
- #include "ui/base/ui_base_switches.h"
- #endif
- #if BUILDFLAG(USE_MINIKIN_HYPHENATION) && !BUILDFLAG(IS_ANDROID)
- #include "chrome/browser/component_updater/hyphenation_component_installer.h"
- #endif
- // This should be after all other #includes.
- #if defined(_WINDOWS_) // Detect whether windows.h was included.
- #include "base/win/windows_h_disallowed.h"
- #endif // defined(_WINDOWS_)
- #if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
- #include "components/services/screen_ai/public/cpp/utilities.h"
- #endif
- using blink::mojom::EffectiveConnectionType;
- using blink::web_pref::WebPreferences;
- using content::BrowserThread;
- using content::BrowserURLHandler;
- using content::ChildProcessSecurityPolicy;
- using content::QuotaPermissionContext;
- using content::RenderFrameHost;
- using content::SiteInstance;
- using content::WebContents;
- #if BUILDFLAG(IS_POSIX)
- using content::PosixFileDescriptorInfo;
- #endif
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- using extensions::APIPermission;
- using extensions::ChromeContentBrowserClientExtensionsPart;
- using extensions::Extension;
- using extensions::Manifest;
- using extensions::mojom::APIPermissionID;
- #endif
- #if BUILDFLAG(ENABLE_PLUGINS)
- using plugins::ChromeContentBrowserClientPluginsPart;
- #endif
- namespace {
- #if BUILDFLAG(IS_WIN) && !defined(COMPONENT_BUILD) && \
- !defined(ADDRESS_SANITIZER)
- // Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when
- // running on Windows 10 1511 and above. See
- // https://blogs.windows.com/blog/tag/code-integrity-guard/.
- const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity",
- base::FEATURE_ENABLED_BY_DEFAULT};
- // Enables pre-launch Code Integrity Guard (CIG) for Chrome network service
- // process, when running on Windows 10 1511 and above. This has no effect if
- // NetworkServiceSandbox feature is disabled. See
- // https://blogs.windows.com/blog/tag/code-integrity-guard/.
- const base::Feature kNetworkServiceCodeIntegrity{
- "NetworkServiceCodeIntegrity", base::FEATURE_DISABLED_BY_DEFAULT};
- #endif // BUILDFLAG(IS_WIN) && !defined(COMPONENT_BUILD) &&
- // !defined(ADDRESS_SANITIZER)
- #if BUILDFLAG(IS_ANDROID)
- // Kill switch that allows falling back to the legacy behavior on Android when
- // it comes to site isolation for Gaia's origin (|GaiaUrls::gaia_origin()|).
- const base::Feature kAllowGaiaOriginIsolationOnAndroid{
- "AllowGaiaOriginIsolationOnAndroid", base::FEATURE_ENABLED_BY_DEFAULT};
- #endif // BUILDFLAG(IS_ANDROID)
- // A small ChromeBrowserMainExtraParts that invokes a callback when threads are
- // ready. Used to initialize ChromeContentBrowserClient data that needs the UI
- // thread.
- class ChromeBrowserMainExtraPartsThreadNotifier final
- : public ChromeBrowserMainExtraParts {
- public:
- explicit ChromeBrowserMainExtraPartsThreadNotifier(
- base::OnceClosure threads_ready_closure)
- : threads_ready_closure_(std::move(threads_ready_closure)) {}
- // ChromeBrowserMainExtraParts:
- void PostCreateThreads() final { std::move(threads_ready_closure_).Run(); }
- private:
- base::OnceClosure threads_ready_closure_;
- };
- bool IsSSLErrorOverrideAllowedForOrigin(const GURL& request_url,
- PrefService* prefs) {
- DCHECK(request_url.SchemeIsCryptographic());
- if (prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed))
- return true;
- const base::Value::List& allow_list_urls =
- prefs->GetValueList(prefs::kSSLErrorOverrideAllowedForOrigins);
- if (allow_list_urls.empty())
- return false;
- for (auto const& value : allow_list_urls) {
- ContentSettingsPattern pattern =
- ContentSettingsPattern::FromString(value.GetString());
- if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
- continue;
- // Despite |request_url| being a GURL, the path is ignored when matching.
- if (pattern.Matches(request_url))
- return true;
- }
- return false;
- }
- // Wrapper for SSLErrorHandler::HandleSSLError() that supplies //chrome-level
- // parameters.
- void HandleSSLErrorWrapper(
- content::WebContents* web_contents,
- int cert_error,
- const net::SSLInfo& ssl_info,
- const GURL& request_url,
- std::unique_ptr<SSLCertReporter> ssl_cert_reporter,
- SSLErrorHandler::BlockingPageReadyCallback blocking_page_ready_callback) {
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
- // Profile should always outlive a WebContents
- DCHECK(profile);
- captive_portal::CaptivePortalService* captive_portal_service = nullptr;
- #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
- captive_portal_service = CaptivePortalServiceFactory::GetForProfile(profile);
- #endif
- SSLErrorHandler::HandleSSLError(
- web_contents, cert_error, ssl_info, request_url,
- std::move(ssl_cert_reporter), std::move(blocking_page_ready_callback),
- g_browser_process->network_time_tracker(), captive_portal_service,
- std::make_unique<ChromeSecurityBlockingPageFactory>(),
- IsSSLErrorOverrideAllowedForOrigin(request_url, profile->GetPrefs()));
- }
- enum AppLoadedInTabSource {
- // A platform app page tried to load one of its own URLs in a tab.
- APP_LOADED_IN_TAB_SOURCE_APP = 0,
- // A platform app background page tried to load one of its own URLs in a tab.
- APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
- // An extension or app tried to load a resource of a different platform app in
- // a tab.
- APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
- // A non-app and non-extension page tried to load a platform app in a tab.
- APP_LOADED_IN_TAB_SOURCE_OTHER,
- APP_LOADED_IN_TAB_SOURCE_MAX
- };
- // Cached version of the locale so we can return the locale on the I/O
- // thread.
- std::string& GetIOThreadApplicationLocale() {
- static base::NoDestructor<std::string> s;
- return *s;
- }
- // Returns a copy of the given url with its host set to given host and path set
- // to given path. Other parts of the url will be the same.
- GURL ReplaceURLHostAndPath(const GURL& url,
- const std::string& host,
- const std::string& path) {
- GURL::Replacements replacements;
- replacements.SetHostStr(host);
- replacements.SetPathStr(path);
- return url.ReplaceComponents(replacements);
- }
- // Handles the rewriting of the new tab page URL based on group policy.
- bool HandleNewTabPageLocationOverride(
- GURL* url,
- content::BrowserContext* browser_context) {
- if (!url->SchemeIs(content::kChromeUIScheme) ||
- url->host() != chrome::kChromeUINewTabHost) {
- return false;
- }
- Profile* profile = Profile::FromBrowserContext(browser_context);
- // Don't change the URL when incognito mode.
- if (profile->IsOffTheRecord())
- return false;
- std::string ntp_location =
- profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
- if (ntp_location.empty())
- return false;
- url::Component scheme;
- if (!url::ExtractScheme(ntp_location.data(),
- static_cast<int>(ntp_location.length()), &scheme)) {
- ntp_location = base::StrCat(
- {url::kHttpsScheme, url::kStandardSchemeSeparator, ntp_location});
- }
- *url = GURL(ntp_location);
- return true;
- }
- #if !BUILDFLAG(IS_ANDROID)
- // Check if the current url is allowlisted based on a list of allowlisted urls.
- bool IsURLAllowlisted(const GURL& current_url,
- const base::Value::List& allowlisted_urls) {
- // Only check on HTTP and HTTPS pages.
- if (!current_url.SchemeIsHTTPOrHTTPS())
- return false;
- for (auto const& value : allowlisted_urls) {
- ContentSettingsPattern pattern =
- ContentSettingsPattern::FromString(value.GetString());
- if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
- continue;
- if (pattern.Matches(current_url))
- return true;
- }
- return false;
- }
- // Check if autoplay is allowed by policy configuration.
- bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
- PrefService* prefs) {
- DCHECK(prefs);
- // Check if we have globally allowed autoplay by policy.
- if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
- prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
- return true;
- }
- if (!contents)
- return false;
- // Check if the current URL matches a URL pattern on the allowlist.
- const base::Value::List& autoplay_allowlist =
- prefs->GetValueList(prefs::kAutoplayAllowlist);
- return prefs->IsManagedPreference(prefs::kAutoplayAllowlist) &&
- IsURLAllowlisted(contents->GetURL(), autoplay_allowlist);
- }
- #endif
- blink::mojom::AutoplayPolicy GetAutoplayPolicyForWebContents(
- WebContents* web_contents) {
- const base::CommandLine& command_line =
- *base::CommandLine::ForCurrentProcess();
- std::string autoplay_policy = media::GetEffectiveAutoplayPolicy(command_line);
- auto result = blink::mojom::AutoplayPolicy::kDocumentUserActivationRequired;
- if (autoplay_policy == switches::autoplay::kNoUserGestureRequiredPolicy) {
- result = blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
- } else if (autoplay_policy ==
- switches::autoplay::kUserGestureRequiredPolicy) {
- result = blink::mojom::AutoplayPolicy::kUserGestureRequired;
- } else if (autoplay_policy ==
- switches::autoplay::kDocumentUserActivationRequiredPolicy) {
- result = blink::mojom::AutoplayPolicy::kDocumentUserActivationRequired;
- } else {
- NOTREACHED();
- }
- #if !BUILDFLAG(IS_ANDROID)
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
- PrefService* prefs = profile->GetPrefs();
- // Override autoplay policy used in internal switch in case of enabling
- // features such as policy, allowlisting or disabling from settings.
- if (IsAutoplayAllowedByPolicy(web_contents, prefs)) {
- result = blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
- } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
- result == blink::mojom::AutoplayPolicy::
- kDocumentUserActivationRequired) {
- result = UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
- ? blink::mojom::AutoplayPolicy::kDocumentUserActivationRequired
- : blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
- } else if (web_contents->GetPrimaryMainFrame()->IsFeatureEnabled(
- blink::mojom::PermissionsPolicyFeature::kAutoplay) &&
- IsAutoplayAllowedByPolicy(web_contents->GetOuterWebContents(),
- prefs)) {
- // If the domain policy allows autoplay and has delegated that to an iframe,
- // allow autoplay within the iframe. Only allow a nesting of single depth.
- result = blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
- }
- #endif // !BUILDFLAG(IS_ANDROID)
- return result;
- }
- #if BUILDFLAG(IS_ANDROID)
- int GetCrashSignalFD(const base::CommandLine& command_line) {
- return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
- }
- #elif BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
- breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
- const std::string& process_type) {
- base::FilePath dumps_path;
- base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
- {
- ANNOTATE_SCOPED_MEMORY_LEAK;
- bool upload = !getenv(env_vars::kHeadless);
- breakpad::CrashHandlerHostLinux* crash_handler =
- new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
- crash_handler->StartUploaderThread();
- return crash_handler;
- }
- }
- int GetCrashSignalFD(const base::CommandLine& command_line) {
- if (crash_reporter::IsCrashpadEnabled()) {
- int fd;
- pid_t pid;
- return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
- }
- // Extensions have the same process type as renderers.
- if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
- static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
- if (!crash_handler)
- crash_handler = CreateCrashHandlerHost("extension");
- return crash_handler->GetDeathSignalSocket();
- }
- std::string process_type =
- command_line.GetSwitchValueASCII(switches::kProcessType);
- if (process_type == switches::kRendererProcess) {
- static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
- if (!crash_handler)
- crash_handler = CreateCrashHandlerHost(process_type);
- return crash_handler->GetDeathSignalSocket();
- }
- if (process_type == switches::kPpapiPluginProcess) {
- static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
- if (!crash_handler)
- crash_handler = CreateCrashHandlerHost(process_type);
- return crash_handler->GetDeathSignalSocket();
- }
- if (process_type == switches::kGpuProcess) {
- static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
- if (!crash_handler)
- crash_handler = CreateCrashHandlerHost(process_type);
- return crash_handler->GetDeathSignalSocket();
- }
- if (process_type == switches::kUtilityProcess) {
- static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
- if (!crash_handler)
- crash_handler = CreateCrashHandlerHost(process_type);
- return crash_handler->GetDeathSignalSocket();
- }
- return -1;
- }
- #endif // BUILDFLAG(IS_ANDROID)
- void SetApplicationLocaleOnIOThread(const std::string& locale) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- GetIOThreadApplicationLocale() = locale;
- }
- // An implementation of the SSLCertReporter interface used by
- // SSLErrorHandler. Uses CertificateReportingService to send reports. The
- // service handles queueing and re-sending of failed reports. Each certificate
- // error creates a new instance of this class.
- class CertificateReportingServiceCertReporter : public SSLCertReporter {
- public:
- explicit CertificateReportingServiceCertReporter(
- content::WebContents* web_contents)
- : service_(CertificateReportingServiceFactory::GetForBrowserContext(
- web_contents->GetBrowserContext())) {}
- CertificateReportingServiceCertReporter(
- const CertificateReportingServiceCertReporter&) = delete;
- CertificateReportingServiceCertReporter& operator=(
- const CertificateReportingServiceCertReporter&) = delete;
- ~CertificateReportingServiceCertReporter() override {}
- // SSLCertReporter implementation
- void ReportInvalidCertificateChain(
- const std::string& serialized_report) override {
- service_->Send(serialized_report);
- }
- private:
- raw_ptr<CertificateReportingService> service_;
- };
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- AppLoadedInTabSource ClassifyAppLoadedInTabSource(
- const GURL& opener_url,
- const extensions::Extension* target_platform_app) {
- if (!opener_url.SchemeIs(extensions::kExtensionScheme)) {
- // The forbidden app URL was being opened by a non-extension page (e.g.
- // http).
- return APP_LOADED_IN_TAB_SOURCE_OTHER;
- }
- if (opener_url.host_piece() != target_platform_app->id()) {
- // The forbidden app URL was being opened by a different app or extension.
- return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
- }
- // This platform app was trying to window.open() one of its own URLs.
- if (opener_url ==
- extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
- // Source was the background page.
- return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
- }
- // Source was a different page inside the app.
- return APP_LOADED_IN_TAB_SOURCE_APP;
- }
- // Returns true if there is is an extension matching `url` in
- // `render_process_id` with `permission`.
- //
- // GetExtensionOrAppByURL requires a full URL in order to match with a hosted
- // app, even though normal extensions just use the host.
- bool URLHasExtensionPermission(extensions::ProcessMap* process_map,
- extensions::ExtensionRegistry* registry,
- const GURL& url,
- int render_process_id,
- APIPermissionID permission) {
- // Includes web URLs that are part of an extension's web extent.
- const Extension* extension =
- registry->enabled_extensions().GetExtensionOrAppByURL(url);
- return extension &&
- extension->permissions_data()->HasAPIPermission(permission) &&
- process_map->Contains(extension->id(), render_process_id);
- }
- #endif
- mojo::PendingRemote<prerender::mojom::PrerenderCanceler> GetPrerenderCanceler(
- base::OnceCallback<content::WebContents*()> wc_getter) {
- mojo::PendingRemote<prerender::mojom::PrerenderCanceler> canceler;
- prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
- std::move(wc_getter).Run())
- ->AddPrerenderCancelerReceiver(canceler.InitWithNewPipeAndPassReceiver());
- return canceler;
- }
- bool ShouldHonorPolicies() {
- #if BUILDFLAG(IS_WIN)
- return policy::ManagementServiceFactory::GetForPlatform()
- ->GetManagementAuthorityTrustworthiness() >=
- policy::ManagementAuthorityTrustworthiness::TRUSTED;
- #else
- return true;
- #endif
- }
- // Used by Enterprise policy. Disable blocking of navigations toward external
- // applications from a sandboxed iframe.
- // https://chromestatus.com/feature/5680742077038592
- const char kDisableSandboxExternalProtocolSwitch[] =
- "disable-sandbox-external-protocols";
- void LaunchURL(base::WeakPtr<ChromeContentBrowserClient> client,
- const GURL& url,
- content::WebContents::Getter web_contents_getter,
- ui::PageTransition page_transition,
- bool is_primary_main_frame,
- bool is_in_fenced_frame_tree,
- network::mojom::WebSandboxFlags sandbox_flags,
- bool has_user_gesture,
- const absl::optional<url::Origin>& initiating_origin,
- content::WeakDocumentPtr initiator_document) {
- // If there is no longer a WebContents, the request may have raced with tab
- // closing. Don't fire the external request. (It may have been a prerender.)
- content::WebContents* web_contents = web_contents_getter.Run();
- if (!web_contents)
- return;
- // Do not launch external requests attached to unswapped no-state prefetchers.
- prerender::NoStatePrefetchContents* no_state_prefetch_contents =
- prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
- web_contents);
- if (no_state_prefetch_contents) {
- no_state_prefetch_contents->Destroy(
- prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
- return;
- }
- // Do not launch external requests for schemes that have a handler registered.
- custom_handlers::ProtocolHandlerRegistry* protocol_handler_registry =
- ProtocolHandlerRegistryFactory::GetForBrowserContext(
- web_contents->GetBrowserContext());
- if (protocol_handler_registry &&
- protocol_handler_registry->IsHandledProtocol(url.scheme()))
- return;
- // Sandbox flags
- // =============
- //
- // Navigations to external protocol in iframe can be seen as "top-level"
- // navigations somehow, because they cause the user to switch from Chrome's
- // page toward a different application.
- //
- // Internally in Chrome, they are seen as aborted iframe navigation, so the
- // regular sandbox logic do not really apply.
- //
- // This block adds an extra logic, gating external protocol in iframes to have
- // one of:
- // - 'allow-top-navigation'
- // - 'allow-top-navigation-to-custom-protocols'
- // - 'allow-top-navigation-by-user-navigation' + user-activation
- // - 'allow-popups'
- //
- // See https://crbug.com/1148777
- if (!is_primary_main_frame) {
- using SandboxFlags = network::mojom::WebSandboxFlags;
- auto allow = [&](SandboxFlags flag) {
- return (sandbox_flags & flag) == SandboxFlags::kNone;
- };
- bool allowed = (allow(SandboxFlags::kTopNavigationToCustomProtocols)) ||
- (allow(SandboxFlags::kTopNavigationByUserActivation) &&
- has_user_gesture);
- if (!allowed) {
- content::RenderFrameHost* rfh = web_contents->GetPrimaryMainFrame();
- if (client) {
- client->LogWebFeatureForCurrentPage(
- rfh, blink::mojom::WebFeature::kExternalProtocolBlockedBySandbox);
- }
- if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
- kDisableSandboxExternalProtocolSwitch)) {
- if (base::FeatureList::IsEnabled(
- features::kSandboxExternalProtocolBlocked)) {
- rfh->AddMessageToConsole(
- blink::mojom::ConsoleMessageLevel::kError,
- "Navigation to external protocol blocked by sandbox, because it "
- "doesn't contain any of: "
- "'allow-top-navigation-to-custom-protocols', "
- "'allow-top-navigation-by-user-activation', "
- "'allow-top-navigation', or "
- "'allow-popups'. See "
- "https://chromestatus.com/feature/5680742077038592 and "
- "https://chromeenterprise.google/policies/"
- "#SandboxExternalProtocolBlocked");
- return;
- }
- if (base::FeatureList::IsEnabled(
- features::kSandboxExternalProtocolBlockedWarning)) {
- rfh->AddMessageToConsole(
- blink::mojom::ConsoleMessageLevel::kError,
- "After Chrome M103, navigation toward external protocol "
- "will be blocked by sandbox, if it doesn't contain any of:"
- "'allow-top-navigation-to-custom-protocols', "
- "'allow-top-navigation-by-user-activation', "
- "'allow-top-navigation', or "
- "'allow-popups'. See "
- "https://chromestatus.com/feature/5680742077038592 and "
- "https://chromeenterprise.google/policies/"
- "#SandboxExternalProtocolBlocked");
- }
- }
- }
- }
- bool is_allowlisted = false;
- PolicyBlocklistService* service =
- PolicyBlocklistFactory::GetForBrowserContext(
- web_contents->GetBrowserContext());
- if (ShouldHonorPolicies() && service) {
- const policy::URLBlocklist::URLBlocklistState url_state =
- service->GetURLBlocklistState(url);
- is_allowlisted =
- url_state == policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST;
- }
- // If the URL is in allowlist, we launch it without asking the user and
- // without any additional security checks. Since the URL is allowlisted,
- // we assume it can be executed.
- if (is_allowlisted) {
- ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(
- url, web_contents, std::move(initiator_document));
- } else {
- ExternalProtocolHandler::LaunchUrl(
- url, std::move(web_contents_getter), page_transition, has_user_gesture,
- is_in_fenced_frame_tree, initiating_origin,
- std::move(initiator_document));
- }
- }
- void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
- // |allowlist| combines pref/policy + cmdline switch in the browser process.
- // For renderer and utility (e.g. NetworkService) processes the switch is the
- // only available source, so below the combined (pref/policy + cmdline)
- // allowlist of secure origins is injected into |cmdline| for these other
- // processes.
- std::vector<std::string> allowlist =
- network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
- if (!allowlist.empty()) {
- cmdline->AppendSwitchASCII(
- network::switches::kUnsafelyTreatInsecureOriginAsSecure,
- base::JoinString(allowlist, ","));
- }
- }
- #if BUILDFLAG(IS_WIN) && !defined(COMPONENT_BUILD) && \
- !defined(ADDRESS_SANITIZER)
- // Returns the full path to |module_name|. Both dev builds (where |module_name|
- // is in the current executable's directory) and proper installs (where
- // |module_name| is in a versioned sub-directory of the current executable's
- // directory) are supported. The identified file is not guaranteed to exist.
- base::FilePath GetModulePath(base::WStringPiece module_name) {
- base::FilePath exe_dir;
- const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
- DCHECK(has_path);
- // Look for the module in a versioned sub-directory of the current
- // executable's directory and return the path if it can be read. This is the
- // expected location of modules for proper installs.
- const base::FilePath module_path =
- exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
- if (base::PathExists(module_path))
- return module_path;
- // Otherwise, return the path to the module in the current executable's
- // directory. This is the expected location of modules for dev builds.
- return exe_dir.Append(module_name);
- }
- #endif // BUILDFLAG(IS_WIN) && !defined(COMPONENT_BUILD) &&
- // !defined(ADDRESS_SANITIZER)
- void MaybeAddThrottle(
- std::unique_ptr<content::NavigationThrottle> maybe_throttle,
- std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) {
- if (maybe_throttle)
- throttles->push_back(std::move(maybe_throttle));
- }
- void MaybeAddCondition(
- std::unique_ptr<content::CommitDeferringCondition> maybe_condition,
- std::vector<std::unique_ptr<content::CommitDeferringCondition>>*
- conditions) {
- if (maybe_condition)
- conditions->push_back(std::move(maybe_condition));
- }
- void MaybeAddThrottles(
- std::vector<std::unique_ptr<content::NavigationThrottle>> additional,
- std::vector<std::unique_ptr<content::NavigationThrottle>>* combined) {
- combined->insert(combined->end(), std::make_move_iterator(additional.begin()),
- std::make_move_iterator(additional.end()));
- }
- // Returns whether |web_contents| is within a hosted app.
- bool IsInHostedApp(WebContents* web_contents) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
- return web_app::AppBrowserController::IsWebApp(browser);
- #else
- return false;
- #endif
- }
- bool IsErrorPageAutoReloadEnabled() {
- const base::CommandLine& command_line =
- *base::CommandLine::ForCurrentProcess();
- if (command_line.HasSwitch(switches::kEnableAutomation))
- return false;
- if (command_line.HasSwitch(embedder_support::kEnableAutoReload))
- return true;
- if (command_line.HasSwitch(embedder_support::kDisableAutoReload))
- return false;
- return true;
- }
- bool IsTopChromeWebUIURL(const GURL& url) {
- return url.SchemeIs(content::kChromeUIScheme) &&
- base::EndsWith(url.host_piece(), chrome::kChromeUITopChromeDomain);
- }
- bool DoesGaiaOriginRequireDedicatedProcess() {
- #if !BUILDFLAG(IS_ANDROID)
- return true;
- #else
- // Sign-in process isolation is not strictly needed on Android, see
- // https://crbug.com/739418. On Android, it's more optional but it does
- // improve security generally and specifically it allows the exposure of
- // certain optional privileged APIs.
- // Kill switch that falls back to the legacy behavior.
- if (!base::FeatureList::IsEnabled(kAllowGaiaOriginIsolationOnAndroid)) {
- return false;
- }
- if (site_isolation::SiteIsolationPolicy::
- ShouldDisableSiteIsolationDueToMemoryThreshold(
- content::SiteIsolationMode::kPartialSiteIsolation)) {
- // Insufficient memory to isolate Gaia's origin.
- return false;
- }
- return true;
- #endif // !BUILDFLAG(IS_ANDROID)
- }
- } // namespace
- ChromeContentBrowserClient::ChromeContentBrowserClient() {
- #if BUILDFLAG(ENABLE_PLUGINS)
- extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
- #endif
- #if BUILDFLAG(IS_CHROMEOS)
- extra_parts_.push_back(new ChromeContentBrowserClientTabletModePart);
- #endif // BUILDFLAG(IS_CHROMEOS)
- #if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
- extra_parts_.push_back(new ChromeContentBrowserClientTabStripPart);
- #endif
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
- #endif
- extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
- }
- ChromeContentBrowserClient::~ChromeContentBrowserClient() {
- for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
- delete extra_parts_[i];
- extra_parts_.clear();
- }
- // static
- void ChromeContentBrowserClient::RegisterLocalStatePrefs(
- PrefRegistrySimple* registry) {
- registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
- registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
- registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
- registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
- registry->RegisterBooleanPref(prefs::kTabFreezingEnabled, true);
- registry->RegisterIntegerPref(prefs::kSCTAuditingHashdanceReportCount, 0);
- }
- // static
- void ChromeContentBrowserClient::RegisterProfilePrefs(
- user_prefs::PrefRegistrySyncable* registry) {
- registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
- registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
- // Register user prefs for mapping SitePerProcess and IsolateOrigins in
- // user policy in addition to the same named ones in Local State (which are
- // used for mapping the command-line flags).
- registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
- registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
- registry->RegisterListPref(
- site_isolation::prefs::kUserTriggeredIsolatedOrigins);
- registry->RegisterDictionaryPref(
- site_isolation::prefs::kWebTriggeredIsolatedOrigins);
- registry->RegisterDictionaryPref(
- prefs::kDevToolsBackgroundServicesExpirationDict);
- registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
- #if !BUILDFLAG(IS_ANDROID)
- registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
- registry->RegisterListPref(prefs::kAutoplayAllowlist);
- registry->RegisterIntegerPref(prefs::kFetchKeepaliveDurationOnShutdown, 0);
- registry->RegisterBooleanPref(
- prefs::kSharedArrayBufferUnrestrictedAccessAllowed, false);
- #endif
- registry->RegisterBooleanPref(prefs::kSandboxExternalProtocolBlocked, true);
- registry->RegisterBooleanPref(prefs::kDisplayCapturePermissionsPolicyEnabled,
- true);
- registry->RegisterBooleanPref(prefs::kSSLErrorOverrideAllowed, true);
- registry->RegisterListPref(prefs::kSSLErrorOverrideAllowedForOrigins);
- registry->RegisterBooleanPref(
- prefs::kSuppressDifferentOriginSubframeJSDialogs, true);
- registry->RegisterBooleanPref(
- policy::policy_prefs::kSetTimeoutWithout1MsClampEnabled, false);
- registry->RegisterBooleanPref(
- policy::policy_prefs::kUnthrottledNestedTimeoutEnabled, false);
- #if BUILDFLAG(IS_ANDROID)
- registry->RegisterBooleanPref(prefs::kWebXRImmersiveArEnabled, true);
- #endif
- registry->RegisterBooleanPref(prefs::kPromptOnMultipleMatchingCertificates,
- false);
- registry->RegisterBooleanPref(prefs::kCorsNonWildcardRequestHeadersSupport,
- true);
- registry->RegisterDictionaryPref(
- enterprise::content::kCopyPreventionSettings);
- registry->RegisterIntegerPref(
- prefs::kUserAgentReduction,
- static_cast<int>(
- embedder_support::UserAgentReductionEnterprisePolicyState::kDefault));
- registry->RegisterBooleanPref(prefs::kOriginAgentClusterDefaultEnabled, true);
- registry->RegisterIntegerPref(
- prefs::kForceMajorVersionToMinorPositionInUserAgent,
- static_cast<int>(
- embedder_support::ForceMajorVersionToMinorPosition::kDefault));
- registry->RegisterBooleanPref(
- policy::policy_prefs::kIsolatedAppsDeveloperModeAllowed, true);
- // TODO(crbug.com/1277431): Disable it by default in M109.
- registry->RegisterBooleanPref(policy::policy_prefs::kEventPathEnabled, true);
- }
- // static
- void ChromeContentBrowserClient::SetApplicationLocale(
- const std::string& locale) {
- // The common case is that this function is called early in Chrome startup
- // before any threads are created or registered. When there are no threads,
- // we can just set the string without worrying about threadsafety.
- if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
- GetIOThreadApplicationLocale() = locale;
- return;
- }
- // Otherwise we're being called to change the locale. In this case set it on
- // the IO thread.
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- content::GetIOThreadTaskRunner({})->PostTask(
- FROM_HERE, base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
- }
- std::unique_ptr<content::BrowserMainParts>
- ChromeContentBrowserClient::CreateBrowserMainParts(bool is_integration_test) {
- std::unique_ptr<ChromeBrowserMainParts> main_parts;
- // Construct the Main browser parts based on the OS type.
- #if BUILDFLAG(IS_WIN)
- main_parts = std::make_unique<ChromeBrowserMainPartsWin>(is_integration_test,
- &startup_data_);
- #elif BUILDFLAG(IS_MAC)
- main_parts = std::make_unique<ChromeBrowserMainPartsMac>(is_integration_test,
- &startup_data_);
- #elif BUILDFLAG(IS_CHROMEOS_ASH)
- main_parts = std::make_unique<ash::ChromeBrowserMainPartsAsh>(
- is_integration_test, &startup_data_);
- #elif BUILDFLAG(IS_CHROMEOS_LACROS)
- main_parts = std::make_unique<ChromeBrowserMainPartsLacros>(
- is_integration_test, &startup_data_);
- #elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
- main_parts = std::make_unique<ChromeBrowserMainPartsLinux>(
- is_integration_test, &startup_data_);
- #elif BUILDFLAG(IS_ANDROID)
- main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(
- is_integration_test, &startup_data_);
- #elif BUILDFLAG(IS_POSIX)
- main_parts = std::make_unique<ChromeBrowserMainPartsPosix>(
- is_integration_test, &startup_data_);
- #elif BUILDFLAG(IS_FUCHSIA)
- main_parts = std::make_unique<ChromeBrowserMainPartsFuchsia>(
- is_integration_test, &startup_data_);
- #else
- NOTREACHED();
- main_parts = std::make_unique<ChromeBrowserMainParts>(is_integration_test,
- &startup_data_);
- #endif
- main_parts->AddParts(
- std::make_unique<ChromeBrowserMainExtraPartsThreadNotifier>(
- base::BindOnce(&ChromeContentBrowserClient::InitOnUIThread,
- weak_factory_.GetWeakPtr())));
- bool add_profiles_extra_parts = true;
- #if BUILDFLAG(IS_ANDROID)
- if (startup_data_.HasBuiltProfilePrefService())
- add_profiles_extra_parts = false;
- #endif
- if (add_profiles_extra_parts)
- chrome::AddProfilesExtraParts(main_parts.get());
- // Construct additional browser parts. Stages are called in the order in
- // which they are added.
- #if defined(TOOLKIT_VIEWS)
- #if BUILDFLAG(IS_CHROMEOS_LACROS)
- main_parts->AddParts(
- std::make_unique<ChromeBrowserMainExtraPartsViewsLacros>());
- // TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
- // of lacros-chrome is complete.
- #elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
- main_parts->AddParts(
- std::make_unique<ChromeBrowserMainExtraPartsViewsLinux>());
- #else
- main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsViews>());
- #endif
- #endif
- #if BUILDFLAG(IS_MAC)
- main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsMac>());
- #endif
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- // TODO(jamescook): Combine with `ChromeBrowserMainPartsAsh`.
- main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsAsh>());
- #endif
- #if BUILDFLAG(IS_CHROMEOS_LACROS)
- main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsLacros>());
- #endif
- #if BUILDFLAG(IS_LINUX)
- main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsLinux>());
- #elif defined(USE_OZONE)
- main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsOzone>());
- #endif
- main_parts->AddParts(
- std::make_unique<ChromeBrowserMainExtraPartsPerformanceMonitor>());
- main_parts->AddParts(
- std::make_unique<ChromeBrowserMainExtraPartsPerformanceManager>());
- main_parts->AddParts(
- std::make_unique<ChromeBrowserMainExtraPartsProfiling>());
- main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsMemory>());
- chrome::AddMetricsExtraParts(main_parts.get());
- // Always add ChromeBrowserMainExtraPartsGpu last to make sure
- // GpuDataManager initialization could pick up about:flags settings.
- main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsGpu>());
- main_parts->AddParts(
- std::make_unique<ChromeBrowserMainExtraPartsSegmentationPlatform>());
- return main_parts;
- }
- void ChromeContentBrowserClient::PostAfterStartupTask(
- const base::Location& from_here,
- const scoped_refptr<base::SequencedTaskRunner>& task_runner,
- base::OnceClosure task) {
- AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
- }
- bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
- return AfterStartupTaskUtils::IsBrowserStartupComplete();
- }
- void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
- AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
- }
- bool ChromeContentBrowserClient::IsShuttingDown() {
- return browser_shutdown::HasShutdownStarted();
- }
- content::StoragePartitionConfig
- ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
- content::BrowserContext* browser_context,
- const GURL& site) {
- // Default to the browser-wide storage partition and override based on |site|
- // below.
- content::StoragePartitionConfig storage_partition_config =
- content::StoragePartitionConfig::CreateDefault(browser_context);
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- // TODO(crbug.com/1212263): Isolated PWAs are tracked by origin, but this
- // function takes a site, so it will only work correctly when the site equals
- // the full origin.
- if (content::SiteIsolationPolicy::ShouldUrlUseApplicationIsolationLevel(
- browser_context, site)) {
- Profile* profile = Profile::FromBrowserContext(browser_context);
- const std::string* isolation_key = web_app::GetStorageIsolationKey(
- profile->GetPrefs(), url::Origin::Create(site));
- CHECK(isolation_key);
- // |in_memory| and |partition_name| are only used in guest schemes, so they
- // are cleared here.
- return content::StoragePartitionConfig::Create(
- browser_context, *isolation_key,
- /*partition_name=*/std::string(),
- /*in_memory=*/false);
- }
- if (site.SchemeIs(extensions::kExtensionScheme)) {
- // The host in an extension site URL is the extension_id.
- CHECK(site.has_host());
- return extensions::util::GetStoragePartitionConfigForExtensionId(
- site.host(), browser_context);
- }
- #endif
- return storage_partition_config;
- }
- std::unique_ptr<content::WebContentsViewDelegate>
- ChromeContentBrowserClient::GetWebContentsViewDelegate(
- content::WebContents* web_contents) {
- if (auto* registry =
- performance_manager::PerformanceManagerRegistry::GetInstance()) {
- registry->MaybeCreatePageNodeForWebContents(web_contents);
- }
- return CreateWebContentsViewDelegate(web_contents);
- }
- bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
- #if BUILDFLAG(IS_ANDROID)
- const base::android::ApplicationState app_state =
- base::android::ApplicationStatusListener::GetState();
- return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
- base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
- base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
- #else
- return true;
- #endif
- }
- void ChromeContentBrowserClient::RenderProcessWillLaunch(
- content::RenderProcessHost* host) {
- Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
- WebRtcLoggingController::AttachToRenderProcessHost(
- host, g_browser_process->webrtc_log_uploader());
- // The audio manager outlives the host, so it's safe to hand a raw pointer to
- // it to the AudioDebugRecordingsHandler, which is owned by the host.
- AudioDebugRecordingsHandler* audio_debug_recordings_handler =
- new AudioDebugRecordingsHandler(profile);
- host->SetUserData(
- AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
- std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
- audio_debug_recordings_handler));
- #if BUILDFLAG(ENABLE_NACL)
- host->AddFilter(new nacl::NaClHostMessageFilter(
- host->GetID(), profile->IsOffTheRecord(), profile->GetPath()));
- #endif
- #if BUILDFLAG(IS_ANDROID)
- // Data cannot be persisted if the profile is off the record.
- host->AddFilter(
- new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
- // Register CrashMemoryMetricsCollector to report oom related metrics.
- host->SetUserData(
- CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
- std::make_unique<CrashMemoryMetricsCollector>(host));
- #endif
- RendererUpdaterFactory::GetForProfile(profile)->InitializeRenderer(host);
- for (size_t i = 0; i < extra_parts_.size(); ++i)
- extra_parts_[i]->RenderProcessWillLaunch(host);
- }
- GURL ChromeContentBrowserClient::GetEffectiveURL(
- content::BrowserContext* browser_context,
- const GURL& url) {
- Profile* profile = Profile::FromBrowserContext(browser_context);
- if (!profile)
- return url;
- #if !BUILDFLAG(IS_ANDROID)
- // If the input |url| should be assigned to the Instant renderer, make its
- // effective URL distinct from other URLs on the search provider's domain.
- // This needs to happen even if |url| corresponds to an isolated origin; see
- // https://crbug.com/755595.
- if (search::ShouldAssignURLToInstantRenderer(url, profile))
- return search::GetEffectiveURLForInstant(url, profile);
- #endif
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
- url);
- #else
- return url;
- #endif
- }
- bool ChromeContentBrowserClient::
- ShouldCompareEffectiveURLsForSiteInstanceSelection(
- content::BrowserContext* browser_context,
- content::SiteInstance* candidate_site_instance,
- bool is_main_frame,
- const GURL& candidate_url,
- const GURL& destination_url) {
- DCHECK(browser_context);
- DCHECK(candidate_site_instance);
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- return ChromeContentBrowserClientExtensionsPart::
- ShouldCompareEffectiveURLsForSiteInstanceSelection(
- browser_context, candidate_site_instance, is_main_frame,
- candidate_url, destination_url);
- #else
- return true;
- #endif
- }
- bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
- #if BUILDFLAG(IS_ANDROID)
- return true;
- #elif BUILDFLAG(IS_CHROMEOS_ASH)
- return ash::TabletMode::IsInTabletMode();
- #else
- return false;
- #endif // BUILDFLAG(IS_ANDROID)
- }
- bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
- content::BrowserContext* browser_context,
- const GURL& site_url) {
- Profile* profile = Profile::FromBrowserContext(browser_context);
- if (!profile)
- return false;
- // NTP should use process-per-site. This is a performance optimization to
- // reduce process count associated with NTP tabs.
- if (site_url == GURL(chrome::kChromeUINewTabURL) ||
- site_url == GURL(chrome::kChromeUINewTabPageURL)) {
- return true;
- }
- #if !BUILDFLAG(IS_ANDROID)
- if (search::ShouldUseProcessPerSiteForInstantSiteURL(site_url, profile))
- return true;
- #endif
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
- profile, site_url))
- return true;
- #endif
- // Non-extension, non-NTP URLs should generally use process-per-site-instance
- // (rather than process-per-site).
- return false;
- }
- bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
- content::BrowserContext* browser_context,
- const GURL& site_url) {
- Profile* profile = Profile::FromBrowserContext(browser_context);
- if (!profile)
- return false;
- // Top Chrome WebUI should share a RendererProcessHost. Return false here to
- // ensure the Spare Renderer is not assigned.
- if (IsTopChromeWebUIURL(site_url))
- return false;
- #if !BUILDFLAG(IS_ANDROID)
- // Instant renderers should not use a spare process, because they require
- // passing switches::kInstantProcess to the renderer process when it
- // launches. A spare process is launched earlier, before it is known which
- // navigation will use it, so it lacks this flag.
- if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
- return false;
- #endif
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- return ChromeContentBrowserClientExtensionsPart::
- ShouldUseSpareRenderProcessHost(profile, site_url);
- #else
- return true;
- #endif
- }
- bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
- content::BrowserContext* browser_context,
- const GURL& effective_site_url) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
- browser_context, effective_site_url)) {
- return true;
- }
- #endif
- return false;
- }
- bool ChromeContentBrowserClient::DoesWebUISchemeRequireProcessLock(
- base::StringPiece scheme) {
- // Note: This method can be called from multiple threads. It is not safe to
- // assume it runs only on the UI thread.
- // chrome-search: documents commit only in the NTP instant process and are not
- // locked to chrome-search: origin. Locking to chrome-search would kill
- // processes upon legitimate requests for cookies from the search engine's
- // domain.
- if (scheme == chrome::kChromeSearchScheme)
- return false;
- // All other WebUIs must be locked to origin.
- return true;
- }
- bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
- base::StringPiece scheme,
- bool is_embedded_origin_secure) {
- // This is needed to bypass the normal SameSite rules for any chrome:// page
- // embedding a secure origin, regardless of the registrable domains of any
- // intervening frames. For example, this is needed for browser UI to interact
- // with SameSite cookies on accounts.google.com, which are used for logging
- // into Cloud Print from chrome://print, for displaying a list of available
- // accounts on the NTP (chrome://new-tab-page), etc.
- if (is_embedded_origin_secure && scheme == content::kChromeUIScheme)
- return true;
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- return scheme == extensions::kExtensionScheme;
- #else
- return false;
- #endif
- }
- bool ChromeContentBrowserClient::
- ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel(
- base::StringPiece scheme,
- bool is_embedded_origin_secure) {
- return is_embedded_origin_secure && scheme == content::kChromeUIScheme;
- }
- // TODO(crbug.com/1087559): This is based on SubframeTask::GetTitle()
- // implementation. Find a general solution to avoid code duplication.
- std::string ChromeContentBrowserClient::GetSiteDisplayNameForCdmProcess(
- content::BrowserContext* browser_context,
- const GURL& site_url) {
- // By default, use the |site_url| spec as the display name.
- std::string name = site_url.spec();
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- // If |site_url| wraps a chrome extension ID, we can display the extension
- // name instead, which is more human-readable.
- if (site_url.SchemeIs(extensions::kExtensionScheme)) {
- const extensions::Extension* extension =
- extensions::ExtensionRegistry::Get(browser_context)
- ->enabled_extensions()
- .GetExtensionOrAppByURL(site_url);
- if (extension)
- name = extension->name();
- }
- #endif // BUILDFLAG(ENABLE_EXTENSIONS)
- return name;
- }
- void ChromeContentBrowserClient::OverrideURLLoaderFactoryParams(
- content::BrowserContext* browser_context,
- const url::Origin& origin,
- bool is_for_isolated_world,
- network::mojom::URLLoaderFactoryParams* factory_params) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- ChromeContentBrowserClientExtensionsPart::OverrideURLLoaderFactoryParams(
- browser_context, origin, is_for_isolated_world, factory_params);
- #endif
- }
- // These are treated as WebUI schemes but do not get WebUI bindings. Also,
- // view-source is allowed for these schemes.
- void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
- std::vector<std::string>* additional_schemes) {
- additional_schemes->emplace_back(chrome::kChromeSearchScheme);
- additional_schemes->emplace_back(dom_distiller::kDomDistillerScheme);
- additional_schemes->emplace_back(content::kChromeDevToolsScheme);
- }
- void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
- std::vector<std::string>* additional_schemes) {
- GetAdditionalWebUISchemes(additional_schemes);
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- additional_schemes->push_back(extensions::kExtensionScheme);
- #endif
- }
- network::mojom::IPAddressSpace
- ChromeContentBrowserClient::DetermineAddressSpaceFromURL(const GURL& url) {
- if (url.SchemeIs(chrome::kChromeSearchScheme))
- return network::mojom::IPAddressSpace::kLocal;
- if (url.SchemeIs(dom_distiller::kDomDistillerScheme))
- return network::mojom::IPAddressSpace::kPublic;
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- if (url.SchemeIs(extensions::kExtensionScheme))
- return network::mojom::IPAddressSpace::kLocal;
- #endif
- return network::mojom::IPAddressSpace::kUnknown;
- }
- bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
- return webui::LogWebUIUrl(web_ui_url);
- }
- bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
- const url::Origin& origin) {
- return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
- origin);
- }
- bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
- return ProfileIOData::IsHandledURL(url);
- }
- bool ChromeContentBrowserClient::HasCustomSchemeHandler(
- content::BrowserContext* browser_context,
- const std::string& scheme) {
- if (custom_handlers::ProtocolHandlerRegistry* protocol_handler_registry =
- ProtocolHandlerRegistryFactory::GetForBrowserContext(
- browser_context)) {
- return protocol_handler_registry->IsHandledProtocol(scheme);
- }
- return false;
- }
- bool ChromeContentBrowserClient::CanCommitURL(
- content::RenderProcessHost* process_host,
- const GURL& url) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host,
- url);
- #else
- return true;
- #endif
- }
- void ChromeContentBrowserClient::OverrideNavigationParams(
- SiteInstance* site_instance,
- ui::PageTransition* transition,
- bool* is_renderer_initiated,
- content::Referrer* referrer,
- absl::optional<url::Origin>* initiator_origin) {
- DCHECK(transition);
- DCHECK(is_renderer_initiated);
- DCHECK(referrer);
- // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
- // use for making security decisions 99.44% of the time, for detecting the NTP
- // it is reliable and the correct way. See http://crbug.com/624410.
- if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
- ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
- // Clicks on tiles of the new tab page should be treated as if a user
- // clicked on a bookmark. This is consistent with native implementations
- // like Android's. This also helps ensure that security features (like
- // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
- // browser-initiated.
- *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
- *is_renderer_initiated = false;
- *referrer = content::Referrer();
- *initiator_origin = absl::nullopt;
- }
- }
- bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
- const GURL& url,
- SiteInstance* parent_site_instance) {
- // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
- // use for making security decisions 99.44% of the time, for detecting the NTP
- // it is reliable and the correct way. See http://crbug.com/624410.
- return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
- search::IsNTPURL(parent_site_instance->GetSiteURL());
- }
- bool ChromeContentBrowserClient::IsSuitableHost(
- content::RenderProcessHost* process_host,
- const GURL& site_url) {
- Profile* profile =
- Profile::FromBrowserContext(process_host->GetBrowserContext());
- // This may be nullptr during tests. In that case, just assume any site can
- // share any host.
- if (!profile)
- return true;
- #if !BUILDFLAG(IS_ANDROID)
- // Instant URLs should only be in the instant process and instant process
- // should only have Instant URLs.
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(profile);
- if (instant_service) {
- bool is_instant_process =
- instant_service->IsInstantProcess(process_host->GetID());
- bool should_be_in_instant_process =
- search::ShouldAssignURLToInstantRenderer(site_url, profile);
- if (is_instant_process || should_be_in_instant_process)
- return is_instant_process && should_be_in_instant_process;
- }
- #endif
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
- profile, process_host, site_url);
- #else
- return true;
- #endif
- }
- bool ChromeContentBrowserClient::MayReuseHost(
- content::RenderProcessHost* process_host) {
- // If there is currently a no-state prefetcher in progress for the host
- // provided, it may not be shared. We require prefetchers to be by themselves
- // in a separate process so that we can monitor their resource usage.
- prerender::NoStatePrefetchManager* no_state_prefetch_manager =
- prerender::NoStatePrefetchManagerFactory::GetForBrowserContext(
- process_host->GetBrowserContext());
- if (no_state_prefetch_manager &&
- !no_state_prefetch_manager->MayReuseProcessHost(process_host)) {
- return false;
- }
- return true;
- }
- size_t ChromeContentBrowserClient::GetProcessCountToIgnoreForLimit() {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- return ChromeContentBrowserClientExtensionsPart::
- GetProcessCountToIgnoreForLimit();
- #else
- return 0;
- #endif
- }
- blink::ParsedPermissionsPolicy
- ChromeContentBrowserClient::GetPermissionsPolicyForIsolatedApp(
- content::BrowserContext* browser_context,
- const url::Origin& app_origin) {
- #if !BUILDFLAG(IS_ANDROID)
- Profile* profile = Profile::FromBrowserContext(browser_context);
- auto& registrar =
- web_app::WebAppProvider::GetForWebApps(profile)->registrar();
- std::vector<web_app::AppId> app_ids_for_origin =
- registrar.FindAppsInScope(app_origin.GetURL());
- if (app_ids_for_origin.empty()) {
- return blink::ParsedPermissionsPolicy();
- }
- return registrar.GetPermissionsPolicy(app_ids_for_origin[0]);
- #else
- NOTIMPLEMENTED();
- return blink::ParsedPermissionsPolicy();
- #endif
- }
- bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
- content::BrowserContext* browser_context,
- const GURL& url) {
- // Top Chrome WebUI should try to share a RenderProcessHost with other
- // existing Top Chrome WebUI.
- if (IsTopChromeWebUIURL(url))
- return true;
- return false;
- }
- bool ChromeContentBrowserClient::ShouldEmbeddedFramesTryToReuseExistingProcess(
- content::RenderFrameHost* outermost_main_frame) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- return ChromeContentBrowserClientExtensionsPart::
- ShouldEmbeddedFramesTryToReuseExistingProcess(outermost_main_frame);
- #else
- return true;
- #endif
- }
- void ChromeContentBrowserClient::SiteInstanceGotProcess(
- SiteInstance* site_instance) {
- CHECK(site_instance->HasProcess());
- Profile* profile =
- Profile::FromBrowserContext(site_instance->GetBrowserContext());
- if (!profile)
- return;
- #if !BUILDFLAG(IS_ANDROID)
- // Remember the ID of the Instant process to signal the renderer process
- // on startup in |AppendExtraCommandLineSwitches| below.
- if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
- profile)) {
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(profile);
- if (instant_service)
- instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
- }
- #endif
- for (size_t i = 0; i < extra_parts_.size(); ++i)
- extra_parts_[i]->SiteInstanceGotProcess(site_instance);
- }
- void ChromeContentBrowserClient::SiteInstanceDeleting(
- SiteInstance* site_instance) {
- if (!site_instance->HasProcess())
- return;
- for (size_t i = 0; i < extra_parts_.size(); ++i)
- extra_parts_[i]->SiteInstanceDeleting(site_instance);
- }
- bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
- SiteInstance* site_instance,
- const GURL& current_effective_url,
- const GURL& destination_effective_url) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- return ChromeContentBrowserClientExtensionsPart::
- ShouldSwapBrowsingInstancesForNavigation(
- site_instance, current_effective_url, destination_effective_url);
- #else
- return false;
- #endif
- }
- bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
- // TODO(nasko): Consider supporting error page isolation in subframes if
- // Site Isolation is enabled.
- return in_main_frame;
- }
- bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
- return !url.SchemeIs(chrome::kChromeNativeScheme);
- }
- std::vector<url::Origin>
- ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
- std::vector<url::Origin> isolated_origin_list;
- if (DoesGaiaOriginRequireDedicatedProcess()) {
- isolated_origin_list.push_back(GaiaUrls::GetInstance()->gaia_origin());
- }
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
- GetOriginsRequiringDedicatedProcess();
- std::move(std::begin(origins_from_extensions),
- std::end(origins_from_extensions),
- std::back_inserter(isolated_origin_list));
- #endif
- // Include additional origins preloaded with specific browser configurations,
- // if any. For example, this is used on Google Chrome for Android to preload
- // a list of important sites to isolate.
- auto built_in_origins =
- site_isolation::GetBrowserSpecificBuiltInIsolatedOrigins();
- std::move(std::begin(built_in_origins), std::end(built_in_origins),
- std::back_inserter(isolated_origin_list));
- return isolated_origin_list;
- }
- bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
- return base::FeatureList::IsEnabled(features::kSitePerProcess);
- }
- bool ChromeContentBrowserClient::ShouldDisableSiteIsolation(
- content::SiteIsolationMode site_isolation_mode) {
- return site_isolation::SiteIsolationPolicy::
- ShouldDisableSiteIsolationDueToMemoryThreshold(site_isolation_mode);
- }
- std::vector<std::string>
- ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
- std::vector<std::string> modes;
- if (site_isolation::SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
- modes.push_back("Password Sites");
- if (site_isolation::SiteIsolationPolicy::IsIsolationForOAuthSitesEnabled())
- modes.push_back("Logged-in Sites");
- return modes;
- }
- void ChromeContentBrowserClient::PersistIsolatedOrigin(
- content::BrowserContext* context,
- const url::Origin& origin,
- content::ChildProcessSecurityPolicy::IsolatedOriginSource source) {
- site_isolation::SiteIsolationPolicy::PersistIsolatedOrigin(context, origin,
- source);
- }
- bool ChromeContentBrowserClient::ShouldUrlUseApplicationIsolationLevel(
- content::BrowserContext* browser_context,
- const GURL& url) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- if (content::SiteIsolationPolicy::IsApplicationIsolationLevelEnabled()) {
- Profile* profile = Profile::FromBrowserContext(browser_context);
- return web_app::GetStorageIsolationKey(profile->GetPrefs(),
- url::Origin::Create(url));
- }
- #endif
- return false;
- }
- bool ChromeContentBrowserClient::IsIsolatedAppsDeveloperModeAllowed(
- content::BrowserContext* context) {
- Profile* profile = Profile::FromBrowserContext(context);
- return profile &&
- profile->GetPrefs()->GetBoolean(
- policy::policy_prefs::kIsolatedAppsDeveloperModeAllowed);
- }
- bool ChromeContentBrowserClient::IsGetDisplayMediaSetSelectAllScreensAllowed(
- content::BrowserContext* context,
- const url::Origin& origin) {
- return capture_policy::IsGetDisplayMediaSetSelectAllScreensAllowed(
- context, origin.GetURL());
- }
- bool ChromeContentBrowserClient::IsFileAccessAllowed(
- const base::FilePath& path,
- const base::FilePath& absolute_path,
- const base::FilePath& profile_path) {
- return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
- profile_path);
- }
- namespace {
- void MaybeAppendBlinkSettingsSwitchForFieldTrial(
- const base::CommandLine& browser_command_line,
- base::CommandLine* command_line) {
- // List of field trials that modify the blink-settings command line flag. No
- // two field trials in the list should specify the same keys, otherwise one
- // field trial may overwrite another. See Source/core/frame/Settings.in in
- // Blink for the list of valid keys.
- static const char* const kBlinkSettingsFieldTrials[] = {
- // Keys: disallowFetchForDocWrittenScriptsInMainFrame
- // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
- // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
- "DisallowFetchForDocWrittenScriptsInMainFrame",
- };
- std::vector<std::string> blink_settings;
- for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
- // Each blink-settings field trial should include a forcing_flag group,
- // to make sure that clients that specify the blink-settings flag on the
- // command line are excluded from the experiment groups. To make
- // sure we assign clients that specify this flag to the forcing_flag
- // group, we must call GetVariationParams for each field trial first
- // (for example, before checking HasSwitch() and returning), since
- // GetVariationParams has the side-effect of assigning the client to
- // a field trial group.
- std::map<std::string, std::string> params;
- if (variations::GetVariationParams(field_trial_name, ¶ms)) {
- for (const auto& param : params) {
- blink_settings.push_back(base::StringPrintf(
- "%s=%s", param.first.c_str(), param.second.c_str()));
- }
- }
- }
- if (blink_settings.empty()) {
- return;
- }
- if (browser_command_line.HasSwitch(blink::switches::kBlinkSettings) ||
- command_line->HasSwitch(blink::switches::kBlinkSettings)) {
- // The field trials should be configured to force users that specify the
- // blink-settings flag into a group with no params, and we return
- // above if no params were specified, so it's an error if we reach
- // this point.
- LOG(WARNING) << "Received field trial params, "
- "but blink-settings switch already specified.";
- return;
- }
- command_line->AppendSwitchASCII(blink::switches::kBlinkSettings,
- base::JoinString(blink_settings, ","));
- }
- } // namespace
- void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
- base::CommandLine* command_line,
- int child_process_id) {
- #if BUILDFLAG(IS_MAC)
- std::unique_ptr<metrics::ClientInfo> client_info =
- GoogleUpdateSettings::LoadMetricsClientInfo();
- if (client_info) {
- command_line->AppendSwitchASCII(switches::kMetricsClientID,
- client_info->client_id);
- }
- #elif BUILDFLAG(IS_POSIX)
- #if BUILDFLAG(IS_ANDROID)
- bool enable_crash_reporter = true;
- #else
- bool enable_crash_reporter = false;
- if (crash_reporter::IsCrashpadEnabled()) {
- command_line->AppendSwitch(switches::kEnableCrashpad);
- enable_crash_reporter = true;
- int fd;
- pid_t pid;
- if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
- command_line->AppendSwitchASCII(
- crash_reporter::switches::kCrashpadHandlerPid,
- base::NumberToString(pid));
- }
- } else {
- enable_crash_reporter = breakpad::IsCrashReporterEnabled();
- }
- #endif
- if (enable_crash_reporter) {
- std::string switch_value;
- std::unique_ptr<metrics::ClientInfo> client_info =
- GoogleUpdateSettings::LoadMetricsClientInfo();
- if (client_info)
- switch_value = client_info->client_id;
- switch_value.push_back(',');
- switch_value.append(
- chrome::GetChannelName(chrome::WithExtendedStable(true)));
- command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
- switch_value);
- }
- #endif
- if (logging::DialogsAreSuppressed())
- command_line->AppendSwitch(switches::kNoErrorDialogs);
- std::string process_type =
- command_line->GetSwitchValueASCII(switches::kProcessType);
- const base::CommandLine& browser_command_line =
- *base::CommandLine::ForCurrentProcess();
- static const char* const kCommonSwitchNames[] = {
- embedder_support::kUserAgent,
- switches::kUserDataDir, // Make logs go to the right file.
- };
- command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
- std::size(kCommonSwitchNames));
- static const char* const kDinosaurEasterEggSwitches[] = {
- error_page::switches::kDisableDinosaurEasterEgg,
- };
- command_line->CopySwitchesFrom(browser_command_line,
- kDinosaurEasterEggSwitches,
- std::size(kDinosaurEasterEggSwitches));
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- // On Chrome OS need to pass primary user homedir (in multi-profiles session).
- base::FilePath homedir;
- base::PathService::Get(base::DIR_HOME, &homedir);
- command_line->AppendSwitchASCII(ash::switches::kHomedir,
- homedir.value().c_str());
- #endif
- if (process_type == switches::kRendererProcess) {
- content::RenderProcessHost* process =
- content::RenderProcessHost::FromID(child_process_id);
- Profile* profile =
- process ? Profile::FromBrowserContext(process->GetBrowserContext())
- : nullptr;
- for (size_t i = 0; i < extra_parts_.size(); ++i) {
- extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line,
- process, profile);
- }
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- const std::string& login_profile =
- browser_command_line.GetSwitchValueASCII(ash::switches::kLoginProfile);
- if (!login_profile.empty())
- command_line->AppendSwitchASCII(ash::switches::kLoginProfile,
- login_profile);
- #endif
- MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line,
- chrome::GetChannel());
- if (process) {
- PrefService* prefs = profile->GetPrefs();
- // Currently this pref is only registered if applied via a policy.
- if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
- prefs->GetBoolean(prefs::kDisable3DAPIs)) {
- // Turn this policy into a command line switch.
- command_line->AppendSwitch(switches::kDisable3DAPIs);
- }
- if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
- command_line->AppendSwitch(switches::kDisablePrintPreview);
- // This passes the preference set by an enterprise policy on to a blink
- // switch so that we know whether to force WebSQL/WebSQL in non-secure
- // context to be enabled.
- if (prefs->GetBoolean(storage::kWebSQLAccess)) {
- command_line->AppendSwitch(blink::switches::kWebSQLAccess);
- }
- if (prefs->GetBoolean(storage::kWebSQLNonSecureContextEnabled)) {
- command_line->AppendSwitch(
- blink::switches::kWebSQLNonSecureContextEnabled);
- }
- // Enable persistent quota if enabled by enterprise policy.
- if (prefs->GetBoolean(storage::kPersistentQuotaEnabled)) {
- command_line->AppendSwitch(blink::switches::kPersistentQuotaEnabled);
- }
- // Enable legacy quota API if enabled by enterprise policy.
- if (prefs->GetBoolean(storage::kPrefixedStorageInfoEnabled)) {
- command_line->AppendSwitch(
- blink::switches::kPrefixedStorageInfoEnabled);
- }
- #if !BUILDFLAG(IS_ANDROID)
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(profile);
- if (instant_service &&
- instant_service->IsInstantProcess(process->GetID())) {
- command_line->AppendSwitch(switches::kInstantProcess);
- }
- // Enable SharedArrayBuffer on desktop if allowed by Enterprise Policy.
- // TODO(crbug.com/1144104) Remove when migration to COOP+COEP is complete.
- if (prefs->GetBoolean(
- prefs::kSharedArrayBufferUnrestrictedAccessAllowed)) {
- command_line->AppendSwitch(
- switches::kSharedArrayBufferUnrestrictedAccessAllowed);
- }
- #endif
- if (!prefs->GetBoolean(prefs::kSandboxExternalProtocolBlocked))
- command_line->AppendSwitch(kDisableSandboxExternalProtocolSwitch);
- if (prefs->GetBoolean(prefs::kDisplayCapturePermissionsPolicyEnabled)) {
- command_line->AppendSwitch(
- switches::kDisplayCapturePermissionsPolicyAllowed);
- }
- if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
- !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
- command_line->AppendSwitch(
- error_page::switches::kDisableDinosaurEasterEgg);
- }
- MaybeAppendSecureOriginsAllowlistSwitch(command_line);
- if (prefs->HasPrefPath(prefs::kScrollToTextFragmentEnabled) &&
- !prefs->GetBoolean(prefs::kScrollToTextFragmentEnabled)) {
- command_line->AppendSwitch(switches::kDisableScrollToTextFragment);
- }
- // Override SetTimeoutWithoutClamp feature if its Enterprise Policy
- // is specified.
- if (prefs->HasPrefPath(
- policy::policy_prefs::kSetTimeoutWithout1MsClampEnabled)) {
- command_line->AppendSwitchASCII(
- blink::switches::kSetTimeoutWithout1MsClampPolicy,
- prefs->GetBoolean(
- policy::policy_prefs::kSetTimeoutWithout1MsClampEnabled)
- ? blink::switches::kSetTimeoutWithout1MsClampPolicy_ForceEnable
- : blink::switches::
- kSetTimeoutWithout1MsClampPolicy_ForceDisable);
- }
- // Override MaxUnthrottledTimeoutNestingLevel feature if its Enterprise
- // Policy is specified.
- if (prefs->HasPrefPath(
- policy::policy_prefs::kUnthrottledNestedTimeoutEnabled)) {
- command_line->AppendSwitchASCII(
- blink::switches::kUnthrottledNestedTimeoutPolicy,
- prefs->GetBoolean(
- policy::policy_prefs::kUnthrottledNestedTimeoutEnabled)
- ? blink::switches::kUnthrottledNestedTimeoutPolicy_ForceEnable
- : blink::switches::
- kUnthrottledNestedTimeoutPolicy_ForceDisable);
- }
- // Override EventPath feature if its Enterprise Policy is specified.
- if (prefs->HasPrefPath(policy::policy_prefs::kEventPathEnabled)) {
- command_line->AppendSwitchASCII(
- blink::switches::kEventPathPolicy,
- prefs->GetBoolean(policy::policy_prefs::kEventPathEnabled)
- ? blink::switches::kEventPathPolicy_ForceEnable
- : blink::switches::kEventPathPolicy_ForceDisable);
- } else if (chrome::GetChannel() < version_info::Channel::BETA) {
- // When its Enterprise Policy is unspecified, disable Event.path by
- // default on Canary and Dev to help the deprecation and removal.
- // See crbug.com/1277431 for more details.
- command_line->AppendSwitchASCII(
- blink::switches::kEventPathPolicy,
- blink::switches::kEventPathPolicy_ForceDisable);
- }
- // The IntensiveWakeUpThrottling feature is typically managed via a
- // base::Feature, but it has a managed policy override. The override is
- // communicated to blink via a custom command-line flag. See
- // PageSchedulerImpl for the other half of related logic.
- PrefService* local_state = g_browser_process->local_state();
- const PrefService::Preference* pref = local_state->FindPreference(
- policy::policy_prefs::kIntensiveWakeUpThrottlingEnabled);
- if (pref && pref->IsManaged()) {
- command_line->AppendSwitchASCII(
- blink::switches::kIntensiveWakeUpThrottlingPolicy,
- pref->GetValue()->GetBool()
- ? blink::switches::kIntensiveWakeUpThrottlingPolicy_ForceEnable
- : blink::switches::
- kIntensiveWakeUpThrottlingPolicy_ForceDisable);
- }
- #if BUILDFLAG(IS_ANDROID)
- // Communicating to content/ for BackForwardCache.
- if (prefs->HasPrefPath(policy::policy_prefs::kBackForwardCacheEnabled) &&
- !prefs->GetBoolean(policy::policy_prefs::kBackForwardCacheEnabled)) {
- command_line->AppendSwitch(switches::kDisableBackForwardCache);
- }
- #endif // BUILDFLAG(IS_ANDROID)
- #if !BUILDFLAG(IS_ANDROID)
- // Make the WebAuthenticationRemoteProxiedRequestsAllowed policy enable
- // the experimental WebAuthenticationRemoteDesktopSupport Blink runtime
- // feature.
- if (prefs->GetBoolean(
- webauthn::pref_names::kRemoteProxiedRequestsAllowed)) {
- command_line->AppendSwitch(switches::kWebAuthRemoteDesktopSupport);
- }
- if (IsCartModuleEnabled()) {
- command_line->AppendSwitch(commerce::switches::kEnableChromeCart);
- }
- #endif
- }
- MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line,
- command_line);
- #if BUILDFLAG(IS_ANDROID)
- // If the platform is Android, force the distillability service on.
- command_line->AppendSwitch(switches::kEnableDistillabilityService);
- #endif
- // Please keep this in alphabetical order.
- static const char* const kSwitchNames[] = {
- autofill::switches::kIgnoreAutocompleteOffForAutofill,
- autofill::switches::kShowAutofillSignatures,
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- switches::kShortMergeSessionTimeoutForTest, // For tests only.
- #endif
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- extensions::switches::kAllowHTTPBackgroundPage,
- extensions::switches::kAllowLegacyExtensionManifests,
- extensions::switches::kDisableExtensionsHttpThrottling,
- extensions::switches::kEnableExperimentalExtensionApis,
- extensions::switches::kExtensionsOnChromeURLs,
- extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
- extensions::switches::kAllowlistedExtensionID,
- extensions::switches::kDEPRECATED_AllowlistedExtensionID,
- #endif
- switches::kAllowInsecureLocalhost,
- switches::kAppsGalleryURL,
- switches::kDisableJavaScriptHarmonyShipping,
- variations::switches::kEnableBenchmarking,
- switches::kEnableDistillabilityService,
- switches::kEnableNaCl,
- #if BUILDFLAG(ENABLE_NACL)
- switches::kEnableNaClDebug,
- #endif
- switches::kEnableNetBenchmarking,
- #if BUILDFLAG(IS_CHROMEOS)
- chromeos::switches::
- kTelemetryExtensionPwaOriginOverrideForTesting, // For tests only.
- switches::kForceAppMode,
- #endif
- #if BUILDFLAG(ENABLE_NACL)
- switches::kForcePNaClSubzero,
- #endif
- switches::kForceUIDirection,
- switches::kIgnoreGooglePortNumbers,
- switches::kJavaScriptHarmony,
- switches::kEnableExperimentalWebAssemblyFeatures,
- embedder_support::kOriginTrialDisabledFeatures,
- embedder_support::kOriginTrialDisabledTokens,
- embedder_support::kOriginTrialPublicKey,
- switches::kReaderModeHeuristics,
- translate::switches::kTranslateSecurityOrigin,
- };
- command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
- std::size(kSwitchNames));
- } else if (process_type == switches::kUtilityProcess) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- static const char* const kSwitchNames[] = {
- extensions::switches::kAllowHTTPBackgroundPage,
- extensions::switches::kEnableExperimentalExtensionApis,
- extensions::switches::kExtensionsOnChromeURLs,
- extensions::switches::kAllowlistedExtensionID,
- extensions::switches::kDEPRECATED_AllowlistedExtensionID,
- };
- command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
- std::size(kSwitchNames));
- #endif
- MaybeAppendSecureOriginsAllowlistSwitch(command_line);
- } else if (process_type == switches::kZygoteProcess) {
- // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
- #if BUILDFLAG(ENABLE_NACL)
- static const char* const kSwitchNames[] = {
- switches::kEnableNaClDebug,
- switches::kForcePNaClSubzero,
- switches::kVerboseLoggingInNacl,
- };
- command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
- std::size(kSwitchNames));
- #endif
- #if BUILDFLAG(IS_CHROMEOS_LACROS)
- // Ensure zygote loads the resource bundle for the right locale.
- static const char* const kMoreSwitchNames[] = {switches::kLang};
- command_line->CopySwitchesFrom(browser_command_line, kMoreSwitchNames,
- std::size(kMoreSwitchNames));
- #endif
- #if BUILDFLAG(IS_CHROMEOS)
- // This is called before feature flags are parsed, so pass them in their raw
- // form.
- static const char* const kMoreCrOSSwitchNames[] = {
- chromeos::switches::kFeatureFlags};
- command_line->CopySwitchesFrom(browser_command_line, kMoreCrOSSwitchNames,
- std::size(kMoreCrOSSwitchNames));
- #endif
- } else if (process_type == switches::kGpuProcess) {
- // If --ignore-gpu-blocklist is passed in, don't send in crash reports
- // because GPU is expected to be unreliable.
- if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlocklist) &&
- !command_line->HasSwitch(switches::kDisableBreakpad))
- command_line->AppendSwitch(switches::kDisableBreakpad);
- }
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) {
- static const char* const kSwitchNames[] = {
- crash_reporter::switches::kCrashLoopBefore,
- };
- command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
- std::size(kSwitchNames));
- }
- #endif
- ThreadProfilerConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
- command_line);
- #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_ASH)
- // Opt into a hardened stack canary mitigation if it hasn't already been
- // force-disabled.
- if (!browser_command_line.HasSwitch(switches::kChangeStackGuardOnFork)) {
- command_line->AppendSwitchASCII(switches::kChangeStackGuardOnFork,
- switches::kChangeStackGuardOnForkEnabled);
- }
- #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
- #if BUILDFLAG(IS_ANDROID)
- if (browser_command_line.HasSwitch(
- autofill_assistant::switches::kAutofillAssistantDebugAnnotateDom)) {
- command_line->AppendSwitch(
- autofill_assistant::switches::kAutofillAssistantDebugAnnotateDom);
- }
- #endif // BUILDFLAG(IS_ANDROID)
- }
- std::string
- ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() {
- return std::string(chrome::kApplicationClientIDStringForAVScanning);
- }
- download::QuarantineConnectionCallback
- ChromeContentBrowserClient::GetQuarantineConnectionCallback() {
- return base::BindRepeating(
- &ChromeDownloadManagerDelegate::ConnectToQuarantineService);
- }
- std::string ChromeContentBrowserClient::GetApplicationLocale() {
- if (BrowserThread::CurrentlyOn(BrowserThread::IO))
- return GetIOThreadApplicationLocale();
- return g_browser_process->GetApplicationLocale();
- }
- std::string ChromeContentBrowserClient::GetAcceptLangs(
- content::BrowserContext* context) {
- Profile* profile = Profile::FromBrowserContext(context);
- return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
- }
- gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
- return favicon::GetDefaultFavicon().AsImageSkia();
- }
- bool ChromeContentBrowserClient::IsDataSaverEnabled(
- content::BrowserContext* browser_context) {
- if (!browser_context || browser_context->IsOffTheRecord())
- return false;
- return data_saver::IsDataSaverEnabled(browser_context);
- }
- void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
- content::BrowserContext* browser_context,
- blink::RendererPreferences* out_prefs) {
- DCHECK(browser_context);
- DCHECK(out_prefs);
- renderer_preferences_util::UpdateFromSystemSettings(
- out_prefs, Profile::FromBrowserContext(browser_context));
- }
- content::AllowServiceWorkerResult
- ChromeContentBrowserClient::AllowServiceWorker(
- const GURL& scope,
- const net::SiteForCookies& site_for_cookies,
- const absl::optional<url::Origin>& top_frame_origin,
- const GURL& script_url,
- content::BrowserContext* context) {
- DCHECK(context);
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- // Check if this is an extension-related service worker, and, if so, if it's
- // allowed (this can return false if, e.g., the extension is disabled).
- // If it's not allowed, return immediately. We deliberately do *not* report
- // to the PageSpecificContentSettings, since the service worker is blocked
- // because of the extension, rather than because of the user's content
- // settings.
- if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorker(
- scope, first_party_url, script_url, context)) {
- return content::AllowServiceWorkerResult::No();
- }
- #endif
- Profile* profile = Profile::FromBrowserContext(context);
- return embedder_support::AllowServiceWorker(
- scope, site_for_cookies, top_frame_origin,
- CookieSettingsFactory::GetForProfile(profile).get(),
- HostContentSettingsMapFactory::GetForProfile(profile));
- }
- void ChromeContentBrowserClient::
- UpdateEnabledBlinkRuntimeFeaturesInIsolatedWorker(
- content::BrowserContext* context,
- const GURL& script_url,
- std::vector<std::string>& out_forced_enabled_runtime_features) {
- DCHECK(context);
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- auto* profile = Profile::FromBrowserContext(context);
- if (!ash::IsSystemExtensionsEnabled(profile))
- return;
- ash::SystemExtensionsProvider::Get(profile)
- .UpdateEnabledBlinkRuntimeFeaturesInIsolatedWorker(
- script_url, out_forced_enabled_runtime_features);
- #endif // BUILDFLAG(IS_CHROMEOS_ASH)
- }
- bool ChromeContentBrowserClient::AllowSharedWorker(
- const GURL& worker_url,
- const net::SiteForCookies& site_for_cookies,
- const absl::optional<url::Origin>& top_frame_origin,
- const std::string& name,
- const blink::StorageKey& storage_key,
- content::BrowserContext* context,
- int render_process_id,
- int render_frame_id) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- // Check if cookies are allowed.
- return embedder_support::AllowSharedWorker(
- worker_url, site_for_cookies, top_frame_origin, name, storage_key,
- render_process_id, render_frame_id,
- CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
- .get());
- }
- bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker(
- const std::string& scheme) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- // Extensions are allowed to start cross-origin shared workers.
- if (scheme == extensions::kExtensionScheme)
- return true;
- #endif
- return false;
- }
- bool ChromeContentBrowserClient::AllowSignedExchange(
- content::BrowserContext* browser_context) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- Profile* profile = Profile::FromBrowserContext(browser_context);
- return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
- }
- void ChromeContentBrowserClient::RequestFilesAccess(
- const std::vector<base::FilePath>& files,
- const GURL& destination_url,
- base::OnceCallback<void(file_access::ScopedFileAccess)>
- continuation_callback) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- #if BUILDFLAG(IS_CHROMEOS)
- auto* delegate = policy::DlpScopedFileAccessDelegate::Get();
- if (delegate) {
- delegate->RequestFilesAccess(files, destination_url,
- std::move(continuation_callback));
- } else {
- std::move(continuation_callback)
- .Run(file_access::ScopedFileAccess::Allowed());
- }
- #else
- std::move(continuation_callback)
- .Run(file_access::ScopedFileAccess::Allowed());
- #endif
- }
- void ChromeContentBrowserClient::AllowWorkerFileSystem(
- const GURL& url,
- content::BrowserContext* browser_context,
- const std::vector<content::GlobalRenderFrameHostId>& render_frames,
- base::OnceCallback<void(bool)> callback) {
- // An empty list is passed for render_frames here since we manually notify
- // PageSpecificContentSettings that the file system was accessed below.
- bool allow = embedder_support::AllowWorkerFileSystem(
- url, {},
- CookieSettingsFactory::GetForProfile(
- Profile::FromBrowserContext(browser_context))
- .get());
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow);
- #else
- FileSystemAccessed(url, render_frames, std::move(callback), allow);
- #endif
- }
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- void ChromeContentBrowserClient::GuestPermissionRequestHelper(
- const GURL& url,
- const std::vector<content::GlobalRenderFrameHostId>& render_frames,
- base::OnceCallback<void(bool)> callback,
- bool allow) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- std::map<int, int> process_map;
- bool has_web_view_guest = false;
- // Record access to file system for potential display in UI.
- for (const auto& it : render_frames) {
- if (process_map.find(it.child_id) != process_map.end())
- continue;
- process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
- if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
- has_web_view_guest = true;
- }
- if (!has_web_view_guest) {
- FileSystemAccessed(url, render_frames, std::move(callback), allow);
- return;
- }
- DCHECK_EQ(1U, process_map.size());
- std::map<int, int>::const_iterator it = process_map.begin();
- extensions::WebViewPermissionHelper* web_view_permission_helper =
- extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second);
- web_view_permission_helper->RequestFileSystemPermission(
- url, allow,
- base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed,
- weak_factory_.GetWeakPtr(), url, render_frames,
- std::move(callback)));
- }
- #endif
- void ChromeContentBrowserClient::FileSystemAccessed(
- const GURL& url,
- const std::vector<content::GlobalRenderFrameHostId>& render_frames,
- base::OnceCallback<void(bool)> callback,
- bool allow) {
- // Record access to file system for potential display in UI.
- for (const auto& it : render_frames) {
- content_settings::PageSpecificContentSettings::StorageAccessed(
- content_settings::mojom::ContentSettingsManager::StorageType::
- FILE_SYSTEM,
- it.child_id, it.frame_routing_id, url, !allow);
- }
- std::move(callback).Run(allow);
- }
- bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
- const GURL& url,
- content::BrowserContext* browser_context,
- const std::vector<content::GlobalRenderFrameHostId>& render_frames) {
- return embedder_support::AllowWorkerIndexedDB(
- url, render_frames,
- CookieSettingsFactory::GetForProfile(
- Profile::FromBrowserContext(browser_context))
- .get());
- }
- bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
- const GURL& url,
- content::BrowserContext* browser_context,
- const std::vector<content::GlobalRenderFrameHostId>& render_frames) {
- return embedder_support::AllowWorkerCacheStorage(
- url, render_frames,
- CookieSettingsFactory::GetForProfile(
- Profile::FromBrowserContext(browser_context))
- .get());
- }
- bool ChromeContentBrowserClient::AllowWorkerWebLocks(
- const GURL& url,
- content::BrowserContext* browser_context,
- const std::vector<content::GlobalRenderFrameHostId>& render_frames) {
- return embedder_support::AllowWorkerWebLocks(
- url, CookieSettingsFactory::GetForProfile(
- Profile::FromBrowserContext(browser_context))
- .get());
- }
- ChromeContentBrowserClient::AllowWebBluetoothResult
- ChromeContentBrowserClient::AllowWebBluetooth(
- content::BrowserContext* browser_context,
- const url::Origin& requesting_origin,
- const url::Origin& embedding_origin) {
- // TODO(crbug.com/598890): Don't disable if
- // base::CommandLine::ForCurrentProcess()->
- // HasSwitch(switches::kEnableWebBluetooth) is true.
- if (variations::GetVariationParamValue(
- permissions::PermissionContextBase::kPermissionsKillSwitchFieldStudy,
- "Bluetooth") ==
- permissions::PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
- // The kill switch is enabled for this permission. Block requests.
- return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
- }
- const HostContentSettingsMap* const content_settings =
- HostContentSettingsMapFactory::GetForProfile(
- Profile::FromBrowserContext(browser_context));
- if (content_settings->GetContentSetting(
- requesting_origin.GetURL(), embedding_origin.GetURL(),
- ContentSettingsType::BLUETOOTH_GUARD) == CONTENT_SETTING_BLOCK) {
- return AllowWebBluetoothResult::BLOCK_POLICY;
- }
- return AllowWebBluetoothResult::ALLOW;
- }
- std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
- return variations::GetVariationParamValue("WebBluetoothBlocklist",
- "blocklist_additions");
- }
- bool ChromeContentBrowserClient::IsInterestGroupAPIAllowed(
- content::RenderFrameHost* render_frame_host,
- InterestGroupApiOperation operation,
- const url::Origin& top_frame_origin,
- const url::Origin& api_origin) {
- Profile* profile =
- Profile::FromBrowserContext(render_frame_host->GetBrowserContext());
- auto* privacy_sandbox_settings =
- PrivacySandboxSettingsFactory::GetForProfile(profile);
- DCHECK(privacy_sandbox_settings);
- // Join operations are subject to an additional check.
- bool join_blocked =
- operation == InterestGroupApiOperation::kJoin
- ? !privacy_sandbox_settings->IsFledgeJoiningAllowed(top_frame_origin)
- : false;
- bool allowed =
- privacy_sandbox_settings->IsFledgeAllowed(top_frame_origin, api_origin) &&
- !join_blocked;
- if (operation == InterestGroupApiOperation::kJoin) {
- content_settings::PageSpecificContentSettings::InterestGroupJoined(
- render_frame_host, api_origin, !allowed);
- }
- return allowed;
- }
- bool ChromeContentBrowserClient::IsConversionMeasurementOperationAllowed(
- content::BrowserContext* browser_context,
- ConversionMeasurementOperation operation,
- const url::Origin* impression_origin,
- const url::Origin* conversion_origin,
- const url::Origin* reporting_origin) {
- Profile* profile = Profile::FromBrowserContext(browser_context);
- auto* privacy_sandbox_settings =
- PrivacySandboxSettingsFactory::GetForProfile(profile);
- if (!privacy_sandbox_settings)
- return false;
- switch (operation) {
- case ConversionMeasurementOperation::kImpression:
- DCHECK(impression_origin);
- DCHECK(reporting_origin);
- return privacy_sandbox_settings->IsConversionMeasurementAllowed(
- *impression_origin, *reporting_origin);
- case ConversionMeasurementOperation::kConversion:
- DCHECK(conversion_origin);
- DCHECK(reporting_origin);
- return privacy_sandbox_settings->IsConversionMeasurementAllowed(
- *conversion_origin, *reporting_origin);
- case ConversionMeasurementOperation::kReport:
- DCHECK(impression_origin);
- DCHECK(conversion_origin);
- DCHECK(reporting_origin);
- return privacy_sandbox_settings->ShouldSendConversionReport(
- *impression_origin, *conversion_origin, *reporting_origin);
- case ConversionMeasurementOperation::kAny:
- return privacy_sandbox_settings->IsPrivacySandboxEnabled();
- }
- }
- bool ChromeContentBrowserClient::IsSharedStorageAllowed(
- content::BrowserContext* browser_context,
- const url::Origin& top_frame_origin,
- const url::Origin& accessing_origin) {
- Profile* profile = Profile::FromBrowserContext(browser_context);
- auto* privacy_sandbox_settings =
- PrivacySandboxSettingsFactory::GetForProfile(profile);
- DCHECK(privacy_sandbox_settings);
- return privacy_sandbox_settings->IsSharedStorageAllowed(top_frame_origin,
- accessing_origin);
- }
- bool ChromeContentBrowserClient::IsPrivateAggregationAllowed(
- content::BrowserContext* browser_context,
- const url::Origin& top_frame_origin,
- const url::Origin& reporting_origin) {
- Profile* profile = Profile::FromBrowserContext(browser_context);
- auto* privacy_sandbox_settings =
- PrivacySandboxSettingsFactory::GetForProfile(profile);
- DCHECK(privacy_sandbox_settings);
- return privacy_sandbox_settings->IsPrivateAggregationAllowed(
- top_frame_origin, reporting_origin);
- }
- #if BUILDFLAG(IS_CHROMEOS)
- void ChromeContentBrowserClient::OnTrustAnchorUsed(
- content::BrowserContext* browser_context) {
- policy::PolicyCertService* service =
- policy::PolicyCertServiceFactory::GetForProfile(
- Profile::FromBrowserContext(browser_context));
- if (!service) {
- NOTREACHED();
- return;
- }
- service->SetUsedPolicyCertificates();
- }
- #endif
- bool ChromeContentBrowserClient::CanSendSCTAuditingReport(
- content::BrowserContext* browser_context) {
- return SCTReportingService::CanSendSCTAuditingReport();
- }
- void ChromeContentBrowserClient::OnNewSCTAuditingReportSent(
- content::BrowserContext* browser_context) {
- SCTReportingService::OnNewSCTAuditingReportSent();
- }
- scoped_refptr<network::SharedURLLoaderFactory>
- ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
- !BrowserThread::IsThreadInitialized(BrowserThread::UI));
- if (!SystemNetworkContextManager::GetInstance())
- return nullptr;
- return SystemNetworkContextManager::GetInstance()
- ->GetSharedURLLoaderFactory();
- }
- network::mojom::NetworkContext*
- ChromeContentBrowserClient::GetSystemNetworkContext() {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- DCHECK(g_browser_process->system_network_context_manager());
- return g_browser_process->system_network_context_manager()->GetContext();
- }
- std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
- return google_apis::GetAPIKey();
- }
- device::GeolocationManager*
- ChromeContentBrowserClient::GetGeolocationManager() {
- #if BUILDFLAG(IS_MAC)
- return g_browser_process->platform_part()->geolocation_manager();
- #else
- return nullptr;
- #endif
- }
- #if BUILDFLAG(IS_ANDROID)
- bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
- // Indicate that Chrome uses the GMS core location provider.
- return true;
- }
- #endif
- scoped_refptr<content::QuotaPermissionContext>
- ChromeContentBrowserClient::CreateQuotaPermissionContext() {
- return new permissions::QuotaPermissionContextImpl();
- }
- content::GeneratedCodeCacheSettings
- ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
- content::BrowserContext* context) {
- base::FilePath cache_path;
- chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
- // If we pass 0 for size, disk_cache will pick a default size using the
- // heuristics based on available disk size. These are implemented in
- // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
- int64_t size_in_bytes = 0;
- DCHECK(g_browser_process);
- PrefService* local_state = g_browser_process->local_state();
- if (local_state) {
- size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize);
- base::FilePath disk_cache_dir =
- local_state->GetFilePath(prefs::kDiskCacheDir);
- if (!disk_cache_dir.empty())
- cache_path = disk_cache_dir.Append(cache_path.BaseName());
- }
- return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
- }
- void ChromeContentBrowserClient::AllowCertificateError(
- content::WebContents* web_contents,
- int cert_error,
- const net::SSLInfo& ssl_info,
- const GURL& request_url,
- bool is_primary_main_frame_request,
- bool strict_enforcement,
- base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
- DCHECK(web_contents);
- if (!is_primary_main_frame_request) {
- // A sub-resource has a certificate error. The user doesn't really
- // have a context for making the right decision, so block the
- // request hard, without an info bar to allow showing the insecure
- // content.
- if (!callback.is_null())
- std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
- return;
- }
- // If the tab is being no-state prefetched, cancel the prefetcher and the
- // request.
- prerender::NoStatePrefetchContents* no_state_prefetch_contents =
- prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
- web_contents);
- if (no_state_prefetch_contents) {
- no_state_prefetch_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
- if (!callback.is_null()) {
- std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
- }
- return;
- }
- std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
- return;
- }
- #if !BUILDFLAG(IS_ANDROID)
- bool ChromeContentBrowserClient::ShouldDenyRequestOnCertificateError(
- const GURL main_page_url) {
- // Desktop Reader Mode pages should never load resources with certificate
- // errors. Desktop Reader Mode is more strict about security than Reader Mode
- // on Android: the desktop version has its own security indicator and
- // is not downgraded to a WARNING, whereas Android will show "Not secure"
- // in the omnibox (for low-end devices which show the omnibox on Reader Mode
- // pages).
- return main_page_url.SchemeIs(dom_distiller::kDomDistillerScheme);
- }
- #endif
- namespace {
- #if !BUILDFLAG(IS_ANDROID)
- blink::mojom::PreferredColorScheme ToBlinkPreferredColorScheme(
- ui::NativeTheme::PreferredColorScheme native_theme_scheme) {
- switch (native_theme_scheme) {
- case ui::NativeTheme::PreferredColorScheme::kDark:
- return blink::mojom::PreferredColorScheme::kDark;
- case ui::NativeTheme::PreferredColorScheme::kLight:
- return blink::mojom::PreferredColorScheme::kLight;
- }
- NOTREACHED();
- }
- #endif // !BUILDFLAG(IS_ANDROID)
- // Returns true if preferred color scheme is modified based on at least one of
- // the following -
- // |url| - Last committed url.
- // |web_contents| - For Android based on IsNightModeEnabled().
- // |native_theme| - For other platforms based on native theme scheme.
- bool UpdatePreferredColorScheme(WebPreferences* web_prefs,
- const GURL& url,
- WebContents* web_contents,
- const ui::NativeTheme* native_theme) {
- auto old_preferred_color_scheme = web_prefs->preferred_color_scheme;
- #if BUILDFLAG(IS_ANDROID)
- auto* delegate = TabAndroid::FromWebContents(web_contents)
- ? static_cast<android::TabWebContentsDelegateAndroid*>(
- web_contents->GetDelegate())
- : nullptr;
- if (delegate) {
- web_prefs->preferred_color_scheme =
- delegate->IsNightModeEnabled()
- ? blink::mojom::PreferredColorScheme::kDark
- : blink::mojom::PreferredColorScheme::kLight;
- }
- #else
- // Update based on native theme scheme.
- web_prefs->preferred_color_scheme =
- ToBlinkPreferredColorScheme(native_theme->GetPreferredColorScheme());
- #endif // BUILDFLAG(IS_ANDROID)
- bool force_light = false;
- // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
- // disabled; some of the UI is not yet correctly themed.
- if (!base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
- // Update based on last committed url.
- force_light = force_light || url.SchemeIs(content::kChromeUIScheme);
- force_light = force_light || IsPdfExtensionOrigin(url::Origin::Create(url));
- }
- // Reauth WebUI doesn't support dark mode yet because it shares the dialog
- // with GAIA web contents that is not correctly themed.
- force_light =
- force_light || (url.SchemeIs(content::kChromeUIScheme) &&
- url.host_piece() == chrome::kChromeUISigninReauthHost);
- if (force_light) {
- web_prefs->preferred_color_scheme =
- blink::mojom::PreferredColorScheme::kLight;
- }
- return old_preferred_color_scheme != web_prefs->preferred_color_scheme;
- }
- // Returns whether the user can be prompted to select a client certificate after
- // no certificate got auto-selected.
- bool CanPromptWithNonmatchingCertificates(const Profile* profile) {
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- if (ash::ProfileHelper::IsSigninProfile(profile) ||
- ash::ProfileHelper::IsLockScreenProfile(profile) ||
- ash::ProfileHelper::IsLockScreenAppProfile(profile)) {
- // On non-regular profiles (e.g. sign-in profile or lock-screen profile),
- // never show certificate selection to the user. A client certificate is an
- // identifier that can be stable for a long time, so only the administrator
- // is allowed to decide which endpoints should see it.
- // This also returns false for the lock screen app profile which can
- // not use client certificates anyway - to be on the safe side in case
- // support for client certificates is added later.
- return false;
- }
- #endif
- return true;
- }
- // Returns whether the user should be prompted to select a client certificate
- // when multiple certificates got auto-selected.
- bool ShouldPromptOnMultipleMatchingCertificates(const Profile* profile) {
- const PrefService* const prefs = profile->GetPrefs();
- DCHECK(prefs);
- const PrefService::Preference* pref =
- prefs->FindPreference(prefs::kPromptOnMultipleMatchingCertificates);
- if (pref && pref->IsManaged() && pref->GetValue()->is_bool())
- return pref->GetValue()->GetBool();
- return false;
- }
- } // namespace
- base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
- content::WebContents* web_contents,
- net::SSLCertRequestInfo* cert_request_info,
- net::ClientCertIdentityList client_certs,
- std::unique_ptr<content::ClientCertificateDelegate> delegate) {
- prerender::NoStatePrefetchContents* no_state_prefetch_contents =
- prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
- web_contents);
- if (no_state_prefetch_contents) {
- no_state_prefetch_contents->Destroy(
- prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
- return base::OnceClosure();
- }
- GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
- DCHECK(requesting_url.is_valid())
- << "Invalid URL string: https://"
- << cert_request_info->host_and_port.ToString();
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- // On the sign-in or lock screen profile, only allow client certs in the
- // context of the sign-in frame.
- // Note that this is explicitly not happening for the lock screen app profile
- // which does not support a gaia / SAML IdP sign-in frame.
- if (ash::ProfileHelper::IsSigninProfile(profile) ||
- ash::ProfileHelper::IsLockScreenProfile(profile)) {
- const char* profile_name = ash::ProfileHelper::IsSigninProfile(profile)
- ? "sign-in"
- : "lock screen";
- content::StoragePartition* storage_partition =
- profile->GetStoragePartition(web_contents->GetSiteInstance());
- auto* signin_partition_manager =
- ash::login::SigninPartitionManager::Factory::GetForBrowserContext(
- profile);
- if (!signin_partition_manager->IsCurrentSigninStoragePartition(
- storage_partition)) {
- LOG(WARNING) << "Client cert requested in " << profile_name
- << " profile in wrong context.";
- // Continue without client certificate. We do this to mimic the case of no
- // client certificate being present in the profile's certificate store.
- delegate->ContinueWithCertificate(nullptr, nullptr);
- return base::OnceClosure();
- }
- VLOG(1) << "Client cert requested in " << profile_name << " profile.";
- }
- #endif // BUILDFLAG(IS_CHROMEOS_ASH)
- net::ClientCertIdentityList matching_certificates, nonmatching_certificates;
- chrome::enterprise_util::AutoSelectCertificates(
- profile, requesting_url, std::move(client_certs), &matching_certificates,
- &nonmatching_certificates);
- if (matching_certificates.size() == 1 ||
- (matching_certificates.size() > 1 &&
- !ShouldPromptOnMultipleMatchingCertificates(profile))) {
- // Always take the first certificate, even if multiple ones matched -
- // there's no other criteria available for tie-breaking, and user prompts
- // aren't enabled.
- std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
- std::move(matching_certificates[0]);
- // The callback will own |auto_selected_identity| and |delegate|, keeping
- // them alive until after ContinueWithCertificate is called.
- scoped_refptr<net::X509Certificate> cert =
- auto_selected_identity->certificate();
- net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
- std::move(auto_selected_identity),
- base::BindOnce(
- &content::ClientCertificateDelegate::ContinueWithCertificate,
- std::move(delegate), std::move(cert)));
- LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
- return base::OnceClosure();
- }
- if (matching_certificates.empty() &&
- !CanPromptWithNonmatchingCertificates(profile)) {
- LOG(WARNING) << "No client cert matched by policy and user selection is "
- "not allowed.";
- LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
- // Continue without client certificate. We do this to mimic the case of no
- // client certificate being present in the profile's certificate store.
- delegate->ContinueWithCertificate(nullptr, nullptr);
- return base::OnceClosure();
- }
- // Note: It can happen that both lists are empty, still the selector needs to
- // be shown - see the comment in SSLClientAuthHandler::DidGetClientCerts()
- // about platforms not having a client cert store.
- net::ClientCertIdentityList client_cert_choices =
- !matching_certificates.empty() ? std::move(matching_certificates)
- : std::move(nonmatching_certificates);
- return chrome::ShowSSLClientCertificateSelector(
- web_contents, cert_request_info, std::move(client_cert_choices),
- std::move(delegate));
- }
- content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
- return MediaCaptureDevicesDispatcher::GetInstance();
- }
- content::FeatureObserverClient*
- ChromeContentBrowserClient::GetFeatureObserverClient() {
- return ChromeBrowserMainExtraPartsPerformanceManager::GetInstance()
- ->GetFeatureObserverClient();
- }
- bool ChromeContentBrowserClient::CanCreateWindow(
- RenderFrameHost* opener,
- const GURL& opener_url,
- const GURL& opener_top_level_frame_url,
- const url::Origin& source_origin,
- content::mojom::WindowContainerType container_type,
- const GURL& target_url,
- const content::Referrer& referrer,
- const std::string& frame_name,
- WindowOpenDisposition disposition,
- const blink::mojom::WindowFeatures& features,
- bool user_gesture,
- bool opener_suppressed,
- bool* no_javascript_access) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- DCHECK(opener);
- content::WebContents* web_contents =
- content::WebContents::FromRenderFrameHost(opener);
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
- DCHECK(profile);
- *no_javascript_access = false;
- // If the opener is trying to create a background window but doesn't have
- // the appropriate permission, fail the attempt.
- if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- auto* process_map = extensions::ProcessMap::Get(profile);
- auto* registry = extensions::ExtensionRegistry::Get(profile);
- if (!URLHasExtensionPermission(process_map, registry, opener_url,
- opener->GetProcess()->GetID(),
- APIPermissionID::kBackground)) {
- return false;
- }
- // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
- // return a recently installed Extension even if this CanCreateWindow call
- // was made by an old copy of the page in a normal web process. That's ok,
- // because the permission check above would have caused an early return
- // already. We must use the full URL to find hosted apps, though, and not
- // just the origin.
- const Extension* extension =
- registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
- if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
- *no_javascript_access = true;
- #endif
- return true;
- }
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- if (extensions::WebViewRendererState::GetInstance()->IsGuest(
- opener->GetProcess()->GetID())) {
- return true;
- }
- if (target_url.SchemeIs(extensions::kExtensionScheme)) {
- // Intentionally duplicating |registry| code from above because we want to
- // reduce calls to retrieve them as this function is a SYNC IPC handler.
- auto* registry = extensions::ExtensionRegistry::Get(profile);
- const Extension* extension =
- registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
- if (extension && extension->is_platform_app()) {
- UMA_HISTOGRAM_ENUMERATION(
- "Extensions.AppLoadedInTab",
- ClassifyAppLoadedInTabSource(opener_url, extension),
- APP_LOADED_IN_TAB_SOURCE_MAX);
- // window.open() may not be used to load v2 apps in a regular tab.
- return false;
- }
- }
- #endif
- DCHECK(!prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
- web_contents));
- BlockedWindowParams blocked_params(
- target_url, source_origin, opener->GetSiteInstance(), referrer,
- frame_name, disposition, features, user_gesture, opener_suppressed);
- NavigateParams nav_params =
- blocked_params.CreateNavigateParams(opener->GetProcess(), web_contents);
- return blocked_content::MaybeBlockPopup(
- web_contents, &opener_top_level_frame_url,
- std::make_unique<ChromePopupNavigationDelegate>(
- std::move(nav_params)),
- nullptr /*=open_url_params*/, blocked_params.features(),
- HostContentSettingsMapFactory::GetForProfile(profile)) != nullptr;
- }
- content::SpeechRecognitionManagerDelegate*
- ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
- return new speech::ChromeSpeechRecognitionManagerDelegate();
- }
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- content::TtsControllerDelegate*
- ChromeContentBrowserClient::GetTtsControllerDelegate() {
- return TtsControllerDelegateImpl::GetInstance();
- }
- #endif
- void ChromeContentBrowserClient::MaybeOverrideManifest(
- content::RenderFrameHost* render_frame_host,
- blink::mojom::ManifestPtr& manifest) {
- #if BUILDFLAG(IS_CHROMEOS)
- Profile* profile =
- Profile::FromBrowserContext(render_frame_host->GetBrowserContext());
- auto* provider = web_app::WebAppProvider::GetForWebApps(profile);
- if (provider)
- provider->policy_manager().MaybeOverrideManifest(render_frame_host,
- manifest);
- #endif
- }
- content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
- #if !BUILDFLAG(IS_ANDROID)
- content::TtsController::GetInstance()->SetTtsEngineDelegate(
- TtsExtensionEngine::GetInstance());
- #endif
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- return TtsPlatformImplChromeOs::GetInstance();
- #elif BUILDFLAG(IS_CHROMEOS_LACROS)
- return TtsPlatformImplLacros::GetInstance();
- #else
- return nullptr;
- #endif
- }
- void ChromeContentBrowserClient::OverrideWebkitPrefs(
- WebContents* web_contents,
- WebPreferences* web_prefs) {
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
- PrefService* prefs = profile->GetPrefs();
- // Fill font preferences. These are not registered on Android
- // - http://crbug.com/308033, http://crbug.com/696364.
- #if !BUILDFLAG(IS_ANDROID)
- FontFamilyCache::FillFontFamilyMap(profile,
- prefs::kWebKitStandardFontFamilyMap,
- &web_prefs->standard_font_family_map);
- FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
- &web_prefs->fixed_font_family_map);
- FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
- &web_prefs->serif_font_family_map);
- FontFamilyCache::FillFontFamilyMap(profile,
- prefs::kWebKitSansSerifFontFamilyMap,
- &web_prefs->sans_serif_font_family_map);
- FontFamilyCache::FillFontFamilyMap(profile,
- prefs::kWebKitCursiveFontFamilyMap,
- &web_prefs->cursive_font_family_map);
- FontFamilyCache::FillFontFamilyMap(profile,
- prefs::kWebKitFantasyFontFamilyMap,
- &web_prefs->fantasy_font_family_map);
- FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitMathFontFamilyMap,
- &web_prefs->math_font_family_map);
- web_prefs->default_font_size =
- prefs->GetInteger(prefs::kWebKitDefaultFontSize);
- web_prefs->default_fixed_font_size =
- prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
- web_prefs->minimum_font_size =
- prefs->GetInteger(prefs::kWebKitMinimumFontSize);
- web_prefs->minimum_logical_font_size =
- prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
- #endif
- web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
- web_prefs->dom_paste_enabled =
- prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
- web_prefs->javascript_can_access_clipboard =
- prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
- web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
- if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
- web_prefs->javascript_enabled = false;
- if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
- web_prefs->web_security_enabled = false;
- if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
- web_prefs->plugins_enabled = false;
- web_prefs->loads_images_automatically =
- prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
- if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
- web_prefs->webgl1_enabled = false;
- web_prefs->webgl2_enabled = false;
- }
- web_prefs->allow_running_insecure_content =
- prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
- #if BUILDFLAG(IS_ANDROID)
- web_prefs->font_scale_factor = static_cast<float>(
- prefs->GetDouble(browser_ui::prefs::kWebKitFontScaleFactor));
- web_prefs->force_enable_zoom =
- prefs->GetBoolean(browser_ui::prefs::kWebKitForceEnableZoom);
- #endif
- web_prefs->force_dark_mode_enabled =
- prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- web_prefs->always_show_focus =
- prefs->GetBoolean(ash::prefs::kAccessibilityFocusHighlightEnabled);
- #else
- if (features::IsAccessibilityFocusHighlightEnabled()) {
- web_prefs->always_show_focus =
- prefs->GetBoolean(prefs::kAccessibilityFocusHighlightEnabled);
- }
- #endif
- #if BUILDFLAG(IS_ANDROID)
- web_prefs->password_echo_enabled =
- prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
- #else
- web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
- #endif
- web_prefs->text_areas_are_resizable =
- prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
- web_prefs->hyperlink_auditing_enabled =
- prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- std::string image_animation_policy =
- prefs->GetString(prefs::kAnimationPolicy);
- if (image_animation_policy == kAnimationPolicyOnce) {
- web_prefs->animation_policy =
- blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAnimateOnce;
- } else if (image_animation_policy == kAnimationPolicyNone) {
- web_prefs->animation_policy =
- blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyNoAnimation;
- } else {
- web_prefs->animation_policy =
- blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
- }
- #endif
- // Make sure we will set the default_encoding with canonical encoding name.
- web_prefs->default_encoding =
- base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
- if (web_prefs->default_encoding.empty()) {
- prefs->ClearPref(prefs::kDefaultCharset);
- web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
- }
- DCHECK(!web_prefs->default_encoding.empty());
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
- web_prefs->disable_reading_from_canvas = true;
- web_prefs->strict_mixed_content_checking = true;
- web_prefs->strict_powerful_feature_restrictions = true;
- }
- // See crbug.com/1238157: the Native Client flag (chrome://flags/#enable-nacl)
- // can be manually re-enabled. In that case, we also need to return the full
- // plugins list, for compat.
- web_prefs->allow_non_empty_navigator_plugins |=
- base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaCl);
- web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
- if (web_contents) {
- #if BUILDFLAG(IS_ANDROID)
- auto* delegate = TabAndroid::FromWebContents(web_contents)
- ? static_cast<android::TabWebContentsDelegateAndroid*>(
- web_contents->GetDelegate())
- : nullptr;
- if (delegate) {
- web_prefs->embedded_media_experience_enabled =
- delegate->ShouldEnableEmbeddedMediaExperience();
- web_prefs->picture_in_picture_enabled =
- delegate->IsPictureInPictureEnabled();
- web_prefs->force_dark_mode_enabled =
- delegate->IsForceDarkWebContentEnabled();
- }
- #endif // BUILDFLAG(IS_ANDROID)
- // web_app_scope value is platform specific.
- #if BUILDFLAG(IS_ANDROID)
- if (delegate)
- web_prefs->web_app_scope = delegate->GetManifestScope();
- #elif BUILDFLAG(ENABLE_EXTENSIONS)
- {
- web_prefs->web_app_scope = GURL();
- // Set |web_app_scope| based on the app associated with the app window if
- // any. Note that the app associated with the window never changes, even
- // if the app navigates off scope. This is not a problem because we still
- // want to use the scope of the app associated with the window, not the
- // WebContents.
- Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
- if (browser && browser->app_controller()) {
- web_app::WebAppProvider* const web_app_provider =
- web_app::WebAppProvider::GetForLocalAppsUnchecked(profile);
- const web_app::AppId& app_id = browser->app_controller()->app_id();
- const web_app::WebAppRegistrar& registrar =
- web_app_provider->registrar();
- if (registrar.IsLocallyInstalled(app_id))
- web_prefs->web_app_scope = registrar.GetAppScope(app_id);
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- auto* system_app = browser->app_controller()->system_app();
- if (system_app) {
- web_prefs->allow_scripts_to_close_windows =
- system_app->ShouldAllowScriptsToCloseWindows();
- }
- #endif // BUILDFLAG(IS_CHROMEOS_ASH)
- }
- }
- #endif
- web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(web_contents);
- }
- web_prefs->lazy_load_enabled =
- !web_contents || !web_contents->GetDelegate() ||
- web_contents->GetDelegate()->ShouldAllowLazyLoad();
- if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
- const char* param_name =
- web_prefs->data_saver_enabled
- ? "lazy_frame_loading_distance_thresholds_px_by_ect"
- : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
- "saver_enabled";
- base::StringPairs pairs;
- base::SplitStringIntoKeyValuePairs(
- base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
- param_name),
- ':', ',', &pairs);
- for (const auto& pair : pairs) {
- absl::optional<net::EffectiveConnectionType> effective_connection_type =
- net::GetEffectiveConnectionTypeForName(pair.first);
- int value = 0;
- if (effective_connection_type && base::StringToInt(pair.second, &value)) {
- web_prefs->lazy_frame_loading_distance_thresholds_px[static_cast<
- EffectiveConnectionType>(effective_connection_type.value())] =
- value;
- }
- }
- }
- if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
- const char* param_name =
- web_prefs->data_saver_enabled
- ? "lazy_image_loading_distance_thresholds_px_by_ect"
- : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
- "saver_enabled";
- base::StringPairs pairs;
- base::SplitStringIntoKeyValuePairs(
- base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
- param_name),
- ':', ',', &pairs);
- for (const auto& pair : pairs) {
- absl::optional<net::EffectiveConnectionType> effective_connection_type =
- net::GetEffectiveConnectionTypeForName(pair.first);
- int value = 0;
- if (effective_connection_type && base::StringToInt(pair.second, &value)) {
- web_prefs->lazy_image_loading_distance_thresholds_px[static_cast<
- EffectiveConnectionType>(effective_connection_type.value())] =
- value;
- }
- }
- pairs.clear();
- base::SplitStringIntoKeyValuePairs(
- base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
- "lazy_image_first_k_fully_load"),
- ':', ',', &pairs);
- for (const auto& pair : pairs) {
- absl::optional<net::EffectiveConnectionType> effective_connection_type =
- net::GetEffectiveConnectionTypeForName(pair.first);
- int value = 0;
- if (effective_connection_type && base::StringToInt(pair.second, &value)) {
- web_prefs->lazy_image_first_k_fully_load[static_cast<
- EffectiveConnectionType>(effective_connection_type.value())] =
- value;
- }
- }
- }
- if (base::FeatureList::IsEnabled(
- features::kNetworkQualityEstimatorWebHoldback)) {
- std::string effective_connection_type_param =
- base::GetFieldTrialParamValueByFeature(
- features::kNetworkQualityEstimatorWebHoldback,
- "web_effective_connection_type_override");
- absl::optional<net::EffectiveConnectionType> effective_connection_type =
- net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
- DCHECK(effective_connection_type_param.empty() ||
- effective_connection_type);
- if (effective_connection_type) {
- DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
- effective_connection_type.value());
- web_prefs->network_quality_estimator_web_holdback =
- static_cast<EffectiveConnectionType>(
- effective_connection_type.value());
- }
- }
- web_prefs->autoplay_policy = GetAutoplayPolicyForWebContents(web_contents);
- switch (GetWebTheme()->GetPreferredContrast()) {
- case ui::NativeTheme::PreferredContrast::kNoPreference:
- web_prefs->preferred_contrast =
- blink::mojom::PreferredContrast::kNoPreference;
- break;
- case ui::NativeTheme::PreferredContrast::kMore:
- web_prefs->preferred_contrast = blink::mojom::PreferredContrast::kMore;
- break;
- case ui::NativeTheme::PreferredContrast::kLess:
- web_prefs->preferred_contrast = blink::mojom::PreferredContrast::kLess;
- break;
- case ui::NativeTheme::PreferredContrast::kCustom:
- web_prefs->preferred_contrast = blink::mojom::PreferredContrast::kCustom;
- break;
- }
- UpdatePreferredColorScheme(
- web_prefs,
- web_contents->GetPrimaryMainFrame()->GetSiteInstance()->GetSiteURL(),
- web_contents, GetWebTheme());
- web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
- absl::optional<ui::CaptionStyle> style =
- captions::GetCaptionStyleFromUserSettings(prefs,
- true /* record_metrics */);
- if (style) {
- web_prefs->text_track_background_color = style->background_color;
- web_prefs->text_track_text_color = style->text_color;
- web_prefs->text_track_text_size = style->text_size;
- web_prefs->text_track_text_shadow = style->text_shadow;
- web_prefs->text_track_font_family = style->font_family;
- web_prefs->text_track_font_variant = style->font_variant;
- web_prefs->text_track_window_color = style->window_color;
- web_prefs->text_track_window_radius = style->window_radius;
- }
- #if BUILDFLAG(IS_ANDROID)
- // If the pref is not set, the default value (true) will be used:
- web_prefs->webxr_immersive_ar_allowed =
- prefs->GetBoolean(prefs::kWebXRImmersiveArEnabled);
- // APIs for Web Authentication are not available prior to N.
- web_prefs->disable_webauthn =
- base::android::BuildInfo::GetInstance()->sdk_int() <
- base::android::SDK_VERSION_NOUGAT;
- #endif
- for (ChromeContentBrowserClientParts* parts : extra_parts_)
- parts->OverrideWebkitPrefs(web_contents, web_prefs);
- }
- bool ChromeContentBrowserClientParts::OverrideWebPreferencesAfterNavigation(
- WebContents* web_contents,
- WebPreferences* web_prefs) {
- return false;
- }
- bool ChromeContentBrowserClient::OverrideWebPreferencesAfterNavigation(
- WebContents* web_contents,
- WebPreferences* prefs) {
- const auto autoplay_policy = GetAutoplayPolicyForWebContents(web_contents);
- const bool new_autoplay_policy_needed =
- prefs->autoplay_policy != autoplay_policy;
- if (new_autoplay_policy_needed)
- prefs->autoplay_policy = autoplay_policy;
- bool extra_parts_need_update = false;
- for (ChromeContentBrowserClientParts* parts : extra_parts_) {
- extra_parts_need_update |=
- parts->OverrideWebPreferencesAfterNavigation(web_contents, prefs);
- }
- bool preferred_color_scheme_updated = UpdatePreferredColorScheme(
- prefs, web_contents->GetLastCommittedURL(), web_contents, GetWebTheme());
- #if BUILDFLAG(IS_ANDROID)
- bool force_dark_mode_changed = false;
- auto* delegate = TabAndroid::FromWebContents(web_contents)
- ? static_cast<android::TabWebContentsDelegateAndroid*>(
- web_contents->GetDelegate())
- : nullptr;
- if (delegate) {
- bool force_dark_mode_new_state = delegate->IsForceDarkWebContentEnabled();
- force_dark_mode_changed =
- prefs->force_dark_mode_enabled != force_dark_mode_new_state;
- prefs->force_dark_mode_enabled = force_dark_mode_new_state;
- }
- #endif
- return new_autoplay_policy_needed || extra_parts_need_update ||
- #if BUILDFLAG(IS_ANDROID)
- force_dark_mode_changed ||
- #endif
- preferred_color_scheme_updated;
- }
- void ChromeContentBrowserClient::BrowserURLHandlerCreated(
- BrowserURLHandler* handler) {
- // The group policy NTP URL handler must be registered before the other NTP
- // URL handlers below. Also register it before the "parts" handlers, so the
- // NTP policy takes precedence over extensions that override the NTP.
- handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
- BrowserURLHandler::null_handler());
- for (size_t i = 0; i < extra_parts_.size(); ++i)
- extra_parts_[i]->BrowserURLHandlerCreated(handler);
- // Handler to rewrite chrome://about and chrome://sync URLs.
- handler->AddHandlerPair(&HandleChromeAboutAndChromeSyncRewrite,
- BrowserURLHandler::null_handler());
- #if BUILDFLAG(IS_ANDROID)
- // Handler to rewrite chrome://newtab on Android.
- handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
- BrowserURLHandler::null_handler());
- #else // BUILDFLAG(IS_ANDROID)
- // Handler to rewrite chrome://newtab for InstantExtended.
- handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
- &search::HandleNewTabURLReverseRewrite);
- #endif // BUILDFLAG(IS_ANDROID)
- // chrome: & friends.
- handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
- &ChromeContentBrowserClient::HandleWebUIReverse);
- }
- base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
- return DownloadPrefs::GetDefaultDownloadDirectory();
- }
- std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
- return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
- }
- base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
- base::FilePath user_data_dir;
- base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
- DCHECK(!user_data_dir.empty());
- return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
- }
- base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
- base::FilePath user_data_dir;
- base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
- DCHECK(!user_data_dir.empty());
- return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
- }
- base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
- base::FilePath user_data_dir;
- base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
- DCHECK(!user_data_dir.empty());
- return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
- }
- base::FilePath ChromeContentBrowserClient::GetNetLogDefaultDirectory() {
- base::FilePath user_data_dir;
- base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
- DCHECK(!user_data_dir.empty());
- return user_data_dir;
- }
- base::FilePath ChromeContentBrowserClient::GetFirstPartySetsDirectory() {
- base::FilePath user_data_dir;
- base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
- DCHECK(!user_data_dir.empty());
- return user_data_dir;
- }
- void ChromeContentBrowserClient::DidCreatePpapiPlugin(
- content::BrowserPpapiHost* browser_host) {
- #if BUILDFLAG(ENABLE_PLUGINS)
- ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
- #endif
- }
- content::BrowserPpapiHost*
- ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) {
- #if BUILDFLAG(ENABLE_NACL)
- content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
- while (!iter.Done()) {
- nacl::NaClProcessHost* host =
- static_cast<nacl::NaClProcessHost*>(iter.GetDelegate());
- if (host->process() && host->process()->GetData().id == plugin_process_id) {
- // Found the plugin.
- return host->browser_ppapi_host();
- }
- ++iter;
- }
- #endif
- return nullptr;
- }
- bool ChromeContentBrowserClient::AllowPepperSocketAPI(
- content::BrowserContext* browser_context,
- const GURL& url,
- bool private_api,
- const content::SocketPermissionRequest* params) {
- #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
- return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
- browser_context, url, private_api, params);
- #else
- return false;
- #endif
- }
- bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
- content::BrowserContext* browser_context,
- const GURL& url) {
- #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
- return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
- browser_context, url);
- #else
- return false;
- #endif
- }
- std::unique_ptr<content::VpnServiceProxy>
- ChromeContentBrowserClient::GetVpnServiceProxy(
- content::BrowserContext* browser_context) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
- browser_context);
- #else
- return nullptr;
- #endif
- }
- std::unique_ptr<ui::SelectFilePolicy>
- ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
- return std::make_unique<ChromeSelectFilePolicy>(web_contents);
- }
- void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
- std::vector<std::string>* additional_allowed_schemes) {
- ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
- additional_allowed_schemes);
- additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
- additional_allowed_schemes->push_back(content::kChromeUIScheme);
- additional_allowed_schemes->push_back(content::kChromeUIUntrustedScheme);
- for (auto*& extra_part : extra_parts_) {
- extra_part->GetAdditionalAllowedSchemesForFileSystem(
- additional_allowed_schemes);
- }
- }
- void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckAllowlist(
- std::set<std::string>* schemes) {
- *schemes = secure_origin_allowlist::GetSchemesBypassingSecureContextCheck();
- }
- void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
- std::vector<storage::URLRequestAutoMountHandler>* handlers) {
- for (size_t i = 0; i < extra_parts_.size(); ++i)
- extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
- }
- void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
- content::BrowserContext* browser_context,
- const base::FilePath& storage_partition_path,
- std::vector<std::unique_ptr<storage::FileSystemBackend>>*
- additional_backends) {
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- storage::ExternalMountPoints* external_mount_points =
- browser_context->GetMountPoints();
- DCHECK(external_mount_points);
- auto backend = std::make_unique<chromeos::FileSystemBackend>(
- Profile::FromBrowserContext(browser_context),
- std::make_unique<ash::file_system_provider::BackendDelegate>(),
- std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
- storage_partition_path),
- std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
- std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
- std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
- Profile::FromBrowserContext(browser_context)),
- std::make_unique<ash::smb_client::SmbFsFileSystemBackendDelegate>(
- Profile::FromBrowserContext(browser_context)),
- external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
- backend->AddSystemMountPoints();
- DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
- additional_backends->push_back(std::move(backend));
- #endif
- for (size_t i = 0; i < extra_parts_.size(); ++i) {
- extra_parts_[i]->GetAdditionalFileSystemBackends(
- browser_context, storage_partition_path,
- GetQuarantineConnectionCallback(), additional_backends);
- }
- }
- #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
- void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
- const base::CommandLine& command_line,
- int child_process_id,
- PosixFileDescriptorInfo* mappings) {
- #if BUILDFLAG(IS_ANDROID)
- base::MemoryMappedFile::Region region;
- int fd = ui::GetMainAndroidPackFd(®ion);
- mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
- // For Android: Native resources for DFMs should only be used by the browser
- // process. Their file descriptors and memory mapped file regions are not
- // passed to child processes.
- fd = ui::GetCommonResourcesPackFd(®ion);
- mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
- fd = ui::GetLocalePackFd(®ion);
- mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
- // Optional secondary locale .pak file.
- fd = ui::GetSecondaryLocalePackFd(®ion);
- if (fd != -1) {
- mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
- }
- base::FilePath app_data_path;
- base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
- DCHECK(!app_data_path.empty());
- #endif // BUILDFLAG(IS_ANDROID)
- int crash_signal_fd = GetCrashSignalFD(command_line);
- if (crash_signal_fd >= 0) {
- mappings->Share(kCrashDumpSignal, crash_signal_fd);
- }
- }
- #endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
- #if BUILDFLAG(IS_WIN)
- std::wstring ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
- sandbox::mojom::Sandbox sandbox_type,
- AppContainerFlags flags) {
- // TODO(wfh): Add support for more process types here. crbug.com/499523
- switch (sandbox_type) {
- case sandbox::mojom::Sandbox::kRenderer:
- if (flags & AppContainerFlags::kAppContainerFlagDisableAppContainer)
- return std::wstring();
- return std::wstring(install_static::GetSandboxSidPrefix()) + L"129201922";
- case sandbox::mojom::Sandbox::kUtility:
- return std::wstring();
- case sandbox::mojom::Sandbox::kGpu:
- return std::wstring();
- #if BUILDFLAG(ENABLE_PLUGINS)
- case sandbox::mojom::Sandbox::kPpapi:
- #endif
- case sandbox::mojom::Sandbox::kNoSandbox:
- case sandbox::mojom::Sandbox::kNoSandboxAndElevatedPrivileges:
- case sandbox::mojom::Sandbox::kXrCompositing:
- case sandbox::mojom::Sandbox::kNetwork:
- case sandbox::mojom::Sandbox::kCdm:
- #if BUILDFLAG(ENABLE_PRINTING)
- case sandbox::mojom::Sandbox::kPrintBackend:
- #endif
- case sandbox::mojom::Sandbox::kPrintCompositor:
- case sandbox::mojom::Sandbox::kAudio:
- case sandbox::mojom::Sandbox::kSpeechRecognition:
- case sandbox::mojom::Sandbox::kPdfConversion:
- case sandbox::mojom::Sandbox::kService:
- case sandbox::mojom::Sandbox::kServiceWithJit:
- case sandbox::mojom::Sandbox::kIconReader:
- case sandbox::mojom::Sandbox::kMediaFoundationCdm:
- case sandbox::mojom::Sandbox::kWindowsSystemProxyResolver:
- // Should never reach here.
- CHECK(0);
- return std::wstring();
- }
- }
- bool ChromeContentBrowserClient::IsRendererAppContainerDisabled() {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- PrefService* local_state = g_browser_process->local_state();
- const PrefService::Preference* pref =
- local_state->FindPreference(prefs::kRendererAppContainerEnabled);
- // App Container is disabled if managed pref is set to false.
- if (pref && pref->IsManaged() && !pref->GetValue()->GetBool())
- return true;
- return false;
- }
- std::wstring
- ChromeContentBrowserClient::GetLPACCapabilityNameForNetworkService() {
- // Use a different LPAC capability name for each Chrome channel so network
- // service data between hannels is isolated.
- version_info::Channel channel = chrome::GetChannel();
- switch (channel) {
- case version_info::Channel::CANARY:
- return std::wstring(L"lpacChromeCanaryNetworkSandbox");
- case version_info::Channel::BETA:
- return std::wstring(L"lpacChromeBetaNetworkSandbox");
- case version_info::Channel::DEV:
- return std::wstring(L"lpacChromeDevNetworkSandbox");
- case version_info::Channel::STABLE:
- return std::wstring(L"lpacChromeStableNetworkSandbox");
- case version_info::Channel::UNKNOWN:
- return std::wstring(L"lpacChromeNetworkSandbox");
- }
- }
- // Note: Only use sparingly to add Chrome specific sandbox functionality here.
- // Other code should reside in the content layer. Changes to this function
- // should be reviewed by the security team.
- bool ChromeContentBrowserClient::PreSpawnChild(
- sandbox::TargetPolicy* policy,
- sandbox::mojom::Sandbox sandbox_type,
- ChildSpawnFlags flags) {
- // Does not work under component build because all the component DLLs would need
- // to be manually added and maintained. Does not work under ASAN build because
- // ASAN has not yet fully initialized its instrumentation by the time the CIG
- // intercepts run.
- #if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
- bool enforce_code_integrity = false;
- switch (sandbox_type) {
- case sandbox::mojom::Sandbox::kRenderer:
- enforce_code_integrity =
- ((flags & ChildSpawnFlags::kChildSpawnFlagRendererCodeIntegrity) &&
- base::FeatureList::IsEnabled(kRendererCodeIntegrity));
- break;
- case sandbox::mojom::Sandbox::kNetwork:
- enforce_code_integrity =
- base::FeatureList::IsEnabled(kNetworkServiceCodeIntegrity);
- break;
- case sandbox::mojom::Sandbox::kServiceWithJit:
- enforce_code_integrity = true;
- break;
- case sandbox::mojom::Sandbox::kUtility:
- case sandbox::mojom::Sandbox::kGpu:
- #if BUILDFLAG(ENABLE_PLUGINS)
- case sandbox::mojom::Sandbox::kPpapi:
- #endif
- case sandbox::mojom::Sandbox::kNoSandbox:
- case sandbox::mojom::Sandbox::kNoSandboxAndElevatedPrivileges:
- case sandbox::mojom::Sandbox::kXrCompositing:
- case sandbox::mojom::Sandbox::kCdm:
- #if BUILDFLAG(ENABLE_PRINTING)
- case sandbox::mojom::Sandbox::kPrintBackend:
- #endif
- case sandbox::mojom::Sandbox::kPrintCompositor:
- case sandbox::mojom::Sandbox::kAudio:
- case sandbox::mojom::Sandbox::kSpeechRecognition:
- case sandbox::mojom::Sandbox::kPdfConversion:
- case sandbox::mojom::Sandbox::kService:
- case sandbox::mojom::Sandbox::kIconReader:
- case sandbox::mojom::Sandbox::kMediaFoundationCdm:
- case sandbox::mojom::Sandbox::kWindowsSystemProxyResolver:
- break;
- }
- #if !defined(OFFICIAL_BUILD)
- // Disable renderer code integrity when Application Verifier or pageheap are
- // enabled for chrome.exe to avoid renderer crashes. https://crbug.com/1004989
- if (base::win::IsAppVerifierEnabled(chrome::kBrowserProcessExecutableName))
- enforce_code_integrity = false;
- #endif // !defined(OFFICIAL_BUILD)
- if (!enforce_code_integrity)
- return true;
- // Only enable signing mitigation if launching from chrome.exe.
- base::FilePath exe_path;
- if (!base::PathService::Get(base::FILE_EXE, &exe_path))
- return true;
- if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value())
- return true;
- sandbox::MitigationFlags mitigations = policy->GetProcessMitigations();
- mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS;
- sandbox::ResultCode result = policy->SetProcessMitigations(mitigations);
- if (result != sandbox::SBOX_ALL_OK)
- return false;
- if (policy->GetConfig()->IsConfigured())
- return true;
- // Allow loading Chrome's DLLs.
- for (const auto* dll : {chrome::kBrowserResourcesDll, chrome::kElfDll}) {
- result = policy->GetConfig()->AddRule(sandbox::SubSystem::kSignedBinary,
- sandbox::Semantics::kSignedAllowLoad,
- GetModulePath(dll).value().c_str());
- if (result != sandbox::SBOX_ALL_OK)
- return false;
- }
- #endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
- return true;
- }
- bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() {
- PrefService* local_state = g_browser_process->local_state();
- if (local_state &&
- local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) &&
- !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled))
- return false;
- return true;
- }
- // Note: Only use sparingly to add Chrome specific sandbox functionality here.
- // Other code should reside in the content layer. Changes to this function
- // should be reviewed by the security team.
- bool ChromeContentBrowserClient::IsUtilityCetCompatible(
- const std::string& utility_sub_type) {
- if (utility_sub_type == chrome::mojom::UtilWin::Name_)
- return false;
- return true;
- }
- void ChromeContentBrowserClient::SessionEnding() {
- chrome::SessionEnding();
- }
- bool ChromeContentBrowserClient::ShouldEnableAudioProcessHighPriority() {
- return IsAudioProcessHighPriorityEnabled();
- }
- #endif // BUILDFLAG(IS_WIN)
- void ChromeContentBrowserClient::
- RegisterMojoBinderPoliciesForSameOriginPrerendering(
- content::MojoBinderPolicyMap& policy_map) {
- // Changes to `policy_map` should be made in
- // RegisterChromeMojoBinderPoliciesForSameOriginPrerendering() which requires
- // security review.
- RegisterChromeMojoBinderPoliciesForSameOriginPrerendering(policy_map);
- }
- void ChromeContentBrowserClient::OpenURL(
- content::SiteInstance* site_instance,
- const content::OpenURLParams& params,
- base::OnceCallback<void(content::WebContents*)> callback) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- content::BrowserContext* browser_context = site_instance->GetBrowserContext();
- #if BUILDFLAG(IS_ANDROID)
- ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
- std::move(callback));
- #else
- NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
- params.url, params.transition);
- nav_params.FillNavigateParamsFromOpenURLParams(params);
- Navigate(&nav_params);
- std::move(callback).Run(nav_params.navigated_or_inserted_contents);
- #endif
- }
- content::ControllerPresentationServiceDelegate*
- ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
- content::WebContents* web_contents) {
- if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
- return media_router::PresentationServiceDelegateImpl::
- GetOrCreateForWebContents(web_contents);
- }
- return nullptr;
- }
- content::ReceiverPresentationServiceDelegate*
- ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
- content::WebContents* web_contents) {
- if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
- // ReceiverPresentationServiceDelegateImpl exists only for WebContents
- // created for offscreen presentations. The WebContents must belong to
- // an incognito profile.
- if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
- FromWebContents(web_contents)) {
- DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
- return impl;
- }
- }
- return nullptr;
- }
- void ChromeContentBrowserClient::AddPresentationObserver(
- content::PresentationObserver* observer,
- content::WebContents* web_contents) {
- if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
- media_router::WebContentsPresentationManager::Get(web_contents)
- ->AddObserver(observer);
- }
- }
- void ChromeContentBrowserClient::RemovePresentationObserver(
- content::PresentationObserver* observer,
- content::WebContents* web_contents) {
- if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
- media_router::WebContentsPresentationManager::Get(web_contents)
- ->RemoveObserver(observer);
- }
- }
- std::vector<std::unique_ptr<content::NavigationThrottle>>
- ChromeContentBrowserClient::CreateThrottlesForNavigation(
- content::NavigationHandle* handle) {
- std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
- // MetricsNavigationThrottle requires that it runs before NavigationThrottles
- // that may delay or cancel navigations, so only NavigationThrottles that
- // don't delay or cancel navigations (e.g. throttles that are only observing
- // callbacks without affecting navigation behavior) should be added before
- // MetricsNavigationThrottle.
- if (handle->IsInMainFrame()) {
- throttles.push_back(
- page_load_metrics::MetricsNavigationThrottle::Create(handle));
- }
- #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
- MaybeAddThrottle(
- SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle),
- &throttles);
- #endif
- #if BUILDFLAG(IS_ANDROID)
- // TODO(davidben): This is insufficient to integrate with prerender properly.
- // https://crbug.com/370595
- prerender::NoStatePrefetchContents* no_state_prefetch_contents =
- prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
- handle->GetWebContents());
- if (!no_state_prefetch_contents) {
- MaybeAddThrottle(
- navigation_interception::InterceptNavigationDelegate::
- MaybeCreateThrottleFor(
- handle, navigation_interception::SynchronyMode::kAsync),
- &throttles);
- }
- throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
- #if BUILDFLAG(DFMIFY_DEV_UI)
- // If the DevUI DFM is already installed, then this is a no-op, except for the
- // side effect of ensuring that the DevUI DFM is loaded.
- MaybeAddThrottle(dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle),
- &throttles);
- #endif // BUILDFLAG(DFMIFY_DEV_UI)
- #elif BUILDFLAG(ENABLE_EXTENSIONS)
- // Redirect some navigations to apps that have registered matching URL
- // handlers ('url_handlers' in the manifest).
- MaybeAddThrottle(
- PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle),
- &throttles);
- #endif
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- // Check if we need to add merge session throttle. This throttle will postpone
- // loading of main frames.
- if (handle->IsInMainFrame()) {
- // Add interstitial page while merge session process (cookie reconstruction
- // from OAuth2 refresh token in ChromeOS login) is still in progress while
- // we are attempting to load a google property.
- if (ash::merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
- !ash::merge_session_throttling_utils::AreAllSessionMergedAlready() &&
- handle->GetURL().SchemeIsHTTPOrHTTPS()) {
- throttles.push_back(ash::MergeSessionNavigationThrottle::Create(handle));
- }
- }
- #endif
- #if !BUILDFLAG(IS_ANDROID)
- auto url_to_apps_throttle =
- #if BUILDFLAG(IS_CHROMEOS)
- apps::CommonAppsNavigationThrottle::MaybeCreate(handle);
- #else
- apps::AppsNavigationThrottle::MaybeCreate(handle);
- #endif
- if (url_to_apps_throttle)
- throttles.push_back(std::move(url_to_apps_throttle));
- #endif
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- throttles.push_back(
- std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
- MaybeAddThrottle(extensions::ExtensionsBrowserClient::Get()
- ->GetUserScriptListener()
- ->CreateNavigationThrottle(handle),
- &throttles);
- #endif
- #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
- MaybeAddThrottle(
- SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle),
- &throttles);
- #endif
- if (auto* throttle_manager =
- subresource_filter::ContentSubresourceFilterThrottleManager::
- FromNavigationHandle(*handle)) {
- throttle_manager->MaybeAppendNavigationThrottles(handle, &throttles);
- }
- MaybeAddThrottle(
- LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle),
- &throttles);
- MaybeAddThrottle(PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle),
- &throttles);
- #if BUILDFLAG(ENABLE_PDF)
- MaybeAddThrottle(pdf::PdfNavigationThrottle::MaybeCreateThrottleFor(
- handle, std::make_unique<ChromePdfStreamDelegate>()),
- &throttles);
- #endif // BUILDFLAG(ENABLE_PDF)
- MaybeAddThrottle(TabUnderNavigationThrottle::MaybeCreate(handle), &throttles);
- MaybeAddThrottle(
- WellKnownChangePasswordNavigationThrottle::MaybeCreateThrottleFor(handle),
- &throttles);
- MaybeAddThrottle(
- PasswordManagerNavigationThrottle::MaybeCreateThrottleFor(handle),
- &throttles);
- throttles.push_back(std::make_unique<PolicyBlocklistNavigationThrottle>(
- handle, handle->GetWebContents()->GetBrowserContext()));
- // Before setting up SSL error detection, configure SSLErrorHandler to invoke
- // the relevant extension API whenever an SSL interstitial is shown.
- SSLErrorHandler::SetClientCallbackOnInterstitialsShown(
- base::BindRepeating(&MaybeTriggerSecurityInterstitialShownEvent));
- content::WebContents* web_contents = handle->GetWebContents();
- throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
- handle,
- std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
- base::BindOnce(&HandleSSLErrorWrapper), base::BindOnce(&IsInHostedApp),
- base::BindOnce(
- &ShouldIgnoreSslInterstitialBecauseNavigationDefaultedToHttps)));
- throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle));
- if (base::FeatureList::IsEnabled(omnibox::kDefaultTypedNavigationsToHttps)) {
- MaybeAddThrottle(
- TypedNavigationUpgradeThrottle::MaybeCreateThrottleFor(handle),
- &throttles);
- }
- #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
- MaybeAddThrottle(
- WebAppSettingsNavigationThrottle::MaybeCreateThrottleFor(handle),
- &throttles);
- #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
- #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || \
- BUILDFLAG(IS_CHROMEOS_ASH)
- MaybeAddThrottle(enterprise_connectors::DeviceTrustNavigationThrottle::
- MaybeCreateThrottleFor(handle),
- &throttles);
- #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) ||
- // BUILDFLAG(IS_CHROMEOS_ASH)
- #if !BUILDFLAG(IS_ANDROID)
- MaybeAddThrottle(DevToolsWindow::MaybeCreateNavigationThrottle(handle),
- &throttles);
- MaybeAddThrottle(NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle),
- &throttles);
- #endif
- // g_browser_process->safe_browsing_service() may be null in unittests.
- safe_browsing::SafeBrowsingUIManager* ui_manager =
- g_browser_process->safe_browsing_service()
- ? g_browser_process->safe_browsing_service()->ui_manager().get()
- : nullptr;
- MaybeAddThrottle(
- safe_browsing::SafeBrowsingNavigationThrottle::MaybeCreateThrottleFor(
- handle, ui_manager),
- &throttles);
- if (base::FeatureList::IsEnabled(safe_browsing::kDelayedWarnings)) {
- throttles.push_back(
- std::make_unique<safe_browsing::DelayedWarningNavigationThrottle>(
- handle));
- }
- // TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
- // of lacros-chrome is complete.
- #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || \
- (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
- MaybeAddThrottle(browser_switcher::BrowserSwitcherNavigationThrottle::
- MaybeCreateThrottleFor(handle),
- &throttles);
- #endif
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- MaybeAddThrottle(
- chromeos::KioskSettingsNavigationThrottle::MaybeCreateThrottleFor(handle),
- &throttles);
- #endif
- #if BUILDFLAG(IS_MAC)
- if (__builtin_available(macOS 10.15, *)) {
- MaybeAddThrottle(MaybeCreateAuthSessionThrottleFor(handle), &throttles);
- }
- #endif
- auto* performance_manager_registry =
- performance_manager::PerformanceManagerRegistry::GetInstance();
- if (performance_manager_registry) {
- MaybeAddThrottles(
- performance_manager_registry->CreateThrottlesForNavigation(handle),
- &throttles);
- }
- Profile* profile = Profile::FromBrowserContext(
- handle->GetWebContents()->GetBrowserContext());
- if (profile && profile->GetPrefs()) {
- MaybeAddThrottle(
- security_interstitials::InsecureFormNavigationThrottle::
- MaybeCreateNavigationThrottle(
- handle, std::make_unique<ChromeSecurityBlockingPageFactory>(),
- profile->GetPrefs()),
- &throttles);
- }
- if (IsErrorPageAutoReloadEnabled()) {
- MaybeAddThrottle(
- error_page::NetErrorAutoReloader::MaybeCreateThrottleFor(handle),
- &throttles);
- }
- MaybeAddThrottle(
- payments::PaymentHandlerNavigationThrottle::MaybeCreateThrottleFor(
- handle),
- &throttles);
- MaybeAddThrottle(
- prerender::NoStatePrefetchNavigationThrottle::MaybeCreateThrottleFor(
- handle),
- &throttles);
- #if defined(TOOLKIT_VIEWS)
- if (profile && IsSideSearchEnabled(profile)) {
- MaybeAddThrottle(
- SideSearchSideContentsHelper::MaybeCreateThrottleFor(handle),
- &throttles);
- }
- #endif
- #if BUILDFLAG(ENABLE_OFFLINE_PAGES)
- MaybeAddThrottle(
- offline_pages::OfflinePageNavigationThrottle::MaybeCreateThrottleFor(
- handle),
- &throttles);
- #endif
- if (profile && profile->GetPrefs()) {
- MaybeAddThrottle(
- HttpsOnlyModeNavigationThrottle::MaybeCreateThrottleFor(
- handle, std::make_unique<ChromeSecurityBlockingPageFactory>(),
- profile->GetPrefs()),
- &throttles);
- }
- MaybeAddThrottle(MaybeCreateNavigationAblationThrottle(handle), &throttles);
- #if !BUILDFLAG(IS_ANDROID)
- MaybeAddThrottle(MaybeCreateAboutThisSiteThrottleFor(handle), &throttles);
- #endif
- return throttles;
- }
- std::vector<std::unique_ptr<content::CommitDeferringCondition>>
- ChromeContentBrowserClient::CreateCommitDeferringConditionsForNavigation(
- content::NavigationHandle* navigation_handle,
- content::CommitDeferringCondition::NavigationType navigation_type) {
- auto conditions =
- std::vector<std::unique_ptr<content::CommitDeferringCondition>>();
- #if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
- MaybeAddCondition(
- safe_browsing::MaybeCreateCommitDeferringCondition(*navigation_handle),
- &conditions);
- #endif
- return conditions;
- }
- std::unique_ptr<content::NavigationUIData>
- ChromeContentBrowserClient::GetNavigationUIData(
- content::NavigationHandle* navigation_handle) {
- return std::make_unique<ChromeNavigationUIData>(navigation_handle);
- }
- std::unique_ptr<media::ScreenEnumerator>
- ChromeContentBrowserClient::CreateScreenEnumerator() const {
- return std::make_unique<ChromeScreenEnumerator>();
- }
- std::unique_ptr<content::DevToolsManagerDelegate>
- ChromeContentBrowserClient::CreateDevToolsManagerDelegate() {
- #if BUILDFLAG(IS_ANDROID)
- return std::make_unique<DevToolsManagerDelegateAndroid>();
- #else
- return std::make_unique<ChromeDevToolsManagerDelegate>();
- #endif
- }
- void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
- content::BrowserContext* browser_context,
- int service,
- base::Time expiration_time) {
- Profile* profile = Profile::FromBrowserContext(browser_context);
- DCHECK(profile);
- auto* pref_service = profile->GetPrefs();
- DCHECK(pref_service);
- DictionaryPrefUpdate pref_update(
- pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
- base::Value* exp_dict = pref_update.Get();
- // Convert |expiration_time| to minutes since that is the most granular
- // option that returns an int. base::Value does not accept int64.
- int expiration_time_minutes =
- expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
- exp_dict->SetIntKey(base::NumberToString(service), expiration_time_minutes);
- }
- base::flat_map<int, base::Time>
- ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
- content::BrowserContext* browser_context) {
- Profile* profile = Profile::FromBrowserContext(browser_context);
- DCHECK(profile);
- auto* pref_service = profile->GetPrefs();
- DCHECK(pref_service);
- const auto& expiration_dict = pref_service->GetValueDict(
- prefs::kDevToolsBackgroundServicesExpirationDict);
- base::flat_map<int, base::Time> expiration_times;
- for (auto it : expiration_dict) {
- // key.
- int service = 0;
- bool did_convert = base::StringToInt(it.first, &service);
- DCHECK(did_convert);
- // value.
- DCHECK(it.second.is_int());
- base::TimeDelta delta = base::Minutes(it.second.GetInt());
- base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
- expiration_times[service] = expiration_time;
- }
- return expiration_times;
- }
- content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
- return new ChromeTracingDelegate();
- }
- bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
- content::BrowserContext* browser_context,
- const GURL& url) {
- #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
- return ChromeContentBrowserClientPluginsPart::
- IsPluginAllowedToCallRequestOSFileHandle(browser_context, url);
- #else
- return false;
- #endif
- }
- bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
- content::BrowserContext* browser_context,
- const GURL& url) {
- #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
- return ChromeContentBrowserClientPluginsPart::
- IsPluginAllowedToUseDevChannelAPIs(browser_context, url);
- #else
- return false;
- #endif
- }
- void ChromeContentBrowserClient::OverridePageVisibilityState(
- RenderFrameHost* render_frame_host,
- content::PageVisibilityState* visibility_state) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- WebContents* web_contents =
- WebContents::FromRenderFrameHost(render_frame_host);
- DCHECK(web_contents);
- prerender::NoStatePrefetchManager* no_state_prefetch_manager =
- prerender::NoStatePrefetchManagerFactory::GetForBrowserContext(
- web_contents->GetBrowserContext());
- if (no_state_prefetch_manager &&
- no_state_prefetch_manager->IsWebContentsPrefetching(web_contents)) {
- *visibility_state = content::PageVisibilityState::kHiddenButPainting;
- }
- }
- void ChromeContentBrowserClient::InitOnUIThread() {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- safe_browsing_service_ = g_browser_process->safe_browsing_service();
- // Initialize `network_contexts_parent_directory_`.
- base::FilePath user_data_dir;
- base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
- DCHECK(!user_data_dir.empty());
- network_contexts_parent_directory_.push_back(user_data_dir);
- base::FilePath cache_dir;
- chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
- DCHECK(!cache_dir.empty());
- // On some platforms, the cache is a child of the user_data_dir so only
- // return the one path.
- if (!user_data_dir.IsParent(cache_dir))
- network_contexts_parent_directory_.push_back(cache_dir);
- // If the cache location has been overridden by a switch or preference,
- // include that as well.
- if (auto* local_state = g_browser_process->local_state()) {
- base::FilePath pref_cache_dir =
- local_state->GetFilePath(prefs::kDiskCacheDir);
- if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir))
- network_contexts_parent_directory_.push_back(pref_cache_dir);
- }
- }
- void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
- base::CommandLine* to_command_line,
- const base::CommandLine& from_command_line,
- version_info::Channel channel) {
- #if BUILDFLAG(IS_ANDROID)
- const version_info::Channel kMaxDisableEncryptionChannel =
- version_info::Channel::BETA;
- #else
- const version_info::Channel kMaxDisableEncryptionChannel =
- version_info::Channel::DEV;
- #endif
- if (channel <= kMaxDisableEncryptionChannel) {
- static const char* const kWebRtcDevSwitchNames[] = {
- switches::kDisableWebRtcEncryption,
- };
- to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
- std::size(kWebRtcDevSwitchNames));
- }
- }
- #if BUILDFLAG(ENABLE_MEDIA_REMOTING)
- void ChromeContentBrowserClient::CreateMediaRemoter(
- content::RenderFrameHost* render_frame_host,
- mojo::PendingRemote<media::mojom::RemotingSource> source,
- mojo::PendingReceiver<media::mojom::Remoter> receiver) {
- CastRemotingConnector::CreateMediaRemoter(
- render_frame_host, std::move(source), std::move(receiver));
- }
- #endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
- base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
- const base::CommandLine& command_line) {
- return logging::GetLogFileName(command_line);
- }
- std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
- ChromeContentBrowserClient::CreateURLLoaderThrottles(
- const network::ResourceRequest& request,
- content::BrowserContext* browser_context,
- const base::RepeatingCallback<content::WebContents*()>& wc_getter,
- content::NavigationUIData* navigation_ui_data,
- int frame_tree_node_id) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
- DCHECK(browser_context);
- Profile* profile = Profile::FromBrowserContext(browser_context);
- DCHECK(profile);
- ChromeNavigationUIData* chrome_navigation_ui_data =
- static_cast<ChromeNavigationUIData*>(navigation_ui_data);
- url_param_filter::UrlParamFilterThrottle::MaybeCreateThrottle(
- profile->GetPrefs()->GetBoolean(
- policy::policy_prefs::kUrlParamFilterEnabled),
- wc_getter.Run(), request, &result);
- #if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
- bool matches_enterprise_allowlist = safe_browsing::IsURLAllowlistedByPolicy(
- request.url, *profile->GetPrefs());
- if (!matches_enterprise_allowlist) {
- #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
- auto* connectors_service =
- enterprise_connectors::ConnectorsServiceFactory::GetForBrowserContext(
- browser_context);
- bool has_valid_dm_token =
- connectors_service &&
- connectors_service->GetDMTokenForRealTimeUrlCheck().has_value();
- bool is_enterprise_lookup_enabled =
- safe_browsing::RealTimePolicyEngine::CanPerformEnterpriseFullURLLookup(
- profile->GetPrefs(), has_valid_dm_token, profile->IsOffTheRecord());
- #else
- bool is_enterprise_lookup_enabled = false;
- #endif
- bool is_consumer_lookup_enabled =
- safe_browsing::RealTimePolicyEngine::CanPerformFullURLLookup(
- profile->GetPrefs(), profile->IsOffTheRecord(),
- g_browser_process->variations_service());
- // |url_lookup_service| is used when real time url check is enabled.
- safe_browsing::RealTimeUrlLookupServiceBase* url_lookup_service =
- GetUrlLookupService(browser_context, is_enterprise_lookup_enabled,
- is_consumer_lookup_enabled);
- result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
- base::BindOnce(
- &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
- base::Unretained(this),
- safe_browsing::IsSafeBrowsingEnabled(*profile->GetPrefs()),
- // Should check for enterprise when safe browsing is disabled.
- /*should_check_on_sb_disabled=*/is_enterprise_lookup_enabled,
- safe_browsing::GetURLAllowlistByPolicy(profile->GetPrefs())),
- wc_getter, frame_tree_node_id,
- url_lookup_service ? url_lookup_service->GetWeakPtr() : nullptr));
- }
- #endif
- #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
- result.push_back(
- std::make_unique<captive_portal::CaptivePortalURLLoaderThrottle>(
- wc_getter.Run()));
- #endif
- if (chrome_navigation_ui_data &&
- chrome_navigation_ui_data->is_no_state_prefetching()) {
- result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
- chrome_navigation_ui_data->prerender_histogram_prefix(),
- GetPrerenderCanceler(wc_getter)));
- }
- #if BUILDFLAG(IS_ANDROID)
- std::string client_data_header;
- bool is_tab_large_enough = false;
- bool is_custom_tab = false;
- if (frame_tree_node_id != content::RenderFrameHost::kNoFrameTreeNodeId) {
- auto* web_contents = WebContents::FromFrameTreeNodeId(frame_tree_node_id);
- // Could be null if the FrameTreeNode's RenderFrameHost is shutting down.
- if (web_contents) {
- auto* client_data_header_observer =
- customtabs::ClientDataHeaderWebContentsObserver::FromWebContents(
- web_contents);
- if (client_data_header_observer)
- client_data_header = client_data_header_observer->header();
- auto* delegate =
- TabAndroid::FromWebContents(web_contents)
- ? static_cast<android::TabWebContentsDelegateAndroid*>(
- web_contents->GetDelegate())
- : nullptr;
- if (delegate) {
- is_tab_large_enough = delegate->IsTabLargeEnoughForDesktopSite();
- is_custom_tab = delegate->IsCustomTab();
- }
- }
- }
- #endif
- chrome::mojom::DynamicParams dynamic_params = {
- profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
- profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
- profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps)};
- result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
- #if BUILDFLAG(IS_ANDROID)
- client_data_header, is_tab_large_enough,
- #endif
- std::move(dynamic_params)));
- {
- auto* factory =
- ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context);
- // null in unit tests.
- if (factory) {
- result.push_back(
- std::make_unique<custom_handlers::ProtocolHandlerThrottle>(*factory));
- }
- }
- #if BUILDFLAG(ENABLE_PLUGINS)
- result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
- request.destination, frame_tree_node_id));
- #endif
- #if BUILDFLAG(IS_ANDROID)
- auto delegate = std::make_unique<signin::HeaderModificationDelegateImpl>(
- profile, /*incognito_enabled=*/!is_custom_tab);
- #else
- auto delegate =
- std::make_unique<signin::HeaderModificationDelegateImpl>(profile);
- #endif
- auto signin_throttle =
- signin::URLLoaderThrottle::MaybeCreate(std::move(delegate), wc_getter);
- if (signin_throttle)
- result.push_back(std::move(signin_throttle));
- return result;
- }
- void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
- int frame_tree_node_id,
- ukm::SourceIdObj ukm_source_id,
- NonNetworkURLLoaderFactoryMap* factories) {
- #if BUILDFLAG(ENABLE_EXTENSIONS) || BUILDFLAG(IS_CHROMEOS_ASH)
- content::WebContents* web_contents =
- content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- factories->emplace(
- extensions::kExtensionScheme,
- extensions::CreateExtensionNavigationURLLoaderFactory(
- web_contents->GetBrowserContext(), ukm_source_id,
- !!extensions::WebViewGuest::FromWebContents(web_contents)));
- #endif // BUILDFLAG(ENABLE_EXTENSIONS)
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
- factories->emplace(content::kExternalFileScheme,
- chromeos::ExternalFileURLLoaderFactory::Create(
- profile, content::ChildProcessHost::kInvalidUniqueID));
- #endif // BUILDFLAG(IS_CHROMEOS_ASH)
- #endif // BUILDFLAG(ENABLE_EXTENSIONS) || BUILDFLAG(IS_CHROMEOS_ASH)
- }
- void ChromeContentBrowserClient::
- RegisterNonNetworkWorkerMainResourceURLLoaderFactories(
- content::BrowserContext* browser_context,
- NonNetworkURLLoaderFactoryMap* factories) {
- DCHECK(browser_context);
- DCHECK(factories);
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- factories->emplace(
- extensions::kExtensionScheme,
- extensions::CreateExtensionWorkerMainResourceURLLoaderFactory(
- browser_context));
- #endif // BUILDFLAG(ENABLE_EXTENSIONS)
- }
- void ChromeContentBrowserClient::
- RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
- content::BrowserContext* browser_context,
- NonNetworkURLLoaderFactoryMap* factories) {
- DCHECK(browser_context);
- DCHECK(factories);
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- factories->emplace(
- extensions::kExtensionScheme,
- extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
- browser_context));
- #endif // BUILDFLAG(ENABLE_EXTENSIONS)
- }
- namespace {
- // The SpecialAccessFileURLLoaderFactory provided to the extension background
- // pages. Checks with the ChildProcessSecurityPolicy to validate the file
- // access.
- class SpecialAccessFileURLLoaderFactory
- : public network::SelfDeletingURLLoaderFactory {
- public:
- // Returns mojo::PendingRemote to a newly constructed
- // SpecialAccessFileURLLoaderFactory. The factory is self-owned - it will
- // delete itself once there are no more receivers (including the receiver
- // associated with the returned mojo::PendingRemote and the receivers bound by
- // the Clone method).
- static mojo::PendingRemote<network::mojom::URLLoaderFactory> Create(
- int child_id) {
- mojo::PendingRemote<network::mojom::URLLoaderFactory> pending_remote;
- // The SpecialAccessFileURLLoaderFactory will delete itself when there are
- // no more receivers - see the
- // network::SelfDeletingURLLoaderFactory::OnDisconnect method.
- new SpecialAccessFileURLLoaderFactory(
- child_id, pending_remote.InitWithNewPipeAndPassReceiver());
- return pending_remote;
- }
- SpecialAccessFileURLLoaderFactory(const SpecialAccessFileURLLoaderFactory&) =
- delete;
- SpecialAccessFileURLLoaderFactory& operator=(
- const SpecialAccessFileURLLoaderFactory&) = delete;
- private:
- explicit SpecialAccessFileURLLoaderFactory(
- int child_id,
- mojo::PendingReceiver<network::mojom::URLLoaderFactory> factory_receiver)
- : network::SelfDeletingURLLoaderFactory(std::move(factory_receiver)),
- child_id_(child_id) {}
- // network::mojom::URLLoaderFactory:
- void CreateLoaderAndStart(
- mojo::PendingReceiver<network::mojom::URLLoader> loader,
- int32_t request_id,
- uint32_t options,
- const network::ResourceRequest& request,
- mojo::PendingRemote<network::mojom::URLLoaderClient> client,
- const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
- override {
- if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
- child_id_, request.url)) {
- mojo::Remote<network::mojom::URLLoaderClient>(std::move(client))
- ->OnComplete(
- network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
- return;
- }
- content::CreateFileURLLoaderBypassingSecurityChecks(
- request, std::move(loader), std::move(client),
- /*observer=*/nullptr,
- /* allow_directory_listing */ true);
- }
- int child_id_;
- };
- #if BUILDFLAG(IS_CHROMEOS)
- bool IsSystemFeatureDisabled(policy::SystemFeature system_feature) {
- return policy::SystemFeaturesDisableListPolicyHandler::
- IsSystemFeatureDisabled(system_feature, g_browser_process->local_state());
- }
- bool IsSystemFeatureURLDisabled(const GURL& url) {
- if (!url.SchemeIs(content::kChromeUIScheme) &&
- !url.SchemeIs(content::kChromeUIUntrustedScheme)) {
- return false;
- }
- // chrome://os-settings/pwa.html shouldn't be replaced to let the settings app
- // installation complete successfully.
- if (url.DomainIs(chrome::kChromeUIOSSettingsHost) &&
- url.path() != "/pwa.html") {
- return IsSystemFeatureDisabled(policy::SystemFeature::kOsSettings);
- }
- if (url.DomainIs(chrome::kChromeUISettingsHost)) {
- return IsSystemFeatureDisabled(policy::SystemFeature::kBrowserSettings);
- }
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- if (url.DomainIs(chrome::kChromeUIUntrustedCroshHost)) {
- return IsSystemFeatureDisabled(policy::SystemFeature::kCrosh);
- }
- if (url.DomainIs(ash::kChromeUIScanningAppHost)) {
- return IsSystemFeatureDisabled(policy::SystemFeature::kScanning);
- }
- if (url.DomainIs(ash::kChromeUICameraAppHost)) {
- return IsSystemFeatureDisabled(policy::SystemFeature::kCamera);
- }
- #endif
- return false;
- }
- #endif
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- void InitializeFileURLLoaderFactoryForExtension(
- int render_process_id,
- content::BrowserContext* browser_context,
- const extensions::Extension* extension,
- ChromeContentBrowserClient::NonNetworkURLLoaderFactoryMap* factories) {
- // Extensions with the necessary permissions get access to file:// URLs that
- // gets approval from ChildProcessSecurityPolicy. Keep this logic in sync with
- // ExtensionWebContentsObserver::RenderFrameCreated.
- Manifest::Type type = extension->GetType();
- if ((type == Manifest::TYPE_EXTENSION ||
- type == Manifest::TYPE_LEGACY_PACKAGED_APP) &&
- extensions::util::AllowFileAccess(extension->id(), browser_context)) {
- factories->emplace(
- url::kFileScheme,
- SpecialAccessFileURLLoaderFactory::Create(render_process_id));
- }
- }
- void AddChromeSchemeFactories(
- int render_process_id,
- content::RenderFrameHost* frame_host,
- content::WebContents* web_contents,
- const extensions::Extension* extension,
- ChromeContentBrowserClient::NonNetworkURLLoaderFactoryMap* factories) {
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(profile);
- // The test below matches when a remote 3P NTP is loaded. The effective
- // URL is chrome-search://remote-ntp. This is to allow the use of the NTP
- // public api and to embed most-visited tiles
- // (chrome-search://most-visited/title.html).
- if (instant_service->IsInstantProcess(render_process_id)) {
- factories->emplace(
- chrome::kChromeSearchScheme,
- content::CreateWebUIURLLoaderFactory(
- frame_host, chrome::kChromeSearchScheme,
- /*allowed_webui_hosts=*/base::flat_set<std::string>()));
- }
- extensions::ChromeExtensionWebContentsObserver* web_observer =
- extensions::ChromeExtensionWebContentsObserver::FromWebContents(
- web_contents);
- // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
- // to the |web_contents| or no enabled extension exists.
- if (!web_observer || !extension)
- return;
- std::vector<std::string> allowed_webui_hosts;
- // Support for chrome:// scheme if appropriate.
- if ((extension->is_extension() || extension->is_platform_app()) &&
- Manifest::IsComponentLocation(extension->location())) {
- // Components of chrome that are implemented as extensions or platform apps
- // are allowed to use chrome://resources/ and chrome://theme/ URLs.
- allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
- allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
- // For testing purposes chrome://webui-test/ is also allowed.
- allowed_webui_hosts.emplace_back(chrome::kChromeUIWebUITestHost);
- }
- if (extension->is_extension() || extension->is_legacy_packaged_app() ||
- (extension->is_platform_app() &&
- Manifest::IsComponentLocation(extension->location()))) {
- // Extensions, legacy packaged apps, and component platform apps are allowed
- // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
- // URLs. Hosted apps are not allowed because they are served via web servers
- // (and are generally never given access to Chrome APIs).
- allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
- allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
- allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
- }
- if (!allowed_webui_hosts.empty()) {
- factories->emplace(content::kChromeUIScheme,
- content::CreateWebUIURLLoaderFactory(
- frame_host, content::kChromeUIScheme,
- std::move(allowed_webui_hosts)));
- }
- }
- #endif // BUILDFLAG(ENABLE_EXTENSIONS)
- } // namespace
- void ChromeContentBrowserClient::
- RegisterNonNetworkSubresourceURLLoaderFactories(
- int render_process_id,
- int render_frame_id,
- const absl::optional<url::Origin>& request_initiator_origin,
- NonNetworkURLLoaderFactoryMap* factories) {
- #if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS)
- content::RenderFrameHost* frame_host =
- RenderFrameHost::FromID(render_process_id, render_frame_id);
- WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
- #endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS)
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- if (web_contents) {
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
- factories->emplace(content::kExternalFileScheme,
- chromeos::ExternalFileURLLoaderFactory::Create(
- profile, render_process_id));
- }
- #endif // BUILDFLAG(IS_CHROMEOS_ASH)
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- factories->emplace(extensions::kExtensionScheme,
- extensions::CreateExtensionURLLoaderFactory(
- render_process_id, render_frame_id));
- content::BrowserContext* browser_context =
- content::RenderProcessHost::FromID(render_process_id)
- ->GetBrowserContext();
- const extensions::Extension* extension = nullptr;
- if (request_initiator_origin != absl::nullopt) {
- extension = extensions::ExtensionRegistry::Get(browser_context)
- ->enabled_extensions()
- .GetExtensionOrAppByURL(request_initiator_origin->GetURL());
- }
- // For service worker contexts, we only allow file access. The remainder of
- // this code is used to allow extensions to access chrome:-scheme
- // resources, which we are moving away from.
- // TODO(crbug.com/1280411) Factories should not be created for unloaded
- // extensions.
- if (extension) {
- InitializeFileURLLoaderFactoryForExtension(
- render_process_id, browser_context, extension, factories);
- }
- // This logic should match
- // ChromeExtensionWebContentsObserver::RenderFrameCreated.
- if (web_contents) {
- AddChromeSchemeFactories(render_process_id, frame_host, web_contents,
- extension, factories);
- }
- #endif // BUILDFLAG(ENABLE_EXTENSIONS)
- }
- bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
- content::BrowserContext* browser_context,
- content::RenderFrameHost* frame,
- int render_process_id,
- URLLoaderFactoryType type,
- const url::Origin& request_initiator,
- absl::optional<int64_t> navigation_id,
- ukm::SourceIdObj ukm_source_id,
- mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
- mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
- header_client,
- bool* bypass_redirect_checks,
- bool* disable_secure_dns,
- network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
- bool use_proxy = false;
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- auto* web_request_api =
- extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
- browser_context);
- // NOTE: Some unit test environments do not initialize
- // BrowserContextKeyedAPI factories for e.g. WebRequest.
- if (web_request_api) {
- bool use_proxy_for_web_request =
- web_request_api->MaybeProxyURLLoaderFactory(
- browser_context, frame, render_process_id, type,
- std::move(navigation_id), ukm_source_id, factory_receiver,
- header_client, request_initiator);
- if (bypass_redirect_checks)
- *bypass_redirect_checks = use_proxy_for_web_request;
- use_proxy |= use_proxy_for_web_request;
- }
- #endif
- use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
- frame, type == URLLoaderFactoryType::kNavigation, request_initiator,
- factory_receiver);
- auto* prefetch_proxy_service = PrefetchProxyServiceFactory::GetForProfile(
- Profile::FromBrowserContext(browser_context));
- // |frame| is null when |type| is service worker.
- if (frame && prefetch_proxy_service) {
- use_proxy |= prefetch_proxy_service->MaybeProxyURLLoaderFactory(
- frame, render_process_id, type, factory_receiver);
- }
- #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
- if (disable_secure_dns) {
- WebContents* web_contents = WebContents::FromRenderFrameHost(frame);
- *disable_secure_dns =
- web_contents &&
- captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents) &&
- captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents)
- ->is_captive_portal_window();
- }
- #endif
- return use_proxy;
- }
- std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
- ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
- content::NavigationUIData* navigation_ui_data,
- int frame_tree_node_id,
- const scoped_refptr<network::SharedURLLoaderFactory>&
- network_loader_factory) {
- std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
- interceptors;
- #if BUILDFLAG(ENABLE_OFFLINE_PAGES)
- interceptors.push_back(
- std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
- navigation_ui_data, frame_tree_node_id));
- #endif
- #if BUILDFLAG(ENABLE_PDF)
- {
- std::unique_ptr<content::URLLoaderRequestInterceptor> pdf_interceptor =
- pdf::PdfURLLoaderRequestInterceptor::MaybeCreateInterceptor(
- frame_tree_node_id, std::make_unique<ChromePdfStreamDelegate>());
- if (pdf_interceptor)
- interceptors.push_back(std::move(pdf_interceptor));
- }
- #endif
- if (base::FeatureList::IsEnabled(features::kIsolatePrerenders)) {
- interceptors.push_back(std::make_unique<PrefetchProxyURLLoaderInterceptor>(
- frame_tree_node_id));
- }
- interceptors.push_back(
- std::make_unique<SearchPrefetchURLLoaderInterceptor>(frame_tree_node_id));
- if (base::FeatureList::IsEnabled(features::kHttpsOnlyMode)) {
- interceptors.push_back(
- std::make_unique<HttpsOnlyModeUpgradeInterceptor>(frame_tree_node_id));
- }
- return interceptors;
- }
- content::ContentBrowserClient::URLLoaderRequestHandler
- ChromeContentBrowserClient::
- CreateURLLoaderHandlerForServiceWorkerNavigationPreload(
- int frame_tree_node_id,
- const network::ResourceRequest& resource_request) {
- content::ContentBrowserClient::URLLoaderRequestHandler callback;
- std::unique_ptr<SearchPrefetchURLLoader> loader =
- SearchPrefetchURLLoaderInterceptor::MaybeCreateLoaderForRequest(
- resource_request, frame_tree_node_id);
- if (!loader) {
- return callback;
- }
- auto* raw_loader = loader.get();
- // Hand ownership of the loader to the callback, when it runs, mojo will
- // manage it. If the callback is deleted, the loader will be deleted.
- callback = raw_loader->ServingResponseHandler(std::move(loader));
- return callback;
- }
- bool ChromeContentBrowserClient::WillInterceptWebSocket(
- content::RenderFrameHost* frame) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- if (!frame) {
- return false;
- }
- const auto* web_request_api =
- extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
- frame->GetBrowserContext());
- // NOTE: Some unit test environments do not initialize
- // BrowserContextKeyedAPI factories for e.g. WebRequest.
- if (!web_request_api)
- return false;
- return web_request_api->MayHaveProxies();
- #else
- return false;
- #endif
- }
- void ChromeContentBrowserClient::CreateWebSocket(
- content::RenderFrameHost* frame,
- WebSocketFactory factory,
- const GURL& url,
- const net::SiteForCookies& site_for_cookies,
- const absl::optional<std::string>& user_agent,
- mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
- handshake_client) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- // TODO(crbug.com/1243518): Request w/o a frame also should be proxied.
- if (!frame) {
- return;
- }
- auto* web_request_api =
- extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
- frame->GetBrowserContext());
- DCHECK(web_request_api);
- web_request_api->ProxyWebSocket(frame, std::move(factory), url,
- site_for_cookies, user_agent,
- std::move(handshake_client));
- #endif
- }
- void ChromeContentBrowserClient::WillCreateWebTransport(
- int process_id,
- int frame_routing_id,
- const GURL& url,
- const url::Origin& initiator_origin,
- mojo::PendingRemote<network::mojom::WebTransportHandshakeClient>
- handshake_client,
- WillCreateWebTransportCallback callback) {
- #if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
- content::RenderFrameHost* frame =
- content::RenderFrameHost::FromID(process_id, frame_routing_id);
- if (frame) {
- int frame_tree_node_id = frame->GetFrameTreeNodeId();
- content::WebContents* web_contents =
- content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
- DCHECK(web_contents);
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
- DCHECK(profile);
- auto checker = std::make_unique<safe_browsing::WebApiHandshakeChecker>(
- base::BindOnce(
- &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
- base::Unretained(this),
- safe_browsing::IsSafeBrowsingEnabled(*profile->GetPrefs()),
- /*should_check_on_sb_disabled=*/false,
- safe_browsing::GetURLAllowlistByPolicy(profile->GetPrefs())),
- base::BindRepeating(&content::WebContents::FromFrameTreeNodeId,
- frame_tree_node_id),
- frame_tree_node_id);
- auto* raw_checker = checker.get();
- raw_checker->Check(
- url,
- base::BindOnce(
- &ChromeContentBrowserClient::SafeBrowsingWebApiHandshakeChecked,
- weak_factory_.GetWeakPtr(), std::move(checker), process_id,
- frame_routing_id, url, initiator_origin,
- std::move(handshake_client), std::move(callback)));
- return;
- }
- #endif
- MaybeInterceptWebTransport(process_id, frame_routing_id, url,
- initiator_origin, std::move(handshake_client),
- std::move(callback));
- }
- void ChromeContentBrowserClient::SafeBrowsingWebApiHandshakeChecked(
- std::unique_ptr<safe_browsing::WebApiHandshakeChecker> checker,
- int process_id,
- int frame_routing_id,
- const GURL& url,
- const url::Origin& initiator_origin,
- mojo::PendingRemote<network::mojom::WebTransportHandshakeClient>
- handshake_client,
- WillCreateWebTransportCallback callback,
- safe_browsing::WebApiHandshakeChecker::CheckResult result) {
- if (result == safe_browsing::WebApiHandshakeChecker::CheckResult::kProceed) {
- MaybeInterceptWebTransport(process_id, frame_routing_id, url,
- initiator_origin, std::move(handshake_client),
- std::move(callback));
- } else {
- std::move(callback).Run(std::move(handshake_client),
- network::mojom::WebTransportError::New(
- net::ERR_ABORTED, quic::QUIC_INTERNAL_ERROR,
- "SafeBrowsing check failed", false));
- }
- }
- void ChromeContentBrowserClient::MaybeInterceptWebTransport(
- int process_id,
- int frame_routing_id,
- const GURL& url,
- const url::Origin& initiator_origin,
- mojo::PendingRemote<network::mojom::WebTransportHandshakeClient>
- handshake_client,
- WillCreateWebTransportCallback callback) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- // TODO(1243518): Add a unit test which calls
- // ChromeContentBrowserClient::WillCreateWebTransport() with invalid process
- // id and routing id.
- auto* render_process_host = content::RenderProcessHost::FromID(process_id);
- if (!render_process_host) {
- std::move(callback).Run(std::move(handshake_client), absl::nullopt);
- return;
- }
- content::BrowserContext* browser_context =
- render_process_host->GetBrowserContext();
- auto* web_request_api =
- extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
- browser_context);
- // NOTE: Some unit test environments do not initialize BrowserContextKeyedAPI
- // factories like WebRequestAPI.
- if (!web_request_api) {
- std::move(callback).Run(std::move(handshake_client), absl::nullopt);
- return;
- }
- web_request_api->ProxyWebTransport(
- *render_process_host, frame_routing_id, url, initiator_origin,
- std::move(handshake_client), std::move(callback));
- #else
- std::move(callback).Run(std::move(handshake_client), absl::nullopt);
- #endif
- }
- bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
- network::mojom::RestrictedCookieManagerRole role,
- content::BrowserContext* browser_context,
- const url::Origin& origin,
- const net::IsolationInfo& isolation_info,
- bool is_service_worker,
- int process_id,
- int routing_id,
- mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- if (origin.scheme() == extensions::kExtensionScheme) {
- DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
- extensions::ChromeExtensionCookies::Get(browser_context)
- ->CreateRestrictedCookieManager(origin, isolation_info,
- std::move(*receiver));
- return true;
- }
- #endif
- return false;
- }
- void ChromeContentBrowserClient::OnNetworkServiceCreated(
- network::mojom::NetworkService* network_service) {
- PrefService* local_state;
- if (g_browser_process) {
- DCHECK(g_browser_process->local_state());
- local_state = g_browser_process->local_state();
- } else {
- DCHECK(startup_data_.chrome_feature_list_creator()->local_state());
- local_state = startup_data_.chrome_feature_list_creator()->local_state();
- }
- // Create SystemNetworkContextManager if it has not been created yet. We need
- // to set up global NetworkService state before anything else uses it and this
- // is the first opportunity to initialize SystemNetworkContextManager with the
- // NetworkService.
- if (!SystemNetworkContextManager::HasInstance())
- SystemNetworkContextManager::CreateInstance(local_state);
- SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
- network_service);
- }
- void ChromeContentBrowserClient::ConfigureNetworkContextParams(
- content::BrowserContext* context,
- bool in_memory,
- const base::FilePath& relative_partition_path,
- network::mojom::NetworkContextParams* network_context_params,
- cert_verifier::mojom::CertVerifierCreationParams*
- cert_verifier_creation_params) {
- ProfileNetworkContextService* service =
- ProfileNetworkContextServiceFactory::GetForContext(context);
- if (service) {
- service->ConfigureNetworkContextParams(in_memory, relative_partition_path,
- network_context_params,
- cert_verifier_creation_params);
- } else {
- // Set default params.
- network_context_params->user_agent = GetUserAgentBasedOnPolicy(context);
- network_context_params->accept_language = GetApplicationLocale();
- }
- }
- std::vector<base::FilePath>
- ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
- DCHECK(!network_contexts_parent_directory_.empty());
- return network_contexts_parent_directory_;
- }
- base::Value::Dict ChromeContentBrowserClient::GetNetLogConstants() {
- return net_log::GetPlatformConstantsForNetLog(
- base::CommandLine::ForCurrentProcess()->GetCommandLineString(),
- chrome::GetChannelName(chrome::WithExtendedStable(true)));
- }
- bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
- content::NavigationUIData* navigation_ui_data) {
- #if BUILDFLAG(ENABLE_OFFLINE_PAGES)
- // It is OK to load the saved offline copy, in MHTML format.
- ChromeNavigationUIData* chrome_navigation_ui_data =
- static_cast<ChromeNavigationUIData*>(navigation_ui_data);
- if (!chrome_navigation_ui_data)
- return false;
- offline_pages::OfflinePageNavigationUIData* offline_page_data =
- chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
- return offline_page_data && offline_page_data->is_offline_page();
- #else
- return false;
- #endif
- }
- bool ChromeContentBrowserClient::ShouldForceDownloadResource(
- const GURL& url,
- const std::string& mime_type) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- // Special-case user scripts to get downloaded instead of viewed.
- return extensions::UserScript::IsURLUserScript(url, mime_type);
- #else
- return false;
- #endif
- }
- content::BluetoothDelegate* ChromeContentBrowserClient::GetBluetoothDelegate() {
- if (!bluetooth_delegate_) {
- bluetooth_delegate_ = std::make_unique<permissions::BluetoothDelegateImpl>(
- std::make_unique<ChromeBluetoothDelegateImplClient>());
- }
- return bluetooth_delegate_.get();
- }
- #if !BUILDFLAG(IS_ANDROID)
- void ChromeContentBrowserClient::CreateDeviceInfoService(
- content::RenderFrameHost* render_frame_host,
- mojo::PendingReceiver<blink::mojom::DeviceAPIService> receiver) {
- DCHECK(render_frame_host);
- DeviceServiceImpl::Create(render_frame_host, std::move(receiver));
- }
- void ChromeContentBrowserClient::CreateManagedConfigurationService(
- content::RenderFrameHost* render_frame_host,
- mojo::PendingReceiver<blink::mojom::ManagedConfigurationService> receiver) {
- DCHECK(render_frame_host);
- ManagedConfigurationServiceImpl::Create(render_frame_host,
- std::move(receiver));
- }
- content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
- if (!serial_delegate_)
- serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
- return serial_delegate_.get();
- }
- content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
- if (!hid_delegate_)
- hid_delegate_ = std::make_unique<ChromeHidDelegate>();
- return hid_delegate_.get();
- }
- content::UsbDelegate* ChromeContentBrowserClient::GetUsbDelegate() {
- if (!usb_delegate_)
- usb_delegate_ = std::make_unique<ChromeUsbDelegate>();
- return usb_delegate_.get();
- }
- content::WebAuthenticationDelegate*
- ChromeContentBrowserClient::GetWebAuthenticationDelegate() {
- if (!web_authentication_delegate_) {
- web_authentication_delegate_ =
- std::make_unique<ChromeWebAuthenticationDelegate>();
- }
- return web_authentication_delegate_.get();
- }
- std::unique_ptr<content::AuthenticatorRequestClientDelegate>
- ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
- content::RenderFrameHost* render_frame_host) {
- return AuthenticatorRequestScheduler::CreateRequestDelegate(
- render_frame_host);
- }
- #endif
- std::unique_ptr<net::ClientCertStore>
- ChromeContentBrowserClient::CreateClientCertStore(
- content::BrowserContext* browser_context) {
- return ProfileNetworkContextServiceFactory::GetForContext(browser_context)
- ->CreateClientCertStore();
- }
- std::unique_ptr<content::LoginDelegate>
- ChromeContentBrowserClient::CreateLoginDelegate(
- const net::AuthChallengeInfo& auth_info,
- content::WebContents* web_contents,
- const content::GlobalRequestID& request_id,
- bool is_request_for_primary_main_frame,
- const GURL& url,
- scoped_refptr<net::HttpResponseHeaders> response_headers,
- bool first_auth_attempt,
- LoginAuthRequiredCallback auth_required_callback) {
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- auto* system_proxy_manager = ash::SystemProxyManager::Get();
- // For Managed Guest Session and Kiosk devices, the credentials configured
- // via the policy SystemProxySettings may be used for proxy authentication.
- // Note: |system_proxy_manager| may be missing in tests.
- if (system_proxy_manager && system_proxy_manager->CanUsePolicyCredentials(
- auth_info, first_auth_attempt)) {
- return system_proxy_manager->CreateLoginDelegate(
- std::move(auth_required_callback));
- }
- #endif // BUILDFLAG(IS_CHROMEOS_ASH)
- // For subresources, create a LoginHandler directly, which may show a login
- // prompt to the user. Main frame resources go through LoginTabHelper, which
- // manages a more complicated flow to avoid confusion about which website is
- // showing the prompt.
- if (is_request_for_primary_main_frame) {
- LoginTabHelper::CreateForWebContents(web_contents);
- return LoginTabHelper::FromWebContents(web_contents)
- ->CreateAndStartMainFrameLoginDelegate(
- auth_info, web_contents, request_id, url, response_headers,
- std::move(auth_required_callback));
- }
- std::unique_ptr<LoginHandler> login_handler = LoginHandler::Create(
- auth_info, web_contents, std::move(auth_required_callback));
- login_handler->StartSubresource(request_id, url, response_headers);
- return login_handler;
- }
- bool ChromeContentBrowserClient::HandleExternalProtocol(
- const GURL& url,
- content::WebContents::Getter web_contents_getter,
- int frame_tree_node_id,
- content::NavigationUIData* navigation_data,
- bool is_primary_main_frame,
- bool is_in_fenced_frame_tree,
- network::mojom::WebSandboxFlags sandbox_flags,
- ui::PageTransition page_transition,
- bool has_user_gesture,
- const absl::optional<url::Origin>& initiating_origin,
- content::RenderFrameHost* initiator_document,
- mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- // External protocols are disabled for guests. An exception is made for the
- // "mailto" protocol, so that pages that utilize it work properly in a
- // WebView.
- ChromeNavigationUIData* chrome_data =
- static_cast<ChromeNavigationUIData*>(navigation_data);
- if ((chrome_data &&
- chrome_data->GetExtensionNavigationUIData()->is_web_view()) &&
- !url.SchemeIs(url::kMailToScheme)) {
- return false;
- }
- #endif // BUILDFLAG(ENABLE_EXTENSIONS)
- #if BUILDFLAG(IS_ANDROID)
- // Main frame external protocols are handled by
- // InterceptNavigationResourceThrottle.
- if (is_primary_main_frame)
- return false;
- #endif // defined(ANDROID)
- auto weak_initiator_document = initiator_document
- ? initiator_document->GetWeakDocumentPtr()
- : content::WeakDocumentPtr();
- content::GetUIThreadTaskRunner({})->PostTask(
- FROM_HERE,
- base::BindOnce(&LaunchURL, weak_factory_.GetWeakPtr(), url,
- std::move(web_contents_getter), page_transition,
- is_primary_main_frame, is_in_fenced_frame_tree,
- sandbox_flags, has_user_gesture, initiating_origin,
- std::move(weak_initiator_document)));
- return true;
- }
- std::unique_ptr<content::VideoOverlayWindow>
- ChromeContentBrowserClient::CreateWindowForVideoPictureInPicture(
- content::VideoPictureInPictureWindowController* controller) {
- // Note: content::VideoOverlayWindow::Create() is defined by platform-specific
- // implementation in chrome/browser/ui/views. This layering hack, which goes
- // through //content and ContentBrowserClient, allows us to work around the
- // dependency constraints that disallow directly calling
- // chrome/browser/ui/views code either from here or from other code in
- // chrome/browser.
- return content::VideoOverlayWindow::Create(controller);
- }
- std::unique_ptr<content::DocumentOverlayWindow>
- ChromeContentBrowserClient::CreateWindowForDocumentPictureInPicture(
- content::DocumentPictureInPictureWindowController* controller) {
- // Note: content::DocumentOverlayWindow::Create() is defined by
- // platform-specific implementation in chrome/browser/ui/views. This layering
- // hack, which goes through //content and ContentBrowserClient, allows us to
- // work around the dependency constraints that disallow directly calling
- // chrome/browser/ui/views code either from here or from other code in
- // chrome/browser.
- return content::DocumentOverlayWindow::Create(controller);
- }
- void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
- content::BrowserContext* browser_context,
- mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
- Profile* profile = Profile::FromBrowserContext(browser_context);
- PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
- std::move(watcher));
- }
- // Static; handles rewriting Web UI URLs.
- bool ChromeContentBrowserClient::HandleWebUI(
- GURL* url,
- content::BrowserContext* browser_context) {
- DCHECK(browser_context);
- // Rewrite chrome://help to chrome://settings/help.
- if (url->SchemeIs(content::kChromeUIScheme) &&
- url->host() == chrome::kChromeUIHelpHost) {
- *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
- chrome::kChromeUIHelpHost);
- }
- if (base::FeatureList::IsEnabled(
- features::kConsolidatedSiteStorageControls)) {
- // Replace deprecated Site Data page URL with the All Sites page, which
- // contains storage controls for sites.
- if (url->SchemeIs(content::kChromeUIScheme) &&
- url->host() == chrome::kChromeUISettingsHost) {
- if (url->path() == chrome::kChromeUISiteDataDeprecatedPath) {
- *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
- chrome::kChromeUIAllSitesPath);
- UMA_HISTOGRAM_BOOLEAN("Settings.AllSites.DeprecatedRedirect", true);
- } else if (url->path() == chrome::kChromeUIAllSitesPath) {
- // Log un-redirected navigations to the page as well to provide context
- // for the raw number of redirects.
- UMA_HISTOGRAM_BOOLEAN("Settings.AllSites.DeprecatedRedirect", false);
- }
- }
- }
- #if BUILDFLAG(IS_WIN)
- // TODO(crbug.com/1003960): Remove when issue is resolved.
- if (url->SchemeIs(content::kChromeUIScheme) &&
- url->host() == chrome::kChromeUIWelcomeWin10Host) {
- *url =
- ReplaceURLHostAndPath(*url, chrome::kChromeUIWelcomeHost, url->path());
- return true;
- }
- #endif // BUILDFLAG(IS_WIN)
- if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
- browser_context, *url) &&
- !content::WebUIConfigMap::GetInstance().GetConfig(
- browser_context, url::Origin::Create(*url))) {
- return false;
- }
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- // Special case : in ChromeOS in Guest mode bookmarks and history are
- // disabled for security reasons. New tab page explains the reasons, so
- // we redirect user to new tab page.
- if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
- if (url->SchemeIs(content::kChromeUIScheme) &&
- (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
- url->DomainIs(chrome::kChromeUIHistoryHost))) {
- // Rewrite with new tab URL
- *url = GURL(chrome::kChromeUINewTabURL);
- }
- }
- #endif
- #if BUILDFLAG(IS_CHROMEOS)
- if (IsSystemFeatureURLDisabled(*url)) {
- *url = GURL(chrome::kChromeUIAppDisabledURL);
- return true;
- }
- #endif
- return true;
- }
- bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
- content::BrowserContext* browser_context,
- const GURL& url,
- base::OnceCallback<void(bool, int, int)> callback) {
- #if BUILDFLAG(IS_ANDROID)
- return false;
- #else
- payments::PaymentRequestDisplayManagerFactory::GetInstance()
- ->GetForBrowserContext(browser_context)
- ->ShowPaymentHandlerWindow(url, std::move(callback));
- return true;
- #endif
- }
- // static
- bool ChromeContentBrowserClient::HandleWebUIReverse(
- GURL* url,
- content::BrowserContext* browser_context) {
- #if BUILDFLAG(IS_WIN)
- // TODO(crbug.com/1003960): Remove when issue is resolved.
- // No need to actually reverse-rewrite the URL, but return true to update the
- // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome.
- if (url->SchemeIs(content::kChromeUIScheme) &&
- url->host() == chrome::kChromeUIWelcomeHost) {
- return true;
- }
- #endif // BUILDFLAG(IS_WIN)
- // No need to actually reverse-rewrite the URL, but return true to update the
- // displayed URL when rewriting chrome://help to chrome://settings/help.
- return url->SchemeIs(content::kChromeUIScheme) &&
- url->host() == chrome::kChromeUISettingsHost;
- }
- const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
- return ui::NativeTheme::GetInstanceForWeb();
- }
- scoped_refptr<safe_browsing::UrlCheckerDelegate>
- ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
- bool safe_browsing_enabled_for_profile,
- bool should_check_on_sb_disabled,
- const std::vector<std::string>& allowlist_domains) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- // Should not bypass safe browsing check if the check is for enterprise
- // lookup.
- if (!safe_browsing_enabled_for_profile && !should_check_on_sb_disabled)
- return nullptr;
- // |safe_browsing_service_| may be unavailable in tests.
- if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
- safe_browsing_url_checker_delegate_ =
- base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
- safe_browsing_service_->database_manager(),
- safe_browsing_service_->ui_manager());
- }
- // Update allowlist domains.
- if (safe_browsing_url_checker_delegate_) {
- safe_browsing_url_checker_delegate_->SetPolicyAllowlistDomains(
- allowlist_domains);
- }
- return safe_browsing_url_checker_delegate_;
- }
- safe_browsing::RealTimeUrlLookupServiceBase*
- ChromeContentBrowserClient::GetUrlLookupService(
- content::BrowserContext* browser_context,
- bool is_enterprise_lookup_enabled,
- bool is_consumer_lookup_enabled) {
- // |safe_browsing_service_| may be unavailable in tests.
- if (!safe_browsing_service_) {
- return nullptr;
- }
- Profile* profile = Profile::FromBrowserContext(browser_context);
- #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
- if (is_enterprise_lookup_enabled) {
- return safe_browsing::ChromeEnterpriseRealTimeUrlLookupServiceFactory::
- GetForProfile(profile);
- }
- #endif
- if (is_consumer_lookup_enabled) {
- return safe_browsing::RealTimeUrlLookupServiceFactory::GetForProfile(
- profile);
- }
- return nullptr;
- }
- bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
- // We require --user-data-dir flag too so that no dangerous changes are made
- // in the user's regular profile.
- return base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kUserDataDir);
- }
- void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
- content::GlobalRenderFrameHostId render_frame_host_id,
- int32_t network_traffic_annotation_id_hash,
- int64_t recv_bytes,
- int64_t sent_bytes) {
- #if !BUILDFLAG(IS_ANDROID)
- task_manager::TaskManagerInterface::UpdateAccumulatedStatsNetworkForRoute(
- render_frame_host_id, recv_bytes, sent_bytes);
- #endif
- ChromeDataUseMeasurement::GetInstance().ReportNetworkServiceDataUse(
- network_traffic_annotation_id_hash, recv_bytes, sent_bytes);
- }
- base::FilePath
- ChromeContentBrowserClient::GetSandboxedStorageServiceDataDirectory() {
- if (!g_browser_process || !g_browser_process->profile_manager())
- return base::FilePath();
- return g_browser_process->profile_manager()->user_data_dir();
- }
- bool ChromeContentBrowserClient::ShouldSandboxAudioService() {
- return IsAudioServiceSandboxEnabled();
- }
- bool ChromeContentBrowserClient::ShouldSandboxNetworkService() {
- return SystemNetworkContextManager::IsNetworkSandboxEnabled();
- }
- void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
- content::RenderFrameHost* render_frame_host,
- blink::mojom::WebFeature feature) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
- render_frame_host, feature);
- }
- std::string ChromeContentBrowserClient::GetProduct() {
- return version_info::GetProductNameAndVersionForUserAgent();
- }
- std::string ChromeContentBrowserClient::GetUserAgent() {
- return embedder_support::GetUserAgent();
- }
- std::string ChromeContentBrowserClient::GetUserAgentBasedOnPolicy(
- content::BrowserContext* context) {
- const PrefService* prefs = Profile::FromBrowserContext(context)->GetPrefs();
- embedder_support::ForceMajorVersionToMinorPosition
- force_major_version_to_minor =
- embedder_support::GetMajorToMinorFromPrefs(prefs);
- embedder_support::UserAgentReductionEnterprisePolicyState
- user_agent_reduction =
- embedder_support::GetUserAgentReductionFromPrefs(prefs);
- switch (user_agent_reduction) {
- case embedder_support::UserAgentReductionEnterprisePolicyState::
- kForceDisabled:
- return embedder_support::GetFullUserAgent(force_major_version_to_minor);
- case embedder_support::UserAgentReductionEnterprisePolicyState::
- kForceEnabled:
- return embedder_support::GetReducedUserAgent(
- force_major_version_to_minor);
- case embedder_support::UserAgentReductionEnterprisePolicyState::kDefault:
- default:
- return embedder_support::GetUserAgent(force_major_version_to_minor,
- user_agent_reduction);
- }
- }
- std::string ChromeContentBrowserClient::GetFullUserAgent() {
- return embedder_support::GetFullUserAgent();
- }
- std::string ChromeContentBrowserClient::GetReducedUserAgent() {
- return embedder_support::GetReducedUserAgent();
- }
- blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- return embedder_support::GetUserAgentMetadata(
- g_browser_process->local_state());
- }
- absl::optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
- // This icon is available on Android, but adds 19KiB to the APK. Since it
- // isn't used on Android we exclude it to avoid bloat.
- #if !BUILDFLAG(IS_ANDROID)
- return absl::optional<gfx::ImageSkia>(
- *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- IDR_PRODUCT_LOGO_256));
- #else
- return absl::nullopt;
- #endif
- }
- bool ChromeContentBrowserClient::IsBuiltinComponent(
- content::BrowserContext* browser_context,
- const url::Origin& origin) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
- browser_context, origin);
- #else
- return false;
- #endif
- }
- bool ChromeContentBrowserClient::ShouldBlockRendererDebugURL(
- const GURL& url,
- content::BrowserContext* context) {
- PolicyBlocklistService* service =
- PolicyBlocklistFactory::GetForBrowserContext(context);
- using URLBlocklistState = policy::URLBlocklist::URLBlocklistState;
- URLBlocklistState blocklist_state = service->GetURLBlocklistState(url);
- return blocklist_state == URLBlocklistState::URL_IN_BLOCKLIST;
- }
- ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
- content::BrowserContext* browser_context) {
- Profile* profile = Profile::FromBrowserContext(browser_context);
- return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
- }
- #if BUILDFLAG(IS_ANDROID)
- content::ContentBrowserClient::WideColorGamutHeuristic
- ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
- if (viz::AlwaysUseWideColorGamut() ||
- features::IsDynamicColorGamutEnabled()) {
- return WideColorGamutHeuristic::kUseDisplay;
- }
- if (display::HasForceDisplayColorProfile() &&
- display::GetForcedDisplayColorProfile() ==
- gfx::ColorSpace::CreateDisplayP3D65()) {
- return WideColorGamutHeuristic::kUseDisplay;
- }
- return WideColorGamutHeuristic::kNone;
- }
- #endif
- base::flat_set<std::string>
- ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
- content::BrowserContext* browser_context) {
- base::flat_set<std::string> mime_types;
- #if BUILDFLAG(ENABLE_PLUGINS)
- auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
- for (const auto& pair : map)
- mime_types.insert(pair.first);
- #endif
- #if BUILDFLAG(ENABLE_PDF)
- mime_types.insert(pdf::kInternalPluginMimeType);
- #endif
- return mime_types;
- }
- void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
- content::RenderFrameHost* frame_host,
- bool user_gesture,
- blink::NavigationDownloadPolicy* download_policy) {
- const auto* throttle_manager =
- subresource_filter::ContentSubresourceFilterThrottleManager::FromPage(
- frame_host->GetPage());
- if (throttle_manager &&
- throttle_manager->IsRenderFrameHostTaggedAsAd(frame_host)) {
- download_policy->SetAllowed(blink::NavigationDownloadType::kAdFrame);
- if (!user_gesture) {
- if (base::FeatureList::IsEnabled(
- blink::features::
- kBlockingDownloadsInAdFrameWithoutUserActivation)) {
- download_policy->SetDisallowed(
- blink::NavigationDownloadType::kAdFrameNoGesture);
- } else {
- download_policy->SetAllowed(
- blink::NavigationDownloadType::kAdFrameNoGesture);
- }
- }
- }
- }
- std::vector<blink::mojom::EpochTopicPtr>
- ChromeContentBrowserClient::GetBrowsingTopicsForJsApi(
- const url::Origin& context_origin,
- content::RenderFrameHost* main_frame) {
- browsing_topics::BrowsingTopicsService* browsing_topics_service =
- browsing_topics::BrowsingTopicsServiceFactory::GetForProfile(
- Profile::FromBrowserContext(
- content::WebContents::FromRenderFrameHost(main_frame)
- ->GetBrowserContext()));
- if (!browsing_topics_service)
- return {};
- auto topics = browsing_topics_service->GetBrowsingTopicsForJsApi(
- context_origin, main_frame);
- // Compare the provided topics to the real (i.e. non random) topics available
- // for the site, this allows filtering out of the randomly generated topics
- // for passing to the Page Specific Content Settings.
- auto real_topics = browsing_topics_service->GetTopicsForSiteForDisplay(
- main_frame->GetLastCommittedOrigin());
- // |topics| and |real_topics| will contain only a handful of entries,
- // and |topics| order must be preserved. A simple loop is thus appropriate.
- for (const auto& topic : topics) {
- int taxonomy_version = 0;
- base::StringToInt(topic->taxonomy_version, &taxonomy_version);
- DCHECK(taxonomy_version);
- privacy_sandbox::CanonicalTopic canonical_topic(
- browsing_topics::Topic(topic->topic), taxonomy_version);
- if (base::Contains(real_topics, canonical_topic)) {
- content_settings::PageSpecificContentSettings::TopicAccessed(
- main_frame, context_origin, /*blocked_by_policy=*/false,
- canonical_topic);
- }
- }
- return topics;
- }
- bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
- content::BrowserContext* browser_context,
- const url::Origin& requesting_origin,
- const url::Origin& embedding_origin) {
- const HostContentSettingsMap* const content_settings =
- HostContentSettingsMapFactory::GetForProfile(
- Profile::FromBrowserContext(browser_context));
- if (content_settings->GetContentSetting(
- requesting_origin.GetURL(), embedding_origin.GetURL(),
- ContentSettingsType::BLUETOOTH_SCANNING) == CONTENT_SETTING_BLOCK) {
- return true;
- }
- return false;
- }
- void ChromeContentBrowserClient::BlockBluetoothScanning(
- content::BrowserContext* browser_context,
- const url::Origin& requesting_origin,
- const url::Origin& embedding_origin) {
- HostContentSettingsMap* const content_settings =
- HostContentSettingsMapFactory::GetForProfile(
- Profile::FromBrowserContext(browser_context));
- content_settings->SetContentSettingDefaultScope(
- requesting_origin.GetURL(), embedding_origin.GetURL(),
- ContentSettingsType::BLUETOOTH_SCANNING, CONTENT_SETTING_BLOCK);
- }
- bool ChromeContentBrowserClient::ArePersistentMediaDeviceIDsAllowed(
- content::BrowserContext* browser_context,
- const GURL& url,
- const net::SiteForCookies& site_for_cookies,
- const absl::optional<url::Origin>& top_frame_origin) {
- // Persistent MediaDevice IDs are allowed if cookies are allowed.
- return CookieSettingsFactory::GetForProfile(
- Profile::FromBrowserContext(browser_context))
- ->IsFullCookieAccessAllowed(
- url, site_for_cookies, top_frame_origin,
- content_settings::CookieSettings::QueryReason::kSiteStorage);
- }
- #if !BUILDFLAG(IS_ANDROID)
- base::OnceClosure ChromeContentBrowserClient::FetchRemoteSms(
- content::WebContents* web_contents,
- const std::vector<url::Origin>& origin_list,
- base::OnceCallback<void(absl::optional<std::vector<url::Origin>>,
- absl::optional<std::string>,
- absl::optional<content::SmsFetchFailureType>)>
- callback) {
- return ::FetchRemoteSms(web_contents, origin_list, std::move(callback));
- }
- #endif
- bool ChromeContentBrowserClient::IsClipboardPasteAllowed(
- content::RenderFrameHost* render_frame_host) {
- DCHECK(render_frame_host);
- // Paste requires either (1) user activation, ...
- if (render_frame_host->HasTransientUserActivation())
- return true;
- // (2) granted web permission, ...
- content::BrowserContext* browser_context =
- render_frame_host->GetBrowserContext();
- content::PermissionController* permission_controller =
- browser_context->GetPermissionController();
- blink::mojom::PermissionStatus status =
- permission_controller->GetPermissionStatusForCurrentDocument(
- blink::PermissionType::CLIPBOARD_READ_WRITE, render_frame_host);
- if (status == blink::mojom::PermissionStatus::GRANTED)
- return true;
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- // (3) origination directly from a Chrome extension, ...
- Profile* profile = Profile::FromBrowserContext(browser_context);
- DCHECK(profile);
- const GURL& url =
- render_frame_host->GetMainFrame()->GetLastCommittedOrigin().GetURL();
- auto* registry = extensions::ExtensionRegistry::Get(profile);
- if (url.SchemeIs(extensions::kExtensionScheme)) {
- return URLHasExtensionPermission(extensions::ProcessMap::Get(profile),
- registry, url,
- render_frame_host->GetProcess()->GetID(),
- APIPermissionID::kClipboardRead);
- }
- // or (4) origination from a process that at least might be running a
- // content script from an extension with the clipboardRead permission.
- extensions::ExtensionIdSet extension_ids =
- extensions::ContentScriptTracker::GetExtensionsThatRanScriptsInProcess(
- *render_frame_host->GetProcess());
- for (const auto& extension_id : extension_ids) {
- const Extension* extension =
- registry->enabled_extensions().GetByID(extension_id);
- if (extension && extension->permissions_data()->HasAPIPermission(
- APIPermissionID::kClipboardRead)) {
- return true;
- }
- }
- #endif // BUILDFLAG(ENABLE_EXTENSIONS)
- return false;
- }
- void ChromeContentBrowserClient::IsClipboardPasteContentAllowed(
- content::WebContents* web_contents,
- const GURL& url,
- const ui::ClipboardFormatType& data_type,
- const std::string& data,
- IsClipboardPasteContentAllowedCallback callback) {
- #if BUILDFLAG(FULL_SAFE_BROWSING)
- // Safe browsing does not support images, so accept without checking.
- // TODO(crbug.com/1013584): check policy on what to do about unsupported
- // types when it is implemented.
- if (data_type == ui::ClipboardFormatType::BitmapType()) {
- std::move(callback).Run(ClipboardPasteContentAllowed(true));
- return;
- }
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
- enterprise_connectors::ContentAnalysisDelegate::Data dialog_data;
- if (enterprise_connectors::ContentAnalysisDelegate::IsEnabled(
- profile, web_contents->GetLastCommittedURL(), &dialog_data,
- enterprise_connectors::AnalysisConnector::BULK_DATA_ENTRY)) {
- dialog_data.text.push_back(data);
- enterprise_connectors::ContentAnalysisDelegate::CreateForWebContents(
- web_contents, std::move(dialog_data),
- base::BindOnce(
- [](IsClipboardPasteContentAllowedCallback callback,
- const enterprise_connectors::ContentAnalysisDelegate::Data& data,
- const enterprise_connectors::ContentAnalysisDelegate::Result&
- result) {
- std::move(callback).Run(
- ClipboardPasteContentAllowed(result.text_results[0]));
- },
- std::move(callback)),
- safe_browsing::DeepScanAccessPoint::PASTE);
- } else {
- std::move(callback).Run(ClipboardPasteContentAllowed(true));
- }
- #else
- std::move(callback).Run(ClipboardPasteContentAllowed(true));
- #endif // BUILDFLAG(FULL_SAFE_BROWSING)
- }
- bool ChromeContentBrowserClient::IsClipboardCopyAllowed(
- content::BrowserContext* browser_context,
- const GURL& url,
- size_t data_size_in_bytes,
- std::u16string& replacement_data) {
- ClipboardRestrictionService* service =
- ClipboardRestrictionServiceFactory::GetInstance()->GetForBrowserContext(
- browser_context);
- return service->IsUrlAllowedToCopy(url, data_size_in_bytes,
- &replacement_data);
- }
- #if BUILDFLAG(ENABLE_VR)
- content::XrIntegrationClient*
- ChromeContentBrowserClient::GetXrIntegrationClient() {
- if (!xr_integration_client_)
- xr_integration_client_ = std::make_unique<vr::ChromeXrIntegrationClient>(
- base::PassKey<ChromeContentBrowserClient>());
- return xr_integration_client_.get();
- }
- #endif // BUILDFLAG(ENABLE_VR)
- void ChromeContentBrowserClient::BindBrowserControlInterface(
- mojo::ScopedMessagePipeHandle pipe) {
- #if BUILDFLAG(IS_CHROMEOS_LACROS)
- chromeos::LacrosService::Get()->BindReceiver(
- chrome::GetVersionString(chrome::WithExtendedStable(true)));
- #endif
- }
- bool ChromeContentBrowserClient::
- ShouldInheritCrossOriginEmbedderPolicyImplicitly(const GURL& url) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- return url.SchemeIs(extensions::kExtensionScheme);
- #else
- return false;
- #endif
- }
- bool ChromeContentBrowserClient::ShouldAllowInsecurePrivateNetworkRequests(
- content::BrowserContext* browser_context,
- const url::Origin& origin) {
- return content_settings::ShouldAllowInsecurePrivateNetworkRequests(
- HostContentSettingsMapFactory::GetForProfile(browser_context), origin);
- }
- bool ChromeContentBrowserClient::IsJitDisabledForSite(
- content::BrowserContext* browser_context,
- const GURL& site_url) {
- Profile* profile = Profile::FromBrowserContext(browser_context);
- auto* map = HostContentSettingsMapFactory::GetForProfile(profile);
- // Special case to determine if any policy is set.
- if (site_url.is_empty()) {
- return map->GetDefaultContentSetting(ContentSettingsType::JAVASCRIPT_JIT,
- nullptr) == CONTENT_SETTING_BLOCK;
- }
- // Only disable JIT for web schemes.
- if (!site_url.SchemeIsHTTPOrHTTPS())
- return false;
- return (map->GetContentSetting(site_url, site_url,
- ContentSettingsType::JAVASCRIPT_JIT) ==
- CONTENT_SETTING_BLOCK);
- }
- ukm::UkmService* ChromeContentBrowserClient::GetUkmService() {
- return g_browser_process->GetMetricsServicesManager()->GetUkmService();
- }
- void ChromeContentBrowserClient::OnKeepaliveRequestStarted(
- content::BrowserContext* context) {
- #if !BUILDFLAG(IS_ANDROID)
- DVLOG(1) << "OnKeepaliveRequestStarted: " << num_keepalive_requests_
- << " ==> " << num_keepalive_requests_ + 1;
- ++num_keepalive_requests_;
- DCHECK_GT(num_keepalive_requests_, 0u);
- if (!context) {
- // We somehow failed to associate the request and the BrowserContext. Bail
- // out.
- return;
- }
- const auto now = base::TimeTicks::Now();
- const auto timeout = GetKeepaliveTimerTimeout(context);
- keepalive_deadline_ = std::max(keepalive_deadline_, now + timeout);
- if (keepalive_deadline_ > now && !keepalive_timer_.IsRunning()) {
- DVLOG(1) << "Starting a keepalive timer(" << timeout.InSecondsF()
- << " seconds)";
- keepalive_timer_.Start(
- FROM_HERE, keepalive_deadline_ - now,
- base::BindOnce(
- &ChromeContentBrowserClient::OnKeepaliveTimerFired,
- weak_factory_.GetWeakPtr(),
- std::make_unique<ScopedKeepAlive>(
- KeepAliveOrigin::BROWSER, KeepAliveRestartOption::DISABLED)));
- }
- #endif // !BUILDFLAG(IS_ANDROID)
- }
- void ChromeContentBrowserClient::OnKeepaliveRequestFinished() {
- #if !BUILDFLAG(IS_ANDROID)
- DCHECK_GT(num_keepalive_requests_, 0u);
- DVLOG(1) << "OnKeepaliveRequestFinished: " << num_keepalive_requests_
- << " ==> " << num_keepalive_requests_ - 1;
- --num_keepalive_requests_;
- if (num_keepalive_requests_ == 0) {
- DVLOG(1) << "Stopping the keepalive timer";
- keepalive_timer_.Stop();
- // This deletes the keep alive handle attached to the timer function and
- // unblock the shutdown sequence.
- }
- #endif // !BUILDFLAG(IS_ANDROID)
- }
- #if BUILDFLAG(IS_MAC)
- bool ChromeContentBrowserClient::SetupEmbedderSandboxParameters(
- sandbox::mojom::Sandbox sandbox_type,
- sandbox::SeatbeltExecClient* client) {
- if (sandbox_type == sandbox::mojom::Sandbox::kSpeechRecognition) {
- base::FilePath soda_component_path = speech::GetSodaDirectory();
- CHECK(!soda_component_path.empty());
- CHECK(client->SetParameter(sandbox::policy::kParamSodaComponentPath,
- soda_component_path.value()));
- base::FilePath soda_language_pack_path =
- speech::GetSodaLanguagePacksDirectory();
- CHECK(!soda_language_pack_path.empty());
- CHECK(client->SetParameter(sandbox::policy::kParamSodaLanguagePackPath,
- soda_language_pack_path.value()));
- return true;
- } else if (sandbox_type == sandbox::mojom::Sandbox::kScreenAI) {
- #if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
- // ScreenAI service needs read access to ScreenAI component path, so that it
- // would be able to find the latest downloaded version, and load its binary
- // and all enclosed model files.
- base::FilePath screen_ai_component_dir = screen_ai::GetComponentDir();
- if (screen_ai_component_dir.empty()) {
- VLOG(1) << "Screen AI component not found.";
- return false;
- }
- CHECK(client->SetParameter(sandbox::policy::kParamScreenAiComponentPath,
- screen_ai_component_dir.value()));
- return true;
- #endif
- }
- return false;
- }
- #endif // BUILDFLAG(IS_MAC)
- void ChromeContentBrowserClient::GetHyphenationDictionary(
- base::OnceCallback<void(const base::FilePath&)> callback) {
- #if BUILDFLAG(USE_MINIKIN_HYPHENATION) && !BUILDFLAG(IS_ANDROID)
- component_updater::HyphenationComponentInstallerPolicy::
- GetHyphenationDictionary(std::move(callback));
- #endif
- }
- bool ChromeContentBrowserClient::HasErrorPage(int http_status_code) {
- // Use an internal error page, if we have one for the status code.
- return error_page::LocalizedError::HasStrings(
- error_page::Error::kHttpErrorDomain, http_status_code);
- }
- std::unique_ptr<content::IdentityRequestDialogController>
- ChromeContentBrowserClient::CreateIdentityRequestDialogController() {
- return std::make_unique<IdentityDialogController>();
- }
- bool ChromeContentBrowserClient::SuppressDifferentOriginSubframeJSDialogs(
- content::BrowserContext* browser_context) {
- Profile* profile = Profile::FromBrowserContext(browser_context);
- if (!profile->GetPrefs()->GetBoolean(
- prefs::kSuppressDifferentOriginSubframeJSDialogs)) {
- return false;
- }
- return ContentBrowserClient::SuppressDifferentOriginSubframeJSDialogs(
- browser_context);
- }
- bool ChromeContentBrowserClient::IsFindInPageDisabledForOrigin(
- const url::Origin& origin) {
- #if BUILDFLAG(ENABLE_PDF)
- // For PDF viewing with the PPAPI-free PDF Viewer, find-in-page should only
- // display results from the PDF content, and not from the UI.
- return IsPdfExtensionOrigin(origin);
- #else
- return false;
- #endif
- }
- std::unique_ptr<content::SpeculationHostDelegate>
- ChromeContentBrowserClient::CreateSpeculationHostDelegate(
- content::RenderFrameHost& render_frame_host) {
- return std::make_unique<ChromeSpeculationHostDelegate>(render_frame_host);
- }
- std::unique_ptr<content::PrefetchServiceDelegate>
- ChromeContentBrowserClient::CreatePrefetchServiceDelegate(
- content::BrowserContext* browser_context) {
- return std::make_unique<ChromePrefetchServiceDelegate>(browser_context);
- }
- void ChromeContentBrowserClient::OnWebContentsCreated(
- content::WebContents* web_contents) {
- // NOTE: Please don't add additional code to this method - attaching universal
- // WebContentsObservers goes through the separate function, to ensure that the
- // (rare) additions of universal helpers are code reviewed by separate OWNERS.
- AttachUniversalWebContentsObservers(web_contents);
- }
- #if !BUILDFLAG(IS_ANDROID)
- base::TimeDelta ChromeContentBrowserClient::GetKeepaliveTimerTimeout(
- content::BrowserContext* context) {
- Profile* profile = Profile::FromBrowserContext(context);
- PrefService* prefs = profile->GetPrefs();
- if (!prefs) {
- return base::TimeDelta();
- }
- const int seconds =
- prefs->GetInteger(prefs::kFetchKeepaliveDurationOnShutdown);
- // The preference is set only be the corresponding enterprise policy, and
- // we have minimum/maximum values on it.
- DCHECK_LE(0, seconds);
- DCHECK_LE(seconds, 5);
- return base::Seconds(seconds);
- }
- void ChromeContentBrowserClient::OnKeepaliveTimerFired(
- std::unique_ptr<ScopedKeepAlive> keep_alive_handle) {
- const auto now = base::TimeTicks::Now();
- const auto then = keepalive_deadline_;
- if (now < then) {
- keepalive_timer_.Start(
- FROM_HERE, then - now,
- base::BindOnce(&ChromeContentBrowserClient::OnKeepaliveTimerFired,
- weak_factory_.GetWeakPtr(),
- std::move(keep_alive_handle)));
- }
- }
- #endif
- bool ChromeContentBrowserClient::ShouldPreconnectNavigation(
- content::BrowserContext* browser_context) {
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- // An extension could be blocking connections for privacy reasons, so skip
- // optimization if there are any extensions with WebRequest permissions.
- const auto* web_request_api =
- extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
- browser_context);
- if (!web_request_api || web_request_api->MayHaveProxies())
- return false;
- #endif
- // Preloading is sometimes disabled globally in Chrome via Finch to monitor
- // its impact. However, we do not want to evaluate the impact of preconnecting
- // at the start of navigation as part of the preloading holdback, so ignore
- // the Finch setting here.
- return prefetch::IsSomePreloadingEnabledIgnoringFinch(
- *Profile::FromBrowserContext(browser_context)->GetPrefs());
- }
- bool ChromeContentBrowserClient::ShouldDisableOriginAgentClusterDefault(
- content::BrowserContext* browser_context) {
- // The enterprise policy for kOriginAgentClusterDefaultEnabled defaults to
- // true to defer to Chromium's decision. If it is set to false, it should
- // override Chromium's decision and use site-keyed agent clusters by default
- // instead.
- return !Profile::FromBrowserContext(browser_context)
- ->GetPrefs()
- ->GetBoolean(prefs::kOriginAgentClusterDefaultEnabled);
- }
- bool ChromeContentBrowserClient::WillProvidePublicFirstPartySets() {
- return !base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableComponentUpdate) &&
- base::FeatureList::IsEnabled(features::kFirstPartySets);
- }
- content::mojom::AlternativeErrorPageOverrideInfoPtr
- ChromeContentBrowserClient::GetAlternativeErrorPageOverrideInfo(
- const GURL& url,
- content::RenderFrameHost* render_frame_host,
- content::BrowserContext* browser_context,
- int32_t error_code) {
- if (error_code != net::ERR_INTERNET_DISCONNECTED)
- return nullptr;
- #if BUILDFLAG(IS_ANDROID)
- if (!base::FeatureList::IsEnabled(features::kAndroidPWAsDefaultOfflinePage)) {
- #else
- if (!base::FeatureList::IsEnabled(features::kDesktopPWAsDefaultOfflinePage)) {
- #endif // BUILDFLAG(IS_ANDROID)
- return nullptr;
- }
- return web_app::GetOfflinePageInfo(url, render_frame_host, browser_context);
- }
- bool ChromeContentBrowserClient::OpenExternally(
- content::RenderFrameHost* opener,
- const GURL& url,
- WindowOpenDisposition disposition) {
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- // If Lacros is the primary browser, we intercept requests from Ash WebUIs and
- // redirect them to Lacros via crosapi. This is to make window.open and <a
- // href target="_blank"> links in WebUIs (e.g. ChromeOS Settings app) open in
- // Lacros rather than in Ash. NOTE: This is breaking change for calls to
- // window.open, as the return value will always be null. By excluding popups
- // and devtools:// and chrome:// URLs, we exclude the existing uses of
- // window.open that make use of the return value (these will have to be dealt
- // with separately) as well as some existing links that currently must remain
- // in Ash.
- bool should_open_in_lacros =
- crosapi::lacros_startup_state::IsLacrosEnabled() &&
- crosapi::lacros_startup_state::IsLacrosPrimaryEnabled() &&
- opener->GetWebUI() != nullptr &&
- disposition != WindowOpenDisposition::NEW_POPUP &&
- !url.SchemeIs(content::kChromeDevToolsScheme) &&
- !url.SchemeIs(content::kChromeUIScheme) &&
- // Terminal's tabs must remain in Ash.
- !url.SchemeIs(content::kChromeUIUntrustedScheme) &&
- // OS Settings's Accessibility section links to chrome-extensions:// URLs
- // for Text-to-Speech engines that are installed in Ash.
- !url.SchemeIs(extensions::kExtensionScheme);
- if (should_open_in_lacros) {
- ash::NewWindowDelegate::GetPrimary()->OpenUrl(
- url, ash::NewWindowDelegate::OpenUrlFrom::kUserInteraction,
- ash::NewWindowDelegate::Disposition::kNewForegroundTab);
- return true;
- }
- #endif
- return false;
- }
|