Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: chrome/renderer/extensions/notifications_native_handler.cc

Issue 2937543002: [Extensions] Use gin::DataObjectBuilder in NotificationsNativeHandler (Closed)
Patch Set: . Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/extensions/notifications_native_handler.h" 5 #include "chrome/renderer/extensions/notifications_native_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/common/extensions/api/notifications/notification_style.h" 12 #include "chrome/common/extensions/api/notifications/notification_style.h"
13 #include "content/public/child/v8_value_converter.h"
14 #include "extensions/renderer/script_context.h" 13 #include "extensions/renderer/script_context.h"
14 #include "gin/data_object_builder.h"
15 #include "ui/base/layout.h" 15 #include "ui/base/layout.h"
16 16
17 namespace extensions { 17 namespace extensions {
18 18
19 NotificationsNativeHandler::NotificationsNativeHandler(ScriptContext* context) 19 NotificationsNativeHandler::NotificationsNativeHandler(ScriptContext* context)
20 : ObjectBackedNativeHandler(context) { 20 : ObjectBackedNativeHandler(context) {
21 RouteFunction( 21 RouteFunction(
22 "GetNotificationImageSizes", "notifications", 22 "GetNotificationImageSizes", "notifications",
23 base::Bind(&NotificationsNativeHandler::GetNotificationImageSizes, 23 base::Bind(&NotificationsNativeHandler::GetNotificationImageSizes,
24 base::Unretained(this))); 24 base::Unretained(this)));
25 } 25 }
26 26
27 void NotificationsNativeHandler::GetNotificationImageSizes( 27 void NotificationsNativeHandler::GetNotificationImageSizes(
28 const v8::FunctionCallbackInfo<v8::Value>& args) { 28 const v8::FunctionCallbackInfo<v8::Value>& args) {
29 NotificationBitmapSizes bitmap_sizes = GetNotificationBitmapSizes(); 29 NotificationBitmapSizes bitmap_sizes = GetNotificationBitmapSizes();
30 30
31 float scale_factor = 31 float scale_factor =
32 ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactors().back()); 32 ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactors().back());
33 33
34 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 34 v8::Isolate* isolate = GetIsolate();
35 dict->SetDouble("scaleFactor", scale_factor); 35 v8::HandleScope handle_scope(isolate);
36 dict->SetInteger("icon.width", bitmap_sizes.icon_size.width());
37 dict->SetInteger("icon.height", bitmap_sizes.icon_size.height());
38 dict->SetInteger("image.width", bitmap_sizes.image_size.width());
39 dict->SetInteger("image.height", bitmap_sizes.image_size.height());
40 dict->SetInteger("buttonIcon.width", bitmap_sizes.button_icon_size.width());
41 dict->SetInteger("buttonIcon.height", bitmap_sizes.button_icon_size.height());
42 dict->SetInteger("appIconMask.width",
43 bitmap_sizes.app_icon_mask_size.width());
44 dict->SetInteger("appIconMask.height",
45 bitmap_sizes.app_icon_mask_size.height());
46 36
47 std::unique_ptr<content::V8ValueConverter> converter( 37 struct {
48 content::V8ValueConverter::create()); 38 const char* key;
49 args.GetReturnValue().Set( 39 const gfx::Size& size;
50 converter->ToV8Value(dict.get(), context()->v8_context())); 40 } entries[] = {
41 {"icon", bitmap_sizes.icon_size},
42 {"image", bitmap_sizes.image_size},
43 {"buttonIcon", bitmap_sizes.button_icon_size},
44 {"appIconMask", bitmap_sizes.app_icon_mask_size},
45 };
46
47 gin::DataObjectBuilder builder(isolate);
48 builder.Set("scaleFactor", scale_factor);
49 for (const auto& entry : entries) {
50 builder.Set(entry.key, gin::DataObjectBuilder(isolate)
51 .Set("width", entry.size.width())
52 .Set("height", entry.size.height())
53 .Build());
54 }
55
56 args.GetReturnValue().Set(builder.Build());
51 } 57 }
52 58
53 } // namespace extensions 59 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698