| 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/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 13 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 13 #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" |
| 14 #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/chrome_notification_types.h" |
| 15 #include "chrome/common/jstemplate_builder.h" | 17 #include "chrome/common/jstemplate_builder.h" |
| 16 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 17 #include "content/browser/tab_contents/tab_contents.h" | 19 #include "content/browser/tab_contents/tab_contents.h" |
| 20 #include "content/public/browser/notification_service.h" |
| 18 #include "grit/browser_resources.h" | 21 #include "grit/browser_resources.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 20 | 23 |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| 23 class ProxySettingsHTMLSource : public ChromeURLDataManager::DataSource { | 26 class ProxySettingsHTMLSource : public ChromeURLDataManager::DataSource { |
| 24 public: | 27 public: |
| 25 explicit ProxySettingsHTMLSource(DictionaryValue* localized_strings); | 28 explicit ProxySettingsHTMLSource(DictionaryValue* localized_strings); |
| 26 | 29 |
| 27 // Called when the network layer has requested a resource underneath | 30 // Called when the network layer has requested a resource underneath |
| (...skipping 30 matching lines...) Expand all Loading... |
| 58 | 61 |
| 59 SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); | 62 SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); |
| 60 } | 63 } |
| 61 | 64 |
| 62 } // namespace | 65 } // namespace |
| 63 | 66 |
| 64 namespace chromeos { | 67 namespace chromeos { |
| 65 | 68 |
| 66 ProxySettingsUI::ProxySettingsUI(TabContents* contents) | 69 ProxySettingsUI::ProxySettingsUI(TabContents* contents) |
| 67 : ChromeWebUI(contents), | 70 : ChromeWebUI(contents), |
| 68 proxy_settings_(NULL), | 71 proxy_handler_(new ProxyHandler()) { |
| 69 proxy_handler_(new ProxyHandler(GetProfile())) { | |
| 70 // |localized_strings| will be owned by ProxySettingsHTMLSource. | 72 // |localized_strings| will be owned by ProxySettingsHTMLSource. |
| 71 DictionaryValue* localized_strings = new DictionaryValue(); | 73 DictionaryValue* localized_strings = new DictionaryValue(); |
| 72 | 74 |
| 73 CoreChromeOSOptionsHandler* core_handler = new CoreChromeOSOptionsHandler(); | 75 CoreChromeOSOptionsHandler* core_handler = new CoreChromeOSOptionsHandler(); |
| 74 core_handler->set_handlers_host(this); | 76 core_handler->set_handlers_host(this); |
| 75 core_handler->GetLocalizedValues(localized_strings); | 77 core_handler->GetLocalizedValues(localized_strings); |
| 76 AddMessageHandler(core_handler->Attach(this)); | 78 AddMessageHandler(core_handler->Attach(this)); |
| 77 | 79 |
| 78 proxy_handler_->GetLocalizedValues(localized_strings); | 80 proxy_handler_->GetLocalizedValues(localized_strings); |
| 79 AddMessageHandler(proxy_handler_->Attach(this)); | 81 AddMessageHandler(proxy_handler_->Attach(this)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 94 } | 96 } |
| 95 proxy_handler_ = NULL; // Weak ptr that is owned by base class, nullify it. | 97 proxy_handler_ = NULL; // Weak ptr that is owned by base class, nullify it. |
| 96 } | 98 } |
| 97 | 99 |
| 98 void ProxySettingsUI::InitializeHandlers() { | 100 void ProxySettingsUI::InitializeHandlers() { |
| 99 std::vector<WebUIMessageHandler*>::iterator iter; | 101 std::vector<WebUIMessageHandler*>::iterator iter; |
| 100 // Skip over the generic handler. | 102 // Skip over the generic handler. |
| 101 for (iter = handlers_.begin() + 1; iter != handlers_.end(); ++iter) { | 103 for (iter = handlers_.begin() + 1; iter != handlers_.end(); ++iter) { |
| 102 (static_cast<OptionsPageUIHandler*>(*iter))->Initialize(); | 104 (static_cast<OptionsPageUIHandler*>(*iter))->Initialize(); |
| 103 } | 105 } |
| 104 if (proxy_settings()) { | 106 GetProfile()->GetProxyConfigTracker()->UIMakeActiveNetworkCurrent(); |
| 105 proxy_settings()->MakeActiveNetworkCurrent(); | 107 std::string network_name; |
| 106 std::string network_name; | 108 GetProfile()->GetProxyConfigTracker()->UIGetCurrentNetworkName( |
| 107 GetProfile()->GetProxyConfigTracker()->UIGetCurrentNetworkName( | 109 &network_name); |
| 108 &network_name); | 110 content::NotificationService::current()->Notify( |
| 109 proxy_handler_->SetNetworkName(network_name); | 111 chrome::NOTIFICATION_CURRENT_NETWORK_CHANGED, |
| 110 } | 112 content::NotificationService::AllSources(), |
| 111 } | 113 content::NotificationService::NoDetails()); |
| 112 | 114 proxy_handler_->SetNetworkName(network_name); |
| 113 chromeos::ProxyCrosSettingsProvider* ProxySettingsUI::proxy_settings() { | |
| 114 if (!proxy_settings_) { | |
| 115 proxy_settings_ = static_cast<chromeos::ProxyCrosSettingsProvider*>( | |
| 116 chromeos::CrosSettings::Get()->GetProvider("cros.session.proxy")); | |
| 117 if (!proxy_settings_) | |
| 118 NOTREACHED() << "Error getting access to proxy cros settings provider"; | |
| 119 } | |
| 120 return proxy_settings_; | |
| 121 } | 115 } |
| 122 | 116 |
| 123 } // namespace chromeos | 117 } // namespace chromeos |
| OLD | NEW |