Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/ui/webui/flags_ui.h" | 5 #include "ios/chrome/browser/ui/webui/flags_ui.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 27 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 28 #include "ios/chrome/browser/chrome_url_constants.h" | 28 #include "ios/chrome/browser/chrome_url_constants.h" |
| 29 #include "ios/web/public/web_ui_ios_data_source.h" | 29 #include "ios/web/public/web_ui_ios_data_source.h" |
| 30 #include "ios/web/public/webui/web_ui_ios.h" | 30 #include "ios/web/public/webui/web_ui_ios.h" |
| 31 #include "ios/web/public/webui/web_ui_ios_message_handler.h" | 31 #include "ios/web/public/webui/web_ui_ios_message_handler.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 33 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 web::WebUIIOSDataSource* CreateFlagsUIHTMLSource( | 37 web::WebUIIOSDataSource* CreateFlagsUIHTMLSource() { |
| 38 BaseFlagsUI::FlagsUIKind flags_ui_kind) { | 38 web::WebUIIOSDataSource* source = |
| 39 web::WebUIIOSDataSource* source = web::WebUIIOSDataSource::Create( | 39 web::WebUIIOSDataSource::Create(kChromeUIFlagsHost); |
| 40 flags_ui_kind == BaseFlagsUI::FLAGS_UI_APPLE ? kChromeUIAppleFlagsHost | |
| 41 : kChromeUIFlagsHost); | |
| 42 | 40 |
| 43 if (flags_ui_kind == BaseFlagsUI::FLAGS_UI_APPLE) { | 41 source->AddLocalizedString(flags_ui::kFlagsLongTitle, |
| 44 source->AddLocalizedString(flags_ui::kFlagsTableTitle, | 42 IDS_FLAGS_UI_LONG_TITLE); |
| 45 IDS_FLAGS_UI_ALTERNATIVES_UI_TABLE_TITLE); | 43 source->AddLocalizedString(flags_ui::kFlagsTableTitle, |
| 46 source->AddLocalizedString( | 44 IDS_FLAGS_UI_TABLE_TITLE); |
| 47 flags_ui::kFlagsNoExperimentsAvailable, | |
| 48 IDS_FLAGS_UI_ALTERNATIVES_UI_NO_EXPERIMENTS_AVAILABLE); | |
| 49 } else { | |
| 50 source->AddLocalizedString(flags_ui::kFlagsLongTitle, | |
| 51 IDS_FLAGS_UI_LONG_TITLE); | |
| 52 source->AddLocalizedString(flags_ui::kFlagsTableTitle, | |
| 53 IDS_FLAGS_UI_TABLE_TITLE); | |
| 54 } | |
| 55 source->AddLocalizedString(flags_ui::kFlagsWarningHeader, | 45 source->AddLocalizedString(flags_ui::kFlagsWarningHeader, |
| 56 IDS_FLAGS_UI_WARNING_HEADER); | 46 IDS_FLAGS_UI_WARNING_HEADER); |
| 57 source->AddLocalizedString(flags_ui::kFlagsBlurb, IDS_FLAGS_UI_WARNING_TEXT); | 47 source->AddLocalizedString(flags_ui::kFlagsBlurb, IDS_FLAGS_UI_WARNING_TEXT); |
| 58 source->AddLocalizedString(flags_ui::kChannelPromoBeta, | 48 source->AddLocalizedString(flags_ui::kChannelPromoBeta, |
| 59 IDS_FLAGS_UI_PROMOTE_BETA_CHANNEL); | 49 IDS_FLAGS_UI_PROMOTE_BETA_CHANNEL); |
| 60 source->AddLocalizedString(flags_ui::kChannelPromoDev, | 50 source->AddLocalizedString(flags_ui::kChannelPromoDev, |
| 61 IDS_FLAGS_UI_PROMOTE_DEV_CHANNEL); | 51 IDS_FLAGS_UI_PROMOTE_DEV_CHANNEL); |
| 62 source->AddLocalizedString(flags_ui::kFlagsUnsupportedTableTitle, | 52 source->AddLocalizedString(flags_ui::kFlagsUnsupportedTableTitle, |
| 63 IDS_FLAGS_UI_UNSUPPORTED_TABLE_TITLE); | 53 IDS_FLAGS_UI_UNSUPPORTED_TABLE_TITLE); |
| 64 source->AddLocalizedString(flags_ui::kFlagsNotSupported, | 54 source->AddLocalizedString(flags_ui::kFlagsNotSupported, |
| 65 IDS_FLAGS_UI_NOT_AVAILABLE); | 55 IDS_FLAGS_UI_NOT_AVAILABLE); |
| 66 source->AddLocalizedString(flags_ui::kFlagsRestartNotice, | 56 source->AddLocalizedString(flags_ui::kFlagsRestartNotice, |
| 67 IDS_FLAGS_UI_RELAUNCH_NOTICE); | 57 IDS_FLAGS_UI_RELAUNCH_NOTICE); |
| 68 source->AddLocalizedString(flags_ui::kFlagsRestartButton, | 58 source->AddLocalizedString(flags_ui::kFlagsRestartButton, |
| 69 IDS_FLAGS_UI_RELAUNCH_BUTTON); | 59 IDS_FLAGS_UI_RELAUNCH_BUTTON); |
| 70 source->AddLocalizedString(flags_ui::kResetAllButton, | 60 source->AddLocalizedString(flags_ui::kResetAllButton, |
| 71 IDS_FLAGS_UI_RESET_ALL_BUTTON); | 61 IDS_FLAGS_UI_RESET_ALL_BUTTON); |
| 72 source->AddLocalizedString(flags_ui::kDisable, IDS_FLAGS_UI_DISABLE); | 62 source->AddLocalizedString(flags_ui::kDisable, IDS_FLAGS_UI_DISABLE); |
| 73 source->AddLocalizedString(flags_ui::kEnable, IDS_FLAGS_UI_ENABLE); | 63 source->AddLocalizedString(flags_ui::kEnable, IDS_FLAGS_UI_ENABLE); |
| 74 | 64 |
| 75 source->SetJsonPath("strings.js"); | 65 source->SetJsonPath("strings.js"); |
| 76 source->AddResourcePath(flags_ui::kFlagsJS, IDR_FLAGS_UI_FLAGS_JS); | 66 source->AddResourcePath(flags_ui::kFlagsJS, IDR_FLAGS_UI_FLAGS_JS); |
| 77 source->SetDefaultResource(flags_ui_kind == BaseFlagsUI::FLAGS_UI_APPLE | 67 source->SetDefaultResource(IDR_FLAGS_UI_FLAGS_HTML); |
| 78 ? IDR_APPLE_FLAGS_HTML | |
| 79 : IDR_FLAGS_UI_FLAGS_HTML); | |
| 80 return source; | 68 return source; |
| 81 } | 69 } |
| 82 | 70 |
| 83 //////////////////////////////////////////////////////////////////////////////// | 71 //////////////////////////////////////////////////////////////////////////////// |
| 84 // | 72 // |
| 85 // FlagsDOMHandler | 73 // FlagsDOMHandler |
| 86 // | 74 // |
| 87 //////////////////////////////////////////////////////////////////////////////// | 75 //////////////////////////////////////////////////////////////////////////////// |
| 88 | 76 |
| 89 // The handler for Javascript messages for the about:flags page. | 77 // The handler for Javascript messages for the about:flags page. |
| 90 class FlagsDOMHandler : public web::WebUIIOSMessageHandler { | 78 class FlagsDOMHandler : public web::WebUIIOSMessageHandler { |
| 91 public: | 79 public: |
| 92 FlagsDOMHandler() | 80 FlagsDOMHandler() |
| 93 : access_(flags_ui::kGeneralAccessFlagsOnly), | 81 : access_(flags_ui::kGeneralAccessFlagsOnly), |
| 94 experimental_features_requested_(false) {} | 82 experimental_features_requested_(false) {} |
| 95 ~FlagsDOMHandler() override {} | 83 ~FlagsDOMHandler() override {} |
| 96 | 84 |
| 97 // Initializes the DOM handler with the provided flags storage and flags | 85 // Initializes the DOM handler with the provided flags storage and flags |
| 98 // access. If there were flags experiments requested from javascript before | 86 // access. If there were flags experiments requested from javascript before |
| 99 // this was called, it calls |HandleRequestExperimentalFeatures| again. | 87 // this was called, it calls |HandleRequestExperimentalFeatures| again. |
| 100 void Init(flags_ui::FlagsStorage* flags_storage, flags_ui::FlagAccess access); | 88 void Init(flags_ui::FlagsStorage* flags_storage, flags_ui::FlagAccess access); |
|
sdefresne
2017/07/04 12:45:25
Since you are changing this file, would you mind c
noyau (Ping after 24h)
2017/07/06 09:53:55
Done.
| |
| 101 | 89 |
| 102 // WebUIMessageHandler implementation. | 90 // WebUIMessageHandler implementation. |
| 103 void RegisterMessages() override; | 91 void RegisterMessages() override; |
| 104 | 92 |
| 105 // Callback for the "requestExperimentFeatures" message. | 93 // Callback for the "requestExperimentFeatures" message. |
| 106 void HandleRequestExperimentalFeatures(const base::ListValue* args); | 94 void HandleRequestExperimentalFeatures(const base::ListValue* args); |
| 107 | 95 |
| 108 // Callback for the "enableExperimentalFeature" message. | 96 // Callback for the "enableExperimentalFeature" message. |
| 109 void HandleEnableExperimentalFeatureMessage(const base::ListValue* args); | 97 void HandleEnableExperimentalFeatureMessage(const base::ListValue* args); |
| 110 | 98 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 | 188 |
| 201 void FlagsDOMHandler::HandleResetAllFlags(const base::ListValue* args) { | 189 void FlagsDOMHandler::HandleResetAllFlags(const base::ListValue* args) { |
| 202 DCHECK(flags_storage_); | 190 DCHECK(flags_storage_); |
| 203 ResetAllFlags(flags_storage_.get()); | 191 ResetAllFlags(flags_storage_.get()); |
| 204 } | 192 } |
| 205 | 193 |
| 206 } // namespace | 194 } // namespace |
| 207 | 195 |
| 208 /////////////////////////////////////////////////////////////////////////////// | 196 /////////////////////////////////////////////////////////////////////////////// |
| 209 // | 197 // |
| 210 // BaseFlagsUI | |
| 211 // | |
| 212 /////////////////////////////////////////////////////////////////////////////// | |
| 213 | |
| 214 BaseFlagsUI::BaseFlagsUI(web::WebUIIOS* web_ui, FlagsUIKind flags_ui_kind) | |
| 215 : web::WebUIIOSController(web_ui), weak_factory_(this) { | |
| 216 Initialize(web_ui, flags_ui_kind); | |
| 217 } | |
| 218 | |
| 219 void BaseFlagsUI::Initialize(web::WebUIIOS* web_ui, FlagsUIKind flags_ui_kind) { | |
| 220 FlagsDOMHandler* handler = new FlagsDOMHandler(); | |
| 221 web_ui->AddMessageHandler(base::WrapUnique(handler)); | |
| 222 | |
| 223 flags_ui::FlagAccess flag_access = flags_ui::kOwnerAccessToFlags; | |
| 224 if (flags_ui_kind == FLAGS_UI_APPLE) | |
| 225 flag_access = flags_ui::kAppleReviewAccessToFlags; | |
| 226 handler->Init(new flags_ui::PrefServiceFlagsStorage( | |
| 227 GetApplicationContext()->GetLocalState()), | |
| 228 flag_access); | |
| 229 | |
| 230 // Set up the about:flags source. | |
| 231 web::WebUIIOSDataSource::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui), | |
| 232 CreateFlagsUIHTMLSource(flags_ui_kind)); | |
| 233 } | |
| 234 | |
| 235 BaseFlagsUI::~BaseFlagsUI() {} | |
| 236 | |
| 237 /////////////////////////////////////////////////////////////////////////////// | |
| 238 // | |
| 239 // FlagsUI | 198 // FlagsUI |
| 240 // | 199 // |
| 241 /////////////////////////////////////////////////////////////////////////////// | 200 /////////////////////////////////////////////////////////////////////////////// |
| 242 | 201 |
| 243 FlagsUI::FlagsUI(web::WebUIIOS* web_ui) | 202 FlagsUI::FlagsUI(web::WebUIIOS* web_ui) |
| 244 : BaseFlagsUI(web_ui, BaseFlagsUI::FLAGS_UI_GENERIC) {} | 203 : web::WebUIIOSController(web_ui), weak_factory_(this) { |
| 204 FlagsDOMHandler* handler = new FlagsDOMHandler(); | |
| 205 web_ui->AddMessageHandler(base::WrapUnique(handler)); | |
| 206 | |
| 207 flags_ui::FlagAccess flag_access = flags_ui::kOwnerAccessToFlags; | |
| 208 handler->Init(new flags_ui::PrefServiceFlagsStorage( | |
| 209 GetApplicationContext()->GetLocalState()), | |
| 210 flag_access); | |
| 211 | |
| 212 // Set up the about:flags source. | |
| 213 web::WebUIIOSDataSource::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui), | |
| 214 CreateFlagsUIHTMLSource()); | |
| 215 } | |
| 245 | 216 |
| 246 FlagsUI::~FlagsUI() {} | 217 FlagsUI::~FlagsUI() {} |
| 247 | |
| 248 /////////////////////////////////////////////////////////////////////////////// | |
| 249 // | |
| 250 // AppleFlagsUI | |
| 251 // | |
| 252 /////////////////////////////////////////////////////////////////////////////// | |
| 253 | |
| 254 AppleFlagsUI::AppleFlagsUI(web::WebUIIOS* web_ui) | |
| 255 : BaseFlagsUI(web_ui, BaseFlagsUI::FLAGS_UI_APPLE) {} | |
| 256 | |
| 257 AppleFlagsUI::~AppleFlagsUI() {} | |
| OLD | NEW |