2014-11-21 10:56:27 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=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 "nsBrowserElement.h"
|
|
|
|
|
2014-11-21 10:56:27 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/Services.h"
|
2014-11-21 10:56:27 +00:00
|
|
|
#include "mozilla/dom/BrowserElementBinding.h"
|
|
|
|
#include "mozilla/dom/DOMRequest.h"
|
2014-11-21 10:56:27 +00:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
|
|
|
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsFrameLoader.h"
|
|
|
|
#include "nsIDOMDOMRequest.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsINode.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
2014-11-21 10:56:27 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-11-21 10:56:27 +00:00
|
|
|
static const char kRemoteBrowserPending[] = "remote-browser-pending";
|
|
|
|
static const char kInprocessBrowserShown[] = "inprocess-browser-shown";
|
|
|
|
|
|
|
|
class nsBrowserElement::BrowserShownObserver : public nsIObserver
|
|
|
|
, public nsSupportsWeakReference
|
|
|
|
{
|
|
|
|
public:
|
2014-12-10 22:49:09 +00:00
|
|
|
explicit BrowserShownObserver(nsBrowserElement* aBrowserElement);
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
void AddObserver();
|
|
|
|
void RemoveObserver();
|
|
|
|
private:
|
|
|
|
virtual ~BrowserShownObserver();
|
|
|
|
|
|
|
|
// Weak reference to the browser element. nsBrowserElement has a
|
|
|
|
// reference to us. nsBrowserElement's destructor is responsible to
|
|
|
|
// null out this weak reference via RemoveObserver()
|
|
|
|
nsBrowserElement* mBrowserElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(nsBrowserElement::BrowserShownObserver, nsIObserver, nsISupportsWeakReference)
|
|
|
|
|
|
|
|
nsBrowserElement::BrowserShownObserver::BrowserShownObserver(nsBrowserElement* aBrowserElement)
|
|
|
|
: mBrowserElement(aBrowserElement)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBrowserElement::BrowserShownObserver::~BrowserShownObserver()
|
|
|
|
{
|
|
|
|
RemoveObserver();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserElement::BrowserShownObserver::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const char16_t* aData)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mBrowserElement, NS_OK);
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, kRemoteBrowserPending) ||
|
|
|
|
!strcmp(aTopic, kInprocessBrowserShown)) {
|
|
|
|
nsCOMPtr<nsIFrameLoader> frameLoader = do_QueryInterface(aSubject);
|
|
|
|
nsCOMPtr<nsIFrameLoader> myFrameLoader = mBrowserElement->GetFrameLoader();
|
|
|
|
// The browser element API needs the frameloader to
|
|
|
|
// initialize. We still use the observer to get notified when the
|
|
|
|
// frameloader is created. So we check if the frameloader created
|
|
|
|
// is ours, then initialize the browser element API.
|
|
|
|
if (frameLoader && frameLoader == myFrameLoader) {
|
|
|
|
mBrowserElement->InitBrowserElementAPI();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserElement::BrowserShownObserver::AddObserver()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->AddObserver(this, kRemoteBrowserPending, true);
|
|
|
|
obs->AddObserver(this, kInprocessBrowserShown, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserElement::BrowserShownObserver::RemoveObserver()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->RemoveObserver(this, kRemoteBrowserPending);
|
|
|
|
obs->RemoveObserver(this, kInprocessBrowserShown);
|
|
|
|
}
|
|
|
|
mBrowserElement = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsBrowserElement::IsBrowserElementOrThrow(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (mBrowserElementAPI) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_NODE_TYPE_ERR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-21 10:56:28 +00:00
|
|
|
bool
|
|
|
|
nsBrowserElement::IsNotWidgetOrThrow(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mOwnerIsWidget) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_NODE_TYPE_ERR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-21 10:56:27 +00:00
|
|
|
void
|
|
|
|
nsBrowserElement::InitBrowserElementAPI()
|
|
|
|
{
|
|
|
|
bool isBrowserOrApp;
|
|
|
|
nsCOMPtr<nsIFrameLoader> frameLoader = GetFrameLoader();
|
|
|
|
NS_ENSURE_TRUE_VOID(frameLoader);
|
|
|
|
nsresult rv = frameLoader->GetOwnerIsBrowserOrAppFrame(&isBrowserOrApp);
|
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2014-11-21 10:56:28 +00:00
|
|
|
rv = frameLoader->GetOwnerIsWidget(&mOwnerIsWidget);
|
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2014-11-21 10:56:27 +00:00
|
|
|
|
|
|
|
if (!isBrowserOrApp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mBrowserElementAPI = do_CreateInstance("@mozilla.org/dom/browser-element-api;1");
|
|
|
|
if (mBrowserElementAPI) {
|
|
|
|
mBrowserElementAPI->SetFrameLoader(frameLoader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBrowserElement::nsBrowserElement()
|
2014-11-21 10:56:28 +00:00
|
|
|
: mOwnerIsWidget(false)
|
2014-11-21 10:56:27 +00:00
|
|
|
{
|
|
|
|
mObserver = new BrowserShownObserver(this);
|
|
|
|
mObserver->AddObserver();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBrowserElement::~nsBrowserElement()
|
|
|
|
{
|
|
|
|
mObserver->RemoveObserver();
|
|
|
|
}
|
|
|
|
|
2014-11-21 10:56:27 +00:00
|
|
|
void
|
|
|
|
nsBrowserElement::SetVisible(bool aVisible, ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
|
|
|
|
|
|
|
nsresult rv = mBrowserElementAPI->SetVisible(aVisible);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 10:56:27 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-21 10:56:27 +00:00
|
|
|
nsBrowserElement::GetVisible(ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDOMRequest> req;
|
|
|
|
nsresult rv = mBrowserElementAPI->GetVisible(getter_AddRefs(req));
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return req.forget().downcast<DOMRequest>();
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserElement::SetActive(bool aVisible, ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
|
|
|
|
|
|
|
nsresult rv = mBrowserElementAPI->SetActive(aVisible);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsBrowserElement::GetActive(ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), false);
|
|
|
|
|
|
|
|
bool isActive;
|
|
|
|
nsresult rv = mBrowserElementAPI->GetActive(&isActive);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isActive;
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserElement::SendMouseEvent(const nsAString& aType,
|
|
|
|
uint32_t aX,
|
|
|
|
uint32_t aY,
|
|
|
|
uint32_t aButton,
|
|
|
|
uint32_t aClickCount,
|
|
|
|
uint32_t aModifiers,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
2014-11-21 10:56:28 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsNotWidgetOrThrow(aRv));
|
2014-11-21 10:56:27 +00:00
|
|
|
|
|
|
|
nsresult rv = mBrowserElementAPI->SendMouseEvent(aType,
|
|
|
|
aX,
|
|
|
|
aY,
|
|
|
|
aButton,
|
|
|
|
aClickCount,
|
|
|
|
aModifiers);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserElement::SendTouchEvent(const nsAString& aType,
|
2014-11-21 10:56:27 +00:00
|
|
|
const Sequence<uint32_t>& aIdentifiers,
|
|
|
|
const Sequence<int32_t>& aXs,
|
|
|
|
const Sequence<int32_t>& aYs,
|
|
|
|
const Sequence<uint32_t>& aRxs,
|
|
|
|
const Sequence<uint32_t>& aRys,
|
|
|
|
const Sequence<float>& aRotationAngles,
|
|
|
|
const Sequence<float>& aForces,
|
2014-11-21 10:56:27 +00:00
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t aModifiers,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
2014-11-21 10:56:28 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsNotWidgetOrThrow(aRv));
|
2014-11-21 10:56:27 +00:00
|
|
|
|
|
|
|
if (aIdentifiers.Length() != aCount ||
|
|
|
|
aXs.Length() != aCount ||
|
|
|
|
aYs.Length() != aCount ||
|
|
|
|
aRxs.Length() != aCount ||
|
|
|
|
aRys.Length() != aCount ||
|
|
|
|
aRotationAngles.Length() != aCount ||
|
|
|
|
aForces.Length() != aCount) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = mBrowserElementAPI->SendTouchEvent(aType,
|
|
|
|
aIdentifiers.Elements(),
|
|
|
|
aXs.Elements(),
|
|
|
|
aYs.Elements(),
|
|
|
|
aRxs.Elements(),
|
|
|
|
aRys.Elements(),
|
|
|
|
aRotationAngles.Elements(),
|
|
|
|
aForces.Elements(),
|
|
|
|
aCount,
|
|
|
|
aModifiers);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserElement::GoBack(ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
2014-11-21 10:56:28 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsNotWidgetOrThrow(aRv));
|
2014-11-21 10:56:27 +00:00
|
|
|
|
|
|
|
nsresult rv = mBrowserElementAPI->GoBack();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserElement::GoForward(ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
2014-11-21 10:56:28 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsNotWidgetOrThrow(aRv));
|
2014-11-21 10:56:27 +00:00
|
|
|
|
|
|
|
nsresult rv = mBrowserElementAPI->GoForward();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserElement::Reload(bool aHardReload, ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
2014-11-21 10:56:28 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsNotWidgetOrThrow(aRv));
|
2014-11-21 10:56:27 +00:00
|
|
|
|
|
|
|
nsresult rv = mBrowserElementAPI->Reload(aHardReload);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserElement::Stop(ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
2014-11-21 10:56:28 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsNotWidgetOrThrow(aRv));
|
2014-11-21 10:56:27 +00:00
|
|
|
|
|
|
|
nsresult rv = mBrowserElementAPI->Stop();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 10:56:27 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-21 10:56:27 +00:00
|
|
|
nsBrowserElement::Download(const nsAString& aUrl,
|
2014-11-21 10:56:27 +00:00
|
|
|
const BrowserElementDownloadOptions& aOptions,
|
2014-11-21 10:56:27 +00:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
|
2014-11-21 10:56:28 +00:00
|
|
|
NS_ENSURE_TRUE(IsNotWidgetOrThrow(aRv), nullptr);
|
2014-11-21 10:56:27 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDOMRequest> req;
|
2014-11-21 10:56:28 +00:00
|
|
|
nsCOMPtr<nsIXPConnectWrappedJS> wrappedObj = do_QueryInterface(mBrowserElementAPI);
|
|
|
|
MOZ_ASSERT(wrappedObj, "Failed to get wrapped JS from XPCOM component.");
|
2014-11-21 10:56:27 +00:00
|
|
|
AutoJSAPI jsapi;
|
2014-11-21 10:56:28 +00:00
|
|
|
jsapi.Init(wrappedObj->GetJSObject());
|
|
|
|
JSContext* cx = jsapi.cx();
|
|
|
|
JS::Rooted<JS::Value> options(cx);
|
|
|
|
if (!ToJSValue(cx, aOptions, &options)) {
|
2014-11-21 10:56:27 +00:00
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsresult rv = mBrowserElementAPI->Download(aUrl, options, getter_AddRefs(req));
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return req.forget().downcast<DOMRequest>();
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 10:56:27 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-21 10:56:27 +00:00
|
|
|
nsBrowserElement::PurgeHistory(ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
|
2014-11-21 10:56:28 +00:00
|
|
|
NS_ENSURE_TRUE(IsNotWidgetOrThrow(aRv), nullptr);
|
2014-11-21 10:56:27 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDOMRequest> req;
|
|
|
|
nsresult rv = mBrowserElementAPI->PurgeHistory(getter_AddRefs(req));
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return req.forget().downcast<DOMRequest>();
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 10:56:27 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-21 10:56:27 +00:00
|
|
|
nsBrowserElement::GetScreenshot(uint32_t aWidth,
|
|
|
|
uint32_t aHeight,
|
2014-11-21 10:56:27 +00:00
|
|
|
const nsAString& aMimeType,
|
2014-11-21 10:56:27 +00:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
|
2014-11-21 10:56:28 +00:00
|
|
|
NS_ENSURE_TRUE(IsNotWidgetOrThrow(aRv), nullptr);
|
2014-11-21 10:56:27 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDOMRequest> req;
|
|
|
|
nsresult rv = mBrowserElementAPI->GetScreenshot(aWidth, aHeight, aMimeType,
|
|
|
|
getter_AddRefs(req));
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
if (rv == NS_ERROR_INVALID_ARG) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
} else {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return req.forget().downcast<DOMRequest>();
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserElement::Zoom(float aZoom, ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
2014-11-21 10:56:28 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsNotWidgetOrThrow(aRv));
|
|
|
|
|
2014-11-21 10:56:27 +00:00
|
|
|
nsresult rv = mBrowserElementAPI->Zoom(aZoom);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 10:56:27 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-21 10:56:27 +00:00
|
|
|
nsBrowserElement::GetCanGoBack(ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
|
2014-11-21 10:56:28 +00:00
|
|
|
NS_ENSURE_TRUE(IsNotWidgetOrThrow(aRv), nullptr);
|
2014-11-21 10:56:27 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDOMRequest> req;
|
|
|
|
nsresult rv = mBrowserElementAPI->GetCanGoBack(getter_AddRefs(req));
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return req.forget().downcast<DOMRequest>();
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 10:56:27 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-21 10:56:27 +00:00
|
|
|
nsBrowserElement::GetCanGoForward(ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
|
2014-11-21 10:56:28 +00:00
|
|
|
NS_ENSURE_TRUE(IsNotWidgetOrThrow(aRv), nullptr);
|
2014-11-21 10:56:27 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDOMRequest> req;
|
|
|
|
nsresult rv = mBrowserElementAPI->GetCanGoForward(getter_AddRefs(req));
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return req.forget().downcast<DOMRequest>();
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 10:56:27 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-21 10:56:27 +00:00
|
|
|
nsBrowserElement::GetContentDimensions(ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
|
2014-11-21 10:56:28 +00:00
|
|
|
NS_ENSURE_TRUE(IsNotWidgetOrThrow(aRv), nullptr);
|
2014-11-21 10:56:27 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDOMRequest> req;
|
|
|
|
nsresult rv = mBrowserElementAPI->GetContentDimensions(getter_AddRefs(req));
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return req.forget().downcast<DOMRequest>();
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-21 10:56:27 +00:00
|
|
|
nsBrowserElement::AddNextPaintListener(BrowserElementNextPaintEventCallback& aListener,
|
2014-11-21 10:56:27 +00:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
|
|
|
|
|
|
|
CallbackObjectHolder<BrowserElementNextPaintEventCallback,
|
|
|
|
nsIBrowserElementNextPaintListener> holder(&aListener);
|
|
|
|
nsCOMPtr<nsIBrowserElementNextPaintListener> listener = holder.ToXPCOMCallback();
|
|
|
|
|
|
|
|
nsresult rv = mBrowserElementAPI->AddNextPaintListener(listener);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-21 10:56:27 +00:00
|
|
|
nsBrowserElement::RemoveNextPaintListener(BrowserElementNextPaintEventCallback& aListener,
|
2014-11-21 10:56:27 +00:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
|
|
|
|
|
|
|
CallbackObjectHolder<BrowserElementNextPaintEventCallback,
|
|
|
|
nsIBrowserElementNextPaintListener> holder(&aListener);
|
|
|
|
nsCOMPtr<nsIBrowserElementNextPaintListener> listener = holder.ToXPCOMCallback();
|
|
|
|
|
|
|
|
nsresult rv = mBrowserElementAPI->RemoveNextPaintListener(listener);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 10:56:27 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-21 10:56:27 +00:00
|
|
|
nsBrowserElement::SetInputMethodActive(bool aIsActive,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2014-11-21 10:56:27 +00:00
|
|
|
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFrameLoader> frameLoader = GetFrameLoader();
|
|
|
|
if (!frameLoader) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> ownerElement;
|
|
|
|
nsresult rv = frameLoader->GetOwnerElement(getter_AddRefs(ownerElement));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(ownerElement);
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = node->NodePrincipal();
|
|
|
|
if (!nsContentUtils::IsExactSitePermAllow(principal, "input-manage")) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDOMRequest> req;
|
|
|
|
rv = mBrowserElementAPI->SetInputMethodActive(aIsActive,
|
|
|
|
getter_AddRefs(req));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
if (rv == NS_ERROR_INVALID_ARG) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
} else {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return req.forget().downcast<DOMRequest>();
|
2014-11-21 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|