Navigation Menu

Skip to content

Commit

Permalink
[embedlite-components] Entering secure JS context by pushing AutoNoJS…
Browse files Browse the repository at this point in the history
…API to the stack. Contributes to JB#49549
  • Loading branch information
paveltkv authored and rainemak committed Apr 22, 2020
1 parent 8c6f02c commit 907a870
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
7 changes: 2 additions & 5 deletions chromehelper/EmbedChromeListener.cpp
Expand Up @@ -26,6 +26,7 @@
#include "nsIFocusManager.h"
#include "nsIDocShellTreeItem.h"
#include "nsIWebNavigation.h"
#include "mozilla/dom/ScriptSettings.h"

EmbedChromeListener::EmbedChromeListener(nsIDOMWindow* aWin)
: DOMWindow(aWin)
Expand Down Expand Up @@ -100,7 +101,7 @@ EmbedChromeListener::HandleEvent(nsIDOMEvent* aEvent)
uint32_t winid;
mService->GetIDByWindow(window, &winid);
NS_ENSURE_TRUE(winid , NS_ERROR_FAILURE);
mService->EnterSecureJSContext();
mozilla::dom::AutoNoJSAPI noJSAPI();

if (type.EqualsLiteral(MOZ_DOMMetaAdded)) {
messageName.AssignLiteral("chrome:metaadded");
Expand All @@ -123,7 +124,6 @@ EmbedChromeListener::HandleEvent(nsIDOMEvent* aEvent)
bool disabled = true;
disabledIface->GetMozDisabled(&disabled);
if (!disabledIface || disabled) {
mService->LeaveSecureJSContext();
return NS_OK;
}
disabledIface->GetHref(href);
Expand All @@ -135,7 +135,6 @@ EmbedChromeListener::HandleEvent(nsIDOMEvent* aEvent)
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(origTarget);
node->GetOwnerDocument(getter_AddRefs(ownDoc));
if (ownDoc != ctDoc) {
mService->LeaveSecureJSContext();
return NS_OK;
}

Expand Down Expand Up @@ -163,14 +162,12 @@ EmbedChromeListener::HandleEvent(nsIDOMEvent* aEvent)
messageName.AssignLiteral("chrome:winopenclose");
root->SetPropertyAsAString(NS_LITERAL_STRING("type"), type);
} else {
mService->LeaveSecureJSContext();
return NS_OK;
}

nsString outStr;
json->CreateJSON(root, message);
mService->SendAsyncMessage(winid, messageName.get(), message.get());
mService->LeaveSecureJSContext();

return NS_OK;
}
13 changes: 4 additions & 9 deletions prompt/EmbedPromptService.cpp
Expand Up @@ -33,6 +33,7 @@
#include "nsILoginInfo.h"
#include "nsComponentManagerUtils.h"
#include "nsMemory.h"
#include "mozilla/dom/ScriptSettings.h"

// Prompt Factory Implementation

