Global Metrics

path: .metrics.loc.cloc
old: 10.0
new: 33.0

path: .metrics.loc.ploc
old: 20.0
new: 315.0

path: .metrics.loc.lloc
old: 6.0
new: 142.0

path: .metrics.loc.sloc
old: 35.0
new: 437.0

path: .metrics.loc.blank
old: 5.0
new: 89.0

path: .metrics.cyclomatic.average
old: 1.0
new: 2.4242424242424243

path: .metrics.cyclomatic.sum
old: 2.0
new: 80.0

path: .metrics.halstead.estimated_program_length
old: 88.71062275542812
new: 1852.571755001392

path: .metrics.halstead.N2
old: 35.0
new: 568.0

path: .metrics.halstead.length
old: 65.0
new: 1385.0

path: .metrics.halstead.n1
old: 4.0
new: 26.0

path: .metrics.halstead.effort
old: 1083.2740473715478
new: 366424.7432203464

path: .metrics.halstead.level
old: 0.2714285714285714
new: 0.030065005417118092

path: .metrics.halstead.n2
old: 19.0
new: 222.0

path: .metrics.halstead.volume
old: 294.03152714370583
new: 11016.56188988582

path: .metrics.halstead.purity_ratio
old: 1.364778811621971
new: 1.3375969350190555

path: .metrics.halstead.bugs
old: 0.03515909094824921
new: 1.7068758748090724

path: .metrics.halstead.difficulty
old: 3.6842105263157894
new: 33.26126126126126

path: .metrics.halstead.N1
old: 30.0
new: 817.0

path: .metrics.halstead.vocabulary
old: 23.0
new: 248.0

path: .metrics.halstead.time
old: 60.18189152064154
new: 20356.930178908133

path: .metrics.nargs.average
old: 2.0
new: 1.2142857142857142

path: .metrics.nargs.sum
old: 2.0
new: 34.0

path: .metrics.mi.mi_visual_studio
old: 48.76502281909749
new: 3.337939181996685

path: .metrics.mi.mi_original
old: 83.3881890206567
new: 5.707876001214331

path: .metrics.mi.mi_sei
old: 81.63818207774861
new: -38.67180506653963

path: .metrics.cognitive.sum
old: 0.0
new: 58.0

path: .metrics.cognitive.average
old: 0.0
new: 2.0714285714285716

path: .metrics.nom.functions
old: 1.0
new: 28.0

path: .metrics.nom.total
old: 1.0
new: 28.0

path: .metrics.nexits.average
old: 0.0
new: 1.8571428571428572

path: .metrics.nexits.sum
old: 0.0
new: 52.0

Spaces Data

Minimal test - lines (39, 167)

path: .spaces[0].metrics.nargs.average
old: 2.0
new: 1.1538461538461535

path: .spaces[0].metrics.nargs.sum
old: 2.0
new: 15.0

path: .spaces[0].metrics.halstead.effort
old: 908.685381950068
new: 56911.700751818695

path: .spaces[0].metrics.halstead.n1
old: 4.0
new: 21.0

path: .spaces[0].metrics.halstead.N2
old: 29.0
new: 169.0

path: .spaces[0].metrics.halstead.level
old: 0.27586206896551724
new: 0.04959143420681882

path: .spaces[0].metrics.halstead.time
old: 50.482521219448216
new: 3161.7611528788166

path: .spaces[0].metrics.halstead.n2
old: 16.0
new: 88.0

path: .spaces[0].metrics.halstead.volume
old: 250.67182950346705
new: 2822.3328634319782

path: .spaces[0].metrics.halstead.bugs
old: 0.031271912314717605
new: 0.49318870458383707

path: .spaces[0].metrics.halstead.purity_ratio
old: 1.2413793103448276
new: 1.5843372861353386

path: .spaces[0].metrics.halstead.N1
old: 29.0
new: 248.0

path: .spaces[0].metrics.halstead.length
old: 58.0
new: 417.0

path: .spaces[0].metrics.halstead.difficulty
old: 3.625
new: 20.164772727272727

path: .spaces[0].metrics.halstead.estimated_program_length
old: 72.0
new: 660.6686483184362

path: .spaces[0].metrics.halstead.vocabulary
old: 20.0
new: 109.0

path: .spaces[0].metrics.cognitive.sum
old: 0.0
new: 9.0

path: .spaces[0].metrics.cognitive.average
old: 0.0
new: 0.6923076923076923

path: .spaces[0].metrics.mi.mi_original
old: 97.12851061595178
new: 45.20537984124371

path: .spaces[0].metrics.mi.mi_sei
old: 64.5277884619564
new: 1.6473763733378617

path: .spaces[0].metrics.mi.mi_visual_studio
old: 56.800298605819755
new: 26.435894644002172

path: .spaces[0].metrics.cyclomatic.sum
old: 1.0
new: 25.0

path: .spaces[0].metrics.cyclomatic.average
old: 1.0
new: 1.6666666666666667

