36b7cf341e
* chore: bump chromium in DEPS to 131.0.6763.0
* chore: bump chromium in DEPS to 131.0.6764.0
* update patches
* chore: bump chromium in DEPS to 131.0.6766.0
* chore: update patches
* Use PathInfo in FileSystemAccess code
Refs https://chromium-review.googlesource.com/c/chromium/src/+/5872329
* Modernize image utilities.
Refs https://chromium-review.googlesource.com/c/chromium/src/+/5905226
* [DevTools] move feature flags to the devtools directory
Refs https://chromium-review.googlesource.com/c/chromium/src/+/5913878
* chore: bump chromium in DEPS to 131.0.6768.0
* chore: update patches
* Remove experimental credshelper flags
Refs 4017a6c8b4
* Change gfx::[PNG|JPEG]Codec::Decode to return a SkBitmap
Refs https://chromium-review.googlesource.com/c/chromium/src/+/5917286
Refs https://chromium-review.googlesource.com/c/chromium/src/+/5905621
* chore: script/gen-libc++-filenames.js
* chore: bump chromium in DEPS to 131.0.6770.0
* chore: update patches
* chore: bump chromium in DEPS to 131.0.6772.0
* chore: update patches
* [UI] Add alias for mojo version of `MenuSourceType`
Refs https://chromium-review.googlesource.com/c/chromium/src/+/5803393
* Update Background Color for Task Manager Refresh
Refs https://chromium-review.googlesource.com/c/chromium/src/+/5875259
* chore: bump chromium in DEPS to 131.0.6774.0
* chore: bump chromium in DEPS to 131.0.6776.0
* chore: update patches
* chore: update filenames.libcxx.gni
* esm: remove --no-import-harmony-assertions
https://github.com/nodejs/node/pull/54890
* 5507047: [import-attributes] Remove support for import assertions
| https://chromium-review.googlesource.com/c/v8/v8/+/5507047
* fixup: Change gfx::[PNG|JPEG]Codec::Decode to return a SkBitmap
* chore: bump chromium in DEPS to 131.0.6778.0
* Revert "chore: bump chromium in DEPS to 131.0.6778.0"
This reverts commit fb9092fc51700651aa4a245931f71ec1ca55a274.
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Jeremy Rose <nornagon@electronjs.org>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
94 lines
2.8 KiB
C++
94 lines
2.8 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/environment.h"
|
|
#include "base/files/file_util.h"
|
|
#include "base/hash/md5.h"
|
|
#include "base/logging.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 IsDebuggingNotifications() {
|
|
return base::Environment::Create()->HasVar("ELECTRON_DEBUG_NOTIFICATIONS");
|
|
}
|
|
|
|
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())
|
|
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 (IsDebuggingNotifications())
|
|
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) {
|
|
std::string filename;
|
|
|
|
if (origin.is_valid()) {
|
|
filename = base::MD5String(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 (base::PathExists(path))
|
|
return path.value();
|
|
if (SaveIconToPath(icon, path))
|
|
return path.value();
|
|
return base::UTF8ToWide(origin.spec());
|
|
}
|
|
|
|
Notification* NotificationPresenterWin::CreateNotificationObject(
|
|
NotificationDelegate* delegate) {
|
|
return new WindowsToastNotification(delegate, this);
|
|
}
|
|
|
|
} // namespace electron
|