Expand Down Expand Up @@ -235,7 +236,7 @@ EmbedPromptService::AlertCheck(const char16_t* aDialogTitle,

nsresult rv(NS_OK);

mService->EnterSecureJSContext();
mozilla::dom::AutoNoJSAPI noJSAPI();

nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(mWin);
NS_ENSURE_TRUE(utils, NS_ERROR_FAILURE);
Expand Down Expand Up @@ -272,8 +273,6 @@ EmbedPromptService::AlertCheck(const char16_t* aDialogTitle,

rv = utils->LeaveModalState();

mService->LeaveSecureJSContext();

return NS_OK;
}

Expand Down Expand Up @@ -320,7 +319,7 @@ EmbedPromptService::ConfirmCheck(const char16_t* aDialogTitle,

nsresult rv(NS_OK);

mService->EnterSecureJSContext();
mozilla::dom::AutoNoJSAPI noJSAPI();

nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(mWin);
NS_ENSURE_TRUE(utils, NS_ERROR_FAILURE);
Expand Down Expand Up @@ -361,8 +360,6 @@ EmbedPromptService::ConfirmCheck(const char16_t* aDialogTitle,

rv = utils->LeaveModalState();

mService->LeaveSecureJSContext();

return NS_OK;
}

Expand Down Expand Up @@ -416,7 +413,7 @@ EmbedPromptService::Prompt(const char16_t* aDialogTitle,

nsresult rv(NS_OK);

mService->EnterSecureJSContext();
mozilla::dom::AutoNoJSAPI noJSAPI();

nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(mWin);
NS_ENSURE_TRUE(utils, NS_ERROR_FAILURE);
Expand Down Expand Up @@ -463,8 +460,6 @@ EmbedPromptService::Prompt(const char16_t* aDialogTitle,

rv = utils->LeaveModalState();

mService->LeaveSecureJSContext();

return NS_OK;
}

Expand Down
7 changes: 3 additions & 4 deletions touchhelper/EmbedTouchListener.cpp
Expand Up @@ -40,6 +40,7 @@
#include "nsIDOMHTMLAnchorElement.h"
#include "nsIDOMHTMLAreaElement.h"
#include "nsIDOMHTMLImageElement.h"
#include "mozilla/dom/ScriptSettings.h"

using namespace mozilla;

Expand Down Expand Up @@ -129,7 +130,7 @@ void EmbedTouchListener::HandleDoubleTap(const CSSPoint& aPoint, mozilla::Modifi
void
EmbedTouchListener::AnyElementFromPoint(nsIDOMWindow* aWindow, double aX, double aY, nsIDOMElement* *aElem)
{
mService->EnterSecureJSContext();
mozilla::dom::AutoNoJSAPI noJSAPI();
nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(aWindow);
nsCOMPtr<nsIDOMElement> elem;
NS_ENSURE_SUCCESS(utils->ElementFromPoint(aX, aY, true, true, getter_AddRefs(elem)), );
Expand Down Expand Up @@ -163,7 +164,6 @@ EmbedTouchListener::AnyElementFromPoint(nsIDOMWindow* aWindow, double aX, double
if (elem) {
NS_ADDREF(*aElem = elem);
}
mService->LeaveSecureJSContext();

return;
}
Expand Down Expand Up @@ -332,7 +332,7 @@ EmbedTouchListener::GetBoundingContentRect(nsIDOMElement* aElement)
return retRect;
}

mService->EnterSecureJSContext();
mozilla::dom::AutoNoJSAPI noJSAPI();
nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(newWin);
int32_t scrollX = 0, scrollY = 0;
NS_ENSURE_SUCCESS(utils->GetScrollXY(false, &scrollX, &scrollY), retRect);
Expand Down Expand Up @@ -377,7 +377,6 @@ EmbedTouchListener::GetBoundingContentRect(nsIDOMElement* aElement)
r->GetTop(&rtop);
r->GetWidth(&rwidth);
r->GetHeight(&rheight);
mService->LeaveSecureJSContext();

return gfx::Rect(rleft + scrollX,
rtop + scrollY,
Expand Down
7 changes: 3 additions & 4 deletions widgetfactory/nsFilePicker.cpp
Expand Up @@ -18,6 +18,7 @@
#include "nsIDOMWindowUtils.h"
#include <nsISimpleEnumerator.h> // for nsISimpleEnumerator
#include <nsServiceManagerUtils.h> // for do_GetService()
#include "mozilla/dom/ScriptSettings.h"

//-----------------------------

Expand Down Expand Up @@ -186,7 +187,7 @@ NS_IMETHODIMP nsEmbedFilePicker::Show(int16_t* _retval)

nsresult rv;

mService->EnterSecureJSContext();
mozilla::dom::AutoNoJSAPI noJSAPI();
nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(mWin);
NS_ENSURE_TRUE(utils, NS_ERROR_FAILURE);

Expand Down Expand Up @@ -214,7 +215,6 @@ NS_IMETHODIMP nsEmbedFilePicker::Show(int16_t* _retval)
}

rv = utils->LeaveModalState();
mService->LeaveSecureJSContext();

return rv;
}
Expand Down Expand Up @@ -341,12 +341,11 @@ nsEmbedFilePicker::GetDomfile(nsISupports * *aDomfile)
return NS_OK;
}

mService->EnterSecureJSContext();
mozilla::dom::AutoNoJSAPI noJSAPI();
nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(mWin);
nsCOMPtr<nsISupports> file;
utils->WrapDOMFile(localFile, getter_AddRefs(file));
file.forget(aDomfile);
mService->LeaveSecureJSContext();

return NS_OK;
}
Expand Down

0 comments on commit 907a870

Please sign in to comment.