mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-20 14:10:40 +01:00
cefclient: Replace global App* functions with singleton MainContext instance (issue #1500).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1985 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
af0635bb34
commit
b9dd027411
@ -147,8 +147,6 @@
|
|||||||
'tests/cefclient/res/xmlhttprequest.html',
|
'tests/cefclient/res/xmlhttprequest.html',
|
||||||
],
|
],
|
||||||
'cefclient_sources_common': [
|
'cefclient_sources_common': [
|
||||||
'tests/cefclient/cefclient.cc',
|
|
||||||
'tests/cefclient/cefclient.h',
|
|
||||||
'tests/cefclient/binding_test.cc',
|
'tests/cefclient/binding_test.cc',
|
||||||
'tests/cefclient/binding_test.h',
|
'tests/cefclient/binding_test.h',
|
||||||
'tests/cefclient/bytes_write_handler.cc',
|
'tests/cefclient/bytes_write_handler.cc',
|
||||||
@ -165,6 +163,10 @@
|
|||||||
'tests/cefclient/dialog_test.cc',
|
'tests/cefclient/dialog_test.cc',
|
||||||
'tests/cefclient/dialog_test.h',
|
'tests/cefclient/dialog_test.h',
|
||||||
'tests/cefclient/dragdrop_events.h',
|
'tests/cefclient/dragdrop_events.h',
|
||||||
|
'tests/cefclient/main_context.cc',
|
||||||
|
'tests/cefclient/main_context.h',
|
||||||
|
'tests/cefclient/main_context_impl.cc',
|
||||||
|
'tests/cefclient/main_context_impl.h',
|
||||||
'tests/cefclient/main_message_loop.h',
|
'tests/cefclient/main_message_loop.h',
|
||||||
'tests/cefclient/main_message_loop.cc',
|
'tests/cefclient/main_message_loop.cc',
|
||||||
'tests/cefclient/main_message_loop_std.h',
|
'tests/cefclient/main_message_loop_std.h',
|
||||||
@ -193,6 +195,7 @@
|
|||||||
'tests/cefclient/cefclient_osr_widget_win.cc',
|
'tests/cefclient/cefclient_osr_widget_win.cc',
|
||||||
'tests/cefclient/cefclient_win.cc',
|
'tests/cefclient/cefclient_win.cc',
|
||||||
'tests/cefclient/client_handler_win.cc',
|
'tests/cefclient/client_handler_win.cc',
|
||||||
|
'tests/cefclient/main_context_impl_win.cc',
|
||||||
'tests/cefclient/main_message_loop_multithreaded_win.h',
|
'tests/cefclient/main_message_loop_multithreaded_win.h',
|
||||||
'tests/cefclient/main_message_loop_multithreaded_win.cc',
|
'tests/cefclient/main_message_loop_multithreaded_win.cc',
|
||||||
'tests/cefclient/resource.h',
|
'tests/cefclient/resource.h',
|
||||||
@ -208,6 +211,7 @@
|
|||||||
'tests/cefclient/cefclient_osr_widget_mac.h',
|
'tests/cefclient/cefclient_osr_widget_mac.h',
|
||||||
'tests/cefclient/cefclient_osr_widget_mac.mm',
|
'tests/cefclient/cefclient_osr_widget_mac.mm',
|
||||||
'tests/cefclient/client_handler_mac.mm',
|
'tests/cefclient/client_handler_mac.mm',
|
||||||
|
'tests/cefclient/main_context_impl_posix.cc',
|
||||||
'tests/cefclient/resource_util_mac.mm',
|
'tests/cefclient/resource_util_mac.mm',
|
||||||
'tests/cefclient/resource_util_posix.cc',
|
'tests/cefclient/resource_util_posix.cc',
|
||||||
'tests/cefclient/window_test_mac.mm',
|
'tests/cefclient/window_test_mac.mm',
|
||||||
@ -227,6 +231,8 @@
|
|||||||
'tests/cefclient/client_switches.h',
|
'tests/cefclient/client_switches.h',
|
||||||
'tests/cefclient/dialog_test.cc',
|
'tests/cefclient/dialog_test.cc',
|
||||||
'tests/cefclient/dialog_test.h',
|
'tests/cefclient/dialog_test.h',
|
||||||
|
'tests/cefclient/main_context.cc',
|
||||||
|
'tests/cefclient/main_context.h',
|
||||||
'tests/cefclient/main_message_loop.cc',
|
'tests/cefclient/main_message_loop.cc',
|
||||||
'tests/cefclient/main_message_loop.h',
|
'tests/cefclient/main_message_loop.h',
|
||||||
'tests/cefclient/performance_test.cc',
|
'tests/cefclient/performance_test.cc',
|
||||||
@ -257,6 +263,7 @@
|
|||||||
'tests/cefclient/cefclient_osr_widget_gtk.h',
|
'tests/cefclient/cefclient_osr_widget_gtk.h',
|
||||||
'tests/cefclient/cefclient_osr_widget_gtk.cc',
|
'tests/cefclient/cefclient_osr_widget_gtk.cc',
|
||||||
'tests/cefclient/client_handler_gtk.cc',
|
'tests/cefclient/client_handler_gtk.cc',
|
||||||
|
'tests/cefclient/main_context_impl_posix.cc',
|
||||||
'tests/cefclient/print_handler_gtk.cc',
|
'tests/cefclient/print_handler_gtk.cc',
|
||||||
'tests/cefclient/print_handler_gtk.h',
|
'tests/cefclient/print_handler_gtk.h',
|
||||||
'tests/cefclient/resource_util_linux.cc',
|
'tests/cefclient/resource_util_linux.cc',
|
||||||
|
@ -1,99 +0,0 @@
|
|||||||
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
|
||||||
// reserved. Use of this source code is governed by a BSD-style license that
|
|
||||||
// can be found in the LICENSE file.
|
|
||||||
|
|
||||||
#include "cefclient/cefclient.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
|
||||||
#include "include/cef_app.h"
|
|
||||||
#include "include/cef_browser.h"
|
|
||||||
#include "include/cef_command_line.h"
|
|
||||||
#include "include/cef_frame.h"
|
|
||||||
#include "include/cef_web_plugin.h"
|
|
||||||
#include "include/wrapper/cef_helpers.h"
|
|
||||||
#include "cefclient/client_handler.h"
|
|
||||||
#include "cefclient/client_switches.h"
|
|
||||||
|
|
||||||
CefRefPtr<ClientHandler> g_handler;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
CefRefPtr<CefCommandLine> g_command_line;
|
|
||||||
int g_offscreen_state = 0;
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
CefRefPtr<CefBrowser> AppGetBrowser() {
|
|
||||||
if (!g_handler.get())
|
|
||||||
return NULL;
|
|
||||||
return g_handler->GetBrowser();
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientWindowHandle AppGetMainWindowHandle() {
|
|
||||||
if (!g_handler.get())
|
|
||||||
return kNullWindowHandle;
|
|
||||||
return g_handler->GetMainWindowHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string AppGetConsoleLogPath() {
|
|
||||||
return AppGetWorkingDirectory() + "console.log";
|
|
||||||
}
|
|
||||||
|
|
||||||
void AppInitCommandLine(int argc, const char* const* argv) {
|
|
||||||
g_command_line = CefCommandLine::CreateCommandLine();
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
g_command_line->InitFromString(::GetCommandLineW());
|
|
||||||
#else
|
|
||||||
g_command_line->InitFromArgv(argc, argv);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the application command line object.
|
|
||||||
CefRefPtr<CefCommandLine> AppGetCommandLine() {
|
|
||||||
return g_command_line;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the application settings based on command line arguments.
|
|
||||||
void AppGetSettings(CefSettings& settings) {
|
|
||||||
DCHECK(g_command_line.get());
|
|
||||||
if (!g_command_line.get())
|
|
||||||
return;
|
|
||||||
|
|
||||||
CefString str;
|
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
settings.multi_threaded_message_loop =
|
|
||||||
g_command_line->HasSwitch(cefclient::kMultiThreadedMessageLoop);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CefString(&settings.cache_path) =
|
|
||||||
g_command_line->GetSwitchValue(cefclient::kCachePath);
|
|
||||||
|
|
||||||
if (g_command_line->HasSwitch(cefclient::kOffScreenRenderingEnabled))
|
|
||||||
settings.windowless_rendering_enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AppGetBrowserSettings(CefBrowserSettings& settings) {
|
|
||||||
DCHECK(g_command_line.get());
|
|
||||||
if (!g_command_line.get())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (g_command_line->HasSwitch(cefclient::kOffScreenFrameRate)) {
|
|
||||||
settings.windowless_frame_rate = atoi(g_command_line->
|
|
||||||
GetSwitchValue(cefclient::kOffScreenFrameRate).ToString().c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AppIsOffScreenRenderingEnabled() {
|
|
||||||
if (g_offscreen_state == 0) {
|
|
||||||
// Store the value so it isn't queried multiple times.
|
|
||||||
DCHECK(g_command_line.get());
|
|
||||||
g_offscreen_state =
|
|
||||||
g_command_line->HasSwitch(cefclient::kOffScreenRenderingEnabled) ?
|
|
||||||
1 : 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (g_offscreen_state == 1);
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
|
||||||
// reserved. Use of this source code is governed by a BSD-style license that
|
|
||||||
// can be found in the LICENSE file.
|
|
||||||
|
|
||||||
#ifndef CEF_TESTS_CEFCLIENT_CEFCLIENT_H_
|
|
||||||
#define CEF_TESTS_CEFCLIENT_CEFCLIENT_H_
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "include/cef_base.h"
|
|
||||||
#include "cefclient/client_app.h"
|
|
||||||
#include "cefclient/client_handler.h"
|
|
||||||
|
|
||||||
class CefApp;
|
|
||||||
class CefBrowser;
|
|
||||||
class CefCommandLine;
|
|
||||||
|
|
||||||
// Returns the main browser window instance.
|
|
||||||
CefRefPtr<CefBrowser> AppGetBrowser();
|
|
||||||
|
|
||||||
// Returns the main application window handle.
|
|
||||||
ClientWindowHandle AppGetMainWindowHandle();
|
|
||||||
|
|
||||||
// Returns the application working directory including trailing path separator.
|
|
||||||
std::string AppGetWorkingDirectory();
|
|
||||||
|
|
||||||
// Returns the full path to the console log file.
|
|
||||||
std::string AppGetConsoleLogPath();
|
|
||||||
|
|
||||||
// Initialize the application command line.
|
|
||||||
void AppInitCommandLine(int argc, const char* const* argv);
|
|
||||||
|
|
||||||
// Returns the application command line object.
|
|
||||||
CefRefPtr<CefCommandLine> AppGetCommandLine();
|
|
||||||
|
|
||||||
// Returns the application settings based on command line arguments.
|
|
||||||
void AppGetSettings(CefSettings& settings);
|
|
||||||
void AppGetBrowserSettings(CefBrowserSettings& settings);
|
|
||||||
|
|
||||||
// Returns true if off-screen rendering is enabled via the command line
|
|
||||||
// argument.
|
|
||||||
bool AppIsOffScreenRenderingEnabled();
|
|
||||||
|
|
||||||
// Returns the full download path for the specified file, or an empty path to
|
|
||||||
// use the default temp directory.
|
|
||||||
std::string AppGetDownloadPath(const std::string& file_name);
|
|
||||||
|
|
||||||
// Quit the application message loop.
|
|
||||||
void AppQuitMessageLoop();
|
|
||||||
|
|
||||||
#endif // CEF_TESTS_CEFCLIENT_CEFCLIENT_H_
|
|
@ -15,7 +15,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "cefclient/cefclient.h"
|
|
||||||
#include "include/base/cef_logging.h"
|
#include "include/base/cef_logging.h"
|
||||||
#include "include/base/cef_scoped_ptr.h"
|
#include "include/base/cef_scoped_ptr.h"
|
||||||
#include "include/cef_app.h"
|
#include "include/cef_app.h"
|
||||||
@ -23,14 +22,16 @@
|
|||||||
#include "include/cef_frame.h"
|
#include "include/cef_frame.h"
|
||||||
#include "include/wrapper/cef_helpers.h"
|
#include "include/wrapper/cef_helpers.h"
|
||||||
#include "cefclient/cefclient_osr_widget_gtk.h"
|
#include "cefclient/cefclient_osr_widget_gtk.h"
|
||||||
|
#include "cefclient/client_app.h"
|
||||||
#include "cefclient/client_handler.h"
|
#include "cefclient/client_handler.h"
|
||||||
#include "cefclient/client_switches.h"
|
#include "cefclient/client_switches.h"
|
||||||
|
#include "cefclient/main_context_impl.h"
|
||||||
#include "cefclient/main_message_loop_std.h"
|
#include "cefclient/main_message_loop_std.h"
|
||||||
#include "cefclient/resource.h"
|
#include "cefclient/resource.h"
|
||||||
#include "cefclient/test_runner.h"
|
#include "cefclient/test_runner.h"
|
||||||
|
|
||||||
// The global ClientHandler reference.
|
// The global ClientHandler reference.
|
||||||
extern CefRefPtr<ClientHandler> g_handler;
|
CefRefPtr<ClientHandler> g_handler;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -88,7 +89,7 @@ gboolean delete_event(GtkWidget* widget, GdkEvent* event,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TerminationSignalHandler(int signatl) {
|
void TerminationSignalHandler(int signatl) {
|
||||||
AppQuitMessageLoop();
|
client::MainMessageLoop::Get()->Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VboxSizeAllocated(GtkWidget* widget,
|
void VboxSizeAllocated(GtkWidget* widget,
|
||||||
@ -332,13 +333,14 @@ int main(int argc, char* argv[]) {
|
|||||||
if (exit_code >= 0)
|
if (exit_code >= 0)
|
||||||
return exit_code;
|
return exit_code;
|
||||||
|
|
||||||
// Parse command line arguments.
|
// Create the main context object.
|
||||||
AppInitCommandLine(argc, argv_copy);
|
scoped_ptr<client::MainContextImpl> context(
|
||||||
|
new client::MainContextImpl(argc, argv));
|
||||||
|
|
||||||
CefSettings settings;
|
CefSettings settings;
|
||||||
|
|
||||||
// Populate the settings based on command line arguments.
|
// Populate the settings based on command line arguments.
|
||||||
AppGetSettings(settings);
|
context->PopulateSettings(&settings);
|
||||||
|
|
||||||
// Install xlib error handlers so that the application won't be terminated
|
// Install xlib error handlers so that the application won't be terminated
|
||||||
// on non-fatal errors.
|
// on non-fatal errors.
|
||||||
@ -437,14 +439,15 @@ int main(int argc, char* argv[]) {
|
|||||||
CefBrowserSettings browserSettings;
|
CefBrowserSettings browserSettings;
|
||||||
|
|
||||||
// Populate the browser settings based on command line arguments.
|
// Populate the browser settings based on command line arguments.
|
||||||
AppGetBrowserSettings(browserSettings);
|
context->PopulateBrowserSettings(&browserSettings);
|
||||||
|
|
||||||
if (AppIsOffScreenRenderingEnabled()) {
|
CefRefPtr<CefCommandLine> command_line =
|
||||||
CefRefPtr<CefCommandLine> cmd_line = AppGetCommandLine();
|
CefCommandLine::GetGlobalCommandLine();
|
||||||
|
if (command_line->HasSwitch(cefclient::kOffScreenRenderingEnabled)) {
|
||||||
const bool transparent =
|
const bool transparent =
|
||||||
cmd_line->HasSwitch(cefclient::kTransparentPaintingEnabled);
|
command_line->HasSwitch(cefclient::kTransparentPaintingEnabled);
|
||||||
const bool show_update_rect =
|
const bool show_update_rect =
|
||||||
cmd_line->HasSwitch(cefclient::kShowUpdateRect);
|
command_line->HasSwitch(cefclient::kShowUpdateRect);
|
||||||
|
|
||||||
// Create the GTKGL surface.
|
// Create the GTKGL surface.
|
||||||
CefRefPtr<OSRWindow> osr_window =
|
CefRefPtr<OSRWindow> osr_window =
|
||||||
@ -484,31 +487,9 @@ int main(int argc, char* argv[]) {
|
|||||||
// Shut down CEF.
|
// Shut down CEF.
|
||||||
CefShutdown();
|
CefShutdown();
|
||||||
|
|
||||||
// Release the |message_loop| object.
|
// Release objects in reverse order of creation.
|
||||||
message_loop.reset();
|
message_loop.reset();
|
||||||
|
context.reset();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Global functions
|
|
||||||
|
|
||||||
std::string AppGetWorkingDirectory() {
|
|
||||||
char szWorkingDir[256];
|
|
||||||
if (getcwd(szWorkingDir, sizeof(szWorkingDir) - 1) == NULL) {
|
|
||||||
szWorkingDir[0] = 0;
|
|
||||||
} else {
|
|
||||||
// Add trailing path separator.
|
|
||||||
size_t len = strlen(szWorkingDir);
|
|
||||||
szWorkingDir[len] = '/';
|
|
||||||
szWorkingDir[len + 1] = 0;
|
|
||||||
}
|
|
||||||
return szWorkingDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string AppGetDownloadPath(const std::string& file_name) {
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AppQuitMessageLoop() {
|
|
||||||
client::MainMessageLoop::Get()->Quit();
|
|
||||||
}
|
|
||||||
|
@ -5,21 +5,22 @@
|
|||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "cefclient/cefclient.h"
|
|
||||||
#include "include/cef_app.h"
|
#include "include/cef_app.h"
|
||||||
#import "include/cef_application_mac.h"
|
#import "include/cef_application_mac.h"
|
||||||
#include "include/cef_browser.h"
|
#include "include/cef_browser.h"
|
||||||
#include "include/cef_frame.h"
|
#include "include/cef_frame.h"
|
||||||
#include "cefclient/cefclient_osr_widget_mac.h"
|
#include "cefclient/cefclient_osr_widget_mac.h"
|
||||||
|
#include "cefclient/client_app.h"
|
||||||
#include "cefclient/client_handler.h"
|
#include "cefclient/client_handler.h"
|
||||||
#include "cefclient/client_switches.h"
|
#include "cefclient/client_switches.h"
|
||||||
|
#include "cefclient/main_context_impl.h"
|
||||||
#include "cefclient/main_message_loop_std.h"
|
#include "cefclient/main_message_loop_std.h"
|
||||||
#include "cefclient/resource.h"
|
#include "cefclient/resource.h"
|
||||||
#include "cefclient/resource_util.h"
|
#include "cefclient/resource_util.h"
|
||||||
#include "cefclient/test_runner.h"
|
#include "cefclient/test_runner.h"
|
||||||
|
|
||||||
// The global ClientHandler reference.
|
// The global ClientHandler reference.
|
||||||
extern CefRefPtr<ClientHandler> g_handler;
|
CefRefPtr<ClientHandler> g_handler;
|
||||||
|
|
||||||
class MainBrowserProvider : public OSRBrowserProvider {
|
class MainBrowserProvider : public OSRBrowserProvider {
|
||||||
virtual CefRefPtr<CefBrowser> GetBrowser() {
|
virtual CefRefPtr<CefBrowser> GetBrowser() {
|
||||||
@ -207,12 +208,14 @@ const int kWindowHeight = 600;
|
|||||||
if (g_handler.get()) {
|
if (g_handler.get()) {
|
||||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||||
if (browser.get()) {
|
if (browser.get()) {
|
||||||
if (AppIsOffScreenRenderingEnabled())
|
if (CefCommandLine::GetGlobalCommandLine()->HasSwitch(
|
||||||
|
cefclient::kOffScreenRenderingEnabled)) {
|
||||||
browser->GetHost()->SendFocusEvent(true);
|
browser->GetHost()->SendFocusEvent(true);
|
||||||
else
|
} else {
|
||||||
browser->GetHost()->SetFocus(true);
|
browser->GetHost()->SetFocus(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when we are deactivated (when we lose focus).
|
// Called when we are deactivated (when we lose focus).
|
||||||
@ -220,12 +223,14 @@ const int kWindowHeight = 600;
|
|||||||
if (g_handler.get()) {
|
if (g_handler.get()) {
|
||||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||||
if (browser.get()) {
|
if (browser.get()) {
|
||||||
if (AppIsOffScreenRenderingEnabled())
|
if (CefCommandLine::GetGlobalCommandLine()->HasSwitch(
|
||||||
|
cefclient::kOffScreenRenderingEnabled)) {
|
||||||
browser->GetHost()->SendFocusEvent(false);
|
browser->GetHost()->SendFocusEvent(false);
|
||||||
else
|
} else {
|
||||||
browser->GetHost()->SetFocus(false);
|
browser->GetHost()->SetFocus(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when we have been minimized.
|
// Called when we have been minimized.
|
||||||
@ -428,14 +433,15 @@ void AddMenuItem(NSMenu *menu, NSString* label, int idval) {
|
|||||||
CefBrowserSettings settings;
|
CefBrowserSettings settings;
|
||||||
|
|
||||||
// Populate the browser settings based on command line arguments.
|
// Populate the browser settings based on command line arguments.
|
||||||
AppGetBrowserSettings(settings);
|
client::MainContext::Get()->PopulateBrowserSettings(&settings);
|
||||||
|
|
||||||
if (AppIsOffScreenRenderingEnabled()) {
|
CefRefPtr<CefCommandLine> command_line =
|
||||||
CefRefPtr<CefCommandLine> cmd_line = AppGetCommandLine();
|
CefCommandLine::GetGlobalCommandLine();
|
||||||
|
if (command_line->HasSwitch(cefclient::kOffScreenRenderingEnabled)) {
|
||||||
const bool transparent =
|
const bool transparent =
|
||||||
cmd_line->HasSwitch(cefclient::kTransparentPaintingEnabled);
|
command_line->HasSwitch(cefclient::kTransparentPaintingEnabled);
|
||||||
const bool show_update_rect =
|
const bool show_update_rect =
|
||||||
cmd_line->HasSwitch(cefclient::kShowUpdateRect);
|
command_line->HasSwitch(cefclient::kShowUpdateRect);
|
||||||
|
|
||||||
CefRefPtr<OSRWindow> osr_window =
|
CefRefPtr<OSRWindow> osr_window =
|
||||||
OSRWindow::Create(&g_main_browser_provider, transparent,
|
OSRWindow::Create(&g_main_browser_provider, transparent,
|
||||||
@ -484,24 +490,20 @@ int main(int argc, char* argv[]) {
|
|||||||
CefMainArgs main_args(argc, argv);
|
CefMainArgs main_args(argc, argv);
|
||||||
CefRefPtr<ClientApp> app(new ClientApp);
|
CefRefPtr<ClientApp> app(new ClientApp);
|
||||||
|
|
||||||
// Execute the secondary process, if any.
|
|
||||||
int exit_code = CefExecuteProcess(main_args, app.get(), NULL);
|
|
||||||
if (exit_code >= 0)
|
|
||||||
return exit_code;
|
|
||||||
|
|
||||||
// Initialize the AutoRelease pool.
|
// Initialize the AutoRelease pool.
|
||||||
NSAutoreleasePool* autopool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool* autopool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
// Initialize the ClientApplication instance.
|
// Initialize the ClientApplication instance.
|
||||||
[ClientApplication sharedApplication];
|
[ClientApplication sharedApplication];
|
||||||
|
|
||||||
// Parse command line arguments.
|
// Create the main context object.
|
||||||
AppInitCommandLine(argc, argv);
|
scoped_ptr<client::MainContextImpl> context(
|
||||||
|
new client::MainContextImpl(argc, argv));
|
||||||
|
|
||||||
CefSettings settings;
|
CefSettings settings;
|
||||||
|
|
||||||
// Populate the settings based on command line arguments.
|
// Populate the settings based on command line arguments.
|
||||||
AppGetSettings(settings);
|
context->PopulateSettings(&settings);
|
||||||
|
|
||||||
// Create the main message loop object.
|
// Create the main message loop object.
|
||||||
scoped_ptr<client::MainMessageLoop> message_loop(
|
scoped_ptr<client::MainMessageLoop> message_loop(
|
||||||
@ -525,41 +527,12 @@ int main(int argc, char* argv[]) {
|
|||||||
// Shut down CEF.
|
// Shut down CEF.
|
||||||
CefShutdown();
|
CefShutdown();
|
||||||
|
|
||||||
// Release the handler.
|
// Release objects in reverse order of creation.
|
||||||
g_handler = NULL;
|
g_handler = NULL;
|
||||||
|
|
||||||
// Release the delegate.
|
|
||||||
[delegate release];
|
[delegate release];
|
||||||
|
|
||||||
// Release the AutoRelease pool.
|
|
||||||
[autopool release];
|
|
||||||
|
|
||||||
// Release the |message_loop| object.
|
|
||||||
message_loop.reset();
|
message_loop.reset();
|
||||||
|
context.reset();
|
||||||
|
[autopool release];
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Global functions
|
|
||||||
|
|
||||||
std::string AppGetWorkingDirectory() {
|
|
||||||
char szWorkingDir[256];
|
|
||||||
if (getcwd(szWorkingDir, sizeof(szWorkingDir) - 1) == NULL) {
|
|
||||||
szWorkingDir[0] = 0;
|
|
||||||
} else {
|
|
||||||
// Add trailing path separator.
|
|
||||||
size_t len = strlen(szWorkingDir);
|
|
||||||
szWorkingDir[len] = '/';
|
|
||||||
szWorkingDir[len + 1] = 0;
|
|
||||||
}
|
|
||||||
return szWorkingDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string AppGetDownloadPath(const std::string& file_name) {
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AppQuitMessageLoop() {
|
|
||||||
client::MainMessageLoop::Get()->Quit();
|
|
||||||
}
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include "include/cef_url.h"
|
#include "include/cef_url.h"
|
||||||
#include "include/wrapper/cef_helpers.h"
|
#include "include/wrapper/cef_helpers.h"
|
||||||
#include "cefclient/bytes_write_handler.h"
|
#include "cefclient/bytes_write_handler.h"
|
||||||
#include "cefclient/cefclient.h"
|
|
||||||
#include "cefclient/osrenderer.h"
|
#include "cefclient/osrenderer.h"
|
||||||
#include "cefclient/resource_util.h"
|
#include "cefclient/resource_util.h"
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// reserved. Use of this source code is governed by a BSD-style license that
|
// reserved. Use of this source code is governed by a BSD-style license that
|
||||||
// can be found in the LICENSE file.
|
// can be found in the LICENSE file.
|
||||||
|
|
||||||
#include "cefclient/cefclient.h"
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <commdlg.h>
|
#include <commdlg.h>
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
@ -19,8 +17,10 @@
|
|||||||
#include "include/cef_sandbox_win.h"
|
#include "include/cef_sandbox_win.h"
|
||||||
#include "include/wrapper/cef_closure_task.h"
|
#include "include/wrapper/cef_closure_task.h"
|
||||||
#include "cefclient/cefclient_osr_widget_win.h"
|
#include "cefclient/cefclient_osr_widget_win.h"
|
||||||
|
#include "cefclient/client_app.h"
|
||||||
#include "cefclient/client_handler.h"
|
#include "cefclient/client_handler.h"
|
||||||
#include "cefclient/client_switches.h"
|
#include "cefclient/client_switches.h"
|
||||||
|
#include "cefclient/main_context_impl.h"
|
||||||
#include "cefclient/main_message_loop_multithreaded_win.h"
|
#include "cefclient/main_message_loop_multithreaded_win.h"
|
||||||
#include "cefclient/main_message_loop_std.h"
|
#include "cefclient/main_message_loop_std.h"
|
||||||
#include "cefclient/resource.h"
|
#include "cefclient/resource.h"
|
||||||
@ -62,7 +62,7 @@ LRESULT CALLBACK FindProc(HWND, UINT, WPARAM, LPARAM);
|
|||||||
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
|
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
|
||||||
|
|
||||||
// The global ClientHandler reference.
|
// The global ClientHandler reference.
|
||||||
extern CefRefPtr<ClientHandler> g_handler;
|
CefRefPtr<ClientHandler> g_handler;
|
||||||
|
|
||||||
class MainBrowserProvider : public OSRBrowserProvider {
|
class MainBrowserProvider : public OSRBrowserProvider {
|
||||||
virtual CefRefPtr<CefBrowser> GetBrowser() {
|
virtual CefRefPtr<CefBrowser> GetBrowser() {
|
||||||
@ -98,8 +98,9 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
|||||||
if (exit_code >= 0)
|
if (exit_code >= 0)
|
||||||
return exit_code;
|
return exit_code;
|
||||||
|
|
||||||
// Parse command line arguments. The passed in values are ignored on Windows.
|
// Create the main context object.
|
||||||
AppInitCommandLine(0, NULL);
|
scoped_ptr<client::MainContextImpl> context(
|
||||||
|
new client::MainContextImpl(0, NULL));
|
||||||
|
|
||||||
CefSettings settings;
|
CefSettings settings;
|
||||||
|
|
||||||
@ -108,7 +109,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Populate the settings based on command line arguments.
|
// Populate the settings based on command line arguments.
|
||||||
AppGetSettings(settings);
|
context->PopulateSettings(&settings);
|
||||||
|
|
||||||
// Create the main message loop object.
|
// Create the main message loop object.
|
||||||
scoped_ptr<client::MainMessageLoop> message_loop;
|
scoped_ptr<client::MainMessageLoop> message_loop;
|
||||||
@ -142,8 +143,9 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
|||||||
// Shut down CEF.
|
// Shut down CEF.
|
||||||
CefShutdown();
|
CefShutdown();
|
||||||
|
|
||||||
// Release the |message_loop| object.
|
// Release objects in reverse order of creation.
|
||||||
message_loop.reset();
|
message_loop.reset();
|
||||||
|
context.reset();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -220,7 +222,8 @@ static void SetFocusToBrowser(CefRefPtr<CefBrowser> browser) {
|
|||||||
if (!g_handler)
|
if (!g_handler)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (AppIsOffScreenRenderingEnabled()) {
|
if (CefCommandLine::GetGlobalCommandLine()->HasSwitch(
|
||||||
|
cefclient::kOffScreenRenderingEnabled)) {
|
||||||
// Give focus to the OSR window.
|
// Give focus to the OSR window.
|
||||||
CefRefPtr<OSRWindow> osr_window =
|
CefRefPtr<OSRWindow> osr_window =
|
||||||
static_cast<OSRWindow*>(g_handler->GetOSRHandler().get());
|
static_cast<OSRWindow*>(g_handler->GetOSRHandler().get());
|
||||||
@ -378,14 +381,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
|
|||||||
CefBrowserSettings settings;
|
CefBrowserSettings settings;
|
||||||
|
|
||||||
// Populate the browser settings based on command line arguments.
|
// Populate the browser settings based on command line arguments.
|
||||||
AppGetBrowserSettings(settings);
|
client::MainContext::Get()->PopulateBrowserSettings(&settings);
|
||||||
|
|
||||||
if (AppIsOffScreenRenderingEnabled()) {
|
CefRefPtr<CefCommandLine> command_line =
|
||||||
CefRefPtr<CefCommandLine> cmd_line = AppGetCommandLine();
|
CefCommandLine::GetGlobalCommandLine();
|
||||||
|
if (command_line->HasSwitch(cefclient::kOffScreenRenderingEnabled)) {
|
||||||
const bool transparent =
|
const bool transparent =
|
||||||
cmd_line->HasSwitch(cefclient::kTransparentPaintingEnabled);
|
command_line->HasSwitch(cefclient::kTransparentPaintingEnabled);
|
||||||
const bool show_update_rect =
|
const bool show_update_rect =
|
||||||
cmd_line->HasSwitch(cefclient::kShowUpdateRect);
|
command_line->HasSwitch(cefclient::kShowUpdateRect);
|
||||||
|
|
||||||
CefRefPtr<OSRWindow> osr_window =
|
CefRefPtr<OSRWindow> osr_window =
|
||||||
OSRWindow::Create(&g_main_browser_provider, transparent,
|
OSRWindow::Create(&g_main_browser_provider, transparent,
|
||||||
@ -488,7 +492,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
|
|||||||
|
|
||||||
// For off-screen browsers when the frame window is minimized set the
|
// For off-screen browsers when the frame window is minimized set the
|
||||||
// browser as hidden to reduce resource usage.
|
// browser as hidden to reduce resource usage.
|
||||||
const bool offscreen = AppIsOffScreenRenderingEnabled();
|
const bool offscreen = CefCommandLine::GetGlobalCommandLine()->HasSwitch(
|
||||||
|
cefclient::kOffScreenRenderingEnabled);
|
||||||
if (offscreen) {
|
if (offscreen) {
|
||||||
CefRefPtr<OSRWindow> osr_window =
|
CefRefPtr<OSRWindow> osr_window =
|
||||||
static_cast<OSRWindow*>(g_handler->GetOSRHandler().get());
|
static_cast<OSRWindow*>(g_handler->GetOSRHandler().get());
|
||||||
@ -627,37 +632,3 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
|
|||||||
}
|
}
|
||||||
return (INT_PTR)FALSE;
|
return (INT_PTR)FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Global functions
|
|
||||||
|
|
||||||
std::string AppGetWorkingDirectory() {
|
|
||||||
char szWorkingDir[MAX_PATH + 1];
|
|
||||||
if (_getcwd(szWorkingDir, MAX_PATH) == NULL) {
|
|
||||||
szWorkingDir[0] = 0;
|
|
||||||
} else {
|
|
||||||
// Add trailing path separator.
|
|
||||||
size_t len = strlen(szWorkingDir);
|
|
||||||
szWorkingDir[len] = '\\';
|
|
||||||
szWorkingDir[len + 1] = 0;
|
|
||||||
}
|
|
||||||
return szWorkingDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string AppGetDownloadPath(const std::string& file_name) {
|
|
||||||
TCHAR szFolderPath[MAX_PATH];
|
|
||||||
std::string path;
|
|
||||||
|
|
||||||
// Save the file in the user's "My Documents" folder.
|
|
||||||
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE,
|
|
||||||
NULL, 0, szFolderPath))) {
|
|
||||||
path = CefString(szFolderPath);
|
|
||||||
path += "\\" + file_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AppQuitMessageLoop() {
|
|
||||||
client::MainMessageLoop::Get()->Quit();
|
|
||||||
}
|
|
||||||
|
@ -19,9 +19,10 @@
|
|||||||
#include "include/cef_url.h"
|
#include "include/cef_url.h"
|
||||||
#include "include/wrapper/cef_closure_task.h"
|
#include "include/wrapper/cef_closure_task.h"
|
||||||
#include "include/wrapper/cef_stream_resource_handler.h"
|
#include "include/wrapper/cef_stream_resource_handler.h"
|
||||||
#include "cefclient/cefclient.h"
|
|
||||||
#include "cefclient/client_renderer.h"
|
#include "cefclient/client_renderer.h"
|
||||||
#include "cefclient/client_switches.h"
|
#include "cefclient/client_switches.h"
|
||||||
|
#include "cefclient/main_context.h"
|
||||||
|
#include "cefclient/main_message_loop.h"
|
||||||
#include "cefclient/resource_util.h"
|
#include "cefclient/resource_util.h"
|
||||||
#include "cefclient/test_runner.h"
|
#include "cefclient/test_runner.h"
|
||||||
|
|
||||||
@ -50,7 +51,8 @@ enum client_menu_ids {
|
|||||||
int ClientHandler::browser_count_ = 0;
|
int ClientHandler::browser_count_ = 0;
|
||||||
|
|
||||||
ClientHandler::ClientHandler()
|
ClientHandler::ClientHandler()
|
||||||
: browser_id_(0),
|
: startup_url_(client::MainContext::Get()->GetMainURL()),
|
||||||
|
browser_id_(0),
|
||||||
is_closing_(false),
|
is_closing_(false),
|
||||||
main_handle_(NULL),
|
main_handle_(NULL),
|
||||||
edit_handle_(NULL),
|
edit_handle_(NULL),
|
||||||
@ -58,7 +60,7 @@ ClientHandler::ClientHandler()
|
|||||||
forward_handle_(NULL),
|
forward_handle_(NULL),
|
||||||
stop_handle_(NULL),
|
stop_handle_(NULL),
|
||||||
reload_handle_(NULL),
|
reload_handle_(NULL),
|
||||||
console_log_file_(AppGetConsoleLogPath()),
|
console_log_file_(client::MainContext::Get()->GetConsoleLogPath()),
|
||||||
first_console_message_(true),
|
first_console_message_(true),
|
||||||
focus_on_editable_field_(false) {
|
focus_on_editable_field_(false) {
|
||||||
#if defined(OS_LINUX)
|
#if defined(OS_LINUX)
|
||||||
@ -70,12 +72,6 @@ ClientHandler::ClientHandler()
|
|||||||
// Read command line settings.
|
// Read command line settings.
|
||||||
CefRefPtr<CefCommandLine> command_line =
|
CefRefPtr<CefCommandLine> command_line =
|
||||||
CefCommandLine::GetGlobalCommandLine();
|
CefCommandLine::GetGlobalCommandLine();
|
||||||
|
|
||||||
if (command_line->HasSwitch(cefclient::kUrl))
|
|
||||||
startup_url_ = command_line->GetSwitchValue(cefclient::kUrl);
|
|
||||||
if (startup_url_.empty())
|
|
||||||
startup_url_ = "http://www.google.com/";
|
|
||||||
|
|
||||||
mouse_cursor_change_disabled_ =
|
mouse_cursor_change_disabled_ =
|
||||||
command_line->HasSwitch(cefclient::kMouseCursorChangeDisabled);
|
command_line->HasSwitch(cefclient::kMouseCursorChangeDisabled);
|
||||||
}
|
}
|
||||||
@ -204,7 +200,8 @@ void ClientHandler::OnBeforeDownload(
|
|||||||
CEF_REQUIRE_UI_THREAD();
|
CEF_REQUIRE_UI_THREAD();
|
||||||
|
|
||||||
// Continue the download and show the "Save As" dialog.
|
// Continue the download and show the "Save As" dialog.
|
||||||
callback->Continue(AppGetDownloadPath(suggested_name), true);
|
callback->Continue(
|
||||||
|
client::MainContext::Get()->GetDownloadPath(suggested_name), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientHandler::OnDownloadUpdated(
|
void ClientHandler::OnDownloadUpdated(
|
||||||
@ -407,7 +404,7 @@ void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
|
|||||||
message_router_ = NULL;
|
message_router_ = NULL;
|
||||||
|
|
||||||
// Quit the application message loop.
|
// Quit the application message loop.
|
||||||
AppQuitMessageLoop();
|
client::MainMessageLoop::Get()->Quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include "cefclient/client_handler.h"
|
#include "cefclient/client_handler.h"
|
||||||
#include "include/cef_browser.h"
|
#include "include/cef_browser.h"
|
||||||
#include "include/cef_frame.h"
|
#include "include/cef_frame.h"
|
||||||
#include "cefclient/cefclient.h"
|
|
||||||
|
|
||||||
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
|
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
|
||||||
CefRefPtr<CefFrame> frame,
|
CefRefPtr<CefFrame> frame,
|
||||||
|
31
tests/cefclient/main_context.cc
Normal file
31
tests/cefclient/main_context.cc
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
|
||||||
|
// reserved. Use of this source code is governed by a BSD-style license that
|
||||||
|
// can be found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "cefclient/main_context.h"
|
||||||
|
|
||||||
|
namespace client {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
MainContext* g_main_context = NULL;
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
// static
|
||||||
|
MainContext* MainContext::Get() {
|
||||||
|
DCHECK(g_main_context);
|
||||||
|
return g_main_context;
|
||||||
|
}
|
||||||
|
|
||||||
|
MainContext::MainContext() {
|
||||||
|
DCHECK(!g_main_context);
|
||||||
|
g_main_context = this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MainContext::~MainContext() {
|
||||||
|
g_main_context = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace client
|
47
tests/cefclient/main_context.h
Normal file
47
tests/cefclient/main_context.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
|
||||||
|
// reserved. Use of this source code is governed by a BSD-style license that
|
||||||
|
// can be found in the LICENSE file.
|
||||||
|
|
||||||
|
#ifndef CEF_TESTS_CEFCLIENT_MAIN_CONTEXT_H_
|
||||||
|
#define CEF_TESTS_CEFCLIENT_MAIN_CONTEXT_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "include/base/cef_ref_counted.h"
|
||||||
|
#include "include/internal/cef_types_wrappers.h"
|
||||||
|
|
||||||
|
namespace client {
|
||||||
|
|
||||||
|
// Used to store global context in the browser process. The methods of this
|
||||||
|
// class are thread-safe unless otherwise indicated.
|
||||||
|
class MainContext {
|
||||||
|
public:
|
||||||
|
// Returns the singleton instance of this object.
|
||||||
|
static MainContext* Get();
|
||||||
|
|
||||||
|
// Returns the full path to the console log file.
|
||||||
|
virtual std::string GetConsoleLogPath() = 0;
|
||||||
|
|
||||||
|
// Returns the full path to |file_name|.
|
||||||
|
virtual std::string GetDownloadPath(const std::string& file_name) = 0;
|
||||||
|
|
||||||
|
// Returns the app working directory including trailing path separator.
|
||||||
|
virtual std::string GetAppWorkingDirectory() = 0;
|
||||||
|
|
||||||
|
// Returns the main application URL.
|
||||||
|
virtual std::string GetMainURL() = 0;
|
||||||
|
|
||||||
|
// Populate |settings| based on command-line arguments.
|
||||||
|
virtual void PopulateSettings(CefSettings* settings) = 0;
|
||||||
|
virtual void PopulateBrowserSettings(CefBrowserSettings* settings) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
MainContext();
|
||||||
|
virtual ~MainContext();
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(MainContext);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace client
|
||||||
|
|
||||||
|
#endif // CEF_TESTS_CEFCLIENT_MAIN_CONTEXT_H_
|
63
tests/cefclient/main_context_impl.cc
Normal file
63
tests/cefclient/main_context_impl.cc
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
|
||||||
|
// reserved. Use of this source code is governed by a BSD-style license that
|
||||||
|
// can be found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "cefclient/main_context_impl.h"
|
||||||
|
|
||||||
|
#include "cefclient/client_switches.h"
|
||||||
|
|
||||||
|
namespace client {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// The default URL to load in a browser window.
|
||||||
|
const char kDefaultUrl[] = "http://www.google.com";
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
MainContextImpl::MainContextImpl(int argc,
|
||||||
|
const char* const* argv) {
|
||||||
|
// Parse the command line.
|
||||||
|
command_line_ = CefCommandLine::CreateCommandLine();
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
command_line_->InitFromString(::GetCommandLineW());
|
||||||
|
#else
|
||||||
|
command_line_->InitFromArgv(argc, argv);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Set the main URL.
|
||||||
|
if (command_line_->HasSwitch(cefclient::kUrl))
|
||||||
|
main_url_ = command_line_->GetSwitchValue(cefclient::kUrl);
|
||||||
|
if (main_url_.empty())
|
||||||
|
main_url_ = kDefaultUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string MainContextImpl::GetConsoleLogPath() {
|
||||||
|
return GetAppWorkingDirectory() + "console.log";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string MainContextImpl::GetMainURL() {
|
||||||
|
return main_url_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainContextImpl::PopulateSettings(CefSettings* settings) {
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
settings->multi_threaded_message_loop =
|
||||||
|
command_line_->HasSwitch(cefclient::kMultiThreadedMessageLoop);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CefString(&settings->cache_path) =
|
||||||
|
command_line_->GetSwitchValue(cefclient::kCachePath);
|
||||||
|
|
||||||
|
if (command_line_->HasSwitch(cefclient::kOffScreenRenderingEnabled))
|
||||||
|
settings->windowless_rendering_enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainContextImpl::PopulateBrowserSettings(CefBrowserSettings* settings) {
|
||||||
|
if (command_line_->HasSwitch(cefclient::kOffScreenFrameRate)) {
|
||||||
|
settings->windowless_frame_rate = atoi(command_line_->
|
||||||
|
GetSwitchValue(cefclient::kOffScreenFrameRate).ToString().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace client
|
42
tests/cefclient/main_context_impl.h
Normal file
42
tests/cefclient/main_context_impl.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
|
||||||
|
// reserved. Use of this source code is governed by a BSD-style license that
|
||||||
|
// can be found in the LICENSE file.
|
||||||
|
|
||||||
|
#ifndef CEF_TESTS_CEFCLIENT_MAIN_CONTEXT_IMPL_H_
|
||||||
|
#define CEF_TESTS_CEFCLIENT_MAIN_CONTEXT_IMPL_H_
|
||||||
|
|
||||||
|
#include "include/base/cef_scoped_ptr.h"
|
||||||
|
#include "include/cef_command_line.h"
|
||||||
|
#include "cefclient/main_context.h"
|
||||||
|
|
||||||
|
namespace client {
|
||||||
|
|
||||||
|
// Used to store global context in the browser process.
|
||||||
|
class MainContextImpl : public MainContext {
|
||||||
|
public:
|
||||||
|
MainContextImpl(int argc,
|
||||||
|
const char* const* argv);
|
||||||
|
|
||||||
|
// MainContext members.
|
||||||
|
std::string GetConsoleLogPath() OVERRIDE;
|
||||||
|
std::string GetDownloadPath(const std::string& file_name) OVERRIDE;
|
||||||
|
std::string GetAppWorkingDirectory() OVERRIDE;
|
||||||
|
std::string GetMainURL() OVERRIDE;
|
||||||
|
void PopulateSettings(CefSettings* settings) OVERRIDE;
|
||||||
|
void PopulateBrowserSettings(CefBrowserSettings* settings) OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Allow deletion via scoped_ptr only.
|
||||||
|
friend struct base::DefaultDeleter<MainContextImpl>;
|
||||||
|
|
||||||
|
~MainContextImpl() {}
|
||||||
|
|
||||||
|
CefRefPtr<CefCommandLine> command_line_;
|
||||||
|
std::string main_url_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(MainContextImpl);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace client
|
||||||
|
|
||||||
|
#endif // CEF_TESTS_CEFCLIENT_MAIN_CONTEXT_IMPL_H_
|
28
tests/cefclient/main_context_impl_posix.cc
Normal file
28
tests/cefclient/main_context_impl_posix.cc
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
|
||||||
|
// reserved. Use of this source code is governed by a BSD-style license that
|
||||||
|
// can be found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "cefclient/main_context_impl.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
namespace client {
|
||||||
|
|
||||||
|
std::string MainContextImpl::GetDownloadPath(const std::string& file_name) {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string MainContextImpl::GetAppWorkingDirectory() {
|
||||||
|
char szWorkingDir[256];
|
||||||
|
if (getcwd(szWorkingDir, sizeof(szWorkingDir) - 1) == NULL) {
|
||||||
|
szWorkingDir[0] = 0;
|
||||||
|
} else {
|
||||||
|
// Add trailing path separator.
|
||||||
|
size_t len = strlen(szWorkingDir);
|
||||||
|
szWorkingDir[len] = '/';
|
||||||
|
szWorkingDir[len + 1] = 0;
|
||||||
|
}
|
||||||
|
return szWorkingDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace client
|
39
tests/cefclient/main_context_impl_win.cc
Normal file
39
tests/cefclient/main_context_impl_win.cc
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
|
||||||
|
// reserved. Use of this source code is governed by a BSD-style license that
|
||||||
|
// can be found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "cefclient/main_context_impl.h"
|
||||||
|
|
||||||
|
#include <direct.h>
|
||||||
|
#include <shlobj.h>
|
||||||
|
|
||||||
|
namespace client {
|
||||||
|
|
||||||
|
std::string MainContextImpl::GetDownloadPath(const std::string& file_name) {
|
||||||
|
TCHAR szFolderPath[MAX_PATH];
|
||||||
|
std::string path;
|
||||||
|
|
||||||
|
// Save the file in the user's "My Documents" folder.
|
||||||
|
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE,
|
||||||
|
NULL, 0, szFolderPath))) {
|
||||||
|
path = CefString(szFolderPath);
|
||||||
|
path += "\\" + file_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string MainContextImpl::GetAppWorkingDirectory() {
|
||||||
|
char szWorkingDir[MAX_PATH + 1];
|
||||||
|
if (_getcwd(szWorkingDir, MAX_PATH) == NULL) {
|
||||||
|
szWorkingDir[0] = 0;
|
||||||
|
} else {
|
||||||
|
// Add trailing path separator.
|
||||||
|
size_t len = strlen(szWorkingDir);
|
||||||
|
szWorkingDir[len] = '\\';
|
||||||
|
szWorkingDir[len + 1] = 0;
|
||||||
|
}
|
||||||
|
return szWorkingDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace client
|
@ -8,25 +8,6 @@
|
|||||||
// a qualified path.
|
// a qualified path.
|
||||||
#include "client_app.h" // NOLINT(build/include)
|
#include "client_app.h" // NOLINT(build/include)
|
||||||
|
|
||||||
// Stub implementations.
|
|
||||||
std::string AppGetWorkingDirectory() {
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
std::string AppGetConsoleLogPath() {
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
std::string AppGetDownloadPath(const std::string& file_name) {
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
CefWindowHandle AppGetMainWindowHandle() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
void AppQuitMessageLoop() {
|
|
||||||
}
|
|
||||||
bool AppIsOffScreenRenderingEnabled() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process entry point.
|
// Process entry point.
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
CefMainArgs main_args(argc, argv);
|
CefMainArgs main_args(argc, argv);
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
#include "include/wrapper/cef_closure_task.h"
|
#include "include/wrapper/cef_closure_task.h"
|
||||||
#include "include/wrapper/cef_stream_resource_handler.h"
|
#include "include/wrapper/cef_stream_resource_handler.h"
|
||||||
#include "cefclient/binding_test.h"
|
#include "cefclient/binding_test.h"
|
||||||
#include "cefclient/cefclient.h"
|
|
||||||
#include "cefclient/dialog_test.h"
|
#include "cefclient/dialog_test.h"
|
||||||
|
#include "cefclient/main_context.h"
|
||||||
#include "cefclient/resource.h"
|
#include "cefclient/resource.h"
|
||||||
#include "cefclient/resource_util.h"
|
#include "cefclient/resource_util.h"
|
||||||
#include "cefclient/scheme_test.h"
|
#include "cefclient/scheme_test.h"
|
||||||
@ -186,7 +186,8 @@ void EndTracing(CefRefPtr<CefBrowser> browser) {
|
|||||||
|
|
||||||
void RunDialog() {
|
void RunDialog() {
|
||||||
static const char kDefaultFileName[] = "trace.txt";
|
static const char kDefaultFileName[] = "trace.txt";
|
||||||
std::string path = AppGetDownloadPath(kDefaultFileName);
|
std::string path =
|
||||||
|
client::MainContext::Get()->GetDownloadPath(kDefaultFileName);
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
path = kDefaultFileName;
|
path = kDefaultFileName;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user