Bug 903311. Remove all ChromeOnly methods on window.history. r=bzbarsky

This commit is contained in:
Johnny Stenback 2013-08-13 21:02:01 -07:00
parent 3e3ee85a07
commit 00517e29d4
3 changed files with 0 additions and 219 deletions

View File

@ -254,208 +254,6 @@ nsHistory::ReplaceState(JSContext* aCx, JS::Handle<JS::Value> aData,
PushOrReplaceState(aCx, aData, aTitle, aUrl, aRv, true);
}
void
nsHistory::GetCurrent(nsString& aRetval, ErrorResult& aRv) const
{
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
aRetval.Truncate();
int32_t curIndex = 0;
nsAutoCString curURL;
nsCOMPtr<nsISHistory> sHistory = GetSessionHistory();
if (!sHistory) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
// Get the current index at session History
sHistory->GetIndex(&curIndex);
nsCOMPtr<nsIHistoryEntry> curEntry;
nsCOMPtr<nsIURI> uri;
// Get the SH entry for the current index
sHistory->GetEntryAtIndex(curIndex, false, getter_AddRefs(curEntry));
if (!curEntry) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
// Get the URI for the current entry
curEntry->GetURI(getter_AddRefs(uri));
if (!uri) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
uri->GetSpec(curURL);
CopyUTF8toUTF16(curURL, aRetval);
}
void
nsHistory::GetPrevious(nsString& aRetval, ErrorResult& aRv) const
{
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
aRetval.Truncate();
int32_t curIndex;
nsAutoCString prevURL;
nsCOMPtr<nsISHistory> sHistory = GetSessionHistory();
if (!sHistory) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
// Get the current index at session History
sHistory->GetIndex(&curIndex);
nsCOMPtr<nsIHistoryEntry> prevEntry;
nsCOMPtr<nsIURI> uri;
// Get the previous SH entry
sHistory->GetEntryAtIndex((curIndex - 1), false, getter_AddRefs(prevEntry));
if (!prevEntry) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
// Get the URI for the previous entry
prevEntry->GetURI(getter_AddRefs(uri));
if (!uri) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
uri->GetSpec(prevURL);
CopyUTF8toUTF16(prevURL, aRetval);
}
void
nsHistory::GetNext(nsString& aRetval, ErrorResult& aRv) const
{
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
aRetval.Truncate();
int32_t curIndex;
nsAutoCString nextURL;
nsCOMPtr<nsISHistory> sHistory = GetSessionHistory();
if (!sHistory) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
// Get the current index at session History
sHistory->GetIndex(&curIndex);
nsCOMPtr<nsIHistoryEntry> nextEntry;
nsCOMPtr<nsIURI> uri;
// Get the next SH entry
sHistory->GetEntryAtIndex((curIndex+1), false, getter_AddRefs(nextEntry));
if (!nextEntry) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
// Get the URI for the next entry
nextEntry->GetURI(getter_AddRefs(uri));
if (!uri) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
uri->GetSpec(nextURL);
CopyUTF8toUTF16(nextURL, aRetval);
}
void
nsHistory::Item(uint32_t aIndex, nsString& aRetval, ErrorResult& aRv)
{
bool unused;
IndexedGetter(aIndex, unused, aRetval, aRv);
}
void
nsHistory::IndexedGetter(uint32_t aIndex, bool &aFound, nsString& aRetval,
ErrorResult& aRv)
{
aRetval.Truncate();
aFound = false;
if (!nsContentUtils::IsCallerChrome()) {
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
return;
}
nsCOMPtr<nsISHistory> session_history = GetSessionHistory();
if (!session_history) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
nsCOMPtr<nsIHistoryEntry> sh_entry;
nsCOMPtr<nsIURI> uri;
aRv = session_history->GetEntryAtIndex(aIndex, false,
getter_AddRefs(sh_entry));
if (aRv.Failed()) {
return;
}
if (sh_entry) {
aRv = sh_entry->GetURI(getter_AddRefs(uri));
}
if (uri) {
nsAutoCString urlCString;
aRv = uri->GetSpec(urlCString);
if (aRv.Failed()) {
return;
}
CopyUTF8toUTF16(urlCString, aRetval);
aFound = true;
}
}
uint32_t
nsHistory::Length()
{
if (!nsContentUtils::IsCallerChrome()) {
return 0;
}
// Get session History from docshell
nsCOMPtr<nsISHistory> sHistory = GetSessionHistory();
if (!sHistory) {
return 0;
}
int32_t len;
nsresult rv = sHistory->GetCount(&len);
if (NS_FAILED(rv) || len < 0) {
return 0;
}
return len;
}
void
nsHistory::PushOrReplaceState(JSContext* aCx, JS::Value aData,
const nsAString& aTitle, const nsAString& aUrl,

View File

@ -47,13 +47,6 @@ public:
void ReplaceState(JSContext* aCx, JS::Handle<JS::Value> aData,
const nsAString& aTitle, const nsAString& aUrl,
mozilla::ErrorResult& aRv);
void GetCurrent(nsString& aRetval, mozilla::ErrorResult& aRv) const;
void GetPrevious(nsString& aRetval, mozilla::ErrorResult& aRv) const;
void GetNext(nsString& aRetval, mozilla::ErrorResult& aRv) const;
void Item(uint32_t aIndex, nsString& aRetval, mozilla::ErrorResult& aRv);
void IndexedGetter(uint32_t aIndex, bool &aFound, nsString& aRetval,
mozilla::ErrorResult& aRv);
uint32_t Length();
protected:
nsIDocShell *GetDocShell() const {

View File

@ -26,14 +26,4 @@ interface History {
void pushState(any data, DOMString title, optional DOMString? url = null);
[Throws]
void replaceState(any data, DOMString title, optional DOMString? url = null);
// Chrome only methods.
[Throws, ChromeOnly]
readonly attribute DOMString current;
[Throws, ChromeOnly]
readonly attribute DOMString previous;
[Throws, ChromeOnly]
readonly attribute DOMString next;
[Throws, ChromeOnly]
getter DOMString? item(unsigned long index);
};