Google Chrome Extensions:

Privacy-related APIs

  -  

Q/A: http://goo.gl/FoMwN

:-(

I couldn't find the required extension APIs, so the demos won't work. Install me as an extension to see things running (or just flip through the pretty slides).

Chrome in Munich

Chrome Privacy

Privacy Features

To avoid a settings UI like this, we want to empower developers to create privacy-enhancing extensions that are well-tuned for specific use-cases.

chrome.proxy

Your company firewall…

…has gotten lots of attention.

Proxies are an important mechanism for private communication

Tor is a great example of an anonymizing service we very much wanted Chrome to support.

This is one solution…

Set up fixed proxy server:

var config = {
  mode: 'fixed_servers',
  rules: {
    proxyForHttp: {
      scheme: 'socks5',
      host: '1.2.3.4'
    },
    bypassList: ['foobar.com']
  }
};
chrome.proxy.settings.set(
    {value: config, scope: 'regular'},
    function() {});

Or generate a PAC script:

var config = {
  mode: "pac_script",
  pacScript: {
    data:
      "function FindProxyForURL(u, h) {" +
      "  if (h === 'foobar.com') {" +
      "    return 'PROXY blackhole:80';" +
      "  }" +
      "  return 'DIRECT';" +
      "}"
  }
};

Query current proxy settings:

chrome.proxy.settings.get(
    {'incognito': false},
    function(config) { 
        console.log(JSON.stringify(config));
    });
 

chrome.experimental.privacy

chrome.privacy.services
    .alternateErrorPagesEnabled
    .set({
      'value': false,
      'scope': 'regular'
    });

chrome.contentSettings

chrome.contentSettings.images.set({
  'primaryPattern':
      'http://images.google.com:80/*',
  'setting': 'block',
  'scope': 'regular'
});

chrome.experimental.clear

chrome.clear.browsingData(
    "everything",
    { "history": true },
    function () { /* ... */ });

chrome.webNavigation

chrome.webNavigation
   .onCompleted.addListener(function(data) {
      if (typeof data)
        console.log(data);
    });

chrome.experimental.webRequest

Google is a dog company

Dog Policy Google's affection for our canine friends is an integral facet of our corporate culture. We like cats, but we're a dog company, so as a general rule we feel cats visiting our offices would be fairly stressed out.

…but the Internet is full of LOLcats!!1!1!!

…but the Internet is full of LOLcats!!1!1!!

So let's help our canine friends!

chrome.experimental.webRequest

Step 1: Block LOLcats at their source

{
  "name": "CatBlock",
  "version": "1.0",
  "description": "I can't has cheezburger!",
  "permissions": ["experimental",
      "http://icanhascheezburger.files.wordpress.com/*",
      "http://chzmemebase.files.wordpress.com/*"],
  "background_page": "background.html"
}

Step 1: Block LOLcats at their source

Demo
chrome.experimental.webRequest
   .onBeforeRequest.addListener(
        function(details) {
          return { cancel: true };
        },
        // filters
        { urls: [
            "http://icanhascheezburger.files.wordpress.com/*",
            "http://chzmemebase.files.wordpress.com/*",
          ],
          types: ["image"]
        },
        // extraInfoSpec
        ["blocking"]);

Step 2: Redirect to LOLdogs

Demo
chrome.experimental.webRequest
   .onBeforeRequest.addListener(
       function(details) {
         console.log("Cat intercepted!");
         // Redirect the lolcat request
         var i = Math.floor(
             Math.random() * loldogs.length);
         return { redirectUrl: loldogs[i] };
       },
       // filters
       { ... },
       // extraInfoSpec
       ["blocking"]);

Step 3: Proclaim our allegiance

chrome.experimental.webRequest
   .onBeforeSendHeaders.addListener(
      function(details) {
        details.requestHeaders.push({
          name: "X-Moar-Dog-Pictures",
          value: "yesplz" });
        return {
          requestHeaders:
            details.requestHeaders};
      }
      // filters
      {},
      // extraInfoSpec
      ["blocking", "requestHeaders"]);

Signals: onBeforeRequest

Signals: onBeforeSendHeaders

Signals: onSendHeaders

Signals: onHeadersReceived

Signals: onAuthRequired

Signals: onBeforeRedirect

Signals: onResponseStarted

Signals: onCompleted

Signals: onErrorOccurred

Filters

webRequest.onXXX.addListener(
      function(details) {} // handler
      {},                  // filters
      ["blocking"]);       // extraInfoSpec

The webRequest API: making dogs happy beginning next year.

Summary

http://code.google.com/chrome/extensions

The web is what you make of it.