cef3知识点1

以下在cefsimple.exe中测试过

1:禁止图片

void SimpleApp::OnContextInitialized()添加如下代码

browser_settings是创建浏览窗口的一个控制变量

browser_settings.image_loading = STATE_DISABLED;
browser_settings.local_storage = STATE_DISABLED;


CefBrowserHost::CreateBrowser(window_info, handler.get(), url,
                                browser_settings, NULL);



2:自定义渲染进程信息回调处理  js调用cef3方法

在winmain主函数中添加如下


CefRefPtr<CefApp> app;

  const std::string& processType = command_line->GetSwitchValue("type");
  if (processType == "renderer")
  {
  app = new ClientAppRenderer();
  }



  //第二参数NULL时其他进程使用默认处理
  int exit_code = CefExecuteProcess(main_args, app, sandbox_info);
  if (exit_code >= 0) {
    // The sub-process has completed so return here.
    return exit_code;
  }

通过自定义类ClientAppRenderer实现CefRenderProcessHandler接口并重写

void OnContextCreated(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context)

{

// Create an instance of my CefV8Handler object.
CefRefPtr<CefV8Handler> handler = new MyV8Handler();


// Create the "myfunc" function.
CefRefPtr<CefV8Value> func = CefV8Value::CreateFunction("OpenGame", handler);


// Add the "myfunc" function to the "window" object.
object->SetValue("OpenGame", func, V8_PROPERTY_ATTRIBUTE_NONE);

}


此方法提供了一个CEF3回调方法给页面调用,MyV8Handler则是回调方法的实现


该回调方法实现如下:

class MyV8Handler : public CefV8Handler {
public:
MyV8Handler() {}


virtual bool Execute(const CefString& name,
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
CefString& exception) OVERRIDE {
if (name == "OpenGame") {
// Return my string value.
retval = CefV8Value::CreateString("My Value!");

CefRefPtr<CefProcessMessage> msg = CefProcessMessage::Create("OpenGame");


// Retrieve the argument list object.
CefRefPtr<CefListValue> args = msg->GetArgumentList();


// Populate the argument values.
CefRefPtr<CefV8Value> urlvalue = arguments.at(0);
CefRefPtr<CefV8Value> accountvalue = arguments.at(1);
CefRefPtr<CefV8Value> servervalue = arguments.at(2);
CefRefPtr<CefV8Value> servernamevalue = arguments.at(3);
args->SetSize(4);
args->SetString(0, urlvalue.get()->GetStringValue());
args->SetString(1, accountvalue.get()->GetStringValue());
args->SetString(2, servervalue.get()->GetStringValue());
args->SetString(3, servernamevalue.get()->GetStringValue());


// Send the process message to the browser process.
CefV8Context::GetCurrentContext()->GetBrowser()->SendProcessMessage(PID_BROWSER, msg);


return true;
}


// Function does not exist.
return false;
}


// Provide the reference counting implementation for this class.
IMPLEMENT_REFCOUNTING(MyV8Handler);
};


3:winmain主函数中添加如下代码实现缓存和本地化

//知识点 缓存
  cef_string_from_ascii("C:\\cef_test", strlen("C:\\cef_test"), &settings.cache_path);
  //知识点 本地化
  cef_string_from_ascii("zh-CN", strlen("zh-CN"), &settings.locale);


4:处理命令行  开启flash 等

void OnBeforeCommandLineProcessing(
      const CefString& process_type,
      CefRefPtr<CefCommandLine> command_line) {

//知识点 flash 
command_line->AppendSwitch("--disable-web-security");//关闭同源策略
command_line->AppendSwitch("--enable-system-flash");//使用系统flash



//知识点  指定路径flash,注意32/64
command_line->AppendSwitchWithValue("ppapi-flash-version", "29.0.0.140");
command_line->AppendSwitchWithValue("ppapi-flash-path", "plugins\\pepflashplayer32_29_0_0_140.dll");

  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值