Skip to content

Commit

Permalink
Merge branch 'omp-jb50924' into 'master'
Browse files Browse the repository at this point in the history
[sailfishos][embedlite] Add an API to load desktop version of the site. Contributes to JB#50924

See merge request mer-core/gecko-dev!207
  • Loading branch information
rainemak committed Feb 15, 2021
2 parents 777f234 + fff2318 commit 94e926f
Show file tree
Hide file tree
Showing 26 changed files with 180 additions and 44 deletions.
4 changes: 2 additions & 2 deletions embedding/embedlite/EmbedLiteApp.cpp
Expand Up @@ -455,7 +455,7 @@ void EmbedLiteApp::RemoveObservers(const std::vector<std::string>& observersList
}

EmbedLiteView*
EmbedLiteApp::CreateView(EmbedLiteWindow* aWindow, uint32_t aParent, bool aIsPrivateWindow)
EmbedLiteApp::CreateView(EmbedLiteWindow* aWindow, uint32_t aParent, bool aIsPrivateWindow, bool isDesktopMode)
{
LOGT();
NS_ASSERTION(mState == INITIALIZED, "The app must be up and runnning by now");
Expand All @@ -464,7 +464,7 @@ EmbedLiteApp::CreateView(EmbedLiteWindow* aWindow, uint32_t aParent, bool aIsPri

PEmbedLiteViewParent* viewParent = static_cast<PEmbedLiteViewParent*>(
mAppParent->SendPEmbedLiteViewConstructor(aWindow->GetUniqueID(), sViewCreateID,
aParent, aIsPrivateWindow));
aParent, aIsPrivateWindow, isDesktopMode));
EmbedLiteView* view = new EmbedLiteView(this, aWindow, viewParent, sViewCreateID);
mViews[sViewCreateID] = view;
return view;
Expand Down
2 changes: 1 addition & 1 deletion embedding/embedlite/EmbedLiteApp.h
Expand Up @@ -110,7 +110,7 @@ class EmbedLiteApp
// Must be called from same thread as StartChildThread, and before Stop()
virtual bool StopChildThread();

virtual EmbedLiteView* CreateView(EmbedLiteWindow* aWindow, uint32_t aParent = 0, bool aIsPrivateWindow = false);
virtual EmbedLiteView* CreateView(EmbedLiteWindow* aWindow, uint32_t aParent = 0, bool aIsPrivateWindow = false, bool isDesktopMode = false);
virtual EmbedLiteWindow* CreateWindow(int width, int height);
virtual EmbedLiteSecurity* CreateSecurity(const char *aStatus, unsigned int aState) const;
virtual void DestroyView(EmbedLiteView* aView);
Expand Down
8 changes: 8 additions & 0 deletions embedding/embedlite/EmbedLiteView.cpp
Expand Up @@ -111,6 +111,14 @@ EmbedLiteView::SetIsFocused(bool aIsFocused)
Unused << mViewParent->SendSetIsFocused(aIsFocused);
}

void
EmbedLiteView::SetDesktopMode(bool aDesktopMode)
{
LOGT();
NS_ENSURE_TRUE(mViewParent, );
Unused << mViewParent->SendSetDesktopMode(aDesktopMode);
}

