Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: docs/chrome_settings.md

Issue 1309473002: WIP: Migrate Wiki content over to src/docs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: documentation_best_practices.md Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Table of Contents
2
3
4
5 # What is chrome://settings?
6
7 Chrome (version 10 and above) uses WebUI settings by default for all platforms. Access it via the wrench menu ("Preferences" on Mac and Linux; "Options" on Wind ows and ChromeOS), or by typing chrome://settings into the address bar.
8
9 One advantage of chrome://settings over platform-native dialogs is that it is sh ared by all platforms; therefore, it is easier to add new options UI and to keep all platforms in sync.
10
11 Note that at the time of this writing, DOMUI is being renamed to WebUI. The two terms will be used interchangeably herein.
12
13 # Moving parts
14
15 ## String resources
16
17 Strings live in `chrome/app/generated_resources.grd`. There are several rules go verning the format of strings:
18 * the **casing of button text** depends on the platform. If your string will b e displayed on a button, you need to add it twice, in sentence case and title ca se. Follow examples inside `<if expr="pp_ifdef('use_titlecase')">` blocks. Do th is even if your string is a single word because it may not be a single word in a nother locale.
19 * strings that are associated with form controls (buttons, checkboxes, dropdow ns, etc.) should NOT have **trailing punctuation**. Standalone strings, such as sectional descriptive text, should have trailing punctuation.
20 * strings may be different between Google Chrome and chromium. If they differ only in **product name**, put them in `generated_resources.grd` and use product name placeholders; if they differ more substantially, use `chromium_strings.grd` and `google_chrome_strings.grd`.
21
22 ## WebUI Handlers
23
24 The C++ WebUI handler classes for chrome://settings live in `chrome/browser/ui/w ebui/options/`. These objects both handle messages from and dispatch messages to the page. Each handler is a logical grouping of related functionality. Hence `C ontentSettingsHandler` is both the delegate and controller of the content settin gs subpage.
25
26 A handler sends a message to the page via `dom_ui_->CallJavascriptFunction()` an d registers for messages from the page via `dom_ui_->RegisterMessageCallback()`.
27
28 ## HTML/CSS/JS
29
30 The HTML, CSS, and JS resources live in `chrome/browser/resources/options`. They are compiled into one resource at compile time by grit, via `<link>`, `<src>` a nd `<include>` tags in `options.html`. There is no need to add new files to any `.gyp` file.
31
32 Some things that are good to know:
33 * JS objects are bound to HTML nodes via `decorate()`.
34 * Javascript calls into C++ via `chrome.send`.
35 * Some automatic preference handling is provided in `preferences.js` and `pref _ui.js`.
36 * Strings defined in a WebUI handler are available via `localStrings.getString ()` and friends.
37
38 # Example: adding a simple pref
39
40 Suppose you want to add a pref controlled by a **checkbox**.
41
42 ## 1. Getting UI approval
43
44 Ask one of the UI leads where your option belongs. First point of contact should be Alex Ainslie <ainslie at chromium>.
45
46 ## 2. Adding Strings
47
48 Add the string to `chrome/app/generated_resources.grd` near related strings. No trailing punctuation; sentence case.
49
50 ## 3. Changing WebUI Handler
51
52 For simple prefs, the UI is kept in sync with the value automagically (see `Core OptionsHandler`). Find the handler most closely relevant to your pref. The only action we need take here is to make the page aware of the new string. Locate the method in the handler called `GetLocalizedStrings` and look at its body for exa mples of `SetString` usage. The first parameter is the javascript name for the s tring.
53
54 ## 4. HTML/CSS/JS
55
56 An example of the form a checkbox should take in html:
57
58 ```
59 <label class="checkbox">
60 <input id="clear-cookies-on-exit"
61 pref="profile.clear_site_data_on_exit" type="checkbox">
62 <span i18n-content="clearCookiesOnExit"></span>
63 </label>
64 ```
65
66 Of note:
67 * the `checkbox` class allows us to style all checkboxes the same via CSS
68 * the class and ID are in dash-form
69 * the i18n-content value is in camelCase
70 * the pref attribute matches that which is defined in `chrome/common/pref_name s.cc` and allows the prefs framework to automatically keep it in sync with the v alue in C++
71 * the `i18n-content` value matches the string we defined in the WebUI handler. The `textContent` of the `span` will automatically be set to the associated tex t.
72
73 In this example, no additional JS or CSS are needed.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698