Attachment #809225: Make layout/style/nsFontFaceLoader.* pointer notation follow layout code style for bug #906852

View | Details | Raw Unified | Return to bug 906852
Collapse All | Expand All

(-)a/layout/style/nsFontFaceLoader.cpp (-44 / +44 lines)
Line     Link Here 
 Lines 33-67    Link Here 
33
#include "nsIConsoleService.h"
33
#include "nsIConsoleService.h"
34
34
35
#include "nsStyleSet.h"
35
#include "nsStyleSet.h"
36
#include "nsPrintfCString.h"
36
#include "nsPrintfCString.h"
37
37
38
using namespace mozilla;
38
using namespace mozilla;
39
39
40
#ifdef PR_LOGGING
40
#ifdef PR_LOGGING
41
static PRLogModuleInfo *
41
static PRLogModuleInfo* 
42
GetFontDownloaderLog()
42
GetFontDownloaderLog()
43
{
43
{
44
  static PRLogModuleInfo *sLog;
44
  static PRLogModuleInfo* sLog;
45
  if (!sLog)
45
  if (!sLog)
46
    sLog = PR_NewLogModule("fontdownloader");
46
    sLog = PR_NewLogModule("fontdownloader");
47
  return sLog;
47
  return sLog;
48
}
48
}
49
#endif /* PR_LOGGING */
49
#endif /* PR_LOGGING */
50
50
51
#define LOG(args) PR_LOG(GetFontDownloaderLog(), PR_LOG_DEBUG, args)
51
#define LOG(args) PR_LOG(GetFontDownloaderLog(), PR_LOG_DEBUG, args)
52
#define LOG_ENABLED() PR_LOG_TEST(GetFontDownloaderLog(), PR_LOG_DEBUG)
52
#define LOG_ENABLED() PR_LOG_TEST(GetFontDownloaderLog(), PR_LOG_DEBUG)
53
53
54
54
55
nsFontFaceLoader::nsFontFaceLoader(gfxMixedFontFamily *aFontFamily,
55
nsFontFaceLoader::nsFontFaceLoader(gfxMixedFontFamily* aFontFamily,
56
                                   gfxProxyFontEntry *aProxy,
56
                                   gfxProxyFontEntry* aProxy,
57
                                   nsIURI *aFontURI,
57
                                   nsIURI* aFontURI,
58
                                   nsUserFontSet *aFontSet,
58
                                   nsUserFontSet* aFontSet,
59
                                   nsIChannel *aChannel)
59
                                   nsIChannel* aChannel)
60
  : mFontFamily(aFontFamily),
60
  : mFontFamily(aFontFamily),
61
    mFontEntry(aProxy),
61
    mFontEntry(aProxy),
62
    mFontURI(aFontURI),
62
    mFontURI(aFontURI),
63
    mFontSet(aFontSet),
63
    mFontSet(aFontSet),
64
    mChannel(aChannel)
64
    mChannel(aChannel)
65
{
65
{
66
}
66
}
67
67
 Lines 75-91   nsFontFaceLoader::~nsFontFaceLoader() Link Here 
75
    mLoadTimer = nullptr;
75
    mLoadTimer = nullptr;
76
  }
76
  }
77
  if (mFontSet) {
77
  if (mFontSet) {
78
    mFontSet->RemoveLoader(this);
78
    mFontSet->RemoveLoader(this);
79
  }
79
  }
