OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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. | |
4 | |
5 cr.exportPath('settings'); | |
6 | |
7 /** | |
8 * An object describing a default image. | |
9 * @typedef {{ | |
10 * author: string, | |
11 * title: string, | |
12 * url: string, | |
13 * website: string | |
14 * }} | |
15 */ | |
16 settings.DefaultImage; | |
17 | |
18 cr.define('settings', function() { | |
19 /** | |
20 * API which encapsulates messaging between JS and C++ for the ChromeOS | |
21 * Change Picture subpage. | |
22 * @constructor | |
23 */ | |
24 function ChangePicturePrivateApi() {} | |
dpapad
2016/01/11 19:25:50
How about instantiating an object from this class,
tommycli
2016/01/13 18:29:11
Done. Based on your examples, I was able to elimin
| |
25 | |
26 /** | |
27 * URLs of special button images. | |
28 * @enum {string} | |
29 */ | |
30 ChangePicturePrivateApi.ButtonImages = { | |
31 TAKE_PHOTO: 'chrome://theme/IDR_BUTTON_USER_IMAGE_TAKE_PHOTO', | |
32 CHOOSE_FILE: 'chrome://theme/IDR_BUTTON_USER_IMAGE_CHOOSE_FILE', | |
33 PROFILE_PICTURE: 'chrome://theme/IDR_PROFILE_PICTURE_LOADING' | |
34 }; | |
35 | |
36 /** @private {?function(!Array<settings.DefaultImage>)} */ | |
37 ChangePicturePrivateApi.getDefaultImagesCallback_ = null; | |
38 | |
39 /** @private {?function(string)} */ | |
40 ChangePicturePrivateApi.getSelectedImageUrlCallback_ = null; | |
41 | |
42 /** @private {?function(string)} */ | |
43 ChangePicturePrivateApi.getOldImageUrlCallback_ = null; | |
44 | |
45 /** @private {?function(string, boolean)} */ | |
46 ChangePicturePrivateApi.getProfileImageUrlCallback_ = null; | |
47 | |
48 /** | |
49 * Called from JavaScript. Initializes page by setting callbacks and | |
50 * retrieving the initial set of default images, profile image, etc. | |
51 * @param {!function(!Array<settings.DefaultImage>)} getDefaultImagesCallback | |
52 * @param {!function(string)} getSelectedImageUrlCallback | |
53 * @param {!function(string)} getOldImageUrlCallback | |
54 * @param {!function(string, boolean)} getProfileImageUrlCallback | |
55 */ | |
56 ChangePicturePrivateApi.initialize = function( | |
57 getDefaultImagesCallback, | |
58 getSelectedImageUrlCallback, | |
59 getOldImageUrlCallback, | |
60 getProfileImageUrlCallback) { | |
61 ChangePicturePrivateApi.getDefaultImagesCallback_ = | |
62 getDefaultImagesCallback; | |
63 ChangePicturePrivateApi.getSelectedImageUrlCallback_ = | |
64 getSelectedImageUrlCallback; | |
65 ChangePicturePrivateApi.getOldImageUrlCallback_ = getOldImageUrlCallback; | |
66 ChangePicturePrivateApi.getProfileImageUrlCallback_ = | |
67 getProfileImageUrlCallback; | |
68 chrome.send('onChangePicturePageInitialized'); | |
69 }; | |
70 | |
71 /** | |
72 * Called from C++ to provide the default set of images. | |
73 * @param {!Array<settings.DefaultImage>} images An array of default images. | |
74 */ | |
75 ChangePicturePrivateApi.receiveDefaultImages = function(images) { | |
76 if (ChangePicturePrivateApi.getDefaultImagesCallback_) | |
77 ChangePicturePrivateApi.getDefaultImagesCallback_(images); | |
78 }; | |
79 | |
80 /** | |
81 * Called from C++ to provide the URL of the selected image. | |
82 * @param {string} imageUrl | |
83 */ | |
84 ChangePicturePrivateApi.receiveSelectedImage = function(imageUrl) { | |
85 if (ChangePicturePrivateApi.getSelectedImageUrlCallback_) | |
86 ChangePicturePrivateApi.getSelectedImageUrlCallback_(imageUrl); | |
87 }; | |
88 | |
89 /** | |
90 * Called from C++ to provide the URL of the 'old' image. The 'old' image is | |
91 * any selected non-profile and non-default image. It can be from the | |
92 * camera, a file, or a deprecated default image. When this method is called, | |
93 * it's implied that the old image is selected. | |
94 * @param {string} imageUrl | |
95 */ | |
96 ChangePicturePrivateApi.receiveOldImage = function(imageUrl) { | |
97 if (ChangePicturePrivateApi.getOldImageUrlCallback_) | |
98 ChangePicturePrivateApi.getOldImageUrlCallback_(imageUrl); | |
99 }; | |
100 | |
101 /** | |
102 * Called from C++ to provide the URL of the profile image. | |
103 * @param {string} imageUrl | |
104 * @param {boolean} selected | |
105 */ | |
106 ChangePicturePrivateApi.receiveProfileImage = function(imageUrl, selected) { | |
107 if (ChangePicturePrivateApi.getProfileImageUrlCallback_) | |
108 ChangePicturePrivateApi.getProfileImageUrlCallback_(imageUrl, selected); | |
109 }; | |
110 | |
111 /** | |
112 * Called from C++ to notify page about camera presence. | |
113 * @param {boolean} cameraPresent | |
114 */ | |
115 ChangePicturePrivateApi.receiveCameraPresence = function(cameraPresent) { | |
116 // TODO(tommycli): Implement camera functionality. | |
117 }; | |
118 | |
119 /** | |
120 * Called from JavaScript. Sets the user image to one of the default images. | |
121 * @param {string} imageUrl | |
122 */ | |
123 ChangePicturePrivateApi.selectDefaultImage = function(imageUrl) { | |
124 chrome.send('selectImage', [imageUrl, 'default']); | |
125 }; | |
126 | |
127 /** | |
128 * Called from JavaScript. Sets the user image to the 'old' image. | |
129 */ | |
130 ChangePicturePrivateApi.selectOldImage = function() { | |
131 chrome.send('selectImage', ['', 'old']); | |
132 }; | |
133 | |
134 /** | |
135 * Called from JavaScript. Sets the user image to the profile image. | |
136 */ | |
137 ChangePicturePrivateApi.selectProfileImage = function() { | |
138 chrome.send('selectImage', ['', 'profile']); | |
139 }; | |
140 | |
141 return { | |
142 ChangePicturePrivateApi: ChangePicturePrivateApi, | |
143 }; | |
144 }); | |
OLD | NEW |