Example usage for com.google.gwt.chrome.crx.client.events Sender getTab

List of usage examples for com.google.gwt.chrome.crx.client.events Sender getTab

Introduction

In this page you can find the example usage for com.google.gwt.chrome.crx.client.events Sender getTab.

Prototype

public final native Tab getTab() ;

Source Link

Document

This will only be set when a request is sent from a Tab or a Content Script.

Usage

From source file:com.google.speedtracer.client.BackgroundPage.java

License:Apache License

private void listenForContentScripts() {
    // A content script connects to us when we want to load data.
    Chrome.getExtension().getOnConnectEvent().addListener(new ConnectEvent.Listener() {
        public void onConnect(final Port port) {
            String portName = port.getName();
            if (portName.equals(DataLoader.DATA_LOAD) || portName.equals(DataLoader.RAW_DATA_LOAD)) {
                // We are loading data.
                doDataLoad(port);//from w  ww  . j  av a 2  s .  c o  m
            }
        }
    });

    // A content script can message us if it detects that we should auto open
    // Speed Tracer for a trampoline file.
    Chrome.getExtension().getOnRequestEvent().addListener(new RequestEvent.Listener() {
        public void onRequest(JavaScriptObject request, Sender sender, SendResponse sendResponse) {
            if (DataBag.getBooleanProperty(request, "autoOpen")) {
                // Open Speed Tracer.
                Tab tab = sender.getTab();
                monitorTabClickListener.onClicked(tab);
                // The Monitor coming alive and calling back should be
                // asynchronous. We should be able to stick in the SendResponse
                // callback in before the Monitor calls back, and then notify the
                // content script after we know the monitor is opened and ready.
                BrowserConnectionState browserConnection = browserConnectionMap.get(CHROME_BROWSER_ID);
                browserConnection.tabMap.get(tab.getId()).monitorOpenedCallback = sendResponse.cast();
            }
        }
    });
}