Kitchen Pages, KitCAD i3 KGC rX - SDK source - Index
This, uMiniBrowser.pas requires:- uMiniBrowser.dfm
modified CEF4Dephi; uMiniBrowser.pas
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright © 2017 Salvador Díaz Fau. All rights reserved.
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
{------------------------------------------------------------------------
KitCAD i3 KGC rX browser modification, modified MiniBrowser, 10-2017, 7-2018, 8-2018
-------------------------------------------------------------------------}
unit uMiniBrowser;
{$I cef.inc}
interface
uses
{$IFDEF DELPHI16_UP}
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Menus,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, System.Types, Vcl.ComCtrls, Vcl.ClipBrd,
System.UITypes, Vcl.AppEvnts,
Winapi.ShellAPI, WideStrUtils, Character,
{$ELSE}
Windows, Messages, SysUtils, Variants, Classes, Graphics, Menus,
Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Types, ComCtrls, ClipBrd, AppEvnts,
ShellAPI, WideStrUtils, Character,
{$ENDIF}
uCEFChromium, uCEFWindowParent, uCEFInterfaces, uCEFApplication, uCEFTypes, uCEFConstants;
const
MINIBROWSER_SHOWDEVTOOLS = WM_APP + $101;
MINIBROWSER_HIDEDEVTOOLS = WM_APP + $102;
MINIBROWSER_COPYHTML = WM_APP + $103;
MINIBROWSER_SHOWRESPONSE = WM_APP + $104;
MINIBROWSER_COPYFRAMEIDS = WM_APP + $105;
MINIBROWSER_COPYFRAMENAMES = WM_APP + $106;
MINIBROWSER_HOMEPAGE = 'https://www.google.com';
MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS = MENU_ID_USER_FIRST + 1;
MINIBROWSER_CONTEXTMENU_HIDEDEVTOOLS = MENU_ID_USER_FIRST + 2;
MINIBROWSER_CONTEXTMENU_COPYHTML = MENU_ID_USER_FIRST + 3;
MINIBROWSER_CONTEXTMENU_JSWRITEDOC = MENU_ID_USER_FIRST + 4;
MINIBROWSER_CONTEXTMENU_JSPRINTDOC = MENU_ID_USER_FIRST + 5;
MINIBROWSER_CONTEXTMENU_SHOWRESPONSE = MENU_ID_USER_FIRST + 6;
MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS = MENU_ID_USER_FIRST + 7;
MINIBROWSER_CONTEXTMENU_COPYFRAMENAMES = MENU_ID_USER_FIRST + 8;
type
TMiniBrowserFrm = class(TForm)
NavControlPnl: TPanel;
NavButtonPnl: TPanel;
URLEditPnl: TPanel;
BackBtn: TButton;
ForwardBtn: TButton;
ReloadBtn: TButton;
CEFWindowParent1: TCEFWindowParent;
Chromium1: TChromium;
StopBtn: TButton;
DevTools: TCEFWindowParent;
Splitter1: TSplitter;
StatusBar1: TStatusBar;
URLCbx: TComboBox;
ConfigPnl: TPanel;
ConfigBtn: TButton;
PopupMenu1: TPopupMenu;
DevTools1: TMenuItem;
N1: TMenuItem;
Preferences1: TMenuItem;
GoBtn: TButton;
N2: TMenuItem;
PrintinPDF1: TMenuItem;
Print1: TMenuItem;
N3: TMenuItem;
Zoom1: TMenuItem;
Inczoom1: TMenuItem;
Deczoom1: TMenuItem;
Resetzoom1: TMenuItem;
SaveDialog1: TSaveDialog;
ApplicationEvents1: TApplicationEvents;
OpenDialog1: TOpenDialog;
N4: TMenuItem;
Openfile1: TMenuItem;
Resolvehost1: TMenuItem;
//added objects for modified MiniBrowser
RichEdit1: TRichEdit;
RichEdit2: TRichEdit;
RichEdit3: TRichEdit;
Timer1: TTimer;
Timer2: TTimer;
Timer3: TTimer;
Timer4: TTimer;
Timer5: TTimer;
Timer6: TTimer;
procedure FormShow(Sender: TObject);
procedure BackBtnClick(Sender: TObject);
procedure ForwardBtnClick(Sender: TObject);
procedure ReloadBtnClick(Sender: TObject);
procedure Chromium1AfterCreated(Sender: TObject;
const browser: ICefBrowser);
procedure Chromium1LoadingStateChange(Sender: TObject;
const browser: ICefBrowser; isLoading, canGoBack,
canGoForward: Boolean);
procedure Chromium1TitleChange(Sender: TObject;
const browser: ICefBrowser; const title: ustring);
procedure Chromium1AddressChange(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const url: ustring);
procedure Chromium1BeforeContextMenu(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; const model: ICefMenuModel);
procedure Chromium1StatusMessage(Sender: TObject;
const browser: ICefBrowser; const value: ustring);
procedure Chromium1TextResultAvailable(Sender: TObject;
const aText: string);
procedure PopupMenu1Popup(Sender: TObject);
procedure DevTools1Click(Sender: TObject);
procedure Preferences1Click(Sender: TObject);
procedure ConfigBtnClick(Sender: TObject);
procedure GoBtnClick(Sender: TObject);
procedure PrintinPDF1Click(Sender: TObject);
procedure Print1Click(Sender: TObject);
procedure Inczoom1Click(Sender: TObject);
procedure Deczoom1Click(Sender: TObject);
procedure Resetzoom1Click(Sender: TObject);
procedure Chromium1FullScreenModeChange(Sender: TObject;
const browser: ICefBrowser; fullscreen: Boolean);
procedure Chromium1PreKeyEvent(Sender: TObject;
const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: PMsg;
out isKeyboardShortcut, Result: Boolean);
procedure Chromium1KeyEvent(Sender: TObject;
const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: PMsg;
out Result: Boolean);
procedure ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
procedure Openfile1Click(Sender: TObject);
procedure Chromium1ContextMenuCommand(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;
eventFlags: Cardinal; out Result: Boolean);
procedure Chromium1PdfPrintFinished(Sender: TObject;
aResultOK: Boolean);
procedure Chromium1ResourceResponse(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; const response: ICefResponse;
out Result: Boolean);
procedure StopBtnClick(Sender: TObject);
procedure Resolvehost1Click(Sender: TObject);
procedure Chromium1ResolvedHostAvailable(Sender: TObject;
result: Integer; const resolvedIps: TStrings);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Timer3Timer(Sender: TObject);
procedure Timer4Timer(Sender: TObject);
procedure crmBeforePopup(Sender: TObject; const browser: ICefBrowser;
const frame: ICefFrame; const targetUrl, targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
//added by jason below
procedure RichEdit1FindText (Sender: TObject; const FindtheText: ustring);
procedure RichEdit3FindText (Sender: TObject; const FindtheText: ustring);
procedure FormCreate(Sender: TObject);
procedure kpLANGUAGEcode(Sender: TObject; const LANGUAGE: AnsiString);
procedure Timer5Timer(Sender: TObject);
procedure FormCreator(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
out Result: Boolean);
procedure Timer6Timer(Sender: TObject);
protected
FResponse : string;
procedure AddURL(const aURL : string);
procedure ShowDevTools(aPoint : TPoint); overload;
procedure ShowDevTools; overload;
procedure HideDevTools;
procedure HandleKeyUp(const aMsg : TMsg; var aHandled : boolean);
procedure HandleKeyDown(const aMsg : TMsg; var aHandled : boolean);
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
procedure ShowDevToolsMsg(var aMessage : TMessage); message MINIBROWSER_SHOWDEVTOOLS;
procedure HideDevToolsMsg(var aMessage : TMessage); message MINIBROWSER_HIDEDEVTOOLS;
procedure CopyHTMLMsg(var aMessage : TMessage); message MINIBROWSER_COPYHTML;
procedure CopyFramesIDsMsg(var aMessage : TMessage); message MINIBROWSER_COPYFRAMEIDS;
procedure CopyFramesNamesMsg(var aMessage : TMessage); message MINIBROWSER_COPYFRAMENAMES;
procedure ShowResponseMsg(var aMessage : TMessage); message MINIBROWSER_SHOWRESPONSE;
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
public
procedure ShowStatusText(const aText : string);
end;
var
MiniBrowserFrm : TMiniBrowserFrm;
implementation
{$R *.dfm}
uses
uPreferences;
procedure TMiniBrowserFrm.BackBtnClick(Sender: TObject);
begin
Chromium1.GoBack;
end;
procedure TMiniBrowserFrm.ForwardBtnClick(Sender: TObject);
begin
Chromium1.GoForward;
end;
procedure TMiniBrowserFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(URLCbx.Text);
end;
procedure TMiniBrowserFrm.ReloadBtnClick(Sender: TObject);
begin
Chromium1.Reload;
end;
procedure TMiniBrowserFrm.Resetzoom1Click(Sender: TObject);
begin
Chromium1.ResetZoomStep;
end;
procedure TMiniBrowserFrm.Resolvehost1Click(Sender: TObject);
var
TempURL : string;
begin
TempURL := inputbox('Resolve host', 'URL :', 'http://google.com');
if (length(TempURL) > 0) then Chromium1.ResolveHost(TempURL);
end;
Procedure TMiniBrowserFrm.Chromium1AddressChange(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const url: ustring);
begin
if Chromium1.browser <> nil then
begin
// edAddress.Text := url;
//OPEN SECURE APPLICATION - start NOV 2014
//insert here for MAIN windows
//add ShellAPI and Character.pas or ShellAPI and Character.hpp to header
try
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\secure_top_browser.STATE_DISABLED') <> True then
if (AnsiPos( 'http:',ToLower(url)) <> 0) or (AnsiPos( 'https:',ToLower(url)) <> 0) then
begin
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\browser.bat') <> False then
begin
ShellExecute(0, PChar('open'), PChar(ExtractFilePath(Application.ExeName) + '\conf\browser.bat'),
PChar('"' + url + '" "0"'), PChar(ExtractFilePath(Application.ExeName) + '\conf\'), SW_SHOWMINIMIZED);
try
Close;//Application.Terminate();
finally
end;
end
else
begin
ShellExecute(0, PChar('open'), PChar(url), 0, nil, SW_SHOW);
try
Close;//Application.Terminate();
finally
end;
end;
end;
finally
end;
//end NOV 2014
end;
{next line added by Jason}
Timer2.Enabled := True;
//back to default
AddURL(url);
end;
procedure TMiniBrowserFrm.Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TMiniBrowserFrm.Chromium1BeforeContextMenu(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; const model: ICefMenuModel);
begin
model.AddSeparator;
model.AddItem(MINIBROWSER_CONTEXTMENU_COPYHTML, 'Copy HTML to clipboard');
model.AddItem(MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS, 'Copy HTML frame identifiers to clipboard');
model.AddItem(MINIBROWSER_CONTEXTMENU_COPYFRAMENAMES, 'Copy HTML frame names to clipboard');
model.AddSeparator;
model.AddItem(MINIBROWSER_CONTEXTMENU_JSWRITEDOC, 'Modify HTML document');
model.AddItem(MINIBROWSER_CONTEXTMENU_JSPRINTDOC, 'Print using Javascript');
model.AddItem(MINIBROWSER_CONTEXTMENU_SHOWRESPONSE, 'Show last server response');
if DevTools.Visible then
model.AddItem(MINIBROWSER_CONTEXTMENU_HIDEDEVTOOLS, 'Hide DevTools')
else
model.AddItem(MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS, 'Show DevTools');
end;
procedure TMiniBrowserFrm.Chromium1ContextMenuCommand(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;
eventFlags: Cardinal; out Result: Boolean);
var
TempParam : WParam;
begin
Result := False;
case commandId of
MINIBROWSER_CONTEXTMENU_HIDEDEVTOOLS :
PostMessage(Handle, MINIBROWSER_HIDEDEVTOOLS, 0, 0);
MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS :
begin
TempParam := ((params.XCoord and $FFFF) shl 16) or (params.YCoord and $FFFF);
PostMessage(Handle, MINIBROWSER_SHOWDEVTOOLS, TempParam, 0);
end;
MINIBROWSER_CONTEXTMENU_COPYHTML :
PostMessage(Handle, MINIBROWSER_COPYHTML, 0, 0);
MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS :
PostMessage(Handle, MINIBROWSER_COPYFRAMEIDS, 0, 0);
MINIBROWSER_CONTEXTMENU_COPYFRAMENAMES :
PostMessage(Handle, MINIBROWSER_COPYFRAMENAMES, 0, 0);
MINIBROWSER_CONTEXTMENU_SHOWRESPONSE :
PostMessage(Handle, MINIBROWSER_SHOWRESPONSE, 0, 0);
MINIBROWSER_CONTEXTMENU_JSWRITEDOC :
if (browser <> nil) and (browser.MainFrame <> nil) then
browser.MainFrame.ExecuteJavaScript(
'var css = ' + chr(39) + '@page {size: A4; margin: 0;} @media print {html, body {width: 210mm; height: 297mm;}}' + chr(39) + '; ' +
'var style = document.createElement(' + chr(39) + 'style' + chr(39) + '); ' +
'style.type = ' + chr(39) + 'text/css' + chr(39) + '; ' +
'style.appendChild(document.createTextNode(css)); ' +
'document.head.appendChild(style);',
'about:blank', 0);
MINIBROWSER_CONTEXTMENU_JSPRINTDOC :
if (browser <> nil) and (browser.MainFrame <> nil) then
browser.MainFrame.ExecuteJavaScript('window.print();', 'about:blank', 0);
end;
end;
procedure TMiniBrowserFrm.Chromium1FullScreenModeChange(Sender: TObject;
const browser: ICefBrowser; fullscreen: Boolean);
begin
if fullscreen then
begin
NavControlPnl.Visible := False;
StatusBar1.Visible := False;
if (WindowState = wsMaximized) then WindowState := wsNormal;
BorderIcons := [];
BorderStyle := bsNone;
WindowState := wsMaximized;
end
else
begin
BorderIcons := [biSystemMenu, biMinimize, biMaximize];
BorderStyle := bsSizeable;
WindowState := wsNormal;
NavControlPnl.Visible := True;
StatusBar1.Visible := True;
end;
end;
procedure TMiniBrowserFrm.Chromium1KeyEvent(Sender: TObject;
const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: PMsg;
out Result: Boolean);
var
TempMsg : TMsg;
begin
Result := False;
if (event <> nil) and (osEvent <> nil) then
case osEvent.Message of
WM_KEYUP :
begin
TempMsg := osEvent^;
HandleKeyUp(TempMsg, Result);
end;
WM_KEYDOWN :
begin
TempMsg := osEvent^;
HandleKeyDown(TempMsg, Result);
end;
end;
end;
procedure TMiniBrowserFrm.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
case Msg.message of
WM_KEYUP : HandleKeyUp(Msg, Handled);
WM_KEYDOWN : HandleKeyDown(Msg, Handled);
end;
end;
procedure TMiniBrowserFrm.HandleKeyUp(const aMsg : TMsg; var aHandled : boolean);
var
TempMessage : TMessage;
TempKeyMsg : TWMKey;
begin
TempMessage.Msg := aMsg.message;
TempMessage.wParam := aMsg.wParam;
TempMessage.lParam := aMsg.lParam;
TempKeyMsg := TWMKey(TempMessage);
if (TempKeyMsg.CharCode = VK_F12) then
begin
aHandled := True;
if DevTools.Visible then
PostMessage(Handle, MINIBROWSER_HIDEDEVTOOLS, 0, 0)
else
PostMessage(Handle, MINIBROWSER_SHOWDEVTOOLS, 0, 0);
end;
end;
procedure TMiniBrowserFrm.HandleKeyDown(const aMsg : TMsg; var aHandled : boolean);
var
TempMessage : TMessage;
TempKeyMsg : TWMKey;
begin
TempMessage.Msg := aMsg.message;
TempMessage.wParam := aMsg.wParam;
TempMessage.lParam := aMsg.lParam;
TempKeyMsg := TWMKey(TempMessage);
if (TempKeyMsg.CharCode = VK_F12) then aHandled := True;
end;
procedure TMiniBrowserFrm.Chromium1LoadingStateChange(Sender: TObject;
const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean);
begin
BackBtn.Enabled := canGoBack;
ForwardBtn.Enabled := canGoForward;
ReloadBtn.Enabled := not(isLoading);
StopBtn.Enabled := isLoading;
end;
procedure TMiniBrowserFrm.Chromium1PdfPrintFinished(Sender: TObject; aResultOK: Boolean);
begin
if aResultOK then
showmessage('The PDF file was generated successfully')
else
showmessage('There was a problem generating the PDF file.');
end;
procedure TMiniBrowserFrm.Chromium1PreKeyEvent(Sender: TObject;
const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: PMsg;
out isKeyboardShortcut, Result: Boolean);
begin
Result := False;
if (event <> nil) and
(event.kind in [KEYEVENT_KEYDOWN, KEYEVENT_KEYUP]) and
(event.windows_key_code = VK_F12) then
isKeyboardShortcut := True;
end;
procedure TMiniBrowserFrm.Chromium1ResolvedHostAvailable(Sender: TObject;
result: Integer; const resolvedIps: TStrings);
begin
if (result = ERR_NONE) then
showmessage('Resolved IPs : ' + resolvedIps.CommaText)
else
showmessage('There was a problem resolving the host.' + CRLF +
'Error code : ' + inttostr(result));
end;
procedure TMiniBrowserFrm.Chromium1ResourceResponse(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; const response: ICefResponse;
out Result: Boolean);
begin
Result := False;
if (frame <> nil) and frame.IsMain and (response <> nil) and (request <> nil) then
begin
FResponse := 'URL : ' + request.Url + CRLF +
'Status : ' + inttostr(response.Status) + CRLF +
'MimeType : ' + response.MimeType;
if (request.postdata <> nil) then
FResponse := FResponse + CRLF + 'Post data elements : ' + inttostr(request.postdata.GetCount);
end;
end;
procedure TMiniBrowserFrm.ShowStatusText(const aText : string);
begin
StatusBar1.Panels[0].Text := aText;
end;
procedure TMiniBrowserFrm.StopBtnClick(Sender: TObject);
begin
Chromium1.StopLoad;
end;
procedure TMiniBrowserFrm.Chromium1StatusMessage(Sender: TObject;
const browser: ICefBrowser; const value: ustring);
begin
ShowStatusText(value);
end;
procedure TMiniBrowserFrm.Chromium1TextResultAvailable(Sender: TObject; const aText: string);
begin
clipboard.AsText := aText;
end;
procedure TMiniBrowserFrm.Chromium1TitleChange(Sender: TObject;
const browser: ICefBrowser; const title: ustring);
var tcaption: ustring;
begin
if (title <> 'about:blank') then
begin //modified by Jason for KitCAD
// caption := 'MiniBrowser';
// else
caption := 'MiniBrowser - ' + title ;
end;
//EOSERROR code 1400 on exit, should the following not be within a IF block
if (title = 'about:blank') then
begin
caption := 'MiniBrowser - ' + title ;
{next line added by Jason}
Timer2.Enabled := True;
//{start december 2014 filewrite for session and local storage cache}
if AnsiPos('file:',ToLower(URLCbx.Text)) <> 0 then begin
RichEdit3.Lines.Text := PChar(title);
//cdata
if (AnsiPos('kitchenpages_',ToLower(RichEdit3.Lines.Text)) <> 0) then
begin
if (AnsiPos('kitchenpages_cdata_',ToLower(RichEdit3.Lines.Text)) <> 0) then
begin
RichEdit3.Lines.BeginUpdate();
RichEdit3FindText(Sender, 'kitchenpages_cdata_');
RichEdit3.SetSelText('');
RichEdit3.Lines.EndUpdate();
RichEdit3.SelStart := 0;
RichEdit3.SelLength := 0;
RichEdit3.Lines.Text := WideStringReplace(RichEdit3.Lines.Text, 'kitchenpages_cdata_', '', [rfReplaceAll]);
try
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_cdata.STATE_ENABLED') <> False then RichEdit3.Lines.SaveToFile(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_cdata.STATE_ENABLED');
//StatusBar.SimpleText := '';
Caption := tcaption;
finally
end;
end;
//grid
if (AnsiPos('kitchenpages_grid_',ToLower(RichEdit3.Lines.Text)) <> 0) then
begin
RichEdit3.Lines.BeginUpdate();
RichEdit3FindText(Sender, 'kitchenpages_grid_');
RichEdit3.SetSelText('');
RichEdit3.Lines.EndUpdate();
RichEdit3.SelStart := 0;
RichEdit3.SelLength := 0;
RichEdit3.Lines.Text := WideStringReplace(RichEdit3.Lines.Text, 'kitchenpages_grid_', '', [rfReplaceAll]);
try
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_grid.STATE_ENABLED') <> False then RichEdit3.Lines.SaveToFile(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_grid.STATE_ENABLED');
//StatusBar.SimpleText := '';
Caption := tcaption;
finally
end ;
end;
//language
if (AnsiPos('kitchenpages_language_',ToLower(RichEdit3.Lines.Text)) <> 0) then
begin
RichEdit3.Lines.BeginUpdate();
RichEdit3FindText(Sender, 'kitchenpages_language_');
RichEdit3.SetSelText('');
RichEdit3.Lines.EndUpdate();
RichEdit3.SelStart := 0;
RichEdit3.SelLength := 0;
RichEdit3.Lines.Text := WideStringReplace(RichEdit3.Lines.Text, 'kitchenpages_language_', '', [rfReplaceAll]);
try
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_language.STATE_ENABLED') <> False then RichEdit3.Lines.SaveToFile(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_language.STATE_ENABLED');
//StatusBar.SimpleText := '';
Caption := tcaption;
finally
end ;
end;
//opera message
if (AnsiPos('kitchenpages_operaturbo_message_',ToLower(RichEdit3.Lines.Text)) <> 0) then
begin
RichEdit3.Lines.BeginUpdate();
RichEdit3FindText(Sender, 'kitchenpages_operaturbo_message_');
RichEdit3.SetSelText('');
RichEdit3.Lines.EndUpdate();
RichEdit3.SelStart := 0;
RichEdit3.SelLength := 0;
RichEdit3.Lines.Text := WideStringReplace(RichEdit3.Lines.Text, 'kitchenpages_operaturbo_message_', '', [rfReplaceAll]);
try
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_operaturbo_message.STATE_ENABLED') <> False then RichEdit3.Lines.SaveToFile(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_operaturbo_message.STATE_ENABLED');
//StatusBar.SimpleText := '';
Caption := tcaption;
finally
end ;
Caption := tcaption;
end;
//if kitchenpages_ then reset, for supporting newier code
end;
end;
//{end december 2014 filewrite for session and local storage cache}
//{start december 2014 update for session and local storage cache}
if AnsiPos('file:',ToLower(URLCbx.Text)) <> 0 then begin
//cdata
try
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_cdata.STATE_ENABLED') <> False then
begin
if Chromium1.Browser <> nil then begin
RichEdit3.Lines.Text:='';
RichEdit3.Lines.LoadFromFile(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_cdata.STATE_ENABLED');
if (RichEdit3.Lines.Text <> EmptyStr) then begin
//bug with following line, RichEdit3 will not insert text to ustring
Chromium1.Browser.MainFrame.ExecuteJavaScript(
'var kpCDATAcode = '''+RichEdit3.Lines.Text+''';' , 'about:blank', 0);
end;
end;
end;
finally
end;
//grid
try
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_grid.STATE_ENABLED') <> False then
begin
if Chromium1.Browser <> nil then begin
RichEdit3.Lines.Text:='';
RichEdit3.Lines.LoadFromFile(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_grid.STATE_ENABLED');
if (RichEdit3.Lines.Text <> EmptyStr) then begin
if (RichEdit3.Lines.IndexOf('0') <> -1) then begin
Chromium1.Browser.MainFrame.ExecuteJavaScript(
'var kpGRIDcode=''0'';try{localStorage.setItem(''kitchenpages_grid'',kpGRIDcode);}catch(e){}' , 'about:blank', 0);
end;
if (RichEdit3.Lines.IndexOf('1') <> -1) then begin
Chromium1.Browser.MainFrame.ExecuteJavaScript(
'var kpGRIDcode=''1'';try{localStorage.setItem(''kitchenpages_grid'',kpGRIDcode);}catch(e){}' , 'about:blank', 0);
end;
if (RichEdit3.Lines.IndexOf('2') <> -1) then begin
Chromium1.Browser.MainFrame.ExecuteJavaScript(
'var kpGRIDcode=''2'';try{localStorage.setItem(''kitchenpages_grid'',kpGRIDcode);}catch(e){}' , 'about:blank', 0);
end;
end;
end;
end;
finally
end;
//language
try
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_language.STATE_ENABLED') <> False then
begin
if Chromium1.Browser <> nil then begin
RichEdit3.Lines.Text:='';
RichEdit3.Lines.LoadFromFile(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_language.STATE_ENABLED');
if (RichEdit3.Lines.Text <> EmptyStr) then begin
if (RichEdit3.Lines.IndexOf('0') = -1) then begin
//all known country codes in 2014, plus za zu zz us au eu uu rx i3 kp = 144 total
kpLANGUAGEcode(Sender,'ab');
kpLANGUAGEcode(Sender,'aa');
kpLANGUAGEcode(Sender,'af');
kpLANGUAGEcode(Sender,'sq');
kpLANGUAGEcode(Sender,'am');
kpLANGUAGEcode(Sender,'ar');
kpLANGUAGEcode(Sender,'hy');
kpLANGUAGEcode(Sender,'as');
kpLANGUAGEcode(Sender,'ay');
kpLANGUAGEcode(Sender,'az');
kpLANGUAGEcode(Sender,'ba');
kpLANGUAGEcode(Sender,'eu');
kpLANGUAGEcode(Sender,'bn');
kpLANGUAGEcode(Sender,'dz');
kpLANGUAGEcode(Sender,'bh');
kpLANGUAGEcode(Sender,'bi');
kpLANGUAGEcode(Sender,'br');
kpLANGUAGEcode(Sender,'bg');
kpLANGUAGEcode(Sender,'my');
kpLANGUAGEcode(Sender,'be');
kpLANGUAGEcode(Sender,'km');
kpLANGUAGEcode(Sender,'ca');
kpLANGUAGEcode(Sender,'zh');
kpLANGUAGEcode(Sender,'co');
kpLANGUAGEcode(Sender,'hr');
kpLANGUAGEcode(Sender,'cs');
kpLANGUAGEcode(Sender,'da');
kpLANGUAGEcode(Sender,'nl');
kpLANGUAGEcode(Sender,'en');
kpLANGUAGEcode(Sender,'eo');
kpLANGUAGEcode(Sender,'et');
kpLANGUAGEcode(Sender,'fo');
kpLANGUAGEcode(Sender,'fj');
kpLANGUAGEcode(Sender,'fi');
kpLANGUAGEcode(Sender,'fr');
kpLANGUAGEcode(Sender,'fy');
kpLANGUAGEcode(Sender,'gd');
kpLANGUAGEcode(Sender,'gl');
kpLANGUAGEcode(Sender,'ka');
kpLANGUAGEcode(Sender,'de');
kpLANGUAGEcode(Sender,'el');
kpLANGUAGEcode(Sender,'kl');
kpLANGUAGEcode(Sender,'gn');
kpLANGUAGEcode(Sender,'gu');
kpLANGUAGEcode(Sender,'ha');
kpLANGUAGEcode(Sender,'iw');
kpLANGUAGEcode(Sender,'hi');
kpLANGUAGEcode(Sender,'hu');
kpLANGUAGEcode(Sender,'is');
kpLANGUAGEcode(Sender,'in');
kpLANGUAGEcode(Sender,'ia');
kpLANGUAGEcode(Sender,'ie');
kpLANGUAGEcode(Sender,'ik');
kpLANGUAGEcode(Sender,'ga');
kpLANGUAGEcode(Sender,'it');
kpLANGUAGEcode(Sender,'ja');
kpLANGUAGEcode(Sender,'jw');
kpLANGUAGEcode(Sender,'kn');
kpLANGUAGEcode(Sender,'ks');
kpLANGUAGEcode(Sender,'kk');
kpLANGUAGEcode(Sender,'rw');
kpLANGUAGEcode(Sender,'ky');
kpLANGUAGEcode(Sender,'rn');
kpLANGUAGEcode(Sender,'ko');
kpLANGUAGEcode(Sender,'ku');
kpLANGUAGEcode(Sender,'lo');
kpLANGUAGEcode(Sender,'la');
kpLANGUAGEcode(Sender,'lv');
kpLANGUAGEcode(Sender,'ln');
kpLANGUAGEcode(Sender,'lt');
kpLANGUAGEcode(Sender,'mk');
kpLANGUAGEcode(Sender,'mg');
kpLANGUAGEcode(Sender,'ms');
kpLANGUAGEcode(Sender,'ml');
kpLANGUAGEcode(Sender,'mt');
kpLANGUAGEcode(Sender,'mi');
kpLANGUAGEcode(Sender,'mr');
kpLANGUAGEcode(Sender,'mo');
kpLANGUAGEcode(Sender,'mn');
kpLANGUAGEcode(Sender,'na');
kpLANGUAGEcode(Sender,'ne');
kpLANGUAGEcode(Sender,'no');
kpLANGUAGEcode(Sender,'oc');
kpLANGUAGEcode(Sender,'or');
kpLANGUAGEcode(Sender,'om');
kpLANGUAGEcode(Sender,'ps');
kpLANGUAGEcode(Sender,'fa');
kpLANGUAGEcode(Sender,'pl');
kpLANGUAGEcode(Sender,'pt');
kpLANGUAGEcode(Sender,'pa');
kpLANGUAGEcode(Sender,'qu');
kpLANGUAGEcode(Sender,'rm');
kpLANGUAGEcode(Sender,'ro');
kpLANGUAGEcode(Sender,'ru');
kpLANGUAGEcode(Sender,'sm');
kpLANGUAGEcode(Sender,'sg');
kpLANGUAGEcode(Sender,'sa');
kpLANGUAGEcode(Sender,'sr');
kpLANGUAGEcode(Sender,'sh');
kpLANGUAGEcode(Sender,'st');
kpLANGUAGEcode(Sender,'tn');
kpLANGUAGEcode(Sender,'sn');
kpLANGUAGEcode(Sender,'sd');
kpLANGUAGEcode(Sender,'si');
kpLANGUAGEcode(Sender,'ss');
kpLANGUAGEcode(Sender,'sk');
kpLANGUAGEcode(Sender,'sl');
kpLANGUAGEcode(Sender,'so');
kpLANGUAGEcode(Sender,'es');
kpLANGUAGEcode(Sender,'su');
kpLANGUAGEcode(Sender,'sw');
kpLANGUAGEcode(Sender,'sv');
kpLANGUAGEcode(Sender,'tl');
kpLANGUAGEcode(Sender,'tg');
kpLANGUAGEcode(Sender,'ta');
kpLANGUAGEcode(Sender,'tt');
kpLANGUAGEcode(Sender,'te');
kpLANGUAGEcode(Sender,'th');
kpLANGUAGEcode(Sender,'bo');
kpLANGUAGEcode(Sender,'ti');
kpLANGUAGEcode(Sender,'to');
kpLANGUAGEcode(Sender,'ts');
kpLANGUAGEcode(Sender,'tr');
kpLANGUAGEcode(Sender,'tk');
kpLANGUAGEcode(Sender,'tw');
kpLANGUAGEcode(Sender,'uk');
kpLANGUAGEcode(Sender,'ur');
kpLANGUAGEcode(Sender,'uz');
kpLANGUAGEcode(Sender,'vi');
kpLANGUAGEcode(Sender,'vo');
kpLANGUAGEcode(Sender,'cy');
kpLANGUAGEcode(Sender,'wo');
kpLANGUAGEcode(Sender,'xh');
kpLANGUAGEcode(Sender,'ji');
kpLANGUAGEcode(Sender,'yo');
kpLANGUAGEcode(Sender,'za');
kpLANGUAGEcode(Sender,'zu');
kpLANGUAGEcode(Sender,'zz');
kpLANGUAGEcode(Sender,'us');
kpLANGUAGEcode(Sender,'au');
kpLANGUAGEcode(Sender,'eu');
kpLANGUAGEcode(Sender,'uu');
kpLANGUAGEcode(Sender,'rx');
kpLANGUAGEcode(Sender,'i3');
kpLANGUAGEcode(Sender,'kp');
end;
end;
end;
end;
finally
end;
//operaturbo
try
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_operaturbo_message.STATE_ENABLED') <> False then
begin
if Chromium1.Browser <> nil then begin
RichEdit3.Lines.Text:='';
RichEdit3.Lines.LoadFromFile(ExtractFilePath(Application.ExeName) + '\conf\kitchenpages_operaturbo_message.STATE_ENABLED');
if (RichEdit3.Lines.Text <> EmptyStr) then begin
if (RichEdit3.Lines.IndexOf('0') <> -1) then begin
Chromium1.Browser.MainFrame.ExecuteJavaScript(
'var kpOPERATURBOMESSAGEcode=''0'';try{localStorage.setItem(''kitchenpages_operaturbo_message'',kpOPERATURBOMESSAGEcode);}catch(e){}' , 'about:blank', 0);
end;
if (RichEdit3.Lines.IndexOf('1') <> -1) then begin
Chromium1.Browser.MainFrame.ExecuteJavaScript(
'var kpOPERATURBOMESSAGEcode=''1'';try{localStorage.setItem(''kitchenpages_operaturbo_message'',kpOPERATURBOMESSAGEcode);}catch(e){}' , 'about:blank', 0);
end;
end;
end;
end;
finally
end;
end;
//{end december 2014 update for session and local storage cache}
end;
end;
procedure TMiniBrowserFrm.FormShow(Sender: TObject);
begin
Chromium1.CreateBrowser(CEFWindowParent1, '');
end;
procedure TMiniBrowserFrm.BrowserCreatedMsg(var aMessage : TMessage);
begin
CEFWindowParent1.UpdateSize;
NavControlPnl.Enabled := True;
//remarked lines below, for KitCAD i3 rX browser, by Jason
// AddURL(MINIBROWSER_HOMEPAGE);
// Chromium1.LoadURL(MINIBROWSER_HOMEPAGE);
end;
procedure TMiniBrowserFrm.AddURL(const aURL : string);
begin
if (URLCbx.Items.IndexOf(aURL) < 0) then URLCbx.Items.Add(aURL);
URLCbx.Text := aURL;
end;
procedure TMiniBrowserFrm.ShowDevToolsMsg(var aMessage : TMessage);
var
TempPoint : TPoint;
begin
TempPoint.x := (aMessage.wParam shr 16) and $FFFF;
TempPoint.y := aMessage.wParam and $FFFF;
ShowDevTools(TempPoint);
end;
procedure TMiniBrowserFrm.HideDevToolsMsg(var aMessage : TMessage);
begin
HideDevTools;
end;
procedure TMiniBrowserFrm.Inczoom1Click(Sender: TObject);
begin
Chromium1.IncZoomStep;
end;
procedure TMiniBrowserFrm.Openfile1Click(Sender: TObject);
begin
// This is a quick solution to load files. The file URL should be properly encoded.
if OpenDialog1.Execute then Chromium1.LoadURL('file:///' + OpenDialog1.FileName);
end;
procedure TMiniBrowserFrm.PopupMenu1Popup(Sender: TObject);
begin
if DevTools.Visible then
DevTools1.Caption := 'Hide DevTools'
else
DevTools1.Caption := 'Show DevTools';
end;
procedure TMiniBrowserFrm.Preferences1Click(Sender: TObject);
begin
PreferencesFrm.ProxyTypeCbx.ItemIndex := Chromium1.ProxyType;
PreferencesFrm.ProxyServerEdt.Text := Chromium1.ProxyServer;
PreferencesFrm.ProxyPortEdt.Text := inttostr(Chromium1.ProxyPort);
PreferencesFrm.ProxyUsernameEdt.Text := Chromium1.ProxyUsername;
PreferencesFrm.ProxyPasswordEdt.Text := Chromium1.ProxyPassword;
PreferencesFrm.ProxyScriptURLEdt.Text := Chromium1.ProxyScriptURL;
PreferencesFrm.ProxyByPassListEdt.Text := Chromium1.ProxyByPassList;
PreferencesFrm.HeaderNameEdt.Text := Chromium1.CustomHeaderName;
PreferencesFrm.HeaderValueEdt.Text := Chromium1.CustomHeaderValue;
if (PreferencesFrm.ShowModal = mrOk) then
begin
Chromium1.ProxyType := PreferencesFrm.ProxyTypeCbx.ItemIndex;
Chromium1.ProxyServer := PreferencesFrm.ProxyServerEdt.Text;
Chromium1.ProxyPort := strtoint(PreferencesFrm.ProxyPortEdt.Text);
Chromium1.ProxyUsername := PreferencesFrm.ProxyUsernameEdt.Text;
Chromium1.ProxyPassword := PreferencesFrm.ProxyPasswordEdt.Text;
Chromium1.ProxyScriptURL := PreferencesFrm.ProxyScriptURLEdt.Text;
Chromium1.ProxyByPassList := PreferencesFrm.ProxyByPassListEdt.Text;
Chromium1.CustomHeaderName := PreferencesFrm.HeaderNameEdt.Text;
Chromium1.CustomHeaderValue := PreferencesFrm.HeaderValueEdt.Text;
Chromium1.UpdatePreferences;
end;
end;
procedure TMiniBrowserFrm.Print1Click(Sender: TObject);
begin
Chromium1.Print;
end;
procedure TMiniBrowserFrm.PrintinPDF1Click(Sender: TObject);
begin
SaveDialog1.DefaultExt := 'pdf';
SaveDialog1.Filter := 'PDF files (*.pdf)|*.PDF';
if SaveDialog1.Execute and (length(SaveDialog1.FileName) > 0) then
Chromium1.PrintToPDF(SaveDialog1.FileName, Chromium1.DocumentURL, Chromium1.DocumentURL);
end;
procedure TMiniBrowserFrm.ConfigBtnClick(Sender: TObject);
var
TempPoint : TPoint;
begin
TempPoint.x := ConfigBtn.left;
TempPoint.y := ConfigBtn.top + ConfigBtn.Height;
TempPoint := ConfigPnl.ClientToScreen(TempPoint);
PopupMenu1.Popup(TempPoint.x, TempPoint.y);
end;
procedure TMiniBrowserFrm.CopyHTMLMsg(var aMessage : TMessage);
begin
Chromium1.RetrieveHTML;
end;
procedure TMiniBrowserFrm.CopyFramesIDsMsg(var aMessage : TMessage);
var
i : NativeUInt;
TempCount : NativeUInt;
TempArray : TCefFrameIdentifierArray;
TempString : string;
begin
TempCount := Chromium1.FrameCount;
if Chromium1.GetFrameIdentifiers(TempCount, TempArray) then
begin
TempString := '';
i := 0;
while (i < TempCount) do
begin
TempString := TempString + inttostr(TempArray[i]) + CRLF;
inc(i);
end;
clipboard.AsText := TempString;
end;
end;
procedure TMiniBrowserFrm.CopyFramesNamesMsg(var aMessage : TMessage);
var
TempSL : TStringList;
begin
try
TempSL := TStringList.Create;
if Chromium1.GetFrameNames(TStrings(TempSL)) then clipboard.AsText := TempSL.Text;
finally
FreeAndNil(TempSL);
end;
end;
procedure TMiniBrowserFrm.ShowResponseMsg(var aMessage : TMessage);
begin
if (length(FResponse) > 0) then MessageDlg(FResponse, mtInformation, [mbOk], 0);
end;
procedure TMiniBrowserFrm.WMMove(var aMessage : TWMMove);
begin
inherited;
if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted;
end;
procedure TMiniBrowserFrm.WMMoving(var aMessage : TMessage);
begin
inherited;
if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted;
end;
procedure TMiniBrowserFrm.Deczoom1Click(Sender: TObject);
begin
Chromium1.DecZoomStep;
end;
procedure TMiniBrowserFrm.DevTools1Click(Sender: TObject);
begin
if DevTools.Visible then
HideDevTools
else
ShowDevTools;
end;
procedure TMiniBrowserFrm.ShowDevTools(aPoint : TPoint);
begin
Splitter1.Visible := True;
DevTools.Visible := True;
DevTools.Width := Width div 4;
Chromium1.ShowDevTools(aPoint, DevTools);
end;
procedure TMiniBrowserFrm.ShowDevTools;
var
TempPoint : TPoint;
begin
TempPoint.x := low(integer);
TempPoint.y := low(integer);
ShowDevTools(TempPoint);
end;
procedure TMiniBrowserFrm.HideDevTools;
begin
Chromium1.CloseDevTools(DevTools);
Splitter1.Visible := False;
DevTools.Visible := False;
DevTools.Width := 0;
end;
procedure TMiniBrowserFrm.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
// if crm.Browser <> nil then
// dcef1 crm.Browser.ShowDevTools;
//dcef3
// actDevTool.Checked := not actDevTool.Checked;
// debug.Visible := actDevTool.Checked;
// Splitter1.Visible := actDevTool.Checked;
// if actDevTool.Checked then
// begin
// if not FDevToolLoaded then
// begin
// debug.Load(crm.Browser.Host.GetDevToolsUrl(True));
// FDevToolLoaded := True;
// end;
// end;
ShowDevTools();
end;
procedure TMiniBrowserFrm.Timer2Timer(Sender: TObject);
begin
Timer2.Enabled := False;
// if crm.Browser <> nil then
if (Chromium1.Browser <> nil) then
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\usr_rX_js.STATE_DISABLED') <> True then
begin
// crm.Browser.MainFrame.ExecuteJavaScript
Chromium1.Browser.MainFrame.ExecuteJavaScript(
'var ChromeBrowser = ''' + ExtractFileName(Application.ExeName) + ''';try{ ChromeBrowserLoadkp2file(); }catch(e){}' , 'about:blank', 0);
end;
//2015
// if crm.Browser <> nil then
if (Chromium1.Browser <> nil) then
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\usr_rX_js.STATE_DISABLED') <> False then
begin
// crm.Browser.MainFrame.ExecuteJavaScript
Chromium1.Browser.MainFrame.ExecuteJavaScript(
'var ChromeBrowser = ''' + ExtractFileName(Application.ExeName) + ''';try{ ChromeBrowserLoadkp2filept2(); }catch(e){}' , 'about:blank', 0);
end;
end;
procedure TMiniBrowserFrm.Timer3Timer(Sender: TObject);
begin
Timer3.Enabled := False;
if FileExists(ParamStr(3)) <> False then
begin
RichEdit2.Lines.Text := 'var kp2loaddata = '''';';
//2015
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\usr_rX_js.STATE_DISABLED') <> True then
RichEdit2.Lines.SaveToFile( ParamStr(3) );
end;
end;
procedure TMiniBrowserFrm.Timer4Timer(Sender: TObject);
begin
Timer4.Enabled := False;
//2015 update for DVD CDR media
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\usr_rX_js.STATE_DISABLED') <> False then
// if crm.Browser <> nil then
if Chromium1 <> nil then
// crm.Browser.MainFrame.ExecuteJavaScript(
Chromium1.Browser.MainFrame.ExecuteJavaScript(
RichEdit2.Lines.Text + #13#10 + 'try{ ChromeBrowserLoadkp2filept2(); }catch(e){}', 'about:blank', 0);
end;
procedure TMiniBrowserFrm.Timer5Timer(Sender: TObject);
begin
Timer5.Enabled := False;
FormCreate(Sender);
end;
procedure TMiniBrowserFrm.Timer6Timer(Sender: TObject);
begin
Timer6.Enabled := False;
//2018 moved OPEN function to here as to prevent EOSError 1400 / EOSError 5
if OpenDialog1.Execute then
begin
if FileExists(OpenDialog1.FileName) then
begin
if ParamStr(1) <> '' then
begin
// edAddress.Text := ExtractFilePath(Application.ExeName) + '/' + ParamStr(1);
// if FileExists(ParamStr(1)) <> False then
// begin
// edAddress.Text := ParamStr(1);
// end;
if FileExists(OpenDialog1.FileName) <> False then
begin
RichEdit1.Lines.Text := '';
try RichEdit1.Lines.SaveToFile( ParamStr(3) );
except
try RichEdit1.Lines.SaveToFile( ParamStr(2) );
except
end;
end;
RichEdit1.Lines.LineBreak := '[!EOL!]\'#13#10;
try RichEdit1.Lines.LoadFromFile( OpenDialog1.FileName );
except
end;
if RichEdit1.Lines.IndexOf('[KitCAD2]') <> -1 then
begin
if AnsiPos('<textarea',tolower(richedit1.lines.text)) <> 0 then
begin
RichEdit1.Lines.BeginUpdate();
RichEdit1FindText(Sender, '[KitCAD2]');
//RichEdit1.SelStart := AnsiPos('[KitCAD2]',RichEdit1.Lines.Text)-1;
//RichEdit1.SelLength := Length(RichEdit1.Lines.Text) - AnsiPos('[KitCAD2]',ToLower(RichEdit1.Lines.Text));
RichEdit1.SetSelText('');
RichEdit1.Lines.EndUpdate();
RichEdit1.SelStart := 0;
RichEdit1.SelLength := 0;
if AnsiPos('<\/textarea',ToLower(RichEdit1.Lines.Text)) <> 0 then
begin
RichEdit1.Lines.BeginUpdate();
RichEdit1FindText(Sender, '<\/textarea>');
//RichEdit1.SelStart := AnsiPos('',ToLower(RichEdit1.Lines.Text));
//RichEdit1.SelLength := Length(RichEdit1.Lines.Text) - AnsiPos('',ToLower(RichEdit1.Lines.Text));
RichEdit1.Lines.Text := RichEdit1.SelText;
RichEdit1.Lines.EndUpdate();
RichEdit1.SelStart := 0;
RichEdit1.SelLength := 0;
end;
end;
//makesafe
RichEdit1.Lines.Text := WideStringReplace(RichEdit1.Lines.Text, '\', '\\', [rfReplaceAll]);
RichEdit1.Lines.Text := WideStringReplace(RichEdit1.Lines.Text, '[!EOL!]\\', '[!EOL!]\', [rfReplaceAll]);
RichEdit1.Lines.Text := WideStringReplace(RichEdit1.Lines.Text, '[!EOL!]\[!EOL!]\', '[!EOL!]\', [rfReplaceAll]);
RichEdit1.Lines.Text := WideStringReplace(RichEdit1.Lines.Text, '"', '', [rfReplaceAll]);
RichEdit1.Lines.Text := WideStringReplace(RichEdit1.Lines.Text, '''', '', [rfReplaceAll]);
RichEdit2.Lines.Text := 'var kp2loaddata = '''+ RichEdit1.Lines.Text + ''';';
//Timer2.Interval := 3333;
//2015 timer4
Timer4.Enabled := True;
Timer2.Enabled := True;
Timer3.Enabled := True;
try
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\usr_rX_js.STATE_DISABLED') <> True then
RichEdit2.Lines.SaveToFile( ParamStr(3) );
except
try
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\usr_rX_js.STATE_DISABLED') <> True then
RichEdit2.Lines.SaveToFile( ParamStr(2) );
except
end;
end;
//finally
//end;
end;
end;
Timer2.Enabled := True;
end;
end;
end;
end;
//procedure TMainForm.crmBeforePopup(Sender: TObject; const browser: ICefBrowser;
// const frame: ICefFrame; const targetUrl, targetFrameName: ustring;
// var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
// var client: ICefClient; var settings: TCefBrowserSettings;
// var noJavascriptAccess: Boolean; out Result: Boolean);
procedure TMiniBrowserFrm.crmBeforePopup(Sender: TObject; const browser: ICefBrowser;
const frame: ICefFrame; const targetUrl, targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
begin
//targetUrl := url;//not v3
// prevent popup
// crm.Load(targetUrl);
// Result := True;
{remarked above, next lines added by Jason}
//SAVE FILE AS SOURCE DUMP
if (targetUrl = 'http://cgi-bin/kitcadi3_kp2.cgi') or
(targetUrl = 'https://cgi-bin/kitcadi3_kp2.cgi') or
(targetUrl = 'http://localhost/cgi-bin/kitcadi3_kp2.cgi') or
(targetUrl = 'https://localhost/cgi-bin/kitcadi3_kp2.cgi') or
(targetUrl = 'http://www.kitchenpages.com/cgi-bin/kitcadi3_kp2.cgi') or
(targetUrl = 'https://secure.netsolhost.com/www.kitchenpages.com/cgi-bin/kitcadi3_kp2.cgi') then
begin
browser.MainFrame.ViewSource();
//browser.MainFrame.ViewSource(); //dcef3
Result := True;
end;
//OPEN DIALOG
if (targetUrl = 'http://www.kitchenpages.com/cgi-bin/kitcadi3_rXopen.cgi') or
(targetUrl = 'https://secure.netsolhost.com/www.kitchenpages.com/cgi-bin/kitcadi3_rXopen.cgi') then
begin
//2018 moved this code to Timer6
Timer6.Enabled := True;
Result := True;
end;
//OPEN SECURE APPLICATION - start NOV 2014
//insert here for POPUP windows
//add ShellAPI and Character.pas or ShellAPI and Character.hpp to header
try
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\secure_frame_browser.STATE_DISABLED') <> True then
if Result <> True then
if (AnsiPos( 'http:',ToLower(targetURL)) <> 0) or (AnsiPos( 'https:',ToLower(targetURL)) <> 0) then
begin
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\browser.bat') <> False then
begin
ShellExecute(0, PChar('open'), PChar(ExtractFilePath(Application.ExeName) + '\conf\browser.bat'),
PChar('"' + targetURL + '" "1"'), PChar(ExtractFilePath(Application.ExeName) + '\conf\'), SW_SHOWMINIMIZED);
Result := True;
end
else
begin
ShellExecute(0, PChar('open'), PChar(targetURL), 0, nil, SW_SHOW);
Result := True;
end;
end;
finally
end;
//end NOV 2014
end;
procedure TMiniBrowserFrm.RichEdit1FindText (Sender: TObject; const FindtheText: ustring);
var
I, J, PosReturn, Skip: Integer;
begin
for I := 0 to RichEdit1.Lines.Count do
begin
PosReturn := AnsiPos(FindtheText,RichEdit1.Lines[I]);
if PosReturn <> 0 then {Found}
begin
Skip := 0;
for J := 0 to I - 1 do
Skip := Skip + Length(RichEdit1.Lines[J]);
Skip := Skip + (I*2);
Skip := Skip + PosReturn - 1;
// RichEdit1.SetFocus;
RichEdit1.SelStart := 0;//Skip;
RichEdit1.SelLength := Skip;//Length(RichEdit1.Lines.Text);
// application.MessageBox(PChar(RichEdit1.SelText),nil,0);
Break;
end;
end;
end;
//{start december 2014 update for session and local storage cache}
procedure TMiniBrowserFrm.RichEdit3FindText (Sender: TObject; const FindtheText: ustring);
var
I, J, PosReturn, Skip: Integer;
begin
for I := 0 to RichEdit3.Lines.Count do
begin
PosReturn := AnsiPos(FindtheText,RichEdit3.Lines[I]);
if PosReturn <> 0 then {Found}
begin
Skip := 0;
for J := 0 to I - 1 do
Skip := Skip + Length(RichEdit3.Lines[J]);
Skip := Skip + (I*2);
Skip := Skip + PosReturn - 1;
// RichEdit1.SetFocus;
RichEdit1.SelStart := 0;//Skip;
RichEdit1.SelLength := Skip;//Length(RichEdit1.Lines.Text);
// application.MessageBox(PChar(RichEdit1.SelText),nil,0);
Break;
end;
end;
end;
//{end december 2014 update for session and local storage cache}
procedure TMiniBrowserFrm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Timer3.Enabled <> False then Timer3Timer(Sender);
end;
procedure TMiniBrowserFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
// avoid AV when closing application
// if CefSingleProcess then
// begin
Chromium1.LoadURL('about:blank');
// debug.LoadURL('about:blank');
// while //debug.Browser.IsLoading or
// Chromium1.Browser.IsLoading do
// Application.ProcessMessages;
// end;
//2018 Chromium1.CloseBrowser(); True to force close
// the following did not work as expected...
//Chromium1.CloseBrowser(False);
//added to destroy the parent browser window, prevent EOERROR 0x0..010
CanClose := True;
end;
procedure TMiniBrowserFrm.FormCreate(Sender: TObject);
var
RichEdit1Lines: TStrings;
RichEdit1LinesLineBreak: String;
ConfigPath: String;
begin
{Security}
ConfigPath := ExtractFilePath(Application.ExeName) + '\conf\';
try
if FileExists(ConfigPath+'Plugins.STATE_DISABLED') <> False then //crm.
Chromium1.Options.Plugins := STATE_DISABLED;
finally
end;
try
if FileExists(ConfigPath+'Plugins.STATE_ENABLED') <> False then //crm.
Chromium1.Options.Plugins := STATE_ENABLED;
finally
end;
try
if FileExists(ConfigPath+'UniversalAccessFromFileUrls.STATE_DISABLED') <> False then //crm.
Chromium1.Options.UniversalAccessFromFileUrls := STATE_DISABLED;
finally
end;
try
if FileExists(ConfigPath+'UniversalAccessFromFileUrls.STATE_ENABLED') <> False then //crm.
Chromium1.Options.UniversalAccessFromFileUrls := STATE_ENABLED;
finally
end;
try
if FileExists(ConfigPath+'FileAccessFromFileUrls.STATE_DISABLED') <> False then //crm.
Chromium1.Options.FileAccessFromFileUrls := STATE_DISABLED;
finally
end;
try
if FileExists(ConfigPath+'FileAccessFromFileUrls.STATE_ENABLED') <> False then //crm.
Chromium1.Options.FileAccessFromFileUrls := STATE_ENABLED;
finally
end;
try
if FileExists(ConfigPath+'WebSecurity.STATE_DISABLED') <> False then //crm.
Chromium1.Options.WebSecurity := STATE_DISABLED;
finally
end;
try
if FileExists(ConfigPath+'WebSecurity.STATE_ENABLED') <> False then //crm.
Chromium1.Options.WebSecurity := STATE_ENABLED;
finally
end;
try
if FileExists(ConfigPath+'Webgl.STATE_DISABLED') <> False then //crm.
Chromium1.Options.Webgl := STATE_DISABLED;
finally
end;
try
if FileExists(ConfigPath+'Webgl.STATE_ENABLED') <> False then //crm.
Chromium1.Options.Webgl := STATE_ENABLED;
finally
end;
try
if FileExists(ConfigPath+'LocalStorage.STATE_DISABLED') <> False then //crm.
Chromium1.Options.LocalStorage := STATE_DISABLED;
finally
end;
try
if FileExists(ConfigPath+'LocalStorage.STATE_ENABLED') <> False then //crm.
Chromium1.Options.LocalStorage := STATE_ENABLED;
finally
end;
try
if FileExists(ConfigPath+'ApplicationCache.STATE_DISABLED') <> False then //crm.
Chromium1.Options.ApplicationCache := STATE_DISABLED;
finally
end;
try
if FileExists(ConfigPath+'ApplicationCache.STATE_ENABLED') <> False then //crm.
Chromium1.Options.ApplicationCache := STATE_ENABLED;
finally
end;
try
if FileExists(ConfigPath+'Javascript.STATE_DISABLED') <> False then //crm.
Chromium1.Options.Javascript := STATE_DISABLED;
finally
end;
try
if FileExists(ConfigPath+'Javascript.STATE_ENABLED') <> False then //crm.
Chromium1.Options.Javascript := STATE_ENABLED;
finally
end;
//try
//if FileExists(ConfigPath+'Java.STATE_DISABLED') <> False then //crm.
//Chromium1.Options.Java := STATE_DISABLED;
//finally
//end;
//try
//if FileExists(ConfigPath+'Java.STATE_ENABLED') <> False then //crm.
//Chromium1.Options.Java := STATE_ENABLED;
//finally
//end;
try
if FileExists(ConfigPath+'Databases.STATE_DISABLED') <> False then //crm.
Chromium1.Options.Databases := STATE_DISABLED;
finally
end;
try
if FileExists(ConfigPath+'Databases.STATE_ENABLED') <> False then //crm.
Chromium1.Options.Databases := STATE_ENABLED;
finally
end;
try
if FileExists(ConfigPath+'TabToLinks.STATE_DISABLED') <> False then //crm.
Chromium1.Options.TabToLinks := STATE_DISABLED;
finally
end;
try
if FileExists(ConfigPath+'TabToLinks.STATE_ENABLED') <> False then //crm.
Chromium1.Options.TabToLinks := STATE_ENABLED;
finally
end;
//try
//if FileExists(ConfigPath+'CaretBrowsing.STATE_DISABLED') <> False then //crm.
//Chromium1.Options.CaretBrowsing := STATE_DISABLED;
//finally
//end;
//try
//if FileExists(ConfigPath+'CaretBrowsing.STATE_ENABLED') <> False then //crm.
//Chromium1.Options.CaretBrowsing := STATE_ENABLED;
//finally
//end;
//try
//if FileExists(ConfigPath+'AcceleratedCompositing.STATE_DISABLED') <> False then //crm.
//Chromium1.Options.AcceleratedCompositing := STATE_DISABLED;
//finally
//end;
//try
//if FileExists(ConfigPath+'AcceleratedCompositing.STATE_ENABLED') <> False then //crm.
//Chromium1.Options.AcceleratedCompositing := STATE_ENABLED;
//finally
//end;
//{start december 2014 update for UserStyleSheetLocation}
//UserStyleSheetLocation
//try
//if FileExists(ConfigPath+'UserStyleSheetLocation.STATE_ENABLED') <> False then
// RichEdit3.Lines.LoadFromFile(ConfigPath+'UserStyleSheetLocation.STATE_ENABLED');
// if RichEdit3.Lines.Text <> '' then
// crm.UserStyleSheetLocation:=RichEdit3.Lines.Text;
//finally
//end;
//{end december 2014 update for UserStyleSheetLocation}
//FLoading := False;
{ modified by Jason to load from command line, and show webkit}
if ParamStr(2) = 'webkit' then
begin
Timer1.Enabled := True;
Timer2.Enabled := True;
end;
if ParamStr(3) = 'webkit' then
begin
Timer1.Enabled := True;
Timer2.Enabled := True;
end;
if ParamStr(4) = 'webkit' then
begin
Timer1.Enabled := True;
Timer2.Enabled := True;
end;
if ParamStr(1) <> '' then
begin
URLCbx.Text := ExtractFilePath(Application.ExeName) + '/' + ParamStr(1);
if FileExists(ParamStr(1)) <> False then
begin
URLCbx.Text := ParamStr(1);
end;
if FileExists(ParamStr(3)) <> False then
begin
RichEdit2.Lines.Text := 'var kp2loaddata = '''';';
try RichEdit2.Lines.SaveToFile( ParamStr(3) );
except
end;
end;
if FileExists(ParamStr(2)) <> False then
begin
RichEdit1.Lines.LineBreak := '[!EOL!]\'#13#10;
try RichEdit1.Lines.LoadFromFile( ParamStr(2) );
except
end;
if RichEdit1.Lines.IndexOf('[KitCAD2]') <> -1 then
begin
if AnsiPos('<textarea',ToLower(RichEdit1.Lines.Text)) <> 0 then
begin
RichEdit1.Lines.BeginUpdate();
RichEdit1FindText(Sender, '[KitCAD2]');
//RichEdit1.SelStart := AnsiPos('[KitCAD2]',RichEdit1.Lines.Text)-1;
//RichEdit1.SelLength := Length(RichEdit1.Lines.Text) - AnsiPos('[KitCAD2]',RichEdit1.Lines.Text);
RichEdit1.SetSelText('');
RichEdit1.Lines.EndUpdate();
RichEdit1.SelStart := 0;
RichEdit1.SelLength := 0;
if AnsiPos('<\/textarea',ToLower(RichEdit1.Lines.Text)) <> 0 then
begin
RichEdit1.Lines.BeginUpdate();
RichEdit1FindText(Sender, '<\/textarea>');
//RichEdit1.SelStart := AnsiPos('</textarea>',ToLower(RichEdit1.Lines.Text));
//RichEdit1.SelLength := Length(RichEdit1.Lines.Text) - AnsiPos('</textarea>',ToLower(RichEdit1.Lines.Text));
RichEdit1.Lines.Text := RichEdit1.SelText;
RichEdit1.Lines.EndUpdate();
RichEdit1.SelStart := 0;
RichEdit1.SelLength := 0;
end;
end;
//makesafe
RichEdit1.Lines.Text := WideStringReplace(RichEdit1.Lines.Text, '\', '\\', [rfReplaceAll]);
RichEdit1.Lines.Text := WideStringReplace(RichEdit1.Lines.Text, '[!EOL!]\\', '[!EOL!]\', [rfReplaceAll]);
RichEdit1.Lines.Text := WideStringReplace(RichEdit1.Lines.Text, '[!EOL!]\[!EOL!]\', '[!EOL!]\', [rfReplaceAll]);
RichEdit1.Lines.Text := WideStringReplace(RichEdit1.Lines.Text, '"', '', [rfReplaceAll]);
RichEdit1.Lines.Text := WideStringReplace(RichEdit1.Lines.Text, '''', '', [rfReplaceAll]);
RichEdit2.Lines.Text := 'var kp2loaddata = '''+ RichEdit1.Lines.Text + ''';';
//2015 timer4
Timer4.Enabled := True;
try
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\usr_rX_js.STATE_DISABLED') <> True then
RichEdit2.Lines.SaveToFile( ParamStr(3) );
except
try
if FileExists(ExtractFilePath(Application.ExeName) + '\conf\usr_rX_js.STATE_DISABLED') <> True then
RichEdit2.Lines.SaveToFile( ParamStr(2) );
except
end;
end;
Timer3.Enabled := True;
end;
end;
Chromium1.Browser.MainFrame.LoadUrl(URLCbx.Text);
Timer2.Enabled := True;
Abort;
end;
{ if FindCmdLineSwitch('webkit') then}
end;
procedure TMiniBrowserFrm.FormCreator(Sender: TObject);
begin
Timer5.Enabled := True;
end;
//{start december 2014 update for language 2-letter code test}
procedure TMiniBrowserFrm.kpLANGUAGEcode(Sender: TObject; const LANGUAGE: AnsiString);
begin
if (RichEdit3.Lines.IndexOf(LANGUAGE) <> -1) then begin
Chromium1.Browser.MainFrame.ExecuteJavaScript(
'var kpLANGUAGEcode=''' + LANGUAGE + ''';try{localStorage.setItem(''kitchenpages_language'',kpLANGUAGEcode);}catch(e){}' , 'about:blank', 0);
end;
end;
//{end december 2014 update for language 2-letter code test}
//2018
procedure TMiniBrowserFrm.Chromium1Close(Sender: TObject;
const browser: ICefBrowser; out Result: Boolean);
begin
//added to destroy the parent browser window, prevent EOERROR 0x0..010
// PostMessage(Handle, CEFBROWSER_DESTROY, 0, 0);
// Chromium1.Destroy();
//PostMessage(browser.GetWindowHandle(), WM_CLOSE, 0, 0);
//PostMessage(Handle, WM_CLOSE, 0, 0);
Result := True;
end;
end.
Copyright 2015-2018, all rights reserved. License.