29
29
#include " mozilla/Mutex.h"
30
30
#include " mozilla/CondVar.h"
31
31
#include " nsISystemProxySettings.h"
32
+ #include " nsINetworkLinkService.h"
32
33
33
34
// ----------------------------------------------------------------------------
34
35
@@ -339,7 +340,7 @@ proxy_GetIntPref(nsIPrefBranch *aPrefBranch,
339
340
{
340
341
int32_t temp;
341
342
nsresult rv = aPrefBranch->GetIntPref (aPref, &temp);
342
- if (NS_FAILED(rv))
343
+ if (NS_FAILED(rv))
343
344
aResult = -1 ;
344
345
else
345
346
aResult = temp;
@@ -352,7 +353,7 @@ proxy_GetBoolPref(nsIPrefBranch *aPrefBranch,
352
353
{
353
354
bool temp;
354
355
nsresult rv = aPrefBranch->GetBoolPref (aPref, &temp);
355
- if (NS_FAILED(rv))
356
+ if (NS_FAILED(rv))
356
357
aResult = false ;
357
358
else
358
359
aResult = temp;
@@ -414,14 +415,66 @@ nsProtocolProxyService::Init()
414
415
PrefsChanged (prefBranch, nullptr );
415
416
}
416
417
417
- // register for shutdown notification so we can clean ourselves up properly.
418
418
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService ();
419
- if (obs)
419
+ if (obs) {
420
+ // register for shutdown notification so we can clean ourselves up
421
+ // properly.
420
422
obs->AddObserver (this , NS_XPCOM_SHUTDOWN_OBSERVER_ID, false );
421
423
424
+ obs->AddObserver (this , NS_NETWORK_LINK_TOPIC, false );
425
+ }
426
+
422
427
return NS_OK;
423
428
}
424
429
430
+ // ReloadNetworkPAC() checks if there's a non-networked PAC in use then avoids
431
+ // to call ReloadPAC()
432
+ nsresult
433
+ nsProtocolProxyService::ReloadNetworkPAC ()
434
+ {
435
+ nsCOMPtr<nsIPrefBranch> prefs =
436
+ do_GetService (NS_PREFSERVICE_CONTRACTID);
437
+ if (!prefs) {
438
+ return NS_OK;
439
+ }
440
+
441
+ int32_t type;
442
+ nsresult rv = prefs->GetIntPref (PROXY_PREF (" type" ), &type);
443
+ if (NS_FAILED(rv)) {
444
+ return NS_OK;
445
+ }
446
+
447
+ if (type == PROXYCONFIG_PAC) {
448
+ nsXPIDLCString pacSpec;
449
+ prefs->GetCharPref (PROXY_PREF (" autoconfig_url" ),
450
+ getter_Copies (pacSpec));
451
+ if (!pacSpec.IsEmpty ()) {
452
+ nsCOMPtr<nsIURI> pacURI;
453
+ rv = NS_NewURI(getter_AddRefs (pacURI), pacSpec);
454
+ if (!NS_SUCCEEDED(rv)) {
455
+ return rv;
456
+ }
457
+
458
+ nsProtocolInfo pac;
459
+ rv = GetProtocolInfo (pacURI, &pac);
460
+ if (!NS_SUCCEEDED(rv)) {
461
+ return rv;
462
+ }
463
+
464
+ if (!pac.scheme .EqualsLiteral (" file" ) &&
465
+ !pac.scheme .EqualsLiteral (" data" )) {
466
+ LOG ((" : received network changed event, reload PAC" ));
467
+ ReloadPAC ();
468
+ }
469
+ }
470
+ } else if ((type == PROXYCONFIG_WPAD) || (type == PROXYCONFIG_SYSTEM)) {
471
+ ReloadPAC ();
472
+ }
473
+
474
+ return NS_OK;
475
+ }
476
+
477
+
425
478
NS_IMETHODIMP
426
479
nsProtocolProxyService::Observe (nsISupports *aSubject,
427
480
const char *aTopic,
@@ -440,6 +493,12 @@ nsProtocolProxyService::Observe(nsISupports *aSubject,
440
493
mPACMan ->Shutdown ();
441
494
mPACMan = nullptr ;
442
495
}
496
+ } else if (strcmp (aTopic, NS_NETWORK_LINK_TOPIC) == 0 ) {
497
+ nsCString converted = NS_ConvertUTF16toUTF8(aData);
498
+ const char *state = converted.get ();
499
+ if (!strcmp (state, NS_NETWORK_LINK_DATA_CHANGED)) {
500
+ ReloadNetworkPAC ();
501
+ }
443
502
}
444
503
else {
445
504
NS_ASSERTION (strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) == 0,
@@ -513,7 +572,7 @@ nsProtocolProxyService::PrefsChanged(nsIPrefBranch *prefBranch,
513
572
514
573
if (!pref || !strcmp (pref, PROXY_PREF (" socks" )))
515
574
proxy_GetStringPref (prefBranch, PROXY_PREF (" socks" ), mSOCKSProxyHost );
516
-
575
+
517
576
if (!pref || !strcmp (pref, PROXY_PREF (" socks_port" )))
518
577
proxy_GetIntPref (prefBranch, PROXY_PREF (" socks_port" ), mSOCKSProxyPort );
519
578
@@ -587,14 +646,14 @@ nsProtocolProxyService::PrefsChanged(nsIPrefBranch *prefBranch,
587
646
}
588
647
589
648
bool
590
- nsProtocolProxyService::CanUseProxy (nsIURI *aURI, int32_t defaultPort)
649
+ nsProtocolProxyService::CanUseProxy (nsIURI *aURI, int32_t defaultPort)
591
650
{
592
651
if (mHostFiltersArray .Length () == 0 )
593
652
return true ;
594
653
595
654
int32_t port;
596
655
nsAutoCString host;
597
-
656
+
598
657
nsresult rv = aURI->GetAsciiHost (host);
599
658
if (NS_FAILED(rv) || host.IsEmpty ())
600
659
return false ;
@@ -624,7 +683,7 @@ nsProtocolProxyService::CanUseProxy(nsIURI *aURI, int32_t defaultPort)
624
683
return true ; // allow proxying
625
684
}
626
685
}
627
-
686
+
628
687
// Don't use proxy for local hosts (plain hostname, no dots)
629
688
if (!is_ipaddr && mFilterLocalHosts && (kNotFound == host.FindChar (' .' ))) {
630
689
LOG ((" Not using proxy for this local host [%s]!\n " , host.get ()));
@@ -810,7 +869,7 @@ nsProtocolProxyService::GetProxyKey(nsProxyInfo *pi, nsCString &key)
810
869
key.Append (' :' );
811
870
key.AppendInt (pi->mPort );
812
871
}
813
- }
872
+ }
814
873
815
874
uint32_t
816
875
nsProtocolProxyService::SecondsSinceSessionStart ()
@@ -1331,7 +1390,7 @@ nsProtocolProxyService::LoadHostFilters(const char *filters)
1331
1390
return ; // fail silently...
1332
1391
1333
1392
//
1334
- // filter = ( host | domain | ipaddr ["/" mask] ) [":" port]
1393
+ // filter = ( host | domain | ipaddr ["/" mask] ) [":" port]
1335
1394
// filters = filter *( "," LWS filter)
1336
1395
//
1337
1396
// Reset mFilterLocalHosts - will be set to true if "<local>" is in pref string
@@ -1343,7 +1402,7 @@ nsProtocolProxyService::LoadHostFilters(const char *filters)
1343
1402
1344
1403
const char *starthost = filters;
1345
1404
const char *endhost = filters + 1 ; // at least that...
1346
- const char *portLocation = 0 ;
1405
+ const char *portLocation = 0 ;
1347
1406
const char *maskLocation = 0 ;
1348
1407
1349
1408
while (*endhost && (*endhost != ' ,' && !IS_ASCII_SPACE (*endhost))) {
0 commit comments