Beispiel #1
0
void InitExtensionTest()
{
  // Register a V8 extension with the below JavaScript code that calls native
  // methods implemented in ClientV8ExtensionHandler.
  std::string code = "var cef;"
    "if (!cef)"
    "  cef = {};"
    "if (!cef.test)"
    "  cef.test = {};"
    "(function() {"
    "  cef.test.__defineGetter__('test_param', function() {"
    "    native function GetTestParam();"
    "    return GetTestParam();"
    "  });"
    "  cef.test.__defineSetter__('test_param', function(b) {"
    "    native function SetTestParam();"
    "    if(b) SetTestParam(b);"
    "  });"
    "  cef.test.test_object = function() {"
    "    native function GetTestObject();"
    "    return GetTestObject();"
    "  };"
    "  cef.test.dummy = function() {"
    "    native function Dummy();"
    "    return Dummy();"
    "  };"
    "})();";
  CefRegisterExtension("v8/test", code, new ClientV8ExtensionHandler());
}
Beispiel #2
0
void ClientApp::OnWebKitInitialized() {
  // Register the client_app extension.
  std::string app_code =
    "var app;"
    "if (!app)"
    "  app = {};"
    "(function() {"
    "  app.sendMessage = function(name, arguments) {"
    "    native function sendMessage();"
    "    return sendMessage(name, arguments);"
    "  };"
    "  app.setMessageCallback = function(name, callback) {"
    "    native function setMessageCallback();"
    "    return setMessageCallback(name, callback);"
    "  };"
    "  app.removeMessageCallback = function(name) {"
    "    native function removeMessageCallback();"
    "    return removeMessageCallback(name);"
    "  };"
    "})();";
  CefRegisterExtension("v8/app", app_code,
      new ClientAppExtensionHandler(this));

  // Execute delegate callbacks.
  RenderDelegateSet::iterator it = render_delegates_.begin();
  for (; it != render_delegates_.end(); ++it)
    (*it)->OnWebKitInitialized(this);
}
Beispiel #3
0
// Inject webinos.js
// The file is loaded from the webinos\test\client folder if possible.
// If this fails, the current folder is used.
void ClientApp::InjectWebinos(CefRefPtr<CefFrame> frame)
{
  CefRefPtr<CefCommandLine> commandLine = AppGetCommandLine();

  // First try and load the platform-supplied webinos.js
  std::string pzpPath = AppGetWebinosWRTConfig(NULL,NULL);
  CefString wrtPath;

  // Make sure there is a trailing separator on the path.
  if (pzpPath.length() > 0) 
  {
    if (pzpPath.find_last_of('/') == pzpPath.length()-1 || pzpPath.find_last_of('\\') == pzpPath.length()-1)
      wrtPath = pzpPath + "wrt/webinos.js";
    else
      wrtPath = pzpPath + "/wrt/webinos.js";
  }

#if defined(OS_WIN)
  base::FilePath webinosJSPath(wrtPath.ToWString().c_str());
#else
  base::FilePath webinosJSPath(wrtPath);
#endif

  LOG(INFO) << "webinos.js path is " << wrtPath;

  int64 webinosJSCodeSize;
  bool gotJSFile = base::GetFileSize(webinosJSPath, &webinosJSCodeSize);
  if (gotJSFile)
  {
    char* webinosJSCode = new char[webinosJSCodeSize+1];
    base::ReadFile(webinosJSPath, webinosJSCode, webinosJSCodeSize);
    webinosJSCode[webinosJSCodeSize] = 0;

    if (frame == NULL)
    {
      // Register as a Cef extension.
      CefRegisterExtension("webinos", webinosJSCode, NULL);
    }
    else
    {
      // Run the code in the frame javascript context right now,
      // but only if the URL refers to the widget server.
      int widgetServerPort;
      AppGetWebinosWRTConfig(NULL,&widgetServerPort);

      char injectionCandidate[MAX_URL_LENGTH];
      sprintf(injectionCandidate,"http://localhost:%d",widgetServerPort);

      std::string url = frame->GetURL();
      if (url.substr(0,strlen(injectionCandidate)) == injectionCandidate)
        frame->ExecuteJavaScript(webinosJSCode, url, 0);
    }

    delete[] webinosJSCode;
  }
  else
  {
    	LOG(ERROR) << "Can't find webinos.js";
  }
}
void RenderProcessHandler::OnWebKitInitialized() {
    QFile extensionFile(":/cef/extension.js");
    const auto ok = extensionFile.open(QFile::ReadOnly | QFile::Text);
    if (ok) {
        const auto extensionCode = QString(extensionFile.readAll()).toStdString();
        CefRegisterExtension("cef/bridge", extensionCode, NULL);
    }
}
Beispiel #5
0
void ClientApp::OnWebKitInitialized()
{
    // generate the JavaScript code for the extension and register it
    Zephyros::GetNativeExtensions()->AddNativeExtensions(m_pAppExtensionHandler.get());
    Zephyros::GetNativeExtensions()->SetNativeExtensionsAdded();
    CefRegisterExtension("v8/app", m_pAppExtensionHandler->GetJavaScriptCode(), m_pAppExtensionHandler.get());

    for (CefRefPtr<RenderDelegate> delegate : m_renderDelegates)
        delegate->OnWebKitInitialized(this);
}
Beispiel #6
0
//////////////////////////////////////////////////////////////////////////
// CefRenderProcessHandler
void XClientApp::OnWebKitInitialized()
{
    CefString strJsCode;
    bool bResult = LoadStringResource(RT_HTML, L"app.js", strJsCode);

    if(bResult)
    {
        bResult = CefRegisterExtension(L"v8/app", strJsCode, new XAppExtentionHandler);
    }
}
Beispiel #7
0
void ClientApp::OnWebKitInitialized() {
  // Register the appshell extension.
  std::string extension_code = GetExtensionJSSource();

  CefRegisterExtension("appshell", extension_code,
      new AppShellExtensionHandler(this));

  // Execute delegate callbacks.
  RenderDelegateSet::iterator it = render_delegates_.begin();
  for (; it != render_delegates_.end(); ++it)
    (*it)->OnWebKitInitialized(this);
}
Beispiel #8
0
void ClientApp::OnWebKitInitialized()
{
    std::string app_code =
        "var app;"
        "if (!app)"
        "    app = {};"
        "(function() {"
        "    app.ChangeTextInJS = function(text) {"
        "        native function ChangeTextInJS();"
        "        return ChangeTextInJS(text);"
        "    };"
		"    app.NotifyCEF3App = function(text) {"
		"        native function NotifyCEF3App();"
		"        return NotifyCEF3App(text);"
		"    };"
        "})();;";

    CefRegisterExtension( "v8/app", app_code, new ClientV8ExtensionHandler(this) );
}
Beispiel #9
0
void ClientApp::OnWebKitInitialized() {
    // Register the client_app extension.
    std::string app_code =
        "var app;"
        "if (!app) {"
        "  app = {"
        "    sendMessage: function(/*one or more*/) {"
        "      native function sendMessage();"
        "      return sendMessage.apply(this, Array.prototype.slice.call(arguments));"
        "    }"
        "  }"
        "}";
    CefRegisterExtension("v8/app", app_code,
                         new ClientAppExtensionHandler(this));

    RenderDelegateSet::iterator it = render_delegates_.begin();
    for (; it != render_delegates_.end(); ++it)
        (*it)->OnWebKitInitialized(this);
}
Beispiel #10
0
void InitUIPluginTest()
{
  // Structure providing information about the client plugin.
  CefPluginInfo plugin_info;
  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");
  CefString(&plugin_info.mime_type).FromASCII("application/x-client-ui-plugin");

  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.
  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());
}
// CefRenderProcessHandler methods.
void Application::OnWebKitInitialized()
{
	// Register our hook extension
	std::string script =
		"var RadiantUI;"
		"if (!RadiantUI)"
		"  RadiantUI = {};"
		"(function() {"
		"  RadiantUI.TriggerEvent = function() {"
		"    native function TriggerEvent();"
		"    return TriggerEvent(Array.prototype.slice.call(arguments));"
		"  };"
		"  RadiantUI.SetCallback = function(name, callback) {"
		"    native function SetHook();"
		"    return SetHook(name, callback);"
		"  };"
		"  RadiantUI.RemoveCallback = function(name) {"
		"    native function RemoveHook();"
		"    return RemoveHook(name);"
		"  };"
		"})();";
	CefRegisterExtension("RadiantUI JSHooks Extension", script, new JSHookExtensionHandler(this));
}
Beispiel #12
0
void CTransChatWebWnd::InitExtension()
{
	std::string Ext = "var Cef;"
		"if (!Cef)"
		"  Cef = {};"
		"if (!Cef.Ext)"
		"  Cef.Ext = {};"
		"if (!Cef.User)"
		"  Cef.User = {};"
		"(function() {"
		"  Cef.Ext.__defineGetter__('test_param', function() {"
		"    native function GetTestParam();"
		"    return GetTestParam();"
		"  });"
		"  Cef.Ext.__defineSetter__('test_param', function(b) {"
		"    native function SetTestParam();"
		"    if (b) SetTestParam(b);"
		"  });"
		"  Cef.Ext.test_object = function() {"
		"    native function GetTestObject();"
		"    return GetTestObject();"
		"  };"
		"  Cef.Ext.SelectFileDlg = function() {"
		"    native function SelectFileDlg();"
		"    return SelectFileDlg();"
		"  };"
		"  Cef.Ext.StartRecord = function() {"
		"    native function StartRecord();"
		"    return StartRecord();"
		"  };"
		"  Cef.Ext.CancelRecord = function() {"
		"    native function CancelRecord();"
		"    return CancelRecord();"
		"  };"
		"  Cef.Ext.SaveRecord = function() {"
		"    native function SaveRecord();"
		"    return SaveRecord();"
		"  };"
		"  Cef.Ext.SendRecord = function() {"
		"    native function SendRecord();"
		"    return SendRecord();"
		"  };"
		"  Cef.Ext.GetVoicePath = function() {"
		"    native function GetVoicePath();"
		"    return GetVoicePath();"
		"  };"
		"  Cef.Ext.GetVoiceData = function() {"
		"    native function GetVoiceData();"
		"    return GetVoiceData();"
		"  };"
		" Cef.Ext.GetFileSize = function(file) {"
		"    native function GetFileSize();"
		"    return GetFileSize(file);"
		"  };"
		" Cef.Ext.GetVoiceSize = function() {"
		"    native function GetVoiceSize();"
		"    return GetVoiceSize();"
		"  };"
		" Cef.Ext.GetVoiceLength = function(file) {"
		"    native function GetVoiceLength();"
		"    return GetVoiceLength(file);"
		"  };"
		"Cef.Ext.PlayAudio = function(url, file){"
		"    native function PlayAudio();"
		"    return PlayAudio(url, file)"
		"  };"
		"Cef.Ext.StopAudio = function(){"
		"    native function StopAudio();"
		"    return StopAudio()"
		"  };"
		"Cef.Ext.ViewImage = function(url){"
		"    native function ViewImage();"
		"    return ViewImage(url)"
		"  };"
		"Cef.User.GetUserId = function(){"
		"    native function GetUserId();"
		"    return GetUserId()"
		"  };"
		"Cef.User.GetUserPwd = function(){"
		"    native function GetUserPwd();"
		"    return GetUserPwd()"
		"  };"
		"Cef.User.GetCustomerId = function(){"
		"    native function GetCustomerId();"
		"    return GetCustomerId()"
		"  };"
		"Cef.User.GetFirstSentence = function(){"
		"    native function GetFirstSentence();"
		"    return GetFirstSentence()"
		"  };"
		"Cef.User.GetCustomerPwd = function(){"
		"    native function GetCustomerPwd();"
		"    return GetCustomerPwd()"
		"  };"
		"})();";

	CefRegisterExtension("v8/Ext", Ext, new ClientV8ExtHandler());//Ext表示的字符串是任意合法的JS代码
}
// Inject webinos.js
// The file is loaded from the webinos\test\client folder if possible.
// If this fails, the current folder is used.
void ClientApp::InjectWebinos(CefRefPtr<CefFrame> frame)
{
  CefRefPtr<CefCommandLine> commandLine = AppGetCommandLine();

  // First try and load the platform-supplied webinos.js
#if defined(OS_WIN)
  FilePath workingDir(commandLine->GetProgram().ToWString().c_str());
  FilePath webinosJSPath = workingDir.DirName().Append(L"..\\..\\webinos\\web_root\\webinos.js");
#else
  FilePath workingDir(commandLine->GetProgram());
  FilePath webinosJSPath = workingDir.DirName().Append("..\\..\\webinos\\web_root\\webinos.js");
#endif

  int64 webinosJSCodeSize;
  bool gotJSFile = file_util::GetFileSize(webinosJSPath, &webinosJSCodeSize);
  if (!gotJSFile)
  {
    // Unable to load the platform-supplied webinos.js, use the installed version.
#if defined(OS_WIN)
    workingDir = FilePath(commandLine->GetProgram().ToWString().c_str());
    webinosJSPath = workingDir.DirName().Append(L"webinos.js");
#else
    workingDir = FilePath(commandLine->GetProgram());
    webinosJSPath = workingDir.DirName().Append("webinos.js");
#endif
    gotJSFile = file_util::GetFileSize(webinosJSPath, &webinosJSCodeSize);
  }

  if (gotJSFile)
  {
    char* webinosJSCode = new char[webinosJSCodeSize+1];
    file_util::ReadFile(webinosJSPath, webinosJSCode, webinosJSCodeSize);
    webinosJSCode[webinosJSCodeSize] = 0;

    if (frame == NULL)
    {
      // Register as a Cef extension.
      CefRegisterExtension("webinos", webinosJSCode, NULL);
    }
    else
    {
      // Run the code in the frame javascript context right now,
      // but only if the URL refers to the widget server.
      int widgetServerPort;
      AppGetWebinosWRTConfig(NULL,&widgetServerPort);

      char injectionCandidate[MAX_URL_LENGTH];
      sprintf(injectionCandidate,"http://localhost:%d",widgetServerPort);

      std::string url = frame->GetURL();
      if (url.substr(0,strlen(injectionCandidate)) == injectionCandidate)
        frame->ExecuteJavaScript(webinosJSCode, url, 0);
    }

    delete[] webinosJSCode;
  }
  else
  {
    	LOG(ERROR) << "Can't find webinos.js";
  }
}