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