diff options
author | smus@chromium.org <smus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-15 00:02:15 +0000 |
---|---|---|
committer | smus@chromium.org <smus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-15 00:02:15 +0000 |
commit | d6fa6fba71f69b2c4c3ad454770d57d837c36f77 (patch) | |
tree | 27da085be382990d3fd9b730eecaa1f7366433e6 | |
parent | cb6573d8608d89db80b50ecdefb9ed1fb51f0101 (diff) | |
download | chromium_src-d6fa6fba71f69b2c4c3ad454770d57d837c36f77.zip chromium_src-d6fa6fba71f69b2c4c3ad454770d57d837c36f77.tar.gz chromium_src-d6fa6fba71f69b2c4c3ad454770d57d837c36f77.tar.bz2 |
Added storage sample.
BUG=98591
TEST=
Review URL: http://codereview.chromium.org/8916013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114531 0039d316-1c4b-4281-b951-d872f2087c98
15 files changed, 260 insertions, 12 deletions
diff --git a/chrome/common/extensions/docs/examples/api/storage/stylizr.zip b/chrome/common/extensions/docs/examples/api/storage/stylizr.zip Binary files differnew file mode 100644 index 0000000..e962e3a --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/storage/stylizr.zip diff --git a/chrome/common/extensions/docs/examples/api/storage/stylizr/icon.png b/chrome/common/extensions/docs/examples/api/storage/stylizr/icon.png Binary files differnew file mode 100644 index 0000000..85ea072 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/storage/stylizr/icon.png diff --git a/chrome/common/extensions/docs/examples/api/storage/stylizr/manifest.json b/chrome/common/extensions/docs/examples/api/storage/stylizr/manifest.json new file mode 100644 index 0000000..64484e0 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/storage/stylizr/manifest.json @@ -0,0 +1,21 @@ +{ + "name": "Stylizr", + "description": "Spruce up your pages with custom CSS.", + "version": "1.0", + + "permissions": [ + "tabs", + "<all_urls>", + "experimental" + ], + + "options_page": "options.html", + + "browser_action": { + "default_icon": "icon.png", + "default_title": "Stylize!", + "default_popup": "popup.html" + }, + + "manifest_version": 2 +} diff --git a/chrome/common/extensions/docs/examples/api/storage/stylizr/options.html b/chrome/common/extensions/docs/examples/api/storage/stylizr/options.html new file mode 100644 index 0000000..108e661 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/storage/stylizr/options.html @@ -0,0 +1,42 @@ +<!doctype html> +<html> + <head> + <title>Stylizr</title> + <style> + body { + font-family: sans-serif; + } + label { + display: block; + } + textarea { + font-family: monospace; + } + .message { + height: 20px; + background: #eee; + padding: 5px; + } + </style> + </head> + <body> + <div class="message"></div> + <h3>Stylizr Instructions</h3> + + <ol> + <li>Write CSS in this textarea and save</li> + <li>Navigate to some page</li> + <li>Click the browser action icon <img src="icon.png" /></li> + <li>Hey presto! CSS is injected!</li> + </ol> + + <textarea name="style_url" id="style_url" cols=80 rows=24 + placeholder="eg: * { font-size: 110%; }"></textarea> + + <br/> + <button class="submit">Save</button> + <button class="reset">Reset</button> + + <script src="options.js"></script> + </body> +</html> diff --git a/chrome/common/extensions/docs/examples/api/storage/stylizr/options.js b/chrome/common/extensions/docs/examples/api/storage/stylizr/options.js new file mode 100644 index 0000000..4eeab8f --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/storage/stylizr/options.js @@ -0,0 +1,58 @@ +// Copyright (c) 2011 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. + +// Store settings in the synchronized repository. +var storage = chrome.experimental.storage.sync; + +// Get at the DOM controls used in the sample. +var resetButton = document.querySelector('button.reset'); +var submitButton = document.querySelector('button.submit'); +var textarea = document.querySelector('textarea'); + +// Load any CSS that may have previously been saved. +loadChanges(); + +submitButton.addEventListener('click', saveChanges); +resetButton.addEventListener('click', reset); + +function saveChanges() { + // Get the current CSS snippet from the form. + var cssCode = textarea.value; + // Check that there's some code there. + if (!cssCode) { + message('Error: No CSS specified'); + return; + } + // Save it locally (un-synchronized) using the Chrome extension storage API. + storage.set({'css': cssCode}, function() { + // Notify that we saved. + message('Settings saved'); + }); +} + +function loadChanges() { + storage.get('css', function(items) { + if (items.css) { + textarea.value = items.css; + message('Loaded saved CSS.'); + } + }); +} + +function reset() { + // Remove the saved value from storage + storage.remove('css', function(items) { + message('Reset stored CSS'); + }); + // Refresh the text area. + textarea.value = ''; +} + +function message(msg) { + var message = document.querySelector('.message'); + message.innerText = msg; + setTimeout(function() { + message.innerText = ''; + }, 3000); +} diff --git a/chrome/common/extensions/docs/examples/api/storage/stylizr/popup.html b/chrome/common/extensions/docs/examples/api/storage/stylizr/popup.html new file mode 100644 index 0000000..02b597d --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/storage/stylizr/popup.html @@ -0,0 +1,16 @@ +<!doctype html> +<html> + <head> + <title>Stylizr</title> + <style> + body { + font-family: sans-serif; + width: 200px; + } + </style> + </head> + <body> + <div id="message"></div> + <script src="popup.js"></script> + </body> +</html> diff --git a/chrome/common/extensions/docs/examples/api/storage/stylizr/popup.js b/chrome/common/extensions/docs/examples/api/storage/stylizr/popup.js new file mode 100644 index 0000000..af1833f --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/storage/stylizr/popup.js @@ -0,0 +1,27 @@ +// Copyright (c) 2011 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. + +// Store settings in the synchronized repository. +var storage = chrome.experimental.storage.sync; +var message = document.querySelector('#message'); + +// Check if there is CSS specified. +storage.get('css', function(items) { + console.log(items); + // If there is CSS specified, inject it into the page. + if (items.css) { + chrome.tabs.insertCSS(null, {code: items.css}, function() { + if (chrome.extension.lastError) { + message.innerText = 'Not allowed to inject CSS into special page.'; + } else { + message.innerText = 'Injected style!'; + } + }); + } else { + var optionsUrl = chrome.extension.getURL('options.html'); + message.innerHTML = 'Set a style in the <a target="_blank" href="' + + optionsUrl + '">options page</a> first.'; + } +}); + diff --git a/chrome/common/extensions/docs/experimental.devtools.console.html b/chrome/common/extensions/docs/experimental.devtools.console.html index aa8f6a6..dbe18d8 100644 --- a/chrome/common/extensions/docs/experimental.devtools.console.html +++ b/chrome/common/extensions/docs/experimental.devtools.console.html @@ -16,8 +16,7 @@ <script type="text/javascript" src="js/api_page_generator.js"></script> <script type="text/javascript" src="js/bootstrap.js"></script> <script type="text/javascript" src="js/sidebar.js"></script> - <meta name="description" content="Documentation for the chrome.experimental.devtools.console module, which is part of the Google Chrome extension APIs."><title>chrome.experimental.devtools.console -API - Google Chrome Extensions - Google Code</title></head> + <meta name="description" content="Documentation for the chrome.experimental.devtools.console module, which is part of the Google Chrome extension APIs."><title>chrome.experimental.devtools.console API - Google Chrome Extensions - Google Code</title></head> <body> <div id="gc-container" class="labs"> <div id="devModeWarning"> You are viewing extension docs in chrome via the 'file:' scheme: are you expecting to see local changes when you refresh? You'll need run chrome with --allow-file-access-from-files. diff --git a/chrome/common/extensions/docs/experimental.devtools.network.html b/chrome/common/extensions/docs/experimental.devtools.network.html index a941e0c..8a3d1c5 100644 --- a/chrome/common/extensions/docs/experimental.devtools.network.html +++ b/chrome/common/extensions/docs/experimental.devtools.network.html @@ -16,8 +16,7 @@ <script type="text/javascript" src="js/api_page_generator.js"></script> <script type="text/javascript" src="js/bootstrap.js"></script> <script type="text/javascript" src="js/sidebar.js"></script> - <meta name="description" content="Documentation for the chrome.experimental.devtools.network module, which is part of the Google Chrome extension APIs."><title>chrome.experimental.devtools.network -API - Google Chrome Extensions - Google Code</title></head> + <meta name="description" content="Documentation for the chrome.experimental.devtools.network module, which is part of the Google Chrome extension APIs."><title>chrome.experimental.devtools.network API - Google Chrome Extensions - Google Code</title></head> <body> <div id="gc-container" class="labs"> <div id="devModeWarning"> You are viewing extension docs in chrome via the 'file:' scheme: are you expecting to see local changes when you refresh? You'll need run chrome with --allow-file-access-from-files. diff --git a/chrome/common/extensions/docs/experimental.devtools.resources.html b/chrome/common/extensions/docs/experimental.devtools.resources.html index ab35342..e6726f7 100644 --- a/chrome/common/extensions/docs/experimental.devtools.resources.html +++ b/chrome/common/extensions/docs/experimental.devtools.resources.html @@ -16,8 +16,7 @@ <script type="text/javascript" src="js/api_page_generator.js"></script> <script type="text/javascript" src="js/bootstrap.js"></script> <script type="text/javascript" src="js/sidebar.js"></script> - <title>chrome.experimental.devtools.resources -API - Google Chrome Extensions - Google Code</title></head> + <title>chrome.experimental.devtools.resources API - Google Chrome Extensions - Google Code</title></head> <body> <div id="gc-container" class="labs"> <div id="devModeWarning"> You are viewing extension docs in chrome via the 'file:' scheme: are you expecting to see local changes when you refresh? You'll need run chrome with --allow-file-access-from-files. diff --git a/chrome/common/extensions/docs/experimental.webInspector.audits.html b/chrome/common/extensions/docs/experimental.webInspector.audits.html index 9262907..fffd9b1 100644 --- a/chrome/common/extensions/docs/experimental.webInspector.audits.html +++ b/chrome/common/extensions/docs/experimental.webInspector.audits.html @@ -16,8 +16,7 @@ <script type="text/javascript" src="js/api_page_generator.js"></script> <script type="text/javascript" src="js/bootstrap.js"></script> <script type="text/javascript" src="js/sidebar.js"></script> - <title>experimental.webInspector.audits -API - Google Chrome Extensions - Google Code</title></head> + <title>experimental.webInspector.audits API - Google Chrome Extensions - Google Code</title></head> <body> <div id="gc-container" class="labs"> <div id="devModeWarning"> You are viewing extension docs in chrome via the 'file:' scheme: are you expecting to see local changes when you refresh? You'll need run chrome with --allow-file-access-from-files. diff --git a/chrome/common/extensions/docs/experimental.webInspector.panels.html b/chrome/common/extensions/docs/experimental.webInspector.panels.html index e473357..d8b9122 100644 --- a/chrome/common/extensions/docs/experimental.webInspector.panels.html +++ b/chrome/common/extensions/docs/experimental.webInspector.panels.html @@ -16,8 +16,7 @@ <script type="text/javascript" src="js/api_page_generator.js"></script> <script type="text/javascript" src="js/bootstrap.js"></script> <script type="text/javascript" src="js/sidebar.js"></script> - <title>experimental.webInspector.panels -API - Google Chrome Extensions - Google Code</title></head> + <title>experimental.webInspector.panels API - Google Chrome Extensions - Google Code</title></head> <body> <div id="gc-container" class="labs"> <div id="devModeWarning"> You are viewing extension docs in chrome via the 'file:' scheme: are you expecting to see local changes when you refresh? You'll need run chrome with --allow-file-access-from-files. diff --git a/chrome/common/extensions/docs/experimental.webInspector.resources.html b/chrome/common/extensions/docs/experimental.webInspector.resources.html index 975aba1..9b77a0c 100644 --- a/chrome/common/extensions/docs/experimental.webInspector.resources.html +++ b/chrome/common/extensions/docs/experimental.webInspector.resources.html @@ -16,8 +16,7 @@ <script type="text/javascript" src="js/api_page_generator.js"></script> <script type="text/javascript" src="js/bootstrap.js"></script> <script type="text/javascript" src="js/sidebar.js"></script> - <title>experimental.webInspector.resources -API - Google Chrome Extensions - Google Code</title></head> + <title>experimental.webInspector.resources API - Google Chrome Extensions - Google Code</title></head> <body> <div id="gc-container" class="labs"> <div id="devModeWarning"> You are viewing extension docs in chrome via the 'file:' scheme: are you expecting to see local changes when you refresh? You'll need run chrome with --allow-file-access-from-files. diff --git a/chrome/common/extensions/docs/samples.html b/chrome/common/extensions/docs/samples.html index a4b5e78..1542db7 100644 --- a/chrome/common/extensions/docs/samples.html +++ b/chrome/common/extensions/docs/samples.html @@ -385,6 +385,7 @@ "fc89b35755483af30b66cd72cefa34a43a3e8312": "SHOW TABS IN PROCESS ADDS A BROWSER ACTION SHOWING WHICH TABS SHARE THE CURRENT TABS PROCESS. BROWSER_ACTION EXPERIMENTAL POPUP TABS CHROME.TABS.GET CHROME.TABS.GETSELECTED CHROME.TABS.UPDATE CHROME.WINDOWS.GET CHROME.WINDOWS.GETALL CHROME.WINDOWS.GETCURRENT CHROME.WINDOWS.UPDATE", "a491a2faa1fe79cb49b2fe9ed2720f4723c14184": "SPEAK SELECTION SPEAKS THE CURRENT SELECTION OUT LOUD. <ALL_URLS> BACKGROUND_PAGE BROWSER_ACTION OPTIONS_PAGE TABS TTS CHROME.BROWSERACTION.ONCLICKED CHROME.BROWSERACTION.SETICON CHROME.EXTENSION.GETURL CHROME.EXTENSION.ONREQUEST CHROME.EXTENSION.SENDREQUEST CHROME.TABS.CREATE CHROME.TABS.EXECUTESCRIPT CHROME.TABS.SENDREQUEST CHROME.TTS.GETVOICES CHROME.TTS.SPEAK CHROME.TTS.STOP CHROME.WINDOWS.GET CHROME.WINDOWS.GETALL", "a942b7626644674b7a56678930d054497b244ee7": "SPEECH RECOGNIZER RECOGNIZES YOUR SPEECH AND TELLS YOU THE MOST LIKELY RESULT. BACKGROUND_PAGE BROWSER_ACTION EXPERIMENTAL CHROME.BROWSERACTION.ONCLICKED CHROME.BROWSERACTION.SETICON CHROME.EXPERIMENTAL.SPEECHINPUT.ISRECORDING CHROME.EXPERIMENTAL.SPEECHINPUT.ONERROR CHROME.EXPERIMENTAL.SPEECHINPUT.ONRESULT CHROME.EXPERIMENTAL.SPEECHINPUT.START CHROME.EXPERIMENTAL.SPEECHINPUT.STOP", + "24452253a5f1a93c2e8d63e55042005f8bc33606": "STYLIZR SPRUCE UP YOUR PAGES WITH CUSTOM CSS. <ALL_URLS> BROWSER_ACTION EXPERIMENTAL OPTIONS_PAGE TABS CHROME.EXTENSION.GETURL CHROME.TABS.INSERTCSS", "230463f2d5c3d4d0ca13c230e1f00f2aae0a8a64": "TAB INSPECTOR UTILITY FOR WORKING WITH THE EXTENSION TABS API BACKGROUND_PAGE BROWSER_ACTION TABS CHROME.BROWSERACTION.ONCLICKED CHROME.EXTENSION.GETURL CHROME.TABS.CREATE CHROME.TABS.GET CHROME.TABS.GETALLINWINDOW CHROME.TABS.GETSELECTED CHROME.TABS.MOVE CHROME.TABS.ONATTACHED CHROME.TABS.ONCREATED CHROME.TABS.ONDETACHED CHROME.TABS.ONMOVED CHROME.TABS.ONREMOVED CHROME.TABS.ONSELECTIONCHANGED CHROME.TABS.ONUPDATED CHROME.TABS.REMOVE CHROME.TABS.UPDATE CHROME.WINDOWS.CREATE CHROME.WINDOWS.GET CHROME.WINDOWS.GETALL CHROME.WINDOWS.GETCURRENT CHROME.WINDOWS.GETLASTFOCUSED CHROME.WINDOWS.ONCREATED CHROME.WINDOWS.ONFOCUSCHANGED CHROME.WINDOWS.ONREMOVED CHROME.WINDOWS.REMOVE CHROME.WINDOWS.UPDATE", "04f5d2ddea95746b0200be1ea223ccb7a748a771": "TALKING ALARM CLOCK A CLOCK WITH TWO CONFIGURABLE ALARMS THAT WILL PLAY A SOUND AND SPEAK A PHRASE OF YOUR CHOICE. BACKGROUND BACKGROUND_PAGE BROWSER_ACTION TTS CHROME.BROWSERACTION.SETICON CHROME.EXTENSION.CONNECT CHROME.EXTENSION.ONCONNECT CHROME.TTS.GETVOICES CHROME.TTS.SPEAK CHROME.TTS.STOP", "e1697cacebad05218798bf3e8a0f724517f0e8c3": "TEST SCREENSHOT EXTENSION DEMONSTRATE SCREENSHOT FUNCTIONALITY IN THE CHROME.TABS API. NOTE: ONLY WORKS FOR CODE.GOOGLE.COM BACKGROUND_PAGE BROWSER_ACTION TABS CHROME.BROWSERACTION.ONCLICKED CHROME.EXTENSION.GETURL CHROME.EXTENSION.GETVIEWS CHROME.TABS.CAPTUREVISIBLETAB CHROME.TABS.CREATE CHROME.TABS.ONUPDATED", @@ -3894,6 +3895,64 @@ - <a>Install extension</a> </span> </div> +</div><div class="sample" id="24452253a5f1a93c2e8d63e55042005f8bc33606"> + <img class="icon" style="display: none; "> + <img class="icon" src="images/sample-default-icon.png"> + <h2 class="name"> + <a href="#24452253a5f1a93c2e8d63e55042005f8bc33606">Stylizr</a> + <span style="display: none; ">(packaged app)</span> + </h2> + <p class="metadata features">Uses + <span> + <strong><all_urls></strong><span>, </span> + <span style="display: none; "> and</span> + </span><span> + <strong>browser_action</strong><span>, </span> + <span style="display: none; "> and</span> + </span><span> + <strong>experimental</strong><span>, </span> + <span style="display: none; "> and</span> + </span><span> + <strong>options_page</strong><span style="display: none; ">, </span> + <span> and</span> + </span><span> + <strong>tabs</strong><span style="display: none; ">, </span> + <span style="display: none; "> and</span> + </span> + </p> + <p>Spruce up your pages with custom CSS.</p> + <div class="apicalls"><strong>Calls:</strong> + <ul> + <li> + <code><a href="extension.html#method-getURL">chrome.extension.getURL</a></code> + </li><li> + <code><a href="tabs.html#method-insertCSS">chrome.tabs.insertCSS</a></code> + </li> + </ul> + </div> + <div class="sourcefiles"><strong>Source files:</strong> + <ul> + <li> + <code><a target="_blank" href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/storage/stylizr/manifest.json?content-type=text/plain">manifest.json</a></code> + </li><li> + <code><a target="_blank" href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/storage/stylizr/options.html?content-type=text/plain">options.html</a></code> + </li><li> + <code><a target="_blank" href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/storage/stylizr/options.js?content-type=text/plain">options.js</a></code> + </li><li> + <code><a target="_blank" href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/storage/stylizr/popup.html?content-type=text/plain">popup.html</a></code> + </li><li> + <code><a target="_blank" href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/storage/stylizr/popup.js?content-type=text/plain">popup.js</a></code> + </li> + </ul> + </div> + <div> + <a target="_blank" href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/storage/stylizr/">Browse source</a> + - <a href="examples/api/storage/stylizr.zip">Download source</a> + <!-- Only show the Install CRX link if a CRX file is provided --> + <span style="display: none; "> + - <a>Install extension</a> + </span> + </div> </div><div class="sample" id="230463f2d5c3d4d0ca13c230e1f00f2aae0a8a64"> <img class="icon" style="display: none; "> <img class="icon" src="images/sample-default-icon.png"> diff --git a/chrome/common/extensions/docs/samples.json b/chrome/common/extensions/docs/samples.json index 41d07de..54a1c3b 100644 --- a/chrome/common/extensions/docs/samples.json +++ b/chrome/common/extensions/docs/samples.json @@ -2139,6 +2139,37 @@ }, { "api_calls": [ + "chrome.extension.getURL", + "chrome.tabs.insertCSS" + ], + "crx_path": null, + "description": "Spruce up your pages with custom CSS.", + "features": [ + "<all_urls>", + "browser_action", + "experimental", + "options_page", + "tabs" + ], + "icon": null, + "id": "24452253a5f1a93c2e8d63e55042005f8bc33606", + "name": "Stylizr", + "packaged_app": false, + "path": "examples\/api\/storage\/stylizr\/", + "protocols": [], + "search_string": "STYLIZR SPRUCE UP YOUR PAGES WITH CUSTOM CSS. <ALL_URLS> BROWSER_ACTION EXPERIMENTAL OPTIONS_PAGE TABS CHROME.EXTENSION.GETURL CHROME.TABS.INSERTCSS", + "source_files": [ + "manifest.json", + "options.html", + "options.js", + "popup.html", + "popup.js" + ], + "source_hash": "fa67fae5afc20d9ad9b46a8d25037aabcb89630e", + "zip_path": "examples\/api\/storage\/stylizr.zip" + }, + { + "api_calls": [ "chrome.browserAction.onClicked", "chrome.extension.getURL", "chrome.tabs.create", |