package com.google.gwt.chrome.crx.client;
import com.google.gwt.chrome.crx.client.events.ConnectEvent;
import com.google.gwt.chrome.crx.client.events.RequestEvent;
import com.google.gwt.core.client.EntryPoint;
/**
*
* {@link GwtContentScriptEntryPoint} is a {@link ContentScript} the main
* difference is it is generated by GWT compiler instead of simple JavaScript
* file. Details at <a
* href="http://code.google.com/chrome/extensions/content_scripts.html" >Content
* Scripts</a>
*/
public abstract class GwtContentScriptEntryPoint implements EntryPoint {
/**
* Should be implemented in you {@link GwtContentScriptEntryPoint}s.<br />
* This is a start point for {@link GwtContentScriptEntryPoint} code.
*/
abstract public void onScriptLoad();
public void onModuleLoad() {
onScriptLoad();
}
/**
* Attempts to connect to extension using specified connection name.
*
* @param connectionName
* the connection name
* @return {@link Port} through which messages can be sent and received with
* the extension
*/
protected Port connect(final String connectionName) {
return Chrome.getExtension().connect(connectionName);
}
/**
* Assigns the {@link ConnectEvent.Listener} for connections from
* {@link BackgroundPage} to {@link GwtContentScript}.
*
* @param listener
* The {@link ConnectEvent.Listener}
*/
protected void onConnect(ConnectEvent.Listener listener) {
Chrome.getExtension().getOnConnectEvent().addListener(listener);
}
/**
* Assigns the {@link RequestEvent.Listener} for connections from
* {@link BackgroundPage} to {@link GwtContentScript}.
*
* @param listener
* listener The {@link RequestEvent.Listener}
*/
protected void onRequestEvent(RequestEvent.Listener listener) {
Chrome.getExtension().getOnRequestEvent().addListener(listener);
}
}