How to disable image loading on ChromiumWebBrowser? - cefsharp

I'm using ChromiumWebBrowser in my project, but I don't need the browser load images. I tried to find in CefSettings but don't found anything. so how to disable load images?

You can use disable-image-loading in CefCommandLineArgs. It works for me.
public BrowserForm() {
InitializeComponent();
var settings = new CefSettings();
settings.CefCommandLineArgs.Add("disable-image-loading", "1");
CefSharp.Cef.Initialize(settings);
browser = new ChromiumWebBrowser("") {
Dock = DockStyle.Fill,
};
Controls.Add(browser);
}

Related

Xamarin Forms: Pause the video or audio playing in webview programattically

I am using custom webview for playing video and audio. I need to pause the video when clicking the back button from the video or audio page. I tried the below solution from this thread but it not working.
string pausefunctionString = #"var videos = document.querySelectorAll('video');
[].forEach.call(videos, function(video) { video.pause(); });
";
web_view.Eval(pausefunctionString);
My data is in 2 formats:
Video or audio link alone.
HTML data having multiple video links.
The above solution is not working for ios and windows in both formats. But it is working for android when the source of the webview is a video URL. When the source is an HTML data, this solution is not working in android.
For parsing the HTML data I am using the below code:
string htmlData = "htmldata";
var htmlSource = new HtmlWebViewSource();
htmlSource.Html = htmlData;
advanced_web_view.Source = htmlSource;
Also, I need a transparent background for my webview. I tried the following 2 codes but not getting a transparent background.
//code1
this.BackgroundColor = UIColor.Clear;
//code2
this.Opaque = false;
this.BackgroundColor = Color.Transparent.ToUIColor();
UPDATE
I have solved the video or audio pausing issue on ios in an easy tricky way.
I just set the webview source or Url value to a blank data like below. So when I go to another page from the video page, the video is automatically stopping.
web_view.Source = "";
web_view.Url= "";
This method is only working for ios; for android and windows, this approach has no effect. So could you please suggest a method for pausing video in android and windows?
My data is in 2 formats:
Video or audio link alone.
HTML data having video links.
The below code is working for android when the source of the webview is a video or audio URL alone. When the source is an HTML data, this solution is not working in android.
string pausefunctionString = #"var videos = document.querySelectorAll('video');
[].forEach.call(videos, function(video) { video.pause(); });
";
web_view.Eval(pausefunctionString);
Conclusion
Video or audio pausing is not working for windows on both data formats(mentioned above), need a solution for this.
For Android, When the source is an HTML data, video is not pausing, need a solution for this.
I think we can forget the video pausing on the ios platform.
I am also attaching an updated file of different data formats.
You need to invoke the JS code in custom renderer
in custom webview
public Action<string> EvaluateJS;
public void OnEvaluate(string script)
{
EvaluateJS(script);
}
in Custom Renderer
protected override void OnElementChanged(ElementChangedEventArgs<MyWebView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
var config = new WKWebViewConfiguration();
config.AllowsInlineMediaPlayback = true;
wkWebView = new WKWebView(Frame, config);
SetNativeControl(wkWebView);
}
if (e.NewElement != null)
{
Control.LoadRequest(new NSUrlRequest(new NSUrl(Element.Url)));
Element.EvaluateJS += (script) =>
{
wkWebView.EvaluateJavaScript(script, (result, error) =>
{
});
};
}
}
Usage
private void Button_Clicked(object sender, EventArgs e)
{
string pausefunctionString = #"var videos = document.querySelectorAll('video');
[].forEach.call(videos, function(video) { video.pause(); });
";
web_view.EvaluateJS(pausefunctionString);
}

Xamarin Forms Load Resources on startup

