| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/local_discovery/local_discovery_ui.h" | 5 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" |
| 8 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h" | 10 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h" |
| 9 #include "chrome/browser/ui/webui/metrics_handler.h" | 11 #include "chrome/browser/ui/webui/metrics_handler.h" |
| 10 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 11 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
| 14 #include "content/public/browser/web_contents.h" |
| 12 #include "content/public/browser/web_ui.h" | 15 #include "content/public/browser/web_ui.h" |
| 13 #include "content/public/browser/web_ui_data_source.h" | 16 #include "content/public/browser/web_ui_data_source.h" |
| 14 #include "grit/browser_resources.h" | 17 #include "grit/browser_resources.h" |
| 15 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 16 | 19 |
| 17 namespace { | 20 namespace { |
| 18 | 21 |
| 19 content::WebUIDataSource* CreateLocalDiscoveryHTMLSource() { | 22 content::WebUIDataSource* CreateLocalDiscoveryHTMLSource() { |
| 20 content::WebUIDataSource* source = | 23 content::WebUIDataSource* source = |
| 21 content::WebUIDataSource::Create(chrome::kChromeUIDevicesHost); | 24 content::WebUIDataSource::Create(chrome::kChromeUIDevicesHost); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 source->AddLocalizedString("cloudDevicesNeedLogin", | 80 source->AddLocalizedString("cloudDevicesNeedLogin", |
| 78 IDS_LOCAL_DISCOVERY_CLOUD_DEVICES_NEED_LOGIN); | 81 IDS_LOCAL_DISCOVERY_CLOUD_DEVICES_NEED_LOGIN); |
| 79 source->AddLocalizedString("cloudDevicesLogin", | 82 source->AddLocalizedString("cloudDevicesLogin", |
| 80 IDS_LOCAL_DISCOVERY_CLOUD_DEVICES_LOGIN); | 83 IDS_LOCAL_DISCOVERY_CLOUD_DEVICES_LOGIN); |
| 81 source->AddLocalizedString("registerNeedLogin", | 84 source->AddLocalizedString("registerNeedLogin", |
| 82 IDS_LOCAL_DISCOVERY_REGISTER_NEED_LOGIN); | 85 IDS_LOCAL_DISCOVERY_REGISTER_NEED_LOGIN); |
| 83 source->AddLocalizedString("availableDevicesTitle", | 86 source->AddLocalizedString("availableDevicesTitle", |
| 84 IDS_LOCAL_DISCOVERY_AVAILABLE_DEVICES); | 87 IDS_LOCAL_DISCOVERY_AVAILABLE_DEVICES); |
| 85 source->AddLocalizedString("myDevicesTitle", | 88 source->AddLocalizedString("myDevicesTitle", |
| 86 IDS_LOCAL_DISCOVERY_MY_DEVICES); | 89 IDS_LOCAL_DISCOVERY_MY_DEVICES); |
| 87 | 90 source->AddLocalizedString("backButton", IDS_SETTINGS_TITLE); |
| 88 | 91 |
| 89 // Cloud print connector-related strings. | 92 // Cloud print connector-related strings. |
| 90 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS) | 93 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS) |
| 91 source->AddLocalizedString("cloudPrintConnectorEnablingButton", | 94 source->AddLocalizedString("cloudPrintConnectorEnablingButton", |
| 92 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLING_BUTTON); | 95 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLING_BUTTON); |
| 93 source->AddLocalizedString("cloudPrintConnectorDisabledButton", | 96 source->AddLocalizedString("cloudPrintConnectorDisabledButton", |
| 94 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_BUTTON); | 97 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_BUTTON); |
| 95 source->AddLocalizedString("cloudPrintConnectorEnabledButton", | 98 source->AddLocalizedString("cloudPrintConnectorEnabledButton", |
| 96 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_BUTTON); | 99 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_BUTTON); |
| 97 source->AddLocalizedString("cloudPrintName", | 100 source->AddLocalizedString("cloudPrintName", |
| 98 IDS_GOOGLE_CLOUD_PRINT); | 101 IDS_GOOGLE_CLOUD_PRINT); |
| 99 source->AddLocalizedString("titleConnector", | 102 source->AddLocalizedString("titleConnector", |
| 100 IDS_LOCAL_DISCOVERY_CONNECTOR_SECTION); | 103 IDS_LOCAL_DISCOVERY_CONNECTOR_SECTION); |
| 101 #endif | 104 #endif |
| 102 | 105 |
| 103 source->SetJsonPath("strings.js"); | 106 source->SetJsonPath("strings.js"); |
| 104 | 107 |
| 105 source->DisableDenyXFrameOptions(); | 108 source->DisableDenyXFrameOptions(); |
| 106 | 109 |
| 107 return source; | 110 return source; |
| 108 } | 111 } |
| 109 | 112 |
| 110 } // namespace | 113 } // namespace |
| 111 | 114 |
| 112 LocalDiscoveryUI::LocalDiscoveryUI(content::WebUI* web_ui) | 115 LocalDiscoveryUI::LocalDiscoveryUI(content::WebUI* web_ui) |
| 113 : WebUIController(web_ui) { | 116 : WebUIController(web_ui) { |
| 114 // Set up the chrome://devices/ source. | 117 // Set up the chrome://devices/ source. |
| 115 Profile* profile = Profile::FromWebUI(web_ui); | 118 content::WebUIDataSource* source = CreateLocalDiscoveryHTMLSource(); |
| 116 content::WebUIDataSource::Add(profile, CreateLocalDiscoveryHTMLSource()); | 119 Browser* browser = |
| 120 chrome::FindBrowserWithWebContents(web_ui->GetWebContents()); |
| 121 // Show a back button pointing to Settings if the browser has no location bar. |
| 122 if (browser && browser->is_trusted_source()) |
| 123 source->AddString("backButtonURL", chrome::kChromeUISettingsURL); |
| 124 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source); |
| 117 | 125 |
| 118 // TODO(gene): Use LocalDiscoveryUIHandler to send updated to the devices | 126 // TODO(gene): Use LocalDiscoveryUIHandler to send updated to the devices |
| 119 // page. For example | 127 // page. For example |
| 120 web_ui->AddMessageHandler(new local_discovery::LocalDiscoveryUIHandler()); | 128 web_ui->AddMessageHandler(new local_discovery::LocalDiscoveryUIHandler()); |
| 121 web_ui->AddMessageHandler(new MetricsHandler()); | 129 web_ui->AddMessageHandler(new MetricsHandler()); |
| 122 } | 130 } |
| 123 | 131 |
| 124 void LocalDiscoveryUI::RegisterProfilePrefs( | 132 void LocalDiscoveryUI::RegisterProfilePrefs( |
| 125 user_prefs::PrefRegistrySyncable* registry) { | 133 user_prefs::PrefRegistrySyncable* registry) { |
| 126 registry->RegisterBooleanPref( | 134 registry->RegisterBooleanPref( |
| 127 prefs::kLocalDiscoveryNotificationsEnabled, | 135 prefs::kLocalDiscoveryNotificationsEnabled, |
| 128 #if defined(OS_WIN) | 136 #if defined(OS_WIN) |
| 129 false, | 137 false, |
| 130 #else | 138 #else |
| 131 true, | 139 true, |
| 132 #endif | 140 #endif |
| 133 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 141 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 134 } | 142 } |
| OLD | NEW |