зеркало из https://github.com/mozilla/gecko-dev.git
Bug 760802 - Add JS nativeHandler attribute for nsIBaseWindow. r=roc
This commit is contained in:
Родитель
15565e885f
Коммит
afd9098bb7
|
@ -4901,6 +4901,13 @@ nsDocShell::SetParentNativeWindow(nativeWindow parentNativeWindow)
|
|||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetNativeHandle(nsAString& aNativeHandle)
|
||||
{
|
||||
// the nativeHandle should be accessed from nsIXULWindow
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetVisibility(bool * aVisibility)
|
||||
{
|
||||
|
|
|
@ -583,6 +583,13 @@ nsDocShellTreeOwner::SetParentNativeWindow(nativeWindow aParentNativeWindow)
|
|||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShellTreeOwner::GetNativeHandle(nsAString& aNativeHandle)
|
||||
{
|
||||
// the nativeHandle should be accessed from nsIXULWindow
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShellTreeOwner::GetVisibility(bool* aVisibility)
|
||||
{
|
||||
|
|
|
@ -1378,6 +1378,12 @@ NS_IMETHODIMP nsWebBrowser::SetParentNativeWindow(nativeWindow aParentNativeWind
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWebBrowser::GetNativeHandle(nsAString& aNativeHandle)
|
||||
{
|
||||
// the nativeHandle should be accessed from nsIXULWindow
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWebBrowser::GetVisibility(bool* visibility)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(visibility);
|
||||
|
|
|
@ -152,6 +152,17 @@ interface nsIBaseWindow : nsISupports
|
|||
*/
|
||||
attribute nativeWindow parentNativeWindow;
|
||||
|
||||
/*
|
||||
This is the handle (HWND, GdkWindow*, ...) to the native window of the
|
||||
control, exposed as a DOMString.
|
||||
|
||||
@return DOMString in hex format with "0x" prepended, or empty string if
|
||||
mainWidget undefined
|
||||
|
||||
@throws NS_ERROR_NOT_IMPLEMENTED for non-XULWindows
|
||||
*/
|
||||
readonly attribute DOMString nativeHandle;
|
||||
|
||||
/*
|
||||
Attribute controls the visibility of the object behind this interface.
|
||||
Setting this attribute to false will hide the control. Setting it to
|
||||
|
|
|
@ -30,6 +30,9 @@ endif
|
|||
|
||||
CPP_UNIT_TESTS += TestAppShellSteadyState.cpp
|
||||
|
||||
MOCHITEST_FILES = test_bug760802.html \
|
||||
$(NULL)
|
||||
|
||||
MOCHITEST_CHROME_FILES = test_bug343416.xul \
|
||||
test_bug429954.xul \
|
||||
window_bug429954.xul \
|
||||
|
@ -92,14 +95,14 @@ MOCHITEST_CHROME_FILES += taskbar_previews.xul \
|
|||
window_mouse_scroll_win.html \
|
||||
$(NULL)
|
||||
|
||||
MOCHITEST_FILES = test_bug565392.html \
|
||||
MOCHITEST_FILES += test_bug565392.html \
|
||||
test_picker_no_crash.html \
|
||||
window_picker_no_crash_child.html \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
|
||||
MOCHITEST_FILES = plugin_scroll_invalidation.html \
|
||||
MOCHITEST_FILES += plugin_scroll_invalidation.html \
|
||||
test_plugin_scroll_invalidation.html \
|
||||
$(NULL)
|
||||
endif
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=760802
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 760802</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=760802">Mozilla Bug 760802</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<iframe id="iframe_not_editable" width="300" height="150"
|
||||
src="data:text/html,<html><body></body></html>"></iframe><br/>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
|
||||
function getBaseWindowInterface(win) {
|
||||
return win.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShellTreeItem)
|
||||
.treeOwner
|
||||
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.nsIBaseWindow;
|
||||
}
|
||||
|
||||
function shouldThrow(fun) {
|
||||
try {
|
||||
fun.call();
|
||||
return false;
|
||||
} catch (e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function doesntThrow(fun) !shouldThrow(fun)
|
||||
|
||||
|
||||
var baseWindow = getBaseWindowInterface(window);
|
||||
var nativeHandle = baseWindow.nativeHandle;
|
||||
$("display").innerHTML = "found nativeHandle for this window: "+nativeHandle;
|
||||
|
||||
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
|
||||
var win = wm.getMostRecentWindow("navigator:browser");
|
||||
var docShell = win.gBrowser.docShell;
|
||||
|
||||
ok(
|
||||
shouldThrow(function(){docShell.getInterface(Ci.nsIBaseWindow).nativeHandle;}),
|
||||
"nativeHandle should not be implemented for nsDocShell"
|
||||
);
|
||||
|
||||
ok(typeof(nativeHandle) === "string", "nativeHandle should be a string");
|
||||
ok(nativeHandle.match(/^0x[0-9a-f]+$/), "nativeHandle should have a memory address format");
|
||||
|
||||
var iWin = window.document.getElementById("iframe_not_editable").contentWindow;
|
||||
is(getBaseWindowInterface(iWin).nativeHandle, nativeHandle,
|
||||
"the nativeHandle of an iframe should be its parent's nativeHandle");
|
||||
|
||||
var dialog = window.openDialog("data:text/plain,this is an active window.", "_blank",
|
||||
"chrome,dialog=yes,width=100,height=100");
|
||||
|
||||
isnot(getBaseWindowInterface(dialog).nativeHandle, "",
|
||||
"the nativeHandle of a dialog should not be empty");
|
||||
|
||||
dialog.close();
|
||||
|
||||
todo(false, "the nativeHandle of a window without a mainWidget should be empty"); // how to build a window without a mainWidget ?
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -418,6 +418,12 @@ NS_IMETHODIMP nsChromeTreeOwner::SetParentNativeWindow(nativeWindow aParentNativ
|
|||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsChromeTreeOwner::GetNativeHandle(nsAString& aNativeHandle)
|
||||
{
|
||||
NS_ENSURE_STATE(mXULWindow);
|
||||
return mXULWindow->GetNativeHandle(aNativeHandle);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsChromeTreeOwner::GetVisibility(bool* aVisibility)
|
||||
{
|
||||
NS_ENSURE_STATE(mXULWindow);
|
||||
|
|
|
@ -635,6 +635,12 @@ NS_IMETHODIMP nsContentTreeOwner::SetParentNativeWindow(nativeWindow aParentNati
|
|||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsContentTreeOwner::GetNativeHandle(nsAString& aNativeHandle)
|
||||
{
|
||||
NS_ENSURE_STATE(mXULWindow);
|
||||
return mXULWindow->GetNativeHandle(aNativeHandle);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsContentTreeOwner::GetVisibility(bool* aVisibility)
|
||||
{
|
||||
NS_ENSURE_STATE(mXULWindow);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "nsXULWindow.h"
|
||||
|
||||
// Helper classes
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsString.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "prprf.h"
|
||||
|
@ -738,6 +739,22 @@ NS_IMETHODIMP nsXULWindow::SetParentNativeWindow(nativeWindow aParentNativeWindo
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULWindow::GetNativeHandle(nsAString& aNativeHandle)
|
||||
{
|
||||
nsCOMPtr<nsIWidget> mainWidget;
|
||||
NS_ENSURE_SUCCESS(GetMainWidget(getter_AddRefs(mainWidget)), NS_ERROR_FAILURE);
|
||||
|
||||
if (mainWidget) {
|
||||
nativeWindow nativeWindowPtr = mainWidget->GetNativeData(NS_NATIVE_WINDOW);
|
||||
/* the nativeWindow pointer is converted to and exposed as a string. This
|
||||
is a more reliable way not to lose information (as opposed to JS
|
||||
|Number| for instance) */
|
||||
aNativeHandle = NS_ConvertASCIItoUTF16(nsPrintfCString("0x%p", nativeWindowPtr));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULWindow::GetVisibility(bool* aVisibility)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aVisibility);
|
||||
|
|
Загрузка…
Ссылка в новой задаче