Commit 8afec0c0 authored by Oleg.Korshul's avatar Oleg.Korshul Committed by Alexander Trofimov

mac version

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@64429 954022d7-b5bf-4e40-9824-e11837661b57
parent d6dc3779
......@@ -978,6 +978,27 @@ DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/linux/libcef_dll/cpptoc sv
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/linux/libcef_dll/ctocpp svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/linux/libcef_dll/wrapper svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/cefclient svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/cefclient/browser svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/cefclient/common svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/cefclient/renderer svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/cefclient/resources svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/cefclient/resources/logo.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/cefclient/resources/mac svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/cefclient/resources/mac/English.lproj svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/cefclient/resources/mac/cefclient.icns svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/cefclient/resources/pdf.pdf svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/include svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/include/base svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/include/base/internal svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/include/capi svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/include/internal svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/include/wrapper svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/libcef_dll svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/libcef_dll/base svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/libcef_dll/cpptoc svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/libcef_dll/ctocpp svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/mac/libcef_dll/wrapper svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/windows svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/windows/cefclient svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/src/cef/windows/cefclient/browser svnc_tsvn_003alogminsize=5
// Copyright (c) 2012 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/browser/binding_test.h"
#include <algorithm>
#include <string>
#include "include/wrapper/cef_stream_resource_handler.h"
namespace client {
namespace binding_test {
namespace {
const char kTestUrl[] = "http://tests/binding";
const char kTestMessageName[] = "BindingTest";
// Handle messages in the browser process.
class Handler : public CefMessageRouterBrowserSide::Handler {
public:
Handler() {}
// Called due to cefQuery execution in binding.html.
virtual bool OnQuery(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int64 query_id,
const CefString& request,
bool persistent,
CefRefPtr<Callback> callback) OVERRIDE {
// Only handle messages from the test URL.
const std::string& url = frame->GetURL();
if (url.find(kTestUrl) != 0)
return false;
const std::string& message_name = request;
if (message_name.find(kTestMessageName) == 0) {
// Reverse the string and return.
std::string result = message_name.substr(sizeof(kTestMessageName));
std::reverse(result.begin(), result.end());
callback->Success(result);
return true;
}
return false;
}
};
} // namespace
void CreateMessageHandlers(test_runner::MessageHandlerSet& handlers) {
handlers.insert(new Handler());
}
} // namespace binding_test
} // namespace client
// Copyright (c) 2012 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_BROWSER_BINDING_TEST_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_BINDING_TEST_H_
#pragma once
#include "cefclient/browser/test_runner.h"
namespace client {
namespace binding_test {
// Create message handlers. Called from test_runner.cc.
void CreateMessageHandlers(test_runner::MessageHandlerSet& handlers);
} // namespace binding_test
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_BINDING_TEST_H_
// 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/browser/browser_window.h"
#include "include/base/cef_bind.h"
#include "cefclient/browser/main_message_loop.h"
namespace client {
BrowserWindow::BrowserWindow(Delegate* delegate)
: delegate_(delegate),
is_closing_(false) {
DCHECK(delegate_);
}
void BrowserWindow::SetDeviceScaleFactor(float device_scale_factor) {
}
float BrowserWindow::GetDeviceScaleFactor() const {
return 1.0f;
}
CefRefPtr<CefBrowser> BrowserWindow::GetBrowser() const {
REQUIRE_MAIN_THREAD();
return browser_;
}
bool BrowserWindow::IsClosing() const {
REQUIRE_MAIN_THREAD();
return is_closing_;
}
void BrowserWindow::OnBrowserCreated(CefRefPtr<CefBrowser> browser) {
REQUIRE_MAIN_THREAD();
DCHECK(!browser_);
browser_ = browser;
delegate_->OnBrowserCreated(browser);
}
void BrowserWindow::OnBrowserClosing(CefRefPtr<CefBrowser> browser) {
REQUIRE_MAIN_THREAD();
DCHECK_EQ(browser->GetIdentifier(), browser_->GetIdentifier());
is_closing_ = true;
}
void BrowserWindow::OnBrowserClosed(CefRefPtr<CefBrowser> browser) {
REQUIRE_MAIN_THREAD();
DCHECK_EQ(browser->GetIdentifier(), browser_->GetIdentifier());
browser_ = NULL;
client_handler_->DetachDelegate();
client_handler_ = NULL;
// |this| may be deleted.
delegate_->OnBrowserWindowDestroyed();
}
void BrowserWindow::OnSetAddress(const std::string& url) {
REQUIRE_MAIN_THREAD();
delegate_->OnSetAddress(url);
}
void BrowserWindow::OnSetTitle(const std::string& title) {
REQUIRE_MAIN_THREAD();
delegate_->OnSetTitle(title);
}
void BrowserWindow::OnSetFullscreen(bool fullscreen) {
REQUIRE_MAIN_THREAD();
delegate_->OnSetFullscreen(fullscreen);
}
void BrowserWindow::OnSetLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward) {
REQUIRE_MAIN_THREAD();
delegate_->OnSetLoadingState(isLoading, canGoBack, canGoForward);
}
void BrowserWindow::OnSetDraggableRegions(
const std::vector<CefDraggableRegion>& regions) {
REQUIRE_MAIN_THREAD();
delegate_->OnSetDraggableRegions(regions);
}
} // namespace client
// 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_BROWSER_BROWSER_WINDOW_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_BROWSER_WINDOW_H_
#pragma once
#include "include/base/cef_scoped_ptr.h"
#include "include/cef_browser.h"
#include "cefclient/browser/client_handler.h"
#include "cefclient/browser/client_types.h"
namespace client {
// Represents a native child window hosting a single browser instance. The
// methods of this class must be called on the main thread unless otherwise
// indicated.
class BrowserWindow : public ClientHandler::Delegate {
public:
// This interface is implemented by the owner of the BrowserWindow. The
// methods of this class will be called on the main thread.
class Delegate {
public:
// Called when the browser has been created.
virtual void OnBrowserCreated(CefRefPtr<CefBrowser> browser) = 0;
// Called when the BrowserWindow has been destroyed.
virtual void OnBrowserWindowDestroyed() = 0;
// Set the window URL address.
virtual void OnSetAddress(const std::string& url) = 0;
// Set the window title.
virtual void OnSetTitle(const std::string& title) = 0;
// Set fullscreen mode.
virtual void OnSetFullscreen(bool fullscreen) = 0;
// Set the loading state.
virtual void OnSetLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward) = 0;
// Set the draggable regions.
virtual void OnSetDraggableRegions(
const std::vector<CefDraggableRegion>& regions) = 0;
protected:
virtual ~Delegate() {}
};
// Create a new browser and native window.
virtual void CreateBrowser(ClientWindowHandle parent_handle,
const CefRect& rect,
const CefBrowserSettings& settings,
CefRefPtr<CefRequestContext> request_context) = 0;
// Retrieve the configuration that will be used when creating a popup window.
// The popup browser will initially be parented to |temp_handle| which should
// be a pre-existing hidden window. The native window will be created later
// after the browser has been created. This method may be called on any
// thread.
virtual void GetPopupConfig(CefWindowHandle temp_handle,
CefWindowInfo& windowInfo,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings) = 0;
// Show the popup window with correct parent and bounds in parent coordinates.
virtual void ShowPopup(ClientWindowHandle parent_handle,
int x, int y, size_t width, size_t height) = 0;
// Show the window.
virtual void Show() = 0;
// Hide the window.
virtual void Hide() = 0;
// Set the window bounds in parent coordinates.
virtual void SetBounds(int x, int y, size_t width, size_t height) = 0;
// Set focus to the window.
virtual void SetFocus(bool focus) = 0;
// Set the device scale factor. Only used in combination with off-screen
// rendering.
virtual void SetDeviceScaleFactor(float device_scale_factor);
// Returns the device scale factor. Only used in combination with off-screen
// rendering.
virtual float GetDeviceScaleFactor() const;
// Returns the window handle.
virtual ClientWindowHandle GetWindowHandle() const = 0;
// Returns the browser owned by the window.
CefRefPtr<CefBrowser> GetBrowser() const;
// Returns true if the browser is closing.
bool IsClosing() const;
protected:
// Allow deletion via scoped_ptr only.
friend struct base::DefaultDeleter<BrowserWindow>;
// Constructor may be called on any thread.
// |delegate| must outlive this object.
explicit BrowserWindow(Delegate* delegate);
// ClientHandler::Delegate methods.
void OnBrowserCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
void OnBrowserClosing(CefRefPtr<CefBrowser> browser) OVERRIDE;
void OnBrowserClosed(CefRefPtr<CefBrowser> browser) OVERRIDE;
void OnSetAddress(const std::string& url) OVERRIDE;
void OnSetTitle(const std::string& title) OVERRIDE;
void OnSetFullscreen(bool fullscreen) OVERRIDE;
void OnSetLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward) OVERRIDE;
void OnSetDraggableRegions(
const std::vector<CefDraggableRegion>& regions) OVERRIDE;
Delegate* delegate_;
CefRefPtr<CefBrowser> browser_;
CefRefPtr<ClientHandler> client_handler_;
bool is_closing_;
private:
DISALLOW_COPY_AND_ASSIGN(BrowserWindow);
};
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_BROWSER_WINDOW_H_
// 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_BROWSER_BROWSER_WINDOW_OSR_MAC_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_BROWSER_WINDOW_OSR_MAC_H_
#pragma once
#include "cefclient/browser/browser_window.h"
#include "cefclient/browser/client_handler_osr.h"
#include "cefclient/browser/osr_renderer.h"
namespace client {
// Represents a native child window hosting a single off-screen browser
// instance. The methods of this class must be called on the main thread unless
// otherwise indicated.
class BrowserWindowOsrMac : public BrowserWindow,
public ClientHandlerOsr::OsrDelegate {
public:
// Constructor may be called on any thread.
// |delegate| must outlive this object.
BrowserWindowOsrMac(BrowserWindow::Delegate* delegate,
const std::string& startup_url,
const OsrRenderer::Settings& settings);
~BrowserWindowOsrMac();
// BrowserWindow methods.
void CreateBrowser(ClientWindowHandle parent_handle,
const CefRect& rect,
const CefBrowserSettings& settings,
CefRefPtr<CefRequestContext> request_context) OVERRIDE;
void GetPopupConfig(CefWindowHandle temp_handle,
CefWindowInfo& windowInfo,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings) OVERRIDE;
void ShowPopup(ClientWindowHandle parent_handle,
int x, int y, size_t width, size_t height) OVERRIDE;
void Show() OVERRIDE;
void Hide() OVERRIDE;
void SetBounds(int x, int y, size_t width, size_t height) OVERRIDE;
void SetFocus(bool focus) OVERRIDE;
void SetDeviceScaleFactor(float device_scale_factor) OVERRIDE;
float GetDeviceScaleFactor() const OVERRIDE;
ClientWindowHandle GetWindowHandle() const OVERRIDE;
// ClientHandlerOsr::OsrDelegate methods.
void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
bool GetRootScreenRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) OVERRIDE;
bool GetViewRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) OVERRIDE;
bool GetScreenPoint(CefRefPtr<CefBrowser> browser,
int viewX,
int viewY,
int& screenX,
int& screenY) OVERRIDE;
bool GetScreenInfo(CefRefPtr<CefBrowser> browser,
CefScreenInfo& screen_info) OVERRIDE;
void OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) OVERRIDE;
void OnPopupSize(CefRefPtr<CefBrowser> browser,
const CefRect& rect) OVERRIDE;
void OnPaint(CefRefPtr<CefBrowser> browser,
CefRenderHandler::PaintElementType type,
const CefRenderHandler::RectList& dirtyRects,
const void* buffer,
int width,
int height) OVERRIDE;
void OnCursorChange(CefRefPtr<CefBrowser> browser,
CefCursorHandle cursor,
CefRenderHandler::CursorType type,
const CefCursorInfo& custom_cursor_info) OVERRIDE;
bool StartDragging(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDragData> drag_data,
CefRenderHandler::DragOperationsMask allowed_ops,
int x, int y) OVERRIDE;
void UpdateDragCursor(CefRefPtr<CefBrowser> browser,
CefRenderHandler::DragOperation operation) OVERRIDE;
private:
// Create the NSView.
void Create(ClientWindowHandle parent_handle, const CefRect& rect);
// The below members will only be accessed on the main thread which should be
// the same as the CEF UI thread.
OsrRenderer renderer_;
ClientWindowHandle nsview_;
bool hidden_;
bool painting_popup_;
DISALLOW_COPY_AND_ASSIGN(BrowserWindowOsrMac);
};
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_BROWSER_WINDOW_OSR_MAC_H_
// 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_BROWSER_BROWSER_WINDOW_STD_MAC_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_BROWSER_WINDOW_STD_MAC_H_
#pragma once
#include "cefclient/browser/browser_window.h"
namespace client {
// Represents a native child window hosting a single windowed browser instance.
// The methods of this class must be called on the main thread unless otherwise
// indicated.
class BrowserWindowStdMac : public BrowserWindow {
public:
// Constructor may be called on any thread.
// |delegate| must outlive this object.
BrowserWindowStdMac(Delegate* delegate,
const std::string& startup_url);
// BrowserWindow methods.
void CreateBrowser(ClientWindowHandle parent_handle,
const CefRect& rect,
const CefBrowserSettings& settings,
CefRefPtr<CefRequestContext> request_context) OVERRIDE;
void GetPopupConfig(CefWindowHandle temp_handle,
CefWindowInfo& windowInfo,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings) OVERRIDE;
void ShowPopup(ClientWindowHandle parent_handle,
int x, int y, size_t width, size_t height) OVERRIDE;
void Show() OVERRIDE;
void Hide() OVERRIDE;
void SetBounds(int x, int y, size_t width, size_t height) OVERRIDE;
void SetFocus(bool focus) OVERRIDE;
ClientWindowHandle GetWindowHandle() const OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(BrowserWindowStdMac);
};
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_BROWSER_WINDOW_STD_MAC_H_
// 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/browser/browser_window_std_mac.h"
#include <Cocoa/Cocoa.h>
#include "include/base/cef_logging.h"
#include "cefclient/browser/client_handler_std.h"
#include "cefclient/browser/main_message_loop.h"
namespace client {
BrowserWindowStdMac::BrowserWindowStdMac(Delegate* delegate,
const std::string& startup_url)
: BrowserWindow(delegate) {
client_handler_ = new ClientHandlerStd(this, startup_url);
}
void BrowserWindowStdMac::CreateBrowser(
ClientWindowHandle parent_handle,
const CefRect& rect,
const CefBrowserSettings& settings,
CefRefPtr<CefRequestContext> request_context) {
REQUIRE_MAIN_THREAD();
CefWindowInfo window_info;
window_info.SetAsChild(parent_handle,
rect.x, rect.y, rect.width, rect.height);
CefBrowserHost::CreateBrowser(window_info, client_handler_,
client_handler_->startup_url(),
settings, request_context);
}
void BrowserWindowStdMac::GetPopupConfig(CefWindowHandle temp_handle,
CefWindowInfo& windowInfo,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings) {
// Note: This method may be called on any thread.
// The window will be properly sized after the browser is created.
windowInfo.SetAsChild(temp_handle, 0, 0, 0, 0);
client = client_handler_;
}
void BrowserWindowStdMac::ShowPopup(ClientWindowHandle parent_handle,
int x, int y, size_t width, size_t height) {
REQUIRE_MAIN_THREAD();
NSView* browser_view = GetWindowHandle();
// Re-parent |browser_view| to |parent_handle|.
[browser_view removeFromSuperview];
[parent_handle addSubview:browser_view];
NSSize size = NSMakeSize(static_cast<int>(width), static_cast<int>(height));
[browser_view setFrameSize:size];
}
void BrowserWindowStdMac::Show() {
REQUIRE_MAIN_THREAD();
if (browser_)
browser_->GetHost()->SetWindowVisibility(true);
}
void BrowserWindowStdMac::Hide() {
REQUIRE_MAIN_THREAD();
if (browser_)
browser_->GetHost()->SetWindowVisibility(false);
}
void BrowserWindowStdMac::SetBounds(int x, int y, size_t width, size_t height) {
REQUIRE_MAIN_THREAD();
// Nothing to do here. Cocoa will size the browser for us.
}
void BrowserWindowStdMac::SetFocus(bool focus) {
REQUIRE_MAIN_THREAD();
if (browser_)
browser_->GetHost()->SetFocus(focus);
}
ClientWindowHandle BrowserWindowStdMac::GetWindowHandle() const {
REQUIRE_MAIN_THREAD();
if (browser_)
return browser_->GetHost()->GetWindowHandle();
return NULL;
}
} // namespace client
// Copyright (c) 2014 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/browser/bytes_write_handler.h"
#include <cstdio>
#include <cstdlib>
#include "include/wrapper/cef_helpers.h"
namespace client {
BytesWriteHandler::BytesWriteHandler(size_t grow)
: grow_(grow),
datasize_(grow),
offset_(0) {
DCHECK_GT(grow, 0U);
data_ = malloc(grow);
DCHECK(data_ != NULL);
}
BytesWriteHandler::~BytesWriteHandler() {
if (data_)
free(data_);
}
size_t BytesWriteHandler::Write(const void* ptr, size_t size, size_t n) {
base::AutoLock lock_scope(lock_);
size_t rv;
if (offset_ + static_cast<int64>(size * n) >= datasize_ &&
Grow(size * n) == 0) {
rv = 0;
} else {
memcpy(reinterpret_cast<char*>(data_) + offset_, ptr, size * n);
offset_ += size * n;
rv = n;
}
return rv;
}
int BytesWriteHandler::Seek(int64 offset, int whence) {
int rv = -1L;
base::AutoLock lock_scope(lock_);
switch (whence) {
case SEEK_CUR:
if (offset_ + offset > datasize_ || offset_ + offset < 0)
break;
offset_ += offset;
rv = 0;
break;
case SEEK_END: {
int64 offset_abs = std::abs(offset);
if (offset_abs > datasize_)
break;
offset_ = datasize_ - offset_abs;
rv = 0;
break;
}
case SEEK_SET:
if (offset > datasize_ || offset < 0)
break;
offset_ = offset;
rv = 0;
break;
}
return rv;
}
int64 BytesWriteHandler::Tell() {
base::AutoLock lock_scope(lock_);
return offset_;
}
int BytesWriteHandler::Flush() {
return 0;
}
size_t BytesWriteHandler::Grow(size_t size) {
base::AutoLock lock_scope(lock_);
size_t rv;
size_t s = (size > grow_ ? size : grow_);
void* tmp = realloc(data_, datasize_ + s);
DCHECK(tmp != NULL);
if (tmp) {
data_ = tmp;
datasize_ += s;
rv = datasize_;
} else {
rv = 0;
}
return rv;
}
} // namespace client
// Copyright (c) 2014 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_BROWSER_BYTES_WRITE_HANDLER_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_BYTES_WRITE_HANDLER_H_
#pragma once
#include "include/base/cef_lock.h"
#include "include/cef_stream.h"
namespace client {
class BytesWriteHandler : public CefWriteHandler {
public:
explicit BytesWriteHandler(size_t grow);
~BytesWriteHandler();
size_t Write(const void* ptr, size_t size, size_t n) OVERRIDE;
int Seek(int64 offset, int whence) OVERRIDE;
int64 Tell() OVERRIDE;
int Flush() OVERRIDE;
bool MayBlock() OVERRIDE { return false; }
void* GetData() { return data_; }
int64 GetDataSize() { return offset_; }
private:
size_t Grow(size_t size);
size_t grow_;
void* data_;
int64 datasize_;
int64 offset_;
base::Lock lock_;
IMPLEMENT_REFCOUNTING(BytesWriteHandler);
DISALLOW_COPY_AND_ASSIGN(BytesWriteHandler);
};
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_BYTES_WRITE_HANDLER_H_
// 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/browser/client_app_browser.h"
#include "include/base/cef_logging.h"
#include "include/cef_cookie.h"
#include "cefclient/common/client_switches.h"
namespace client {
ClientAppBrowser::ClientAppBrowser() {
}
void ClientAppBrowser::OnBeforeCommandLineProcessing(
const CefString& process_type,
CefRefPtr<CefCommandLine> command_line) {
// Pass additional command-line flags to the browser process.
if (process_type.empty()) {
// Pass additional command-line flags when off-screen rendering is enabled.
if (command_line->HasSwitch(switches::kOffScreenRenderingEnabled)) {
// If the PDF extension is enabled then cc Surfaces must be disabled for
// PDFs to render correctly.
// See https://bitbucket.org/chromiumembedded/cef/issues/1689 for details.
if (!command_line->HasSwitch("disable-extensions") &&
!command_line->HasSwitch("disable-pdf-extension")) {
command_line->AppendSwitch("disable-surfaces");
}
// Use software rendering and compositing (disable GPU) for increased FPS
// and decreased CPU usage. This will also disable WebGL so remove these
// switches if you need that capability.
// See https://bitbucket.org/chromiumembedded/cef/issues/1257 for details.
if (!command_line->HasSwitch(switches::kEnableGPU)) {
command_line->AppendSwitch("disable-gpu");
command_line->AppendSwitch("disable-gpu-compositing");
}
// Synchronize the frame rate between all processes. This results in
// decreased CPU usage by avoiding the generation of extra frames that
// would otherwise be discarded. The frame rate can be set at browser
// creation time via CefBrowserSettings.windowless_frame_rate or changed
// dynamically using CefBrowserHost::SetWindowlessFrameRate. In cefclient
// it can be set via the command-line using `--off-screen-frame-rate=XX`.
// See https://bitbucket.org/chromiumembedded/cef/issues/1368 for details.
command_line->AppendSwitch("enable-begin-frame-scheduling");
}
}
}
void ClientAppBrowser::OnContextInitialized() {
CreateDelegates(delegates_);
// Register cookieable schemes with the global cookie manager.
CefRefPtr<CefCookieManager> manager =
CefCookieManager::GetGlobalManager(NULL);
DCHECK(manager.get());
manager->SetSupportedSchemes(cookieable_schemes_, NULL);
print_handler_ = CreatePrintHandler();
DelegateSet::iterator it = delegates_.begin();
for (; it != delegates_.end(); ++it)
(*it)->OnContextInitialized(this);
}
void ClientAppBrowser::OnBeforeChildProcessLaunch(
CefRefPtr<CefCommandLine> command_line) {
DelegateSet::iterator it = delegates_.begin();
for (; it != delegates_.end(); ++it)
(*it)->OnBeforeChildProcessLaunch(this, command_line);
}
void ClientAppBrowser::OnRenderProcessThreadCreated(
CefRefPtr<CefListValue> extra_info) {
DelegateSet::iterator it = delegates_.begin();
for (; it != delegates_.end(); ++it)
(*it)->OnRenderProcessThreadCreated(this, extra_info);
}
} // namespace client
// 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_BROWSER_CLIENT_APP_BROWSER_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_APP_BROWSER_H_
#pragma once
#include <set>
#include "cefclient/common/client_app.h"
namespace client {
// Client app implementation for the browser process.
class ClientAppBrowser : public ClientApp,
public CefBrowserProcessHandler {
public:
// Interface for browser delegates. All Delegates must be returned via
// CreateDelegates. Do not perform work in the Delegate
// constructor. See CefBrowserProcessHandler for documentation.
class Delegate : public virtual CefBase {
public:
virtual void OnContextInitialized(CefRefPtr<ClientApp> app) {}
virtual void OnBeforeChildProcessLaunch(
CefRefPtr<ClientAppBrowser> app,
CefRefPtr<CefCommandLine> command_line) {}
virtual void OnRenderProcessThreadCreated(
CefRefPtr<ClientAppBrowser> app,
CefRefPtr<CefListValue> extra_info) {}
};
typedef std::set<CefRefPtr<Delegate> > DelegateSet;
ClientAppBrowser();
private:
// Creates all of the Delegate objects. Implemented by cefclient in
// client_app_delegates_browser.cc
static void CreateDelegates(DelegateSet& delegates);
// Create the Linux print handler. Implemented by cefclient in
// client_app_delegates_browser.cc
static CefRefPtr<CefPrintHandler> CreatePrintHandler();
// CefApp methods.
void OnBeforeCommandLineProcessing(
const CefString& process_type,
CefRefPtr<CefCommandLine> command_line) OVERRIDE;
CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() OVERRIDE {
return this;
}
// CefBrowserProcessHandler methods.
void OnContextInitialized() OVERRIDE;
void OnBeforeChildProcessLaunch(
CefRefPtr<CefCommandLine> command_line) OVERRIDE;
void OnRenderProcessThreadCreated(
CefRefPtr<CefListValue> extra_info) OVERRIDE;
CefRefPtr<CefPrintHandler> GetPrintHandler() OVERRIDE {
return print_handler_;
}
// Set of supported Delegates.
DelegateSet delegates_;
CefRefPtr<CefPrintHandler> print_handler_;
IMPLEMENT_REFCOUNTING(ClientAppBrowser);
DISALLOW_COPY_AND_ASSIGN(ClientAppBrowser);
};
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_APP_BROWSER_H_
// Copyright (c) 2012 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/browser/client_app_browser.h"
#if defined(OS_LINUX)
#include "cefclient/browser/print_handler_gtk.h"
#endif
namespace client {
// static
void ClientAppBrowser::CreateDelegates(DelegateSet& delegates) {
}
// static
CefRefPtr<CefPrintHandler> ClientAppBrowser::CreatePrintHandler() {
#if defined(OS_LINUX)
return new ClientPrintHandlerGtk();
#else
return NULL;
#endif
}
} // namespace client
// 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/browser/client_handler_osr.h"
#include "include/base/cef_bind.h"
#include "include/wrapper/cef_closure_task.h"
#include "include/wrapper/cef_helpers.h"
namespace client {
ClientHandlerOsr::ClientHandlerOsr(Delegate* delegate,
OsrDelegate* osr_delegate,
const std::string& startup_url)
: ClientHandler(delegate, true, startup_url),
osr_delegate_(osr_delegate) {
DCHECK(osr_delegate_);
}
void ClientHandlerOsr::DetachOsrDelegate() {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&ClientHandlerOsr::DetachOsrDelegate, this));
return;
}
DCHECK(osr_delegate_);
osr_delegate_ = NULL;
}
void ClientHandlerOsr::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
CEF_REQUIRE_UI_THREAD();
if (osr_delegate_)
osr_delegate_->OnAfterCreated(browser);
ClientHandler::OnAfterCreated(browser);
}
void ClientHandlerOsr::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
CEF_REQUIRE_UI_THREAD();
if (osr_delegate_)
osr_delegate_->OnBeforeClose(browser);
ClientHandler::OnBeforeClose(browser);
}
bool ClientHandlerOsr::GetRootScreenRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
return false;
return osr_delegate_->GetRootScreenRect(browser, rect);
}
bool ClientHandlerOsr::GetViewRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
return false;
return osr_delegate_->GetViewRect(browser, rect);
}
bool ClientHandlerOsr::GetScreenPoint(CefRefPtr<CefBrowser> browser,
int viewX,
int viewY,
int& screenX,
int& screenY) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
return false;
return osr_delegate_->GetScreenPoint(browser, viewX, viewY, screenX, screenY);
}
bool ClientHandlerOsr::GetScreenInfo(CefRefPtr<CefBrowser> browser,
CefScreenInfo& screen_info) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
return false;
return osr_delegate_->GetScreenInfo(browser, screen_info);
}
void ClientHandlerOsr::OnPopupShow(CefRefPtr<CefBrowser> browser,
bool show) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
return;
return osr_delegate_->OnPopupShow(browser, show);
}
void ClientHandlerOsr::OnPopupSize(CefRefPtr<CefBrowser> browser,
const CefRect& rect) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
return;
return osr_delegate_->OnPopupSize(browser, rect);
}
void ClientHandlerOsr::OnPaint(CefRefPtr<CefBrowser> browser,
PaintElementType type,
const RectList& dirtyRects,
const void* buffer,
int width,
int height) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
return;
osr_delegate_->OnPaint(browser, type, dirtyRects, buffer, width, height);
}
void ClientHandlerOsr::OnCursorChange(
CefRefPtr<CefBrowser> browser,
CefCursorHandle cursor,
CursorType type,
const CefCursorInfo& custom_cursor_info) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
return;
osr_delegate_->OnCursorChange(browser, cursor, type, custom_cursor_info);
}
bool ClientHandlerOsr::StartDragging(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDragData> drag_data,
CefRenderHandler::DragOperationsMask allowed_ops,
int x, int y) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
return false;
return osr_delegate_->StartDragging(browser, drag_data, allowed_ops, x, y);
}
void ClientHandlerOsr::UpdateDragCursor(CefRefPtr<CefBrowser> browser,
CefRenderHandler::DragOperation operation) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
return;
osr_delegate_->UpdateDragCursor(browser, operation);
}
} // namespace client
// 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_BROWSER_CLIENT_HANDLER_OSR_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_HANDLER_OSR_H_
#pragma once
#include "cefclient/browser/client_handler.h"
namespace client {
// Client handler implementation for windowless browsers. There will only ever
// be one browser per handler instance.
class ClientHandlerOsr : public ClientHandler,
public CefRenderHandler {
public:
// Implement this interface to receive notification of ClientHandlerOsr
// events. The methods of this class will be called on the CEF UI thread.
class OsrDelegate {
public:
// These methods match the CefLifeSpanHandler interface.
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) = 0;
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) = 0;
// These methods match the CefRenderHandler interface.
virtual bool GetRootScreenRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) = 0;
virtual bool GetViewRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) = 0;
virtual bool GetScreenPoint(CefRefPtr<CefBrowser> browser,
int viewX,
int viewY,
int& screenX,
int& screenY) = 0;
virtual bool GetScreenInfo(CefRefPtr<CefBrowser> browser,
CefScreenInfo& screen_info) = 0;
virtual void OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) = 0;
virtual void OnPopupSize(CefRefPtr<CefBrowser> browser,
const CefRect& rect) = 0;
virtual void OnPaint(CefRefPtr<CefBrowser> browser,
PaintElementType type,
const RectList& dirtyRects,
const void* buffer,
int width,
int height) = 0;
virtual void OnCursorChange(
CefRefPtr<CefBrowser> browser,
CefCursorHandle cursor,
CefRenderHandler::CursorType type,
const CefCursorInfo& custom_cursor_info) = 0;
virtual bool StartDragging(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDragData> drag_data,
CefRenderHandler::DragOperationsMask allowed_ops,
int x, int y) = 0;
virtual void UpdateDragCursor(
CefRefPtr<CefBrowser> browser,
CefRenderHandler::DragOperation operation) = 0;
protected:
virtual ~OsrDelegate() {}
};
ClientHandlerOsr(Delegate* delegate,
OsrDelegate* osr_delegate,
const std::string& startup_url);
// This object may outlive the OsrDelegate object so it's necessary for the
// OsrDelegate to detach itself before destruction.
void DetachOsrDelegate();
// CefClient methods.
CefRefPtr<CefRenderHandler> GetRenderHandler() OVERRIDE {
return this;
}
// CefLifeSpanHandler methods.
void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
// CefRenderHandler methods.
bool GetRootScreenRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) OVERRIDE;
bool GetViewRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) OVERRIDE;
bool GetScreenPoint(CefRefPtr<CefBrowser> browser,
int viewX,
int viewY,
int& screenX,
int& screenY) OVERRIDE;
bool GetScreenInfo(CefRefPtr<CefBrowser> browser,
CefScreenInfo& screen_info) OVERRIDE;
void OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) OVERRIDE;
void OnPopupSize(CefRefPtr<CefBrowser> browser,
const CefRect& rect) OVERRIDE;
void OnPaint(CefRefPtr<CefBrowser> browser,
CefRenderHandler::PaintElementType type,
const CefRenderHandler::RectList& dirtyRects,
const void* buffer,
int width,
int height) OVERRIDE;
void OnCursorChange(CefRefPtr<CefBrowser> browser,
CefCursorHandle cursor,
CursorType type,
const CefCursorInfo& custom_cursor_info) OVERRIDE;
bool StartDragging(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDragData> drag_data,
CefRenderHandler::DragOperationsMask allowed_ops,
int x, int y) OVERRIDE;
void UpdateDragCursor(CefRefPtr<CefBrowser> browser,
CefRenderHandler::DragOperation operation) OVERRIDE;
private:
// Only accessed on the UI thread.
OsrDelegate* osr_delegate_;
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(ClientHandlerOsr);
DISALLOW_COPY_AND_ASSIGN(ClientHandlerOsr);
};
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_HANDLER_OSR_H_
// 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/browser/client_handler_std.h"
namespace client {
ClientHandlerStd::ClientHandlerStd(Delegate* delegate,
const std::string& startup_url)
: ClientHandler(delegate, false, startup_url) {
}
} // namespace client
// 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_BROWSER_CLIENT_HANDLER_STD_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_HANDLER_STD_H_
#pragma once
#include "cefclient/browser/client_handler.h"
namespace client {
// Client handler implementation for windowed browsers. There will only ever be
// one browser per handler instance.
class ClientHandlerStd : public ClientHandler {
public:
ClientHandlerStd(Delegate* delegate,
const std::string& startup_url);
private:
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(ClientHandlerStd);
DISALLOW_COPY_AND_ASSIGN(ClientHandlerStd);
};
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_HANDLER_STD_H_
// 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_BROWSER_CLIENT_TYPES_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_TYPES_H_
#pragma once
#include "include/cef_base.h"
#if defined(OS_LINUX)
#include <gtk/gtk.h>
// The Linux client uses GTK instead of the underlying platform type (X11).
#define ClientWindowHandle GtkWidget*
#else
#define ClientWindowHandle CefWindowHandle
#endif
#if defined(OS_MACOSX)
// Forward declaration of ObjC types used by cefclient and not provided by
// include/internal/cef_types_mac.h.
#ifdef __cplusplus
#ifdef __OBJC__
@class NSWindow;
#else
class NSWindow;
#endif
#endif
#endif // defined OS_MACOSX
#endif // CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_TYPES_H_
// Copyright (c) 2012 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/browser/dialog_test.h"
#include <string>
#include "include/cef_browser.h"
#include "include/wrapper/cef_helpers.h"
namespace client {
namespace dialog_test {
namespace {
const char kTestUrl[] = "http://tests/dialogs";
const char kFileOpenMessageName[] = "DialogTest.FileOpen";
const char kFileOpenMultipleMessageName[] = "DialogTest.FileOpenMultiple";
const char kFileOpenFolderMessageName[] = "DialogTest.FileOpenFolder";
const char kFileSaveMessageName[] = "DialogTest.FileSave";
#if defined(OS_WIN)
#define PATH_SEP '\\'
#else
#define PATH_SEP '/'
#endif
// Store persistent dialog state information.
class DialogState : public base::RefCountedThreadSafe<DialogState> {
public:
DialogState()
: mode_(FILE_DIALOG_OPEN),
last_selected_filter_(0),
pending_(false) {}
cef_file_dialog_mode_t mode_;
int last_selected_filter_;
CefString last_file_;
bool pending_;
DISALLOW_COPY_AND_ASSIGN(DialogState);
};
// Callback executed when the file dialog is dismissed.
class DialogCallback : public CefRunFileDialogCallback {
public:
DialogCallback(
CefRefPtr<CefMessageRouterBrowserSide::Callback> router_callback,
scoped_refptr<DialogState> dialog_state)
: router_callback_(router_callback),
dialog_state_(dialog_state) {
}
virtual void OnFileDialogDismissed(
int last_selected_filter,
const std::vector<CefString>& file_paths) OVERRIDE {
CEF_REQUIRE_UI_THREAD();
DCHECK(dialog_state_->pending_);
if (!file_paths.empty()) {
if (dialog_state_->mode_ != FILE_DIALOG_OPEN_FOLDER)
dialog_state_->last_selected_filter_ = last_selected_filter;
dialog_state_->last_file_ = file_paths[0];
if (dialog_state_->mode_ == FILE_DIALOG_OPEN_FOLDER) {
std::string last_file = dialog_state_->last_file_;
if (last_file[last_file.length() - 1] != PATH_SEP) {
// Add a trailing slash so we know it's a directory. Otherwise, file
// dialogs will think the last path component is a file name.
last_file += PATH_SEP;
dialog_state_->last_file_ = last_file;
}
}
}
// Send a message back to the render process with the list of file paths.
std::string response;
for (int i = 0; i < static_cast<int>(file_paths.size()); ++i) {
if (!response.empty())
response += "|"; // Use a delimiter disallowed in file paths.
response += file_paths[i];
}
router_callback_->Success(response);
router_callback_ = NULL;
dialog_state_->pending_ = false;
dialog_state_ = NULL;
}
private:
CefRefPtr<CefMessageRouterBrowserSide::Callback> router_callback_;
scoped_refptr<DialogState> dialog_state_;
IMPLEMENT_REFCOUNTING(DialogCallback);
DISALLOW_COPY_AND_ASSIGN(DialogCallback);
};
// Handle messages in the browser process.
class Handler : public CefMessageRouterBrowserSide::Handler {
public:
Handler() {}
// Called due to cefQuery execution in dialogs.html.
virtual bool OnQuery(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int64 query_id,
const CefString& request,
bool persistent,
CefRefPtr<Callback> callback) OVERRIDE {
CEF_REQUIRE_UI_THREAD();
// Only handle messages from the test URL.
const std::string& url = frame->GetURL();
if (url.find(kTestUrl) != 0)
return false;
if (!dialog_state_.get())
dialog_state_ = new DialogState;
// Make sure we're only running one dialog at a time.
DCHECK(!dialog_state_->pending_);
std::vector<CefString> accept_filters;
std::string title;
const std::string& message_name = request;
if (message_name == kFileOpenMessageName) {
dialog_state_->mode_ = FILE_DIALOG_OPEN;
title = "My Open Dialog";
} else if (message_name == kFileOpenMultipleMessageName) {
dialog_state_->mode_ = FILE_DIALOG_OPEN_MULTIPLE;
title = "My Open Multiple Dialog";
} else if (message_name == kFileOpenFolderMessageName) {
dialog_state_->mode_ = FILE_DIALOG_OPEN_FOLDER;
title = "My Open Folder Dialog";
} else if (message_name == kFileSaveMessageName) {
dialog_state_->mode_ = static_cast<cef_file_dialog_mode_t>(
FILE_DIALOG_SAVE | FILE_DIALOG_OVERWRITEPROMPT_FLAG);
title = "My Save Dialog";
} else {
NOTREACHED();
return true;
}
if (dialog_state_->mode_ != FILE_DIALOG_OPEN_FOLDER) {
// Build filters based on mime time.
accept_filters.push_back("text/*");
// Build filters based on file extension.
accept_filters.push_back(".log");
accept_filters.push_back(".patch");
// Add specific filters as-is.
accept_filters.push_back("Document Files|.doc;.odt");
accept_filters.push_back("Image Files|.png;.jpg;.gif");
accept_filters.push_back("PDF Files|.pdf");
}
dialog_state_->pending_ = true;
browser->GetHost()->RunFileDialog(
dialog_state_->mode_,
title,
dialog_state_->last_file_,
accept_filters,
dialog_state_->last_selected_filter_,
new DialogCallback(callback, dialog_state_));
return true;
}
private:
scoped_refptr<DialogState> dialog_state_;
DISALLOW_COPY_AND_ASSIGN(Handler);
};
} // namespace
void CreateMessageHandlers(test_runner::MessageHandlerSet& handlers) {
handlers.insert(new Handler());
}
} // namespace dialog_test
} // namespace client
// Copyright (c) 2012 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_BROWSER_DIALOG_TEST_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_DIALOG_TEST_H_
#pragma once
#include "cefclient/browser/test_runner.h"
namespace client {
namespace dialog_test {
// Create message handlers. Called from test_runner.cc.
void CreateMessageHandlers(test_runner::MessageHandlerSet& handlers);
} // namespace dialog_test
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_DIALOG_TEST_H_
// 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/browser/geometry_util.h"
#include <cmath>
namespace client {
int LogicalToDevice(int value, float device_scale_factor) {
float scaled_val = static_cast<float>(value) * device_scale_factor;
return static_cast<int>(std::floor(scaled_val));
}
CefRect LogicalToDevice(const CefRect& value, float device_scale_factor) {
return CefRect(LogicalToDevice(value.x, device_scale_factor),
LogicalToDevice(value.y, device_scale_factor),
LogicalToDevice(value.width, device_scale_factor),
LogicalToDevice(value.height, device_scale_factor));
}
int DeviceToLogical(int value, float device_scale_factor) {
float scaled_val = static_cast<float>(value) / device_scale_factor;
return static_cast<int>(std::floor(scaled_val));
}
void DeviceToLogical(CefMouseEvent& value, float device_scale_factor) {
value.x = DeviceToLogical(value.x, device_scale_factor);
value.y = DeviceToLogical(value.y, device_scale_factor);
}
} // namespace client
// 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_BROWSER_GEOMETRY_UTIL_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_GEOMETRY_UTIL_H_
#pragma once
#include "include/internal/cef_types_wrappers.h"
namespace client {
// Convert |value| from logical coordinates to device coordinates.
int LogicalToDevice(int value, float device_scale_factor);
CefRect LogicalToDevice(const CefRect& value, float device_scale_factor);
// Convert |value| from device coordinates to logical coordinates.
int DeviceToLogical(int value, float device_scale_factor);
void DeviceToLogical(CefMouseEvent& value, float device_scale_factor);
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_GEOMETRY_UTIL_H_
// 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/browser/main_context.h"
#include "include/base/cef_logging.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
// 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_BROWSER_MAIN_CONTEXT_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_MAIN_CONTEXT_H_
#pragma once
#include <string>
#include "include/base/cef_ref_counted.h"
#include "include/internal/cef_types_wrappers.h"
#include "cefclient/browser/osr_renderer.h"
namespace client {
class RootWindowManager;
// 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;
// Returns the background color.
virtual cef_color_t GetBackgroundColor() = 0;
// Populate |settings| based on command-line arguments.
virtual void PopulateSettings(CefSettings* settings) = 0;
virtual void PopulateBrowserSettings(CefBrowserSettings* settings) = 0;
virtual void PopulateOsrSettings(OsrRenderer::Settings* settings) = 0;
// Returns the object used to create/manage RootWindow instances.
virtual RootWindowManager* GetRootWindowManager() = 0;
protected:
MainContext();
virtual ~MainContext();
private:
DISALLOW_COPY_AND_ASSIGN(MainContext);
};
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_MAIN_CONTEXT_H_
// 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/browser/main_context_impl.h"
#include "include/cef_parser.h"
#include "cefclient/common/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(CefRefPtr<CefCommandLine> command_line,
bool terminate_when_all_windows_closed)
: command_line_(command_line),
terminate_when_all_windows_closed_(terminate_when_all_windows_closed),
initialized_(false),
shutdown_(false),
background_color_(CefColorSetARGB(255, 255, 255, 255)) {
DCHECK(command_line_.get());
// Set the main URL.
if (command_line_->HasSwitch(switches::kUrl))
main_url_ = command_line_->GetSwitchValue(switches::kUrl);
if (main_url_.empty())
main_url_ = kDefaultUrl;
if (command_line_->HasSwitch(switches::kBackgroundColor)) {
// Parse the background color value.
CefParseCSSColor(command_line_->GetSwitchValue(switches::kBackgroundColor),
false, background_color_);
}
}
MainContextImpl::~MainContextImpl() {
// The context must either not have been initialized, or it must have also
// been shut down.
DCHECK(!initialized_ || shutdown_);
}
std::string MainContextImpl::GetConsoleLogPath() {
return GetAppWorkingDirectory() + "console.log";
}
std::string MainContextImpl::GetMainURL() {
return main_url_;
}
cef_color_t MainContextImpl::GetBackgroundColor() {
return background_color_;
}
void MainContextImpl::PopulateSettings(CefSettings* settings) {
#if defined(OS_WIN)
settings->multi_threaded_message_loop =
command_line_->HasSwitch(switches::kMultiThreadedMessageLoop);
#endif
CefString(&settings->cache_path) =
command_line_->GetSwitchValue(switches::kCachePath);
if (command_line_->HasSwitch(switches::kOffScreenRenderingEnabled))
settings->windowless_rendering_enabled = true;
settings->background_color = background_color_;
}
void MainContextImpl::PopulateBrowserSettings(CefBrowserSettings* settings) {
if (command_line_->HasSwitch(switches::kOffScreenFrameRate)) {
settings->windowless_frame_rate = atoi(command_line_->
GetSwitchValue(switches::kOffScreenFrameRate).ToString().c_str());
}
}
void MainContextImpl::PopulateOsrSettings(OsrRenderer::Settings* settings) {
settings->transparent =
command_line_->HasSwitch(switches::kTransparentPaintingEnabled);
settings->show_update_rect =
command_line_->HasSwitch(switches::kShowUpdateRect);
settings->background_color = background_color_;
}
RootWindowManager* MainContextImpl::GetRootWindowManager() {
DCHECK(InValidState());
return root_window_manager_.get();
}
bool MainContextImpl::Initialize(const CefMainArgs& args,
const CefSettings& settings,
CefRefPtr<CefApp> application,
void* windows_sandbox_info) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!initialized_);
DCHECK(!shutdown_);
if (!CefInitialize(args, settings, application, windows_sandbox_info))
return false;
// Need to create the RootWindowManager after calling CefInitialize because
// TempWindowX11 uses cef_get_xdisplay().
root_window_manager_.reset(
new RootWindowManager(terminate_when_all_windows_closed_));
initialized_ = true;
return true;
}
void MainContextImpl::Shutdown() {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(initialized_);
DCHECK(!shutdown_);
root_window_manager_.reset();
CefShutdown();
shutdown_ = true;
}
} // namespace client
// 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_BROWSER_MAIN_CONTEXT_IMPL_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_MAIN_CONTEXT_IMPL_H_
#pragma once
#include "include/base/cef_scoped_ptr.h"
#include "include/base/cef_thread_checker.h"
#include "include/cef_app.h"
#include "include/cef_command_line.h"
#include "cefclient/browser/main_context.h"
#include "cefclient/browser/root_window_manager.h"
namespace client {
// Used to store global context in the browser process.
class MainContextImpl : public MainContext {
public:
MainContextImpl(CefRefPtr<CefCommandLine> command_line,
bool terminate_when_all_windows_closed);
// MainContext members.
std::string GetConsoleLogPath() OVERRIDE;
std::string GetDownloadPath(const std::string& file_name) OVERRIDE;
std::string GetAppWorkingDirectory() OVERRIDE;
std::string GetMainURL() OVERRIDE;
cef_color_t GetBackgroundColor() OVERRIDE;
void PopulateSettings(CefSettings* settings) OVERRIDE;
void PopulateBrowserSettings(CefBrowserSettings* settings) OVERRIDE;
void PopulateOsrSettings(OsrRenderer::Settings* settings) OVERRIDE;
RootWindowManager* GetRootWindowManager() OVERRIDE;
// Initialize CEF and associated main context state. This method must be
// called on the same thread that created this object.
bool Initialize(const CefMainArgs& args,
const CefSettings& settings,
CefRefPtr<CefApp> application,
void* windows_sandbox_info);
// Shut down CEF and associated context state. This method must be called on
// the same thread that created this object.
void Shutdown();
private:
// Allow deletion via scoped_ptr only.
friend struct base::DefaultDeleter<MainContextImpl>;
~MainContextImpl();
// Returns true if the context is in a valid state (initialized and not yet
// shut down).
bool InValidState() const {
return initialized_ && !shutdown_;
}
CefRefPtr<CefCommandLine> command_line_;
const bool terminate_when_all_windows_closed_;
// Track context state. Accessing these variables from multiple threads is
// safe because only a single thread will exist at the time that they're set
// (during context initialization and shutdown).
bool initialized_;
bool shutdown_;
std::string main_url_;
cef_color_t background_color_;
scoped_ptr<RootWindowManager> root_window_manager_;
// Used to verify that methods are called on the correct thread.
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(MainContextImpl);
};
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_MAIN_CONTEXT_IMPL_H_
// 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/browser/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
// 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/browser/main_message_loop.h"
#include "include/cef_task.h"
#include "include/wrapper/cef_closure_task.h"
namespace client {
namespace {
MainMessageLoop* g_main_message_loop = NULL;
} // namespace
MainMessageLoop::MainMessageLoop() {
DCHECK(!g_main_message_loop);
g_main_message_loop = this;
}
MainMessageLoop::~MainMessageLoop() {
g_main_message_loop = NULL;
}
// static
MainMessageLoop* MainMessageLoop::Get() {
DCHECK(g_main_message_loop);
return g_main_message_loop;
}
void MainMessageLoop::PostClosure(const base::Closure& closure) {
PostTask(CefCreateClosureTask(closure));
}
} // namespace client
// 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/browser/main_message_loop_std.h"
#include "include/cef_app.h"
namespace client {
MainMessageLoopStd::MainMessageLoopStd() {
}
int MainMessageLoopStd::Run() {
CefRunMessageLoop();
return 0;
}
void MainMessageLoopStd::Quit() {
CefQuitMessageLoop();
}
void MainMessageLoopStd::PostTask(CefRefPtr<CefTask> task) {
CefPostTask(TID_UI, task);
}
bool MainMessageLoopStd::RunsTasksOnCurrentThread() const {
return CefCurrentlyOn(TID_UI);
}
#if defined(OS_WIN)
void MainMessageLoopStd::SetCurrentModelessDialog(HWND hWndDialog) {
// Nothing to do here. The Chromium message loop implementation will
// internally route dialog messages.
}
#endif
} // namespace client
// 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_BROWSER_MAIN_MESSAGE_LOOP_STD_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_MAIN_MESSAGE_LOOP_STD_H_
#pragma once
#include "cefclient/browser/main_message_loop.h"
namespace client {
// Represents the main message loop in the browser process. This implementation
// is a light-weight wrapper around the Chromium UI thread.
class MainMessageLoopStd : public MainMessageLoop {
public:
MainMessageLoopStd();
// MainMessageLoop methods.
int Run() OVERRIDE;
void Quit() OVERRIDE;
void PostTask(CefRefPtr<CefTask> task) OVERRIDE;
bool RunsTasksOnCurrentThread() const OVERRIDE;
#if defined(OS_WIN)
void SetCurrentModelessDialog(HWND hWndDialog) OVERRIDE;
#endif
private:
DISALLOW_COPY_AND_ASSIGN(MainMessageLoopStd);
};
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_MAIN_MESSAGE_LOOP_STD_H_
/* Localized versions of Info.plist keys */
NSHumanReadableCopyright = "© Chromium Embedded Framework Authors, 2010";
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment