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/chromeos/proxy_settings_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/proxy_settings_ui.h" |
6 | 6 |
7 #include "base/memory/ref_counted_memory.h" | 7 #include "base/memory/ref_counted_memory.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/chromeos/proxy_config_service_impl.h" | 11 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
12 #include "chrome/browser/chromeos/settings/cros_settings.h" | 12 #include "chrome/browser/chromeos/settings/cros_settings.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
15 #include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler
.h" | 14 #include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler
.h" |
16 #include "chrome/browser/ui/webui/options/chromeos/proxy_handler.h" | 15 #include "chrome/browser/ui/webui/options/chromeos/proxy_handler.h" |
| 16 #include "chrome/browser/ui/webui/web_ui_util.h" |
17 #include "chrome/common/jstemplate_builder.h" | 17 #include "chrome/common/jstemplate_builder.h" |
18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
19 #include "content/public/browser/url_data_source_delegate.h" | 19 #include "content/public/browser/url_data_source.h" |
20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "content/public/browser/web_ui.h" | 21 #include "content/public/browser/web_ui.h" |
22 #include "content/public/browser/web_ui_message_handler.h" | 22 #include "content/public/browser/web_ui_message_handler.h" |
23 #include "grit/browser_resources.h" | 23 #include "grit/browser_resources.h" |
24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
25 | 25 |
26 using content::WebContents; | 26 using content::WebContents; |
27 using content::WebUIMessageHandler; | 27 using content::WebUIMessageHandler; |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 class ProxySettingsHTMLSource : public content::URLDataSourceDelegate { | 31 class ProxySettingsHTMLSource : public content::URLDataSource { |
32 public: | 32 public: |
33 explicit ProxySettingsHTMLSource(DictionaryValue* localized_strings); | 33 explicit ProxySettingsHTMLSource(DictionaryValue* localized_strings); |
34 | 34 |
35 // content::URLDataSourceDelegate implementation. | 35 // content::URLDataSource implementation. |
36 virtual std::string GetSource() OVERRIDE; | 36 virtual std::string GetSource() OVERRIDE; |
37 virtual void StartDataRequest(const std::string& path, | 37 virtual void StartDataRequest( |
38 bool is_incognito, | 38 const std::string& path, |
39 int request_id) OVERRIDE; | 39 bool is_incognito, |
| 40 const content::URLDataSource::GotDataCallback& callback) OVERRIDE; |
40 virtual std::string GetMimeType(const std::string&) const OVERRIDE { | 41 virtual std::string GetMimeType(const std::string&) const OVERRIDE { |
41 return "text/html"; | 42 return "text/html"; |
42 } | 43 } |
43 | 44 |
44 protected: | 45 protected: |
45 virtual ~ProxySettingsHTMLSource() {} | 46 virtual ~ProxySettingsHTMLSource() {} |
46 | 47 |
47 private: | 48 private: |
48 scoped_ptr<DictionaryValue> localized_strings_; | 49 scoped_ptr<DictionaryValue> localized_strings_; |
49 | 50 |
50 DISALLOW_COPY_AND_ASSIGN(ProxySettingsHTMLSource); | 51 DISALLOW_COPY_AND_ASSIGN(ProxySettingsHTMLSource); |
51 }; | 52 }; |
52 | 53 |
53 ProxySettingsHTMLSource::ProxySettingsHTMLSource( | 54 ProxySettingsHTMLSource::ProxySettingsHTMLSource( |
54 DictionaryValue* localized_strings) | 55 DictionaryValue* localized_strings) |
55 : localized_strings_(localized_strings) { | 56 : localized_strings_(localized_strings) { |
56 } | 57 } |
57 | 58 |
58 std::string ProxySettingsHTMLSource::GetSource() { | 59 std::string ProxySettingsHTMLSource::GetSource() { |
59 return chrome::kChromeUIProxySettingsHost; | 60 return chrome::kChromeUIProxySettingsHost; |
60 } | 61 } |
61 | 62 |
62 void ProxySettingsHTMLSource::StartDataRequest(const std::string& path, | 63 void ProxySettingsHTMLSource::StartDataRequest( |
63 bool is_incognito, | 64 const std::string& path, |
64 int request_id) { | 65 bool is_incognito, |
65 URLDataSource::SetFontAndTextDirection(localized_strings_.get()); | 66 const content::URLDataSource::GotDataCallback& callback) { |
| 67 web_ui_util::SetFontAndTextDirection(localized_strings_.get()); |
66 | 68 |
67 static const base::StringPiece html( | 69 static const base::StringPiece html( |
68 ResourceBundle::GetSharedInstance().GetRawDataResource( | 70 ResourceBundle::GetSharedInstance().GetRawDataResource( |
69 IDR_PROXY_SETTINGS_HTML)); | 71 IDR_PROXY_SETTINGS_HTML)); |
70 std::string full_html = jstemplate_builder::GetI18nTemplateHtml( | 72 std::string full_html = jstemplate_builder::GetI18nTemplateHtml( |
71 html, localized_strings_.get()); | 73 html, localized_strings_.get()); |
72 | 74 |
73 url_data_source()->SendResponse( | 75 callback.Run(base::RefCountedString::TakeString(&full_html)); |
74 request_id, base::RefCountedString::TakeString(&full_html)); | |
75 } | 76 } |
76 | 77 |
77 } // namespace | 78 } // namespace |
78 | 79 |
79 namespace chromeos { | 80 namespace chromeos { |
80 | 81 |
81 ProxySettingsUI::ProxySettingsUI(content::WebUI* web_ui) | 82 ProxySettingsUI::ProxySettingsUI(content::WebUI* web_ui) |
82 : WebUIController(web_ui), | 83 : WebUIController(web_ui), |
83 proxy_handler_(new options::ProxyHandler()), | 84 proxy_handler_(new options::ProxyHandler()), |
84 core_handler_(new options::CoreChromeOSOptionsHandler()) { | 85 core_handler_(new options::CoreChromeOSOptionsHandler()) { |
(...skipping 26 matching lines...) Expand all Loading... |
111 core_handler_->InitializePage(); | 112 core_handler_->InitializePage(); |
112 proxy_handler_->InitializePage(); | 113 proxy_handler_->InitializePage(); |
113 Profile* profile = Profile::FromWebUI(web_ui()); | 114 Profile* profile = Profile::FromWebUI(web_ui()); |
114 PrefProxyConfigTracker* proxy_tracker = profile->GetProxyConfigTracker(); | 115 PrefProxyConfigTracker* proxy_tracker = profile->GetProxyConfigTracker(); |
115 proxy_tracker->UIMakeActiveNetworkCurrent(); | 116 proxy_tracker->UIMakeActiveNetworkCurrent(); |
116 std::string network_name; | 117 std::string network_name; |
117 proxy_tracker->UIGetCurrentNetworkName(&network_name); | 118 proxy_tracker->UIGetCurrentNetworkName(&network_name); |
118 } | 119 } |
119 | 120 |
120 } // namespace chromeos | 121 } // namespace chromeos |
OLD | NEW |