void
EmbedLiteView::SetThrottlePainting(bool aThrottle)
{
Expand Down
1 change: 1 addition & 0 deletions embedding/embedlite/EmbedLiteView.h
Expand Up @@ -78,6 +78,7 @@ class EmbedLiteView
virtual void LoadURL(const char* aUrl);
virtual void SetIsActive(bool);
virtual void SetIsFocused(bool);
virtual void SetDesktopMode(bool);
virtual void SetThrottlePainting(bool);
virtual void SuspendTimeouts();
virtual void ResumeTimeouts();
Expand Down
2 changes: 1 addition & 1 deletion embedding/embedlite/PEmbedLiteApp.ipdl
Expand Up @@ -22,7 +22,7 @@ parent:
async PrefsArrayInitialized(Pref[] prefs);

child:
async PEmbedLiteView(uint32_t windowId, uint32_t id, uint32_t parentId, bool isPrivateWindow);
async PEmbedLiteView(uint32_t windowId, uint32_t id, uint32_t parentId, bool isPrivateWindow, bool isDesktopMode);
async PEmbedLiteWindow(uint16_t width, uint16_t height, uint32_t id);
async PreDestroy();
async SetBoolPref(nsCString name, bool value);
Expand Down
1 change: 1 addition & 0 deletions embedding/embedlite/PEmbedLiteView.ipdl
Expand Up @@ -50,6 +50,7 @@ child:
async LoadFrameScript(nsString uri);
async SetIsActive(bool aIsActive);
async SetIsFocused(bool aIsFocused);
async SetDesktopMode(bool aDesktopMode);
async SetThrottlePainting(bool aThrottle);
async SetMargins(int top, int right, int bottom, int left);
async ScheduleUpdate();
Expand Down
5 changes: 3 additions & 2 deletions embedding/embedlite/embedprocess/EmbedLiteAppProcessChild.cpp
Expand Up @@ -165,15 +165,16 @@ EmbedLiteAppProcessChild::QuickExit()

PEmbedLiteViewChild*
EmbedLiteAppProcessChild::AllocPEmbedLiteViewChild(const uint32_t& windowId, const uint32_t& id,
const uint32_t& parentId, const bool& isPrivateWindow)
const uint32_t& parentId, const bool& isPrivateWindow,
const bool& isDesktopMode)
{
LOGT("id:%u, parentId:%u", id, parentId);
static bool sViewInitializeOnce = false;
if (!sViewInitializeOnce) {
gfxPlatform::GetPlatform();
sViewInitializeOnce = true;
}
EmbedLiteViewProcessChild* view = new EmbedLiteViewProcessChild(windowId, id, parentId, isPrivateWindow);
EmbedLiteViewProcessChild* view = new EmbedLiteViewProcessChild(windowId, id, parentId, isPrivateWindow, isDesktopMode);
view->AddRef();
return view;
}
Expand Down
8 changes: 5 additions & 3 deletions embedding/embedlite/embedprocess/EmbedLiteAppProcessChild.h
Expand Up @@ -40,9 +40,11 @@ class EmbedLiteAppProcessChild : public EmbedLiteAppBaseChild

protected:
virtual PEmbedLiteViewChild* AllocPEmbedLiteViewChild(const uint32_t& windowId,
const uint32_t& id,
const uint32_t& parentId,
const bool& isPrivateWindow) override;
const uint32_t& id,
const uint32_t& parentId,
const bool& isPrivateWindow,
const bool& isDesktopMode) override;

virtual PEmbedLiteWindowChild* AllocPEmbedLiteWindowChild(const uint16_t& width, const uint16_t& height,
const uint32_t& id) override;

Expand Down
Expand Up @@ -232,7 +232,11 @@ EmbedLiteAppProcessParent::RecvObserve(const nsCString& topic, const nsString& d
}

PEmbedLiteViewParent*
EmbedLiteAppProcessParent::AllocPEmbedLiteViewParent(const uint32_t& windowId, const uint32_t& id, const uint32_t& parentId, const bool& isPrivateWindow)
EmbedLiteAppProcessParent::AllocPEmbedLiteViewParent(const uint32_t& windowId,
const uint32_t& id,
const uint32_t& parentId,
const bool& isPrivateWindow,
const bool& isDesktopMode)
{
LOGT();

Expand All @@ -242,7 +246,7 @@ EmbedLiteAppProcessParent::AllocPEmbedLiteViewParent(const uint32_t& windowId, c
mozilla::layers::CompositorThreadHolder::Start();
}

EmbedLiteViewProcessParent* p = new EmbedLiteViewProcessParent(windowId, id, parentId, isPrivateWindow);
EmbedLiteViewProcessParent* p = new EmbedLiteViewProcessParent(windowId, id, parentId, isPrivateWindow, isDesktopMode);
p->AddRef();
return p;
}
Expand Down
Expand Up @@ -42,7 +42,7 @@ class EmbedLiteAppProcessParent : public PEmbedLiteAppParent
virtual mozilla::ipc::IPCResult RecvObserve(const nsCString &topic,
const nsString &data) override;

