1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/renderer/extensions/notifications_native_handler.h"
9 #include "base/logging.h"
10 #include "base/values.h"
11 #include "chrome/common/extensions/api/notifications/notification_style.h"
12 #include "content/public/child/v8_value_converter.h"
13 #include "extensions/renderer/script_context.h"
14 #include "ui/base/layout.h"
16 namespace extensions
{
18 NotificationsNativeHandler::NotificationsNativeHandler(ScriptContext
* context
)
19 : ObjectBackedNativeHandler(context
) {
21 "GetNotificationImageSizes",
22 base::Bind(&NotificationsNativeHandler::GetNotificationImageSizes
,
23 base::Unretained(this)));
26 void NotificationsNativeHandler::GetNotificationImageSizes(
27 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
28 NotificationBitmapSizes bitmap_sizes
= GetNotificationBitmapSizes();
31 ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactors().back());
33 scoped_ptr
<base::DictionaryValue
> dict(new base::DictionaryValue
);
34 dict
->SetDouble("scaleFactor", scale_factor
);
35 dict
->SetInteger("icon.width", bitmap_sizes
.icon_size
.width());
36 dict
->SetInteger("icon.height", bitmap_sizes
.icon_size
.height());
37 dict
->SetInteger("image.width", bitmap_sizes
.image_size
.width());
38 dict
->SetInteger("image.height", bitmap_sizes
.image_size
.height());
39 dict
->SetInteger("buttonIcon.width", bitmap_sizes
.button_icon_size
.width());
40 dict
->SetInteger("buttonIcon.height", bitmap_sizes
.button_icon_size
.height());
41 dict
->SetInteger("appIconMask.width",
42 bitmap_sizes
.app_icon_mask_size
.width());
43 dict
->SetInteger("appIconMask.height",
44 bitmap_sizes
.app_icon_mask_size
.height());
46 scoped_ptr
<content::V8ValueConverter
> converter(
47 content::V8ValueConverter::create());
48 args
.GetReturnValue().Set(
49 converter
->ToV8Value(dict
.get(), context()->v8_context()));
52 } // namespace extensions