80
}
80
}
81
81
82
void
82
void
83
nsFontFaceLoader::StartedLoading(nsIStreamLoader *aStreamLoader)
83
nsFontFaceLoader::StartedLoading(nsIStreamLoader* aStreamLoader)
84
{
84
{
85
  int32_t loadTimeout =
85
  int32_t loadTimeout =
86
    Preferences::GetInt("gfx.downloadable_fonts.fallback_delay", 3000);
86
    Preferences::GetInt("gfx.downloadable_fonts.fallback_delay", 3000);
87
  if (loadTimeout > 0) {
87
  if (loadTimeout > 0) {
88
    mLoadTimer = do_CreateInstance("@mozilla.org/timer;1");
88
    mLoadTimer = do_CreateInstance("@mozilla.org/timer;1");
89
    if (mLoadTimer) {
89
    if (mLoadTimer) {
90
      mLoadTimer->InitWithFuncCallback(LoadTimerCallback,
90
      mLoadTimer->InitWithFuncCallback(LoadTimerCallback,
91
                                       static_cast<void*>(this),
91
                                       static_cast<void*>(this),
 Lines 94-119   nsFontFaceLoader::StartedLoading(nsIStre Link Here 
94
    }
94
    }
95
  } else {
95
  } else {
96
    mFontEntry->mLoadingState = gfxProxyFontEntry::LOADING_SLOWLY;
96
    mFontEntry->mLoadingState = gfxProxyFontEntry::LOADING_SLOWLY;
97
  }
97
  }
98
  mStreamLoader = aStreamLoader;
98
  mStreamLoader = aStreamLoader;
99
}
99
}
100
100
101
void
101
void
102
nsFontFaceLoader::LoadTimerCallback(nsITimer *aTimer, void *aClosure)
102
nsFontFaceLoader::LoadTimerCallback(nsITimer* aTimer, void* aClosure)
103
{
103
{
104
  nsFontFaceLoader *loader = static_cast<nsFontFaceLoader*>(aClosure);
104
  nsFontFaceLoader* loader = static_cast<nsFontFaceLoader*>(aClosure);
105
105
106
  if (!loader->mFontSet) {
106
  if (!loader->mFontSet) {
107
    // We've been canceled
107
    // We've been canceled
108
    return;
108
    return;
109
  }
109
  }
110
110
111
  gfxProxyFontEntry *pe = loader->mFontEntry.get();
111
  gfxProxyFontEntry* pe = loader->mFontEntry.get();
112
  bool updateUserFontSet = true;
112
  bool updateUserFontSet = true;
113
113
114
  // If the entry is loading, check whether it's >75% done; if so,
114
  // If the entry is loading, check whether it's >75% done; if so,
115
  // we allow another timeout period before showing a fallback font.
115
  // we allow another timeout period before showing a fallback font.
116
  if (pe->mLoadingState == gfxProxyFontEntry::LOADING_STARTED) {
116
  if (pe->mLoadingState == gfxProxyFontEntry::LOADING_STARTED) {
117
    int64_t contentLength;
117
    int64_t contentLength;
118
    uint32_t numBytesRead;
118
    uint32_t numBytesRead;
119
    if (NS_SUCCEEDED(loader->mChannel->GetContentLength(&contentLength)) &&
119
    if (NS_SUCCEEDED(loader->mChannel->GetContentLength(&contentLength)) &&
 Lines 137-154   nsFontFaceLoader::LoadTimerCallback(nsIT Link Here 
137
    }
137
    }
138
  }
138
  }
139
139
140
  // If the font is not 75% loaded, or if we've already timed out once
140
  // If the font is not 75% loaded, or if we've already timed out once
141
  // before, we mark this entry as "loading slowly", so the fallback
141
  // before, we mark this entry as "loading slowly", so the fallback
142
  // font will be used in the meantime, and tell the context to refresh.
142
  // font will be used in the meantime, and tell the context to refresh.
143
  if (updateUserFontSet) {
143
  if (updateUserFontSet) {
144
    pe->mLoadingState = gfxProxyFontEntry::LOADING_SLOWLY;
144
    pe->mLoadingState = gfxProxyFontEntry::LOADING_SLOWLY;
145
    gfxUserFontSet *fontSet = loader->mFontSet;
145
    gfxUserFontSet* fontSet = loader->mFontSet;
146
    nsPresContext *ctx = loader->mFontSet->GetPresContext();
146
    nsPresContext* ctx = loader->mFontSet->GetPresContext();
147
    NS_ASSERTION(ctx, "userfontset doesn't have a presContext?");
147
    NS_ASSERTION(ctx, "userfontset doesn't have a presContext?");
148
    if (ctx) {
148
    if (ctx) {
149
      fontSet->IncrementGeneration();
149
      fontSet->IncrementGeneration();
150
      ctx->UserFontSetUpdated();
150
      ctx->UserFontSetUpdated();
151
      LOG(("fontdownloader (%p) timeout reflow\n", loader));
151
      LOG(("fontdownloader (%p) timeout reflow\n", loader));
152
    }
152
    }
153
  }
153
  }
154
}
154
}
 Lines 178-194   nsFontFaceLoader::OnStreamComplete(nsISt Link Here 
178
           this, fontURI.get()));
178
           this, fontURI.get()));
179
    } else {
179
    } else {
180
      LOG(("fontdownloader (%p) download failed - font uri: (%s) error: %8.8x\n", 
180
      LOG(("fontdownloader (%p) download failed - font uri: (%s) error: %8.8x\n", 
181
           this, fontURI.get(), aStatus));
181
           this, fontURI.get(), aStatus));
182
    }
182
    }
183
  }
183
  }
184
#endif
184
#endif
185
185
186
  nsPresContext *ctx = mFontSet->GetPresContext();
186
  nsPresContext* ctx = mFontSet->GetPresContext();
187
  NS_ASSERTION(ctx && !ctx->PresShell()->IsDestroying(),
187
  NS_ASSERTION(ctx && !ctx->PresShell()->IsDestroying(),
188
               "We should have been canceled already");
188
               "We should have been canceled already");
