SilverlightisolatedStorageFile.IncreaseQuotaTo

发布于 2024-11-07 22:14:05 字数 742 浏览 0 评论 0原文

IsolatedStorageFile.IncreaseQuotaTo 指出:

要增加配额,您必须致电 该方法由用户发起 事件,例如在事件处理程序中 按钮单击事件。当你打电话时 常用的IncreaseQuotaTo方法 Silverlight 中的语言运行时 呈现一个对话框供用户 批准该请求。如果用户 拒绝请求,此方法 返回 false 并且配额仍然存在 大小相同。

Silverlight 如何知道该方法是从用户启动的事件(如按钮单击)调用的,而不是从其他线程调用的?

更具体地说:什么是用户发起的事件?有什么办法可以克服这个限制吗?

另一个问题:

当用户第一次访问我的应用程序时,我会自动下载一些文件,但我不希望用户按“下载”,然后当我检测到需要更多空间时,调用IncreaseQuota 并出现“Silverlight 对话框”要求更多空间。

我想自动开始下载(不是用户启动的),如果我检测到需要更多空间,请调用IncreaseQuota,从而出现“Silverlight 对话框”。 (没有用户按下下载)。

Msdn doc for IsolatedStorageFile.IncreaseQuotaTo states that:

To increase the quota, you must call
this method from a user-initiated
event, such as in an event handler for
a button-click event. When you call
the IncreaseQuotaTo method, the common
language runtime in Silverlight
presents a dialog box for the user to
approve the request. If the user
declines the request, this method
returns false and the quota remains
the same size.

How does Silverlight know that the method was called from a user-initiated event like a button click and not from some other thread?

More specifically: What is a user initiated event? Is there any way to overcome this limitation?

And another question:

I do some automatic downloads of files when user first accesses my application, but I don't want the user to press "Download" and then when I detect more space is needed call IncreaseQuota and have the "Silverlight dialog" appearing asking for more space.

I want to start the download automatically (not user initiated), and if I detect more space is needed, call IncreaseQuota and hence have the "Silverlight dialog" appear. (No user pressing download).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

相权↑美人 2024-11-14 22:14:05

经过大量挖掘,我确实发现了用户发起的事件是什么。似乎 msdn 文档在与“事件概述”相关的部分中指定了用户启动的事件,但 IsolatedStorageFile.IncreaseQuotaTo事件概述

所以用户发起的事件根据定义是:

Silverlight 强制执行某些
操作只允许在
处理程序的上下文
用户发起的事件。以下是
此类操作的列表:

设置为全屏。

显示某些对话框。这包括
保存文件对话框、打开文件对话框和
显示的打印对话框
打印文档.打印。

从超链接按钮导航。

访问主剪贴板 API。

Silverlight 用户启动的事件
包括鼠标事件(例如
MouseLeftButtonDown)和键盘
事件(例如 KeyDown)。事件
基于此类事件的控件
(如Click)也被考虑
用户发起的。

需要用户启动的 API 调用
应尽快致电
在事件处理程序中。这是因为
Silverlight 用户启动
概念还要求调用
发生在某个时间窗口内
事件发生后。在
Silverlight 4,这个时间窗口是
大约一秒钟。

用户发起的事件也受到限制
适用于 JavaScript API 的使用
银光。

当 Silverlight 全屏时
模式,一些输入事件是
出于安全考虑而故意限制
原因,尽管这可能是
减少浏览器外的影响
使用提升信任的应用程序。为了
更多信息,请参阅全屏
支持。

虽然我没有在“操作”列表中看到“IncreaseQuotaTo”,但我猜他们只是忘记了它,因为行为/限制与文档中描述的相同。

我很好奇 silverlight 到底如何知道用户启动的事件是什么,但是在深入研究 .net 框架源代码后,我陷入了死胡同:

if ((browserService == null) || !browserService.InPrivateMode())
{
    //..
}
return false; //means that IncreaseQuota will fail

browser.IsInPrivateMode 位于哪里:

[SecuritySafeCritical]
public bool InPrivateMode()
{
    bool privateMode = false;
    return (NativeMethods.SUCCEEDED(UnsafeNativeMethods.DOM_InPrivateMode(this._browserServiceHandle, out privateMode)) && privateMode);
}

DOM_InPrivateMode 位于 DllImport["agcore"] 中据微软称是保密的:(
所以看起来我不会很快知道他们如何检测用户发起的事件。

仔细想想,我猜微软不希望用户在浏览器中打开许多选项卡,然后噗:我自动调用IncreaseQuotaTo。

IncreaseQuotaTo 是一个浏览器模式对话框。这意味着您无法在处于活动状态时导航到其他浏览器选项卡。
因此,如果用户现在已从我的页面移动到 google.com 选项卡,并且如果我能够延迟调用 IncreaseQuotaTo,则用户可能会认为 google.com 正在请求更多存储空间:)。

