Skip to content

Commit

Permalink
#405: plumbing into browser
Browse files Browse the repository at this point in the history
  • Loading branch information
classilla committed Jun 15, 2018
1 parent f702324 commit e2a5d0b
Show file tree
Hide file tree
Showing 18 changed files with 440 additions and 0 deletions.
29 changes: 29 additions & 0 deletions dom/html/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
#include <limits>

#include "nsIColorPicker.h"
#include "nsIDatePicker.h" // TenFourFox issue 405
#include "nsIStringEnumerator.h"
#include "HTMLSplitOnSpacesTokenizer.h"
#include "nsIController.h"
Expand Down Expand Up @@ -565,6 +566,22 @@ HTMLInputElement::IsPopupBlocked() const
return permission == nsIPopupWindowManager::DENY_POPUP;
}

/* Time and date picker implementations from TenFourFox issue 405. */

nsresult
HTMLInputElement::InitTimePicker()
{
NS_WARNING("InitTimePicker NYI");
return NS_ERROR_FAILURE;
}

nsresult
HTMLInputElement::InitDatePicker()
{
NS_WARNING("InitDatePicker NYI");
return NS_ERROR_FAILURE;
}

nsresult
HTMLInputElement::InitColorPicker()
{
Expand Down Expand Up @@ -3608,6 +3625,12 @@ HTMLInputElement::MaybeInitPickers(EventChainPostVisitor& aVisitor)
if (mType == NS_FORM_INPUT_COLOR) {
return InitColorPicker();
}
if (mType == NS_FORM_INPUT_DATE) {
return InitDatePicker();
}
if (mType == NS_FORM_INPUT_TIME) {
return InitTimePicker();
}
return NS_OK;
}

