2013-04-03 20:20:59 +02:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors.
|
2012-04-03 03:34:16 +02:00
|
|
|
// Portions copyright (c) 2010 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
#include <sstream>
|
|
|
|
#include "cefclient/cefclient.h"
|
|
|
|
#include "include/cef_app.h"
|
|
|
|
#import "include/cef_application_mac.h"
|
|
|
|
#include "include/cef_browser.h"
|
|
|
|
#include "include/cef_frame.h"
|
|
|
|
#include "include/cef_runnable.h"
|
2012-04-12 22:21:50 +02:00
|
|
|
#include "cefclient/binding_test.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "cefclient/client_handler.h"
|
2012-10-16 21:28:07 +02:00
|
|
|
#include "cefclient/dialog_test.h"
|
2012-04-27 23:19:06 +02:00
|
|
|
#include "cefclient/dom_test.h"
|
2012-10-26 22:42:41 +02:00
|
|
|
#include "cefclient/performance_test.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "cefclient/resource_util.h"
|
|
|
|
#include "cefclient/scheme_test.h"
|
|
|
|
#include "cefclient/string_util.h"
|
2013-04-01 19:57:28 +02:00
|
|
|
#include "cefclient/window_test.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// The global ClientHandler reference.
|
|
|
|
extern CefRefPtr<ClientHandler> g_handler;
|
|
|
|
|
|
|
|
char szWorkingDir[512]; // The current working directory
|
|
|
|
|
|
|
|
// Sizes for URL bar layout
|
|
|
|
#define BUTTON_HEIGHT 22
|
|
|
|
#define BUTTON_WIDTH 72
|
|
|
|
#define BUTTON_MARGIN 8
|
|
|
|
#define URLBAR_HEIGHT 32
|
|
|
|
|
|
|
|
// Content area size for newly created windows.
|
|
|
|
const int kWindowWidth = 800;
|
|
|
|
const int kWindowHeight = 600;
|
|
|
|
|
|
|
|
// Memory AutoRelease pool.
|
|
|
|
static NSAutoreleasePool* g_autopool = nil;
|
|
|
|
|
|
|
|
// Provide the CefAppProtocol implementation required by CEF.
|
|
|
|
@interface ClientApplication : NSApplication<CefAppProtocol> {
|
|
|
|
@private
|
|
|
|
BOOL handlingSendEvent_;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation ClientApplication
|
|
|
|
- (BOOL)isHandlingSendEvent {
|
|
|
|
return handlingSendEvent_;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent {
|
|
|
|
handlingSendEvent_ = handlingSendEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendEvent:(NSEvent*)event {
|
|
|
|
CefScopedSendingEvent sendingEventScoper;
|
|
|
|
[super sendEvent:event];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
// Receives notifications from controls and the browser window. Will delete
|
|
|
|
// itself when done.
|
|
|
|
@interface ClientWindowDelegate : NSObject <NSWindowDelegate>
|
|
|
|
- (IBAction)goBack:(id)sender;
|
|
|
|
- (IBAction)goForward:(id)sender;
|
|
|
|
- (IBAction)reload:(id)sender;
|
|
|
|
- (IBAction)stopLoading:(id)sender;
|
|
|
|
- (IBAction)takeURLStringValueFrom:(NSTextField *)sender;
|
|
|
|
- (void)alert:(NSString*)title withMessage:(NSString*)message;
|
|
|
|
- (void)notifyConsoleMessage:(id)object;
|
|
|
|
- (void)notifyDownloadComplete:(id)object;
|
|
|
|
- (void)notifyDownloadError:(id)object;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation ClientWindowDelegate
|
|
|
|
|
|
|
|
- (IBAction)goBack:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
|
|
|
g_handler->GetBrowser()->GoBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)goForward:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
|
|
|
g_handler->GetBrowser()->GoForward();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)reload:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
|
|
|
g_handler->GetBrowser()->Reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)stopLoading:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
|
|
|
g_handler->GetBrowser()->StopLoad();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)takeURLStringValueFrom:(NSTextField *)sender {
|
|
|
|
if (!g_handler.get() || !g_handler->GetBrowserId())
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSString *url = [sender stringValue];
|
|
|
|
|
|
|
|
// if it doesn't already have a prefix, add http. If we can't parse it,
|
|
|
|
// just don't bother rather than making things worse.
|
|
|
|
NSURL* tempUrl = [NSURL URLWithString:url];
|
|
|
|
if (tempUrl && ![tempUrl scheme])
|
|
|
|
url = [@"http://" stringByAppendingString:url];
|
|
|
|
|
|
|
|
std::string urlStr = [url UTF8String];
|
|
|
|
g_handler->GetBrowser()->GetMainFrame()->LoadURL(urlStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)alert:(NSString*)title withMessage:(NSString*)message {
|
|
|
|
NSAlert *alert = [NSAlert alertWithMessageText:title
|
|
|
|
defaultButton:@"OK"
|
|
|
|
alternateButton:nil
|
|
|
|
otherButton:nil
|
|
|
|
informativeTextWithFormat:message];
|
|
|
|
[alert runModal];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)notifyConsoleMessage:(id)object {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "Console messages will be written to " << g_handler->GetLogFile();
|
|
|
|
NSString* str = [NSString stringWithUTF8String:(ss.str().c_str())];
|
|
|
|
[self alert:@"Console Messages" withMessage:str];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)notifyDownloadComplete:(id)object {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "File \"" << g_handler->GetLastDownloadFile() <<
|
|
|
|
"\" downloaded successfully.";
|
|
|
|
NSString* str = [NSString stringWithUTF8String:(ss.str().c_str())];
|
|
|
|
[self alert:@"File Download" withMessage:str];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)notifyDownloadError:(id)object {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "File \"" << g_handler->GetLastDownloadFile() <<
|
|
|
|
"\" failed to download.";
|
|
|
|
NSString* str = [NSString stringWithUTF8String:(ss.str().c_str())];
|
|
|
|
[self alert:@"File Download" withMessage:str];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidBecomeKey:(NSNotification*)notification {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId()) {
|
|
|
|
// Give focus to the browser window.
|
|
|
|
g_handler->GetBrowser()->GetHost()->SetFocus(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called when the window is about to close. Perform the self-destruction
|
|
|
|
// sequence by getting rid of the window. By returning YES, we allow the window
|
|
|
|
// to be removed from the screen.
|
2013-03-19 23:59:33 +01:00
|
|
|
- (BOOL)windowShouldClose:(id)window {
|
|
|
|
if (g_handler.get() && !g_handler->IsClosing()) {
|
|
|
|
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
|
|
|
if (browser.get()) {
|
|
|
|
// Notify the browser window that we would like to close it. This
|
|
|
|
// will result in a call to ClientHandler::DoClose() if the
|
|
|
|
// JavaScript 'onbeforeunload' event handler allows it.
|
|
|
|
browser->GetHost()->CloseBrowser(false);
|
|
|
|
|
|
|
|
// Cancel the close.
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Try to make the window go away.
|
|
|
|
[window autorelease];
|
2013-03-19 23:59:33 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Clean ourselves up after clearing the stack of anything that might have the
|
|
|
|
// window on it.
|
|
|
|
[self performSelectorOnMainThread:@selector(cleanup:)
|
|
|
|
withObject:window
|
|
|
|
waitUntilDone:NO];
|
2013-03-19 23:59:33 +01:00
|
|
|
|
|
|
|
// Allow the close.
|
2012-04-03 03:34:16 +02:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deletes itself.
|
|
|
|
- (void)cleanup:(id)window {
|
|
|
|
[self release];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
|
|
|
NSButton* button = [[[NSButton alloc] initWithFrame:*rect] autorelease];
|
|
|
|
[button setTitle:title];
|
|
|
|
[button setBezelStyle:NSSmallSquareBezelStyle];
|
|
|
|
[button setAutoresizingMask:(NSViewMaxXMargin | NSViewMinYMargin)];
|
|
|
|
[parent addSubview:button];
|
|
|
|
rect->origin.x += BUTTON_WIDTH;
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Receives notifications from the application. Will delete itself when done.
|
|
|
|
@interface ClientAppDelegate : NSObject
|
|
|
|
- (void)createApp:(id)object;
|
|
|
|
- (IBAction)testGetSource:(id)sender;
|
|
|
|
- (IBAction)testGetText:(id)sender;
|
2013-04-03 20:20:59 +02:00
|
|
|
- (IBAction)testPopupWindow:(id)sender;
|
2012-04-03 03:34:16 +02:00
|
|
|
- (IBAction)testRequest:(id)sender;
|
|
|
|
- (IBAction)testSchemeHandler:(id)sender;
|
2012-04-12 22:21:50 +02:00
|
|
|
- (IBAction)testBinding:(id)sender;
|
2012-10-26 22:42:41 +02:00
|
|
|
- (IBAction)testPerformance:(id)sender;
|
2012-04-16 23:15:27 +02:00
|
|
|
- (IBAction)testDialogs:(id)sender;
|
2013-04-01 19:57:28 +02:00
|
|
|
- (IBAction)testWindow:(id)sender;
|
2012-04-27 21:12:01 +02:00
|
|
|
- (IBAction)testPluginInfo:(id)sender;
|
2012-04-27 23:19:06 +02:00
|
|
|
- (IBAction)testDOMAccess:(id)sender;
|
2012-06-12 21:50:24 +02:00
|
|
|
- (IBAction)testZoomIn:(id)sender;
|
|
|
|
- (IBAction)testZoomOut:(id)sender;
|
|
|
|
- (IBAction)testZoomReset:(id)sender;
|
2012-10-18 00:45:49 +02:00
|
|
|
- (IBAction)testBeginTracing:(id)sender;
|
|
|
|
- (IBAction)testEndTracing:(id)sender;
|
2013-04-03 20:20:59 +02:00
|
|
|
- (IBAction)testOtherTests:(id)sender;
|
2012-04-03 03:34:16 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation ClientAppDelegate
|
|
|
|
|
|
|
|
// Create the application on the UI thread.
|
|
|
|
- (void)createApp:(id)object {
|
|
|
|
[NSApplication sharedApplication];
|
|
|
|
[NSBundle loadNibNamed:@"MainMenu" owner:NSApp];
|
|
|
|
|
|
|
|
// Set the delegate for application events.
|
|
|
|
[NSApp setDelegate:self];
|
|
|
|
|
|
|
|
// Add the Tests menu.
|
|
|
|
NSMenu* menubar = [NSApp mainMenu];
|
|
|
|
NSMenuItem *testItem = [[[NSMenuItem alloc] initWithTitle:@"Tests"
|
|
|
|
action:nil
|
|
|
|
keyEquivalent:@""] autorelease];
|
|
|
|
NSMenu *testMenu = [[[NSMenu alloc] initWithTitle:@"Tests"] autorelease];
|
|
|
|
[testMenu addItemWithTitle:@"Get Source"
|
|
|
|
action:@selector(testGetSource:)
|
|
|
|
keyEquivalent:@""];
|
|
|
|
[testMenu addItemWithTitle:@"Get Text"
|
|
|
|
action:@selector(testGetText:)
|
|
|
|
keyEquivalent:@""];
|
|
|
|
[testMenu addItemWithTitle:@"Popup Window"
|
|
|
|
action:@selector(testPopupWindow:)
|
|
|
|
keyEquivalent:@""];
|
|
|
|
[testMenu addItemWithTitle:@"Request"
|
|
|
|
action:@selector(testRequest:)
|
|
|
|
keyEquivalent:@""];
|
|
|
|
[testMenu addItemWithTitle:@"Scheme Handler"
|
|
|
|
action:@selector(testSchemeHandler:)
|
|
|
|
keyEquivalent:@""];
|
2012-04-12 22:21:50 +02:00
|
|
|
[testMenu addItemWithTitle:@"JavaScript Binding"
|
|
|
|
action:@selector(testBinding:)
|
|
|
|
keyEquivalent:@""];
|
2012-10-26 22:42:41 +02:00
|
|
|
[testMenu addItemWithTitle:@"Performance Tests"
|
|
|
|
action:@selector(testPerformance:)
|
|
|
|
keyEquivalent:@""];
|
2012-10-16 21:28:07 +02:00
|
|
|
[testMenu addItemWithTitle:@"Dialogs"
|
2012-04-16 23:15:27 +02:00
|
|
|
action:@selector(testDialogs:)
|
|
|
|
keyEquivalent:@""];
|
2013-04-01 19:57:28 +02:00
|
|
|
[testMenu addItemWithTitle:@"Window"
|
|
|
|
action:@selector(testWindow:)
|
|
|
|
keyEquivalent:@""];
|
2012-04-27 21:12:01 +02:00
|
|
|
[testMenu addItemWithTitle:@"Plugin Info"
|
|
|
|
action:@selector(testPluginInfo:)
|
|
|
|
keyEquivalent:@""];
|
2012-04-27 23:19:06 +02:00
|
|
|
[testMenu addItemWithTitle:@"DOM Access"
|
|
|
|
action:@selector(testDOMAccess:)
|
|
|
|
keyEquivalent:@""];
|
2012-06-12 21:50:24 +02:00
|
|
|
[testMenu addItemWithTitle:@"Zoom In"
|
|
|
|
action:@selector(testZoomIn:)
|
|
|
|
keyEquivalent:@""];
|
|
|
|
[testMenu addItemWithTitle:@"Zoom Out"
|
|
|
|
action:@selector(testZoomOut:)
|
|
|
|
keyEquivalent:@""];
|
|
|
|
[testMenu addItemWithTitle:@"Zoom Reset"
|
|
|
|
action:@selector(testZoomReset:)
|
|
|
|
keyEquivalent:@""];
|
2012-10-18 00:45:49 +02:00
|
|
|
[testMenu addItemWithTitle:@"Begin Tracing"
|
|
|
|
action:@selector(testBeginTracing:)
|
|
|
|
keyEquivalent:@""];
|
|
|
|
[testMenu addItemWithTitle:@"End Tracing"
|
|
|
|
action:@selector(testEndTracing:)
|
|
|
|
keyEquivalent:@""];
|
2013-04-03 20:20:59 +02:00
|
|
|
[testMenu addItemWithTitle:@"Other Tests"
|
|
|
|
action:@selector(testOtherTests:)
|
|
|
|
keyEquivalent:@""];
|
2012-04-03 03:34:16 +02:00
|
|
|
[testItem setSubmenu:testMenu];
|
|
|
|
[menubar addItem:testItem];
|
|
|
|
|
|
|
|
// Create the delegate for control and browser window events.
|
|
|
|
ClientWindowDelegate* delegate = [[ClientWindowDelegate alloc] init];
|
|
|
|
|
|
|
|
// Create the main application window.
|
|
|
|
NSRect screen_rect = [[NSScreen mainScreen] visibleFrame];
|
|
|
|
NSRect window_rect = { {0, screen_rect.size.height - kWindowHeight},
|
|
|
|
{kWindowWidth, kWindowHeight} };
|
2012-04-24 20:01:48 +02:00
|
|
|
NSWindow* mainWnd = [[UnderlayOpenGLHostingWindow alloc]
|
2012-04-03 03:34:16 +02:00
|
|
|
initWithContentRect:window_rect
|
|
|
|
styleMask:(NSTitledWindowMask |
|
|
|
|
NSClosableWindowMask |
|
|
|
|
NSMiniaturizableWindowMask |
|
|
|
|
NSResizableWindowMask )
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:NO];
|
|
|
|
[mainWnd setTitle:@"cefclient"];
|
|
|
|
[mainWnd setDelegate:delegate];
|
|
|
|
|
|
|
|
// Rely on the window delegate to clean us up rather than immediately
|
|
|
|
// releasing when the window gets closed. We use the delegate to do
|
|
|
|
// everything from the autorelease pool so the window isn't on the stack
|
|
|
|
// during cleanup (ie, a window close from javascript).
|
|
|
|
[mainWnd setReleasedWhenClosed:NO];
|
|
|
|
|
|
|
|
NSView* contentView = [mainWnd contentView];
|
|
|
|
|
|
|
|
// Create the buttons.
|
|
|
|
NSRect button_rect = [contentView bounds];
|
|
|
|
button_rect.origin.y = window_rect.size.height - URLBAR_HEIGHT +
|
|
|
|
(URLBAR_HEIGHT - BUTTON_HEIGHT) / 2;
|
|
|
|
button_rect.size.height = BUTTON_HEIGHT;
|
|
|
|
button_rect.origin.x += BUTTON_MARGIN;
|
|
|
|
button_rect.size.width = BUTTON_WIDTH;
|
|
|
|
|
|
|
|
NSButton* button = MakeButton(&button_rect, @"Back", contentView);
|
|
|
|
[button setTarget:delegate];
|
|
|
|
[button setAction:@selector(goBack:)];
|
|
|
|
|
|
|
|
button = MakeButton(&button_rect, @"Forward", contentView);
|
|
|
|
[button setTarget:delegate];
|
|
|
|
[button setAction:@selector(goForward:)];
|
|
|
|
|
|
|
|
button = MakeButton(&button_rect, @"Reload", contentView);
|
|
|
|
[button setTarget:delegate];
|
|
|
|
[button setAction:@selector(reload:)];
|
|
|
|
|
|
|
|
button = MakeButton(&button_rect, @"Stop", contentView);
|
|
|
|
[button setTarget:delegate];
|
|
|
|
[button setAction:@selector(stopLoading:)];
|
|
|
|
|
|
|
|
// Create the URL text field.
|
|
|
|
button_rect.origin.x += BUTTON_MARGIN;
|
|
|
|
button_rect.size.width = [contentView bounds].size.width -
|
|
|
|
button_rect.origin.x - BUTTON_MARGIN;
|
|
|
|
NSTextField* editWnd = [[NSTextField alloc] initWithFrame:button_rect];
|
|
|
|
[contentView addSubview:editWnd];
|
|
|
|
[editWnd setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)];
|
|
|
|
[editWnd setTarget:delegate];
|
|
|
|
[editWnd setAction:@selector(takeURLStringValueFrom:)];
|
|
|
|
[[editWnd cell] setWraps:NO];
|
|
|
|
[[editWnd cell] setScrollable:YES];
|
|
|
|
|
|
|
|
// Create the handler.
|
|
|
|
g_handler = new ClientHandler();
|
|
|
|
g_handler->SetMainHwnd(contentView);
|
|
|
|
g_handler->SetEditHwnd(editWnd);
|
|
|
|
|
|
|
|
// Create the browser view.
|
|
|
|
CefWindowInfo window_info;
|
|
|
|
CefBrowserSettings settings;
|
|
|
|
|
|
|
|
window_info.SetAsChild(contentView, 0, 0, kWindowWidth, kWindowHeight);
|
|
|
|
CefBrowserHost::CreateBrowser(window_info, g_handler.get(),
|
2012-06-26 18:47:05 +02:00
|
|
|
g_handler->GetStartupURL(), settings);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Show the window.
|
|
|
|
[mainWnd makeKeyAndOrderFront: nil];
|
|
|
|
|
|
|
|
// Size the window.
|
|
|
|
NSRect r = [mainWnd contentRectForFrameRect:[mainWnd frame]];
|
|
|
|
r.size.width = kWindowWidth;
|
|
|
|
r.size.height = kWindowHeight + URLBAR_HEIGHT;
|
|
|
|
[mainWnd setFrame:[mainWnd frameRectForContentRect:r] display:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)testGetSource:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
|
|
|
RunGetSourceTest(g_handler->GetBrowser());
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)testGetText:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
|
|
|
RunGetTextTest(g_handler->GetBrowser());
|
|
|
|
}
|
|
|
|
|
2013-04-03 20:20:59 +02:00
|
|
|
- (IBAction)testPopupWindow:(id)sender {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
2013-04-03 20:20:59 +02:00
|
|
|
RunPopupTest(g_handler->GetBrowser());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-04-03 20:20:59 +02:00
|
|
|
- (IBAction)testRequest:(id)sender {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
2013-04-03 20:20:59 +02:00
|
|
|
RunRequestTest(g_handler->GetBrowser());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)testSchemeHandler:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
2012-04-24 20:01:48 +02:00
|
|
|
scheme_test::RunTest(g_handler->GetBrowser());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-04-12 22:21:50 +02:00
|
|
|
- (IBAction)testBinding:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
|
|
|
binding_test::RunTest(g_handler->GetBrowser());
|
|
|
|
}
|
|
|
|
|
2012-10-26 22:42:41 +02:00
|
|
|
- (IBAction)testPerformance:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
|
|
|
performance_test::RunTest(g_handler->GetBrowser());
|
|
|
|
}
|
|
|
|
|
2012-04-16 23:15:27 +02:00
|
|
|
- (IBAction)testDialogs:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
2012-10-16 21:28:07 +02:00
|
|
|
dialog_test::RunTest(g_handler->GetBrowser());
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
2013-04-01 19:57:28 +02:00
|
|
|
- (IBAction)testWindow:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
|
|
|
window_test::RunTest(g_handler->GetBrowser());
|
|
|
|
}
|
|
|
|
|
2012-04-27 21:12:01 +02:00
|
|
|
- (IBAction)testPluginInfo:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
|
|
|
RunPluginInfoTest(g_handler->GetBrowser());
|
|
|
|
}
|
|
|
|
|
2012-04-27 23:19:06 +02:00
|
|
|
- (IBAction)testDOMAccess:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
|
|
|
dom_test::RunTest(g_handler->GetBrowser());
|
|
|
|
}
|
|
|
|
|
2012-06-14 17:38:17 +02:00
|
|
|
- (IBAction)testZoomIn:(id)sender {
|
2012-06-12 21:50:24 +02:00
|
|
|
if (g_handler.get() && g_handler->GetBrowserId()) {
|
|
|
|
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
|
|
|
browser->GetHost()->SetZoomLevel(browser->GetHost()->GetZoomLevel() + 0.5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)testZoomOut:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId()) {
|
|
|
|
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
|
|
|
browser->GetHost()->SetZoomLevel(browser->GetHost()->GetZoomLevel() - 0.5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)testZoomReset:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId()) {
|
|
|
|
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
|
|
|
browser->GetHost()->SetZoomLevel(0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-18 00:45:49 +02:00
|
|
|
- (IBAction)testBeginTracing:(id)sender {
|
|
|
|
if (g_handler.get())
|
|
|
|
g_handler->BeginTracing();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)testEndTracing:(id)sender {
|
|
|
|
if (g_handler.get())
|
|
|
|
g_handler->EndTracing();
|
|
|
|
}
|
2012-06-12 21:50:24 +02:00
|
|
|
|
2013-04-03 20:20:59 +02:00
|
|
|
- (IBAction)testOtherTests:(id)sender {
|
|
|
|
if (g_handler.get() && g_handler->GetBrowserId())
|
|
|
|
RunOtherTests(g_handler->GetBrowser());
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Sent by the default notification center immediately before the application
|
2013-03-19 23:59:33 +01:00
|
|
|
// terminates. Quitting CEF is handled in ClientHandler::OnBeforeClose().
|
2012-04-03 03:34:16 +02:00
|
|
|
- (void)applicationWillTerminate:(NSNotification *)aNotification {
|
2013-03-19 23:59:33 +01:00
|
|
|
// Release the handler.
|
2012-04-03 03:34:16 +02:00
|
|
|
g_handler = NULL;
|
|
|
|
|
|
|
|
[self release];
|
|
|
|
|
|
|
|
// Release the AutoRelease pool.
|
|
|
|
[g_autopool release];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
CefMainArgs main_args(argc, argv);
|
2012-04-12 22:21:50 +02:00
|
|
|
CefRefPtr<ClientApp> app(new ClientApp);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Execute the secondary process, if any.
|
2012-04-12 22:21:50 +02:00
|
|
|
int exit_code = CefExecuteProcess(main_args, app.get());
|
2012-04-03 03:34:16 +02:00
|
|
|
if (exit_code >= 0)
|
|
|
|
return exit_code;
|
|
|
|
|
|
|
|
// Retrieve the current working directory.
|
|
|
|
getcwd(szWorkingDir, sizeof(szWorkingDir));
|
|
|
|
|
|
|
|
// Initialize the AutoRelease pool.
|
|
|
|
g_autopool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
|
|
|
// Initialize the ClientApplication instance.
|
|
|
|
[ClientApplication sharedApplication];
|
|
|
|
|
|
|
|
// Parse command line arguments.
|
|
|
|
AppInitCommandLine(argc, argv);
|
|
|
|
|
|
|
|
CefSettings settings;
|
|
|
|
|
|
|
|
// Populate the settings based on command line arguments.
|
2013-02-07 20:59:40 +01:00
|
|
|
AppGetSettings(settings);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Initialize CEF.
|
2012-04-12 22:21:50 +02:00
|
|
|
CefInitialize(main_args, settings, app.get());
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-04-24 20:01:48 +02:00
|
|
|
// Register the scheme handler.
|
|
|
|
scheme_test::InitTest();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Create the application delegate and window.
|
|
|
|
NSObject* delegate = [[ClientAppDelegate alloc] init];
|
|
|
|
[delegate performSelectorOnMainThread:@selector(createApp:) withObject:nil
|
|
|
|
waitUntilDone:NO];
|
|
|
|
|
|
|
|
// Run the application message loop.
|
|
|
|
CefRunMessageLoop();
|
|
|
|
|
2013-03-19 23:59:33 +01:00
|
|
|
// Shut down CEF.
|
|
|
|
CefShutdown();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Global functions
|
|
|
|
|
|
|
|
std::string AppGetWorkingDirectory() {
|
|
|
|
return szWorkingDir;
|
|
|
|
}
|
2013-03-19 23:59:33 +01:00
|
|
|
|
|
|
|
void AppQuitMessageLoop() {
|
|
|
|
CefQuitMessageLoop();
|
|
|
|
}
|