forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnotifications_native_handler.cc
53 lines (43 loc) · 2.08 KB
/
notifications_native_handler.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/renderer/extensions/notifications_native_handler.h"
#include <memory>
#include <string>
#include "base/logging.h"
#include "base/values.h"
#include "chrome/common/extensions/api/notifications/notification_style.h"
#include "content/public/child/v8_value_converter.h"
#include "extensions/renderer/script_context.h"
#include "ui/base/layout.h"
namespace extensions {
NotificationsNativeHandler::NotificationsNativeHandler(ScriptContext* context)
: ObjectBackedNativeHandler(context) {
RouteFunction(
"GetNotificationImageSizes", "notifications",
base::Bind(&NotificationsNativeHandler::GetNotificationImageSizes,
base::Unretained(this)));
}
void NotificationsNativeHandler::GetNotificationImageSizes(
const v8::FunctionCallbackInfo<v8::Value>& args) {
NotificationBitmapSizes bitmap_sizes = GetNotificationBitmapSizes();
float scale_factor =
ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactors().back());
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
dict->SetDouble("scaleFactor", scale_factor);
dict->SetInteger("icon.width", bitmap_sizes.icon_size.width());
dict->SetInteger("icon.height", bitmap_sizes.icon_size.height());
dict->SetInteger("image.width", bitmap_sizes.image_size.width());
dict->SetInteger("image.height", bitmap_sizes.image_size.height());
dict->SetInteger("buttonIcon.width", bitmap_sizes.button_icon_size.width());
dict->SetInteger("buttonIcon.height", bitmap_sizes.button_icon_size.height());
dict->SetInteger("appIconMask.width",
bitmap_sizes.app_icon_mask_size.width());
dict->SetInteger("appIconMask.height",
bitmap_sizes.app_icon_mask_size.height());
std::unique_ptr<content::V8ValueConverter> converter(
content::V8ValueConverter::create());
args.GetReturnValue().Set(
converter->ToV8Value(dict.get(), context()->v8_context()));
}
} // namespace extensions