2010-10-03 23:04:50 +02:00
|
|
|
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "cefclient/uiplugin_test.h"
|
|
|
|
#include <string>
|
2011-12-23 18:36:30 +01:00
|
|
|
#include "include/cef_browser.h"
|
|
|
|
#include "include/cef_frame.h"
|
|
|
|
#include "include/cef_v8.h"
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "cefclient/uiplugin.h"
|
|
|
|
#include "cefclient/cefclient.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Implementation of the V8 handler class for the "window.uiapp" functions.
|
2012-01-10 00:46:23 +01:00
|
|
|
class ClientV8UIHandler : public CefV8Handler {
|
|
|
|
public:
|
2010-10-03 23:04:50 +02:00
|
|
|
ClientV8UIHandler() {}
|
|
|
|
|
|
|
|
// Execute with the specified argument list and return value. Return true if
|
|
|
|
// the method was handled.
|
2010-11-22 18:49:46 +01:00
|
|
|
virtual bool Execute(const CefString& name,
|
2010-10-03 23:04:50 +02:00
|
|
|
CefRefPtr<CefV8Value> object,
|
|
|
|
const CefV8ValueList& arguments,
|
|
|
|
CefRefPtr<CefV8Value>& retval,
|
2012-01-10 00:46:23 +01:00
|
|
|
CefString& exception) {
|
|
|
|
if (name == "modifyRotation") {
|
2010-10-03 23:04:50 +02:00
|
|
|
// This function requires one argument.
|
2012-01-10 00:46:23 +01:00
|
|
|
if (arguments.size() != 1)
|
2010-10-03 23:04:50 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
float increment = 0.;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (arguments[0]->IsInt()) {
|
2010-10-03 23:04:50 +02:00
|
|
|
// The argument is an integer value.
|
|
|
|
increment = static_cast<float>(arguments[0]->GetIntValue());
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (arguments[0]->IsDouble()) {
|
2010-10-03 23:04:50 +02:00
|
|
|
// The argument is an double value.
|
|
|
|
increment = static_cast<float>(arguments[0]->GetDoubleValue());
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (increment != 0.) {
|
2010-10-03 23:04:50 +02:00
|
|
|
// Modify the rotation accordingly.
|
|
|
|
ModifyRotation(increment);
|
|
|
|
return true;
|
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (name == "resetRotation") {
|
2010-10-03 23:04:50 +02:00
|
|
|
// Reset the rotation value.
|
|
|
|
ResetRotation();
|
|
|
|
return true;
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (name == "viewSource") {
|
2010-10-03 23:04:50 +02:00
|
|
|
// View the page source.
|
|
|
|
AppGetBrowser()->GetMainFrame()->ViewSource();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(ClientV8UIHandler);
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void InitUIPluginTest() {
|
2010-10-03 23:04:50 +02:00
|
|
|
// Structure providing information about the client plugin.
|
|
|
|
CefPluginInfo plugin_info;
|
2011-02-15 19:07:24 +01:00
|
|
|
CefString(&plugin_info.display_name).FromASCII("Client UI Plugin");
|
|
|
|
CefString(&plugin_info.unique_name).FromASCII("client_ui_plugin");
|
|
|
|
CefString(&plugin_info.description).FromASCII("My Example Client UI Plugin");
|
2011-11-01 17:04:57 +01:00
|
|
|
CefString(&plugin_info.mime_types).FromASCII(
|
|
|
|
"application/x-client-ui-plugin");
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
plugin_info.np_getentrypoints = NP_UIGetEntryPoints;
|
|
|
|
plugin_info.np_initialize = NP_UIInitialize;
|
|
|
|
plugin_info.np_shutdown = NP_UIShutdown;
|
|
|
|
|
|
|
|
// Register the internal client plugin
|
|
|
|
CefRegisterPlugin(plugin_info);
|
|
|
|
|
|
|
|
// Register a V8 extension with the below JavaScript code that calls native
|
|
|
|
// methods implemented in ClientV8UIHandler.
|
2010-11-22 18:49:46 +01:00
|
|
|
std::string code = "var cef;"
|
|
|
|
"if (!cef)"
|
|
|
|
" cef = {};"
|
|
|
|
"if (!cef.uiapp)"
|
|
|
|
" cef.uiapp = {};"
|
|
|
|
"(function() {"
|
|
|
|
" cef.uiapp.modifyRotation = function(val) {"
|
|
|
|
" native function modifyRotation();"
|
|
|
|
" return modifyRotation(val);"
|
|
|
|
" };"
|
|
|
|
" cef.uiapp.resetRotation = function() {"
|
|
|
|
" native function resetRotation();"
|
|
|
|
" return resetRotation();"
|
|
|
|
" };"
|
|
|
|
" cef.uiapp.viewSource = function() {"
|
|
|
|
" native function viewSource();"
|
|
|
|
" return viewSource();"
|
|
|
|
" };"
|
|
|
|
"})();";
|
|
|
|
CefRegisterExtension("uiplugin/test", code, new ClientV8UIHandler());
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void RunUIPluginTest(CefRefPtr<CefBrowser> browser) {
|
2010-11-22 18:49:46 +01:00
|
|
|
browser->GetMainFrame()->LoadURL("http://tests/uiapp");
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|