virtual PEmbedLiteViewParent *AllocPEmbedLiteViewParent(const uint32_t &windowId, const uint32_t &id, const uint32_t &parentId, const bool&);
virtual PEmbedLiteViewParent *AllocPEmbedLiteViewParent(const uint32_t &windowId, const uint32_t &id, const uint32_t &parentId, const bool&, const bool&);

virtual bool DeallocPEmbedLiteViewParent(PEmbedLiteViewParent *aActor);
virtual PEmbedLiteWindowParent *AllocPEmbedLiteWindowParent(const uint16_t &width, const uint16_t &height, const uint32_t &id) override;
Expand Down
Expand Up @@ -10,10 +10,11 @@ namespace embedlite {

MOZ_IMPLICIT
EmbedLiteViewProcessChild::EmbedLiteViewProcessChild(const uint32_t& windowId,
const uint32_t& id,
const uint32_t& parentId,
const bool& isPrivateWindow)
: EmbedLiteViewBaseChild(windowId, id, parentId, isPrivateWindow)
const uint32_t& id,
const uint32_t& parentId,
const bool& isPrivateWindow,
const bool& isDesktopMode)
: EmbedLiteViewBaseChild(windowId, id, parentId, isPrivateWindow, isDesktopMode)
{
LOGT();
}
Expand Down
3 changes: 2 additions & 1 deletion embedding/embedlite/embedprocess/EmbedLiteViewProcessChild.h
Expand Up @@ -17,7 +17,8 @@ class EmbedLiteViewProcessChild : public EmbedLiteViewBaseChild
MOZ_IMPLICIT EmbedLiteViewProcessChild(const uint32_t& windowId,
const uint32_t& id,
const uint32_t& parentId,
const bool& isPrivateWindow);
const bool& isPrivateWindow,
const bool& isDesktopMode);

