| 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" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "chrome/browser/ui/webui/options/options_sync_setup_handler.h" | 42 #include "chrome/browser/ui/webui/options/options_sync_setup_handler.h" |
| 43 #include "chrome/browser/ui/webui/options/password_manager_handler.h" | 43 #include "chrome/browser/ui/webui/options/password_manager_handler.h" |
| 44 #include "chrome/browser/ui/webui/options/search_engine_manager_handler.h" | 44 #include "chrome/browser/ui/webui/options/search_engine_manager_handler.h" |
| 45 #include "chrome/browser/ui/webui/options/startup_pages_handler.h" | 45 #include "chrome/browser/ui/webui/options/startup_pages_handler.h" |
| 46 #include "chrome/browser/ui/webui/theme_source.h" | 46 #include "chrome/browser/ui/webui/theme_source.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/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
| 53 #include "content/public/browser/web_contents_delegate.h" | 54 #include "content/public/browser/web_contents_delegate.h" |
| 54 #include "content/public/browser/web_ui.h" | 55 #include "content/public/browser/web_ui.h" |
| 55 #include "grit/chromium_strings.h" | 56 #include "grit/chromium_strings.h" |
| 56 #include "grit/generated_resources.h" | 57 #include "grit/generated_resources.h" |
| 57 #include "grit/locale_settings.h" | 58 #include "grit/locale_settings.h" |
| 58 #include "grit/options_resources.h" | 59 #include "grit/options_resources.h" |
| 59 #include "grit/theme_resources.h" | 60 #include "grit/theme_resources.h" |
| 60 #include "net/base/escape.h" | 61 #include "net/base/escape.h" |
| 61 #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... |
| 94 } // namespace | 95 } // namespace |
| 95 | 96 |
| 96 namespace options { | 97 namespace options { |
| 97 | 98 |
| 98 //////////////////////////////////////////////////////////////////////////////// | 99 //////////////////////////////////////////////////////////////////////////////// |
| 99 // | 100 // |
| 100 // OptionsUIHTMLSource | 101 // OptionsUIHTMLSource |
| 101 // | 102 // |
| 102 //////////////////////////////////////////////////////////////////////////////// | 103 //////////////////////////////////////////////////////////////////////////////// |
| 103 | 104 |
| 104 class OptionsUIHTMLSource : public ChromeURLDataManager::DataSource { | 105 class OptionsUIHTMLSource : public content::URLDataSourceDelegate { |
| 105 public: | 106 public: |
| 106 // The constructor takes over ownership of |localized_strings|. | 107 // The constructor takes over ownership of |localized_strings|. |
| 107 explicit OptionsUIHTMLSource(DictionaryValue* localized_strings); | 108 explicit OptionsUIHTMLSource(DictionaryValue* localized_strings); |
| 108 | 109 |
| 109 // Called when the network layer has requested a resource underneath | 110 // content::URLDataSourceDelegate implementation. |
| 110 // the path we registered. | 111 virtual std::string GetSource() OVERRIDE; |
| 111 virtual void StartDataRequest(const std::string& path, | 112 virtual void StartDataRequest(const std::string& path, |
| 112 bool is_incognito, | 113 bool is_incognito, |
| 113 int request_id); | 114 int request_id); |
| 114 virtual std::string GetMimeType(const std::string&) const; | 115 virtual std::string GetMimeType(const std::string&) const; |
| 115 | 116 |
| 116 private: | 117 private: |
| 117 virtual ~OptionsUIHTMLSource(); | 118 virtual ~OptionsUIHTMLSource(); |
| 118 | 119 |
| 119 // Localized strings collection. | 120 // Localized strings collection. |
| 120 scoped_ptr<DictionaryValue> localized_strings_; | 121 scoped_ptr<DictionaryValue> localized_strings_; |
| 121 | 122 |
| 122 DISALLOW_COPY_AND_ASSIGN(OptionsUIHTMLSource); | 123 DISALLOW_COPY_AND_ASSIGN(OptionsUIHTMLSource); |
| 123 }; | 124 }; |
| 124 | 125 |
| 125 OptionsUIHTMLSource::OptionsUIHTMLSource(DictionaryValue* localized_strings) | 126 OptionsUIHTMLSource::OptionsUIHTMLSource(DictionaryValue* localized_strings) { |
| 126 : DataSource(chrome::kChromeUISettingsFrameHost, MessageLoop::current()) { | |
| 127 DCHECK(localized_strings); | 127 DCHECK(localized_strings); |
| 128 localized_strings_.reset(localized_strings); | 128 localized_strings_.reset(localized_strings); |
| 129 } | 129 } |
| 130 | 130 |
| 131 std::string OptionsUIHTMLSource::GetSource() { |
| 132 return chrome::kChromeUISettingsFrameHost; |
| 133 } |
| 134 |
| 131 void OptionsUIHTMLSource::StartDataRequest(const std::string& path, | 135 void OptionsUIHTMLSource::StartDataRequest(const std::string& path, |
| 132 bool is_incognito, | 136 bool is_incognito, |
| 133 int request_id) { | 137 int request_id) { |
| 134 scoped_refptr<base::RefCountedMemory> response_bytes; | 138 scoped_refptr<base::RefCountedMemory> response_bytes; |
| 135 SetFontAndTextDirection(localized_strings_.get()); | 139 URLDataSource::SetFontAndTextDirection(localized_strings_.get()); |
| 136 | 140 |
| 137 if (path == kLocalizedStringsFile) { | 141 if (path == kLocalizedStringsFile) { |
| 138 // Return dynamically-generated strings from memory. | 142 // Return dynamically-generated strings from memory. |
| 139 jstemplate_builder::UseVersion2 version; | 143 jstemplate_builder::UseVersion2 version; |
| 140 std::string strings_js; | 144 std::string strings_js; |
| 141 jstemplate_builder::AppendJsonJS(localized_strings_.get(), &strings_js); | 145 jstemplate_builder::AppendJsonJS(localized_strings_.get(), &strings_js); |
| 142 response_bytes = base::RefCountedString::TakeString(&strings_js); | 146 response_bytes = base::RefCountedString::TakeString(&strings_js); |
| 143 } else if (path == kOptionsBundleJsFile) { | 147 } else if (path == kOptionsBundleJsFile) { |
| 144 // Return (and cache) the options javascript code. | 148 // Return (and cache) the options javascript code. |
| 145 response_bytes = ui::ResourceBundle::GetSharedInstance(). | 149 response_bytes = ui::ResourceBundle::GetSharedInstance(). |
| 146 LoadDataResourceBytes(IDR_OPTIONS_BUNDLE_JS); | 150 LoadDataResourceBytes(IDR_OPTIONS_BUNDLE_JS); |
| 147 } else { | 151 } else { |
| 148 // Return (and cache) the main options html page as the default. | 152 // Return (and cache) the main options html page as the default. |
| 149 response_bytes = ui::ResourceBundle::GetSharedInstance(). | 153 response_bytes = ui::ResourceBundle::GetSharedInstance(). |
| 150 LoadDataResourceBytes(IDR_OPTIONS_HTML); | 154 LoadDataResourceBytes(IDR_OPTIONS_HTML); |
| 151 } | 155 } |
| 152 | 156 |
| 153 SendResponse(request_id, response_bytes); | 157 url_data_source()->SendResponse(request_id, response_bytes); |
| 154 } | 158 } |
| 155 | 159 |
| 156 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const { | 160 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const { |
| 157 if (path == kLocalizedStringsFile || path == kOptionsBundleJsFile) | 161 if (path == kLocalizedStringsFile || path == kOptionsBundleJsFile) |
| 158 return "application/javascript"; | 162 return "application/javascript"; |
| 159 | 163 |
| 160 return "text/html"; | 164 return "text/html"; |
| 161 } | 165 } |
| 162 | 166 |
| 163 OptionsUIHTMLSource::~OptionsUIHTMLSource() {} | 167 OptionsUIHTMLSource::~OptionsUIHTMLSource() {} |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 // Add only if handler's service is enabled. | 407 // Add only if handler's service is enabled. |
| 404 if (handler->IsEnabled()) { | 408 if (handler->IsEnabled()) { |
| 405 // Add handler to the list and also pass the ownership. | 409 // Add handler to the list and also pass the ownership. |
| 406 web_ui()->AddMessageHandler(handler.release()); | 410 web_ui()->AddMessageHandler(handler.release()); |
| 407 handler_raw->GetLocalizedValues(localized_strings); | 411 handler_raw->GetLocalizedValues(localized_strings); |
| 408 handlers_.push_back(handler_raw); | 412 handlers_.push_back(handler_raw); |
| 409 } | 413 } |
| 410 } | 414 } |
| 411 | 415 |
| 412 } // namespace options | 416 } // namespace options |
| OLD | NEW |