2012-04-03 03:34:16 +02:00
|
|
|
// 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.
|
|
|
|
|
2012-04-12 22:21:50 +02:00
|
|
|
#ifndef CEF_TESTS_CEFCLIENT_CLIENT_APP_H_
|
|
|
|
#define CEF_TESTS_CEFCLIENT_CLIENT_APP_H_
|
2012-04-03 03:34:16 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
2012-06-19 18:29:49 +02:00
|
|
|
#include <vector>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_app.h"
|
|
|
|
|
2012-04-12 22:21:50 +02:00
|
|
|
class ClientApp : public CefApp,
|
2012-06-19 18:29:49 +02:00
|
|
|
public CefBrowserProcessHandler,
|
2012-04-12 22:21:50 +02:00
|
|
|
public CefProxyHandler,
|
|
|
|
public CefRenderProcessHandler {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
2012-04-12 22:21:50 +02:00
|
|
|
// Interface for renderer delegates. All RenderDelegates must be returned via
|
|
|
|
// CreateRenderDelegates. Do not perform work in the RenderDelegate
|
|
|
|
// constructor.
|
|
|
|
class RenderDelegate : public virtual CefBase {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
|
|
|
// Called when WebKit is initialized. Used to register V8 extensions.
|
2012-04-12 22:21:50 +02:00
|
|
|
virtual void OnWebKitInitialized(CefRefPtr<ClientApp> app) {
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Called when a V8 context is created. Used to create V8 window bindings
|
2012-04-12 22:21:50 +02:00
|
|
|
// and set message callbacks. RenderDelegates should check for unique URLs
|
|
|
|
// to avoid interfering with each other.
|
|
|
|
virtual void OnContextCreated(CefRefPtr<ClientApp> app,
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefV8Context> context) {
|
|
|
|
};
|
|
|
|
|
|
|
|
// Called when a V8 context is released. Used to clean up V8 window
|
2012-04-12 22:21:50 +02:00
|
|
|
// bindings. RenderDelegates should check for unique URLs to avoid
|
|
|
|
// interfering with each other.
|
|
|
|
virtual void OnContextReleased(CefRefPtr<ClientApp> app,
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefV8Context> context) {
|
|
|
|
};
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
// Called when the focused node in a frame has changed.
|
|
|
|
virtual void OnFocusedNodeChanged(CefRefPtr<ClientApp> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefDOMNode> node) {
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Called when a process message is received. Return true if the message was
|
2012-04-12 22:21:50 +02:00
|
|
|
// handled and should not be passed on to other handlers. RenderDelegates
|
|
|
|
// should check for unique message names to avoid interfering with each
|
|
|
|
// other.
|
2012-06-11 22:03:49 +02:00
|
|
|
virtual bool OnProcessMessageReceived(
|
2012-04-12 22:21:50 +02:00
|
|
|
CefRefPtr<ClientApp> app,
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefProcessId source_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-12 22:21:50 +02:00
|
|
|
typedef std::set<CefRefPtr<RenderDelegate> > RenderDelegateSet;
|
|
|
|
|
|
|
|
ClientApp();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-04-12 22:21:50 +02:00
|
|
|
// Set the proxy configuration. Should only be called during initialization.
|
|
|
|
void SetProxyConfig(cef_proxy_type_t proxy_type,
|
|
|
|
const CefString& proxy_config) {
|
|
|
|
proxy_type_ = proxy_type;
|
|
|
|
proxy_config_ = proxy_config;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Set a JavaScript callback for the specified |message_name| and |browser_id|
|
|
|
|
// combination. Will automatically be removed when the associated context is
|
|
|
|
// released. Callbacks can also be set in JavaScript using the
|
2012-04-12 22:21:50 +02:00
|
|
|
// app.setMessageCallback function.
|
2012-04-03 03:34:16 +02:00
|
|
|
void SetMessageCallback(const std::string& message_name,
|
|
|
|
int browser_id,
|
|
|
|
CefRefPtr<CefV8Context> context,
|
|
|
|
CefRefPtr<CefV8Value> function);
|
|
|
|
|
|
|
|
// Removes the JavaScript callback for the specified |message_name| and
|
|
|
|
// |browser_id| combination. Returns true if a callback was removed. Callbacks
|
2012-04-12 22:21:50 +02:00
|
|
|
// can also be removed in JavaScript using the app.removeMessageCallback
|
2012-04-03 03:34:16 +02:00
|
|
|
// function.
|
|
|
|
bool RemoveMessageCallback(const std::string& message_name,
|
|
|
|
int browser_id);
|
|
|
|
|
|
|
|
private:
|
2012-04-12 22:21:50 +02:00
|
|
|
// Creates all of the RenderDelegate objects. Implemented in
|
|
|
|
// client_app_delegates.
|
|
|
|
static void CreateRenderDelegates(RenderDelegateSet& delegates);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-04-24 20:01:48 +02:00
|
|
|
// Registers custom schemes. Implemented in client_app_delegates.
|
2012-06-19 18:29:49 +02:00
|
|
|
static void RegisterCustomSchemes(CefRefPtr<CefSchemeRegistrar> registrar,
|
|
|
|
std::vector<CefString>& cookiable_schemes);
|
2012-04-24 20:01:48 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// CefApp methods.
|
2012-04-24 20:01:48 +02:00
|
|
|
virtual void OnRegisterCustomSchemes(
|
|
|
|
CefRefPtr<CefSchemeRegistrar> registrar) OVERRIDE {
|
2012-06-19 18:29:49 +02:00
|
|
|
RegisterCustomSchemes(registrar, cookieable_schemes_);
|
2012-04-24 20:01:48 +02:00
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler()
|
|
|
|
OVERRIDE { return this; }
|
2012-04-03 03:34:16 +02:00
|
|
|
virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler()
|
|
|
|
OVERRIDE { return this; }
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
// CefBrowserProcessHandler methods.
|
2012-04-24 20:01:48 +02:00
|
|
|
virtual CefRefPtr<CefProxyHandler> GetProxyHandler() OVERRIDE { return this; }
|
2012-06-19 18:29:49 +02:00
|
|
|
virtual void OnContextInitialized();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-04-12 22:21:50 +02:00
|
|
|
// CefProxyHandler methods.
|
|
|
|
virtual void GetProxyForUrl(const CefString& url,
|
|
|
|
CefProxyInfo& proxy_info) OVERRIDE;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// CefRenderProcessHandler methods.
|
|
|
|
virtual void OnWebKitInitialized() OVERRIDE;
|
|
|
|
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefV8Context> context) OVERRIDE;
|
|
|
|
virtual void OnContextReleased(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefV8Context> context) OVERRIDE;
|
2012-06-11 17:52:49 +02:00
|
|
|
virtual void OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefDOMNode> node) OVERRIDE;
|
2012-06-11 22:03:49 +02:00
|
|
|
virtual bool OnProcessMessageReceived(
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefProcessId source_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) OVERRIDE;
|
|
|
|
|
2012-04-12 22:21:50 +02:00
|
|
|
// Proxy configuration.
|
|
|
|
cef_proxy_type_t proxy_type_;
|
|
|
|
CefString proxy_config_;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Map of message callbacks.
|
|
|
|
typedef std::map<std::pair<std::string, int>,
|
|
|
|
std::pair<CefRefPtr<CefV8Context>, CefRefPtr<CefV8Value> > >
|
|
|
|
CallbackMap;
|
|
|
|
CallbackMap callback_map_;
|
|
|
|
|
2012-04-12 22:21:50 +02:00
|
|
|
// Set of supported RenderDelegates.
|
|
|
|
RenderDelegateSet render_delegates_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
// Schemes that will be registered with the global cookie manager.
|
|
|
|
std::vector<CefString> cookieable_schemes_;
|
|
|
|
|
2012-04-12 22:21:50 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(ClientApp);
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
2012-04-12 22:21:50 +02:00
|
|
|
#endif // CEF_TESTS_CEFCLIENT_CLIENT_APP_H_
|