Example usage for com.google.gwt.chrome.crx.client Chrome getExtension

List of usage examples for com.google.gwt.chrome.crx.client Chrome getExtension

Introduction

In this page you can find the example usage for com.google.gwt.chrome.crx.client Chrome getExtension.

Prototype

public static final native Chrome getExtension() ;

Source Link

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);/*w  w w  .j a v 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();
            }
        }
    });
}

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

License:Apache License

private void listenForExternalExtensions(final ExternalExtensionListener exListener) {
    // External extensions can also be used as data sources. Hook this up.
    Chrome.getExtension().getOnRequestExternalEvent().addListener(new RequestExternalEvent.Listener() {
        public void onRequestExternal(JavaScriptObject request, Sender sender, SendResponse sendResponse) {
            // Ensure the extension attempting to connect is not blacklisted.
            if (!ExternalExtensionDataInstance.isBlackListed(sender.getId())) {
                final ConnectRequest connectRequest = request.cast();
                final int browserId = connectRequest.getBrowserId();

                BrowserConnectionState connection = browserConnectionMap.get(browserId);

                if (connection == null) {
                    // If this is the first opened connection for this browser type,
                    // then we provision an entry for it in the browser map.
                    exListener.onBrowserConnected(browserId);
                }//from   w w  w  .  ja  v a  2s .c om

                final int tabId = connectRequest.getTabId();
                final String portName = ExternalExtensionDataInstance.SPEED_TRACER_EXTERNAL_PORT + browserId
                        + "-" + tabId;

                // So we will now begin listening for connections on a dedicated
                // port name for this browser/tab combo.
                Chrome.getExtension().getOnConnectExternalEvent()
                        .addListener(new ConnectExternalEvent.Listener() {
                            public void onConnectExternal(Port port) {
                                if (portName.equals(port.getName())) {
                                    // Provision a DataInstance and a TabDescription.
                                    DataInstance dataInstance = ExternalExtensionDataInstance.create(port);
                                    TabDescription tabDescription = TabDescription.create(tabId,
                                            connectRequest.getTitle(), connectRequest.getUrl());

                                    // Now remember the DataInstance and TabDescription, and
                                    // open a Monitor.
                                    exListener.onTabMonitorStarted(browserId, tabDescription, dataInstance);
                                }
                            }
                        });

                // Send a response that tells the external extension what port
                // name to connect to.
                sendResponse.invoke(ExternalExtensionDataInstance.createResponse(portName));
            }
        }
    });
}

From source file:com.google.speedtracer.client.model.ChromeDebuggerDataInstance.java

License:Apache License

private static void startTimeline(final int tabId, final Proxy proxy) {
    Debugger.sendRequest(tabId, "Timeline.start", createStartTimelineParams(tabId),
            new Debugger.SendRequestCallback() {
                public void onResponse(JavaScriptObject result) {
                    if (result == null) {
                        // Starting failed.
                        Chrome.getExtension().getBackgroundPage().getConsole()
                                .log("Error starting timeline for tab: " + tabId);
                    }/*from   ww  w. j  a va2  s.  c om*/
                    proxy.onTimelineProfilerStarted();
                }
            });
}

From source file:com.google.speedtracer.client.model.ChromeDebuggerDataInstance.java

License:Apache License

private static void startNetwork(final int tabId, final Proxy proxy) {
    Debugger.sendRequest(tabId, "Network.enable", createStartNetworkParams(tabId),
            new Debugger.SendRequestCallback() {
                public void onResponse(JavaScriptObject result) {
                    if (result == null) {
                        // Starting failed.
                        Chrome.getExtension().getBackgroundPage().getConsole()
                                .log("Error starting network tracing for tab: " + tabId);
                    }/*from w w w .  ja  v  a 2 s .  c  o  m*/
                    proxy.onTimelineProfilerStarted();
                }
            });
}

From source file:com.google.speedtracer.client.model.ChromeDebuggerDataInstance.java

License:Apache License

private static void startPage(final int tabId, final Proxy proxy) {
    Debugger.sendRequest(tabId, "Page.enable", createStartPageParams(tabId),
            new Debugger.SendRequestCallback() {
                public void onResponse(JavaScriptObject result) {
                    if (result == null) {
                        // Starting failed.
                        Chrome.getExtension().getBackgroundPage().getConsole()
                                .log("Error starting page events for tab: " + tabId);
                    }/*  w w  w  . java 2s.  com*/
                    proxy.onTimelineProfilerStarted();
                }
            });
}

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

License:Apache License

/**
 * Creates an instance of the SourceViewer and invokes the passed in callback
 * when the iFrame is loaded with the target source.
 * /*  w ww  . jav a 2 s  .  co  m*/
 * We first load the proxy html page. This proxy page uses cross site XHR
 * enabled by Chrome extensions to fetch and format the target source. Once
 * the target source is loaded, we consider the viewer initialized.
 * 
 * @param parent the parent container element we will attach the SourceViewer
 *          to.
 * @param resources the ClientBundle instance for this class.
 * @param initializedCallback the {@link SourceViewerInitializedCallback} that
 *          we pass the loaded SourceViewer to.
 */
public static void create(Element parent, final Resources resources,
        final SourceViewerInitializedCallback initializedCallback) {
    Document document = parent.getOwnerDocument();
    // Create the iframe within which we will load the source.
    final IFrameElement sourceFrame = document.createIFrameElement();
    Element frameWrapper = document.createDivElement();
    frameWrapper.setClassName(resources.sourceViewerCss().frameWrapper());
    frameWrapper.appendChild(sourceFrame);

    final Element baseElement = document.createDivElement();
    final Element headerElem = document.createDivElement();
    headerElem.setClassName(resources.sourceViewerCss().header());
    baseElement.appendChild(headerElem);

    // IFrame must be attached to fire onload.
    baseElement.appendChild(frameWrapper);
    parent.appendChild(baseElement);
    Event.addEventListener("load", sourceFrame, new EventListener() {
        public void handleEvent(Event event) {
            // The source fetcher should be loaded. Lets now point it at the source
            // we want to load.
            SourceViewer sourceViewer = new SourceViewer(baseElement, headerElem, sourceFrame, resources);
            initializedCallback.onSourceViewerInitialized(sourceViewer);
        }
    });

    sourceFrame.setSrc(Chrome.getExtension().getUrl("monitor/SourceFetcher.html"));
}

From source file:com.google.speedtracer.client.view.Controller.java

License:Apache License

private void saveRecords(JSOArray<String> visitedUrls, String version, JSOArray<String> traceData) {
    // Create expando on our View so that the tab we create can callback and
    // receive the record data and file information.
    setupViewCallback(visitedUrls, version, traceData);

    // Create a new tab at the save data template page. Give it the same query
    // string as our own.
    Tabs.create(/*  www .  jav  a 2 s. c  o  m*/
            Chrome.getExtension().getUrl("monitor/SpeedTracerData.html") + Window.Location.getQueryString());
}

From source file:com.google.speedtracer.headlessextension.client.HeadlessBackgroundPage.java

License:Apache License

private void initialize() {
    // Listen for messages from the content script
    Chrome.getExtension().getOnConnectEvent().addListener(this);
    console = Chrome.getExtension().getBackgroundPage().getConsole();
}