I have an Xamarin Forms app with MvvmCross for Android and IOS and I would like to add a dark theme. My idea was to have to dictionaries with the ressources for either the dark or the light theme and load the one I need on startup.
I added this after I registered the dependencies in my MvxApplication:
if (Mvx.IoCProvider.Resolve<ISettingsManager>().Theme == AppTheme.Dark)
{
Application.Current.Resources.Add(new ColorsDark());
}
else
{
Application.Current.Resources.Add(new ColorsLight());
}
ColorsDark and ColorsLight are my ResourceDictionary. After that i can see the new Dictionary under Application.Current.Resources.MergedDictionaries but the controls can't find the resources as it seems. However it does work when I add it to the App.xaml
<ResourceDictionary Source="Style/ColorsDark.xaml" />
Do I have to put move that another part in the code or is that a wrong approach at all?
Personally don't like this approach at all. What i do: have a static class with all the colors, sizes etc. defined in static fields. At app startup or at app reload after changing skin just call ex: UiSettings.Init() for this ui definitions static class, like follows:
public static class UiSettings
{
public static Init()
{
if (Settings.AppSettings.Skin=="butterfly")
{
ColorButton = Color.Blue;
TitleSize= 12.0;
}
else
if (Settings.AppSettings.Skin=="yammy")
{
ColorButton = Color.Red;
if (Core.IsAndroid)
ButtonsMargin = new Thickness(0.5,0.6,0.7,0.8);
}
// else just use default unmodified field default values
}
public static Color ColorButton = Color.Green;
public static Thickness ButtonsMargin = new Thickness(0.3,0.3,0.2,0.2);
public static double TitleSize= 14.0;
}
in XAML use example:
Color= "{x:Static xam:UiSettings.ColorProgressBack}"
in code use example:
Color = UiSettings.ColorProgressBack;
UPDATE:
Remember that if you access a static class from different assemblies it is possible that you will access a fresh copy of it with default values where Init() didn't happen, if you face such case call Init() from this assembly too.
If you want something to load up when your app loads then you have to code it in App.xaml.cs
protected override void OnStart ()
{
if (Mvx.IoCProvider.Resolve<ISettingsManager>().Theme == AppTheme.Dark)
{
Application.Current.Resources.Add(new Xamarin.Forms.Style(typeof(ContentPage))
{
ApplyToDerivedTypes = true,
Setters = {
new Xamarin.Forms.Setter { Property = ContentPage.BackgroundImageProperty, Value = "bkg7.png"},
}
});
}
else
{
Application.Current.Resources.Add(new Xamarin.Forms.Style(typeof(ContentPage))
{
ApplyToDerivedTypes = true,
Setters = {
new Xamarin.Forms.Setter { Property = ContentPage.BackgroundImageProperty, Value = "bkg7.png"},
}
});
}
}
In this code I'm setting the BackgroungImage of all of my pages. Hope you'll get the idea from this code.

Qt installer framework: remove radio buttons from uninstaller

I have created a simple installer for our product with only 1 component and no remote repositories manager.
When I start the uninstaller, the introduction page shows 3 radio buttons:
Package manager
Update components
Remove all components
I need only the third one, so I checked this documentation:
http://doc-snapshot.qt-project.org/qtifw-master/noninteractive.html
As I have understood and being unable to hide the buttons, I added this to my install.qs file:
function Controller()
{
}
Controller.prototype.IntroductionPageCallback = function()
{
gui.clickButton(buttons.NextButton);
}
This should auto-click Next on the introduction page so it should go directly to the uninstall page.
Nothing happens, what ever I write in the Controller functions, the introduction page shows the 3 radio buttons. I added some messagebox in the function and they are never called.
Somebody knows how to solve it ?
I think I have 2 working solutions.
First solution, if you want to have a single page uninstaller:
You need to create a Controller like the one you started before:
function Controller() {
if (installer.isUninstaller()) {
installer.setDefaultPageVisible(QInstaller.Introduction, false);
installer.setDefaultPageVisible(QInstaller.ComponentSelection, false);
installer.setDefaultPageVisible(QInstaller.LicenseCheck, false);
}
}
This will disable all pages in the classic install/uninstall workflow. Make sure to check you're in uninstall mode.
If you want a 2 pages uninstaller:
function Controller()
{
}
Controller.prototype.IntroductionPageCallback = function()
{
if (installer.isUninstaller()) {
// Get the current wizard page
var widget = gui.currentPageWidget();
if (widget != null) {
// Don't show buttons because we just want to uninstall the software
widget.findChild("PackageManagerRadioButton").visible = false;
widget.findChild("UpdaterRadioButton").visible = false;
widget.findChild("UninstallerRadioButton").visible = false;
}
}
}
Bonus
In installer mode, select by default "I accept" the Licence Agreement. Seriously, who doesn't?
Controller.prototype.LicenseAgreementPageCallback = function()
{
var widget = gui.currentPageWidget();
if (widget != null) {
widget.AcceptLicenseRadioButton.checked = true;
}
}

Flex Mobile 4.6 StageVideo not removing from stage

