forked from chromiumembedded/java-cef
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser_process_handler.cpp
More file actions
91 lines (74 loc) · 2.72 KB
/
Copy pathbrowser_process_handler.cpp
File metadata and controls
91 lines (74 loc) · 2.72 KB
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
// Copyright (c) 2014 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 "browser_process_handler.h"
#include "client_handler.h"
#include "context.h"
#include "jni_scoped_helpers.h"
#include "jni_util.h"
#include "print_handler.h"
#include "util.h"
#include "include/cef_base.h"
// instantiate static values
std::set<CefMessageRouterConfig, cmpCfg> BrowserProcessHandler::router_cfg_;
base::Lock BrowserProcessHandler::router_cfg_lock_;
BrowserProcessHandler::BrowserProcessHandler(JNIEnv* env, jobject app_handler)
: handle_(env, app_handler) {}
BrowserProcessHandler::~BrowserProcessHandler() {
base::AutoLock lock_scope(router_cfg_lock_);
router_cfg_.clear();
}
void BrowserProcessHandler::OnContextInitialized() {
Context::GetInstance()->OnContextInitialized();
if (!handle_)
return;
BEGIN_ENV(env)
JNI_CALL_VOID_METHOD(env, handle_, "onContextInitialized", "()V");
END_ENV(env)
}
void BrowserProcessHandler::OnRenderProcessThreadCreated(
CefRefPtr<CefListValue> extra_info) {
int idx = 0;
static std::set<CefMessageRouterConfig, cmpCfg>::iterator iter;
// Delegate creation of the renderer-side router for query handling.
base::AutoLock lock_scope(router_cfg_lock_);
for (iter = router_cfg_.begin(); iter != router_cfg_.end(); ++iter) {
CefRefPtr<CefDictionaryValue> dict = CefDictionaryValue::Create();
dict->SetString("js_query_function", iter->js_query_function);
dict->SetString("js_cancel_function", iter->js_cancel_function);
extra_info->SetDictionary(idx, dict);
idx++;
}
}
CefRefPtr<CefPrintHandler> BrowserProcessHandler::GetPrintHandler() {
CefRefPtr<CefPrintHandler> result;
BEGIN_ENV(env)
ScopedJNIObjectResult jresult(env);
JNI_CALL_METHOD(env, handle_, "getPrintHandler",
"()Lorg/cef/handler/CefPrintHandler;", Object, jresult);
if (jresult) {
ScopedJNIObject<PrintHandler> jprintHandler(
env, jresult.Release(), true /* should_delete */, "CefPrintHandler");
result = jprintHandler.GetOrCreateCefObject();
}
END_ENV(env)
return result;
}
void BrowserProcessHandler::OnScheduleMessagePumpWork(int64 delay_ms) {
if (!handle_)
return;
BEGIN_ENV(env)
JNI_CALL_VOID_METHOD(env, handle_, "onScheduleMessagePumpWork", "(J)V",
delay_ms);
END_ENV(env)
}
void BrowserProcessHandler::AddMessageRouterConfig(
const CefMessageRouterConfig& cfg) {
base::AutoLock lock_scope(router_cfg_lock_);
router_cfg_.insert(cfg);
}
void BrowserProcessHandler::RemoveMessageRouterConfig(
const CefMessageRouterConfig& cfg) {
base::AutoLock lock_scope(router_cfg_lock_);
router_cfg_.erase(cfg);
}