Skip to content

Commit

Permalink
Share more TabChild stuff, messaging, helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeshkova committed Mar 11, 2014
1 parent f3d1e65 commit 0b6df23
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 180 deletions.
34 changes: 18 additions & 16 deletions dom/ipc/TabChild.cpp
Expand Up @@ -217,6 +217,13 @@ class TabChild::CachedFileDescriptorCallbackRunnable : public nsRunnable

StaticRefPtr<TabChild> sPreallocatedTab;

TabChildBase::TabChildBase()
: mOldViewportWidth(0.0f)
, mContentDocumentIsDisplayed(false)
, mTabChildGlobal(nullptr)
{
}

/*static*/ void
TabChild::PreloadSlowThings()
{
Expand Down Expand Up @@ -278,18 +285,15 @@ TabChild::TabChild(ContentChild* aManager, const TabContext& aContext, uint32_t
: TabContext(aContext)
, mRemoteFrame(nullptr)
, mManager(aManager)
, mTabChildGlobal(nullptr)
, mChromeFlags(aChromeFlags)
, mOuterRect(0, 0, 0, 0)
, mInnerSize(0, 0)
, mActivePointerId(-1)
, mTapHoldTimer(nullptr)
, mAppPackageFileDescriptorRecved(false)
, mOldViewportWidth(0.0f)
, mLastBackgroundColor(NS_RGB(255, 255, 255))
, mDidFakeShow(false)
, mNotified(false)
, mContentDocumentIsDisplayed(false)
, mTriedBrowserInit(false)
, mOrientation(eScreenOrientation_PortraitPrimary)
, mUpdateHitRegion(false)
Expand Down Expand Up @@ -495,7 +499,7 @@ TabChild::OnSecurityChange(nsIWebProgress* aWebProgress,
}

void
TabChild::SetCSSViewport(const CSSSize& aSize)
TabChildBase::SetCSSViewport(const CSSSize& aSize)
{
mOldViewportWidth = aSize.width;

Expand All @@ -505,8 +509,8 @@ TabChild::SetCSSViewport(const CSSSize& aSize)
}
}

static CSSSize
GetPageSize(nsCOMPtr<nsIDocument> aDocument, const CSSSize& aViewport)
CSSSize
TabChildBase::GetPageSize(nsCOMPtr<nsIDocument> aDocument, const CSSSize& aViewport)
{
nsCOMPtr<Element> htmlDOMElement = aDocument->GetHtmlElement();
HTMLBodyElement* bodyDOMElement = aDocument->GetBodyElement();
Expand Down Expand Up @@ -1083,15 +1087,15 @@ TabChild::BrowserFrameProvideWindow(nsIDOMWindow* aOpener,
}

already_AddRefed<nsIDOMWindowUtils>
TabChild::GetDOMWindowUtils()
TabChildBase::GetDOMWindowUtils()
{
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(WebNavigation());
nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(window);
return utils.forget();
}

already_AddRefed<nsIDocument>
TabChild::GetDocument()
TabChildBase::GetDocument()
{
nsCOMPtr<nsIDOMDocument> domDoc;
WebNavigation()->GetDocument(getter_AddRefs(domDoc));
Expand Down Expand Up @@ -1526,15 +1530,15 @@ TabChild::RecvUpdateDimensions(const nsRect& rect, const nsIntSize& size, const
}

void
TabChild::DispatchMessageManagerMessage(const nsAString& aMessageName,
const nsACString& aJSONData)
TabChildBase::DispatchMessageManagerMessage(const nsAString& aMessageName,
const nsAString& aJSONData)
{
AutoSafeJSContext cx;
JS::Rooted<JS::Value> json(cx, JSVAL_NULL);
StructuredCloneData cloneData;
JSAutoStructuredCloneBuffer buffer;
if (JS_ParseJSON(cx,
static_cast<const jschar*>(NS_ConvertUTF8toUTF16(aJSONData).get()),
static_cast<const jschar*>(aJSONData.BeginReading()),
aJSONData.Length(),
&json)) {
WriteStructuredClone(cx, json, buffer, cloneData.mClosure);
Expand Down Expand Up @@ -1603,7 +1607,7 @@ TabChild::ProcessUpdateFrame(const FrameMetrics& aFrameMetrics)
// The BrowserElementScrolling helper must know about these updated metrics
// for other functions it performs, such as double tap handling.
// Note, %f must not be used because it is locale specific!
nsCString data;
nsString data;
data.AppendPrintf("{ \"x\" : %d", NS_lround(newMetrics.mScrollOffset.x));
data.AppendPrintf(", \"y\" : %d", NS_lround(newMetrics.mScrollOffset.y));
data.AppendLiteral(", \"viewport\" : ");
Expand Down Expand Up @@ -1660,10 +1664,8 @@ TabChild::RecvHandleDoubleTap(const CSSIntPoint& aPoint, const ScrollableLayerGu
return true;
}

nsCString data;
data += nsPrintfCString("{ \"x\" : %d", aPoint.x);
data += nsPrintfCString(", \"y\" : %d", aPoint.y);
data += nsPrintfCString(" }");
nsString data;
data.AppendPrintf("{ \"x\" : %d, \"y\" : %d }", aPoint.x, aPoint.y);

DispatchMessageManagerMessage(NS_LITERAL_STRING("Gesture:DoubleTap"), data);

Expand Down
51 changes: 29 additions & 22 deletions dom/ipc/TabChild.h
Expand Up @@ -149,8 +149,35 @@ class TabChildBase : public nsFrameScriptExecutor,
public ipc::MessageManagerCallback
{
public:
virtual nsIWebNavigation* WebNavigation() = 0;
nsIPrincipal* GetPrincipal() { return mPrincipal; }
TabChildBase();

virtual nsIWebNavigation* WebNavigation() = 0;
nsIPrincipal* GetPrincipal() { return mPrincipal; }

protected:
CSSSize GetPageSize(nsCOMPtr<nsIDocument> aDocument, const CSSSize& aViewport);

// Get the DOMWindowUtils for the top-level window in this tab.
already_AddRefed<nsIDOMWindowUtils> GetDOMWindowUtils();
// Get the Document for the top-level window in this tab.
already_AddRefed<nsIDocument> GetDocument();

// Wrapper for nsIDOMWindowUtils.setCSSViewport(). This updates some state
// variables local to this class before setting it.
void SetCSSViewport(const CSSSize& aSize);

// Wraps up a JSON object as a structured clone and sends it to the browser
// chrome script.
//
// XXX/bug 780335: Do the work the browser chrome script does in C++ instead
// so we don't need things like this.
void DispatchMessageManagerMessage(const nsAString& aMessageName,
const nsAString& aJSONData);

protected:
float mOldViewportWidth;
bool mContentDocumentIsDisplayed;
nsRefPtr<TabChildGlobal> mTabChildGlobal;
};

class TabChild : public PBrowserChild,
Expand Down Expand Up @@ -448,25 +475,13 @@ class TabChild : public PBrowserChild,
// Call RecvShow(nsIntSize(0, 0)) and block future calls to RecvShow().
void DoFakeShow();

// Wrapper for nsIDOMWindowUtils.setCSSViewport(). This updates some state
// variables local to this class before setting it.
void SetCSSViewport(const CSSSize& aSize);

// Recalculates the display state, including the CSS
// viewport. This should be called whenever we believe the
// viewport data on a document may have changed. If it didn't
// change, this function doesn't do anything. However, it should
// not be called all the time as it is fairly expensive.
void HandlePossibleViewportChange();

// Wraps up a JSON object as a structured clone and sends it to the browser
// chrome script.
//
// XXX/bug 780335: Do the work the browser chrome script does in C++ instead
// so we don't need things like this.
void DispatchMessageManagerMessage(const nsAString& aMessageName,
const nsACString& aJSONData);

void DispatchSynthesizedMouseEvent(uint32_t aMsg, uint64_t aTime,
const LayoutDevicePoint& aRefPoint);

Expand All @@ -488,11 +503,6 @@ class TabChild : public PBrowserChild,
bool* aWindowIsNew,
nsIDOMWindow** aReturn);

// Get the DOMWindowUtils for the top-level window in this tab.
already_AddRefed<nsIDOMWindowUtils> GetDOMWindowUtils();
// Get the Document for the top-level window in this tab.
already_AddRefed<nsIDocument> GetDocument();

class CachedFileDescriptorInfo;
class CachedFileDescriptorCallbackRunnable;

Expand All @@ -503,7 +513,6 @@ class TabChild : public PBrowserChild,
FrameMetrics mLastRootMetrics;
RenderFrameChild* mRemoteFrame;
nsRefPtr<ContentChild> mManager;
nsRefPtr<TabChildGlobal> mTabChildGlobal;
uint32_t mChromeFlags;
nsIntRect mOuterRect;
ScreenIntSize mInnerSize;
Expand All @@ -521,12 +530,10 @@ class TabChild : public PBrowserChild,
// At present only 1 of these is really expected.
nsAutoTArray<nsAutoPtr<CachedFileDescriptorInfo>, 1>
mCachedFileDescriptorInfos;
float mOldViewportWidth;
nscolor mLastBackgroundColor;
ScrollingBehavior mScrolling;
bool mDidFakeShow;
bool mNotified;
bool mContentDocumentIsDisplayed;
bool mTriedBrowserInit;
ScreenOrientation mOrientation;
bool mUpdateHitRegion;
Expand Down
3 changes: 3 additions & 0 deletions embedding/embedlite/PEmbedLiteView.ipdl
Expand Up @@ -104,6 +104,9 @@ parent:
sync SyncMessage(nsString aMessage, nsString aJSON)
returns (nsString[] retval);

rpc RpcMessage(nsString aMessage, nsString aJSON)
returns (nsString[] retval);

// IME
sync GetInputContext() returns (int32_t IMEEnabled, int32_t IMEOpen,
intptr_t NativeIMEContext);
Expand Down
22 changes: 16 additions & 6 deletions embedding/embedlite/embedthread/EmbedLiteViewThreadChild.cpp
Expand Up @@ -416,7 +416,7 @@ EmbedLiteViewThreadChild::RecvAsyncMessage(const nsString& aMessage,
{
LOGT("msg:%s, data:%s", NS_ConvertUTF16toUTF8(aMessage).get(), NS_ConvertUTF16toUTF8(aData).get());
AppChild()->AppService()->HandleAsyncMessage(NS_ConvertUTF16toUTF8(aMessage).get(), aData);
mHelper->RecvAsyncMessage(aMessage, aData);
mHelper->DispatchMessageManagerMessage(aMessage, aData);
return true;
}

Expand Down Expand Up @@ -449,12 +449,22 @@ EmbedLiteViewThreadChild::DoSendSyncMessage(const char16_t* aMessageName, const
return true;
}

bool
EmbedLiteViewThreadChild::DoCallRpcMessage(const char16_t* aMessageName, const char16_t* aMessage, InfallibleTArray<nsString>* aJSONRetVal)
{
LOGT("msg:%s, data:%s", NS_ConvertUTF16toUTF8(aMessageName).get(), NS_ConvertUTF16toUTF8(aMessage).get());
if (mRegisteredMessages.Get(nsDependentString(aMessageName))) {
CallRpcMessage(nsDependentString(aMessageName), nsDependentString(aMessage), aJSONRetVal);
}
return true;
}

void
EmbedLiteViewThreadChild::RecvAsyncMessage(const nsAString& aMessage,
const nsAString& aData)
{
LOGT("msg:%s, data:%s", NS_ConvertUTF16toUTF8(aMessage).get(), NS_ConvertUTF16toUTF8(aData).get());
mHelper->RecvAsyncMessage(aMessage, aData);
mHelper->DispatchMessageManagerMessage(aMessage, aData);
}

bool
Expand Down Expand Up @@ -567,7 +577,7 @@ EmbedLiteViewThreadChild::RecvAsyncScrollDOMEvent(const gfxRect& contentRect,
data.AppendPrintf(", \"height\" : ");
data.AppendFloat(scrollSize.height);
data.AppendPrintf(" }}");
mHelper->RecvAsyncMessage(NS_LITERAL_STRING("AZPC:ScrollDOMEvent"), data);
mHelper->DispatchMessageManagerMessage(NS_LITERAL_STRING("AZPC:ScrollDOMEvent"), data);
}

return true;
Expand Down Expand Up @@ -614,7 +624,7 @@ EmbedLiteViewThreadChild::RecvHandleDoubleTap(const nsIntPoint& aPoint)
if (sPostAZPCAsJson.doubleTap) {
nsString data;
data.AppendPrintf("{ \"x\" : %d, \"y\" : %d }", aPoint.x, aPoint.y);
mHelper->RecvAsyncMessage(NS_LITERAL_STRING("Gesture:DoubleTap"), data);
mHelper->DispatchMessageManagerMessage(NS_LITERAL_STRING("Gesture:DoubleTap"), data);
}

return true;
Expand Down Expand Up @@ -654,7 +664,7 @@ EmbedLiteViewThreadChild::RecvHandleSingleTap(const nsIntPoint& aPoint)
if (sPostAZPCAsJson.singleTap) {
nsString data;
data.AppendPrintf("{ \"x\" : %d, \"y\" : %d }", aPoint.x, aPoint.y);
mHelper->RecvAsyncMessage(NS_LITERAL_STRING("Gesture:SingleTap"), data);
mHelper->DispatchMessageManagerMessage(NS_LITERAL_STRING("Gesture:SingleTap"), data);
}

if (sHandleDefaultAZPC.singleTap) {
Expand All @@ -676,7 +686,7 @@ EmbedLiteViewThreadChild::RecvHandleLongTap(const nsIntPoint& aPoint)
if (sPostAZPCAsJson.longTap) {
nsString data;
data.AppendPrintf("{ \"x\" : %d, \"y\" : %d }", aPoint.x, aPoint.y);
mHelper->RecvAsyncMessage(NS_LITERAL_STRING("Gesture:LongTap"), data);
mHelper->DispatchMessageManagerMessage(NS_LITERAL_STRING("Gesture:LongTap"), data);
}

if (sHandleDefaultAZPC.longTap) {
Expand Down
7 changes: 3 additions & 4 deletions embedding/embedlite/embedthread/EmbedLiteViewThreadChild.h
Expand Up @@ -39,14 +39,13 @@ class EmbedLiteViewThreadChild : public PEmbedLiteViewChild,
}
void ResetInputState();

JSContext* GetJSContext() {
return mHelper ? mHelper->GetJSContext() : nullptr;
}

virtual bool DoSendAsyncMessage(const char16_t* aMessageName, const char16_t* aMessage);
virtual bool DoSendSyncMessage(const char16_t* aMessageName,
const char16_t* aMessage,
InfallibleTArray<nsString>* aJSONRetVal);
virtual bool DoCallRpcMessage(const char16_t* aMessageName,
const char16_t* aMessage,
InfallibleTArray<nsString>* aJSONRetVal);
bool HasMessageListener(const nsAString& aMessageName);
void AddGeckoContentListener(mozilla::layers::GeckoContentController* listener);
void RemoveGeckoContentListener(mozilla::layers::GeckoContentController* listener);
Expand Down
8 changes: 8 additions & 0 deletions embedding/embedlite/embedthread/EmbedLiteViewThreadParent.cpp
Expand Up @@ -454,6 +454,14 @@ EmbedLiteViewThreadParent::RecvSyncMessage(const nsString& aMessage,
return true;
}

bool
EmbedLiteViewThreadParent::AnswerRpcMessage(const nsString& aMessage,
const nsString& aJSON,
InfallibleTArray<nsString>* aJSONRetVal)
{
return RecvSyncMessage(aMessage, aJSON, aJSONRetVal);
}

static inline gfx::SurfaceFormat
_depth_to_gfxformat(int depth)
{
Expand Down
7 changes: 5 additions & 2 deletions embedding/embedlite/embedthread/EmbedLiteViewThreadParent.h
Expand Up @@ -109,10 +109,13 @@ class EmbedLiteViewThreadParent : public PEmbedLiteViewParent,
RecvOnTitleChanged(const nsString& aTitle);

virtual bool RecvAsyncMessage(const nsString& aMessage,
const nsString& aData);
const nsString& aData) MOZ_OVERRIDE;
virtual bool RecvSyncMessage(const nsString& aMessage,
const nsString& aJSON,
InfallibleTArray<nsString>* aJSONRetVal);
InfallibleTArray<nsString>* aJSONRetVal) MOZ_OVERRIDE;
virtual bool AnswerRpcMessage(const nsString& aMessage,
const nsString& aJSON,
InfallibleTArray<nsString>* aJSONRetVal) MOZ_OVERRIDE;
virtual bool
RecvUpdateZoomConstraints(const uint32_t& aPresShellId,
const ViewID& aViewId,
Expand Down
8 changes: 0 additions & 8 deletions embedding/embedlite/modules/EmbedLiteAppService.cpp
Expand Up @@ -245,14 +245,6 @@ NS_IMETHODIMP EmbedLiteAppService::LeaveSecureJSContext()
return NS_OK;
}

JSContext*
EmbedLiteAppService::GetAnyJSContext(uint32_t aWinId)
{
EmbedLiteViewThreadChild* view = sGetViewById(aWinId);
NS_ENSURE_TRUE(view, nullptr);
return view->GetJSContext();
}

NS_IMETHODIMP
EmbedLiteAppService::AddContentListener(uint32_t aWinId, mozilla::layers::GeckoContentController* listener)
{
Expand Down
1 change: 0 additions & 1 deletion embedding/embedlite/modules/EmbedLiteAppService.h
Expand Up @@ -32,7 +32,6 @@ class EmbedLiteAppService : public nsIObserver,

private:
friend class EmbedLiteJSON;
JSContext* GetAnyJSContext(uint32_t aWinID);
std::map<uint64_t, uint32_t> mIDMap;
typedef nsClassHashtable<nsCStringHashKey, nsTArray<nsCOMPtr<nsIEmbedMessageListener> > > MsgListenersArray;
MsgListenersArray mMessageListeners;
Expand Down

0 comments on commit 0b6df23

Please sign in to comment.