mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add support for JavaScript alert, confirm, prompt and onbeforeunload dialogs (issue #507).
- Add CefJSDialogHandler and CefJSDialogCallback interfaces. - Add default dialog implementations for Windows and Mac OS-X. - Add "JavaScript Dialogs" example to cefclient. - Change TestHandler::AddResource to ignore the query component when matching URLs. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@594 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -322,6 +322,10 @@ void RunPopupTest(CefRefPtr<CefBrowser> browser) {
|
||||
"window.open('http://www.google.com');", "about:blank", 0);
|
||||
}
|
||||
|
||||
void RunDialogTest(CefRefPtr<CefBrowser> browser) {
|
||||
browser->GetMainFrame()->LoadURL("http://tests/dialogs");
|
||||
}
|
||||
|
||||
void RunLocalStorageTest(CefRefPtr<CefBrowser> browser) {
|
||||
browser->GetMainFrame()->LoadURL("http://tests/localstorage");
|
||||
}
|
||||
|
@@ -40,6 +40,7 @@ void RunGetSourceTest(CefRefPtr<CefBrowser> browser);
|
||||
void RunGetTextTest(CefRefPtr<CefBrowser> browser);
|
||||
void RunRequestTest(CefRefPtr<CefBrowser> browser);
|
||||
void RunPopupTest(CefRefPtr<CefBrowser> browser);
|
||||
void RunDialogTest(CefRefPtr<CefBrowser> browser);
|
||||
void RunLocalStorageTest(CefRefPtr<CefBrowser> browser);
|
||||
void RunAccelerated2DCanvasTest(CefRefPtr<CefBrowser> browser);
|
||||
void RunAcceleratedLayersTest(CefRefPtr<CefBrowser> browser);
|
||||
|
@@ -29,6 +29,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
//
|
||||
|
||||
IDS_BINDING BINARY "res\\binding.html"
|
||||
IDS_DIALOGS BINARY "res\\dialogs.html"
|
||||
IDS_LOGO BINARY "res\\logo.png"
|
||||
IDS_LOGOBALL BINARY "res\\logoball.png"
|
||||
IDS_LOCALSTORAGE BINARY "res\\localstorage.html"
|
||||
@@ -67,6 +68,7 @@ BEGIN
|
||||
MENUITEM "Request", ID_TESTS_REQUEST
|
||||
MENUITEM "Scheme Handler", ID_TESTS_SCHEME_HANDLER
|
||||
MENUITEM "JavaScript Binding", ID_TESTS_BINDING
|
||||
MENUITEM "JavaScript Dialogs", ID_TESTS_DIALOGS
|
||||
MENUITEM "Local Storage", ID_TESTS_LOCALSTORAGE
|
||||
MENUITEM "XMLHttpRequest", ID_TESTS_XMLHTTPREQUEST
|
||||
MENUITEM "Accelerated 2D Canvas", ID_TESTS_ACCELERATED2DCANVAS
|
||||
|
@@ -230,6 +230,7 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||
- (IBAction)testXMLHttpRequest:(id)sender;
|
||||
- (IBAction)testSchemeHandler:(id)sender;
|
||||
- (IBAction)testBinding:(id)sender;
|
||||
- (IBAction)testDialogs:(id)sender;
|
||||
- (IBAction)testPopupWindow:(id)sender;
|
||||
- (IBAction)testAccelerated2DCanvas:(id)sender;
|
||||
- (IBAction)testAcceleratedLayers:(id)sender;
|
||||
@@ -272,6 +273,9 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||
[testMenu addItemWithTitle:@"JavaScript Binding"
|
||||
action:@selector(testBinding:)
|
||||
keyEquivalent:@""];
|
||||
[testMenu addItemWithTitle:@"JavaScript Dialogs"
|
||||
action:@selector(testDialogs:)
|
||||
keyEquivalent:@""];
|
||||
[testMenu addItemWithTitle:@"Local Storage"
|
||||
action:@selector(testLocalStorage:)
|
||||
keyEquivalent:@""];
|
||||
@@ -419,6 +423,11 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||
binding_test::RunTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testDialogs:(id)sender {
|
||||
if (g_handler.get() && g_handler->GetBrowserId())
|
||||
RunDialogTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testPopupWindow:(id)sender {
|
||||
if (g_handler.get() && g_handler->GetBrowserId())
|
||||
RunPopupTest(g_handler->GetBrowser());
|
||||
|
@@ -377,6 +377,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
if (browser.get())
|
||||
binding_test::RunTest(browser);
|
||||
return 0;
|
||||
case ID_TESTS_DIALOGS: // Test JavaScript dialofs
|
||||
if (browser.get())
|
||||
RunDialogTest(browser);
|
||||
return 0;
|
||||
case ID_TESTS_LOCALSTORAGE: // Test localStorage
|
||||
if (browser.get())
|
||||
RunLocalStorageTest(browser);
|
||||
|
@@ -137,6 +137,12 @@ CefRefPtr<CefResourceHandler> ClientHandler::GetResourceHandler(
|
||||
dump.size());
|
||||
ASSERT(stream.get());
|
||||
return new CefStreamResourceHandler("text/plain", stream);
|
||||
} else if (url == "http://tests/dialogs") {
|
||||
// Show the dialogs contents
|
||||
CefRefPtr<CefStreamReader> stream =
|
||||
GetBinaryResourceReader("dialogs.html");
|
||||
ASSERT(stream.get());
|
||||
return new CefStreamResourceHandler("text/html", stream);
|
||||
} else if (url == "http://tests/localstorage") {
|
||||
// Show the localstorage contents
|
||||
CefRefPtr<CefStreamReader> stream =
|
||||
|
45
tests/cefclient/res/dialogs.html
Normal file
45
tests/cefclient/res/dialogs.html
Normal file
@@ -0,0 +1,45 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Dialog Test</title>
|
||||
<script>
|
||||
function show_alert() {
|
||||
alert("I am an alert box!");
|
||||
}
|
||||
|
||||
function show_confirm() {
|
||||
var r = confirm("Press a button");
|
||||
var msg = r ? "You pressed OK!" : "You pressed Cancel!";
|
||||
document.getElementById('cm').innerText = msg;
|
||||
}
|
||||
|
||||
function show_prompt() {
|
||||
var name = prompt("Please enter your name" ,"Harry Potter");
|
||||
if (name != null && name != "")
|
||||
document.getElementById('pm').innerText = "Hello " + name + "!";
|
||||
}
|
||||
|
||||
window.onbeforeunload = function() {
|
||||
return 'This is an onbeforeunload message.';
|
||||
}
|
||||
|
||||
function update_time() {
|
||||
document.getElementById('time').innerText = new Date().toLocaleString();
|
||||
}
|
||||
|
||||
function setup() {
|
||||
setInterval(update_time, 1000);
|
||||
}
|
||||
|
||||
window.addEventListener('load', setup, false);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<form>
|
||||
Click a button to show the associated dialog type.
|
||||
<br/><input type="button" onclick="show_alert();" value="Show Alert">
|
||||
<br/><input type="button" onclick="show_confirm();" value="Show Confirm"> <span id="cm"></span>
|
||||
<br/><input type="button" onclick="show_prompt();" value="Show Prompt"> <span id="pm"></span>
|
||||
<p id="time"></p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@@ -38,12 +38,14 @@
|
||||
#define ID_TESTS_DRAGDROP 32771
|
||||
#define ID_TESTS_GEOLOCATION 32772
|
||||
#define ID_TESTS_BINDING 32773
|
||||
#define ID_TESTS_DIALOGS 32774
|
||||
#define IDC_STATIC -1
|
||||
#define IDS_BINDING 1000
|
||||
#define IDS_LOGO 1001
|
||||
#define IDS_LOGOBALL 1002
|
||||
#define IDS_LOCALSTORAGE 1003
|
||||
#define IDS_XMLHTTPREQUEST 1004
|
||||
#define IDS_DIALOGS 1001
|
||||
#define IDS_LOGO 1002
|
||||
#define IDS_LOGOBALL 1003
|
||||
#define IDS_LOCALSTORAGE 1004
|
||||
#define IDS_XMLHTTPREQUEST 1005
|
||||
|
||||
// Avoid files associated with MacOS
|
||||
#define _X86_
|
||||
|
@@ -35,6 +35,7 @@ CefRefPtr<CefStreamReader> GetBinaryResourceReader(int binaryId) {
|
||||
new CefByteReadHandler(pBytes, dwSize, NULL));
|
||||
}
|
||||
|
||||
ASSERT(FALSE); // The resource should be found.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -45,6 +46,7 @@ CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name) {
|
||||
int id;
|
||||
} resource_map[] = {
|
||||
{"binding.html", IDS_BINDING},
|
||||
{"dialogs.html", IDS_DIALOGS},
|
||||
{"localstorage.html", IDS_LOCALSTORAGE},
|
||||
{"xmlhttprequest.html", IDS_XMLHTTPREQUEST},
|
||||
};
|
||||
|
Reference in New Issue
Block a user