When I instantiate a new StageVideo instsance with stage.stageVideos[0] everything works great, but when i leave my view that's displaying the video it sticks on the stage. So when i goto another view it's still showing on the stage in the background. I tried setting sv = null, removing event listeners...etc.
I've created a StageVideoDisplay class which is instantiated in mxml like: and on view initialization i call a play() method:
if ( _path )
{
//...
// Connections
_nc = new NetConnection();
_nc.connect(null);
_ns = new NetStream(_nc);
_ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
_ns.client = this;
// Screen
_video = new Video();
_video.smoothing = true;
// Video Events
// the StageVideoEvent.STAGE_VIDEO_STATE informs you whether
// StageVideo is available
stage.addEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY,
onStageVideoState);
// in case of fallback to Video, listen to the VideoEvent.RENDER_STATE
// event to handle resize properly and know about the acceleration mode running
_video.addEventListener(VideoEvent.RENDER_STATE, videoStateChange);
//...
}
On video stage event:
if ( stageVideoInUse ) {
try {
_rc = new Rectangle(0,0,this.width,this.height);
_sv.viewPort = _rc;
} catch (e:Error) {}
} else {
try {
_video.width = this.width;
_video.height = this.height;
} catch (e:Error) {}
}
And on stage video availability event:
protected function toggleStageVideo(on:Boolean):void
{
// To choose StageVideo attach the NetStream to StageVideo
if (on)
{
stageVideoInUse = true;
if ( _sv == null )
{
try {
_sv = stage.stageVideos[0];
_sv.addEventListener(StageVideoEvent.RENDER_STATE, stageVideoStateChange);
_sv.attachNetStream(_ns);
_sv.depth = 1;
} catch (e:Error) {}
}
if (classicVideoInUse)
{
// If you use StageVideo, remove from the display list the
// Video object to avoid covering the StageVideo object
// (which is always in the background)
stage.removeChild ( _video );
classicVideoInUse = false;
}
} else
{
// Otherwise attach it to a Video object
if (stageVideoInUse)
stageVideoInUse = false;
classicVideoInUse = true;
try {
_video.attachNetStream(_ns);
stage.addChildAt(_video, 0);
} catch (e:Error) {}
}
if ( !played )
{
played = true;
_ns.play(path);
}
}
What happens is in the view when i navigator.popView(), the stageVideo remains on the stage, even in other views, and when returning to that view to play a different stream the same stream is kind of "burned" on top. I can not figure out a way to get rid of it! Thanks in advance!
In Flash Player 11, Adobe added the dispose() method to the NetStream class.
This is useful to clear the Video or StageVideo object when you're done with it.
When you call the dispose() method at runtime, you may get an exception indicating that there is no property named dispose on the NetStream object.
This occurs because Flash Builder is not compiling the app with the proper SWF version. To fix that, just add this to your compiler directives:
-swf-version=13
In the new Flash Builder 4.7, we hopefully won't have to specify the SWF version to use the newer Flash Player features.
This seems to be the best solution, but if you can't use Flash 11 (or the latest Adobe AIR), some other work arounds would be:
set the viewPort of stage video object to a rectangle that has width=0 and height=0
since stage video appears underneath your app, you can always cover the viewport (with a background color or some DisplayObject)
Ok the issue was actually that, even though it seemed like stage video was in use since i got the "Accelerated" message in status, that it was actually the video render even running and classic video was actually in use. The only thing I needed to do was add stage.removeChild( _video ) to the close() event in the class!!

To bring the IE window in front of the Screen

I am creating new IE browser instance dynamically, and opening a aspx page from there. Everything works fine , but the browser is not popping in the Front of the screen .Able to see the Aspx page in the task bar when I click it from there it comes to the Front . How to bring that page in front of all the Screen as soon as IE is created.
I have pasted the code I used to create new IE instance.
public class IEInstance
{
public SHDocVw.InternetExplorer IE1;
public void IEInstanceCls(string check)
{
IE1 = new SHDocVw.InternetExplorer();
object Empty = 0;
string urlpath = " ";
urlpath = "http://localhost/TestPage.aspx?";
object URL = urlpath;
IE1.Top = 260;
IE1.Left = 900;
IE1.Width = 390;
IE1.Height = 460;
IE1.StatusBar = false;
IE1.ToolBar = 0;
IE1.MenuBar = false;
IE1.Visible = true;
IE1.Navigate2(ref URL, ref Empty, ref Empty, ref Empty, ref Empty);
}
}
Help me to solve this problem.
Thank You
The Internet explorer object has an HWND property, which is the handle to a window. You can use that to bring the window to the front like:
SetForegroundWindow((IntPtr)IE1.HWND);
You'll need to import SetForgroundWindow windows API like this near the top of your file.
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);

Resources