2011-03-24 21:36:47 +01:00
|
|
|
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "osrplugin_test.h"
|
|
|
|
#include "osrplugin.h"
|
|
|
|
#include "cefclient.h"
|
2011-05-20 16:42:25 +02:00
|
|
|
#include "client_handler.h"
|
2011-03-24 21:36:47 +01:00
|
|
|
#include "plugin_test.h"
|
|
|
|
|
|
|
|
void InitOSRPluginTest()
|
|
|
|
{
|
|
|
|
// Structure providing information about the client plugin.
|
|
|
|
CefPluginInfo plugin_info;
|
|
|
|
CefString(&plugin_info.display_name).FromASCII("Client OSR Plugin");
|
|
|
|
CefString(&plugin_info.unique_name).FromASCII("client_osr_plugin");
|
|
|
|
CefString(&plugin_info.description).FromASCII("My Example Client OSR Plugin");
|
|
|
|
CefString(&plugin_info.mime_type).FromASCII(
|
|
|
|
"application/x-client-osr-plugin");
|
|
|
|
|
|
|
|
plugin_info.np_getentrypoints = NP_OSRGetEntryPoints;
|
|
|
|
plugin_info.np_initialize = NP_OSRInitialize;
|
|
|
|
plugin_info.np_shutdown = NP_OSRShutdown;
|
|
|
|
|
|
|
|
// Register the internal client plugin
|
|
|
|
CefRegisterPlugin(plugin_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunOSRPluginTest(CefRefPtr<CefBrowser> browser)
|
|
|
|
{
|
2011-05-20 16:42:25 +02:00
|
|
|
class Listener : public CefDOMEventListener
|
2011-03-24 21:36:47 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Listener() {}
|
|
|
|
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") {
|
|
|
|
browser->GoForward();
|
|
|
|
} else if(elementId == "stop") {
|
|
|
|
browser->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
|
|
|
|
// browser window.
|
|
|
|
CefRefPtr<CefDOMDocument> document = event->GetDocument();
|
|
|
|
ASSERT(document.get());
|
|
|
|
CefRefPtr<CefDOMNode> url = document->GetElementById("url");
|
|
|
|
ASSERT(url.get());
|
|
|
|
CefString value = url->GetValue();
|
|
|
|
if (!value.empty())
|
|
|
|
browser->GetMainFrame()->LoadURL(value);
|
|
|
|
} else if(elementId == "testWindowedPlugin") {
|
|
|
|
// Run the windowed plugin test.
|
|
|
|
RunPluginTest(browser);
|
|
|
|
} 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") {
|
|
|
|
// View the page source for the host browser window.
|
|
|
|
AppGetBrowser()->GetMainFrame()->ViewSource();
|
|
|
|
} else {
|
|
|
|
// Not reached.
|
|
|
|
ASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(Listener);
|
2011-03-24 21:36:47 +01:00
|
|
|
};
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
class Visitor : public CefDOMVisitor
|
2011-03-24 21:36:47 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Visitor() {}
|
|
|
|
|
|
|
|
void RegisterClickListener(CefRefPtr<CefDOMDocument> document,
|
|
|
|
CefRefPtr<CefDOMEventListener> listener,
|
|
|
|
const std::string& elementId)
|
|
|
|
{
|
|
|
|
CefRefPtr<CefDOMNode> element = document->GetElementById(elementId);
|
|
|
|
ASSERT(element.get());
|
|
|
|
element->AddEventListener("click", listener, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
RegisterClickListener(document, listener, "stop");
|
|
|
|
RegisterClickListener(document, listener, "reload");
|
|
|
|
RegisterClickListener(document, listener, "go");
|
|
|
|
RegisterClickListener(document, listener, "testWindowedPlugin");
|
|
|
|
RegisterClickListener(document, listener, "testWindowlessPlugin");
|
|
|
|
RegisterClickListener(document, listener, "viewSource");
|
|
|
|
}
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(Visitor);
|
2011-03-24 21:36:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Center the window on the screen.
|
|
|
|
int screenX = GetSystemMetrics(SM_CXFULLSCREEN);
|
|
|
|
int screenY = GetSystemMetrics(SM_CYFULLSCREEN);
|
|
|
|
int width = 1000, height = 760;
|
|
|
|
int x = (screenX - width) / 2;
|
|
|
|
int y = (screenY - height) / 2;
|
|
|
|
|
|
|
|
SetWindowPos(AppGetMainHwnd(), NULL, x, y, width, height,
|
|
|
|
SWP_NOZORDER | SWP_SHOWWINDOW);
|
|
|
|
|
|
|
|
// The DOM visitor will be called after the path is loaded.
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
|
|
|
static_cast<ClientHandler*>(client.get())->AddDOMVisitor(
|
2011-03-24 21:36:47 +01:00
|
|
|
"http://tests/osrapp", new Visitor());
|
|
|
|
|
|
|
|
browser->GetMainFrame()->LoadURL("http://tests/osrapp");
|
|
|
|
}
|