1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "nsColorPickerProxy.h"
8 
9 #include "mozilla/dom/TabChild.h"
10 
11 using namespace mozilla::dom;
12 
NS_IMPL_ISUPPORTS(nsColorPickerProxy,nsIColorPicker)13 NS_IMPL_ISUPPORTS(nsColorPickerProxy, nsIColorPicker)
14 
15 NS_IMETHODIMP
16 nsColorPickerProxy::Init(mozIDOMWindowProxy* aParent, const nsAString& aTitle,
17                          const nsAString& aInitialColor) {
18   TabChild* tabChild = TabChild::GetFrom(aParent);
19   if (!tabChild) {
20     return NS_ERROR_FAILURE;
21   }
22 
23   tabChild->SendPColorPickerConstructor(this, nsString(aTitle),
24                                         nsString(aInitialColor));
25   NS_ADDREF_THIS();
26   return NS_OK;
27 }
28 
29 NS_IMETHODIMP
Open(nsIColorPickerShownCallback * aColorPickerShownCallback)30 nsColorPickerProxy::Open(
31     nsIColorPickerShownCallback* aColorPickerShownCallback) {
32   NS_ENSURE_STATE(!mCallback);
33   mCallback = aColorPickerShownCallback;
34 
35   SendOpen();
36   return NS_OK;
37 }
38 
RecvUpdate(const nsString & aColor)39 mozilla::ipc::IPCResult nsColorPickerProxy::RecvUpdate(const nsString& aColor) {
40   if (mCallback) {
41     mCallback->Update(aColor);
42   }
43   return IPC_OK();
44 }
45 
Recv__delete__(const nsString & aColor)46 mozilla::ipc::IPCResult nsColorPickerProxy::Recv__delete__(
47     const nsString& aColor) {
48   if (mCallback) {
49     mCallback->Done(aColor);
50     mCallback = nullptr;
51   }
52   return IPC_OK();
53 }
54