Expand Down Expand Up @@ -3831,6 +3854,8 @@ HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
case NS_FORM_INPUT_SUBMIT:
case NS_FORM_INPUT_IMAGE: // Bug 34418
case NS_FORM_INPUT_COLOR:
case NS_FORM_INPUT_DATE: // TenFourFox issue 405
case NS_FORM_INPUT_TIME: // ditto
{
WidgetMouseEvent event(aVisitor.mEvent->mFlags.mIsTrusted,
eMouseClick, nullptr,
Expand Down Expand Up @@ -4732,6 +4757,10 @@ HTMLInputElement::ParseAttribute(int32_t aNamespaceID,
newType = aResult.GetEnumValue();
if ((IsExperimentalMobileType(newType) &&
!Preferences::GetBool("dom.experimental_forms", false)) ||
(newType == NS_FORM_INPUT_DATE &&
!Preferences::GetBool("tenfourfox.dom.forms.date", false)) ||
(newType == NS_FORM_INPUT_TIME &&
!Preferences::GetBool("tenfourfox.dom.forms.time", false)) ||
(newType == NS_FORM_INPUT_NUMBER &&
!Preferences::GetBool("dom.forms.number", false)) ||
(newType == NS_FORM_INPUT_COLOR &&
Expand Down
4 changes: 4 additions & 0 deletions dom/html/HTMLInputElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,10 @@ class HTMLInputElement final : public nsGenericHTMLFormElementWithState,
nsresult InitFilePicker(FilePickerType aType);
nsresult InitColorPicker();

// TenFourFox issue 405
nsresult InitDatePicker();
nsresult InitTimePicker();

/**
* Use this function before trying to open a picker.
* It checks if the page is allowed to open a new pop-up.
Expand Down
93 changes: 93 additions & 0 deletions dom/ipc/DatePickerParent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "DatePickerParent.h"
#include "nsComponentManagerUtils.h"
#include "nsIDocument.h"
#include "nsIDOMWindow.h"
#include "mozilla/unused.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/TabParent.h"

using mozilla::Unused;
using namespace mozilla::dom;

NS_IMPL_ISUPPORTS(DatePickerParent::DatePickerShownCallback,
nsIDatePickerShownCallback);

NS_IMETHODIMP
DatePickerParent::DatePickerShownCallback::Update(const nsAString& aDate)
{
if (mDatePickerParent) {
Unused << mDatePickerParent->SendUpdate(nsString(aDate));
}
return NS_OK;
}

NS_IMETHODIMP
DatePickerParent::DatePickerShownCallback::Done(int16_t aResult)
{
if (mDatePickerParent) {
mDatePickerParent->Done(aResult);
}
return NS_OK;
}

void
DatePickerParent::DatePickerShownCallback::Destroy()
{
mDatePickerParent = nullptr;
}

bool
DatePickerParent::CreateDatePicker()
{
mPicker = do_CreateInstance("@mozilla.org/datepicker;1");
if (!mPicker) {
return false;
}

Element* ownerElement = TabParent::GetFrom(Manager())->GetOwnerElement();
if (!ownerElement) {
return false;
}

nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(ownerElement->OwnerDoc()->GetWindow());
if (!window) {
return false;
}

return NS_SUCCEEDED(mPicker->Init(window, mTitle));
}

void
DatePickerParent::Done(int16_t aResult)
{
Unused << Send__delete__(this, nsString());
MOZ_CRASH("DatePickerParent::Done NYI");
}

bool
DatePickerParent::RecvOpen()
{
if (!CreateDatePicker()) {
Unused << Send__delete__(this, nsString());
return true;
}

mCallback = new DatePickerShownCallback(this);

mPicker->Open(mCallback);
return true;
};

void
DatePickerParent::ActorDestroy(ActorDestroyReason aWhy)
{
if (mCallback) {
mCallback->Destroy();
}
}
63 changes: 63 additions & 0 deletions dom/ipc/DatePickerParent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_dom_DatePickerParent_h
#define mozilla_dom_DatePickerParent_h

#include "mozilla/dom/PDatePickerParent.h"
#include "nsIDatePicker.h"

namespace mozilla {
namespace dom {

class DatePickerParent : public PDatePickerParent
{
public:
DatePickerParent(const nsString& aTitle)
: mTitle(aTitle)
{}

virtual bool RecvOpen() override;
virtual void ActorDestroy(ActorDestroyReason aWhy) override;

void Done(int16_t aResult);

class DatePickerShownCallback final
: public nsIDatePickerShownCallback
{
public:
explicit DatePickerShownCallback(DatePickerParent* aDatePickerParent)
: mDatePickerParent(aDatePickerParent)
{}

NS_DECL_ISUPPORTS
NS_DECL_NSIDATEPICKERSHOWNCALLBACK

NS_IMETHODIMP Update(const nsAString& aDate);

void Destroy();

private:
~DatePickerShownCallback() {}

DatePickerParent* mDatePickerParent;
};

private:
virtual ~DatePickerParent() {}

bool CreateDatePicker();

RefPtr<DatePickerShownCallback> mCallback;
nsCOMPtr<nsIDatePicker> mPicker;

nsString mTitle;
};

} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_DatePickerParent_h
4 changes: 4 additions & 0 deletions dom/ipc/PBrowser.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ include protocol PContent;
include protocol PContentBridge;
include protocol PDocAccessible;
include protocol PDocumentRenderer;
include protocol PDatePicker;
include protocol PFilePicker;
include protocol PIndexedDBPermissionRequest;
include protocol PRenderFrame;
Expand Down Expand Up @@ -104,6 +105,7 @@ prio(normal upto urgent) sync protocol PBrowser
manages PDocAccessible;
manages PDocumentRenderer;
manages PFilePicker;
manages PDatePicker;
manages PIndexedDBPermissionRequest;
manages PRenderFrame;
manages PPluginWidget;
Expand Down Expand Up @@ -377,6 +379,8 @@ parent:

PFilePicker(nsString aTitle, int16_t aMode);

PDatePicker(nsString aTitle);

/**
* Initiates an asynchronous request for one of the special indexedDB
* permissions for the provided principal.
Expand Down
27 changes: 27 additions & 0 deletions dom/ipc/PDatePicker.ipdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

include protocol PBrowser;

namespace mozilla {
namespace dom {

protocol PDatePicker
{
manager PBrowser;

parent:
Open();

child:
Update(nsString date);

__delete__(nsString date);
};

} // namespace dom
} // namespace mozilla
16 changes: 16 additions & 0 deletions dom/ipc/TabChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#ifdef MOZ_CRASHREPORTER
#include "nsExceptionHandler.h"
#endif
#include "nsDatePickerProxy.h"
#include "nsFilePickerProxy.h"
#include "mozilla/dom/Element.h"
#include "nsIBaseWindow.h"
Expand Down Expand Up @@ -2136,6 +2137,21 @@ TabChild::DeallocPFilePickerChild(PFilePickerChild* actor)
return true;
}

PDatePickerChild*
TabChild::AllocPDatePickerChild(const nsString&)
{
NS_RUNTIMEABORT("unused");
return nullptr;
}

bool
TabChild::DeallocPDatePickerChild(PDatePickerChild* actor)
{
nsDatePickerProxy* datePicker = static_cast<nsDatePickerProxy*>(actor);
NS_RELEASE(datePicker);
return true;
}

auto
TabChild::AllocPIndexedDBPermissionRequestChild(const Principal& aPrincipal)
-> PIndexedDBPermissionRequestChild*
Expand Down
5 changes: 5 additions & 0 deletions dom/ipc/TabChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ class TabChild final : public TabChildBase,
virtual bool
DeallocPFilePickerChild(PFilePickerChild* actor) override;

virtual PDatePickerChild*
AllocPDatePickerChild(const nsString& aTitle) override;
virtual bool
DeallocPDatePickerChild(PDatePickerChild* actor) override;

virtual PIndexedDBPermissionRequestChild*
AllocPIndexedDBPermissionRequestChild(const Principal& aPrincipal)
override;
Expand Down
14 changes: 14 additions & 0 deletions dom/ipc/TabParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#include "PermissionMessageUtils.h"
#include "StructuredCloneData.h"
#include "ColorPickerParent.h"
#include "DatePickerParent.h"
#include "FilePickerParent.h"
#include "TabChild.h"
#include "LoadContext.h"
Expand Down Expand Up @@ -1214,6 +1215,19 @@ TabParent::DeallocPFilePickerParent(PFilePickerParent* actor)
return true;
}

PDatePickerParent*
TabParent::AllocPDatePickerParent(const nsString& aTitle)
{
return new DatePickerParent(aTitle);
}

bool
TabParent::DeallocPDatePickerParent(PDatePickerParent* actor)
{
delete actor;
return true;
}

auto
TabParent::AllocPIndexedDBPermissionRequestParent(const Principal& aPrincipal)
-> PIndexedDBPermissionRequestParent*
Expand Down
4 changes: 4 additions & 0 deletions dom/ipc/TabParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ class TabParent final : public PBrowserParent
const int16_t& aMode) override;
virtual bool DeallocPFilePickerParent(PFilePickerParent* actor) override;

virtual PDatePickerParent*
AllocPDatePickerParent(const nsString& aTitle) override;
virtual bool DeallocPDatePickerParent(PDatePickerParent* actor) override;

virtual PIndexedDBPermissionRequestParent*
AllocPIndexedDBPermissionRequestParent(const Principal& aPrincipal)
override;
Expand Down
2 changes: 2 additions & 0 deletions dom/ipc/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ UNIFIED_SOURCES += [
'ContentProcess.cpp',
'ContentProcessManager.cpp',
'CrashReporterParent.cpp',
'DatePickerParent.cpp',
'FilePickerParent.cpp',
'nsIContentChild.cpp',
'nsIContentParent.cpp',
Expand Down Expand Up @@ -102,6 +103,7 @@ IPDL_SOURCES += [
'PContentPermissionRequest.ipdl',
'PCrashReporter.ipdl',
'PCycleCollectWithLogs.ipdl',
'PDatePicker.ipdl',
'PDocumentRenderer.ipdl',
'PFilePicker.ipdl',
'PMemoryReportRequest.ipdl',
Expand Down
2 changes: 2 additions & 0 deletions modules/libpref/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -5139,3 +5139,5 @@ pref("toolkit.pageThumbs.minHeight", 0);

pref("tenfourfox.adblock.enabled", false);
pref("tenfourfox.adblock.logging.enabled", false);
pref("tenfourfox.dom.forms.date", false);
pref("tenfourfox.dom.forms.time", false);
Loading

0 comments on commit e2a5d0b

Please sign in to comment.