2014-11-21 13:56:27 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-11-21 13:56:27 +03:00
|
|
|
/* 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 13:56:27 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-11-21 13:56:27 +03:00
|
|
|
#include "mozilla/dom/BrowserElementBinding.h"
|
2018-11-02 00:37:48 +03:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2014-11-21 13:56:27 +03:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
|
|
|
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsFrameLoader.h"
|
2015-07-10 19:38:44 +03:00
|
|
|
#include "nsIMozBrowserFrame.h"
|
2014-11-21 13:56:27 +03:00
|
|
|
#include "nsINode.h"
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
|
2018-07-24 10:19:25 +03:00
|
|
|
#include "js/Wrapper.h"
|
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
using namespace mozilla::dom;
|
2014-11-21 13:56:27 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
bool nsBrowserElement::IsBrowserElementOrThrow(ErrorResult& aRv) {
|
|
|
|
if (mBrowserElementAPI) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_NODE_TYPE_ERR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsBrowserElement::InitBrowserElementAPI() {
|
2018-03-22 05:43:16 +03:00
|
|
|
RefPtr<nsFrameLoader> frameLoader = GetFrameLoader();
|
2014-11-21 13:56:27 +03:00
|
|
|
NS_ENSURE_TRUE_VOID(frameLoader);
|
|
|
|
|
2018-03-22 05:43:16 +03:00
|
|
|
if (!frameLoader->OwnerIsMozBrowserFrame()) {
|
2014-11-21 13:56:27 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-31 13:21:40 +03:00
|
|
|
if (!mBrowserElementAPI) {
|
|
|
|
mBrowserElementAPI =
|
|
|
|
do_CreateInstance("@mozilla.org/dom/browser-element-api;1");
|
|
|
|
if (NS_WARN_IF(!mBrowserElementAPI)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-21 13:56:27 +03:00
|
|
|
}
|
2018-04-07 01:32:25 +03:00
|
|
|
mBrowserElementAPI->SetFrameLoader(frameLoader);
|
2014-11-21 13:56:27 +03:00
|
|
|
}
|
|
|
|
|
2016-09-09 00:00:12 +03:00
|
|
|
void nsBrowserElement::DestroyBrowserElementFrameScripts() {
|
|
|
|
if (!mBrowserElementAPI) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mBrowserElementAPI->DestroyFrameScripts();
|
|
|
|
}
|
|
|
|
|
2014-11-21 13:56:27 +03: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 13:56:27 +03:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
|
|
|
|
|
|
|
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 13:56:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsBrowserElement::GoBack(ErrorResult& aRv) {
|
2014-11-21 13:56:27 +03:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
|
|
|
|
|
|
|
nsresult rv = mBrowserElementAPI->GoBack();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-11-21 13:56:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsBrowserElement::GoForward(ErrorResult& aRv) {
|
2014-11-21 13:56:27 +03:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
|
|
|
|
|
|
|
nsresult rv = mBrowserElementAPI->GoForward();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-11-21 13:56:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsBrowserElement::Reload(bool aHardReload, ErrorResult& aRv) {
|
2014-11-21 13:56:27 +03:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
|
|
|
|
|
|
|
nsresult rv = mBrowserElementAPI->Reload(aHardReload);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-11-21 13:56:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsBrowserElement::Stop(ErrorResult& aRv) {
|
2014-11-21 13:56:27 +03:00
|
|
|
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
|
|
|
|
|
|
|
|
nsresult rv = mBrowserElementAPI->Stop();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-11-21 13:56:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise> nsBrowserElement::GetCanGoBack(ErrorResult& aRv) {
|
2014-11-21 13:56:27 +03:00
|
|
|
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
|
|
|
|
|
2018-11-02 00:37:48 +03:00
|
|
|
RefPtr<Promise> p;
|
|
|
|
nsresult rv = mBrowserElementAPI->GetCanGoBack(getter_AddRefs(p));
|
2014-11-21 13:56:27 +03:00
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-11-02 00:37:48 +03:00
|
|
|
return p.forget();
|
2014-11-21 13:56:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise> nsBrowserElement::GetCanGoForward(ErrorResult& aRv) {
|
2014-11-21 13:56:27 +03:00
|
|
|
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
|
|
|
|
|
2018-11-02 00:37:48 +03:00
|
|
|
RefPtr<Promise> p;
|
|
|
|
nsresult rv = mBrowserElementAPI->GetCanGoForward(getter_AddRefs(p));
|
2014-11-21 13:56:27 +03:00
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-11-02 00:37:48 +03:00
|
|
|
return p.forget();
|
2014-11-21 13:56:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|