Skip to content

Commit

Permalink
Sync to TabChildBase API
Browse files Browse the repository at this point in the history
  • Loading branch information
rainemak committed Dec 19, 2016
1 parent 96aac6e commit 148c075
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 78 deletions.
4 changes: 2 additions & 2 deletions dom/ipc/TabChild.h
Expand Up @@ -180,7 +180,7 @@ class TabChildBase : public nsISupports,
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TabChildBase)

virtual nsIWebNavigation* WebNavigation() const = 0;
virtual PuppetWidget* WebWidget() = 0;
virtual nsIWidget* WebWidget() = 0;
nsIPrincipal* GetPrincipal() { return mPrincipal; }
virtual bool DoUpdateZoomConstraints(const uint32_t& aPresShellId,
const mozilla::layers::FrameMetrics::ViewID& aViewId,
Expand Down Expand Up @@ -430,7 +430,7 @@ class TabChild final : public TabChildBase,
override;

virtual nsIWebNavigation* WebNavigation() const override { return mWebNav; }
virtual PuppetWidget* WebWidget() override { return mPuppetWidget; }
virtual nsIWidget* WebWidget() override { return mPuppetWidget; }

/** Return the DPI of the widget this TabChild draws to. */
void GetDPI(float* aDPI);
Expand Down
3 changes: 1 addition & 2 deletions embedding/embedlite/PEmbedLiteView.ipdl
Expand Up @@ -92,8 +92,7 @@ parent:
* The zoom controller code lives on the parent side and so this allows it to
* have up-to-date zoom constraints.
*/
UpdateZoomConstraints(uint32_t aPresShellId, ViewID aViewId, bool aIsRoot,
MaybeZoomConstraints aConstraints);
UpdateZoomConstraints(uint32_t aPresShellId, ViewID aViewId, MaybeZoomConstraints aConstraints);

/**
* Instructs the EmbedLiteViewThreadParent to forward a request to zoom to a rect given in
Expand Down
18 changes: 7 additions & 11 deletions embedding/embedlite/embedshared/EmbedLiteViewBaseChild.cpp
Expand Up @@ -366,12 +366,10 @@ EmbedLiteViewBaseChild::GetDPI(float* aDPI)
bool
EmbedLiteViewBaseChild::UpdateZoomConstraints(const uint32_t& aPresShellId,
const ViewID& aViewId,
const bool& aIsRoot,
const Maybe<ZoomConstraints> &aConstraints)
{
return SendUpdateZoomConstraints(aPresShellId,
aViewId,
aIsRoot,
aConstraints);
}

Expand Down Expand Up @@ -757,12 +755,12 @@ EmbedLiteViewBaseChild::RecvUpdateFrame(const FrameMetrics& aFrameMetrics)
return true;
}

if (mViewResized &&
aFrameMetrics.GetIsRoot() &&
mHelper->mLastRootMetrics.GetPresShellId() == aFrameMetrics.GetPresShellId() &&
mHelper->HandlePossibleViewportChange(mHelper->mInnerSize)) {
mViewResized = false;
}
// if (mViewResized &&
// aFrameMetrics.GetIsRoot() &&
// mHelper->mLastRootMetrics.GetPresShellId() == aFrameMetrics.GetPresShellId() &&
// mHelper->HandlePossibleViewportChange(mHelper->mInnerSize)) {
// mViewResized = false;
// }

RelayFrameMetrics(aFrameMetrics);

Expand Down Expand Up @@ -1069,9 +1067,7 @@ EmbedLiteViewBaseChild::RecvInputDataTouchMoveEvent(const ScrollableLayerGuid& a
NS_IMETHODIMP
EmbedLiteViewBaseChild::OnLocationChanged(const char* aLocation, bool aCanGoBack, bool aCanGoForward, bool aIsSameDocument)
{
if (!aIsSameDocument) {
mHelper->mContentDocumentIsDisplayed = false;
}
Unused << aIsSameDocument;
return SendOnLocationChanged(nsDependentCString(aLocation), aCanGoBack, aCanGoForward) ? NS_OK : NS_ERROR_FAILURE;
}

Expand Down
1 change: 0 additions & 1 deletion embedding/embedlite/embedshared/EmbedLiteViewBaseChild.h
Expand Up @@ -48,7 +48,6 @@ class EmbedLiteViewBaseChild : public PEmbedLiteViewChild,
virtual bool
UpdateZoomConstraints(const uint32_t& aPresShellId,
const ViewID& aViewId,
const bool& aIsRoot,
const Maybe<ZoomConstraints>& aConstraints) override;

virtual bool HasMessageListener(const nsAString& aMessageName) override;
Expand Down
Expand Up @@ -258,7 +258,6 @@ EmbedLiteViewBaseParent::RecvOnTitleChanged(const nsString& aTitle)
bool
EmbedLiteViewBaseParent::RecvUpdateZoomConstraints(const uint32_t& aPresShellId,
const ViewID& aViewId,
const bool& aIsRoot,
const Maybe<ZoomConstraints>& aConstraints)
{
if (mController->GetManager()) {
Expand Down
1 change: 0 additions & 1 deletion embedding/embedlite/embedshared/EmbedLiteViewBaseParent.h
Expand Up @@ -93,7 +93,6 @@ class EmbedLiteViewBaseParent : public PEmbedLiteViewParent,
virtual bool
RecvUpdateZoomConstraints(const uint32_t& aPresShellId,
const ViewID& aViewId,
const bool& aIsRoot,
const Maybe<ZoomConstraints> &aConstraints) override;
virtual bool RecvZoomToRect(const uint32_t& aPresShellId,
const ViewID& aViewId,
Expand Down
1 change: 0 additions & 1 deletion embedding/embedlite/embedshared/EmbedLiteViewChildIface.h
Expand Up @@ -40,7 +40,6 @@ class EmbedLiteViewChildIface
virtual bool
UpdateZoomConstraints(const uint32_t& aPresShellId,
const mozilla::layers::FrameMetrics::ViewID& aViewId,
const bool& aIsRoot,
const Maybe<mozilla::layers::ZoomConstraints>& aConstraints) = 0;

virtual bool HasMessageListener(const nsAString& aMessageName) = 0;
Expand Down
120 changes: 69 additions & 51 deletions embedding/embedlite/utils/TabChildHelper.cpp
Expand Up @@ -24,7 +24,6 @@
#include "nsIDocShell.h"
#include "nsViewportInfo.h"
#include "nsPIWindowRoot.h"
#include "StructuredCloneUtils.h"
#include "mozilla/Preferences.h"
#include "nsIFrame.h"
#include "nsView.h"
Expand Down Expand Up @@ -56,7 +55,7 @@ TabChildHelper::TabChildHelper(EmbedLiteViewChildIface* aView)
{
LOGT();

mScrolling = sDisableViewportHandler == false ? ASYNC_PAN_ZOOM : DEFAULT_SCROLLING;
// mScrolling = sDisableViewportHandler == false ? ASYNC_PAN_ZOOM : DEFAULT_SCROLLING;

// Init default prefs
static bool sPrefInitialized = false;
Expand Down Expand Up @@ -123,8 +122,7 @@ class EmbedUnloadScriptEvent : public nsRunnable

NS_IMETHOD Run() {
LOGT();
nsCOMPtr<nsIDOMEvent> event;
NS_NewDOMEvent(getter_AddRefs(event), mTabChildGlobal, nullptr, nullptr);
RefPtr<Event> event = NS_NewDOMEvent(mTabChildGlobal, nullptr, nullptr);
if (event) {
event->InitEvent(NS_LITERAL_STRING("unload"), false, false);
event->SetTrusted(true);
Expand Down Expand Up @@ -233,34 +231,38 @@ TabChildHelper::Observe(nsISupports* aSubject,
if (SameCOMIdentity(subject, doc)) {
mozilla::dom::AutoNoJSAPI nojsapi;

nsCOMPtr<nsIDOMWindowUtils> utils(GetDOMWindowUtils());

mContentDocumentIsDisplayed = true;

if (!sDisableViewportHandler) {
// Reset CSS viewport and zoom to default on new page, then
// calculate them properly using the actual metadata from the
// page.
SetCSSViewport(kDefaultViewportSize);

// In some cases before-first-paint gets called before
// RecvUpdateDimensions is called and therefore before we have an
// mInnerSize value set. In such cases defer initializing the viewport
// until we we get an inner size.
if (HasValidInnerSize()) {
InitializeRootMetrics();

utils->SetResolution(mLastRootMetrics.GetPresShellResolution(),
mLastRootMetrics.GetPresShellResolution());
HandlePossibleViewportChange(mInnerSize);
// Relay frame metrics to subscribed listeners
mView->RelayFrameMetrics(mLastRootMetrics);
}
nsCOMPtr<nsIPresShell> shell(doc->GetShell());
if (shell) {
shell->SetIsFirstPaint(true);
}

APZCCallbackHelper::InitializeRootDisplayport(shell);

// if (!sDisableViewportHandler) {
// // Reset CSS viewport and zoom to default on new page, then
// // calculate them properly using the actual metadata from the
// // page.
// SetCSSViewport(kDefaultViewportSize);

// // In some cases before-first-paint gets called before
// // RecvUpdateDimensions is called and therefore before we have an
// // mInnerSize value set. In such cases defer initializing the viewport
// // until we we get an inner size.
// if (HasValidInnerSize()) {
// InitializeRootMetrics();

// utils->SetResolution(mLastRootMetrics.GetPresShellResolution(),
// mLastRootMetrics.GetPresShellResolution());
//// HandlePossibleViewportChange(mInnerSize);
// // Relay frame metrics to subscribed listeners
// mView->RelayFrameMetrics(mLastRootMetrics);
// }
// }



nsCOMPtr<nsIObserverService> observerService =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
utils->SetIsFirstPaint(true);
if (observerService) {
observerService->NotifyObservers(aSubject, "embedlite-before-first-paint", nullptr);
}
Expand All @@ -279,9 +281,9 @@ TabChildHelper::HandleEvent(nsIDOMEvent* aEvent)
if (eventType.EqualsLiteral("DOMMetaAdded")) {
// This meta data may or may not have been a meta viewport tag. If it was,
// we should handle it immediately.
HandlePossibleViewportChange(mInnerSize);
// HandlePossibleViewportChange(mInnerSize);
// Relay frame metrics to subscribed listeners
mView->RelayFrameMetrics(mLastRootMetrics);
// mView->RelayFrameMetrics(mLastRootMetrics);
}

return NS_OK;
Expand Down Expand Up @@ -323,10 +325,10 @@ TabChildHelper::DoLoadMessageManagerScript(const nsAString& aURL, bool aRunInGlo
bool
TabChildHelper::DoSendBlockingMessage(JSContext* aCx,
const nsAString& aMessage,
const StructuredCloneData& aData,
mozilla::dom::ipc::StructuredCloneData& aData,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal,
InfallibleTArray<nsString>* aJSONRetVal,
nsTArray<mozilla::dom::ipc::StructuredCloneData> *aRetVal,
bool aIsSync)
{
if (!mView->HasMessageListener(aMessage)) {
Expand All @@ -347,22 +349,24 @@ TabChildHelper::DoSendBlockingMessage(JSContext* aCx,
}

nsAutoString json;
NS_ENSURE_TRUE(JS_Stringify(cx, &rval, JS::NullPtr(), JS::NullHandleValue, EmbedLiteJSON::JSONCreator, &json), false);
NS_ENSURE_TRUE(JS_Stringify(cx, &rval, nullptr, JS::NullHandleValue, EmbedLiteJSON::JSONCreator, &json), false);
NS_ENSURE_TRUE(!json.IsEmpty(), false);

// FIXME : Return value should be written to nsTArray<StructuredCloneData> *aRetVal
InfallibleTArray<nsString> jsonRetVal;

if (aIsSync) {
return mView->DoSendSyncMessage(nsString(aMessage).get(), json.get(), aJSONRetVal);
return mView->DoSendSyncMessage(nsString(aMessage).get(), json.get(), &jsonRetVal);
}

return mView->DoCallRpcMessage(nsString(aMessage).get(), json.get(), aJSONRetVal);
return mView->DoCallRpcMessage(nsString(aMessage).get(), json.get(), &jsonRetVal);
}

bool
TabChildHelper::DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
const mozilla::dom::StructuredCloneData& aData,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal)
nsresult TabChildHelper::DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
mozilla::dom::ipc::StructuredCloneData& aData,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal)
{
nsCOMPtr<nsIMessageBroadcaster> globalIMessageManager =
do_GetService("@mozilla.org/globalmessagemanager;1");
Expand All @@ -382,7 +386,7 @@ TabChildHelper::DoSendAsyncMessage(JSContext* aCx,

if (!mView->HasMessageListener(aMessage)) {
LOGW("Message not registered msg:%s\n", NS_ConvertUTF16toUTF8(aMessage).get());
return true;
return NS_OK;
}

NS_ENSURE_TRUE(InitTabChildGlobal(), false);
Expand All @@ -391,17 +395,26 @@ TabChildHelper::DoSendAsyncMessage(JSContext* aCx,

// FIXME: Need callback interface for simple JSON to avoid useless conversion here
JS::Rooted<JS::Value> rval(cx, JS::NullValue());
if (aData.mDataLength &&
if (aData.DataLength() &&
!ReadStructuredClone(cx, aData, &rval)) {
JS_ClearPendingException(cx);
return false;
return NS_ERROR_UNEXPECTED;
}

nsAutoString json;
NS_ENSURE_TRUE(JS_Stringify(cx, &rval, JS::NullPtr(), JS::NullHandleValue, EmbedLiteJSON::JSONCreator, &json), false);
NS_ENSURE_TRUE(!json.IsEmpty(), false);
// Check EmbedLiteJSON::JSONCreator and/or JS_Stringify from Android side
if (!JS_Stringify(cx, &rval, nullptr, JS::NullHandleValue, EmbedLiteJSON::JSONCreator, &json)) {
return NS_ERROR_UNEXPECTED;
}

return mView->DoSendAsyncMessage(nsString(aMessage).get(), json.get());
if (json.IsEmpty()) {
return NS_ERROR_UNEXPECTED;
}

if (!mView->DoSendAsyncMessage(nsString(aMessage).get(), json.get())) {
return NS_ERROR_UNEXPECTED;
}
return NS_OK;
}

bool
Expand All @@ -411,6 +424,12 @@ TabChildHelper::CheckPermission(const nsAString& aPermission)
return false;
}

ScreenIntSize
TabChildHelper::GetInnerSize()
{
return mInnerSize;
}

bool
TabChildHelper::ConvertMutiTouchInputToEvent(const mozilla::MultiTouchInput& aData,
WidgetTouchEvent& aEvent)
Expand Down Expand Up @@ -456,12 +475,10 @@ TabChildHelper::GetPresContext()
bool
TabChildHelper::DoUpdateZoomConstraints(const uint32_t& aPresShellId,
const ViewID& aViewId,
const bool& aIsRoot,
const Maybe<mozilla::layers::ZoomConstraints> &aConstraints)
{
return mView->UpdateZoomConstraints(aPresShellId,
aViewId,
aIsRoot,
aConstraints);
}

Expand All @@ -474,11 +491,12 @@ TabChildHelper::ReportSizeUpdate(const gfxSize& aSize)
mHasValidInnerSize = true;
}

ScreenIntSize oldScreenSize(mInnerSize);
// ScreenIntSize oldScreenSize(mInnerSize);
mInnerSize = ScreenIntSize::FromUnknownSize(gfx::IntSize(aSize.width, aSize.height));

HandlePossibleViewportChange(oldScreenSize);
// HandlePossibleViewportChange(oldScreenSize);
}

// -- nsITabChild --------------

NS_IMETHODIMP
Expand Down
19 changes: 11 additions & 8 deletions embedding/embedlite/utils/TabChildHelper.h
Expand Up @@ -48,21 +48,23 @@ class TabChildHelper : public mozilla::dom::TabChildBase,
virtual bool DoLoadMessageManagerScript(const nsAString& aURL, bool aRunInGlobalScope) override;
virtual bool DoSendBlockingMessage(JSContext* aCx,
const nsAString& aMessage,
const mozilla::dom::StructuredCloneData& aData,
mozilla::dom::ipc::StructuredCloneData& aData,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal,
InfallibleTArray<nsString>* aJSONRetVal,
nsTArray<mozilla::dom::ipc::StructuredCloneData>* aRetVal,
bool aIsSync) override;
virtual bool DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
const mozilla::dom::StructuredCloneData& aData,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal) override;
virtual nsresult DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
mozilla::dom::ipc::StructuredCloneData& aData,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal) override;
virtual bool CheckPermission(const nsAString& aPermission) override;
virtual bool DoUpdateZoomConstraints(const uint32_t& aPresShellId,
const mozilla::layers::FrameMetrics::ViewID& aViewId,
const bool& aIsRoot,
const Maybe<mozilla::layers::ZoomConstraints>& aConstraints) override;

virtual ScreenIntSize GetInnerSize() override;

void ReportSizeUpdate(const gfxSize& aSize);

protected:
Expand All @@ -86,6 +88,7 @@ class TabChildHelper : public mozilla::dom::TabChildBase,
friend class EmbedLiteViewBaseChild;
EmbedLiteViewChildIface* mView;
bool mHasValidInnerSize;
ScreenIntSize mInnerSize;
};

}
Expand Down

0 comments on commit 148c075

Please sign in to comment.