这确实是一个安全漏洞。

如果他们通过页面级对话框实现这一点,那么可能会更容易被黑客攻击(或解决)。

总而言之,想到这一点,我开始明白为什么他们会这样实施以及为什么存在这些限制。

After much digging, I did find out what a user initiated event is. Seems that msdn doc specifies what a user initiated event in the section related to "events overview", but there's no link between documentation of IsolatedStorageFile.IncreaseQuotaTo and Events Overview

So a user initiated event according to the definition is:

Silverlight enforces that certain
operations are only permitted in the
context of a handler that handles a
user-initiated event. The following is
a list of such operations:

Setting IsFullScreen.

Showing certain dialogs. This includes
SaveFileDialog, OpenFileDialog, and
the print dialog displayed by
PrintDocument.Print.

Navigating from a HyperlinkButton.

Accessing the primary Clipboard API.

Silverlight user-initiated events
include the mouse events (such as
MouseLeftButtonDown), and the keyboard
events (such as KeyDown). Events of
controls that are based on such events
(such as Click) are also considered
user-initiated.

API calls that require user initiation
should be called as soon as possible
in an event handler. This is because
the Silverlight user initiation
concept also requires that the calls
occur within a certain time window
after the event occurrence. In
Silverlight 4, this time window is
approximately one second.

User-initiated event restrictions also
apply to usages of JavaScript API for
Silverlight.

When Silverlight is in full-screen
mode, some input events are
deliberately limited for security
reasons, although this can be
mitigated for out-of-browser
applications using elevated trust. For
more information, see Full-Screen
Support.

Although I don't see "IncreaseQuotaTo" inside the list of "operations", I'm guessing they just forgot it, since the behavior/limitations are the same as the ones described in the doc.

I was curios how exactly does silverlight know what a user initiated event is but after digging through .net framework source code I've got to a dead end:

if ((browserService == null) || !browserService.InPrivateMode())
{
    //..
}
return false; //means that IncreaseQuota will fail

where browser.IsInPrivateMode is:

[SecuritySafeCritical]
public bool InPrivateMode()
{
    bool privateMode = false;
    return (NativeMethods.SUCCEEDED(UnsafeNativeMethods.DOM_InPrivateMode(this._browserServiceHandle, out privateMode)) && privateMode);
}

where DOM_InPrivateMode is in a DllImport["agcore"] which according to microsoft is confidential :(
So it looks like I won't find out soon how they're detecting user initiated events.

Thinking it more about it, I guess microsoft didn't want a user to have many tabs open in a browser and then poof: I call automatically IncreaseQuotaTo.

The IncreaseQuotaTo is a browser modal dialog. This means you can't navigate to other browser tabs while is active.
So if the user has now moved from my page to the tab with google.com, and if I would be able to call IncreaseQuotaTo with a delay, the user might think that google.com is asking for more storage :).

This would be a security breach indeed.

Had they implemented this with a page level dialog, then that would have been probably more easily hacked (or worked around).

So all in all, thinking of it, I'm starting to see why they implemented it like this and why these limitations exist.

装纯掩盖桑 2024-11-14 22:14:05

该文档并非不完整。

如果我这样做...button_click(..) { new UserControl() }...这仍然算作用户发起的事件吗?

是的。但是这一点额外的代码真正实现了什么?

我个人从未尝试过什么构成了用户事件; IOW 鼠标悬停是否被视为用户事件?这对您来说尝试起来非常简单,并且您可以尝试许多其他的事情。如果有必要,您可以有一个欢迎用户的启动屏幕弹出窗口,他们必须单击它才能关闭它,此时您可以提出请求。这可能看起来有点老套,但如果你表现得好,你就可以摆脱这样的事情。

请注意,提示是一次性的。如果您提示用户并且他们接受,则在访问之间为您的应用程序保留该存储,这意味着您不需要在下次他们使用您的控件时再次提示他们,您的配额仍比上次增加(除非用户故意删除它,他们可以通过右键单击 Silverlight 控件,然后转到“应用程序存储”选项卡来完成此操作)。

The documentation isn't incomplete.

If I do this... button_click(..) { new UserControl() }... Does this still count as a user initiated event?

Yes. But what has that little bit of extra code really achieved?

What i've personally never experimented with is exactly what consitutes a user event; IOW is a mouse-over considered a user event? This will be very simple for you to try, and there are a multitude of other things you can experiment with. If necessary you could have a splash screen popup that welcomes the user and they have to click on it to dismiss it, at which point you make the request. It may seem a bit corny, but you can get away with things like this if you present it well.

Note that the prompt is a one-time thing. If you prompt the user and they accept, that storage is persisted for your application between visits, which means you don't need to prompt them again the next time they use your control, your quota is still increased from last time (unless the user has deliberately deleted it, which they can do by right clicking on the Silverlight control and then going to the Application Storage tab).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文