summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/settings/people_page/change_picture_private_api.js
blob: 208a3cdd5c384ac212704d89bbffb62cb36e9e32 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2015 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.

cr.exportPath('settings');

/**
 * An object describing a default image.
 * @typedef {{
 *   author: string,
 *   title: string,
 *   url: string,
 *   website: string
 * }}
 */
settings.DefaultImage;

cr.define('settings', function() {
  /**
   * API which encapsulates messaging between JS and C++ for the ChromeOS
   * Change Picture subpage.
   * @constructor
   */
  function ChangePicturePrivateApi() {}

  /**
   * URLs of special button images.
   * @enum {string}
   */
  ChangePicturePrivateApi.ButtonImages = {
    TAKE_PHOTO: 'chrome://theme/IDR_BUTTON_USER_IMAGE_TAKE_PHOTO',
    CHOOSE_FILE: 'chrome://theme/IDR_BUTTON_USER_IMAGE_CHOOSE_FILE',
    PROFILE_PICTURE: 'chrome://theme/IDR_PROFILE_PICTURE_LOADING'
  };

  /**
   * Called from JavaScript. Retrieves the initial set of default images,
   * profile image, etc. As a response, the C++ calls these ChangePicturePage
   * methods as callbacks: receiveDefaultImages, receiveOldImage,
   * receiveProfileImage, and receiveSelectedImage.
   */
  ChangePicturePrivateApi.initialize = function() {
    chrome.send('onChangePicturePageInitialized');
  };

  /**
   * Called from JavaScript. Sets the user image to one of the default images.
   * As a response, the C++ calls ChangePicturePage.receiveSelectedImage.
   * @param {string} imageUrl
   */
  ChangePicturePrivateApi.selectDefaultImage = function(imageUrl) {
    chrome.send('selectImage', [imageUrl, 'default']);
  };

  /**
   * Called from JavaScript. Sets the user image to the 'old' image.
   * As a response, the C++ calls ChangePicturePage.receiveSelectedImage.
   */
  ChangePicturePrivateApi.selectOldImage = function() {
    chrome.send('selectImage', ['', 'old']);
  };

  /**
   * Called from JavaScript. Sets the user image to the profile image.
   * As a response, the C++ calls ChangePicturePage.receiveSelectedImage.
   */
  ChangePicturePrivateApi.selectProfileImage = function() {
    chrome.send('selectImage', ['', 'profile']);
  };

  return {
    ChangePicturePrivateApi: ChangePicturePrivateApi,
  };
});