OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/options/options_ui.h" | 5 #include "chrome/browser/ui/webui/options/options_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "chrome/browser/autocomplete/autocomplete_match.h" | 20 #include "chrome/browser/autocomplete/autocomplete_match.h" |
21 #include "chrome/browser/autocomplete/autocomplete_result.h" | 21 #include "chrome/browser/autocomplete/autocomplete_result.h" |
22 #include "chrome/browser/browser_about_handler.h" | 22 #include "chrome/browser/browser_about_handler.h" |
23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
26 #include "chrome/browser/ui/webui/options/autofill_options_handler.h" | 25 #include "chrome/browser/ui/webui/options/autofill_options_handler.h" |
27 #include "chrome/browser/ui/webui/options/browser_options_handler.h" | 26 #include "chrome/browser/ui/webui/options/browser_options_handler.h" |
28 #include "chrome/browser/ui/webui/options/clear_browser_data_handler.h" | 27 #include "chrome/browser/ui/webui/options/clear_browser_data_handler.h" |
29 #include "chrome/browser/ui/webui/options/content_settings_handler.h" | 28 #include "chrome/browser/ui/webui/options/content_settings_handler.h" |
30 #include "chrome/browser/ui/webui/options/cookies_view_handler.h" | 29 #include "chrome/browser/ui/webui/options/cookies_view_handler.h" |
31 #include "chrome/browser/ui/webui/options/core_options_handler.h" | 30 #include "chrome/browser/ui/webui/options/core_options_handler.h" |
32 #include "chrome/browser/ui/webui/options/font_settings_handler.h" | 31 #include "chrome/browser/ui/webui/options/font_settings_handler.h" |
33 #include "chrome/browser/ui/webui/options/handler_options_handler.h" | 32 #include "chrome/browser/ui/webui/options/handler_options_handler.h" |
34 #include "chrome/browser/ui/webui/options/home_page_overlay_handler.h" | 33 #include "chrome/browser/ui/webui/options/home_page_overlay_handler.h" |
35 #include "chrome/browser/ui/webui/options/import_data_handler.h" | 34 #include "chrome/browser/ui/webui/options/import_data_handler.h" |
36 #include "chrome/browser/ui/webui/options/language_dictionary_overlay_handler.h" | 35 #include "chrome/browser/ui/webui/options/language_dictionary_overlay_handler.h" |
37 #include "chrome/browser/ui/webui/options/language_options_handler.h" | 36 #include "chrome/browser/ui/webui/options/language_options_handler.h" |
38 #include "chrome/browser/ui/webui/options/manage_profile_handler.h" | 37 #include "chrome/browser/ui/webui/options/manage_profile_handler.h" |
39 #include "chrome/browser/ui/webui/options/managed_user_settings_handler.h" | 38 #include "chrome/browser/ui/webui/options/managed_user_settings_handler.h" |
40 #include "chrome/browser/ui/webui/options/media_devices_selection_handler.h" | 39 #include "chrome/browser/ui/webui/options/media_devices_selection_handler.h" |
41 #include "chrome/browser/ui/webui/options/media_galleries_handler.h" | 40 #include "chrome/browser/ui/webui/options/media_galleries_handler.h" |
42 #include "chrome/browser/ui/webui/options/options_sync_setup_handler.h" | 41 #include "chrome/browser/ui/webui/options/options_sync_setup_handler.h" |
43 #include "chrome/browser/ui/webui/options/password_manager_handler.h" | 42 #include "chrome/browser/ui/webui/options/password_manager_handler.h" |
44 #include "chrome/browser/ui/webui/options/search_engine_manager_handler.h" | 43 #include "chrome/browser/ui/webui/options/search_engine_manager_handler.h" |
45 #include "chrome/browser/ui/webui/options/startup_pages_handler.h" | 44 #include "chrome/browser/ui/webui/options/startup_pages_handler.h" |
46 #include "chrome/browser/ui/webui/theme_source.h" | 45 #include "chrome/browser/ui/webui/theme_source.h" |
| 46 #include "chrome/browser/ui/webui/web_ui_util.h" |
47 #include "chrome/common/jstemplate_builder.h" | 47 #include "chrome/common/jstemplate_builder.h" |
48 #include "chrome/common/time_format.h" | 48 #include "chrome/common/time_format.h" |
49 #include "chrome/common/url_constants.h" | 49 #include "chrome/common/url_constants.h" |
50 #include "content/public/browser/notification_types.h" | 50 #include "content/public/browser/notification_types.h" |
51 #include "content/public/browser/render_view_host.h" | 51 #include "content/public/browser/render_view_host.h" |
52 #include "content/public/browser/url_data_source_delegate.h" | 52 #include "content/public/browser/url_data_source.h" |
53 #include "content/public/browser/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
54 #include "content/public/browser/web_contents_delegate.h" | 54 #include "content/public/browser/web_contents_delegate.h" |
55 #include "content/public/browser/web_ui.h" | 55 #include "content/public/browser/web_ui.h" |
56 #include "grit/chromium_strings.h" | 56 #include "grit/chromium_strings.h" |
57 #include "grit/generated_resources.h" | 57 #include "grit/generated_resources.h" |
58 #include "grit/locale_settings.h" | 58 #include "grit/locale_settings.h" |
59 #include "grit/options_resources.h" | 59 #include "grit/options_resources.h" |
60 #include "grit/theme_resources.h" | 60 #include "grit/theme_resources.h" |
61 #include "net/base/escape.h" | 61 #include "net/base/escape.h" |
62 #include "ui/base/resource/resource_bundle.h" | 62 #include "ui/base/resource/resource_bundle.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } // namespace | 95 } // namespace |
96 | 96 |
97 namespace options { | 97 namespace options { |
98 | 98 |
99 //////////////////////////////////////////////////////////////////////////////// | 99 //////////////////////////////////////////////////////////////////////////////// |
100 // | 100 // |
101 // OptionsUIHTMLSource | 101 // OptionsUIHTMLSource |
102 // | 102 // |
103 //////////////////////////////////////////////////////////////////////////////// | 103 //////////////////////////////////////////////////////////////////////////////// |
104 | 104 |
105 class OptionsUIHTMLSource : public content::URLDataSourceDelegate { | 105 class OptionsUIHTMLSource : public content::URLDataSource { |
106 public: | 106 public: |
107 // The constructor takes over ownership of |localized_strings|. | 107 // The constructor takes over ownership of |localized_strings|. |
108 explicit OptionsUIHTMLSource(DictionaryValue* localized_strings); | 108 explicit OptionsUIHTMLSource(DictionaryValue* localized_strings); |
109 | 109 |
110 // content::URLDataSourceDelegate implementation. | 110 // content::URLDataSource implementation. |
111 virtual std::string GetSource() OVERRIDE; | 111 virtual std::string GetSource() OVERRIDE; |
112 virtual void StartDataRequest(const std::string& path, | 112 virtual void StartDataRequest( |
113 bool is_incognito, | 113 const std::string& path, |
114 int request_id); | 114 bool is_incognito, |
| 115 const content::URLDataSource::GotDataCallback& callback); |
115 virtual std::string GetMimeType(const std::string&) const; | 116 virtual std::string GetMimeType(const std::string&) const; |
116 | 117 |
117 private: | 118 private: |
118 virtual ~OptionsUIHTMLSource(); | 119 virtual ~OptionsUIHTMLSource(); |
119 | 120 |
120 // Localized strings collection. | 121 // Localized strings collection. |
121 scoped_ptr<DictionaryValue> localized_strings_; | 122 scoped_ptr<DictionaryValue> localized_strings_; |
122 | 123 |
123 DISALLOW_COPY_AND_ASSIGN(OptionsUIHTMLSource); | 124 DISALLOW_COPY_AND_ASSIGN(OptionsUIHTMLSource); |
124 }; | 125 }; |
125 | 126 |
126 OptionsUIHTMLSource::OptionsUIHTMLSource(DictionaryValue* localized_strings) { | 127 OptionsUIHTMLSource::OptionsUIHTMLSource(DictionaryValue* localized_strings) { |
127 DCHECK(localized_strings); | 128 DCHECK(localized_strings); |
128 localized_strings_.reset(localized_strings); | 129 localized_strings_.reset(localized_strings); |
129 } | 130 } |
130 | 131 |
131 std::string OptionsUIHTMLSource::GetSource() { | 132 std::string OptionsUIHTMLSource::GetSource() { |
132 return chrome::kChromeUISettingsFrameHost; | 133 return chrome::kChromeUISettingsFrameHost; |
133 } | 134 } |
134 | 135 |
135 void OptionsUIHTMLSource::StartDataRequest(const std::string& path, | 136 void OptionsUIHTMLSource::StartDataRequest( |
136 bool is_incognito, | 137 const std::string& path, |
137 int request_id) { | 138 bool is_incognito, |
| 139 const content::URLDataSource::GotDataCallback& callback) { |
138 scoped_refptr<base::RefCountedMemory> response_bytes; | 140 scoped_refptr<base::RefCountedMemory> response_bytes; |
139 URLDataSource::SetFontAndTextDirection(localized_strings_.get()); | 141 web_ui_util::SetFontAndTextDirection(localized_strings_.get()); |
140 | 142 |
141 if (path == kLocalizedStringsFile) { | 143 if (path == kLocalizedStringsFile) { |
142 // Return dynamically-generated strings from memory. | 144 // Return dynamically-generated strings from memory. |
143 jstemplate_builder::UseVersion2 version; | 145 jstemplate_builder::UseVersion2 version; |
144 std::string strings_js; | 146 std::string strings_js; |
145 jstemplate_builder::AppendJsonJS(localized_strings_.get(), &strings_js); | 147 jstemplate_builder::AppendJsonJS(localized_strings_.get(), &strings_js); |
146 response_bytes = base::RefCountedString::TakeString(&strings_js); | 148 response_bytes = base::RefCountedString::TakeString(&strings_js); |
147 } else if (path == kOptionsBundleJsFile) { | 149 } else if (path == kOptionsBundleJsFile) { |
148 // Return (and cache) the options javascript code. | 150 // Return (and cache) the options javascript code. |
149 response_bytes = ui::ResourceBundle::GetSharedInstance(). | 151 response_bytes = ui::ResourceBundle::GetSharedInstance(). |
150 LoadDataResourceBytes(IDR_OPTIONS_BUNDLE_JS); | 152 LoadDataResourceBytes(IDR_OPTIONS_BUNDLE_JS); |
151 } else { | 153 } else { |
152 // Return (and cache) the main options html page as the default. | 154 // Return (and cache) the main options html page as the default. |
153 response_bytes = ui::ResourceBundle::GetSharedInstance(). | 155 response_bytes = ui::ResourceBundle::GetSharedInstance(). |
154 LoadDataResourceBytes(IDR_OPTIONS_HTML); | 156 LoadDataResourceBytes(IDR_OPTIONS_HTML); |
155 } | 157 } |
156 | 158 |
157 url_data_source()->SendResponse(request_id, response_bytes); | 159 callback.Run(response_bytes); |
158 } | 160 } |
159 | 161 |
160 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const { | 162 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const { |
161 if (path == kLocalizedStringsFile || path == kOptionsBundleJsFile) | 163 if (path == kLocalizedStringsFile || path == kOptionsBundleJsFile) |
162 return "application/javascript"; | 164 return "application/javascript"; |
163 | 165 |
164 return "text/html"; | 166 return "text/html"; |
165 } | 167 } |
166 | 168 |
167 OptionsUIHTMLSource::~OptionsUIHTMLSource() {} | 169 OptionsUIHTMLSource::~OptionsUIHTMLSource() {} |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 // Add only if handler's service is enabled. | 409 // Add only if handler's service is enabled. |
408 if (handler->IsEnabled()) { | 410 if (handler->IsEnabled()) { |
409 // Add handler to the list and also pass the ownership. | 411 // Add handler to the list and also pass the ownership. |
410 web_ui()->AddMessageHandler(handler.release()); | 412 web_ui()->AddMessageHandler(handler.release()); |
411 handler_raw->GetLocalizedValues(localized_strings); | 413 handler_raw->GetLocalizedValues(localized_strings); |
412 handlers_.push_back(handler_raw); | 414 handlers_.push_back(handler_raw); |
413 } | 415 } |
414 } | 416 } |
415 | 417 |
416 } // namespace options | 418 } // namespace options |
OLD | NEW |