Merge revision 1041 changes:
- Mac: Add default implementation for JavaScript confirm/prompt dialogs (issue #795). git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1364@1042 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
df11268f62
commit
b6ede2c8fa
|
@ -152,6 +152,7 @@
|
||||||
'tests/cefclient/mac/English.lproj/InfoPlist.strings',
|
'tests/cefclient/mac/English.lproj/InfoPlist.strings',
|
||||||
'tests/cefclient/mac/English.lproj/MainMenu.xib',
|
'tests/cefclient/mac/English.lproj/MainMenu.xib',
|
||||||
'tests/cefclient/mac/Info.plist',
|
'tests/cefclient/mac/Info.plist',
|
||||||
|
'tests/cefclient/res/dialogs.html',
|
||||||
'tests/cefclient/res/domaccess.html',
|
'tests/cefclient/res/domaccess.html',
|
||||||
'tests/cefclient/res/localstorage.html',
|
'tests/cefclient/res/localstorage.html',
|
||||||
'tests/cefclient/res/logo.png',
|
'tests/cefclient/res/logo.png',
|
||||||
|
|
|
@ -13,11 +13,14 @@
|
||||||
#include "base/file_util.h"
|
#include "base/file_util.h"
|
||||||
#include "base/mac/mac_util.h"
|
#include "base/mac/mac_util.h"
|
||||||
#include "base/sys_string_conversions.h"
|
#include "base/sys_string_conversions.h"
|
||||||
|
#include "base/utf_string_conversions.h"
|
||||||
#include "base/threading/thread_restrictions.h"
|
#include "base/threading/thread_restrictions.h"
|
||||||
#include "skia/ext/skia_utils_mac.h"
|
#include "skia/ext/skia_utils_mac.h"
|
||||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
|
||||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
|
||||||
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
|
||||||
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
|
||||||
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
|
||||||
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
|
||||||
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
|
||||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
|
||||||
|
@ -80,6 +83,17 @@ void AddMenuSeparator(NSMenu* menu) {
|
||||||
[menu addItem:item];
|
[menu addItem:item];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSString* GetDialogLabel(WebKit::WebFrame* webframe, const std::string& label) {
|
||||||
|
const GURL& url = webframe->document().url();
|
||||||
|
std::string urlStr;
|
||||||
|
if (!url.is_empty())
|
||||||
|
urlStr = url.host();
|
||||||
|
string16 labelStr = ASCIIToUTF16(label);
|
||||||
|
if (!urlStr.empty())
|
||||||
|
labelStr += ASCIIToUTF16(" - " + urlStr);
|
||||||
|
return base::SysUTF16ToNSString(labelStr);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@interface BrowserMenuDelegate : NSObject <NSMenuDelegate> {
|
@interface BrowserMenuDelegate : NSObject <NSMenuDelegate> {
|
||||||
|
@ -470,9 +484,11 @@ void BrowserWebViewDelegate::DidMovePlugin(
|
||||||
|
|
||||||
void BrowserWebViewDelegate::ShowJavaScriptAlert(
|
void BrowserWebViewDelegate::ShowJavaScriptAlert(
|
||||||
WebKit::WebFrame* webframe, const CefString& message) {
|
WebKit::WebFrame* webframe, const CefString& message) {
|
||||||
|
NSString* label = GetDialogLabel(webframe, "JavaScript Alert");
|
||||||
std::string messageStr(message);
|
std::string messageStr(message);
|
||||||
NSString *text = [NSString stringWithUTF8String:messageStr.c_str()];
|
NSString* text = [NSString stringWithUTF8String:messageStr.c_str()];
|
||||||
NSAlert *alert = [NSAlert alertWithMessageText:@"JavaScript Alert"
|
|
||||||
|
NSAlert* alert = [NSAlert alertWithMessageText:label
|
||||||
defaultButton:@"OK"
|
defaultButton:@"OK"
|
||||||
alternateButton:nil
|
alternateButton:nil
|
||||||
otherButton:nil
|
otherButton:nil
|
||||||
|
@ -482,15 +498,52 @@ void BrowserWebViewDelegate::ShowJavaScriptAlert(
|
||||||
|
|
||||||
bool BrowserWebViewDelegate::ShowJavaScriptConfirm(
|
bool BrowserWebViewDelegate::ShowJavaScriptConfirm(
|
||||||
WebKit::WebFrame* webframe, const CefString& message) {
|
WebKit::WebFrame* webframe, const CefString& message) {
|
||||||
NOTIMPLEMENTED();
|
NSString* label = GetDialogLabel(webframe, "JavaScript Confirm");
|
||||||
return false;
|
std::string messageStr(message);
|
||||||
|
NSString* text = [NSString stringWithUTF8String:messageStr.c_str()];
|
||||||
|
|
||||||
|
NSAlert *alert = [NSAlert alertWithMessageText:label
|
||||||
|
defaultButton:@"OK"
|
||||||
|
alternateButton:@"Cancel"
|
||||||
|
otherButton:nil
|
||||||
|
informativeTextWithFormat:text];
|
||||||
|
|
||||||
|
NSInteger r = [alert runModal];
|
||||||
|
|
||||||
|
return (r == NSAlertDefaultReturn);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BrowserWebViewDelegate::ShowJavaScriptPrompt(
|
bool BrowserWebViewDelegate::ShowJavaScriptPrompt(
|
||||||
WebKit::WebFrame* webframe, const CefString& message,
|
WebKit::WebFrame* webframe, const CefString& message,
|
||||||
const CefString& default_value, CefString* result) {
|
const CefString& default_value, CefString* result) {
|
||||||
NOTIMPLEMENTED();
|
NSString* label = GetDialogLabel(webframe, "JavaScript Prompt");
|
||||||
return false;
|
|
||||||
|
NSAlert *alert =
|
||||||
|
[NSAlert alertWithMessageText:label
|
||||||
|
defaultButton:@"OK"
|
||||||
|
alternateButton:@"Cancel"
|
||||||
|
otherButton:nil
|
||||||
|
informativeTextWithFormat:@""];
|
||||||
|
|
||||||
|
NSTextField *input =
|
||||||
|
[[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 22)];
|
||||||
|
[[input cell] setLineBreakMode:NSLineBreakByTruncatingTail];
|
||||||
|
std::string default_valueStr(default_value);
|
||||||
|
[input setStringValue:
|
||||||
|
[NSString stringWithUTF8String:default_valueStr.c_str()]];
|
||||||
|
[alert setAccessoryView:input];
|
||||||
|
[input release];
|
||||||
|
|
||||||
|
std::string messageStr(message);
|
||||||
|
[alert setInformativeText:[NSString stringWithUTF8String:messageStr.c_str()]];
|
||||||
|
|
||||||
|
NSInteger r = [alert runModal];
|
||||||
|
if (r == NSAlertDefaultReturn) {
|
||||||
|
[input validateEditing];
|
||||||
|
*result = base::SysNSStringToUTF8([input stringValue]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (r == NSAlertDefaultReturn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called to show the file chooser dialog.
|
// Called to show the file chooser dialog.
|
||||||
|
|
|
@ -200,6 +200,7 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||||
- (IBAction)testJSExecute:(id)sender;
|
- (IBAction)testJSExecute:(id)sender;
|
||||||
- (IBAction)testJSInvoke:(id)sender;
|
- (IBAction)testJSInvoke:(id)sender;
|
||||||
- (IBAction)testPerformance:(id)sender;
|
- (IBAction)testPerformance:(id)sender;
|
||||||
|
- (IBAction)testDialogs:(id)sender;
|
||||||
- (IBAction)testRequest:(id)sender;
|
- (IBAction)testRequest:(id)sender;
|
||||||
- (IBAction)testLocalStorage:(id)sender;
|
- (IBAction)testLocalStorage:(id)sender;
|
||||||
- (IBAction)testXMLHttpRequest:(id)sender;
|
- (IBAction)testXMLHttpRequest:(id)sender;
|
||||||
|
@ -259,6 +260,9 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||||
[testMenu addItemWithTitle:@"Performance Tests"
|
[testMenu addItemWithTitle:@"Performance Tests"
|
||||||
action:@selector(testPerformance:)
|
action:@selector(testPerformance:)
|
||||||
keyEquivalent:@""];
|
keyEquivalent:@""];
|
||||||
|
[testMenu addItemWithTitle:@"Dialogs"
|
||||||
|
action:@selector(testDialogs:)
|
||||||
|
keyEquivalent:@""];
|
||||||
[testMenu addItemWithTitle:@"Popup Window"
|
[testMenu addItemWithTitle:@"Popup Window"
|
||||||
action:@selector(testPopupWindow:)
|
action:@selector(testPopupWindow:)
|
||||||
keyEquivalent:@""];
|
keyEquivalent:@""];
|
||||||
|
@ -445,6 +449,11 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||||
performance_test::RunTest(g_handler->GetBrowser());
|
performance_test::RunTest(g_handler->GetBrowser());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (IBAction)testDialogs:(id)sender {
|
||||||
|
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||||
|
RunDialogsTest(g_handler->GetBrowser());
|
||||||
|
}
|
||||||
|
|
||||||
- (IBAction)testRequest:(id)sender {
|
- (IBAction)testRequest:(id)sender {
|
||||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||||
RunRequestTest(g_handler->GetBrowser());
|
RunRequestTest(g_handler->GetBrowser());
|
||||||
|
|
|
@ -80,6 +80,11 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||||
resourceStream = GetBinaryResourceReader("performance.html");
|
resourceStream = GetBinaryResourceReader("performance.html");
|
||||||
response->SetMimeType("text/html");
|
response->SetMimeType("text/html");
|
||||||
response->SetStatus(200);
|
response->SetStatus(200);
|
||||||
|
} else if (url == "http://tests/dialogs") {
|
||||||
|
// Show the dialogs HTML contents
|
||||||
|
resourceStream = GetBinaryResourceReader("dialogs.html");
|
||||||
|
response->SetMimeType("text/html");
|
||||||
|
response->SetStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue