forked from chromiumembedded/java-cef
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCefAppHandlerAdapter.java
More file actions
101 lines (90 loc) · 3.58 KB
/
CefAppHandlerAdapter.java
File metadata and controls
101 lines (90 loc) · 3.58 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
92
93
94
95
96
97
98
99
100
101
// 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.
package org.cef.handler;
import org.cef.CefApp;
import org.cef.CefApp.CefAppState;
import org.cef.callback.CefCommandLine;
import org.cef.callback.CefSchemeRegistrar;
/**
* An abstract adapter class for managing app handler events.
* The methods in this class are using a default implementation.
* This class exists as convenience for creating handler objects.
*/
public abstract class CefAppHandlerAdapter implements CefAppHandler {
private String[] args_;
public CefAppHandlerAdapter(String[] args) {
args_ = args;
}
@Override
public void onBeforeCommandLineProcessing(String process_type, CefCommandLine command_line) {
if (process_type.isEmpty() && args_ != null) {
// Forward switches and arguments from Java to Cef
boolean parseSwitchesDone = false;
for (String arg : args_) {
if (parseSwitchesDone || arg.length() < 2) {
command_line.appendArgument(arg);
continue;
}
// Arguments with '--', '-' and, on Windows, '/' prefixes are considered switches.
int switchCnt = arg.startsWith("--") ? 2
: arg.startsWith("/") ? 1
: arg.startsWith("-") ? 1
: 0;
switch (switchCnt) {
case 2:
// An argument of "--" will terminate switch parsing with all subsequent
// tokens
if (arg.length() == 2) {
parseSwitchesDone = true;
continue;
}
// FALL THRU
case 1: {
// Switches can optionally have a value specified using the '=' delimiter
// (e.g. "-switch=value").
String switchStr = arg.substring(switchCnt);
int index = switchStr.indexOf('=');
if (index > 0) {
command_line.appendSwitchWithValue(
switchStr.substring(0, index), switchStr.substring(index + 1));
} else {
command_line.appendSwitch(switchStr);
}
break;
}
case 0:
command_line.appendArgument(arg);
break;
}
}
}
}
@Override
public boolean onBeforeTerminate() {
// The default implementation does nothing
return false;
}
@Override
public void stateHasChanged(CefAppState state) {
// The default implementation does nothing
}
@Override
public void onRegisterCustomSchemes(CefSchemeRegistrar registrar) {
// The default implementation does nothing
}
@Override
public void onContextInitialized() {
// The default implementation does nothing
}
@Override
public void onScheduleMessagePumpWork(long delay_ms) {
CefApp.getInstance().doMessageLoopWork(delay_ms);
}
@Override
public boolean onAlreadyRunningAppRelaunch(
CefCommandLine command_line, String current_directory) {
// The default implementation does nothing
return false;
}
}