OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/chromeos/cros_settings.h" | 10 #include "chrome/browser/chromeos/cros_settings.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/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 13 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
14 #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" |
15 #include "chrome/browser/ui/webui/options/chromeos/proxy_handler.h" | 15 #include "chrome/browser/ui/webui/options/chromeos/proxy_handler.h" |
16 #include "chrome/common/jstemplate_builder.h" | 16 #include "chrome/common/jstemplate_builder.h" |
17 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 18 #include "content/browser/webui/web_ui.h" |
18 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
19 #include "content/public/browser/web_ui_message_handler.h" | 20 #include "content/public/browser/web_ui_message_handler.h" |
20 #include "grit/browser_resources.h" | 21 #include "grit/browser_resources.h" |
21 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
22 | 23 |
23 using content::WebContents; | 24 using content::WebContents; |
24 using content::WebUIMessageHandler; | 25 using content::WebUIMessageHandler; |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 std::string full_html = jstemplate_builder::GetI18nTemplateHtml( | 62 std::string full_html = jstemplate_builder::GetI18nTemplateHtml( |
62 html, localized_strings_.get()); | 63 html, localized_strings_.get()); |
63 | 64 |
64 SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); | 65 SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); |
65 } | 66 } |
66 | 67 |
67 } // namespace | 68 } // namespace |
68 | 69 |
69 namespace chromeos { | 70 namespace chromeos { |
70 | 71 |
71 ProxySettingsUI::ProxySettingsUI(WebContents* contents) | 72 ProxySettingsUI::ProxySettingsUI(WebUI* web_ui) |
72 : WebUI(contents, this), | 73 : WebUIController(web_ui), |
73 proxy_handler_(new ProxyHandler()) { | 74 proxy_handler_(new ProxyHandler()), |
| 75 core_handler_(new CoreChromeOSOptionsHandler()) { |
74 // |localized_strings| will be owned by ProxySettingsHTMLSource. | 76 // |localized_strings| will be owned by ProxySettingsHTMLSource. |
75 DictionaryValue* localized_strings = new DictionaryValue(); | 77 DictionaryValue* localized_strings = new DictionaryValue(); |
76 | 78 |
77 CoreChromeOSOptionsHandler* core_handler = new CoreChromeOSOptionsHandler(); | 79 core_handler_->set_handlers_host(this); |
78 core_handler->set_handlers_host(this); | 80 core_handler_->GetLocalizedValues(localized_strings); |
79 core_handler->GetLocalizedValues(localized_strings); | 81 web_ui->AddMessageHandler(core_handler_); |
80 AddMessageHandler(core_handler); | |
81 | 82 |
82 proxy_handler_->GetLocalizedValues(localized_strings); | 83 proxy_handler_->GetLocalizedValues(localized_strings); |
83 AddMessageHandler(proxy_handler_); | 84 web_ui->AddMessageHandler(proxy_handler_); |
84 | 85 |
85 ProxySettingsHTMLSource* source = | 86 ProxySettingsHTMLSource* source = |
86 new ProxySettingsHTMLSource(localized_strings); | 87 new ProxySettingsHTMLSource(localized_strings); |
87 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 88 Profile* profile = Profile::FromBrowserContext( |
| 89 web_ui->web_contents()->GetBrowserContext()); |
88 profile->GetChromeURLDataManager()->AddDataSource(source); | 90 profile->GetChromeURLDataManager()->AddDataSource(source); |
89 } | 91 } |
90 | 92 |
91 ProxySettingsUI::~ProxySettingsUI() { | 93 ProxySettingsUI::~ProxySettingsUI() { |
92 // Uninitialize all registered handlers. The base class owns them and it will | 94 // Uninitialize all registered handlers. The base class owns them and it will |
93 // eventually delete them. Skip over the generic handler. | 95 // eventually delete them. |
94 for (std::vector<WebUIMessageHandler*>::iterator iter = handlers_.begin() + 1; | 96 core_handler_->Uninitialize(); |
95 iter != handlers_.end(); | 97 proxy_handler_->Uninitialize(); |
96 ++iter) { | |
97 static_cast<OptionsPageUIHandler*>(*iter)->Uninitialize(); | |
98 } | |
99 proxy_handler_ = NULL; // Weak ptr that is owned by base class, nullify it. | |
100 } | 98 } |
101 | 99 |
102 void ProxySettingsUI::InitializeHandlers() { | 100 void ProxySettingsUI::InitializeHandlers() { |
103 std::vector<WebUIMessageHandler*>::iterator iter; | 101 core_handler_->Initialize(); |
104 // Skip over the generic handler. | 102 proxy_handler_->Initialize(); |
105 for (iter = handlers_.begin() + 1; iter != handlers_.end(); ++iter) { | 103 Profile* profile = Profile::FromBrowserContext( |
106 (static_cast<OptionsPageUIHandler*>(*iter))->Initialize(); | 104 web_ui()->web_contents()->GetBrowserContext()); |
107 } | |
108 Profile* profile = | |
109 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | |
110 PrefProxyConfigTracker* proxy_tracker = profile->GetProxyConfigTracker(); | 105 PrefProxyConfigTracker* proxy_tracker = profile->GetProxyConfigTracker(); |
111 proxy_tracker->UIMakeActiveNetworkCurrent(); | 106 proxy_tracker->UIMakeActiveNetworkCurrent(); |
112 std::string network_name; | 107 std::string network_name; |
113 proxy_tracker->UIGetCurrentNetworkName(&network_name); | 108 proxy_tracker->UIGetCurrentNetworkName(&network_name); |
114 proxy_handler_->SetNetworkName(network_name); | 109 proxy_handler_->SetNetworkName(network_name); |
115 } | 110 } |
116 | 111 |
117 } // namespace chromeos | 112 } // namespace chromeos |
OLD | NEW |