forked from academiadocodigo/TBGWebCharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Browser.Chromium.Resources.Pages.pas
96 lines (81 loc) · 2.22 KB
/
Browser.Chromium.Resources.Pages.pas
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
unit Browser.Chromium.Resources.Pages;
interface
uses
Interfaces,
uCEFInterfaces,
Generics.Collections;
type
TChromiumResourcesPages = class (TInterfacedObject, iModelChromiumResourcesPages)
private
FPages : TDictionary<string, ICefResourceHandler>;
FContador : integer;
function GetContador: integer;
public
constructor Create;
destructor Destroy; override;
class function New : iModelChromiumResourcesPages;
function Add(HTML : String) : string;
function Get(Key : String) : ICefResourceHandler;
function Extract(Key : String) :ICefResourceHandler;
procedure Remove(Key : String);
end;
implementation
uses
System.SysUtils,
System.Classes,
Chromium.CustomResourceHandler,
uCEFMiscFunctions;
{ TBrowserPages }
function TChromiumResourcesPages.Add(HTML: string): string;
var
key : integer;
TempStream : TStringStream;
begin
key := GetContador;
try
try
TempStream := TStringStream.Create(HTML, TEncoding.UTF8, false);
FPages.Add(IntToStr(key), TCustomResourceHandler.Create(nil, nil, '', nil, TStream(TempStream), CefGetMimeType('html')));
except
raise Exception.Create('Erro ao gerar Handle HTML');
end;
finally
if TempStream <> nil then
FreeAndNil(TempStream);
end;
Result := IntToStr(key);
end;
constructor TChromiumResourcesPages.Create;
begin
FPages := TDictionary<string, ICefResourceHandler>.Create;
FContador := 0;
end;
destructor TChromiumResourcesPages.Destroy;
begin
FreeAndNil(FPages);
inherited;
end;
function TChromiumResourcesPages.Extract(Key: String): ICefResourceHandler;
begin
Result := FPages.ExtractPair(Key).Value;
end;
function TChromiumResourcesPages.Get(Key: String): ICefResourceHandler;
begin
Result := nil;
if FPages.ContainsKey(Key) then
Result := FPAges.Items[Key];
end;
function TChromiumResourcesPages.GetContador: integer;
begin
inc(FContador);
Result := FContador;
end;
class function TChromiumResourcesPages.New: iModelChromiumResourcesPages;
begin
Result := Self.Create;
end;
Procedure TChromiumResourcesPages.Remove(Key: String);
begin
FPages.Remove(Key);
end;
end.