mirror of
https://github.com/electron/electron.git
synced 2026-01-06 22:24:03 -05:00
* chore: bump chromium in DEPS to 144.0.7507.0
* chore: bump chromium in DEPS to 144.0.7508.0
* chore: update patches
* 7101838: [pathbuilder] Enforce immutable SkPath APIs globally
https://chromium-review.googlesource.com/c/chromium/src/+/7101838
* chore: update filenames.libcxx.gni
* [pathbuilder] Enforce immutable SkPath APIs globally
https://chromium-review.googlesource.com/c/chromium/src/+/7101838
* Reduce service_worker_info.h includes in headers
https://chromium-review.googlesource.com/c/chromium/src/+/7108401
* chore: bump chromium in DEPS to 144.0.7510.0
* chore: update patches
* Use internal popup menus for tabs in actor-controlled states
https://chromium-review.googlesource.com/c/chromium/src/+/7074751
* [api] Delete deprecated fields on v8::Isolate
https://chromium-review.googlesource.com/c/v8/v8/+/7081397
xref: 98d243aea0
* Fixup Reduce service_worker_info.h includes in headers
* Promote deprecation of v8::Context and v8::Object API methods
https://chromium-review.googlesource.com/c/v8/v8/+/7087956
* fixup Promote deprecation of v8::Context and v8::Object API methods
* chore: bump chromium in DEPS to 144.0.7512.1
* chore: update patches
* fixup [pathbuilder] Enforce immutable SkPath APIs global
* chore: update filenames.hunspell.gni
* fix deprecation of v8::Context and v8::Object API methods for nan
https://chromium-review.googlesource.com/c/v8/v8/+/7087956
* [PDF] Implement PdfHelpBubbleHandlerFactory
https://chromium-review.googlesource.com/c/chromium/src/+/7056325
also: [PDF Ink Signatures] Hook up IPH
https://chromium-review.googlesource.com/c/chromium/src/+/7056207
* Remove base/hash/md5.h
https://chromium-review.googlesource.com/c/chromium/src/+/7113738
* fixup for lint
* Remove deprecated interceptor callback types and AccessControl enum
https://chromium-review.googlesource.com/c/v8/v8/+/7112747
* fixup for lint
* fixup [PDF] Implement PdfHelpBubbleHandlerFactory
* use base::SHA1HashString instead of std::hash
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
92 lines
2.7 KiB
C++
92 lines
2.7 KiB
C++
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
// Copyright (c) 2015 Felix Rieseberg <feriese@microsoft.com> and
|
|
// Jason Poon <jason.poon@microsoft.com>. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE-CHROMIUM file.
|
|
|
|
#include "shell/browser/notifications/win/notification_presenter_win.h"
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "base/files/file_util.h"
|
|
#include "base/hash/sha1.h"
|
|
#include "base/logging.h"
|
|
#include "base/strings/string_number_conversions.h"
|
|
#include "base/strings/utf_string_conversions.h"
|
|
#include "base/time/time.h"
|
|
#include "shell/browser/notifications/win/windows_toast_notification.h"
|
|
#include "shell/common/thread_restrictions.h"
|
|
#include "third_party/skia/include/core/SkBitmap.h"
|
|
#include "ui/gfx/codec/png_codec.h"
|
|
|
|
#pragma comment(lib, "runtimeobject.lib")
|
|
|
|
namespace electron {
|
|
|
|
namespace {
|
|
|
|
bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) {
|
|
std::optional<std::vector<uint8_t>> png_data =
|
|
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false);
|
|
if (!png_data.has_value() || !png_data.value().size())
|
|
return false;
|
|
return base::WriteFile(path, png_data.value());
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// static
|
|
std::unique_ptr<NotificationPresenter> NotificationPresenter::Create() {
|
|
if (!WindowsToastNotification::Initialize())
|
|
return {};
|
|
auto presenter = std::make_unique<NotificationPresenterWin>();
|
|
if (!presenter->Init())
|
|
return {};
|
|
|
|
if (electron::debug_notifications)
|
|
LOG(INFO) << "Successfully created Windows notifications presenter";
|
|
|
|
return presenter;
|
|
}
|
|
|
|
NotificationPresenterWin::NotificationPresenterWin() = default;
|
|
|
|
NotificationPresenterWin::~NotificationPresenterWin() = default;
|
|
|
|
bool NotificationPresenterWin::Init() {
|
|
ScopedAllowBlockingForElectron allow_blocking;
|
|
return temp_dir_.CreateUniqueTempDir();
|
|
}
|
|
|
|
std::wstring NotificationPresenterWin::SaveIconToFilesystem(
|
|
const SkBitmap& icon,
|
|
const GURL& origin) {
|
|
if (icon.drawsNothing())
|
|
return L"";
|
|
|
|
std::string filename;
|
|
if (origin.is_valid()) {
|
|
filename = base::SHA1HashString(origin.spec()) + ".png";
|
|
} else {
|
|
const int64_t now_usec = base::Time::Now().since_origin().InMicroseconds();
|
|
filename = base::NumberToString(now_usec) + ".png";
|
|
}
|
|
|
|
ScopedAllowBlockingForElectron allow_blocking;
|
|
base::FilePath path = temp_dir_.GetPath().Append(base::UTF8ToWide(filename));
|
|
|
|
if (!SaveIconToPath(icon, path))
|
|
return L"";
|
|
|
|
return path.value();
|
|
}
|
|
|
|
Notification* NotificationPresenterWin::CreateNotificationObject(
|
|
NotificationDelegate* delegate) {
|
|
return new WindowsToastNotification(delegate, this);
|
|
}
|
|
|
|
} // namespace electron
|