189
189
190
  if (NS_SUCCEEDED(aStatus)) {
190
  if (NS_SUCCEEDED(aStatus)) {
191
    // for HTTP requests, check whether the request _actually_ succeeded;
191
    // for HTTP requests, check whether the request _actually_ succeeded;
192
    // the "request status" in aStatus does not necessarily indicate this,
192
    // the "request status" in aStatus does not necessarily indicate this,
193
    // because HTTP responses such as 404 (Not Found) will still result in
193
    // because HTTP responses such as 404 (Not Found) will still result in
194
    // a success code and potentially an HTML error page from the server
194
    // a success code and potentially an HTML error page from the server
 Lines 252-268   nsFontFaceLoader::CheckLoadAllowed(nsIPr Link Here 
252
                                   nsISupports* aContext)
252
                                   nsISupports* aContext)
253
{
253
{
254
  nsresult rv;
254
  nsresult rv;
255
255
256
  if (!aSourcePrincipal)
256
  if (!aSourcePrincipal)
257
    return NS_OK;
257
    return NS_OK;
258
258
259
  // check with the security manager
259
  // check with the security manager
260
  nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
260
  nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
261
  rv = secMan->CheckLoadURIWithPrincipal(aSourcePrincipal, aTargetURI,
261
  rv = secMan->CheckLoadURIWithPrincipal(aSourcePrincipal, aTargetURI,
262
                                        nsIScriptSecurityManager::STANDARD);
262
                                        nsIScriptSecurityManager::STANDARD);
263
  if (NS_FAILED(rv)) {
263
  if (NS_FAILED(rv)) {
264
    return rv;
264
    return rv;
265
  }
265
  }
266
266
267
  // check content policy
267
  // check content policy
268
  int16_t shouldLoad = nsIContentPolicy::ACCEPT;
268
  int16_t shouldLoad = nsIContentPolicy::ACCEPT;
 Lines 278-294   nsFontFaceLoader::CheckLoadAllowed(nsIPr Link Here 
278
278
279
  if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) {
279
  if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) {
280
    return NS_ERROR_CONTENT_BLOCKED;
280
    return NS_ERROR_CONTENT_BLOCKED;
281
  }
281
  }
282
282
283
  return NS_OK;
283
  return NS_OK;
284
}
284
}
285
285
286
nsUserFontSet::nsUserFontSet(nsPresContext *aContext)
286
nsUserFontSet::nsUserFontSet(nsPresContext* aContext)
287
  : mPresContext(aContext)
287
  : mPresContext(aContext)