protected:
virtual void OnGeckoWindowInitialized();
Expand Down
Expand Up @@ -6,10 +6,11 @@ namespace mozilla {
namespace embedlite {

MOZ_IMPLICIT EmbedLiteViewProcessParent::EmbedLiteViewProcessParent(const uint32_t& windowId,
const uint32_t& id,
const uint32_t& parentId,
const bool& isPrivateWindow)
: EmbedLiteViewBaseParent(windowId, id, parentId, isPrivateWindow)
const uint32_t& id,
const uint32_t& parentId,
const bool& isPrivateWindow,
const bool& isDesktopMode)
: EmbedLiteViewBaseParent(windowId, id, parentId, isPrivateWindow, isDesktopMode)
{
LOGT();
}
Expand Down
7 changes: 4 additions & 3 deletions embedding/embedlite/embedprocess/EmbedLiteViewProcessParent.h
Expand Up @@ -16,9 +16,10 @@ class EmbedLiteViewProcessParent : public EmbedLiteViewBaseParent
{
public:
MOZ_IMPLICIT EmbedLiteViewProcessParent(const uint32_t& windowId,
const uint32_t& id,
const uint32_t& parentId,
const bool&);
const uint32_t& id,
const uint32_t& parentId,
const bool& isPrivateWindow,
const bool& isDesktopMode);
virtual ~EmbedLiteViewProcessParent() override;

private:
Expand Down
113 changes: 109 additions & 4 deletions embedding/embedlite/embedshared/EmbedLiteViewBaseChild.cpp
Expand Up @@ -9,6 +9,7 @@
#include "EmbedLiteAppThreadChild.h"
#include "nsWindow.h"

#include "nsIURIMutator.h"
#include "mozilla/Unused.h"

#include "nsEmbedCID.h"
Expand Down Expand Up @@ -54,6 +55,15 @@ using namespace mozilla::widget;
namespace mozilla {
namespace embedlite {

// This should be removed and used common StartsWith. But that's not available => simpler to copy for now.
template <int N>
static bool StartsWith(const nsACString& string, const char (&prefix)[N]) {
if (N - 1 > string.Length()) {
return false;
}
return memcmp(string.Data(), prefix, N - 1) == 0;
}

static struct {
bool viewport;
bool scroll;
Expand Down Expand Up @@ -90,7 +100,8 @@ static void ReadAZPCPrefs()
}

EmbedLiteViewBaseChild::EmbedLiteViewBaseChild(const uint32_t& aWindowId, const uint32_t& aId,
const uint32_t& aParentId, const bool& isPrivateWindow)
const uint32_t& aParentId, const bool& isPrivateWindow,
const bool& isDesktopMode)
: mId(aId)
, mOuterId(0)
, mWindow(nullptr)
Expand All @@ -115,12 +126,13 @@ EmbedLiteViewBaseChild::EmbedLiteViewBaseChild(const uint32_t& aWindowId, const
mWindow = EmbedLiteAppBaseChild::GetInstance()->GetWindowByID(aWindowId);
MOZ_ASSERT(mWindow != nullptr);

MessageLoop::current()->PostTask(NewRunnableMethod<const uint32_t, const bool>
MessageLoop::current()->PostTask(NewRunnableMethod<const uint32_t, const bool, const bool>
("mozilla::embedlite::EmbedLiteViewBaseChild::InitGeckoWindow",
this,
&EmbedLiteViewBaseChild::InitGeckoWindow,
aParentId,
isPrivateWindow));
isPrivateWindow,
isDesktopMode));
}

NS_IMETHODIMP EmbedLiteViewBaseChild::QueryInterface(REFNSIID aIID, void **aInstancePtr)
Expand Down Expand Up @@ -150,6 +162,13 @@ EmbedLiteViewBaseChild::ActorDestroy(ActorDestroyReason aWhy)
mozilla::ipc::IPCResult EmbedLiteViewBaseChild::RecvDestroy()
{
LOGT("destroy");

nsCOMPtr<nsIObserverService> observerService =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
if (observerService) {
observerService->NotifyObservers(mDOMWindow, "embedliteviewdestroyed", nullptr);
}

EmbedLiteAppService::AppService()->UnregisterView(mId);
if (mHelper)
mHelper->Unload();
Expand All @@ -168,7 +187,7 @@ mozilla::ipc::IPCResult EmbedLiteViewBaseChild::RecvDestroy()
}

void
EmbedLiteViewBaseChild::InitGeckoWindow(const uint32_t parentId, const bool isPrivateWindow)
EmbedLiteViewBaseChild::InitGeckoWindow(const uint32_t parentId, const bool isPrivateWindow, const bool isDesktopMode)
{
if (!mWindow) {
LOGT("Init called for already destroyed object");
Expand Down Expand Up @@ -322,6 +341,8 @@ EmbedLiteViewBaseChild::InitGeckoWindow(const uint32_t parentId, const bool isPr
}
};

SetDesktopMode(isDesktopMode);

OnGeckoWindowInitialized();
mHelper->OpenIPC();

Expand Down Expand Up @@ -621,6 +642,90 @@ mozilla::ipc::IPCResult EmbedLiteViewBaseChild::RecvSetIsFocused(const bool &aIs
return IPC_OK();
}

mozilla::ipc::IPCResult EmbedLiteViewBaseChild::RecvSetDesktopMode(const bool &aDesktopMode)
{
LOGT("aDesktopMode:%d", aDesktopMode);

SetDesktopMode(aDesktopMode);

return IPC_OK();
}

void EmbedLiteViewBaseChild::SetDesktopMode(const bool aDesktopMode)
{
LOGT("aDesktopMode:%d", aDesktopMode);

if (!SetDesktopModeInternal(aDesktopMode)) {
return;
}

nsCOMPtr<nsIDocument> document = mHelper->GetDocument();

nsIURI* currentURI = document->GetDocumentURI();

// Only reload the page for http/https schemes
bool isValidScheme =
(NS_SUCCEEDED(currentURI->SchemeIs("http", &isValidScheme)) &&
isValidScheme) ||
(NS_SUCCEEDED(currentURI->SchemeIs("https", &isValidScheme)) &&
isValidScheme);

if (!isValidScheme) {
return;
}

nsCOMPtr<nsIURI> clonedURI;
currentURI->Clone(getter_AddRefs(clonedURI));
NS_ENSURE_TRUE(clonedURI, );

nsAutoCString host;
nsresult rv = clonedURI->GetHost(host);

if (StartsWith(host, "www.")) {
host.Cut(0, 4);
} else if (StartsWith(host, "mobile.")) {
host.Cut(0, 7);
} else if (StartsWith(host, "m.")) {
host.Cut(0, 2);
}

rv = NS_MutateURI(clonedURI).SetHost(host).Finalize(clonedURI);
NS_ENSURE_SUCCESS(rv, );

nsAutoCString url;
clonedURI->GetSpec(url);

// We need LOAD_FLAGS_BYPASS_CACHE here since we're changing the User-Agent
// string, and servers typically don't use the Vary: User-Agent header, so
// not doing this means that we'd get some of the previously cached content.
uint32_t flags = nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE |
nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY;

NS_ENSURE_TRUE(mWebNavigation, );
mWebNavigation->LoadURI(NS_ConvertUTF8toUTF16(url).get(),
flags,
nullptr, nullptr,
nullptr, nsContentUtils::GetSystemPrincipal());
}

bool EmbedLiteViewBaseChild::SetDesktopModeInternal(const bool aDesktopMode) {
NS_ENSURE_TRUE(mDOMWindow, false);

if (mDOMWindow->IsDesktopModeViewport() == aDesktopMode) {
return false;
}

mDOMWindow->SetDesktopModeViewport(aDesktopMode);

nsCOMPtr<nsIObserverService> observerService =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
if (observerService) {
observerService->NotifyObservers(mDOMWindow, "embedliteviewdesktopmodechanged", mDOMWindow->IsDesktopModeViewport() ? u"true" : u"false");
return true;
}
return false;
}

mozilla::ipc::IPCResult EmbedLiteViewBaseChild::RecvSetThrottlePainting(const bool &aThrottle)
{
LOGT("aThrottle:%d", aThrottle);
Expand Down
7 changes: 5 additions & 2 deletions embedding/embedlite/embedshared/EmbedLiteViewBaseChild.h
Expand Up @@ -42,7 +42,7 @@ class EmbedLiteViewBaseChild : public PEmbedLiteViewChild,

public:
EmbedLiteViewBaseChild(const uint32_t& windowId, const uint32_t& id,
const uint32_t& parentId, const bool& isPrivateWindow);
const uint32_t& parentId, const bool& isPrivateWindow, const bool &isDesktopMode);

NS_DECL_NSIEMBEDBROWSERCHROMELISTENER
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
Expand Down Expand Up @@ -143,6 +143,7 @@ class EmbedLiteViewBaseChild : public PEmbedLiteViewChild,

virtual mozilla::ipc::IPCResult RecvSetIsActive(const bool &) override;
virtual mozilla::ipc::IPCResult RecvSetIsFocused(const bool &) override;
virtual mozilla::ipc::IPCResult RecvSetDesktopMode(const bool &) override;
virtual mozilla::ipc::IPCResult RecvSetThrottlePainting(const bool &) override;
virtual mozilla::ipc::IPCResult RecvSetMargins(const int&, const int&, const int&, const int&) override;
virtual mozilla::ipc::IPCResult RecvScheduleUpdate();
Expand Down Expand Up @@ -213,9 +214,11 @@ class EmbedLiteViewBaseChild : public PEmbedLiteViewChild,
friend class EmbedLiteAppThreadChild;
friend class EmbedLiteAppBaseChild;

void InitGeckoWindow(const uint32_t parentId, const bool isPrivateWindow);
void InitGeckoWindow(const uint32_t parentId, const bool isPrivateWindow, const bool isDesktopMode);
void InitEvent(WidgetGUIEvent& event, nsIntPoint* aPoint = nullptr);
nsresult DispatchKeyPressEvent(nsIWidget *widget, const EventMessage &message, const int &domKeyCode, const int &gmodifiers, const int &charCode);
void SetDesktopMode(const bool aDesktopMode);
bool SetDesktopModeInternal(const bool aDesktopMode);

uint32_t mId;
uint64_t mOuterId;
Expand Down

0 comments on commit 94e926f

Please sign in to comment.