package eu.ydp.empiria.player.client.module.media.html5;

import static eu.ydp.gwtutil.client.util.UserAgentChecker.isUserAgent;

import com.google.gwt.event.logical.shared.AttachEvent;
import com.google.gwt.event.logical.shared.AttachEvent.Handler;
import com.google.inject.Inject;
import com.google.inject.Provider;

import eu.ydp.empiria.player.client.controller.extensions.internal.media.html5.HTML5VideoMediaExecutor;
import eu.ydp.empiria.player.client.module.media.html5.reattachhack.HTML5VideoReattachHack;
import eu.ydp.empiria.player.client.util.events.bus.EventsBus;
import eu.ydp.gwtutil.client.util.UserAgentChecker.MobileUserAgent;
import eu.ydp.gwtutil.client.util.UserAgentChecker.UserAgent;

public class AttachHandlerImpl implements Handler {

	private HTML5VideoMediaExecutor mediaExecutor;
	private HTML5VideoMediaWrapper mediaWrapper;
	private boolean firstTimeInitialization = true;

	@Inject
	protected EventsBus eventsBus;

	@Inject
	Provider<HTML5VideoReattachHack> html5VideoReattachHackProvider;

	@Override
	public void onAttachOrDetach(AttachEvent event) {
		if (firstTimeInitialization) {
			firstTimeInitialization = false;
		} else if (event.isAttached() && requiresReattachment()) {
			HTML5VideoReattachHack html5VideoReattachHack = html5VideoReattachHackProvider.get();
			html5VideoReattachHack.reAttachVideo(mediaWrapper, mediaExecutor, this);
		}
	}

	private boolean requiresReattachment() {
		return isUserAgent(MobileUserAgent.SAFARI) || isUserAgent(UserAgent.SAFARI);
	}

	public void setMediaExecutor(HTML5VideoMediaExecutor mediaExecutor) {
		this.mediaExecutor = mediaExecutor;
	}

	public void setMediaWrapper(HTML5VideoMediaWrapper mediaWrapper) {
		this.mediaWrapper = mediaWrapper;
	}

}

@@ -1532,22 +1532,22 @@
 erAgent.
-SAFARI
+CHROME
 );%0D%0A%09%7D%0D%0A

Change browser to Chrome