288
{
288
{
289
  NS_ASSERTION(mPresContext, "null context passed to nsUserFontSet");
289
  NS_ASSERTION(mPresContext, "null context passed to nsUserFontSet");
290
}
290
}
291
291
292
nsUserFontSet::~nsUserFontSet()
292
nsUserFontSet::~nsUserFontSet()
293
{
293
{
294
  NS_ASSERTION(mLoaders.Count() == 0, "mLoaders should have been emptied");
294
  NS_ASSERTION(mLoaders.Count() == 0, "mLoaders should have been emptied");
 Lines 305-333   void Link Here 
305
nsUserFontSet::Destroy()
305
nsUserFontSet::Destroy()
306
{
306
{
307
  mPresContext = nullptr;
307
  mPresContext = nullptr;
308
  mLoaders.EnumerateEntries(DestroyIterator, nullptr);
308
  mLoaders.EnumerateEntries(DestroyIterator, nullptr);
309
  mRules.Clear();
309
  mRules.Clear();
310
}
310
}
311
311
312
void
312
void
313
nsUserFontSet::RemoveLoader(nsFontFaceLoader *aLoader)
313
nsUserFontSet::RemoveLoader(nsFontFaceLoader* aLoader)
314
{
314
{
315
  mLoaders.RemoveEntry(aLoader);
315
  mLoaders.RemoveEntry(aLoader);
316
}
316
}
317
317
318
nsresult
318
nsresult
319
nsUserFontSet::StartLoad(gfxMixedFontFamily *aFamily,
319
nsUserFontSet::StartLoad(gfxMixedFontFamily* aFamily,
320
                         gfxProxyFontEntry *aProxy,
320
                         gfxProxyFontEntry* aProxy,
321
                         const gfxFontFaceSrc *aFontFaceSrc)
321
                         const gfxFontFaceSrc* aFontFaceSrc)
322
{
322
{
323
  nsresult rv;
323
  nsresult rv;
324
324
325
  nsIPresShell *ps = mPresContext->PresShell();
325
  nsIPresShell* ps = mPresContext->PresShell();
326
  if (!ps)
326
  if (!ps)
327
    return NS_ERROR_FAILURE;
327
    return NS_ERROR_FAILURE;
328
328
329
  nsCOMPtr<nsIStreamLoader> streamLoader;
329
  nsCOMPtr<nsIStreamLoader> streamLoader;
330
  nsCOMPtr<nsILoadGroup> loadGroup(ps->GetDocument()->GetDocumentLoadGroup());
330
  nsCOMPtr<nsILoadGroup> loadGroup(ps->GetDocument()->GetDocumentLoadGroup());
331
331
332
  nsCOMPtr<nsIChannel> channel;
332
  nsCOMPtr<nsIChannel> channel;
333
  // get Content Security Policy from principal to pass into channel
333
  // get Content Security Policy from principal to pass into channel
 Lines 456-493   nsUserFontSet::UpdateRules(const nsTArra Link Here 
456
    modified = true;
456
    modified = true;
457
    // Any in-progress loaders for obsolete rules should be cancelled,
457
    // Any in-progress loaders for obsolete rules should be cancelled,
458
    // as the resource being downloaded will no longer be required.
458
    // as the resource being downloaded will no longer be required.
459
    // We need to explicitly remove any loaders here, otherwise the loaders
459
    // We need to explicitly remove any loaders here, otherwise the loaders
460
    // will keep their "orphaned" font entries alive until they complete,
460
    // will keep their "orphaned" font entries alive until they complete,
461
    // even after the oldRules array is deleted.
461
    // even after the oldRules array is deleted.
462
    size_t count = oldRules.Length();
462
    size_t count = oldRules.Length();
463
    for (size_t i = 0; i < count; ++i) {
463
    for (size_t i = 0; i < count; ++i) {
464
      gfxFontEntry *fe = oldRules[i].mFontEntry;
464
      gfxFontEntry* fe = oldRules[i].mFontEntry;
465
      if (!fe->mIsProxy) {
465
      if (!fe->mIsProxy) {
466
        continue;
466
        continue;
467
      }
467
      }
468
      gfxProxyFontEntry *proxy = static_cast<gfxProxyFontEntry*>(fe);
468
      gfxProxyFontEntry* proxy = static_cast<gfxProxyFontEntry*>(fe);
469
      nsFontFaceLoader *loader = proxy->mLoader;
469
      nsFontFaceLoader* loader = proxy->mLoader;
470
      if (loader) {
470
      if (loader) {
471
        loader->Cancel();
471
        loader->Cancel();
472
        RemoveLoader(loader);
472
        RemoveLoader(loader);
473
      }
473
      }
474
    }
474
    }
475
  }
475
  }
476
476
477
  if (modified) {
477
  if (modified) {
478
    IncrementGeneration();
478
    IncrementGeneration();
479
  }
479
  }
480
480
481
  return modified;
481
  return modified;
482
}
482
}
483
483
484
void
484
void
485
nsUserFontSet::InsertRule(nsCSSFontFaceRule *aRule, uint8_t aSheetType,
485
nsUserFontSet::InsertRule(nsCSSFontFaceRule* aRule, uint8_t aSheetType,
486
                          nsTArray<FontFaceRuleRecord>& aOldRules,
486
                          nsTArray<FontFaceRuleRecord>& aOldRules,
487
                          bool& aFontSetModified)
487
                          bool& aFontSetModified)
488
{
488
{
489
  NS_ABORT_IF_FALSE(aRule->GetType() == mozilla::css::Rule::FONT_FACE_RULE,
489
  NS_ABORT_IF_FALSE(aRule->GetType() == mozilla::css::Rule::FONT_FACE_RULE,
490
                    "InsertRule passed a non-fontface CSS rule");
490
                    "InsertRule passed a non-fontface CSS rule");
491
491
492
  // set up family name
492
  // set up family name
493
  nsAutoString fontfamily;
493
  nsAutoString fontfamily;
 Lines 595-617   nsUserFontSet::InsertRule(nsCSSFontFaceR Link Here 
595
  }
595
  }
596
596
597
  // set up src array
597
  // set up src array
598
  nsTArray<gfxFontFaceSrc> srcArray;
598
  nsTArray<gfxFontFaceSrc> srcArray;
599
599
600
  aRule->GetDesc(eCSSFontDesc_Src, val);
600
  aRule->GetDesc(eCSSFontDesc_Src, val);
601
  unit = val.GetUnit();
601
  unit = val.GetUnit();
602
  if (unit == eCSSUnit_Array) {
602
  if (unit == eCSSUnit_Array) {
603
    nsCSSValue::Array *srcArr = val.GetArrayValue();
603
    nsCSSValue::Array* srcArr = val.GetArrayValue();
604
    size_t numSrc = srcArr->Count();
604
    size_t numSrc = srcArr->Count();
605
    
605
    
606
    for (size_t i = 0; i < numSrc; i++) {
606
    for (size_t i = 0; i < numSrc; i++) {
607
      val = srcArr->Item(i);
607
      val = srcArr->Item(i);
608
      unit = val.GetUnit();
608
      unit = val.GetUnit();
609
      gfxFontFaceSrc *face = srcArray.AppendElements(1);
609
      gfxFontFaceSrc* face = srcArray.AppendElements(1);
610
      if (!face)
610
      if (!face)
611
        return;
611
        return;
612
612
613
      switch (unit) {
613
      switch (unit) {
614
614
615
      case eCSSUnit_Local_Font:
615
      case eCSSUnit_Local_Font:
616
        val.GetStringValue(face->mLocalName);
616
        val.GetStringValue(face->mLocalName);
617
        face->mIsLocal = true;
617
        face->mIsLocal = true;
 Lines 684-730   nsUserFontSet::InsertRule(nsCSSFontFaceR Link Here 
684
      mRules.AppendElement(ruleRec);
684
      mRules.AppendElement(ruleRec);
685
    }
685
    }
686
    // this was a new rule and fontEntry, so note that the set was modified
686
    // this was a new rule and fontEntry, so note that the set was modified
687
    aFontSetModified = true;
687
    aFontSetModified = true;
688
  }
688
  }
689
}
689
}
690
690
691
void
691
void
692
nsUserFontSet::ReplaceFontEntry(gfxMixedFontFamily *aFamily,
692
nsUserFontSet::ReplaceFontEntry(gfxMixedFontFamily* aFamily,
693
                                gfxProxyFontEntry *aProxy,
693
                                gfxProxyFontEntry* aProxy,
694
                                gfxFontEntry *aFontEntry)
694
                                gfxFontEntry* aFontEntry)
695
{
695
{
696
  // aProxy is being supplanted by the "real" font aFontEntry, so we need to
696
  // aProxy is being supplanted by the "real" font aFontEntry, so we need to
697
  // update any rules that refer to it. Note that there may be multiple rules
697
  // update any rules that refer to it. Note that there may be multiple rules
698
  // that refer to the same proxy - e.g. if a stylesheet was loaded multiple
698
  // that refer to the same proxy - e.g. if a stylesheet was loaded multiple
699
  // times, so that several identical @font-face rules are present.
699
  // times, so that several identical @font-face rules are present.
700
  for (uint32_t i = 0; i < mRules.Length(); ++i) {
700
  for (uint32_t i = 0; i < mRules.Length(); ++i) {
701
    if (mRules[i].mFontEntry == aProxy) {
701
    if (mRules[i].mFontEntry == aProxy) {
702
      mRules[i].mFontEntry = aFontEntry;
702
      mRules[i].mFontEntry = aFontEntry;
703
    }
703
    }
704
  }
704
  }
705
  aFamily->ReplaceFontEntry(aProxy, aFontEntry);
705
  aFamily->ReplaceFontEntry(aProxy, aFontEntry);
706
}
706
}
707
707
708
nsCSSFontFaceRule*
708
nsCSSFontFaceRule*
709
nsUserFontSet::FindRuleForEntry(gfxFontEntry *aFontEntry)
709
nsUserFontSet::FindRuleForEntry(gfxFontEntry* aFontEntry)
710
{
710
{
711
  for (uint32_t i = 0; i < mRules.Length(); ++i) {
711
  for (uint32_t i = 0; i < mRules.Length(); ++i) {
712
    if (mRules[i].mFontEntry == aFontEntry) {
712
    if (mRules[i].mFontEntry == aFontEntry) {
713
      return mRules[i].mContainer.mRule;
713
      return mRules[i].mContainer.mRule;
714
    }
714
    }
715
  }
715
  }
716
  return nullptr;
716
  return nullptr;
717
}
717
}
718
718
719
nsresult
719
nsresult
720
nsUserFontSet::LogMessage(gfxMixedFontFamily *aFamily,
720
nsUserFontSet::LogMessage(gfxMixedFontFamily* aFamily,
721
                          gfxProxyFontEntry *aProxy,
721
                          gfxProxyFontEntry* aProxy,
722
                          const char        *aMessage,
722
                          const char*        aMessage,
723
                          uint32_t          aFlags,
723
                          uint32_t          aFlags,
724
                          nsresult          aStatus)
724
                          nsresult          aStatus)
725
{
725
{
726
  nsCOMPtr<nsIConsoleService>
726
  nsCOMPtr<nsIConsoleService>
727
    console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
727
    console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
728
  if (!console) {
728
  if (!console) {
729
    return NS_ERROR_NOT_AVAILABLE;
729
    return NS_ERROR_NOT_AVAILABLE;
730
  }
730
  }
 Lines 737-753   nsUserFontSet::LogMessage(gfxMixedFontFa Link Here 
737
    if (aProxy->mSrcList[aProxy->mSrcIndex].mURI) {
737
    if (aProxy->mSrcList[aProxy->mSrcIndex].mURI) {
738
      aProxy->mSrcList[aProxy->mSrcIndex].mURI->GetSpec(fontURI);
738
      aProxy->mSrcList[aProxy->mSrcIndex].mURI->GetSpec(fontURI);
739
    } else {
739
    } else {
740
      fontURI.AppendLiteral("(invalid URI)");
740
      fontURI.AppendLiteral("(invalid URI)");
741
    }
741
    }
742
  }
742
  }
743
743
744
  char weightKeywordBuf[8]; // plenty to sprintf() a uint16_t
744
  char weightKeywordBuf[8]; // plenty to sprintf() a uint16_t
745
  const char *weightKeyword;
745
  const char* weightKeyword;
746
  const nsAFlatCString& weightKeywordString =
746
  const nsAFlatCString& weightKeywordString =
747
    nsCSSProps::ValueToKeyword(aProxy->Weight(),
747
    nsCSSProps::ValueToKeyword(aProxy->Weight(),
748
                               nsCSSProps::kFontWeightKTable);
748
                               nsCSSProps::kFontWeightKTable);
749
  if (weightKeywordString.Length() > 0) {
749
  if (weightKeywordString.Length() > 0) {
750
    weightKeyword = weightKeywordString.get();
750
    weightKeyword = weightKeywordString.get();
751
  } else {
751
  } else {
752
    sprintf(weightKeywordBuf, "%u", aProxy->Weight());
752
    sprintf(weightKeywordBuf, "%u", aProxy->Weight());
753
    weightKeyword = weightKeywordBuf;
753
    weightKeyword = weightKeywordBuf;
 Lines 825-846   nsUserFontSet::LogMessage(gfxMixedFontFa Link Here 
825
  if (NS_SUCCEEDED(rv)) {
825
  if (NS_SUCCEEDED(rv)) {
826
    console->LogMessage(scriptError);
826
    console->LogMessage(scriptError);
827
  }
827
  }
828
828
829
  return NS_OK;
829
  return NS_OK;
830
}
830
}
831
831
832
nsresult
832
nsresult
833
nsUserFontSet::CheckFontLoad(const gfxFontFaceSrc *aFontFaceSrc,
833
nsUserFontSet::CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc,
834
                             nsIPrincipal **aPrincipal,
834
                             nsIPrincipal** aPrincipal,
835
                             bool *aBypassCache)
835
                             bool* aBypassCache)
836
{
836
{
837
  // check same-site origin
837
  // check same-site origin
838
  nsIPresShell *ps = mPresContext->PresShell();
838
  nsIPresShell* ps = mPresContext->PresShell();
839
  if (!ps)
839
  if (!ps)
840
    return NS_ERROR_FAILURE;
840
    return NS_ERROR_FAILURE;
841
841
842
  NS_ASSERTION(aFontFaceSrc && !aFontFaceSrc->mIsLocal,
842
  NS_ASSERTION(aFontFaceSrc && !aFontFaceSrc->mIsLocal,
843
               "bad font face url passed to fontloader");
843
               "bad font face url passed to fontloader");
844
  NS_ASSERTION(aFontFaceSrc->mURI, "null font uri");
844
  NS_ASSERTION(aFontFaceSrc->mURI, "null font uri");
845
  if (!aFontFaceSrc->mURI)
845
  if (!aFontFaceSrc->mURI)
846
    return NS_ERROR_FAILURE;
846
    return NS_ERROR_FAILURE;
 Lines 876-895   nsUserFontSet::CheckFontLoad(const gfxFo Link Here 
876
      }
876
      }
877
    }
877
    }
878
  }
878
  }
879
879
880
  return rv;
880
  return rv;
881
}
881
}
882
882
883
nsresult
883
nsresult
884
nsUserFontSet::SyncLoadFontData(gfxProxyFontEntry *aFontToLoad,
884
nsUserFontSet::SyncLoadFontData(gfxProxyFontEntry* aFontToLoad,
885
                                const gfxFontFaceSrc *aFontFaceSrc,
885
                                const gfxFontFaceSrc* aFontFaceSrc,
886
                                uint8_t* &aBuffer,
886
                                uint8_t*& aBuffer,
887
                                uint32_t &aBufferLength)
887
                                uint32_t& aBufferLength)
