diff options
author | mkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-26 08:31:45 +0000 |
---|---|---|
committer | mkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-26 08:31:45 +0000 |
commit | eb77fe592eed618a37d3b73ba0dff5b1968b4efa (patch) | |
tree | 3db331c422b41b4f79719ac31e84fc196478f4da /chrome/common/extensions/docs/examples/tutorials | |
parent | 9d56027a1bd54cdf472fbc115688ebe24078e8d7 (diff) | |
download | chromium_src-eb77fe592eed618a37d3b73ba0dff5b1968b4efa.zip chromium_src-eb77fe592eed618a37d3b73ba0dff5b1968b4efa.tar.gz chromium_src-eb77fe592eed618a37d3b73ba0dff5b1968b4efa.tar.bz2 |
Improving `content_security_policy` documentation.
Added a document just for `content_security_policy` explaining the default
restrictions, and offering pointers regarding best practice. Also updated
the Analytics example and documentation accordingly.
BUG=111049
TEST=
Review URL: https://chromiumcodereview.appspot.com/9212044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119211 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/docs/examples/tutorials')
5 files changed, 62 insertions, 54 deletions
diff --git a/chrome/common/extensions/docs/examples/tutorials/analytics.zip b/chrome/common/extensions/docs/examples/tutorials/analytics.zip Binary files differindex 5ad25f9..5997e76 100644 --- a/chrome/common/extensions/docs/examples/tutorials/analytics.zip +++ b/chrome/common/extensions/docs/examples/tutorials/analytics.zip diff --git a/chrome/common/extensions/docs/examples/tutorials/analytics/analytics.js b/chrome/common/extensions/docs/examples/tutorials/analytics/analytics.js deleted file mode 100644 index 06945ce..0000000 --- a/chrome/common/extensions/docs/examples/tutorials/analytics/analytics.js +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this - * source code is governed by a BSD-style license that can be found in the - * LICENSE file. - * - * Below is a modified version of the Google Analytics asynchronous tracking - * code snippet. It has been modified to pull the HTTPS version of ga.js - * instead of the default HTTP version. It is recommended that you use this - * snippet instead of the standard tracking snippet provided when setting up - * a Google Analytics account. - * - * See http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html - * for information on how to use the asynchronous tracking API. - * - * If you wish to use this file in your own extension, replace UA-12026369-1 - * with your own Google Analytics account number. Note that the default code - * will automatically track a page view for any page this file is included in. - * - * When including this file in your code, the best practice is to insert the - * <script src="analytics.js"></script> include at the top of the <body> - * section of your pages, after the opening <body> tag. - */ - -var _gaq = _gaq || []; -_gaq.push(['_setAccount', 'UA-12026369-1']); -_gaq.push(['_trackPageview']); - -(function() { - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - ga.src = 'https://ssl.google-analytics.com/ga.js'; - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); -})();
\ No newline at end of file diff --git a/chrome/common/extensions/docs/examples/tutorials/analytics/manifest.json b/chrome/common/extensions/docs/examples/tutorials/analytics/manifest.json index 55e3f7b..11f90a0 100644 --- a/chrome/common/extensions/docs/examples/tutorials/analytics/manifest.json +++ b/chrome/common/extensions/docs/examples/tutorials/analytics/manifest.json @@ -1,10 +1,7 @@ { "name": "Event Tracking with Google Analytics", - "version": "1.0.0", + "version": "2.0.0", "description": "A sample extension which uses Google Analytics to track usage.", - "background": { - "scripts": ["analytics.js"] - }, "browser_action": { "default_title": "Open the popup", "default_icon": "analytics-extension-icon-19.png", @@ -13,5 +10,8 @@ "icons": { "48": "analytics-extension-icon-48.png", "128": "analytics-extension-icon-128.png" - } + }, + + "manifest_version": 2, + "content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'" } diff --git a/chrome/common/extensions/docs/examples/tutorials/analytics/popup.html b/chrome/common/extensions/docs/examples/tutorials/analytics/popup.html index 19284a8..9a76c26 100644 --- a/chrome/common/extensions/docs/examples/tutorials/analytics/popup.html +++ b/chrome/common/extensions/docs/examples/tutorials/analytics/popup.html @@ -1,6 +1,6 @@ <!DOCTYPE html> <!-- - * Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this + * Copyright (c) 2012 The Chromium Authors. All rights reserved. Use of this * source code is governed by a BSD-style license that can be found in the * LICENSE file. --> @@ -17,25 +17,16 @@ text-align: center; } </style> + <script src="popup.js"></script> </head> <body> - <script src="analytics.js"></script> - <script> - /** - * Tracks a single button click. You can use the _trackEvent command - * to track user interactions with different parts of your extension. - */ - function trackButton(button_id) { - _gaq.push(['_trackEvent', 'button' + button_id, 'clicked']); - } - </script> <h1>Popup</h1> <p>Track the following actions:</p> - <button onclick="trackButton(1);">Button 1</button> - <button onclick="trackButton(2);">Button 2</button> - <button onclick="trackButton(3);">Button 3</button> - <button onclick="trackButton(4);">Button 4</button> - <button onclick="trackButton(5);">Button 5</button> - <button onclick="trackButton(6);">Button 6</button> + <button id='button1'>Button 1</button> + <button id='button2'>Button 2</button> + <button id='button3'>Button 3</button> + <button id='button4'>Button 4</button> + <button id='button5'>Button 5</button> + <button id='button6'>Button 6</button> </body> </html> diff --git a/chrome/common/extensions/docs/examples/tutorials/analytics/popup.js b/chrome/common/extensions/docs/examples/tutorials/analytics/popup.js new file mode 100644 index 0000000..160fe15 --- /dev/null +++ b/chrome/common/extensions/docs/examples/tutorials/analytics/popup.js @@ -0,0 +1,49 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * Add your Analytics tracking ID here. + */ +var _AnalyticsCode = 'UA-XXXXXX-X'; + +/** + * Below is a modified version of the Google Analytics asynchronous tracking + * code snippet. It has been modified to pull the HTTPS version of ga.js + * instead of the default HTTP version. It is recommended that you use this + * snippet instead of the standard tracking snippet provided when setting up + * a Google Analytics account. + */ +var _gaq = _gaq || []; +_gaq.push(['_setAccount', _AnalyticsCode]); +_gaq.push(['_trackPageview']); + +(function() { + var ga = document.createElement('script'); + ga.type = 'text/javascript'; + ga.async = true; + ga.src = 'https://ssl.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; + s.parentNode.insertBefore(ga, s); +})(); + +/** + * Track a click on a button using the asynchronous tracking API. + * + * See http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html + * for information on how to use the asynchronous tracking API. + */ +function trackButtonClick(e) { + _gaq.push(['_trackEvent', e.target.id, 'clicked']); +} + +/** + * Now set up your event handlers for the popup's `button` elements once the + * popup's DOM has loaded. + */ +document.addEventListener('DOMContentLoaded', function () { + var buttons = document.querySelectorAll('button'); + for (var i = 0; i < buttons.length; i++) { + buttons[i].addEventListener('click', trackButtonClick); + } +}); |