Bug 1634779 - pt 2. Partially revert Bug 1603006 r=kmag
[gecko.git] / dom / ipc / ColorPickerParent.cpp
blobdeca8986332dc5b8e727cb6786e330bebc47467e
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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/. */
7 #include "ColorPickerParent.h"
8 #include "nsComponentManagerUtils.h"
9 #include "mozilla/dom/Document.h"
10 #include "mozilla/Unused.h"
11 #include "mozilla/dom/Element.h"
12 #include "mozilla/dom/BrowserParent.h"
14 using mozilla::Unused;
15 using namespace mozilla::dom;
17 NS_IMPL_ISUPPORTS(ColorPickerParent::ColorPickerShownCallback,
18 nsIColorPickerShownCallback);
20 NS_IMETHODIMP
21 ColorPickerParent::ColorPickerShownCallback::Update(const nsAString& aColor) {
22 if (mColorPickerParent) {
23 Unused << mColorPickerParent->SendUpdate(nsString(aColor));
25 return NS_OK;
28 NS_IMETHODIMP
29 ColorPickerParent::ColorPickerShownCallback::Done(const nsAString& aColor) {
30 if (mColorPickerParent) {
31 Unused << ColorPickerParent::Send__delete__(mColorPickerParent,
32 nsString(aColor));
34 return NS_OK;
37 void ColorPickerParent::ColorPickerShownCallback::Destroy() {
38 mColorPickerParent = nullptr;
41 bool ColorPickerParent::CreateColorPicker() {
42 mPicker = do_CreateInstance("@mozilla.org/colorpicker;1");
43 if (!mPicker) {
44 return false;
47 Element* ownerElement = BrowserParent::GetFrom(Manager())->GetOwnerElement();
48 if (!ownerElement) {
49 return false;
52 nsCOMPtr<nsPIDOMWindowOuter> window = ownerElement->OwnerDoc()->GetWindow();
53 if (!window) {
54 return false;
57 return NS_SUCCEEDED(mPicker->Init(window, mTitle, mInitialColor));
60 mozilla::ipc::IPCResult ColorPickerParent::RecvOpen() {
61 if (!CreateColorPicker()) {
62 Unused << Send__delete__(this, mInitialColor);
63 return IPC_OK();
66 mCallback = new ColorPickerShownCallback(this);
68 mPicker->Open(mCallback);
69 return IPC_OK();
72 void ColorPickerParent::ActorDestroy(ActorDestroyReason aWhy) {
73 if (mCallback) {
74 mCallback->Destroy();