| 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(std::unique_ptr<flags_ui::FlagsStorage> flags_storage, |
| 89 flags_ui::FlagAccess access); |
| 101 | 90 |
| 102 // WebUIMessageHandler implementation. | 91 // WebUIMessageHandler implementation. |
| 103 void RegisterMessages() override; | 92 void RegisterMessages() override; |
| 104 | 93 |
| 105 // Callback for the "requestExperimentFeatures" message. | 94 // Callback for the "requestExperimentFeatures" message. |
| 106 void HandleRequestExperimentalFeatures(const base::ListValue* args); | 95 void HandleRequestExperimentalFeatures(const base::ListValue* args); |
| 107 | 96 |
| 108 // Callback for the "enableExperimentalFeature" message. | 97 // Callback for the "enableExperimentalFeature" message. |
| 109 void HandleEnableExperimentalFeatureMessage(const base::ListValue* args); | 98 void HandleEnableExperimentalFeatureMessage(const base::ListValue* args); |
| 110 | 99 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 134 web_ui()->RegisterMessageCallback( | 123 web_ui()->RegisterMessageCallback( |
| 135 flags_ui::kRestartBrowser, | 124 flags_ui::kRestartBrowser, |
| 136 base::Bind(&FlagsDOMHandler::HandleRestartBrowser, | 125 base::Bind(&FlagsDOMHandler::HandleRestartBrowser, |
| 137 base::Unretained(this))); | 126 base::Unretained(this))); |
| 138 web_ui()->RegisterMessageCallback( | 127 web_ui()->RegisterMessageCallback( |
| 139 flags_ui::kResetAllFlags, | 128 flags_ui::kResetAllFlags, |
| 140 base::Bind(&FlagsDOMHandler::HandleResetAllFlags, | 129 base::Bind(&FlagsDOMHandler::HandleResetAllFlags, |
| 141 base::Unretained(this))); | 130 base::Unretained(this))); |
| 142 } | 131 } |
| 143 | 132 |
| 144 void FlagsDOMHandler::Init(flags_ui::FlagsStorage* flags_storage, | 133 void FlagsDOMHandler::Init( |
| 145 flags_ui::FlagAccess access) { | 134 std::unique_ptr<flags_ui::FlagsStorage> flags_storage, |
| 146 flags_storage_.reset(flags_storage); | 135 flags_ui::FlagAccess access) { |
| 136 flags_storage_ = std::move(flags_storage); |
| 147 access_ = access; | 137 access_ = access; |
| 148 | 138 |
| 149 if (experimental_features_requested_) | 139 if (experimental_features_requested_) |
| 150 HandleRequestExperimentalFeatures(NULL); | 140 HandleRequestExperimentalFeatures(NULL); |
| 151 } | 141 } |
| 152 | 142 |
| 153 void FlagsDOMHandler::HandleRequestExperimentalFeatures( | 143 void FlagsDOMHandler::HandleRequestExperimentalFeatures( |
| 154 const base::ListValue* args) { | 144 const base::ListValue* args) { |
| 155 experimental_features_requested_ = true; | 145 experimental_features_requested_ = true; |
| 156 // Bail out if the handler hasn't been initialized yet. The request will be | 146 // Bail out if the handler hasn't been initialized yet. The request will be |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 190 |
| 201 void FlagsDOMHandler::HandleResetAllFlags(const base::ListValue* args) { | 191 void FlagsDOMHandler::HandleResetAllFlags(const base::ListValue* args) { |
| 202 DCHECK(flags_storage_); | 192 DCHECK(flags_storage_); |
| 203 ResetAllFlags(flags_storage_.get()); | 193 ResetAllFlags(flags_storage_.get()); |
| 204 } | 194 } |
| 205 | 195 |
| 206 } // namespace | 196 } // namespace |
| 207 | 197 |
| 208 /////////////////////////////////////////////////////////////////////////////// | 198 /////////////////////////////////////////////////////////////////////////////// |
| 209 // | 199 // |
| 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 | 200 // FlagsUI |
| 240 // | 201 // |
| 241 /////////////////////////////////////////////////////////////////////////////// | 202 /////////////////////////////////////////////////////////////////////////////// |
| 242 | 203 |
| 243 FlagsUI::FlagsUI(web::WebUIIOS* web_ui) | 204 FlagsUI::FlagsUI(web::WebUIIOS* web_ui) |
| 244 : BaseFlagsUI(web_ui, BaseFlagsUI::FLAGS_UI_GENERIC) {} | 205 : web::WebUIIOSController(web_ui), weak_factory_(this) { |
| 206 FlagsDOMHandler* handler = new FlagsDOMHandler(); |
| 207 web_ui->AddMessageHandler(base::WrapUnique(handler)); |
| 208 |
| 209 flags_ui::FlagAccess flag_access = flags_ui::kOwnerAccessToFlags; |
| 210 handler->Init(base::MakeUnique<flags_ui::PrefServiceFlagsStorage>( |
| 211 GetApplicationContext()->GetLocalState()), |
| 212 flag_access); |
| 213 |
| 214 // Set up the about:flags source. |
| 215 web::WebUIIOSDataSource::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui), |
| 216 CreateFlagsUIHTMLSource()); |
| 217 } |
| 245 | 218 |
| 246 FlagsUI::~FlagsUI() {} | 219 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 |