888
{
888
{
889
  nsresult rv;
889
  nsresult rv;
890
890
891
  nsCOMPtr<nsIChannel> channel;
891
  nsCOMPtr<nsIChannel> channel;
892
  // get Content Security Policy from principal to pass into channel
892
  // get Content Security Policy from principal to pass into channel
893
  nsCOMPtr<nsIChannelPolicy> channelPolicy;
893
  nsCOMPtr<nsIChannelPolicy> channelPolicy;
894
  nsCOMPtr<nsIContentSecurityPolicy> csp;
894
  nsCOMPtr<nsIContentSecurityPolicy> csp;
895
  rv = aFontToLoad->mPrincipal->GetCsp(getter_AddRefs(csp));
895
  rv = aFontToLoad->mPrincipal->GetCsp(getter_AddRefs(csp));
 Lines 960-976   nsUserFontSet::SyncLoadFontData(gfxProxy Link Here 
960
  }
960
  }
961
961
962
  return NS_OK;
962
  return NS_OK;
963
}
963
}
964
964
965
bool
965
bool
966
nsUserFontSet::GetPrivateBrowsing()
966
nsUserFontSet::GetPrivateBrowsing()
967
{
967
{
968
  nsIPresShell *ps = mPresContext->PresShell();
968
  nsIPresShell* ps = mPresContext->PresShell();
969
  if (!ps) {
969
  if (!ps) {
970
    return false;
970
    return false;
971
  }
971
  }
972
972
973
  nsCOMPtr<nsISupports> container = ps->GetDocument()->GetContainer();
973
  nsCOMPtr<nsISupports> container = ps->GetDocument()->GetContainer();
974
  if (!container) {
974
  if (!container) {
975
    return false;
975
    return false;
976
  }
976
  }
(-)a/layout/style/nsFontFaceLoader.h (-28 / +28 lines)
Line     Link Here 
 Lines 21-134   class nsPresContext; Link Here 
21
class nsIPrincipal;
21
class nsIPrincipal;
22
22
23
class nsFontFaceLoader;
23
class nsFontFaceLoader;
24
24
25
// nsUserFontSet - defines the loading mechanism for downloadable fonts
25
// nsUserFontSet - defines the loading mechanism for downloadable fonts
26
class nsUserFontSet : public gfxUserFontSet
26
class nsUserFontSet : public gfxUserFontSet
27
{
27
{
28
public:
28
public:
29
  nsUserFontSet(nsPresContext *aContext);
29
  nsUserFontSet(nsPresContext* aContext);
30
  ~nsUserFontSet();
30
  ~nsUserFontSet();
31
31
32
  // Called when this font set is no longer associated with a presentation.
32
  // Called when this font set is no longer associated with a presentation.
33
  void Destroy();
33
  void Destroy();
34
34
35
  // starts loading process, creating and initializing a nsFontFaceLoader obj
35
  // starts loading process, creating and initializing a nsFontFaceLoader obj
36
  // returns whether load process successfully started or not
36
  // returns whether load process successfully started or not
37
  nsresult StartLoad(gfxMixedFontFamily *aFamily,
37
  nsresult StartLoad(gfxMixedFontFamily* aFamily,
38
                     gfxProxyFontEntry *aFontToLoad,
38
                     gfxProxyFontEntry* aFontToLoad,
39
                     const gfxFontFaceSrc *aFontFaceSrc);
39
                     const gfxFontFaceSrc* aFontFaceSrc);
40
40
41
  // Called by nsFontFaceLoader when the loader has completed normally.
41
  // Called by nsFontFaceLoader when the loader has completed normally.
42
  // It's removed from the mLoaders set.
42
  // It's removed from the mLoaders set.
43
  void RemoveLoader(nsFontFaceLoader *aLoader);
43
  void RemoveLoader(nsFontFaceLoader* aLoader);
44
44
45
  bool UpdateRules(const nsTArray<nsFontFaceRuleContainer>& aRules);
45
  bool UpdateRules(const nsTArray<nsFontFaceRuleContainer>& aRules);
46
46
47
  nsPresContext *GetPresContext() { return mPresContext; }
47
  nsPresContext* GetPresContext() { return mPresContext; }
48
48
49
  virtual void ReplaceFontEntry(gfxMixedFontFamily *aFamily,
49
  virtual void ReplaceFontEntry(gfxMixedFontFamily* aFamily,
50
                                gfxProxyFontEntry *aProxy,
50
                                gfxProxyFontEntry* aProxy,
51
                                gfxFontEntry *aFontEntry);
51
                                gfxFontEntry* aFontEntry);
52
52
53
  nsCSSFontFaceRule *FindRuleForEntry(gfxFontEntry *aFontEntry);
53
  nsCSSFontFaceRule* FindRuleForEntry(gfxFontEntry* aFontEntry);
54
54
55
protected:
55
protected:
56
  // The font-set keeps track of the collection of rules, and their
56
  // The font-set keeps track of the collection of rules, and their
57
  // corresponding font entries (whether proxies or real entries),
57
  // corresponding font entries (whether proxies or real entries),
58
  // so that we can update the set without having to throw away
58
  // so that we can update the set without having to throw away
59
  // all the existing fonts.
59
  // all the existing fonts.
60
  struct FontFaceRuleRecord {
60
  struct FontFaceRuleRecord {
61
    nsRefPtr<gfxFontEntry>       mFontEntry;
61
    nsRefPtr<gfxFontEntry>       mFontEntry;
62
    nsFontFaceRuleContainer      mContainer;
62
    nsFontFaceRuleContainer      mContainer;
63
  };
63
  };
64
64
65
  void InsertRule(nsCSSFontFaceRule *aRule, uint8_t aSheetType,
65
  void InsertRule(nsCSSFontFaceRule* aRule, uint8_t aSheetType,
66
                  nsTArray<FontFaceRuleRecord>& oldRules,
66
                  nsTArray<FontFaceRuleRecord>& oldRules,
67
                  bool& aFontSetModified);
67
                  bool& aFontSetModified);
68
68
69
  virtual nsresult LogMessage(gfxMixedFontFamily *aFamily,
69
  virtual nsresult LogMessage(gfxMixedFontFamily* aFamily,
70
                              gfxProxyFontEntry *aProxy,
70
                              gfxProxyFontEntry* aProxy,
71
                              const char *aMessage,
71
                              const char* aMessage,
72
                              uint32_t aFlags = nsIScriptError::errorFlag,
72
                              uint32_t aFlags = nsIScriptError::errorFlag,
73
                              nsresult aStatus = NS_OK);
73
                              nsresult aStatus = NS_OK);
74
74
75
  virtual nsresult CheckFontLoad(const gfxFontFaceSrc *aFontFaceSrc,
75
  virtual nsresult CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc,
76
                                 nsIPrincipal **aPrincipal,
76
                                 nsIPrincipal** aPrincipal,
77
                                 bool *aBypassCache);
77
                                 bool* aBypassCache);
78
78
79
  virtual nsresult SyncLoadFontData(gfxProxyFontEntry *aFontToLoad,
79
  virtual nsresult SyncLoadFontData(gfxProxyFontEntry* aFontToLoad,
80
                                    const gfxFontFaceSrc *aFontFaceSrc,
80
                                    const gfxFontFaceSrc* aFontFaceSrc,
81
                                    uint8_t* &aBuffer,
81
                                    uint8_t*& aBuffer,
82
                                    uint32_t &aBufferLength);
82
                                    uint32_t& aBufferLength);
83
83
84
  virtual bool GetPrivateBrowsing() MOZ_OVERRIDE;
84
  virtual bool GetPrivateBrowsing() MOZ_OVERRIDE;
85
85
86
  nsPresContext *mPresContext;  // weak reference
86
  nsPresContext* mPresContext;  // weak reference
87
87
88
  // Set of all loaders pointing to us. These are not strong pointers,
88
  // Set of all loaders pointing to us. These are not strong pointers,
89
  // but that's OK because nsFontFaceLoader always calls RemoveLoader on
89
  // but that's OK because nsFontFaceLoader always calls RemoveLoader on
90
  // us before it dies (unless we die first).
90
  // us before it dies (unless we die first).
91
  nsTHashtable< nsPtrHashKey<nsFontFaceLoader> > mLoaders;
91
  nsTHashtable< nsPtrHashKey<nsFontFaceLoader> > mLoaders;
92
92
93
  nsTArray<FontFaceRuleRecord>   mRules;
93
  nsTArray<FontFaceRuleRecord>   mRules;
94
};
94
};
95
95
96
class nsFontFaceLoader : public nsIStreamLoaderObserver
96
class nsFontFaceLoader : public nsIStreamLoaderObserver
97
{
97
{
98
public:
98
public:
99
  nsFontFaceLoader(gfxMixedFontFamily *aFontFamily,
99
  nsFontFaceLoader(gfxMixedFontFamily* aFontFamily,
100
                   gfxProxyFontEntry *aFontToLoad, nsIURI *aFontURI, 
100
                   gfxProxyFontEntry* aFontToLoad, nsIURI* aFontURI, 
101
                   nsUserFontSet *aFontSet, nsIChannel *aChannel);
101
                   nsUserFontSet* aFontSet, nsIChannel* aChannel);
102
102
103
  virtual ~nsFontFaceLoader();
103
  virtual ~nsFontFaceLoader();
104
104
105
  NS_DECL_ISUPPORTS
105
  NS_DECL_ISUPPORTS
106
  NS_DECL_NSISTREAMLOADEROBSERVER 
106
  NS_DECL_NSISTREAMLOADEROBSERVER 
107
107
108
  // initiate the load
108
  // initiate the load
109
  nsresult Init();
109
  nsresult Init();
110
  // cancel the load and remove its reference to mFontSet
110
  // cancel the load and remove its reference to mFontSet
111
  void Cancel();
111
  void Cancel();
112
112
113
  void DropChannel() { mChannel = nullptr; }
113
  void DropChannel() { mChannel = nullptr; }
114
114
115
  void StartedLoading(nsIStreamLoader *aStreamLoader);
115
  void StartedLoading(nsIStreamLoader* aStreamLoader);
116
116
117
  static void LoadTimerCallback(nsITimer *aTimer, void *aClosure);
117
  static void LoadTimerCallback(nsITimer* aTimer, void* aClosure);
118
118
119
  static nsresult CheckLoadAllowed(nsIPrincipal* aSourcePrincipal,
119
  static nsresult CheckLoadAllowed(nsIPrincipal* aSourcePrincipal,
120
                                   nsIURI* aTargetURI,
120
                                   nsIURI* aTargetURI,
121
                                   nsISupports* aContext);
121
                                   nsISupports* aContext);
122
122
123
private:
123
private:
124
  nsRefPtr<gfxMixedFontFamily> mFontFamily;
124
  nsRefPtr<gfxMixedFontFamily> mFontFamily;
125
  nsRefPtr<gfxProxyFontEntry>  mFontEntry;
125
  nsRefPtr<gfxProxyFontEntry>  mFontEntry;
126
  nsCOMPtr<nsIURI>        mFontURI;
126
  nsCOMPtr<nsIURI>        mFontURI;
127
  nsRefPtr<nsUserFontSet> mFontSet;
127
  nsRefPtr<nsUserFontSet> mFontSet;
128
  nsCOMPtr<nsIChannel>    mChannel;
128
  nsCOMPtr<nsIChannel>    mChannel;
129
  nsCOMPtr<nsITimer>      mLoadTimer;
129
  nsCOMPtr<nsITimer>      mLoadTimer;
130
130
131
  nsIStreamLoader        *mStreamLoader;
131
  nsIStreamLoader*        mStreamLoader;
132
};
132
};
133
133
134
#endif /* !defined(nsFontFaceLoader_h_) */
134
#endif /* !defined(nsFontFaceLoader_h_) */

Return to bug 906852