mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add the ability to restrict V8 extension loading by frame using a new CefPermissionHandler::OnBeforeScriptExtensionLoad() callback (issue #471).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@457 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -1748,3 +1748,52 @@ TEST(V8Test, Exception)
|
||||
EXPECT_TRUE(handler->got_exception_[i]) << "test = " << i+1;
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class TestPermissionsHandler : public V8TestHandler
|
||||
{
|
||||
public:
|
||||
TestPermissionsHandler(bool denyExtensions) : V8TestHandler(false) {
|
||||
deny_extensions_ = denyExtensions;
|
||||
}
|
||||
|
||||
virtual bool OnBeforeScriptExtensionLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& extensionName)
|
||||
{
|
||||
return deny_extensions_;
|
||||
}
|
||||
|
||||
bool deny_extensions_;
|
||||
};
|
||||
|
||||
// Verify extension permissions
|
||||
TEST(V8Test, Permissions)
|
||||
{
|
||||
g_V8TestV8HandlerExecuteCalled = false;
|
||||
|
||||
std::string extensionCode =
|
||||
"var test;"
|
||||
"if (!test)"
|
||||
" test = {};"
|
||||
"(function() {"
|
||||
" test.execute = function(a,b,c,d,e,f,g,h,i) {"
|
||||
" native function execute();"
|
||||
" return execute(a,b,c,d,e,f,g,h,i);"
|
||||
" };"
|
||||
"})();";
|
||||
CefRegisterExtension("v8/test", extensionCode, new V8TestV8Handler(false));
|
||||
|
||||
CefRefPtr<V8TestHandler> deny_handler = new TestPermissionsHandler(true);
|
||||
deny_handler->ExecuteTest();
|
||||
|
||||
ASSERT_FALSE(g_V8TestV8HandlerExecuteCalled);
|
||||
|
||||
CefRefPtr<V8TestHandler> allow_handler = new TestPermissionsHandler(false);
|
||||
allow_handler->ExecuteTest();
|
||||
|
||||
ASSERT_TRUE(g_V8TestV8HandlerExecuteCalled);
|
||||
}
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user