mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Make CEF compliant with Google/Chromium style (issue #473).
- Add a new check_style tool based on Google's cpplint that can be used to verify compliance of pending changes and specific files/directories. - Update existing CEF source code to be compliant with the style requirements. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@463 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -2,18 +2,19 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "binding_test.h"
|
||||
#include "cefclient/binding_test.h"
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "include/cef_v8.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
// Implementation of the V8 handler class for the "window.cef_test.Dump"
|
||||
// function.
|
||||
class ClientV8FunctionHandler : public CefV8Handler
|
||||
{
|
||||
public:
|
||||
class ClientV8FunctionHandler : public CefV8Handler {
|
||||
public:
|
||||
ClientV8FunctionHandler() {}
|
||||
virtual ~ClientV8FunctionHandler() {}
|
||||
|
||||
@@ -23,17 +24,14 @@ public:
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) OVERRIDE
|
||||
{
|
||||
if(name == "Dump")
|
||||
{
|
||||
CefString& exception) OVERRIDE {
|
||||
if (name == "Dump") {
|
||||
// The "Dump" function will return a human-readable dump of the input
|
||||
// arguments.
|
||||
std::stringstream stream;
|
||||
size_t i;
|
||||
|
||||
for(i = 0; i < arguments.size(); ++i)
|
||||
{
|
||||
for (i = 0; i < arguments.size(); ++i) {
|
||||
stream << "arg[" << i << "] = ";
|
||||
PrintValue(arguments[i], stream, 0);
|
||||
stream << "\n";
|
||||
@@ -41,15 +39,13 @@ public:
|
||||
|
||||
retval = CefV8Value::CreateString(stream.str());
|
||||
return true;
|
||||
}
|
||||
else if(name == "Call")
|
||||
{
|
||||
} else if (name == "Call") {
|
||||
// The "Call" function will execute a function to get an object and then
|
||||
// return the result of calling a function belonging to that object. The
|
||||
// first arument is the function that will return an object and the second
|
||||
// argument is the function that will be called on that returned object.
|
||||
int argSize = arguments.size();
|
||||
if(argSize < 2 || !arguments[0]->IsFunction()
|
||||
if (argSize < 2 || !arguments[0]->IsFunction()
|
||||
|| !arguments[1]->IsString())
|
||||
return false;
|
||||
|
||||
@@ -68,7 +64,7 @@ public:
|
||||
return false;
|
||||
|
||||
// Verify that the returned value is an object.
|
||||
if(!objectPtr.get() || !objectPtr->IsObject())
|
||||
if (!objectPtr.get() || !objectPtr->IsObject())
|
||||
return false;
|
||||
|
||||
// Retrieve the member function specified by name in the second argument
|
||||
@@ -76,13 +72,13 @@ public:
|
||||
CefRefPtr<CefV8Value> funcPtr =
|
||||
objectPtr->GetValue(arguments[1]->GetStringValue());
|
||||
// Verify that the returned value is a function.
|
||||
if(!funcPtr.get() || !funcPtr->IsFunction())
|
||||
if (!funcPtr.get() || !funcPtr->IsFunction())
|
||||
return false;
|
||||
|
||||
// Pass any additional arguments on to the member function.
|
||||
for(int i = 2; i < argSize; ++i)
|
||||
for (int i = 2; i < argSize; ++i)
|
||||
argList.push_back(arguments[i]);
|
||||
|
||||
|
||||
// Execute the member function.
|
||||
result = funcPtr->ExecuteFunction(arguments[0], argList, retval,
|
||||
exceptionPtr, false);
|
||||
@@ -95,40 +91,39 @@ public:
|
||||
|
||||
// Simple function for formatted output of a V8 value.
|
||||
void PrintValue(CefRefPtr<CefV8Value> value, std::stringstream &stream,
|
||||
int indent)
|
||||
{
|
||||
int indent) {
|
||||
std::stringstream indent_stream;
|
||||
for(int i = 0; i < indent; ++i)
|
||||
for (int i = 0; i < indent; ++i)
|
||||
indent_stream << " ";
|
||||
std::string indent_str = indent_stream.str();
|
||||
|
||||
if(value->IsUndefined())
|
||||
|
||||
if (value->IsUndefined())
|
||||
stream << "(undefined)";
|
||||
else if(value->IsNull())
|
||||
else if (value->IsNull())
|
||||
stream << "(null)";
|
||||
else if(value->IsBool())
|
||||
else if (value->IsBool())
|
||||
stream << "(bool) " << (value->GetBoolValue() ? "true" : "false");
|
||||
else if(value->IsInt())
|
||||
else if (value->IsInt())
|
||||
stream << "(int) " << value->GetIntValue();
|
||||
else if(value->IsDouble())
|
||||
else if (value->IsDouble())
|
||||
stream << "(double) " << value->GetDoubleValue();
|
||||
else if(value->IsString())
|
||||
else if (value->IsString())
|
||||
stream << "(string) " << std::string(value->GetStringValue());
|
||||
else if(value->IsFunction())
|
||||
else if (value->IsFunction())
|
||||
stream << "(function) " << std::string(value->GetFunctionName());
|
||||
else if(value->IsArray()) {
|
||||
else if (value->IsArray()) {
|
||||
stream << "(array) [";
|
||||
int len = value->GetArrayLength();
|
||||
for(int i = 0; i < len; ++i) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
stream << "\n " << indent_str.c_str() << i << " = ";
|
||||
PrintValue(value->GetValue(i), stream, indent+1);
|
||||
}
|
||||
stream << "\n" << indent_str.c_str() << "]";
|
||||
} else if(value->IsObject()) {
|
||||
} else if (value->IsObject()) {
|
||||
stream << "(object) [";
|
||||
std::vector<CefString> keys;
|
||||
if(value->GetKeys(keys)) {
|
||||
for(size_t i = 0; i < keys.size(); ++i) {
|
||||
if (value->GetKeys(keys)) {
|
||||
for (size_t i = 0; i < keys.size(); ++i) {
|
||||
stream << "\n " << indent_str.c_str() << keys[i].c_str() << " = ";
|
||||
PrintValue(value->GetValue(keys[i]), stream, indent+1);
|
||||
}
|
||||
@@ -143,8 +138,7 @@ public:
|
||||
|
||||
void InitBindingTest(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Value> object)
|
||||
{
|
||||
CefRefPtr<CefV8Value> object) {
|
||||
// Create the new V8 object.
|
||||
CefRefPtr<CefV8Value> testObjPtr = CefV8Value::CreateObject(NULL, NULL);
|
||||
// Add the new V8 object to the global window object with the name
|
||||
@@ -164,8 +158,7 @@ void InitBindingTest(CefRefPtr<CefBrowser> browser,
|
||||
V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
|
||||
void RunBindingTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunBindingTest(CefRefPtr<CefBrowser> browser) {
|
||||
std::string html =
|
||||
"<html><body>ClientV8FunctionHandler says:<br><pre>"
|
||||
"<script language=\"JavaScript\">"
|
||||
@@ -178,7 +171,8 @@ void RunBindingTest(CefRefPtr<CefBrowser> browser)
|
||||
" var obj = {};"
|
||||
" (function() {"
|
||||
" obj.GetMessage = function(a) {"
|
||||
" return 'Calling a function with value '+a+' on a user object succeeded.';"
|
||||
" return 'Calling a function with value '+a+' on a user object "
|
||||
"succeeded.';"
|
||||
" };"
|
||||
" })();"
|
||||
" return obj;"
|
||||
|
@@ -2,8 +2,9 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _CEFCLIENT_BINDING_TEST_H
|
||||
#define _CEFCLIENT_BINDING_TEST_H
|
||||
#ifndef CEF_TESTS_CEFCLIENT_BINDING_TEST_H_
|
||||
#define CEF_TESTS_CEFCLIENT_BINDING_TEST_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_base.h"
|
||||
|
||||
@@ -19,4 +20,4 @@ void InitBindingTest(CefRefPtr<CefBrowser> browser,
|
||||
// Run the test.
|
||||
void RunBindingTest(CefRefPtr<CefBrowser> browser);
|
||||
|
||||
#endif // _CEFCLIENT_BINDING_TEST_H
|
||||
#endif // CEF_TESTS_CEFCLIENT_BINDING_TEST_H_
|
||||
|
@@ -2,27 +2,26 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "cefclient.h"
|
||||
#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_runnable.h"
|
||||
#include "include/cef_web_urlrequest.h"
|
||||
#include "cefclient_switches.h"
|
||||
#include "client_handler.h"
|
||||
#include "binding_test.h"
|
||||
#include "string_util.h"
|
||||
#include "util.h"
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include "cefclient/cefclient_switches.h"
|
||||
#include "cefclient/client_handler.h"
|
||||
#include "cefclient/binding_test.h"
|
||||
#include "cefclient/string_util.h"
|
||||
#include "cefclient/util.h"
|
||||
|
||||
namespace {
|
||||
|
||||
void UIT_InvokeScript(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void UIT_InvokeScript(CefRefPtr<CefBrowser> browser) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
CefRefPtr<CefFrame> frame = browser->GetMainFrame();
|
||||
@@ -67,8 +66,7 @@ void UIT_InvokeScript(CefRefPtr<CefBrowser> browser)
|
||||
}
|
||||
|
||||
// Return the int representation of the specified string.
|
||||
int GetIntValue(const CefString& str)
|
||||
{
|
||||
int GetIntValue(const CefString& str) {
|
||||
if (str.empty())
|
||||
return 0;
|
||||
|
||||
@@ -79,13 +77,11 @@ int GetIntValue(const CefString& str)
|
||||
|
||||
// ClientApp implementation.
|
||||
class ClientApp : public CefApp,
|
||||
public CefProxyHandler
|
||||
{
|
||||
public:
|
||||
public CefProxyHandler {
|
||||
public:
|
||||
ClientApp(cef_proxy_type_t proxy_type, const CefString& proxy_config)
|
||||
: proxy_type_(proxy_type),
|
||||
proxy_config_(proxy_config)
|
||||
{
|
||||
proxy_config_(proxy_config) {
|
||||
}
|
||||
|
||||
// CefApp methods
|
||||
@@ -93,41 +89,37 @@ public:
|
||||
|
||||
// CefProxyHandler methods
|
||||
virtual void GetProxyForUrl(const CefString& url,
|
||||
CefProxyInfo& proxy_info) OVERRIDE
|
||||
{
|
||||
CefProxyInfo& proxy_info) OVERRIDE {
|
||||
proxy_info.proxyType = proxy_type_;
|
||||
if (!proxy_config_.empty())
|
||||
CefString(&proxy_info.proxyList) = proxy_config_;
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
cef_proxy_type_t proxy_type_;
|
||||
CefString proxy_config_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(ClientApp);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
CefRefPtr<ClientHandler> g_handler;
|
||||
CefRefPtr<CefCommandLine> g_command_line;
|
||||
|
||||
CefRefPtr<CefBrowser> AppGetBrowser()
|
||||
{
|
||||
if(!g_handler.get())
|
||||
CefRefPtr<CefBrowser> AppGetBrowser() {
|
||||
if (!g_handler.get())
|
||||
return NULL;
|
||||
return g_handler->GetBrowser();
|
||||
}
|
||||
|
||||
CefWindowHandle AppGetMainHwnd()
|
||||
{
|
||||
if(!g_handler.get())
|
||||
CefWindowHandle AppGetMainHwnd() {
|
||||
if (!g_handler.get())
|
||||
return NULL;
|
||||
return g_handler->GetMainHwnd();
|
||||
}
|
||||
|
||||
void AppInitCommandLine(int argc, const char* const* argv)
|
||||
{
|
||||
void AppInitCommandLine(int argc, const char* const* argv) {
|
||||
g_command_line = CefCommandLine::CreateCommandLine();
|
||||
#if defined(OS_WIN)
|
||||
g_command_line->InitFromString(::GetCommandLineW());
|
||||
@@ -137,14 +129,12 @@ void AppInitCommandLine(int argc, const char* const* argv)
|
||||
}
|
||||
|
||||
// Returns the application command line object.
|
||||
CefRefPtr<CefCommandLine> AppGetCommandLine()
|
||||
{
|
||||
CefRefPtr<CefCommandLine> AppGetCommandLine() {
|
||||
return g_command_line;
|
||||
}
|
||||
|
||||
// Returns the application settings based on command line arguments.
|
||||
void AppGetSettings(CefSettings& settings, CefRefPtr<CefApp>& app)
|
||||
{
|
||||
void AppGetSettings(CefSettings& settings, CefRefPtr<CefApp>& app) {
|
||||
ASSERT(g_command_line.get());
|
||||
if (!g_command_line.get())
|
||||
return;
|
||||
@@ -247,8 +237,7 @@ void AppGetSettings(CefSettings& settings, CefRefPtr<CefApp>& app)
|
||||
}
|
||||
|
||||
// Returns the application browser settings based on command line arguments.
|
||||
void AppGetBrowserSettings(CefBrowserSettings& settings)
|
||||
{
|
||||
void AppGetBrowserSettings(CefBrowserSettings& settings) {
|
||||
ASSERT(g_command_line.get());
|
||||
if (!g_command_line.get())
|
||||
return;
|
||||
@@ -344,46 +333,39 @@ void AppGetBrowserSettings(CefBrowserSettings& settings)
|
||||
g_command_line->HasSwitch(cefclient::kFullscreenEnabled);
|
||||
}
|
||||
|
||||
static void ExecuteGetSource(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
static void ExecuteGetSource(CefRefPtr<CefFrame> frame) {
|
||||
// Retrieve the current page source and display.
|
||||
std::string source = frame->GetSource();
|
||||
source = StringReplace(source, "<", "<");
|
||||
source = StringReplace(source, ">", ">");
|
||||
std::stringstream ss;
|
||||
ss << "<html><body>Source:" << "<pre>" << source
|
||||
<< "</pre></body></html>";
|
||||
ss << "<html><body>Source:<pre>" << source << "</pre></body></html>";
|
||||
frame->LoadString(ss.str(), "http://tests/getsource");
|
||||
}
|
||||
|
||||
void RunGetSourceTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunGetSourceTest(CefRefPtr<CefBrowser> browser) {
|
||||
// Execute the GetSource() call on the UI thread.
|
||||
CefPostTask(TID_UI,
|
||||
NewCefRunnableFunction(&ExecuteGetSource, browser->GetMainFrame()));
|
||||
}
|
||||
|
||||
static void ExecuteGetText(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
static void ExecuteGetText(CefRefPtr<CefFrame> frame) {
|
||||
std::string text = frame->GetText();
|
||||
text = StringReplace(text, "<", "<");
|
||||
text = StringReplace(text, ">", ">");
|
||||
std::stringstream ss;
|
||||
ss << "<html><body>Text:" << "<pre>" << text
|
||||
<< "</pre></body></html>";
|
||||
ss << "<html><body>Text:<pre>" << text << "</pre></body></html>";
|
||||
frame->LoadString(ss.str(), "http://tests/gettext");
|
||||
}
|
||||
|
||||
void RunGetTextTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunGetTextTest(CefRefPtr<CefBrowser> browser) {
|
||||
// Execute the GetText() call on the UI thread.
|
||||
CefPostTask(TID_UI,
|
||||
NewCefRunnableFunction(&ExecuteGetText, browser->GetMainFrame()));
|
||||
}
|
||||
|
||||
void RunRequestTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
// Create a new request
|
||||
void RunRequestTest(CefRefPtr<CefBrowser> browser) {
|
||||
// Create a new request
|
||||
CefRefPtr<CefRequest> request(CefRequest::CreateRequest());
|
||||
|
||||
// Set the request URL
|
||||
@@ -409,14 +391,12 @@ void RunRequestTest(CefRefPtr<CefBrowser> browser)
|
||||
browser->GetMainFrame()->LoadRequest(request);
|
||||
}
|
||||
|
||||
void RunJavaScriptExecuteTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunJavaScriptExecuteTest(CefRefPtr<CefBrowser> browser) {
|
||||
browser->GetMainFrame()->ExecuteJavaScript(
|
||||
"alert('JavaScript execute works!');", "about:blank", 0);
|
||||
}
|
||||
|
||||
void RunJavaScriptInvokeTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunJavaScriptInvokeTest(CefRefPtr<CefBrowser> browser) {
|
||||
if (CefCurrentlyOn(TID_UI)) {
|
||||
UIT_InvokeScript(browser);
|
||||
} else {
|
||||
@@ -425,56 +405,46 @@ void RunJavaScriptInvokeTest(CefRefPtr<CefBrowser> browser)
|
||||
}
|
||||
}
|
||||
|
||||
void RunPopupTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunPopupTest(CefRefPtr<CefBrowser> browser) {
|
||||
browser->GetMainFrame()->ExecuteJavaScript(
|
||||
"window.open('http://www.google.com');", "about:blank", 0);
|
||||
}
|
||||
|
||||
void RunLocalStorageTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunLocalStorageTest(CefRefPtr<CefBrowser> browser) {
|
||||
browser->GetMainFrame()->LoadURL("http://tests/localstorage");
|
||||
}
|
||||
|
||||
void RunAccelerated2DCanvasTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunAccelerated2DCanvasTest(CefRefPtr<CefBrowser> browser) {
|
||||
browser->GetMainFrame()->LoadURL(
|
||||
"http://mudcu.be/labs/JS1k/BreathingGalaxies.html");
|
||||
}
|
||||
|
||||
void RunAcceleratedLayersTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunAcceleratedLayersTest(CefRefPtr<CefBrowser> browser) {
|
||||
browser->GetMainFrame()->LoadURL(
|
||||
"http://webkit.org/blog-files/3d-transforms/poster-circle.html");
|
||||
}
|
||||
|
||||
void RunWebGLTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunWebGLTest(CefRefPtr<CefBrowser> browser) {
|
||||
browser->GetMainFrame()->LoadURL(
|
||||
"http://webglsamples.googlecode.com/hg/field/field.html");
|
||||
}
|
||||
|
||||
void RunHTML5VideoTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunHTML5VideoTest(CefRefPtr<CefBrowser> browser) {
|
||||
browser->GetMainFrame()->LoadURL(
|
||||
"http://www.youtube.com/watch?v=siOHh0uzcuY&html5=True");
|
||||
}
|
||||
|
||||
void RunXMLHTTPRequestTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunXMLHTTPRequestTest(CefRefPtr<CefBrowser> browser) {
|
||||
browser->GetMainFrame()->LoadURL("http://tests/xmlhttprequest");
|
||||
}
|
||||
|
||||
void RunWebURLRequestTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
class RequestClient : public CefWebURLRequestClient
|
||||
{
|
||||
public:
|
||||
RequestClient(CefRefPtr<CefBrowser> browser) : browser_(browser) {}
|
||||
void RunWebURLRequestTest(CefRefPtr<CefBrowser> browser) {
|
||||
class RequestClient : public CefWebURLRequestClient {
|
||||
public:
|
||||
explicit RequestClient(CefRefPtr<CefBrowser> browser) : browser_(browser) {}
|
||||
|
||||
virtual void OnStateChange(CefRefPtr<CefWebURLRequest> requester,
|
||||
RequestState state)
|
||||
{
|
||||
virtual void OnStateChange(CefRefPtr<CefWebURLRequest> requester,
|
||||
RequestState state) {
|
||||
REQUIRE_UI_THREAD();
|
||||
if (state == WUR_STATE_DONE) {
|
||||
buffer_ = StringReplace(buffer_, "<", "<");
|
||||
@@ -486,36 +456,31 @@ void RunWebURLRequestTest(CefRefPtr<CefBrowser> browser)
|
||||
"http://tests/weburlrequest");
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnRedirect(CefRefPtr<CefWebURLRequest> requester,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefResponse> response)
|
||||
{
|
||||
|
||||
virtual void OnRedirect(CefRefPtr<CefWebURLRequest> requester,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefResponse> response) {
|
||||
REQUIRE_UI_THREAD();
|
||||
}
|
||||
|
||||
virtual void OnHeadersReceived(CefRefPtr<CefWebURLRequest> requester,
|
||||
CefRefPtr<CefResponse> response)
|
||||
{
|
||||
|
||||
virtual void OnHeadersReceived(CefRefPtr<CefWebURLRequest> requester,
|
||||
CefRefPtr<CefResponse> response) {
|
||||
REQUIRE_UI_THREAD();
|
||||
}
|
||||
|
||||
virtual void OnProgress(CefRefPtr<CefWebURLRequest> requester,
|
||||
uint64 bytesSent, uint64 totalBytesToBeSent)
|
||||
{
|
||||
|
||||
virtual void OnProgress(CefRefPtr<CefWebURLRequest> requester,
|
||||
uint64 bytesSent, uint64 totalBytesToBeSent) {
|
||||
REQUIRE_UI_THREAD();
|
||||
}
|
||||
|
||||
virtual void OnData(CefRefPtr<CefWebURLRequest> requester,
|
||||
const void* data, int dataLength)
|
||||
{
|
||||
|
||||
virtual void OnData(CefRefPtr<CefWebURLRequest> requester,
|
||||
const void* data, int dataLength) {
|
||||
REQUIRE_UI_THREAD();
|
||||
buffer_.append(static_cast<const char*>(data), dataLength);
|
||||
}
|
||||
|
||||
virtual void OnError(CefRefPtr<CefWebURLRequest> requester,
|
||||
ErrorCode errorCode)
|
||||
{
|
||||
|
||||
virtual void OnError(CefRefPtr<CefWebURLRequest> requester,
|
||||
ErrorCode errorCode) {
|
||||
REQUIRE_UI_THREAD();
|
||||
std::stringstream ss;
|
||||
ss << "Load failed with error code " << errorCode;
|
||||
@@ -523,7 +488,7 @@ void RunWebURLRequestTest(CefRefPtr<CefBrowser> browser)
|
||||
"http://tests/weburlrequest");
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
CefRefPtr<CefBrowser> browser_;
|
||||
std::string buffer_;
|
||||
|
||||
@@ -538,27 +503,24 @@ void RunWebURLRequestTest(CefRefPtr<CefBrowser> browser)
|
||||
CefWebURLRequest::CreateWebURLRequest(request, client));
|
||||
}
|
||||
|
||||
void RunDOMAccessTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
class Listener : public CefDOMEventListener
|
||||
{
|
||||
public:
|
||||
void RunDOMAccessTest(CefRefPtr<CefBrowser> browser) {
|
||||
class Listener : public CefDOMEventListener {
|
||||
public:
|
||||
Listener() {}
|
||||
virtual void HandleEvent(CefRefPtr<CefDOMEvent> event)
|
||||
{
|
||||
virtual void HandleEvent(CefRefPtr<CefDOMEvent> event) {
|
||||
CefRefPtr<CefDOMDocument> document = event->GetDocument();
|
||||
ASSERT(document.get());
|
||||
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
CefRefPtr<CefDOMNode> button = event->GetTarget();
|
||||
ASSERT(button.get());
|
||||
std::string buttonValue = button->GetElementAttribute("value");
|
||||
ss << "You clicked the " << buttonValue.c_str() << " button. ";
|
||||
|
||||
|
||||
if (document->HasSelection()) {
|
||||
std::string startName, endName;
|
||||
|
||||
|
||||
// Determine the start name by first trying to locate the "id" attribute
|
||||
// and then defaulting to the tag name.
|
||||
{
|
||||
@@ -590,7 +552,7 @@ void RunDOMAccessTest(CefRefPtr<CefBrowser> browser)
|
||||
} else {
|
||||
ss << "Nothing is selected.";
|
||||
}
|
||||
|
||||
|
||||
// Update the description.
|
||||
CefRefPtr<CefDOMNode> desc = document->GetElementById("description");
|
||||
ASSERT(desc.get());
|
||||
@@ -603,12 +565,10 @@ void RunDOMAccessTest(CefRefPtr<CefBrowser> browser)
|
||||
IMPLEMENT_REFCOUNTING(Listener);
|
||||
};
|
||||
|
||||
class Visitor : public CefDOMVisitor
|
||||
{
|
||||
public:
|
||||
class Visitor : public CefDOMVisitor {
|
||||
public:
|
||||
Visitor() {}
|
||||
virtual void Visit(CefRefPtr<CefDOMDocument> document)
|
||||
{
|
||||
virtual void Visit(CefRefPtr<CefDOMDocument> document) {
|
||||
// Register an click listener for the button.
|
||||
CefRefPtr<CefDOMNode> button = document->GetElementById("button");
|
||||
ASSERT(button.get());
|
||||
@@ -626,12 +586,10 @@ void RunDOMAccessTest(CefRefPtr<CefBrowser> browser)
|
||||
browser->GetMainFrame()->LoadURL("http://tests/domaccess");
|
||||
}
|
||||
|
||||
void RunDragDropTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunDragDropTest(CefRefPtr<CefBrowser> browser) {
|
||||
browser->GetMainFrame()->LoadURL("http://html5demos.com/drag");
|
||||
}
|
||||
|
||||
void RunModalDialogTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunModalDialogTest(CefRefPtr<CefBrowser> browser) {
|
||||
browser->GetMainFrame()->LoadURL("http://tests/modalmain");
|
||||
}
|
||||
|
@@ -2,9 +2,11 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _CEFCLIENT_H
|
||||
#define _CEFCLIENT_H
|
||||
#ifndef CEF_TESTS_CEFCLIENT_CEFCLIENT_H_
|
||||
#define CEF_TESTS_CEFCLIENT_CEFCLIENT_H_
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "include/cef_base.h"
|
||||
|
||||
class CefApp;
|
||||
@@ -55,4 +57,4 @@ void RunTransparentPopupTest(CefRefPtr<CefBrowser> browser);
|
||||
void RunGetImageTest(CefRefPtr<CefBrowser> browser);
|
||||
#endif
|
||||
|
||||
#endif // _CEFCLIENT_H
|
||||
#endif // CEF_TESTS_CEFCLIENT_CEFCLIENT_H_
|
||||
|
@@ -2,24 +2,22 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "cefclient.h"
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
#include "cefclient/cefclient.h"
|
||||
#include "include/cef_app.h"
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "include/cef_runnable.h"
|
||||
#include "binding_test.h"
|
||||
#include "client_handler.h"
|
||||
#include "extension_test.h"
|
||||
#include "scheme_test.h"
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "string_util.h"
|
||||
#include <iostream>
|
||||
#include "cefclient/binding_test.h"
|
||||
#include "cefclient/client_handler.h"
|
||||
#include "cefclient/extension_test.h"
|
||||
#include "cefclient/scheme_test.h"
|
||||
#include "cefclient/string_util.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
char szWorkingDir[512]; // The current working directory
|
||||
char szWorkingDir[512]; // The current working directory
|
||||
|
||||
// The global ClientHandler reference.
|
||||
extern CefRefPtr<ClientHandler> g_handler;
|
||||
@@ -35,31 +33,31 @@ void TerminationSignalHandler(int signatl) {
|
||||
|
||||
// Callback for Debug > Get Source... menu item.
|
||||
gboolean GetSourceActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunGetSourceTest(g_handler->GetBrowser());
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunGetSourceTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
}
|
||||
|
||||
// Callback for Debug > Get Source... menu item.
|
||||
gboolean GetTextActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunGetTextTest(g_handler->GetBrowser());
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunGetTextTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
}
|
||||
|
||||
// Callback for Debug > JS Binding... menu item.
|
||||
gboolean JSBindngActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunBindingTest(g_handler->GetBrowser());
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunBindingTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
}
|
||||
|
||||
// Callback for Debug > JS Extension... menu item.
|
||||
gboolean JSExtensionActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunExtensionTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
@@ -67,7 +65,7 @@ gboolean JSExtensionActivated(GtkWidget* widget) {
|
||||
|
||||
// Callback for Debug > JS Execute... menu item.
|
||||
gboolean JSExecuteActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunJavaScriptExecuteTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
@@ -75,7 +73,7 @@ gboolean JSExecuteActivated(GtkWidget* widget) {
|
||||
|
||||
// Callback for Debug > Request... menu item.
|
||||
gboolean RequestActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunRequestTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
@@ -83,7 +81,7 @@ gboolean RequestActivated(GtkWidget* widget) {
|
||||
|
||||
// Callback for Debug > Local Storage... menu item.
|
||||
gboolean LocalStorageActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunLocalStorageTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
@@ -91,7 +89,7 @@ gboolean LocalStorageActivated(GtkWidget* widget) {
|
||||
|
||||
// Callback for Debug > XMLHttpRequest... menu item.
|
||||
gboolean XMLHttpRequestActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunXMLHTTPRequestTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
@@ -99,7 +97,7 @@ gboolean XMLHttpRequestActivated(GtkWidget* widget) {
|
||||
|
||||
// Callback for Debug > WebURLRequest... menu item.
|
||||
gboolean WebURLRequestActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunWebURLRequestTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
@@ -107,7 +105,7 @@ gboolean WebURLRequestActivated(GtkWidget* widget) {
|
||||
|
||||
// Callback for Debug > DOM Access... menu item.
|
||||
gboolean DOMAccessActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunDOMAccessTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
@@ -115,7 +113,7 @@ gboolean DOMAccessActivated(GtkWidget* widget) {
|
||||
|
||||
// Callback for Debug > Scheme Handler... menu item.
|
||||
gboolean SchemeHandlerActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunSchemeTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
@@ -123,7 +121,7 @@ gboolean SchemeHandlerActivated(GtkWidget* widget) {
|
||||
|
||||
// Callback for Debug > Popup Window... menu item.
|
||||
gboolean PopupWindowActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunPopupTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
@@ -131,7 +129,7 @@ gboolean PopupWindowActivated(GtkWidget* widget) {
|
||||
|
||||
// Callback for Debug > Accelerated 2D Canvas:... menu item.
|
||||
gboolean Accelerated2DCanvasActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunAccelerated2DCanvasTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
@@ -139,7 +137,7 @@ gboolean Accelerated2DCanvasActivated(GtkWidget* widget) {
|
||||
|
||||
// Callback for Debug > Accelerated Layers:... menu item.
|
||||
gboolean AcceleratedLayersActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunAcceleratedLayersTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
@@ -147,7 +145,7 @@ gboolean AcceleratedLayersActivated(GtkWidget* widget) {
|
||||
|
||||
// Callback for Debug > WebGL:... menu item.
|
||||
gboolean WebGLActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunWebGLTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
@@ -155,7 +153,7 @@ gboolean WebGLActivated(GtkWidget* widget) {
|
||||
|
||||
// Callback for Debug > HTML5 Video... menu item.
|
||||
gboolean HTML5VideoActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunHTML5VideoTest(g_handler->GetBrowser());
|
||||
|
||||
return FALSE; // Don't stop this message.
|
||||
@@ -163,7 +161,7 @@ gboolean HTML5VideoActivated(GtkWidget* widget) {
|
||||
|
||||
// Callback for Debug > Zoom In... menu item.
|
||||
gboolean ZoomInActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||
browser->SetZoomLevel(browser->GetZoomLevel() + 0.5);
|
||||
}
|
||||
@@ -173,7 +171,7 @@ gboolean ZoomInActivated(GtkWidget* widget) {
|
||||
|
||||
// Callback for Debug > Zoom Out... menu item.
|
||||
gboolean ZoomOutActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||
browser->SetZoomLevel(browser->GetZoomLevel() - 0.5);
|
||||
}
|
||||
@@ -183,7 +181,7 @@ gboolean ZoomOutActivated(GtkWidget* widget) {
|
||||
|
||||
// Callback for Debug > Zoom Reset... menu item.
|
||||
gboolean ZoomResetActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||
browser->SetZoomLevel(0.0);
|
||||
}
|
||||
@@ -192,7 +190,7 @@ gboolean ZoomResetActivated(GtkWidget* widget) {
|
||||
}
|
||||
|
||||
gboolean DragDropActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||
RunDragDropTest(browser);
|
||||
}
|
||||
@@ -201,7 +199,7 @@ gboolean DragDropActivated(GtkWidget* widget) {
|
||||
}
|
||||
|
||||
gboolean ShowDevtoolsActivated(GtkWidget* widget) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||
browser->ShowDevTools();
|
||||
}
|
||||
@@ -237,7 +235,7 @@ void ReloadButtonClicked(GtkButton* button) {
|
||||
void URLEntryActivate(GtkEntry* entry) {
|
||||
if (!g_handler.get() || !g_handler->GetBrowserHwnd())
|
||||
return;
|
||||
|
||||
|
||||
const gchar* url = gtk_entry_get_text(entry);
|
||||
g_handler->GetBrowser()->GetMainFrame()->LoadURL(std::string(url).c_str());
|
||||
}
|
||||
@@ -263,7 +261,7 @@ GtkWidget* CreateMenu(GtkWidget* menu_bar, const char* text) {
|
||||
GtkWidget* CreateMenuBar() {
|
||||
GtkWidget* menu_bar = gtk_menu_bar_new();
|
||||
GtkWidget* debug_menu = CreateMenu(menu_bar, "Tests");
|
||||
|
||||
|
||||
AddMenuEntry(debug_menu, "Get Source",
|
||||
G_CALLBACK(GetSourceActivated));
|
||||
AddMenuEntry(debug_menu, "Get Text",
|
||||
@@ -311,7 +309,7 @@ GtkWidget* CreateMenuBar() {
|
||||
// WebViewDelegate::TakeFocus in the test webview delegate.
|
||||
static gboolean HandleFocus(GtkWidget* widget,
|
||||
GdkEventFocus* focus) {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
// Give focus to the browser window.
|
||||
g_handler->GetBrowser()->SetFocus(true);
|
||||
}
|
||||
@@ -320,10 +318,10 @@ static gboolean HandleFocus(GtkWidget* widget,
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if(!getcwd(szWorkingDir, sizeof (szWorkingDir)))
|
||||
if (!getcwd(szWorkingDir, sizeof (szWorkingDir)))
|
||||
return -1;
|
||||
|
||||
GtkWidget *window;
|
||||
GtkWidget* window;
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
@@ -387,10 +385,10 @@ int main(int argc, char *argv[]) {
|
||||
GtkToolItem* tool_item = gtk_tool_item_new();
|
||||
gtk_container_add(GTK_CONTAINER(tool_item), m_editWnd);
|
||||
gtk_tool_item_set_expand(tool_item, TRUE);
|
||||
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool_item, -1); //append
|
||||
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool_item, -1); // append
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
|
||||
|
||||
|
||||
g_signal_connect(G_OBJECT(window), "destroy",
|
||||
G_CALLBACK(gtk_widget_destroyed), &window);
|
||||
g_signal_connect(G_OBJECT(window), "destroy",
|
||||
|
@@ -3,20 +3,20 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cefclient.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#include <sstream>
|
||||
#include "cefclient/cefclient.h"
|
||||
#include "include/cef_app.h"
|
||||
#import "include/cef_application_mac.h"
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "include/cef_runnable.h"
|
||||
#include "binding_test.h"
|
||||
#include "client_handler.h"
|
||||
#include "extension_test.h"
|
||||
#include "resource_util.h"
|
||||
#include "scheme_test.h"
|
||||
#include "string_util.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#include <sstream>
|
||||
#include "cefclient/binding_test.h"
|
||||
#include "cefclient/client_handler.h"
|
||||
#include "cefclient/extension_test.h"
|
||||
#include "cefclient/resource_util.h"
|
||||
#include "cefclient/scheme_test.h"
|
||||
#include "cefclient/string_util.h"
|
||||
|
||||
// The global ClientHandler reference.
|
||||
extern CefRefPtr<ClientHandler> g_handler;
|
||||
@@ -144,7 +144,7 @@ static NSAutoreleasePool* g_autopool = nil;
|
||||
}
|
||||
|
||||
- (void)windowDidBecomeKey:(NSNotification*)notification {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
// Give focus to the browser window.
|
||||
g_handler->GetBrowser()->SetFocus(true);
|
||||
}
|
||||
@@ -393,130 +393,130 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||
}
|
||||
|
||||
- (IBAction)testGetSource:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunGetSourceTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testGetText:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunGetTextTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testJSBinding:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunBindingTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testJSExtension:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunExtensionTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testJSExtensionPerf:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunExtensionPerfTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testJSExecute:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunJavaScriptExecuteTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testJSInvoke:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunJavaScriptInvokeTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testRequest:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunRequestTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testLocalStorage:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunLocalStorageTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testXMLHttpRequest:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunXMLHTTPRequestTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testWebURLRequest:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunWebURLRequestTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testDOMAccess:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunDOMAccessTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testSchemeHandler:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunSchemeTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testPopupWindow:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunPopupTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testAccelerated2DCanvas:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunAccelerated2DCanvasTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testAcceleratedLayers:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunAcceleratedLayersTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testWebGL:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunWebGLTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testHTML5Video:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunHTML5VideoTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testDragDrop:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunDragDropTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testZoomIn:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||
browser->SetZoomLevel(browser->GetZoomLevel() + 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)testZoomOut:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||
browser->SetZoomLevel(browser->GetZoomLevel() - 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)testZoomReset:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||
browser->SetZoomLevel(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)testDevToolsShow:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||
browser->ShowDevTools();
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)testDevToolsClose:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||
browser->CloseDevTools();
|
||||
}
|
||||
@@ -538,8 +538,7 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||
@end
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
// Retrieve the current working directory.
|
||||
getcwd(szWorkingDir, sizeof(szWorkingDir));
|
||||
|
||||
@@ -580,7 +579,6 @@ int main(int argc, char* argv[])
|
||||
|
||||
// Global functions
|
||||
|
||||
std::string AppGetWorkingDirectory()
|
||||
{
|
||||
std::string AppGetWorkingDirectory() {
|
||||
return szWorkingDir;
|
||||
}
|
||||
|
@@ -2,7 +2,9 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "cefclient_switches.h"
|
||||
// This file is shared by cefclient and cef_unittests so don't include using
|
||||
// a qualified path.
|
||||
#include "cefclient_switches.h" // NOLINT(build/include)
|
||||
|
||||
namespace cefclient {
|
||||
|
||||
|
@@ -4,8 +4,9 @@
|
||||
|
||||
// Defines all of the command line switches used by cefclient.
|
||||
|
||||
#ifndef _CEFCLIENT_SWITCHES_H
|
||||
#define _CEFCLIENT_SWITCHES_H
|
||||
#ifndef CEF_TESTS_CEFCLIENT_CEFCLIENT_SWITCHES_H_
|
||||
#define CEF_TESTS_CEFCLIENT_CEFCLIENT_SWITCHES_H_
|
||||
#pragma once
|
||||
|
||||
namespace cefclient {
|
||||
|
||||
@@ -85,4 +86,4 @@ extern const char kProxyConfig[];
|
||||
|
||||
} // namespace cefclient
|
||||
|
||||
#endif // _CEFCLIENT_SWITCHES_H
|
||||
#endif // CEF_TESTS_CEFCLIENT_CEFCLIENT_SWITCHES_H_
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -2,16 +2,16 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "client_handler.h"
|
||||
#include "cefclient/client_handler.h"
|
||||
#include <stdio.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "binding_test.h"
|
||||
#include "cefclient.h"
|
||||
#include "download_handler.h"
|
||||
#include "string_util.h"
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include "cefclient/binding_test.h"
|
||||
#include "cefclient/cefclient.h"
|
||||
#include "cefclient/download_handler.h"
|
||||
#include "cefclient/string_util.h"
|
||||
|
||||
|
||||
ClientHandler::ClientHandler()
|
||||
@@ -22,30 +22,25 @@ ClientHandler::ClientHandler()
|
||||
m_ForwardHwnd(NULL),
|
||||
m_StopHwnd(NULL),
|
||||
m_ReloadHwnd(NULL),
|
||||
m_bFormElementHasFocus(false)
|
||||
{
|
||||
m_bFormElementHasFocus(false) {
|
||||
}
|
||||
|
||||
ClientHandler::~ClientHandler()
|
||||
{
|
||||
ClientHandler::~ClientHandler() {
|
||||
}
|
||||
|
||||
|
||||
void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
AutoLock lock_scope(this);
|
||||
if(!m_Browser.get())
|
||||
{
|
||||
if (!m_Browser.get()) {
|
||||
// We need to keep the main child window, but not popup windows
|
||||
m_Browser = browser;
|
||||
m_BrowserHwnd = browser->GetWindowHandle();
|
||||
}
|
||||
}
|
||||
|
||||
bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if (m_BrowserHwnd == browser->GetWindowHandle()) {
|
||||
@@ -53,7 +48,7 @@ bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser)
|
||||
// the parent window instead of the browser window.
|
||||
CloseMainWindow();
|
||||
|
||||
// Return true here so that we can skip closing the browser window
|
||||
// Return true here so that we can skip closing the browser window
|
||||
// in this pass. (It will be destroyed due to the call to close
|
||||
// the parent above.)
|
||||
return true;
|
||||
@@ -64,22 +59,20 @@ bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser)
|
||||
return false;
|
||||
}
|
||||
|
||||
void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(m_BrowserHwnd == browser->GetWindowHandle()) {
|
||||
if (m_BrowserHwnd == browser->GetWindowHandle()) {
|
||||
// Free the browser pointer so that the browser can be destroyed
|
||||
m_Browser = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void ClientHandler::OnLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
CefRefPtr<CefFrame> frame) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
|
||||
if (m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
|
||||
// We've just started loading a page
|
||||
SetLoading(true);
|
||||
}
|
||||
@@ -87,16 +80,15 @@ void ClientHandler::OnLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
|
||||
void ClientHandler::OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int httpStatusCode)
|
||||
{
|
||||
int httpStatusCode) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
|
||||
if (m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
|
||||
// We've just finished loading a page
|
||||
SetLoading(false);
|
||||
|
||||
CefRefPtr<CefDOMVisitor> visitor = GetDOMVisitor(frame->GetURL());
|
||||
if(visitor.get())
|
||||
if (visitor.get())
|
||||
frame->VisitDOM(visitor);
|
||||
}
|
||||
}
|
||||
@@ -105,11 +97,10 @@ bool ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
ErrorCode errorCode,
|
||||
const CefString& failedUrl,
|
||||
CefString& errorText)
|
||||
{
|
||||
CefString& errorText) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(errorCode == ERR_CACHE_MISS) {
|
||||
if (errorCode == ERR_CACHE_MISS) {
|
||||
// Usually caused by navigating to a page with POST data via back or
|
||||
// forward buttons.
|
||||
errorText = "<html><head><title>Expired Form Data</title></head>"
|
||||
@@ -136,8 +127,7 @@ bool ClientHandler::GetDownloadHandler(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& mimeType,
|
||||
const CefString& fileName,
|
||||
int64 contentLength,
|
||||
CefRefPtr<CefDownloadHandler>& handler)
|
||||
{
|
||||
CefRefPtr<CefDownloadHandler>& handler) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Create the handler for the file download.
|
||||
@@ -152,8 +142,7 @@ bool ClientHandler::GetDownloadHandler(CefRefPtr<CefBrowser> browser,
|
||||
|
||||
void ClientHandler::OnNavStateChange(CefRefPtr<CefBrowser> browser,
|
||||
bool canGoBack,
|
||||
bool canGoForward)
|
||||
{
|
||||
bool canGoForward) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
SetNavState(canGoBack, canGoForward);
|
||||
@@ -162,8 +151,7 @@ void ClientHandler::OnNavStateChange(CefRefPtr<CefBrowser> browser,
|
||||
bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& message,
|
||||
const CefString& source,
|
||||
int line)
|
||||
{
|
||||
int line) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
bool first_message;
|
||||
@@ -171,9 +159,9 @@ bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||
|
||||
{
|
||||
AutoLock lock_scope(this);
|
||||
|
||||
|
||||
first_message = m_LogFile.empty();
|
||||
if(first_message) {
|
||||
if (first_message) {
|
||||
std::stringstream ss;
|
||||
ss << AppGetWorkingDirectory();
|
||||
#if defined(OS_WIN)
|
||||
@@ -185,10 +173,10 @@ bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||
m_LogFile = ss.str();
|
||||
}
|
||||
logFile = m_LogFile;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FILE* file = fopen(logFile.c_str(), "a");
|
||||
if(file) {
|
||||
if (file) {
|
||||
std::stringstream ss;
|
||||
ss << "Message: " << std::string(message) << "\r\nSource: " <<
|
||||
std::string(source) << "\r\nLine: " << line <<
|
||||
@@ -196,7 +184,7 @@ bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||
fputs(ss.str().c_str(), file);
|
||||
fclose(file);
|
||||
|
||||
if(first_message)
|
||||
if (first_message)
|
||||
SendNotification(NOTIFY_CONSOLE_MESSAGE);
|
||||
}
|
||||
|
||||
@@ -205,8 +193,7 @@ bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||
|
||||
void ClientHandler::OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefDOMNode> node)
|
||||
{
|
||||
CefRefPtr<CefDOMNode> node) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Set to true if a form element has focus.
|
||||
@@ -218,8 +205,7 @@ bool ClientHandler::OnKeyEvent(CefRefPtr<CefBrowser> browser,
|
||||
int code,
|
||||
int modifiers,
|
||||
bool isSystemKey,
|
||||
bool isAfterJavaScript)
|
||||
{
|
||||
bool isAfterJavaScript) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if (isAfterJavaScript && !m_bFormElementHasFocus && code == 0x20) {
|
||||
@@ -247,15 +233,14 @@ bool ClientHandler::GetPrintHeaderFooter(CefRefPtr<CefBrowser> browser,
|
||||
CefString& topRight,
|
||||
CefString& bottomLeft,
|
||||
CefString& bottomCenter,
|
||||
CefString& bottomRight)
|
||||
{
|
||||
CefString& bottomRight) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Place the page title at top left
|
||||
topLeft = title;
|
||||
// Place the page URL at top right
|
||||
topRight = url;
|
||||
|
||||
|
||||
// Place "Page X of Y" at bottom center
|
||||
std::stringstream strstream;
|
||||
strstream << "Page " << currentPage << " of " << maxPages;
|
||||
@@ -266,8 +251,7 @@ bool ClientHandler::GetPrintHeaderFooter(CefRefPtr<CefBrowser> browser,
|
||||
|
||||
void ClientHandler::OnContextCreated(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context)
|
||||
{
|
||||
CefRefPtr<CefV8Context> context) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Add the V8 bindings.
|
||||
@@ -276,8 +260,7 @@ void ClientHandler::OnContextCreated(CefRefPtr<CefBrowser> browser,
|
||||
|
||||
bool ClientHandler::OnDragStart(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefDragData> dragData,
|
||||
DragOperationsMask mask)
|
||||
{
|
||||
DragOperationsMask mask) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Forbid dragging of image files.
|
||||
@@ -292,8 +275,7 @@ bool ClientHandler::OnDragStart(CefRefPtr<CefBrowser> browser,
|
||||
|
||||
bool ClientHandler::OnDragEnter(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefDragData> dragData,
|
||||
DragOperationsMask mask)
|
||||
{
|
||||
DragOperationsMask mask) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Forbid dragging of link URLs.
|
||||
@@ -303,33 +285,29 @@ bool ClientHandler::OnDragEnter(CefRefPtr<CefBrowser> browser,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ClientHandler::OnBeforeScriptExtensionLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& extensionName)
|
||||
{
|
||||
bool ClientHandler::OnBeforeScriptExtensionLoad(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& extensionName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ClientHandler::NotifyDownloadComplete(const CefString& fileName)
|
||||
{
|
||||
void ClientHandler::NotifyDownloadComplete(const CefString& fileName) {
|
||||
SetLastDownloadFile(fileName);
|
||||
SendNotification(NOTIFY_DOWNLOAD_COMPLETE);
|
||||
}
|
||||
|
||||
void ClientHandler::NotifyDownloadError(const CefString& fileName)
|
||||
{
|
||||
void ClientHandler::NotifyDownloadError(const CefString& fileName) {
|
||||
SetLastDownloadFile(fileName);
|
||||
SendNotification(NOTIFY_DOWNLOAD_ERROR);
|
||||
}
|
||||
|
||||
void ClientHandler::SetMainHwnd(CefWindowHandle hwnd)
|
||||
{
|
||||
void ClientHandler::SetMainHwnd(CefWindowHandle hwnd) {
|
||||
AutoLock lock_scope(this);
|
||||
m_MainHwnd = hwnd;
|
||||
}
|
||||
|
||||
void ClientHandler::SetEditHwnd(CefWindowHandle hwnd)
|
||||
{
|
||||
void ClientHandler::SetEditHwnd(CefWindowHandle hwnd) {
|
||||
AutoLock lock_scope(this);
|
||||
m_EditHwnd = hwnd;
|
||||
}
|
||||
@@ -337,8 +315,7 @@ void ClientHandler::SetEditHwnd(CefWindowHandle hwnd)
|
||||
void ClientHandler::SetButtonHwnds(CefWindowHandle backHwnd,
|
||||
CefWindowHandle forwardHwnd,
|
||||
CefWindowHandle reloadHwnd,
|
||||
CefWindowHandle stopHwnd)
|
||||
{
|
||||
CefWindowHandle stopHwnd) {
|
||||
AutoLock lock_scope(this);
|
||||
m_BackHwnd = backHwnd;
|
||||
m_ForwardHwnd = forwardHwnd;
|
||||
@@ -346,27 +323,23 @@ void ClientHandler::SetButtonHwnds(CefWindowHandle backHwnd,
|
||||
m_StopHwnd = stopHwnd;
|
||||
}
|
||||
|
||||
std::string ClientHandler::GetLogFile()
|
||||
{
|
||||
std::string ClientHandler::GetLogFile() {
|
||||
AutoLock lock_scope(this);
|
||||
return m_LogFile;
|
||||
}
|
||||
|
||||
void ClientHandler::SetLastDownloadFile(const std::string& fileName)
|
||||
{
|
||||
void ClientHandler::SetLastDownloadFile(const std::string& fileName) {
|
||||
AutoLock lock_scope(this);
|
||||
m_LastDownloadFile = fileName;
|
||||
}
|
||||
|
||||
std::string ClientHandler::GetLastDownloadFile()
|
||||
{
|
||||
std::string ClientHandler::GetLastDownloadFile() {
|
||||
AutoLock lock_scope(this);
|
||||
return m_LastDownloadFile;
|
||||
}
|
||||
|
||||
void ClientHandler::AddDOMVisitor(const std::string& path,
|
||||
CefRefPtr<CefDOMVisitor> visitor)
|
||||
{
|
||||
CefRefPtr<CefDOMVisitor> visitor) {
|
||||
AutoLock lock_scope(this);
|
||||
DOMVisitorMap::iterator it = m_DOMVisitors.find(path);
|
||||
if (it == m_DOMVisitors.end())
|
||||
@@ -375,8 +348,7 @@ void ClientHandler::AddDOMVisitor(const std::string& path,
|
||||
it->second = visitor;
|
||||
}
|
||||
|
||||
CefRefPtr<CefDOMVisitor> ClientHandler::GetDOMVisitor(const std::string& path)
|
||||
{
|
||||
CefRefPtr<CefDOMVisitor> ClientHandler::GetDOMVisitor(const std::string& path) {
|
||||
AutoLock lock_scope(this);
|
||||
DOMVisitorMap::iterator it = m_DOMVisitors.find(path);
|
||||
if (it != m_DOMVisitors.end())
|
||||
|
@@ -2,17 +2,20 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _CLIENT_HANDLER_H
|
||||
#define _CLIENT_HANDLER_H
|
||||
#ifndef CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_
|
||||
#define CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "include/cef_client.h"
|
||||
#include "download_handler.h"
|
||||
#include "util.h"
|
||||
#include "cefclient/download_handler.h"
|
||||
#include "cefclient/util.h"
|
||||
|
||||
|
||||
// Define this value to redirect all popup URLs to the main application browser
|
||||
// window.
|
||||
//#define TEST_REDIRECT_POPUP_URLS
|
||||
// #define TEST_REDIRECT_POPUP_URLS
|
||||
|
||||
|
||||
// ClientHandler implementation.
|
||||
@@ -27,33 +30,42 @@ class ClientHandler : public CefClient,
|
||||
public CefV8ContextHandler,
|
||||
public CefDragHandler,
|
||||
public CefPermissionHandler,
|
||||
public DownloadListener
|
||||
{
|
||||
public:
|
||||
public DownloadListener {
|
||||
public:
|
||||
ClientHandler();
|
||||
virtual ~ClientHandler();
|
||||
|
||||
// CefClient methods
|
||||
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefFocusHandler> GetFocusHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefPrintHandler> GetPrintHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefV8ContextHandler> GetV8ContextHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefDragHandler> GetDragHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefPermissionHandler> GetPermissionHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefFocusHandler> GetFocusHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefPrintHandler> GetPrintHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefV8ContextHandler> GetV8ContextHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefDragHandler> GetDragHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefPermissionHandler> GetPermissionHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
|
||||
// CefLifeSpanHandler methods
|
||||
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
|
||||
@@ -77,7 +89,7 @@ public:
|
||||
ErrorCode errorCode,
|
||||
const CefString& failedUrl,
|
||||
CefString& errorText) OVERRIDE;
|
||||
|
||||
|
||||
// CefRequestHandler methods
|
||||
virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefRequest> request,
|
||||
@@ -105,7 +117,7 @@ public:
|
||||
const CefString& message,
|
||||
const CefString& source,
|
||||
int line) OVERRIDE;
|
||||
|
||||
|
||||
// CefFocusHandler methods.
|
||||
virtual void OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
@@ -133,7 +145,7 @@ public:
|
||||
CefString& bottomLeft,
|
||||
CefString& bottomCenter,
|
||||
CefString& bottomRight) OVERRIDE;
|
||||
|
||||
|
||||
// CefV8ContextHandler methods
|
||||
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
@@ -163,7 +175,7 @@ public:
|
||||
CefWindowHandle forwardHwnd,
|
||||
CefWindowHandle reloadHwnd,
|
||||
CefWindowHandle stopHwnd);
|
||||
|
||||
|
||||
CefRefPtr<CefBrowser> GetBrowser() { return m_Browser; }
|
||||
CefWindowHandle GetBrowserHwnd() { return m_BrowserHwnd; }
|
||||
|
||||
@@ -178,8 +190,7 @@ public:
|
||||
|
||||
// Send a notification to the application. Notifications should not block the
|
||||
// caller.
|
||||
enum NotificationType
|
||||
{
|
||||
enum NotificationType {
|
||||
NOTIFY_CONSOLE_MESSAGE,
|
||||
NOTIFY_DOWNLOAD_COMPLETE,
|
||||
NOTIFY_DOWNLOAD_ERROR,
|
||||
@@ -187,7 +198,7 @@ public:
|
||||
void SendNotification(NotificationType type);
|
||||
void CloseMainWindow();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void SetLoading(bool isLoading);
|
||||
void SetNavState(bool canGoBack, bool canGoForward);
|
||||
|
||||
@@ -228,4 +239,4 @@ protected:
|
||||
IMPLEMENT_LOCKING(ClientHandler);
|
||||
};
|
||||
|
||||
#endif // _CLIENT_HANDLER_H
|
||||
#endif // CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_
|
||||
|
@@ -2,12 +2,13 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "client_handler.h"
|
||||
#include <gtk/gtk.h>
|
||||
#include <string>
|
||||
#include "cefclient/client_handler.h"
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "resource_util.h"
|
||||
#include "string_util.h"
|
||||
#include <gtk/gtk.h>
|
||||
#include "cefclient/resource_util.h"
|
||||
#include "cefclient/string_util.h"
|
||||
|
||||
// ClientHandler::ClientLifeSpanHandler implementation
|
||||
bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
|
||||
@@ -15,8 +16,7 @@ bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
|
||||
CefWindowInfo& windowInfo,
|
||||
const CefString& url,
|
||||
CefRefPtr<CefClient>& client,
|
||||
CefBrowserSettings& settings)
|
||||
{
|
||||
CefBrowserSettings& settings) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
return false;
|
||||
@@ -27,18 +27,18 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefString& redirectUrl,
|
||||
CefRefPtr<CefStreamReader>& resourceStream,
|
||||
CefRefPtr<CefResponse> response,
|
||||
int loadFlags)
|
||||
{
|
||||
int loadFlags) {
|
||||
REQUIRE_IO_THREAD();
|
||||
|
||||
std::string url = request->GetURL();
|
||||
|
||||
if(url == "http://tests/request") {
|
||||
if (url == "http://tests/request") {
|
||||
// Show the request contents
|
||||
std::string dump;
|
||||
DumpRequestContents(request, dump);
|
||||
resourceStream = CefStreamReader::CreateForData(
|
||||
(void*)dump.c_str(), dump.size());
|
||||
static_cast<void*>(const_cast<char*>(dump.c_str())),
|
||||
dump.size());
|
||||
response->SetMimeType("text/plain");
|
||||
response->SetStatus(200);
|
||||
} else if (strstr(url.c_str(), "/ps_logo2.png") != NULL) {
|
||||
@@ -46,17 +46,17 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
resourceStream = GetBinaryResourceReader("logo.png");
|
||||
response->SetMimeType("image/png");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/localstorage") {
|
||||
} else if (url == "http://tests/localstorage") {
|
||||
// Show the localstorage contents
|
||||
resourceStream = GetBinaryResourceReader("localstorage.html");
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/xmlhttprequest") {
|
||||
} else if (url == "http://tests/xmlhttprequest") {
|
||||
// Show the xmlhttprequest HTML contents
|
||||
resourceStream = GetBinaryResourceReader("xmlhttprequest.html");
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/domaccess") {
|
||||
} else if (url == "http://tests/domaccess") {
|
||||
// Show the domaccess HTML contents
|
||||
resourceStream = GetBinaryResourceReader("domaccess.html");
|
||||
response->SetMimeType("text/html");
|
||||
@@ -64,15 +64,14 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& url)
|
||||
{
|
||||
const CefString& url) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
|
||||
if (m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
|
||||
// Set the edit window text
|
||||
std::string urlStr(url);
|
||||
gtk_entry_set_text(GTK_ENTRY(m_EditHwnd), urlStr.c_str());
|
||||
@@ -80,8 +79,7 @@ void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
}
|
||||
|
||||
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title)
|
||||
{
|
||||
const CefString& title) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
GtkWidget* window =
|
||||
@@ -91,33 +89,29 @@ void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
gtk_window_set_title(GTK_WINDOW(window), titleStr.c_str());
|
||||
}
|
||||
|
||||
void ClientHandler::SendNotification(NotificationType type)
|
||||
{
|
||||
void ClientHandler::SendNotification(NotificationType type) {
|
||||
// TODO(port): Implement this method.
|
||||
}
|
||||
|
||||
void ClientHandler::SetLoading(bool isLoading)
|
||||
{
|
||||
if(isLoading)
|
||||
void ClientHandler::SetLoading(bool isLoading) {
|
||||
if (isLoading)
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(m_StopHwnd), true);
|
||||
else
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(m_StopHwnd), false);
|
||||
}
|
||||
|
||||
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward)
|
||||
{
|
||||
if(canGoBack)
|
||||
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) {
|
||||
if (canGoBack)
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(m_BackHwnd), true);
|
||||
else
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(m_BackHwnd), false);
|
||||
|
||||
if(canGoForward)
|
||||
if (canGoForward)
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(m_ForwardHwnd), true);
|
||||
else
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(m_ForwardHwnd), false);
|
||||
}
|
||||
|
||||
void ClientHandler::CloseMainWindow()
|
||||
{
|
||||
void ClientHandler::CloseMainWindow() {
|
||||
// TODO(port): Close main window.
|
||||
}
|
||||
|
@@ -2,16 +2,17 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "client_handler.h"
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "cefclient.h"
|
||||
#include "resource_util.h"
|
||||
#include "string_util.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "cefclient/client_handler.h"
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "cefclient/cefclient.h"
|
||||
#include "cefclient/resource_util.h"
|
||||
#include "cefclient/string_util.h"
|
||||
|
||||
#ifdef TEST_REDIRECT_POPUP_URLS
|
||||
#include "client_popup_handler.h"
|
||||
#include "cefclient/client_popup_handler.h"
|
||||
#endif
|
||||
|
||||
// ClientHandler::ClientLifeSpanHandler implementation
|
||||
@@ -21,13 +22,12 @@ bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
|
||||
CefWindowInfo& windowInfo,
|
||||
const CefString& url,
|
||||
CefRefPtr<CefClient>& client,
|
||||
CefBrowserSettings& settings)
|
||||
{
|
||||
CefBrowserSettings& settings) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
#ifdef TEST_REDIRECT_POPUP_URLS
|
||||
std::string urlStr = url;
|
||||
if(urlStr.find("chrome-devtools:") == std::string::npos) {
|
||||
if (urlStr.find("chrome-devtools:") == std::string::npos) {
|
||||
// Show all popup windows excluding DevTools in the current window.
|
||||
windowInfo.m_bHidden = true;
|
||||
client = new ClientPopupHandler(m_Browser);
|
||||
@@ -42,17 +42,17 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefString& redirectUrl,
|
||||
CefRefPtr<CefStreamReader>& resourceStream,
|
||||
CefRefPtr<CefResponse> response,
|
||||
int loadFlags)
|
||||
{
|
||||
int loadFlags) {
|
||||
REQUIRE_IO_THREAD();
|
||||
|
||||
std::string url = request->GetURL();
|
||||
if(url == "http://tests/request") {
|
||||
if (url == "http://tests/request") {
|
||||
// Show the request contents
|
||||
std::string dump;
|
||||
DumpRequestContents(request, dump);
|
||||
resourceStream = CefStreamReader::CreateForData(
|
||||
(void*)dump.c_str(), dump.size());
|
||||
static_cast<void*>(const_cast<char*>(dump.c_str())),
|
||||
dump.size());
|
||||
response->SetMimeType("text/plain");
|
||||
response->SetStatus(200);
|
||||
} else if (strstr(url.c_str(), "/ps_logo2.png") != NULL) {
|
||||
@@ -60,17 +60,17 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
resourceStream = GetBinaryResourceReader("logo.png");
|
||||
response->SetMimeType("image/png");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/localstorage") {
|
||||
} else if (url == "http://tests/localstorage") {
|
||||
// Show the localstorage contents
|
||||
resourceStream = GetBinaryResourceReader("localstorage.html");
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/xmlhttprequest") {
|
||||
} else if (url == "http://tests/xmlhttprequest") {
|
||||
// Show the xmlhttprequest HTML contents
|
||||
resourceStream = GetBinaryResourceReader("xmlhttprequest.html");
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/domaccess") {
|
||||
} else if (url == "http://tests/domaccess") {
|
||||
// Show the domaccess HTML contents
|
||||
resourceStream = GetBinaryResourceReader("domaccess.html");
|
||||
response->SetMimeType("text/html");
|
||||
@@ -82,12 +82,10 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
|
||||
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& url)
|
||||
{
|
||||
const CefString& url) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain())
|
||||
{
|
||||
if (m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
|
||||
// Set the edit window text
|
||||
NSTextField* textField = (NSTextField*)m_EditHwnd;
|
||||
std::string urlStr(url);
|
||||
@@ -97,8 +95,7 @@ void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
}
|
||||
|
||||
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title)
|
||||
{
|
||||
const CefString& title) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Set the frame window title bar
|
||||
@@ -109,8 +106,7 @@ void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
[window setTitle:str];
|
||||
}
|
||||
|
||||
void ClientHandler::SendNotification(NotificationType type)
|
||||
{
|
||||
void ClientHandler::SendNotification(NotificationType type) {
|
||||
SEL sel = nil;
|
||||
switch(type) {
|
||||
case NOTIFY_CONSOLE_MESSAGE:
|
||||
@@ -124,7 +120,7 @@ void ClientHandler::SendNotification(NotificationType type)
|
||||
break;
|
||||
}
|
||||
|
||||
if(sel == nil)
|
||||
if (sel == nil)
|
||||
return;
|
||||
|
||||
NSWindow* window = [AppGetMainHwnd() window];
|
||||
@@ -132,17 +128,14 @@ void ClientHandler::SendNotification(NotificationType type)
|
||||
[delegate performSelectorOnMainThread:sel withObject:nil waitUntilDone:NO];
|
||||
}
|
||||
|
||||
void ClientHandler::SetLoading(bool isLoading)
|
||||
{
|
||||
void ClientHandler::SetLoading(bool isLoading) {
|
||||
// TODO(port): Change button status.
|
||||
}
|
||||
|
||||
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward)
|
||||
{
|
||||
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) {
|
||||
// TODO(port): Change button status.
|
||||
}
|
||||
|
||||
void ClientHandler::CloseMainWindow()
|
||||
{
|
||||
void ClientHandler::CloseMainWindow() {
|
||||
// TODO(port): Close window
|
||||
}
|
||||
|
@@ -2,15 +2,16 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "client_handler.h"
|
||||
#include "cefclient/client_handler.h"
|
||||
#include <string>
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "resource.h"
|
||||
#include "resource_util.h"
|
||||
#include "string_util.h"
|
||||
#include "cefclient/resource.h"
|
||||
#include "cefclient/resource_util.h"
|
||||
#include "cefclient/string_util.h"
|
||||
|
||||
#ifdef TEST_REDIRECT_POPUP_URLS
|
||||
#include "client_popup_handler.h"
|
||||
#include "cefclient/client_popup_handler.h"
|
||||
#endif
|
||||
|
||||
bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
|
||||
@@ -18,18 +19,17 @@ bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
|
||||
CefWindowInfo& windowInfo,
|
||||
const CefString& url,
|
||||
CefRefPtr<CefClient>& client,
|
||||
CefBrowserSettings& settings)
|
||||
{
|
||||
CefBrowserSettings& settings) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
#ifdef TEST_REDIRECT_POPUP_URLS
|
||||
std::string urlStr = url;
|
||||
if(urlStr.find("chrome-devtools:") == std::string::npos) {
|
||||
if (urlStr.find("chrome-devtools:") == std::string::npos) {
|
||||
// Show all popup windows excluding DevTools in the current window.
|
||||
windowInfo.m_dwStyle &= ~WS_VISIBLE;
|
||||
client = new ClientPopupHandler(m_Browser);
|
||||
}
|
||||
#endif // TEST_REDIRECT_POPUP_URLS
|
||||
#endif // TEST_REDIRECT_POPUP_URLS
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -39,67 +39,67 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefString& redirectUrl,
|
||||
CefRefPtr<CefStreamReader>& resourceStream,
|
||||
CefRefPtr<CefResponse> response,
|
||||
int loadFlags)
|
||||
{
|
||||
int loadFlags) {
|
||||
REQUIRE_IO_THREAD();
|
||||
|
||||
std::string url = request->GetURL();
|
||||
if(url == "http://tests/request") {
|
||||
if (url == "http://tests/request") {
|
||||
// Show the request contents
|
||||
std::string dump;
|
||||
DumpRequestContents(request, dump);
|
||||
resourceStream =
|
||||
CefStreamReader::CreateForData((void*)dump.c_str(), dump.size());
|
||||
resourceStream = CefStreamReader::CreateForData(
|
||||
static_cast<void*>(const_cast<char*>(dump.c_str())),
|
||||
dump.size());
|
||||
response->SetMimeType("text/plain");
|
||||
response->SetStatus(200);
|
||||
} else if(strstr(url.c_str(), "/ps_logo2.png") != NULL) {
|
||||
} else if (strstr(url.c_str(), "/ps_logo2.png") != NULL) {
|
||||
// Any time we find "ps_logo2.png" in the URL substitute in our own image
|
||||
resourceStream = GetBinaryResourceReader(IDS_LOGO);
|
||||
response->SetMimeType("image/png");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/uiapp") {
|
||||
} else if (url == "http://tests/uiapp") {
|
||||
// Show the uiapp contents
|
||||
resourceStream = GetBinaryResourceReader(IDS_UIPLUGIN);
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/osrapp") {
|
||||
} else if (url == "http://tests/osrapp") {
|
||||
// Show the osrapp contents
|
||||
resourceStream = GetBinaryResourceReader(IDS_OSRPLUGIN);
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/localstorage") {
|
||||
} else if (url == "http://tests/localstorage") {
|
||||
// Show the localstorage contents
|
||||
resourceStream = GetBinaryResourceReader(IDS_LOCALSTORAGE);
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/xmlhttprequest") {
|
||||
} else if (url == "http://tests/xmlhttprequest") {
|
||||
// Show the xmlhttprequest HTML contents
|
||||
resourceStream = GetBinaryResourceReader(IDS_XMLHTTPREQUEST);
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/domaccess") {
|
||||
} else if (url == "http://tests/domaccess") {
|
||||
// Show the domaccess HTML contents
|
||||
resourceStream = GetBinaryResourceReader(IDS_DOMACCESS);
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
} else if(strstr(url.c_str(), "/logoball.png") != NULL) {
|
||||
} else if (strstr(url.c_str(), "/logoball.png") != NULL) {
|
||||
// Load the "logoball.png" image resource.
|
||||
resourceStream = GetBinaryResourceReader(IDS_LOGOBALL);
|
||||
response->SetMimeType("image/png");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/modalmain") {
|
||||
} else if (url == "http://tests/modalmain") {
|
||||
resourceStream = GetBinaryResourceReader(IDS_MODALMAIN);
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/modaldialog") {
|
||||
} else if (url == "http://tests/modaldialog") {
|
||||
resourceStream = GetBinaryResourceReader(IDS_MODALDIALOG);
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/transparency") {
|
||||
} else if (url == "http://tests/transparency") {
|
||||
resourceStream = GetBinaryResourceReader(IDS_TRANSPARENCY);
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/plugin") {
|
||||
} else if (url == "http://tests/plugin") {
|
||||
std::string html =
|
||||
"<html><body>\n"
|
||||
"Client Plugin loaded by Mime Type:<br>\n"
|
||||
@@ -109,9 +109,10 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
// Add some extra space below the plugin to allow scrolling.
|
||||
"<div style=\"height:1000px;\"> </div>\n"
|
||||
"</body></html>";
|
||||
|
||||
resourceStream =
|
||||
CefStreamReader::CreateForData((void*)html.c_str(), html.size());
|
||||
|
||||
resourceStream = CefStreamReader::CreateForData(
|
||||
static_cast<void*>(const_cast<char*>(html.c_str())),
|
||||
html.size());
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
}
|
||||
@@ -121,37 +122,31 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
|
||||
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& url)
|
||||
{
|
||||
const CefString& url) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain())
|
||||
{
|
||||
if (m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
|
||||
// Set the edit window text
|
||||
SetWindowText(m_EditHwnd, std::wstring(url).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title)
|
||||
{
|
||||
const CefString& title) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Set the frame window title bar
|
||||
CefWindowHandle hwnd = browser->GetWindowHandle();
|
||||
if(m_BrowserHwnd == hwnd)
|
||||
{
|
||||
if (m_BrowserHwnd == hwnd) {
|
||||
// The frame window will be the parent of the browser window
|
||||
hwnd = GetParent(hwnd);
|
||||
}
|
||||
SetWindowText(hwnd, std::wstring(title).c_str());
|
||||
}
|
||||
|
||||
void ClientHandler::SendNotification(NotificationType type)
|
||||
{
|
||||
void ClientHandler::SendNotification(NotificationType type) {
|
||||
UINT id;
|
||||
switch(type)
|
||||
{
|
||||
switch (type) {
|
||||
case NOTIFY_CONSOLE_MESSAGE:
|
||||
id = ID_WARN_CONSOLEMESSAGE;
|
||||
break;
|
||||
@@ -167,22 +162,19 @@ void ClientHandler::SendNotification(NotificationType type)
|
||||
PostMessage(m_MainHwnd, WM_COMMAND, id, 0);
|
||||
}
|
||||
|
||||
void ClientHandler::SetLoading(bool isLoading)
|
||||
{
|
||||
void ClientHandler::SetLoading(bool isLoading) {
|
||||
ASSERT(m_EditHwnd != NULL && m_ReloadHwnd != NULL && m_StopHwnd != NULL);
|
||||
EnableWindow(m_EditHwnd, TRUE);
|
||||
EnableWindow(m_ReloadHwnd, !isLoading);
|
||||
EnableWindow(m_StopHwnd, isLoading);
|
||||
}
|
||||
|
||||
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward)
|
||||
{
|
||||
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) {
|
||||
ASSERT(m_BackHwnd != NULL && m_ForwardHwnd != NULL);
|
||||
EnableWindow(m_BackHwnd, canGoBack);
|
||||
EnableWindow(m_ForwardHwnd, canGoForward);
|
||||
}
|
||||
|
||||
void ClientHandler::CloseMainWindow()
|
||||
{
|
||||
void ClientHandler::CloseMainWindow() {
|
||||
::PostMessage(m_MainHwnd, WM_CLOSE, 0, 0);
|
||||
}
|
||||
|
@@ -2,29 +2,25 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "client_popup_handler.h"
|
||||
#include "cefclient/client_popup_handler.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "util.h"
|
||||
#include "cefclient/util.h"
|
||||
|
||||
ClientPopupHandler::ClientPopupHandler(CefRefPtr<CefBrowser> parentBrowser)
|
||||
: m_ParentBrowser(parentBrowser)
|
||||
{
|
||||
: m_ParentBrowser(parentBrowser) {
|
||||
ASSERT(m_ParentBrowser.get());
|
||||
}
|
||||
|
||||
ClientPopupHandler::~ClientPopupHandler()
|
||||
{
|
||||
ClientPopupHandler::~ClientPopupHandler() {
|
||||
}
|
||||
|
||||
|
||||
bool ClientPopupHandler::OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
NavType navType,
|
||||
bool isRedirect)
|
||||
{
|
||||
bool isRedirect) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
|
||||
// Load the request in the parent browser window.
|
||||
m_ParentBrowser->GetMainFrame()->LoadRequest(request);
|
||||
browser->CloseBrowser();
|
||||
|
@@ -2,8 +2,9 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _CLIENT_POPUP_HANDLER_H
|
||||
#define _CLIENT_POPUP_HANDLER_H
|
||||
#ifndef CEF_TESTS_CEFCLIENT_CLIENT_POPUP_HANDLER_H_
|
||||
#define CEF_TESTS_CEFCLIENT_CLIENT_POPUP_HANDLER_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_client.h"
|
||||
@@ -12,15 +13,15 @@
|
||||
// Handler for popup windows that loads the request in an existing browser
|
||||
// window.
|
||||
class ClientPopupHandler : public CefClient,
|
||||
public CefRequestHandler
|
||||
{
|
||||
public:
|
||||
ClientPopupHandler(CefRefPtr<CefBrowser> parentBrowser);
|
||||
public CefRequestHandler {
|
||||
public:
|
||||
explicit ClientPopupHandler(CefRefPtr<CefBrowser> parentBrowser);
|
||||
virtual ~ClientPopupHandler();
|
||||
|
||||
// CefClient methods
|
||||
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
|
||||
// CefRequestHandler methods
|
||||
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
@@ -28,11 +29,11 @@ public:
|
||||
CefRefPtr<CefRequest> request,
|
||||
NavType navType,
|
||||
bool isRedirect) OVERRIDE;
|
||||
protected:
|
||||
protected:
|
||||
CefRefPtr<CefBrowser> m_ParentBrowser;
|
||||
|
||||
// Include the default reference counting implementation.
|
||||
IMPLEMENT_REFCOUNTING(ClientPopupHandler);
|
||||
};
|
||||
|
||||
#endif // _CLIENT_POPUP_HANDLER_H
|
||||
#endif // CEF_TESTS_CEFCLIENT_CLIENT_POPUP_HANDLER_H_
|
||||
|
@@ -3,7 +3,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "clientplugin.h"
|
||||
#include "cefclient/clientplugin.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
||||
@@ -56,24 +56,21 @@ NPError NPP_ClientSetWindow(NPP instance, NPWindow* window_info) {
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
} // anonymous
|
||||
} // namespace
|
||||
|
||||
NPError API_CALL NP_ClientGetEntryPoints(NPPluginFuncs* pFuncs)
|
||||
{
|
||||
NPError API_CALL NP_ClientGetEntryPoints(NPPluginFuncs* pFuncs) {
|
||||
pFuncs->newp = NPP_ClientNew;
|
||||
pFuncs->destroy = NPP_ClientDestroy;
|
||||
pFuncs->setwindow = NPP_ClientSetWindow;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError API_CALL NP_ClientInitialize(NPNetscapeFuncs* pFuncs)
|
||||
{
|
||||
NPError API_CALL NP_ClientInitialize(NPNetscapeFuncs* pFuncs) {
|
||||
g_browser = pFuncs;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError API_CALL NP_ClientShutdown(void)
|
||||
{
|
||||
NPError API_CALL NP_ClientShutdown(void) {
|
||||
g_browser = NULL;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
@@ -82,24 +79,20 @@ NPError API_CALL NP_ClientShutdown(void)
|
||||
// ClientPlugin Implementation
|
||||
|
||||
ClientPlugin::ClientPlugin(int16 mode)
|
||||
: mode_(mode)
|
||||
{
|
||||
: mode_(mode) {
|
||||
}
|
||||
|
||||
ClientPlugin::~ClientPlugin()
|
||||
{
|
||||
ClientPlugin::~ClientPlugin() {
|
||||
}
|
||||
|
||||
bool ClientPlugin::Initialize(HINSTANCE module_handle, NPP instance,
|
||||
NPMIMEType mime_type, int16 argc, char* argn[],
|
||||
char* argv[])
|
||||
{
|
||||
char* argv[]) {
|
||||
RefreshDisplay();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ClientPlugin::SetWindow(HWND parent_window)
|
||||
{
|
||||
bool ClientPlugin::SetWindow(HWND parent_window) {
|
||||
if (!::IsWindow(parent_window)) {
|
||||
// No window created yet. Ignore this call.
|
||||
if (!IsWindow())
|
||||
@@ -119,23 +112,21 @@ bool ClientPlugin::SetWindow(HWND parent_window)
|
||||
// First time in -- no window created by plugin yet.
|
||||
::GetClientRect(parent_window, &parent_rect);
|
||||
Create(parent_window, parent_rect, NULL, WS_CHILD | WS_BORDER);
|
||||
|
||||
|
||||
UpdateWindow();
|
||||
ShowWindow(SW_SHOW);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ClientPlugin::Shutdown()
|
||||
{
|
||||
void ClientPlugin::Shutdown() {
|
||||
if (IsWindow()) {
|
||||
DestroyWindow();
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT ClientPlugin::OnPaint(UINT message, WPARAM wparam, LPARAM lparam,
|
||||
BOOL& handled)
|
||||
{
|
||||
BOOL& handled) {
|
||||
PAINTSTRUCT paint_struct;
|
||||
BeginPaint(&paint_struct);
|
||||
Paint(paint_struct.hdc);
|
||||
@@ -145,15 +136,13 @@ LRESULT ClientPlugin::OnPaint(UINT message, WPARAM wparam, LPARAM lparam,
|
||||
|
||||
// PrintClient is necessary to support off-screen rendering.
|
||||
LRESULT ClientPlugin::OnPrintClient(UINT message, WPARAM wparam, LPARAM lparam,
|
||||
BOOL& handled)
|
||||
{
|
||||
BOOL& handled) {
|
||||
Paint(reinterpret_cast<HDC>(wparam));
|
||||
return 0;
|
||||
}
|
||||
|
||||
LRESULT ClientPlugin::OnEraseBackGround(UINT message, WPARAM wparam,
|
||||
LPARAM lparam, BOOL& handled)
|
||||
{
|
||||
LPARAM lparam, BOOL& handled) {
|
||||
HDC paint_device_context = reinterpret_cast<HDC>(wparam);
|
||||
RECT erase_rect;
|
||||
GetClipBox(paint_device_context, &erase_rect);
|
||||
@@ -164,8 +153,7 @@ LRESULT ClientPlugin::OnEraseBackGround(UINT message, WPARAM wparam,
|
||||
}
|
||||
|
||||
LRESULT ClientPlugin::OnLButtonDown(UINT message, WPARAM wparam, LPARAM lparam,
|
||||
BOOL& handled)
|
||||
{
|
||||
BOOL& handled) {
|
||||
MessageBox(L"You clicked on the client plugin!", L"Client Plugin", MB_OK);
|
||||
return 0;
|
||||
}
|
||||
@@ -198,4 +186,4 @@ void ClientPlugin::Paint(HDC hdc) {
|
||||
SetTextColor(hdc, old_color);
|
||||
}
|
||||
|
||||
#endif // OS_WIN
|
||||
#endif // OS_WIN
|
||||
|
@@ -6,15 +6,17 @@
|
||||
// Portions of this implementation are borrowed from webkit\default_plugin\
|
||||
// plugin_impl.h
|
||||
|
||||
#ifndef _CEFCLIENT_CLIENTPLUGIN_H
|
||||
#define _CEFCLIENT_CLIENTPLUGIN_H
|
||||
#ifndef CEF_TESTS_CEFCLIENT_CLIENTPLUGIN_H_
|
||||
#define CEF_TESTS_CEFCLIENT_CLIENTPLUGIN_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_nplugin.h"
|
||||
#include "include/internal/cef_types.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
||||
#include <atlbase.h>
|
||||
#include <atlwin.h>
|
||||
#include <atlbase.h> // NOLINT(build/include_order)
|
||||
#include <atlwin.h> // NOLINT(build/include_order)
|
||||
#include "include/cef_nplugin.h"
|
||||
|
||||
extern NPNetscapeFuncs* g_browser;
|
||||
|
||||
@@ -82,7 +84,7 @@ class ClientPlugin : public CWindowImpl<ClientPlugin> {
|
||||
BOOL& handled);
|
||||
LRESULT OnLButtonDown(UINT message, WPARAM wparam, LPARAM lparam,
|
||||
BOOL& handled);
|
||||
|
||||
|
||||
// Enables the plugin window if required and initiates an update of the
|
||||
// the plugin window.
|
||||
void RefreshDisplay();
|
||||
@@ -96,6 +98,6 @@ class ClientPlugin : public CWindowImpl<ClientPlugin> {
|
||||
int16 mode_;
|
||||
};
|
||||
|
||||
#endif // OS_WIN
|
||||
#endif // OS_WIN
|
||||
|
||||
#endif // _CEFCLIENT_CLIENTPLUGIN_H
|
||||
#endif // CEF_TESTS_CEFCLIENT_CLIENTPLUGIN_H_
|
||||
|
@@ -2,48 +2,45 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "download_handler.h"
|
||||
#include "cefclient/download_handler.h"
|
||||
#include <stdio.h>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include "include/cef_download_handler.h"
|
||||
#include "include/cef_runnable.h"
|
||||
#include "util.h"
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include "cefclient/util.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include <windows.h>
|
||||
#include <shlobj.h>
|
||||
#include <shlwapi.h>
|
||||
#endif // OS_WIN
|
||||
#include <windows.h> // NOLINT(build/include_order)
|
||||
#include <shlobj.h> // NOLINT(build/include_order)
|
||||
#include <shlwapi.h> // NOLINT(build/include_order)
|
||||
#endif // OS_WIN
|
||||
|
||||
// Implementation of the CefDownloadHandler interface.
|
||||
class ClientDownloadHandler : public CefDownloadHandler
|
||||
{
|
||||
public:
|
||||
class ClientDownloadHandler : public CefDownloadHandler {
|
||||
public:
|
||||
ClientDownloadHandler(CefRefPtr<DownloadListener> listener,
|
||||
const CefString& fileName)
|
||||
: listener_(listener), filename_(fileName), file_(NULL)
|
||||
{
|
||||
: listener_(listener), filename_(fileName), file_(NULL) {
|
||||
}
|
||||
|
||||
~ClientDownloadHandler()
|
||||
{
|
||||
~ClientDownloadHandler() {
|
||||
ASSERT(pending_data_.empty());
|
||||
ASSERT(file_ == NULL);
|
||||
|
||||
if(!pending_data_.empty()) {
|
||||
|
||||
if (!pending_data_.empty()) {
|
||||
// Delete remaining pending data.
|
||||
std::vector<std::vector<char>*>::iterator it = pending_data_.begin();
|
||||
for(; it != pending_data_.end(); ++it)
|
||||
for (; it != pending_data_.end(); ++it)
|
||||
delete (*it);
|
||||
}
|
||||
|
||||
if(file_) {
|
||||
|
||||
if (file_) {
|
||||
// Close the dangling file pointer on the FILE thread.
|
||||
CefPostTask(TID_FILE,
|
||||
NewCefRunnableFunction(&ClientDownloadHandler::CloseDanglingFile,
|
||||
file_));
|
||||
|
||||
|
||||
// Notify the listener that the download failed.
|
||||
listener_->NotifyDownloadError(filename_);
|
||||
}
|
||||
@@ -53,8 +50,7 @@ public:
|
||||
// The following methods are called on the UI thread.
|
||||
// --------------------------------------------------
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
void Initialize() {
|
||||
// Open the file on the FILE thread.
|
||||
CefPostTask(TID_FILE,
|
||||
NewCefRunnableMethod(this, &ClientDownloadHandler::OnOpen));
|
||||
@@ -63,11 +59,10 @@ public:
|
||||
// A portion of the file contents have been received. This method will be
|
||||
// called multiple times until the download is complete. Return |true| to
|
||||
// continue receiving data and |false| to cancel.
|
||||
virtual bool ReceivedData(void* data, int data_size)
|
||||
{
|
||||
virtual bool ReceivedData(void* data, int data_size) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(data_size == 0)
|
||||
if (data_size == 0)
|
||||
return true;
|
||||
|
||||
// Create a new vector for the data.
|
||||
@@ -87,8 +82,7 @@ public:
|
||||
}
|
||||
|
||||
// The download is complete.
|
||||
virtual void Complete()
|
||||
{
|
||||
virtual void Complete() {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Flush and close the file on the FILE thread.
|
||||
@@ -100,41 +94,40 @@ public:
|
||||
// The following methods are called on the FILE thread.
|
||||
// ----------------------------------------------------
|
||||
|
||||
void OnOpen()
|
||||
{
|
||||
void OnOpen() {
|
||||
REQUIRE_FILE_THREAD();
|
||||
|
||||
if(file_)
|
||||
if (file_)
|
||||
return;
|
||||
|
||||
|
||||
#if defined(OS_WIN)
|
||||
TCHAR szFolderPath[MAX_PATH];
|
||||
|
||||
// Save the file in the user's "My Documents" folder.
|
||||
if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE,
|
||||
NULL, 0, szFolderPath))) {
|
||||
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE,
|
||||
NULL, 0, szFolderPath))) {
|
||||
std::wstring fileNameStr = filename_;
|
||||
LPWSTR name = PathFindFileName(fileNameStr.c_str());
|
||||
LPWSTR ext = PathFindExtension(fileNameStr.c_str());
|
||||
int ct = 0;
|
||||
std::wstringstream ss;
|
||||
|
||||
if(ext) {
|
||||
if (ext) {
|
||||
name[ext-name] = 0;
|
||||
ext++;
|
||||
}
|
||||
|
||||
// Make sure the file name is unique.
|
||||
do {
|
||||
if(ct > 0)
|
||||
if (ct > 0)
|
||||
ss.str(L"");
|
||||
ss << szFolderPath << L"\\" << name;
|
||||
if(ct > 0)
|
||||
if (ct > 0)
|
||||
ss << L" (" << ct << L")";
|
||||
if(ext)
|
||||
if (ext)
|
||||
ss << L"." << ext;
|
||||
ct++;
|
||||
} while(PathFileExists(ss.str().c_str()));
|
||||
} while (PathFileExists(ss.str().c_str()));
|
||||
|
||||
{
|
||||
AutoLock lock_scope(this);
|
||||
@@ -146,15 +139,14 @@ public:
|
||||
}
|
||||
#else
|
||||
// TODO(port): Implement this.
|
||||
ASSERT(false); // Not implemented
|
||||
ASSERT(false); // Not implemented
|
||||
#endif
|
||||
}
|
||||
|
||||
void OnComplete()
|
||||
{
|
||||
void OnComplete() {
|
||||
REQUIRE_FILE_THREAD();
|
||||
|
||||
if(!file_)
|
||||
if (!file_)
|
||||
return;
|
||||
|
||||
// Make sure any pending data is written.
|
||||
@@ -167,8 +159,7 @@ public:
|
||||
listener_->NotifyDownloadComplete(filename_);
|
||||
}
|
||||
|
||||
void OnReceivedData()
|
||||
{
|
||||
void OnReceivedData() {
|
||||
REQUIRE_FILE_THREAD();
|
||||
|
||||
std::vector<std::vector<char>*> data;
|
||||
@@ -176,32 +167,31 @@ public:
|
||||
// Remove all data from the pending data queue.
|
||||
{
|
||||
AutoLock lock_scope(this);
|
||||
if(!pending_data_.empty()) {
|
||||
if (!pending_data_.empty()) {
|
||||
data = pending_data_;
|
||||
pending_data_.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if(data.empty())
|
||||
if (data.empty())
|
||||
return;
|
||||
|
||||
// Write all pending data to file.
|
||||
std::vector<std::vector<char>*>::iterator it = data.begin();
|
||||
for(; it != data.end(); ++it) {
|
||||
for (; it != data.end(); ++it) {
|
||||
std::vector<char>* buffer = *it;
|
||||
if(file_)
|
||||
if (file_)
|
||||
fwrite(&(*buffer)[0], buffer->size(), 1, file_);
|
||||
delete buffer;
|
||||
}
|
||||
data.clear();
|
||||
}
|
||||
|
||||
static void CloseDanglingFile(FILE *file)
|
||||
{
|
||||
static void CloseDanglingFile(FILE *file) {
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
CefRefPtr<DownloadListener> listener_;
|
||||
CefString filename_;
|
||||
FILE* file_;
|
||||
@@ -212,8 +202,7 @@ private:
|
||||
};
|
||||
|
||||
CefRefPtr<CefDownloadHandler> CreateDownloadHandler(
|
||||
CefRefPtr<DownloadListener> listener, const CefString& fileName)
|
||||
{
|
||||
CefRefPtr<DownloadListener> listener, const CefString& fileName) {
|
||||
CefRefPtr<ClientDownloadHandler> handler =
|
||||
new ClientDownloadHandler(listener, fileName);
|
||||
handler->Initialize();
|
||||
|
@@ -2,17 +2,17 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _CEFCLIENT_DOWNLOAD_HANDLER_H
|
||||
#define _CEFCLIENT_DOWNLOAD_HANDLER_H
|
||||
#ifndef CEF_TESTS_CEFCLIENT_DOWNLOAD_HANDLER_H_
|
||||
#define CEF_TESTS_CEFCLIENT_DOWNLOAD_HANDLER_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_base.h"
|
||||
|
||||
class CefDownloadHandler;
|
||||
|
||||
// Implement this interface to receive download notifications.
|
||||
class DownloadListener : public virtual CefBase
|
||||
{
|
||||
public:
|
||||
class DownloadListener : public virtual CefBase {
|
||||
public:
|
||||
// Called when the download is complete.
|
||||
virtual void NotifyDownloadComplete(const CefString& fileName) =0;
|
||||
|
||||
@@ -24,4 +24,4 @@ public:
|
||||
CefRefPtr<CefDownloadHandler> CreateDownloadHandler(
|
||||
CefRefPtr<DownloadListener> listener, const CefString& fileName);
|
||||
|
||||
#endif // _CEFCLIENT_DOWNLOAD_HANDLER_H
|
||||
#endif // CEF_TESTS_CEFCLIENT_DOWNLOAD_HANDLER_H_
|
||||
|
@@ -2,17 +2,17 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "extension_test.h"
|
||||
#include "cefclient/extension_test.h"
|
||||
#include <string>
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "include/cef_stream.h"
|
||||
#include "include/cef_v8.h"
|
||||
#include "resource_util.h"
|
||||
#include "cefclient/resource_util.h"
|
||||
|
||||
// Implementation of the V8 handler class for the "cef.test" extension.
|
||||
class ClientV8ExtensionHandler : public CefV8Handler
|
||||
{
|
||||
public:
|
||||
class ClientV8ExtensionHandler : public CefV8Handler {
|
||||
public:
|
||||
ClientV8ExtensionHandler() : test_param_("An initial string value.") {}
|
||||
virtual ~ClientV8ExtensionHandler() {}
|
||||
|
||||
@@ -22,32 +22,24 @@ public:
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception)
|
||||
{
|
||||
if(name == "Dummy")
|
||||
{
|
||||
CefString& exception) {
|
||||
if (name == "Dummy") {
|
||||
// Used for performance testing.
|
||||
return true;
|
||||
}
|
||||
else if(name == "SetTestParam")
|
||||
{
|
||||
} else if (name == "SetTestParam") {
|
||||
// Handle the SetTestParam native function by saving the string argument
|
||||
// into the local member.
|
||||
if(arguments.size() != 1 || !arguments[0]->IsString())
|
||||
if (arguments.size() != 1 || !arguments[0]->IsString())
|
||||
return false;
|
||||
|
||||
|
||||
test_param_ = arguments[0]->GetStringValue();
|
||||
return true;
|
||||
}
|
||||
else if(name == "GetTestParam")
|
||||
{
|
||||
} else if (name == "GetTestParam") {
|
||||
// Handle the GetTestParam native function by returning the local member
|
||||
// value.
|
||||
retval = CefV8Value::CreateString(test_param_);
|
||||
return true;
|
||||
}
|
||||
else if(name == "GetTestObject")
|
||||
{
|
||||
} else if (name == "GetTestObject") {
|
||||
// Handle the GetTestObject native function by creating and returning a
|
||||
// new V8 object.
|
||||
retval = CefV8Value::CreateObject(NULL, NULL);
|
||||
@@ -60,9 +52,7 @@ public:
|
||||
CefV8Value::CreateFunction("GetMessage", this),
|
||||
V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
return true;
|
||||
}
|
||||
else if(name == "GetMessage")
|
||||
{
|
||||
} else if (name == "GetMessage") {
|
||||
// Handle the GetMessage object function by returning a string.
|
||||
retval = CefV8Value::CreateString(
|
||||
"Calling a function on a native object succeeded.");
|
||||
@@ -71,15 +61,14 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
CefString test_param_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(ClientV8ExtensionHandler);
|
||||
};
|
||||
|
||||
|
||||
void InitExtensionTest()
|
||||
{
|
||||
void InitExtensionTest() {
|
||||
// Register a V8 extension with the below JavaScript code that calls native
|
||||
// methods implemented in ClientV8ExtensionHandler.
|
||||
std::string code = "var cef;"
|
||||
@@ -94,7 +83,7 @@ void InitExtensionTest()
|
||||
" });"
|
||||
" cef.test.__defineSetter__('test_param', function(b) {"
|
||||
" native function SetTestParam();"
|
||||
" if(b) SetTestParam(b);"
|
||||
" if (b) SetTestParam(b);"
|
||||
" });"
|
||||
" cef.test.test_object = function() {"
|
||||
" native function GetTestObject();"
|
||||
@@ -108,8 +97,7 @@ void InitExtensionTest()
|
||||
CefRegisterExtension("v8/test", code, new ClientV8ExtensionHandler());
|
||||
}
|
||||
|
||||
void RunExtensionTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunExtensionTest(CefRefPtr<CefBrowser> browser) {
|
||||
std::string html =
|
||||
"<html><body>ClientV8ExtensionHandler says:<br><pre>"
|
||||
"<script language=\"JavaScript\">"
|
||||
@@ -127,8 +115,7 @@ void RunExtensionTest(CefRefPtr<CefBrowser> browser)
|
||||
browser->GetMainFrame()->LoadString(html, "about:blank");
|
||||
}
|
||||
|
||||
void RunExtensionPerfTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunExtensionPerfTest(CefRefPtr<CefBrowser> browser) {
|
||||
CefRefPtr<CefStreamReader> resourceStream;
|
||||
#if defined(OS_WIN)
|
||||
resourceStream = GetBinaryResourceReader(IDS_EXTENSIONPERF);
|
||||
|
@@ -2,8 +2,9 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _CEFCLIENT_EXTENSION_TEST_H
|
||||
#define _CEFCLIENT_EXTENSION_TEST_H
|
||||
#ifndef CEF_TESTS_CEFCLIENT_EXTENSION_TEST_H_
|
||||
#define CEF_TESTS_CEFCLIENT_EXTENSION_TEST_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_base.h"
|
||||
|
||||
@@ -16,4 +17,4 @@ void InitExtensionTest();
|
||||
void RunExtensionTest(CefRefPtr<CefBrowser> browser);
|
||||
void RunExtensionPerfTest(CefRefPtr<CefBrowser> browser);
|
||||
|
||||
#endif // _CEFCLIENT_EXTENSION_TEST_H
|
||||
#endif // CEF_TESTS_CEFCLIENT_EXTENSION_TEST_H_
|
||||
|
@@ -3,23 +3,26 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "osrplugin.h"
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "cefclient.h"
|
||||
#include "client_popup_handler.h"
|
||||
#include "resource.h"
|
||||
#include "resource_util.h"
|
||||
#include "string_util.h"
|
||||
#include "util.h"
|
||||
#include <gl/gl.h>
|
||||
#include <gl/glu.h>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <sstream>
|
||||
#include "cefclient/osrplugin.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
||||
#include <windows.h>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <gl/gl.h>
|
||||
#include <gl/glu.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "cefclient/cefclient.h"
|
||||
#include "cefclient/client_popup_handler.h"
|
||||
#include "cefclient/resource.h"
|
||||
#include "cefclient/resource_util.h"
|
||||
#include "cefclient/string_util.h"
|
||||
#include "cefclient/util.h"
|
||||
|
||||
// Initialized in NP_Initialize.
|
||||
NPNetscapeFuncs* g_osrbrowser = NULL;
|
||||
|
||||
@@ -38,11 +41,9 @@ bool g_offscreenTransparent = false;
|
||||
#define GL_BYTE_COUNT (g_offscreenTransparent?4:3)
|
||||
|
||||
// Class holding pointers for the client plugin window.
|
||||
class ClientPlugin
|
||||
{
|
||||
public:
|
||||
ClientPlugin()
|
||||
{
|
||||
class ClientPlugin {
|
||||
public:
|
||||
ClientPlugin() {
|
||||
hWnd = NULL;
|
||||
hDC = NULL;
|
||||
hRC = NULL;
|
||||
@@ -59,19 +60,16 @@ class ClientOSRHandler : public CefClient,
|
||||
public CefLoadHandler,
|
||||
public CefRequestHandler,
|
||||
public CefDisplayHandler,
|
||||
public CefRenderHandler
|
||||
{
|
||||
public:
|
||||
ClientOSRHandler(ClientPlugin* plugin)
|
||||
public CefRenderHandler {
|
||||
public:
|
||||
explicit ClientOSRHandler(ClientPlugin* plugin)
|
||||
: plugin_(plugin),
|
||||
view_buffer_(NULL),
|
||||
view_buffer_size_(0),
|
||||
popup_buffer_(NULL),
|
||||
popup_buffer_size_(0)
|
||||
{
|
||||
popup_buffer_size_(0) {
|
||||
}
|
||||
~ClientOSRHandler()
|
||||
{
|
||||
~ClientOSRHandler() {
|
||||
if (view_buffer_)
|
||||
delete [] view_buffer_;
|
||||
if (popup_buffer_)
|
||||
@@ -79,16 +77,21 @@ public:
|
||||
}
|
||||
|
||||
// CefClient methods
|
||||
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
|
||||
// CefLifeSpanHandler methods
|
||||
|
||||
@@ -97,8 +100,7 @@ public:
|
||||
CefWindowInfo& windowInfo,
|
||||
const CefString& url,
|
||||
CefRefPtr<CefClient>& client,
|
||||
CefBrowserSettings& settings) OVERRIDE
|
||||
{
|
||||
CefBrowserSettings& settings) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
windowInfo.m_bWindowRenderingDisabled = TRUE;
|
||||
@@ -106,8 +108,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE
|
||||
{
|
||||
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Set the view size to match the plugin window size.
|
||||
@@ -116,19 +117,17 @@ public:
|
||||
g_offscreenBrowser = browser;
|
||||
}
|
||||
|
||||
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE
|
||||
{
|
||||
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE {
|
||||
g_offscreenBrowser = NULL;
|
||||
}
|
||||
|
||||
// CefLoadHandler methods
|
||||
|
||||
virtual void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame) OVERRIDE
|
||||
{
|
||||
CefRefPtr<CefFrame> frame) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(!browser->IsPopup() && frame->IsMain()) {
|
||||
if (!browser->IsPopup() && frame->IsMain()) {
|
||||
// We've just started loading a page
|
||||
SetLoading(true);
|
||||
}
|
||||
@@ -136,11 +135,10 @@ public:
|
||||
|
||||
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int httpStatusCode) OVERRIDE
|
||||
{
|
||||
int httpStatusCode) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(!browser->IsPopup() && frame->IsMain()) {
|
||||
if (!browser->IsPopup() && frame->IsMain()) {
|
||||
// We've just finished loading a page
|
||||
SetLoading(false);
|
||||
}
|
||||
@@ -153,12 +151,11 @@ public:
|
||||
CefString& redirectUrl,
|
||||
CefRefPtr<CefStreamReader>& resourceStream,
|
||||
CefRefPtr<CefResponse> response,
|
||||
int loadFlags) OVERRIDE
|
||||
{
|
||||
int loadFlags) OVERRIDE {
|
||||
REQUIRE_IO_THREAD();
|
||||
|
||||
std::string url = request->GetURL();
|
||||
if(url == "http://tests/transparency") {
|
||||
if (url == "http://tests/transparency") {
|
||||
resourceStream = GetBinaryResourceReader(IDS_TRANSPARENCY);
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
@@ -171,8 +168,7 @@ public:
|
||||
|
||||
virtual void OnNavStateChange(CefRefPtr<CefBrowser> browser,
|
||||
bool canGoBack,
|
||||
bool canGoForward) OVERRIDE
|
||||
{
|
||||
bool canGoForward) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Set the "back" and "forward" button state in the HTML.
|
||||
@@ -186,8 +182,7 @@ public:
|
||||
|
||||
virtual void OnAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& url) OVERRIDE
|
||||
{
|
||||
const CefString& url) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Set the "url" value in the HTML.
|
||||
@@ -199,8 +194,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void OnTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title) OVERRIDE
|
||||
{
|
||||
const CefString& title) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Set the "title" value in the HTML.
|
||||
@@ -215,8 +209,7 @@ public:
|
||||
// CefRenderHandler methods
|
||||
|
||||
virtual bool GetViewRect(CefRefPtr<CefBrowser> browser,
|
||||
CefRect& rect) OVERRIDE
|
||||
{
|
||||
CefRect& rect) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// The simulated screen and view rectangle are the same. This is necessary
|
||||
@@ -228,8 +221,7 @@ public:
|
||||
}
|
||||
|
||||
virtual bool GetScreenRect(CefRefPtr<CefBrowser> browser,
|
||||
CefRect& rect) OVERRIDE
|
||||
{
|
||||
CefRect& rect) OVERRIDE {
|
||||
return GetViewRect(browser, rect);
|
||||
}
|
||||
|
||||
@@ -237,8 +229,7 @@ public:
|
||||
int viewX,
|
||||
int viewY,
|
||||
int& screenX,
|
||||
int& screenY) OVERRIDE
|
||||
{
|
||||
int& screenY) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Convert the point from view coordinates to actual screen coordinates.
|
||||
@@ -250,13 +241,12 @@ public:
|
||||
}
|
||||
|
||||
virtual void OnPopupShow(CefRefPtr<CefBrowser> browser,
|
||||
bool show) OVERRIDE
|
||||
{
|
||||
bool show) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(!show) {
|
||||
if (!show) {
|
||||
// Clear the popup buffer.
|
||||
popup_rect_.Set(0,0,0,0);
|
||||
popup_rect_.Set(0, 0, 0, 0);
|
||||
if (popup_buffer_) {
|
||||
delete [] popup_buffer_;
|
||||
popup_buffer_ = NULL;
|
||||
@@ -266,8 +256,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void OnPopupSize(CefRefPtr<CefBrowser> browser,
|
||||
const CefRect& rect) OVERRIDE
|
||||
{
|
||||
const CefRect& rect) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if (rect.width > 0) {
|
||||
@@ -282,8 +271,7 @@ public:
|
||||
virtual void OnPaint(CefRefPtr<CefBrowser> browser,
|
||||
PaintElementType type,
|
||||
const RectList& dirtyRects,
|
||||
const void* buffer) OVERRIDE
|
||||
{
|
||||
const void* buffer) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
wglMakeCurrent(plugin_->hDC, plugin_->hRC);
|
||||
@@ -297,7 +285,7 @@ public:
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, g_textureID);
|
||||
|
||||
|
||||
if (type == PET_VIEW) {
|
||||
// Paint the view.
|
||||
if (g_offscreenTransparent)
|
||||
@@ -310,8 +298,8 @@ public:
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, g_width, g_height,
|
||||
GL_IMAGE_FORMAT, GL_UNSIGNED_BYTE, view_buffer_);
|
||||
}
|
||||
|
||||
if(popup_rect_.width > 0) {
|
||||
|
||||
if (popup_rect_.width > 0) {
|
||||
if (type == PET_POPUP) {
|
||||
// Paint the popup.
|
||||
if (g_offscreenTransparent)
|
||||
@@ -339,8 +327,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void OnCursorChange(CefRefPtr<CefBrowser> browser,
|
||||
CefCursorHandle cursor) OVERRIDE
|
||||
{
|
||||
CefCursorHandle cursor) OVERRIDE {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Change the plugin window's cursor.
|
||||
@@ -349,9 +336,8 @@ public:
|
||||
SetCursor(cursor);
|
||||
}
|
||||
|
||||
private:
|
||||
void SetLoading(bool isLoading)
|
||||
{
|
||||
private:
|
||||
void SetLoading(bool isLoading) {
|
||||
// Set the "stop" and "reload" button state in the HTML.
|
||||
std::stringstream ss;
|
||||
ss << "document.getElementById('stop').disabled = "
|
||||
@@ -362,10 +348,9 @@ private:
|
||||
}
|
||||
|
||||
// Size the RGB buffer.
|
||||
void SetBufferSize(int width, int height, bool view)
|
||||
{
|
||||
void SetBufferSize(int width, int height, bool view) {
|
||||
int dst_size = width * height * GL_BYTE_COUNT;
|
||||
|
||||
|
||||
// Allocate a new buffer if necesary.
|
||||
if (view) {
|
||||
if (dst_size > view_buffer_size_) {
|
||||
@@ -385,8 +370,7 @@ private:
|
||||
}
|
||||
|
||||
// Set the contents of the RGBA buffer.
|
||||
void SetRGBA(const void* src, int width, int height, bool view)
|
||||
{
|
||||
void SetRGBA(const void* src, int width, int height, bool view) {
|
||||
SetBufferSize(width, height, view);
|
||||
ConvertToRGBA((unsigned char*)src, view?view_buffer_:popup_buffer_, width,
|
||||
height);
|
||||
@@ -394,23 +378,21 @@ private:
|
||||
|
||||
// Convert from BGRA to RGBA format and from upper-left to lower-left origin.
|
||||
static void ConvertToRGBA(const unsigned char* src, unsigned char* dst,
|
||||
int width, int height)
|
||||
{
|
||||
int width, int height) {
|
||||
int sp = 0, dp = (height-1) * width * 4;
|
||||
for(int i = 0; i < height; i++) {
|
||||
for(int j = 0; j < width; j++, dp += 4, sp += 4) {
|
||||
dst[dp] = src[sp+2]; // R
|
||||
dst[dp+1] = src[sp+1]; // G
|
||||
dst[dp+2] = src[sp]; // B
|
||||
dst[dp+3] = src[sp+3]; // A
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++, dp += 4, sp += 4) {
|
||||
dst[dp] = src[sp+2]; // R
|
||||
dst[dp+1] = src[sp+1]; // G
|
||||
dst[dp+2] = src[sp]; // B
|
||||
dst[dp+3] = src[sp+3]; // A
|
||||
}
|
||||
dp -= width * 8;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the contents of the RGB buffer.
|
||||
void SetRGB(const void* src, int width, int height, bool view)
|
||||
{
|
||||
void SetRGB(const void* src, int width, int height, bool view) {
|
||||
SetBufferSize(width, height, view);
|
||||
ConvertToRGB((unsigned char*)src, view?view_buffer_:popup_buffer_, width,
|
||||
height);
|
||||
@@ -418,14 +400,13 @@ private:
|
||||
|
||||
// Convert from BGRA to RGB format and from upper-left to lower-left origin.
|
||||
static void ConvertToRGB(const unsigned char* src, unsigned char* dst,
|
||||
int width, int height)
|
||||
{
|
||||
int width, int height) {
|
||||
int sp = 0, dp = (height-1) * width * 3;
|
||||
for(int i = 0; i < height; i++) {
|
||||
for(int j = 0; j < width; j++, dp += 3, sp += 4) {
|
||||
dst[dp] = src[sp+2]; // R
|
||||
dst[dp+1] = src[sp+1]; // G
|
||||
dst[dp+2] = src[sp]; // B
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++, dp += 3, sp += 4) {
|
||||
dst[dp] = src[sp+2]; // R
|
||||
dst[dp+1] = src[sp+1]; // G
|
||||
dst[dp+2] = src[sp]; // B
|
||||
}
|
||||
dp -= width * 6;
|
||||
}
|
||||
@@ -447,14 +428,13 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
LPARAM lParam);
|
||||
|
||||
// Enable GL.
|
||||
void EnableGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
|
||||
{
|
||||
void EnableGL(HWND hWnd, HDC * hDC, HGLRC * hRC) {
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
int format;
|
||||
|
||||
|
||||
// Get the device context.
|
||||
*hDC = GetDC(hWnd);
|
||||
|
||||
|
||||
// Set the pixel format for the DC.
|
||||
ZeroMemory(&pfd, sizeof(pfd));
|
||||
pfd.nSize = sizeof(pfd);
|
||||
@@ -466,7 +446,7 @@ void EnableGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
format = ChoosePixelFormat(*hDC, &pfd);
|
||||
SetPixelFormat(*hDC, format, &pfd);
|
||||
|
||||
|
||||
// Create and enable the render context.
|
||||
*hRC = wglCreateContext(*hDC);
|
||||
wglMakeCurrent(*hDC, *hRC);
|
||||
@@ -483,20 +463,18 @@ void EnableGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
|
||||
}
|
||||
|
||||
// Disable GL.
|
||||
void DisableGL(HWND hWnd, HDC hDC, HGLRC hRC)
|
||||
{
|
||||
void DisableGL(HWND hWnd, HDC hDC, HGLRC hRC) {
|
||||
// Delete the texture.
|
||||
if(g_textureID != -1)
|
||||
if (g_textureID != -1)
|
||||
glDeleteTextures(1, &g_textureID);
|
||||
|
||||
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
wglDeleteContext(hRC);
|
||||
ReleaseDC(hWnd, hDC);
|
||||
}
|
||||
|
||||
// Size the GL view.
|
||||
void SizeGL(ClientPlugin* plugin, int width, int height)
|
||||
{
|
||||
void SizeGL(ClientPlugin* plugin, int width, int height) {
|
||||
g_width = width;
|
||||
g_height = height;
|
||||
|
||||
@@ -517,7 +495,7 @@ void SizeGL(ClientPlugin* plugin, int width, int height)
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
// Delete the existing exture.
|
||||
if(g_textureID != -1)
|
||||
if (g_textureID != -1)
|
||||
glDeleteTextures(1, &g_textureID);
|
||||
|
||||
// Create a new texture.
|
||||
@@ -543,16 +521,15 @@ void SizeGL(ClientPlugin* plugin, int width, int height)
|
||||
}
|
||||
|
||||
delete [] buffer;
|
||||
|
||||
if(g_offscreenBrowser.get())
|
||||
|
||||
if (g_offscreenBrowser.get())
|
||||
g_offscreenBrowser->SetSize(PET_VIEW, width, height);
|
||||
}
|
||||
|
||||
// Render the view contents.
|
||||
void RenderGL(ClientPlugin* plugin)
|
||||
{
|
||||
void RenderGL(ClientPlugin* plugin) {
|
||||
wglMakeCurrent(plugin->hDC, plugin->hRC);
|
||||
|
||||
|
||||
struct {
|
||||
float tu, tv;
|
||||
float x, y, z;
|
||||
@@ -567,20 +544,20 @@ void RenderGL(ClientPlugin* plugin)
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
//glTranslatef(0.0f, 0.0f, -3.0f);
|
||||
// glTranslatef(0.0f, 0.0f, -3.0f);
|
||||
|
||||
// Draw the background gradient.
|
||||
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||
glBegin(GL_QUADS);
|
||||
glColor4f(1.0,0.0,0.0,1.0); // red
|
||||
glVertex2f(-1.0,-1.0);
|
||||
glVertex2f(1.0,-1.0);
|
||||
glColor4f(0.0,0.0,1.0,1.0); // blue
|
||||
glColor4f(1.0, 0.0, 0.0, 1.0); // red
|
||||
glVertex2f(-1.0, -1.0);
|
||||
glVertex2f(1.0, -1.0);
|
||||
glColor4f(0.0, 0.0, 1.0, 1.0); // blue
|
||||
glVertex2f(1.0, 1.0);
|
||||
glVertex2f(-1.0, 1.0);
|
||||
glEnd();
|
||||
glPopAttrib();
|
||||
|
||||
|
||||
// Rotate the view based on the mouse spin.
|
||||
glRotatef(-g_spinX, 1.0f, 0.0f, 0.0f);
|
||||
glRotatef(-g_spinY, 0.0f, 1.0f, 0.0f);
|
||||
@@ -615,17 +592,17 @@ NPError NPP_NewImpl(NPMIMEType plugin_type, NPP instance, uint16 mode,
|
||||
if (instance == NULL)
|
||||
return NPERR_INVALID_INSTANCE_ERROR;
|
||||
|
||||
ClientPlugin *plugin = new ClientPlugin;
|
||||
ClientPlugin* plugin = new ClientPlugin;
|
||||
instance->pdata = reinterpret_cast<void*>(plugin);
|
||||
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError NPP_DestroyImpl(NPP instance, NPSavedData** save) {
|
||||
ClientPlugin *plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
|
||||
ClientPlugin* plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
|
||||
if (plugin) {
|
||||
if(plugin->hWnd) {
|
||||
if (plugin->hWnd) {
|
||||
DestroyWindow(plugin->hWnd);
|
||||
DisableGL(plugin->hWnd, plugin->hDC, plugin->hRC);
|
||||
}
|
||||
@@ -642,14 +619,13 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
|
||||
if (window_info == NULL)
|
||||
return NPERR_GENERIC_ERROR;
|
||||
|
||||
ClientPlugin *plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
ClientPlugin* plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
HWND parent_hwnd = reinterpret_cast<HWND>(window_info->window);
|
||||
|
||||
if (plugin->hWnd == NULL)
|
||||
{
|
||||
|
||||
if (plugin->hWnd == NULL) {
|
||||
WNDCLASS wc;
|
||||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||||
|
||||
|
||||
// Register the window class.
|
||||
wc.style = CS_OWNDC;
|
||||
wc.lpfnWndProc = PluginWndProc;
|
||||
@@ -662,7 +638,7 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
|
||||
wc.lpszMenuName = NULL;
|
||||
wc.lpszClassName = L"ClientOSRPlugin";
|
||||
RegisterClass(&wc);
|
||||
|
||||
|
||||
// Create the main window.
|
||||
plugin->hWnd = CreateWindow(L"ClientOSRPlugin", L"Client OSR Plugin",
|
||||
WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, 0, 0, 0, 0, parent_hwnd, NULL,
|
||||
@@ -670,7 +646,7 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
|
||||
|
||||
SetWindowLongPtr(plugin->hWnd, GWLP_USERDATA,
|
||||
reinterpret_cast<LONG_PTR>(plugin));
|
||||
|
||||
|
||||
// Enable GL drawing for the window.
|
||||
EnableGL(plugin->hWnd, &(plugin->hDC), &(plugin->hRC));
|
||||
|
||||
@@ -699,22 +675,20 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
|
||||
|
||||
// Plugin window procedure.
|
||||
LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
LPARAM lParam) {
|
||||
static POINT lastMousePos, curMousePos;
|
||||
static bool mouseRotation = false;
|
||||
static bool mouseTracking = false;
|
||||
|
||||
ClientPlugin* plugin =
|
||||
reinterpret_cast<ClientPlugin*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
|
||||
|
||||
switch(message)
|
||||
{
|
||||
|
||||
switch (message) {
|
||||
case WM_CREATE:
|
||||
// Start the timer that's used for redrawing.
|
||||
SetTimer(hWnd, 1, 20, NULL);
|
||||
return 0;
|
||||
|
||||
|
||||
case WM_DESTROY:
|
||||
// Stop the timer that's used for redrawing.
|
||||
KillTimer(hWnd, 1);
|
||||
@@ -724,10 +698,10 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
g_offscreenBrowser = NULL;
|
||||
return 0;
|
||||
|
||||
case WM_TIMER:
|
||||
case WM_TIMER:
|
||||
RenderGL(plugin);
|
||||
break;
|
||||
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
case WM_RBUTTONDOWN:
|
||||
SetCapture(hWnd);
|
||||
@@ -740,7 +714,7 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
} else {
|
||||
if (g_offscreenBrowser.get()) {
|
||||
g_offscreenBrowser->SendMouseClickEvent(LOWORD(lParam), HIWORD(lParam),
|
||||
(message==WM_LBUTTONDOWN?MBT_LEFT:MBT_RIGHT), false, 1);
|
||||
(message == WM_LBUTTONDOWN?MBT_LEFT:MBT_RIGHT), false, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -757,13 +731,13 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
} else {
|
||||
if (g_offscreenBrowser.get()) {
|
||||
g_offscreenBrowser->SendMouseClickEvent(LOWORD(lParam), HIWORD(lParam),
|
||||
(message==WM_LBUTTONUP?MBT_LEFT:MBT_RIGHT), true, 1);
|
||||
(message == WM_LBUTTONUP?MBT_LEFT:MBT_RIGHT), true, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_MOUSEMOVE:
|
||||
if(mouseRotation) {
|
||||
if (mouseRotation) {
|
||||
// Apply rotation effect.
|
||||
curMousePos.x = LOWORD(lParam);
|
||||
curMousePos.y = HIWORD(lParam);
|
||||
@@ -809,23 +783,24 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
GET_WHEEL_DELTA_WPARAM(wParam));
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case WM_SIZE: {
|
||||
int width = LOWORD(lParam);
|
||||
int width = LOWORD(lParam);
|
||||
int height = HIWORD(lParam);
|
||||
if(width > 0 && height > 0)
|
||||
if (width > 0 && height > 0)
|
||||
SizeGL(plugin, width, height);
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_SETFOCUS:
|
||||
case WM_KILLFOCUS:
|
||||
if (g_offscreenBrowser.get())
|
||||
g_offscreenBrowser->SendFocusEvent(message==WM_SETFOCUS);
|
||||
g_offscreenBrowser->SendFocusEvent(message == WM_SETFOCUS);
|
||||
break;
|
||||
|
||||
case WM_CAPTURECHANGED:
|
||||
case WM_CANCELMODE:
|
||||
if(!mouseRotation) {
|
||||
if (!mouseRotation) {
|
||||
if (g_offscreenBrowser.get())
|
||||
g_offscreenBrowser->SendCaptureLostEvent();
|
||||
}
|
||||
@@ -846,7 +821,7 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
type = KT_KEYDOWN;
|
||||
else if (message == WM_KEYUP || message == WM_SYSKEYUP)
|
||||
type = KT_KEYUP;
|
||||
|
||||
|
||||
if (message == WM_SYSKEYDOWN || message == WM_SYSKEYUP ||
|
||||
message == WM_SYSCHAR)
|
||||
sysChar = true;
|
||||
@@ -862,7 +837,8 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
PAINTSTRUCT ps;
|
||||
BeginPaint(hWnd, &ps);
|
||||
EndPaint(hWnd, &ps);
|
||||
} return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
return 0;
|
||||
@@ -871,36 +847,31 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
NPError API_CALL NP_OSRGetEntryPoints(NPPluginFuncs* pFuncs)
|
||||
{
|
||||
NPError API_CALL NP_OSRGetEntryPoints(NPPluginFuncs* pFuncs) {
|
||||
pFuncs->newp = NPP_NewImpl;
|
||||
pFuncs->destroy = NPP_DestroyImpl;
|
||||
pFuncs->setwindow = NPP_SetWindowImpl;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError API_CALL NP_OSRInitialize(NPNetscapeFuncs* pFuncs)
|
||||
{
|
||||
NPError API_CALL NP_OSRInitialize(NPNetscapeFuncs* pFuncs) {
|
||||
g_osrbrowser = pFuncs;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError API_CALL NP_OSRShutdown(void)
|
||||
{
|
||||
NPError API_CALL NP_OSRShutdown(void) {
|
||||
g_osrbrowser = NULL;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowser> GetOffScreenBrowser()
|
||||
{
|
||||
CefRefPtr<CefBrowser> GetOffScreenBrowser() {
|
||||
return g_offscreenBrowser;
|
||||
}
|
||||
|
||||
void SetOffScreenTransparent(bool transparent)
|
||||
{
|
||||
void SetOffScreenTransparent(bool transparent) {
|
||||
g_offscreenTransparent = transparent;
|
||||
}
|
||||
|
||||
#endif // OS_WIN
|
||||
#endif // OS_WIN
|
||||
|
@@ -6,8 +6,9 @@
|
||||
// Portions of this implementation are borrowed from webkit\default_plugin\
|
||||
// plugin_impl.h
|
||||
|
||||
#ifndef _CEFCLIENT_OSRPLUGIN_H
|
||||
#define _CEFCLIENT_OSRPLUGIN_H
|
||||
#ifndef CEF_TESTS_CEFCLIENT_OSRPLUGIN_H_
|
||||
#define CEF_TESTS_CEFCLIENT_OSRPLUGIN_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_base.h"
|
||||
|
||||
@@ -27,6 +28,6 @@ CefRefPtr<CefBrowser> GetOffScreenBrowser();
|
||||
|
||||
void SetOffScreenTransparent(bool transparent);
|
||||
|
||||
#endif // OS_WIN
|
||||
#endif // OS_WIN
|
||||
|
||||
#endif // _CEFCLIENT_OSRPLUGIN_H
|
||||
#endif // CEF_TESTS_CEFCLIENT_OSRPLUGIN_H_
|
||||
|
@@ -2,16 +2,16 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "osrplugin_test.h"
|
||||
#include "cefclient/osrplugin_test.h"
|
||||
#include <string>
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "osrplugin.h"
|
||||
#include "cefclient.h"
|
||||
#include "client_handler.h"
|
||||
#include "plugin_test.h"
|
||||
#include "cefclient/osrplugin.h"
|
||||
#include "cefclient/cefclient.h"
|
||||
#include "cefclient/client_handler.h"
|
||||
#include "cefclient/plugin_test.h"
|
||||
|
||||
void InitOSRPluginTest()
|
||||
{
|
||||
void InitOSRPluginTest() {
|
||||
// Structure providing information about the client plugin.
|
||||
CefPluginInfo plugin_info;
|
||||
CefString(&plugin_info.display_name).FromASCII("Client OSR Plugin");
|
||||
@@ -28,27 +28,24 @@ void InitOSRPluginTest()
|
||||
CefRegisterPlugin(plugin_info);
|
||||
}
|
||||
|
||||
void RunOSRPluginTest(CefRefPtr<CefBrowser> browser, bool transparent)
|
||||
{
|
||||
class Listener : public CefDOMEventListener
|
||||
{
|
||||
public:
|
||||
void RunOSRPluginTest(CefRefPtr<CefBrowser> browser, bool transparent) {
|
||||
class Listener : public CefDOMEventListener {
|
||||
public:
|
||||
Listener() {}
|
||||
virtual void HandleEvent(CefRefPtr<CefDOMEvent> event)
|
||||
{
|
||||
virtual void HandleEvent(CefRefPtr<CefDOMEvent> event) {
|
||||
CefRefPtr<CefBrowser> browser = GetOffScreenBrowser();
|
||||
|
||||
|
||||
CefRefPtr<CefDOMNode> element = event->GetTarget();
|
||||
ASSERT(element.get());
|
||||
std::string elementId = element->GetElementAttribute("id");
|
||||
|
||||
if (elementId == "back") {
|
||||
browser->GoBack();
|
||||
} else if(elementId == "forward") {
|
||||
} else if (elementId == "forward") {
|
||||
browser->GoForward();
|
||||
} else if(elementId == "stop") {
|
||||
} else if (elementId == "stop") {
|
||||
browser->Reload();
|
||||
} else if(elementId == "reload") {
|
||||
} else if (elementId == "reload") {
|
||||
browser->StopLoad();
|
||||
} else if (elementId == "go") {
|
||||
// Retrieve the value of the "url" field and load it in the off-screen
|
||||
@@ -60,15 +57,15 @@ void RunOSRPluginTest(CefRefPtr<CefBrowser> browser, bool transparent)
|
||||
CefString value = url->GetValue();
|
||||
if (!value.empty())
|
||||
browser->GetMainFrame()->LoadURL(value);
|
||||
} else if(elementId == "testTransparency") {
|
||||
} else if (elementId == "testTransparency") {
|
||||
// Transparency test.
|
||||
browser->GetMainFrame()->LoadURL(
|
||||
"http://tests/transparency");
|
||||
} else if(elementId == "testWindowlessPlugin") {
|
||||
} else if (elementId == "testWindowlessPlugin") {
|
||||
// Load flash, which is a windowless plugin.
|
||||
browser->GetMainFrame()->LoadURL(
|
||||
"http://www.adobe.com/software/flash/about/");
|
||||
} else if(elementId == "viewSource") {
|
||||
} else if (elementId == "viewSource") {
|
||||
// View the page source for the host browser window.
|
||||
AppGetBrowser()->GetMainFrame()->ViewSource();
|
||||
} else {
|
||||
@@ -80,24 +77,21 @@ void RunOSRPluginTest(CefRefPtr<CefBrowser> browser, bool transparent)
|
||||
IMPLEMENT_REFCOUNTING(Listener);
|
||||
};
|
||||
|
||||
class Visitor : public CefDOMVisitor
|
||||
{
|
||||
public:
|
||||
class Visitor : public CefDOMVisitor {
|
||||
public:
|
||||
Visitor() {}
|
||||
|
||||
void RegisterClickListener(CefRefPtr<CefDOMDocument> document,
|
||||
CefRefPtr<CefDOMEventListener> listener,
|
||||
const std::string& elementId)
|
||||
{
|
||||
const std::string& elementId) {
|
||||
CefRefPtr<CefDOMNode> element = document->GetElementById(elementId);
|
||||
ASSERT(element.get());
|
||||
element->AddEventListener("click", listener, false);
|
||||
}
|
||||
|
||||
virtual void Visit(CefRefPtr<CefDOMDocument> document)
|
||||
{
|
||||
virtual void Visit(CefRefPtr<CefDOMDocument> document) {
|
||||
CefRefPtr<CefDOMEventListener> listener(new Listener());
|
||||
|
||||
|
||||
// Register click listeners for the various HTML elements.
|
||||
RegisterClickListener(document, listener, "back");
|
||||
RegisterClickListener(document, listener, "forward");
|
||||
|
@@ -2,8 +2,9 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _CEFCLIENT_OSRPLUGIN_TEST_H
|
||||
#define _CEFCLIENT_OSRPLUGIN_TEST_H
|
||||
#ifndef CEF_TESTS_CEFCLIENT_OSRPLUGIN_TEST_H_
|
||||
#define CEF_TESTS_CEFCLIENT_OSRPLUGIN_TEST_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_base.h"
|
||||
|
||||
@@ -15,4 +16,4 @@ void InitOSRPluginTest();
|
||||
// Run the test.
|
||||
void RunOSRPluginTest(CefRefPtr<CefBrowser> browser, bool transparent);
|
||||
|
||||
#endif // _CEFCLIENT_OSRPLUGIN_TEST_H
|
||||
#endif // CEF_TESTS_CEFCLIENT_OSRPLUGIN_TEST_H_
|
||||
|
@@ -6,10 +6,9 @@
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "include/cef_nplugin.h"
|
||||
#include "clientplugin.h"
|
||||
#include "cefclient/clientplugin.h"
|
||||
|
||||
void InitPluginTest()
|
||||
{
|
||||
void InitPluginTest() {
|
||||
// Structure providing information about the client plugin.
|
||||
CefPluginInfo plugin_info;
|
||||
CefString(&plugin_info.display_name).FromASCII("Client Plugin");
|
||||
@@ -26,8 +25,7 @@ void InitPluginTest()
|
||||
CefRegisterPlugin(plugin_info);
|
||||
}
|
||||
|
||||
void RunPluginTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunPluginTest(CefRefPtr<CefBrowser> browser) {
|
||||
// Page content is provided in ClientHandler::OnBeforeResourceLoad().
|
||||
browser->GetMainFrame()->LoadURL("http://tests/plugin");
|
||||
}
|
||||
|
@@ -2,8 +2,9 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _CEFCLIENT_PLUGIN_TEST_H
|
||||
#define _CEFCLIENT_PLUGIN_TEST_H
|
||||
#ifndef CEF_TESTS_CEFCLIENT_PLUGIN_TEST_H_
|
||||
#define CEF_TESTS_CEFCLIENT_PLUGIN_TEST_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_base.h"
|
||||
|
||||
@@ -15,4 +16,4 @@ void InitPluginTest();
|
||||
// Run the test.
|
||||
void RunPluginTest(CefRefPtr<CefBrowser> browser);
|
||||
|
||||
#endif // _CEFCLIENT_PLUGIN_TEST_H
|
||||
#endif // CEF_TESTS_CEFCLIENT_PLUGIN_TEST_H_
|
||||
|
@@ -2,8 +2,9 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _CEFCLIENT_RESOURCE_UTIL
|
||||
#define _CEFCLIENT_RESOURCE_UTIL
|
||||
#ifndef CEF_TESTS_CEFCLIENT_RESOURCE_UTIL_H_
|
||||
#define CEF_TESTS_CEFCLIENT_RESOURCE_UTIL_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_base.h"
|
||||
|
||||
@@ -11,13 +12,15 @@ class CefStreamReader;
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
||||
#include "resource.h"
|
||||
#include "cefclient/resource.h"
|
||||
|
||||
// Load a resource of type BINARY
|
||||
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes);
|
||||
CefRefPtr<CefStreamReader> GetBinaryResourceReader(int binaryId);
|
||||
|
||||
#elif (defined(OS_MACOSX) || defined(OS_POSIX))
|
||||
#elif defined(OS_MACOSX) || defined(OS_POSIX)
|
||||
|
||||
#include <string> // NOLINT(build/include_order)
|
||||
|
||||
// Load the resource with the specified name.
|
||||
bool LoadBinaryResource(const char* resource_name, std::string& resource_data);
|
||||
@@ -25,4 +28,4 @@ CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name);
|
||||
|
||||
#endif
|
||||
|
||||
#endif // _CEFCLIENT_RESOURCE_UTIL
|
||||
#endif // CEF_TESTS_CEFCLIENT_RESOURCE_UTIL_H_
|
||||
|
@@ -3,18 +3,17 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "resource_util.h"
|
||||
#include "include/cef_stream.h"
|
||||
#include "util.h"
|
||||
#include "cefclient/resource_util.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "base/file_util.h"
|
||||
#include <string>
|
||||
#include "include/cef_stream.h"
|
||||
#include "cefclient/util.h"
|
||||
|
||||
bool GetResourceDir(std::string& dir) {
|
||||
char buff[1024];
|
||||
|
||||
// Retrieve the executable path.
|
||||
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
|
||||
ssize_t len = readlink("/proc/self/exe", buff, sizeof(buff)-1);
|
||||
if (len == -1)
|
||||
return false;
|
||||
|
||||
@@ -26,7 +25,7 @@ bool GetResourceDir(std::string& dir) {
|
||||
return false;
|
||||
|
||||
// Add "files" to the path.
|
||||
strcpy(pos+1, "files");
|
||||
strcpy(pos+1, "files"); // NOLINT(runtime/printf)
|
||||
dir = std::string(buff);
|
||||
return true;
|
||||
}
|
||||
@@ -50,7 +49,7 @@ bool LoadBinaryResource(const char* resource_name, std::string& resource_data) {
|
||||
bytes_read = fread(buff, 1, sizeof(buff)-1, f);
|
||||
if (bytes_read > 0)
|
||||
resource_data.append(buff, bytes_read);
|
||||
} while(bytes_read > 0);
|
||||
} while (bytes_read > 0);
|
||||
|
||||
fclose(f);
|
||||
return true;
|
||||
@@ -58,7 +57,7 @@ bool LoadBinaryResource(const char* resource_name, std::string& resource_data) {
|
||||
|
||||
CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name) {
|
||||
std::string path;
|
||||
if (!GetResourceDir(path))
|
||||
if (!GetResourceDir(path))
|
||||
return NULL;
|
||||
|
||||
path.append("/");
|
||||
|
@@ -3,13 +3,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "resource_util.h"
|
||||
#include "include/cef_stream.h"
|
||||
#include "util.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#include <mach-o/dyld.h>
|
||||
#include <stdio.h>
|
||||
#include "cefclient/resource_util.h"
|
||||
#include "include/cef_stream.h"
|
||||
#include "cefclient/util.h"
|
||||
|
||||
namespace {
|
||||
|
||||
|
@@ -2,38 +2,34 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "resource_util.h"
|
||||
#include "cefclient/resource_util.h"
|
||||
#include "include/cef_stream.h"
|
||||
#include "include/wrapper/cef_byte_read_handler.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
||||
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes)
|
||||
{
|
||||
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes) {
|
||||
extern HINSTANCE hInst;
|
||||
HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(binaryId),
|
||||
HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(binaryId),
|
||||
MAKEINTRESOURCE(256));
|
||||
if(hRes)
|
||||
{
|
||||
HGLOBAL hGlob = LoadResource(hInst, hRes);
|
||||
if(hGlob)
|
||||
{
|
||||
dwSize = SizeofResource(hInst, hRes);
|
||||
pBytes = (LPBYTE)LockResource(hGlob);
|
||||
if(dwSize > 0 && pBytes)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (hRes) {
|
||||
HGLOBAL hGlob = LoadResource(hInst, hRes);
|
||||
if (hGlob) {
|
||||
dwSize = SizeofResource(hInst, hRes);
|
||||
pBytes = (LPBYTE)LockResource(hGlob);
|
||||
if (dwSize > 0 && pBytes)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
CefRefPtr<CefStreamReader> GetBinaryResourceReader(int binaryId)
|
||||
{
|
||||
CefRefPtr<CefStreamReader> GetBinaryResourceReader(int binaryId) {
|
||||
DWORD dwSize;
|
||||
LPBYTE pBytes;
|
||||
|
||||
if(LoadBinaryResource(binaryId, dwSize, pBytes)) {
|
||||
if (LoadBinaryResource(binaryId, dwSize, pBytes)) {
|
||||
return CefStreamReader::CreateForHandler(
|
||||
new CefByteReadHandler(pBytes, dwSize, NULL));
|
||||
}
|
||||
@@ -41,4 +37,4 @@ CefRefPtr<CefStreamReader> GetBinaryResourceReader(int binaryId)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif // OS_WIN
|
||||
#endif // OS_WIN
|
||||
|
@@ -2,46 +2,46 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "scheme_test.h"
|
||||
#include "cefclient/scheme_test.h"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "include/cef_response.h"
|
||||
#include "include/cef_request.h"
|
||||
#include "include/cef_scheme.h"
|
||||
#include "resource_util.h"
|
||||
#include "string_util.h"
|
||||
#include "util.h"
|
||||
#include "cefclient/resource_util.h"
|
||||
#include "cefclient/string_util.h"
|
||||
#include "cefclient/util.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "resource.h"
|
||||
#include "cefclient/resource.h"
|
||||
#endif
|
||||
|
||||
|
||||
// Implementation of the schema handler for client:// requests.
|
||||
class ClientSchemeHandler : public CefSchemeHandler
|
||||
{
|
||||
public:
|
||||
class ClientSchemeHandler : public CefSchemeHandler {
|
||||
public:
|
||||
ClientSchemeHandler() : offset_(0) {}
|
||||
|
||||
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefSchemeHandlerCallback> callback)
|
||||
OVERRIDE
|
||||
{
|
||||
OVERRIDE {
|
||||
REQUIRE_IO_THREAD();
|
||||
|
||||
bool handled = false;
|
||||
|
||||
AutoLock lock_scope(this);
|
||||
|
||||
|
||||
std::string url = request->GetURL();
|
||||
if(strstr(url.c_str(), "handler.html") != NULL) {
|
||||
if (strstr(url.c_str(), "handler.html") != NULL) {
|
||||
// Build the response html
|
||||
data_ = "<html><head><title>Client Scheme Handler</title></head><body>"
|
||||
"This contents of this page page are served by the "
|
||||
"ClientSchemeHandler class handling the client:// protocol."
|
||||
"<br/>You should see an image:"
|
||||
"<br/><img src=\"client://tests/client.png\"><pre>";
|
||||
|
||||
|
||||
// Output a string representation of the request
|
||||
std::string dump;
|
||||
DumpRequestContents(request, dump);
|
||||
@@ -58,20 +58,19 @@ public:
|
||||
|
||||
// Set the resulting mime type
|
||||
mime_type_ = "text/html";
|
||||
}
|
||||
else if(strstr(url.c_str(), "client.png") != NULL) {
|
||||
} else if (strstr(url.c_str(), "client.png") != NULL) {
|
||||
// Load the response image
|
||||
#if defined(OS_WIN)
|
||||
DWORD dwSize;
|
||||
LPBYTE pBytes;
|
||||
if(LoadBinaryResource(IDS_LOGO, dwSize, pBytes)) {
|
||||
if (LoadBinaryResource(IDS_LOGO, dwSize, pBytes)) {
|
||||
data_ = std::string(reinterpret_cast<const char*>(pBytes), dwSize);
|
||||
handled = true;
|
||||
// Set the resulting mime type
|
||||
mime_type_ = "image/jpg";
|
||||
}
|
||||
#elif (defined(OS_MACOSX) || defined(OS_LINUX))
|
||||
if(LoadBinaryResource("logo.png", data_)) {
|
||||
#elif defined(OS_MACOSX) || defined(OS_LINUX)
|
||||
if (LoadBinaryResource("logo.png", data_)) {
|
||||
handled = true;
|
||||
// Set the resulting mime type
|
||||
mime_type_ = "image/png";
|
||||
@@ -92,8 +91,7 @@ public:
|
||||
|
||||
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
||||
int64& response_length,
|
||||
CefString& redirectUrl) OVERRIDE
|
||||
{
|
||||
CefString& redirectUrl) OVERRIDE {
|
||||
REQUIRE_IO_THREAD();
|
||||
|
||||
ASSERT(!data_.empty());
|
||||
@@ -105,8 +103,7 @@ public:
|
||||
response_length = data_.length();
|
||||
}
|
||||
|
||||
virtual void Cancel() OVERRIDE
|
||||
{
|
||||
virtual void Cancel() OVERRIDE {
|
||||
REQUIRE_IO_THREAD();
|
||||
}
|
||||
|
||||
@@ -114,8 +111,7 @@ public:
|
||||
int bytes_to_read,
|
||||
int& bytes_read,
|
||||
CefRefPtr<CefSchemeHandlerCallback> callback)
|
||||
OVERRIDE
|
||||
{
|
||||
OVERRIDE {
|
||||
REQUIRE_IO_THREAD();
|
||||
|
||||
bool has_data = false;
|
||||
@@ -123,7 +119,7 @@ public:
|
||||
|
||||
AutoLock lock_scope(this);
|
||||
|
||||
if(offset_ < data_.length()) {
|
||||
if (offset_ < data_.length()) {
|
||||
// Copy the next block of data into the buffer.
|
||||
int transfer_size =
|
||||
std::min(bytes_to_read, static_cast<int>(data_.length() - offset_));
|
||||
@@ -137,7 +133,7 @@ public:
|
||||
return has_data;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string data_;
|
||||
std::string mime_type_;
|
||||
size_t offset_;
|
||||
@@ -147,15 +143,13 @@ private:
|
||||
};
|
||||
|
||||
// Implementation of the factory for for creating schema handlers.
|
||||
class ClientSchemeHandlerFactory : public CefSchemeHandlerFactory
|
||||
{
|
||||
public:
|
||||
class ClientSchemeHandlerFactory : public CefSchemeHandlerFactory {
|
||||
public:
|
||||
// Return a new scheme handler instance to handle the request.
|
||||
virtual CefRefPtr<CefSchemeHandler> Create(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& scheme_name,
|
||||
CefRefPtr<CefRequest> request)
|
||||
OVERRIDE
|
||||
{
|
||||
OVERRIDE {
|
||||
REQUIRE_IO_THREAD();
|
||||
return new ClientSchemeHandler();
|
||||
}
|
||||
@@ -163,14 +157,12 @@ public:
|
||||
IMPLEMENT_REFCOUNTING(ClientSchemeHandlerFactory);
|
||||
};
|
||||
|
||||
void InitSchemeTest()
|
||||
{
|
||||
void InitSchemeTest() {
|
||||
CefRegisterCustomScheme("client", true, false, false);
|
||||
CefRegisterSchemeHandlerFactory("client", "tests",
|
||||
new ClientSchemeHandlerFactory());
|
||||
}
|
||||
|
||||
void RunSchemeTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunSchemeTest(CefRefPtr<CefBrowser> browser) {
|
||||
browser->GetMainFrame()->LoadURL("client://tests/handler.html");
|
||||
}
|
||||
|
@@ -2,8 +2,9 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _CEFCLIENT_SCHEME_TEST
|
||||
#define _CEFCLIENT_SCHEME_TEST
|
||||
#ifndef CEF_TESTS_CEFCLIENT_SCHEME_TEST_H_
|
||||
#define CEF_TESTS_CEFCLIENT_SCHEME_TEST_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_base.h"
|
||||
|
||||
@@ -15,4 +16,4 @@ void InitSchemeTest();
|
||||
// Run the test.
|
||||
void RunSchemeTest(CefRefPtr<CefBrowser> browser);
|
||||
|
||||
#endif // _CEFCLIENT_SCHEME_TEST
|
||||
#endif // CEF_TESTS_CEFCLIENT_SCHEME_TEST_H_
|
||||
|
@@ -2,12 +2,12 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "string_util.h"
|
||||
#include "include/cef_request.h"
|
||||
#include "cefclient/string_util.h"
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "include/cef_request.h"
|
||||
|
||||
void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str)
|
||||
{
|
||||
void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str) {
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "URL: " << std::string(request->GetURL());
|
||||
@@ -15,31 +15,31 @@ void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str)
|
||||
|
||||
CefRequest::HeaderMap headerMap;
|
||||
request->GetHeaderMap(headerMap);
|
||||
if(headerMap.size() > 0) {
|
||||
if (headerMap.size() > 0) {
|
||||
ss << "\nHeaders:";
|
||||
CefRequest::HeaderMap::const_iterator it = headerMap.begin();
|
||||
for(; it != headerMap.end(); ++it) {
|
||||
for (; it != headerMap.end(); ++it) {
|
||||
ss << "\n\t" << std::string((*it).first) << ": " <<
|
||||
std::string((*it).second);
|
||||
}
|
||||
}
|
||||
|
||||
CefRefPtr<CefPostData> postData = request->GetPostData();
|
||||
if(postData.get()) {
|
||||
if (postData.get()) {
|
||||
CefPostData::ElementVector elements;
|
||||
postData->GetElements(elements);
|
||||
if(elements.size() > 0) {
|
||||
if (elements.size() > 0) {
|
||||
ss << "\nPost Data:";
|
||||
CefRefPtr<CefPostDataElement> element;
|
||||
CefPostData::ElementVector::const_iterator it = elements.begin();
|
||||
for(; it != elements.end(); ++it) {
|
||||
for (; it != elements.end(); ++it) {
|
||||
element = (*it);
|
||||
if(element->GetType() == PDE_TYPE_BYTES) {
|
||||
if (element->GetType() == PDE_TYPE_BYTES) {
|
||||
// the element is composed of bytes
|
||||
ss << "\n\tBytes: ";
|
||||
if(element->GetBytesCount() == 0)
|
||||
if (element->GetBytesCount() == 0) {
|
||||
ss << "(empty)";
|
||||
else {
|
||||
} else {
|
||||
// retrieve the data.
|
||||
size_t size = element->GetBytesCount();
|
||||
char* bytes = new char[size];
|
||||
@@ -47,7 +47,7 @@ void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str)
|
||||
ss << std::string(bytes, size);
|
||||
delete [] bytes;
|
||||
}
|
||||
} else if(element->GetType() == PDE_TYPE_FILE) {
|
||||
} else if (element->GetType() == PDE_TYPE_FILE) {
|
||||
ss << "\n\tFile: " << std::string(element->GetFile());
|
||||
}
|
||||
}
|
||||
@@ -58,18 +58,17 @@ void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str)
|
||||
}
|
||||
|
||||
std::string StringReplace(const std::string& str, const std::string& from,
|
||||
const std::string& to)
|
||||
{
|
||||
const std::string& to) {
|
||||
std::string result = str;
|
||||
std::string::size_type pos = 0;
|
||||
std::string::size_type from_len = from.length();
|
||||
std::string::size_type to_len = to.length();
|
||||
do {
|
||||
pos = result.find(from, pos);
|
||||
if(pos != std::string::npos) {
|
||||
if (pos != std::string::npos) {
|
||||
result.replace(pos, from_len, to);
|
||||
pos += to_len;
|
||||
}
|
||||
} while(pos != std::string::npos);
|
||||
} while (pos != std::string::npos);
|
||||
return result;
|
||||
}
|
||||
|
@@ -2,9 +2,11 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _CEFCLIENT_STRING_UTIL_H
|
||||
#define _CEFCLIENT_STRING_UTIL_H
|
||||
#ifndef CEF_TESTS_CEFCLIENT_STRING_UTIL_H_
|
||||
#define CEF_TESTS_CEFCLIENT_STRING_UTIL_H_
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "include/cef_base.h"
|
||||
|
||||
class CefRequest;
|
||||
@@ -16,4 +18,4 @@ void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str);
|
||||
std::string StringReplace(const std::string& str, const std::string& from,
|
||||
const std::string& to);
|
||||
|
||||
#endif // _CEFCLIENT_STRING_UTIL_H
|
||||
#endif // CEF_TESTS_CEFCLIENT_STRING_UTIL_H_
|
||||
|
@@ -3,15 +3,17 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "uiplugin.h"
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "cefclient.h"
|
||||
#include <gl/gl.h>
|
||||
#include <sstream>
|
||||
#include "cefclient/uiplugin.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
||||
#include <windows.h>
|
||||
#include <gl/gl.h>
|
||||
#include <sstream>
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "cefclient/cefclient.h"
|
||||
|
||||
// Initialized in NP_Initialize.
|
||||
NPNetscapeFuncs* g_uibrowser = NULL;
|
||||
|
||||
@@ -22,11 +24,9 @@ float g_rotationspeed = 0.0f;
|
||||
float g_theta = 0.0f;
|
||||
|
||||
// Class holding pointers for the client plugin window.
|
||||
class ClientPlugin
|
||||
{
|
||||
public:
|
||||
ClientPlugin()
|
||||
{
|
||||
class ClientPlugin {
|
||||
public:
|
||||
ClientPlugin() {
|
||||
hWnd = NULL;
|
||||
hDC = NULL;
|
||||
hRC = NULL;
|
||||
@@ -49,17 +49,17 @@ NPError NPP_NewImpl(NPMIMEType plugin_type, NPP instance, uint16 mode,
|
||||
if (instance == NULL)
|
||||
return NPERR_INVALID_INSTANCE_ERROR;
|
||||
|
||||
ClientPlugin *plugin = new ClientPlugin;
|
||||
ClientPlugin* plugin = new ClientPlugin;
|
||||
instance->pdata = reinterpret_cast<void*>(plugin);
|
||||
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError NPP_DestroyImpl(NPP instance, NPSavedData** save) {
|
||||
ClientPlugin *plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
|
||||
ClientPlugin* plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
|
||||
if (plugin) {
|
||||
if(plugin->hWnd) {
|
||||
if (plugin->hWnd) {
|
||||
DestroyWindow(plugin->hWnd);
|
||||
DisableOpenGL(plugin->hWnd, plugin->hDC, plugin->hRC);
|
||||
}
|
||||
@@ -78,14 +78,13 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
|
||||
if (window_info == NULL)
|
||||
return NPERR_GENERIC_ERROR;
|
||||
|
||||
ClientPlugin *plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
ClientPlugin* plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
HWND parent_hwnd = reinterpret_cast<HWND>(window_info->window);
|
||||
|
||||
if (plugin->hWnd == NULL)
|
||||
{
|
||||
|
||||
if (plugin->hWnd == NULL) {
|
||||
WNDCLASS wc;
|
||||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||||
|
||||
|
||||
// Register the window class.
|
||||
wc.style = CS_OWNDC;
|
||||
wc.lpfnWndProc = PluginWndProc;
|
||||
@@ -124,8 +123,7 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
|
||||
}
|
||||
|
||||
// Send the notification to the browser as a JavaScript function call.
|
||||
static void NotifyNewRotation(float value)
|
||||
{
|
||||
static void NotifyNewRotation(float value) {
|
||||
std::stringstream buf;
|
||||
buf << "notifyNewRotation(" << value << ");";
|
||||
AppGetBrowser()->GetMainFrame()->ExecuteJavaScript(buf.str(), CefString(),
|
||||
@@ -135,42 +133,40 @@ static void NotifyNewRotation(float value)
|
||||
// Nice little fly polygon borrowed from the OpenGL Red Book.
|
||||
const GLubyte fly[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x03, 0x80, 0x01, 0xC0, 0x06, 0xC0, 0x03, 0x60,
|
||||
0x04, 0x60, 0x06, 0x20, 0x04, 0x30, 0x0C, 0x20,
|
||||
0x03, 0x80, 0x01, 0xC0, 0x06, 0xC0, 0x03, 0x60,
|
||||
0x04, 0x60, 0x06, 0x20, 0x04, 0x30, 0x0C, 0x20,
|
||||
0x04, 0x18, 0x18, 0x20, 0x04, 0x0C, 0x30, 0x20,
|
||||
0x04, 0x06, 0x60, 0x20, 0x44, 0x03, 0xC0, 0x22,
|
||||
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
|
||||
0x04, 0x06, 0x60, 0x20, 0x44, 0x03, 0xC0, 0x22,
|
||||
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
|
||||
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
|
||||
0x66, 0x01, 0x80, 0x66, 0x33, 0x01, 0x80, 0xCC,
|
||||
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
|
||||
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
|
||||
0x66, 0x01, 0x80, 0x66, 0x33, 0x01, 0x80, 0xCC,
|
||||
0x19, 0x81, 0x81, 0x98, 0x0C, 0xC1, 0x83, 0x30,
|
||||
0x07, 0xe1, 0x87, 0xe0, 0x03, 0x3f, 0xfc, 0xc0,
|
||||
0x03, 0x31, 0x8c, 0xc0, 0x03, 0x33, 0xcc, 0xc0,
|
||||
0x07, 0xe1, 0x87, 0xe0, 0x03, 0x3f, 0xfc, 0xc0,
|
||||
0x03, 0x31, 0x8c, 0xc0, 0x03, 0x33, 0xcc, 0xc0,
|
||||
0x06, 0x64, 0x26, 0x60, 0x0c, 0xcc, 0x33, 0x30,
|
||||
0x18, 0xcc, 0x33, 0x18, 0x10, 0xc4, 0x23, 0x08,
|
||||
0x10, 0x63, 0xC6, 0x08, 0x10, 0x30, 0x0c, 0x08,
|
||||
0x18, 0xcc, 0x33, 0x18, 0x10, 0xc4, 0x23, 0x08,
|
||||
0x10, 0x63, 0xC6, 0x08, 0x10, 0x30, 0x0c, 0x08,
|
||||
0x10, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00, 0x08};
|
||||
|
||||
|
||||
// Plugin window procedure.
|
||||
LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
LPARAM lParam) {
|
||||
ClientPlugin* plugin =
|
||||
reinterpret_cast<ClientPlugin*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
|
||||
|
||||
switch(message)
|
||||
{
|
||||
switch (message) {
|
||||
case WM_CREATE:
|
||||
// Start the timer that's used for redrawing.
|
||||
SetTimer(hWnd, 1, 1, NULL);
|
||||
return 0;
|
||||
|
||||
|
||||
case WM_DESTROY:
|
||||
// Stop the timer that's used for redrawing.
|
||||
KillTimer(hWnd, 1);
|
||||
return 0;
|
||||
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
// Decrement rotation speed.
|
||||
ModifyRotation(-2.0f);
|
||||
@@ -201,24 +197,28 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
// Adjust the theta value and redraw the display when the timer fires.
|
||||
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
||||
glPushMatrix();
|
||||
glEnable(GL_POLYGON_STIPPLE);
|
||||
glPolygonStipple(fly);
|
||||
|
||||
glRotatef(g_theta, 0.0f, 0.0f, 1.0f);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(1.0f, 0.0f, 0.0f); glVertex2f(0.7f, 0.7f);
|
||||
glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(0.7f, -0.7f);
|
||||
glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(-0.7f, -0.7f);
|
||||
glColor3f(1.0f, 0.0f, 1.0f); glVertex2f(-0.7f, 0.7f);
|
||||
glColor3f(1.0f, 0.0f, 0.0f);
|
||||
glVertex2f(0.7f, 0.7f);
|
||||
glColor3f(0.0f, 1.0f, 0.0f);
|
||||
glVertex2f(0.7f, -0.7f);
|
||||
glColor3f(0.0f, 0.0f, 1.0f);
|
||||
glVertex2f(-0.7f, -0.7f);
|
||||
glColor3f(1.0f, 0.0f, 1.0f);
|
||||
glVertex2f(-0.7f, 0.7f);
|
||||
glEnd();
|
||||
|
||||
glDisable(GL_POLYGON_STIPPLE);
|
||||
glPopMatrix();
|
||||
|
||||
|
||||
SwapBuffers(plugin->hDC);
|
||||
|
||||
|
||||
g_theta -= g_rotationspeed;
|
||||
}
|
||||
|
||||
@@ -226,14 +226,13 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
}
|
||||
|
||||
// Enable OpenGL.
|
||||
void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
|
||||
{
|
||||
void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC) {
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
int format;
|
||||
|
||||
|
||||
// Get the device context.
|
||||
*hDC = GetDC(hWnd);
|
||||
|
||||
|
||||
// Set the pixel format for the DC.
|
||||
ZeroMemory(&pfd, sizeof(pfd));
|
||||
pfd.nSize = sizeof(pfd);
|
||||
@@ -245,51 +244,45 @@ void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
format = ChoosePixelFormat(*hDC, &pfd);
|
||||
SetPixelFormat(*hDC, format, &pfd);
|
||||
|
||||
|
||||
// Create and enable the render contex.
|
||||
*hRC = wglCreateContext(*hDC);
|
||||
}
|
||||
|
||||
// Disable OpenGL.
|
||||
void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC)
|
||||
{
|
||||
void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC) {
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
wglDeleteContext(hRC);
|
||||
ReleaseDC(hWnd, hDC);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
NPError API_CALL NP_UIGetEntryPoints(NPPluginFuncs* pFuncs)
|
||||
{
|
||||
NPError API_CALL NP_UIGetEntryPoints(NPPluginFuncs* pFuncs) {
|
||||
pFuncs->newp = NPP_NewImpl;
|
||||
pFuncs->destroy = NPP_DestroyImpl;
|
||||
pFuncs->setwindow = NPP_SetWindowImpl;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError API_CALL NP_UIInitialize(NPNetscapeFuncs* pFuncs)
|
||||
{
|
||||
NPError API_CALL NP_UIInitialize(NPNetscapeFuncs* pFuncs) {
|
||||
g_uibrowser = pFuncs;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError API_CALL NP_UIShutdown(void)
|
||||
{
|
||||
NPError API_CALL NP_UIShutdown(void) {
|
||||
g_uibrowser = NULL;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
void ModifyRotation(float value)
|
||||
{
|
||||
void ModifyRotation(float value) {
|
||||
g_rotationspeed += value;
|
||||
NotifyNewRotation(g_rotationspeed);
|
||||
}
|
||||
|
||||
void ResetRotation()
|
||||
{
|
||||
void ResetRotation() {
|
||||
g_rotationspeed = 0.0;
|
||||
NotifyNewRotation(g_rotationspeed);
|
||||
}
|
||||
|
||||
#endif // OS_WIN
|
||||
#endif // OS_WIN
|
||||
|
@@ -6,8 +6,9 @@
|
||||
// Portions of this implementation are borrowed from webkit\default_plugin\
|
||||
// plugin_impl.h
|
||||
|
||||
#ifndef _CEFCLIENT_UIPLUGIN_H
|
||||
#define _CEFCLIENT_UIPLUGIN_H
|
||||
#ifndef CEF_TESTS_CEFCLIENT_UIPLUGIN_H_
|
||||
#define CEF_TESTS_CEFCLIENT_UIPLUGIN_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_nplugin.h"
|
||||
|
||||
@@ -24,6 +25,6 @@ void ModifyRotation(float value);
|
||||
// Function called to reset the rotation value.
|
||||
void ResetRotation();
|
||||
|
||||
#endif // OS_WIN
|
||||
#endif // OS_WIN
|
||||
|
||||
#endif // _CEFCLIENT_UIPLUGIN_H
|
||||
#endif // CEF_TESTS_CEFCLIENT_UIPLUGIN_H_
|
||||
|
@@ -2,18 +2,18 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "uiplugin_test.h"
|
||||
#include "cefclient/uiplugin_test.h"
|
||||
#include <string>
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "include/cef_v8.h"
|
||||
#include "uiplugin.h"
|
||||
#include "cefclient.h"
|
||||
#include "cefclient/uiplugin.h"
|
||||
#include "cefclient/cefclient.h"
|
||||
|
||||
|
||||
// Implementation of the V8 handler class for the "window.uiapp" functions.
|
||||
class ClientV8UIHandler : public CefV8Handler
|
||||
{
|
||||
public:
|
||||
class ClientV8UIHandler : public CefV8Handler {
|
||||
public:
|
||||
ClientV8UIHandler() {}
|
||||
|
||||
// Execute with the specified argument list and return value. Return true if
|
||||
@@ -22,32 +22,31 @@ public:
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception)
|
||||
{
|
||||
if(name == "modifyRotation") {
|
||||
CefString& exception) {
|
||||
if (name == "modifyRotation") {
|
||||
// This function requires one argument.
|
||||
if(arguments.size() != 1)
|
||||
if (arguments.size() != 1)
|
||||
return false;
|
||||
|
||||
float increment = 0.;
|
||||
if(arguments[0]->IsInt()) {
|
||||
if (arguments[0]->IsInt()) {
|
||||
// The argument is an integer value.
|
||||
increment = static_cast<float>(arguments[0]->GetIntValue());
|
||||
} else if(arguments[0]->IsDouble()) {
|
||||
} else if (arguments[0]->IsDouble()) {
|
||||
// The argument is an double value.
|
||||
increment = static_cast<float>(arguments[0]->GetDoubleValue());
|
||||
}
|
||||
|
||||
if(increment != 0.) {
|
||||
if (increment != 0.) {
|
||||
// Modify the rotation accordingly.
|
||||
ModifyRotation(increment);
|
||||
return true;
|
||||
}
|
||||
} else if(name == "resetRotation") {
|
||||
} else if (name == "resetRotation") {
|
||||
// Reset the rotation value.
|
||||
ResetRotation();
|
||||
return true;
|
||||
} else if(name == "viewSource") {
|
||||
} else if (name == "viewSource") {
|
||||
// View the page source.
|
||||
AppGetBrowser()->GetMainFrame()->ViewSource();
|
||||
return true;
|
||||
@@ -59,8 +58,7 @@ public:
|
||||
IMPLEMENT_REFCOUNTING(ClientV8UIHandler);
|
||||
};
|
||||
|
||||
void InitUIPluginTest()
|
||||
{
|
||||
void InitUIPluginTest() {
|
||||
// Structure providing information about the client plugin.
|
||||
CefPluginInfo plugin_info;
|
||||
CefString(&plugin_info.display_name).FromASCII("Client UI Plugin");
|
||||
@@ -100,7 +98,6 @@ void InitUIPluginTest()
|
||||
CefRegisterExtension("uiplugin/test", code, new ClientV8UIHandler());
|
||||
}
|
||||
|
||||
void RunUIPluginTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
void RunUIPluginTest(CefRefPtr<CefBrowser> browser) {
|
||||
browser->GetMainFrame()->LoadURL("http://tests/uiapp");
|
||||
}
|
||||
|
@@ -2,8 +2,9 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _CEFCLIENT_UIPLUGIN_TEST_H
|
||||
#define _CEFCLIENT_UIPLUGIN_TEST_H
|
||||
#ifndef CEF_TESTS_CEFCLIENT_UIPLUGIN_TEST_H_
|
||||
#define CEF_TESTS_CEFCLIENT_UIPLUGIN_TEST_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_base.h"
|
||||
|
||||
@@ -15,4 +16,4 @@ void InitUIPluginTest();
|
||||
// Run the test.
|
||||
void RunUIPluginTest(CefRefPtr<CefBrowser> browser);
|
||||
|
||||
#endif // _CEFCLIENT_UIPLUGIN_TEST_H
|
||||
#endif // CEF_TESTS_CEFCLIENT_UIPLUGIN_TEST_H_
|
||||
|
@@ -2,35 +2,36 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _CEFCLIENT_UTIL_H
|
||||
#define _CEFCLIENT_UTIL_H
|
||||
#ifndef CEF_TESTS_CEFCLIENT_UTIL_H_
|
||||
#define CEF_TESTS_CEFCLIENT_UTIL_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_task.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
||||
#include <windows.h>
|
||||
#include <windows.h> // NOLINT(build/include_order)
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define ASSERT(condition) if(!(condition)) { DebugBreak(); }
|
||||
#define ASSERT(condition) if (!(condition)) { DebugBreak(); }
|
||||
#else
|
||||
#define ASSERT(condition) ((void)0)
|
||||
#endif
|
||||
|
||||
#else // !OS_WIN
|
||||
#else // !OS_WIN
|
||||
|
||||
#include <assert.h>
|
||||
#include <assert.h> // NOLINT(build/include_order)
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define ASSERT(condition) if(!(condition)) { assert(false); }
|
||||
#define ASSERT(condition) if (!(condition)) { assert(false); }
|
||||
#else
|
||||
#define ASSERT(condition) ((void)0)
|
||||
#endif
|
||||
|
||||
#endif // !OS_WIN
|
||||
#endif // !OS_WIN
|
||||
|
||||
#define REQUIRE_UI_THREAD() ASSERT(CefCurrentlyOn(TID_UI));
|
||||
#define REQUIRE_IO_THREAD() ASSERT(CefCurrentlyOn(TID_IO));
|
||||
#define REQUIRE_FILE_THREAD() ASSERT(CefCurrentlyOn(TID_FILE));
|
||||
|
||||
#endif // _CEFCLIENT_UTIL_H
|
||||
#endif // CEF_TESTS_CEFCLIENT_UTIL_H_
|
||||
|
Reference in New Issue
Block a user