-
Notifications
You must be signed in to change notification settings - Fork 1
/
clientapp.cc
91 lines (64 loc) · 2.27 KB
/
clientapp.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "stdafx.h"
#include "clientapp.h"
CCefClientApp::CCefClientApp()
{
v8Handler_ = new CCEFV8HandlerEx;
}
CCefClientApp::~CCefClientApp()
{
}
CefRefPtr<CefBrowserProcessHandler> CCefClientApp::GetBrowserProcessHandler()
{
return this;
}
void CCefClientApp::OnBeforeCommandLineProcessing(const CefString & process_type, CefRefPtr<CefCommandLine> command_line)
{
//加载flash插件
command_line->AppendSwitchWithValue("--ppapi-flash-path", "ppflash/18_0_0_209/pepflashplayer32_18_0_0_209.dll");
//manifest.json中的version
command_line->AppendSwitchWithValue("--ppapi-flash-version", "18.0.0.209");
command_line->AppendSwitch("--disable-extensions");
}
void CCefClientApp::OnContextInitialized()
{
}
//CefRefPtr<CefRenderProcessHandler> CCefClientApp::GetRenderProcessHandler()
//{
// return this;
//}
void CCefClientApp::OnWebKitInitialized()
{
std::string app_code =
//-----------------------------------
//声明JavaScript里要调用的Cpp方法
"var app;"
"if (!app)"
" app = {};"
"(function() {"
// jsInvokeCPlusPlus
" app.jsInvokeCPlusPlus = function(v1, v2) {"
" native function jsInvokeCPlusPlus();"
" return jsInvokeCPlusPlus(v1, v2);"
" };"
"})();";
// Register app extension module
// JavaScript里调用app.jsInvokeCPlusPlus时,就会去通过CefRegisterExtension注册的CefV8Handler列表里查找
// 找到"v8/app"对应的CCEFV8HandlerEx,就调用它的Execute方法
// 假设v8Handler_是CCefClientApp的一个成员变量
//v8Handler_ = new CCEFV8HandlerEx();
CefRegisterExtension("v8/app", app_code, v8Handler_);
}
void CCefClientApp::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
{
CefRefPtr<CefV8Value> object = context->GetGlobal();// 获取到window
CefRefPtr<CefV8Value> str = CefV8Value::CreateString("C++ created Value!");
object->SetValue("jsValue", str, V8_PROPERTY_ATTRIBUTE_NONE);
CefRefPtr<CefV8Accessor> accessor = new MyV8Accessor;
CefRefPtr<CefV8Value> obj = CefV8Value::CreateObject(accessor);
obj->SetValue("myval", V8_ACCESS_CONTROL_DEFAULT, V8_PROPERTY_ATTRIBUTE_NONE);
object->SetValue("myobject", obj, V8_PROPERTY_ATTRIBUTE_NONE);
}
void CCefClientApp::OnContextReleased(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
{
v8Handler_ = nullptr;
}