path: .spaces[0].metrics.nom.functions
old: 1.0
new: 13.0

path: .spaces[0].metrics.nom.total
old: 1.0
new: 13.0

path: .spaces[0].metrics.nexits.average
old: 0.0
new: 1.3076923076923077

path: .spaces[0].metrics.nexits.sum
old: 0.0
new: 17.0

path: .spaces[0].metrics.loc.cloc
old: 0.0
new: 2.0

path: .spaces[0].metrics.loc.ploc
old: 15.0
new: 97.0

path: .spaces[0].metrics.loc.lloc
old: 6.0
new: 41.0

path: .spaces[0].metrics.loc.sloc
old: 16.0
new: 129.0

path: .spaces[0].metrics.loc.blank
old: 1.0
new: 30.0

Code

namespace {

HWND GetHWNDFromDocShell(nsIDocShell* aShell) {
  nsCOMPtr baseWindow(
      do_QueryInterface(reinterpret_cast(aShell)));

  if (!baseWindow) return nullptr;

  nsCOMPtr widget;
  baseWindow->GetMainWidget(getter_AddRefs(widget));

  return widget ? (HWND)widget->GetNativeData(NS_NATIVE_WINDOW) : nullptr;
}

HWND GetHWNDFromDOMWindow(mozIDOMWindow* dw) {
  nsCOMPtr widget;

  if (!dw) return nullptr;

  nsCOMPtr window = nsPIDOMWindowInner::From(dw);
  return GetHWNDFromDocShell(window->GetDocShell());
}

nsresult SetWindowAppUserModelProp(mozIDOMWindow* aParent,
                                   const nsString& aIdentifier) {
  NS_ENSURE_ARG_POINTER(aParent);

  if (aIdentifier.IsEmpty()) return NS_ERROR_INVALID_ARG;

  HWND toplevelHWND = ::GetAncestor(GetHWNDFromDOMWindow(aParent), GA_ROOT);

  if (!toplevelHWND) return NS_ERROR_INVALID_ARG;

  RefPtr pPropStore;
  if (FAILED(SHGetPropertyStoreForWindow(toplevelHWND, IID_IPropertyStore,
                                         getter_AddRefs(pPropStore)))) {
    return NS_ERROR_INVALID_ARG;
  }

  PROPVARIANT pv;
  if (FAILED(InitPropVariantFromString(aIdentifier.get(), &pv))) {
    return NS_ERROR_UNEXPECTED;
  }

  nsresult rv = NS_OK;
  if (FAILED(pPropStore->SetValue(PKEY_AppUserModel_ID, pv)) ||
      FAILED(pPropStore->Commit())) {
    rv = NS_ERROR_FAILURE;
  }

  PropVariantClear(&pv);

  return rv;
}

///////////////////////////////////////////////////////////////////////////////
// default nsITaskbarPreviewController

class DefaultController final : public nsITaskbarPreviewController {
  ~DefaultController() {}
  HWND mWnd;

 public:
  explicit DefaultController(HWND hWnd) : mWnd(hWnd) {}

  NS_DECL_ISUPPORTS
  NS_DECL_NSITASKBARPREVIEWCONTROLLER
};

NS_IMETHODIMP
DefaultController::GetWidth(uint32_t* aWidth) {
  RECT r;
  ::GetClientRect(mWnd, &r);
  *aWidth = r.right;
  return NS_OK;
}

NS_IMETHODIMP
DefaultController::GetHeight(uint32_t* aHeight) {
  RECT r;
  ::GetClientRect(mWnd, &r);
  *aHeight = r.bottom;
  return NS_OK;
}

NS_IMETHODIMP
DefaultController::GetThumbnailAspectRatio(float* aThumbnailAspectRatio) {
  uint32_t width, height;
  GetWidth(&width);
  GetHeight(&height);
  if (!height) height = 1;

  *aThumbnailAspectRatio = width / float(height);
  return NS_OK;
}

NS_IMETHODIMP
DefaultController::RequestThumbnail(nsITaskbarPreviewCallback* aCallback,
                                    uint32_t width, uint32_t height) {
  return NS_OK;
}

NS_IMETHODIMP
DefaultController::RequestPreview(nsITaskbarPreviewCallback* aCallback) {
  return NS_OK;
}

NS_IMETHODIMP
DefaultController::OnClose(void) {
  MOZ_ASSERT_UNREACHABLE(
      "OnClose should not be called for "
      "TaskbarWindowPreviews");
  return NS_OK;
}

NS_IMETHODIMP
DefaultController::OnActivate(bool* rAcceptActivation) {
  *rAcceptActivation = true;
  MOZ_ASSERT_UNREACHABLE(
      "OnActivate should not be called for "
      "TaskbarWindowPreviews");
  return NS_OK;
}

NS_IMETHODIMP
DefaultController::OnClick(nsITaskbarPreviewButton* button) { return NS_OK; }

NS_IMPL_ISUPPORTS(DefaultController, nsITaskbarPreviewController)
}  // namespace