Index: ios/chrome/browser/ui/webui/flags_ui.cc |
diff --git a/chrome/browser/ui/webui/flags_ui.cc b/ios/chrome/browser/ui/webui/flags_ui.cc |
similarity index 46% |
copy from chrome/browser/ui/webui/flags_ui.cc |
copy to ios/chrome/browser/ui/webui/flags_ui.cc |
index 48c7920b68fc10c7874930db0dd801e898bcc476..95153375391a60291480c470ea91f87532d2491a 100644 |
--- a/chrome/browser/ui/webui/flags_ui.cc |
+++ b/ios/chrome/browser/ui/webui/flags_ui.cc |
@@ -1,73 +1,62 @@ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/ui/webui/flags_ui.h" |
+#include "ios/chrome/browser/ui/webui/flags_ui.h" |
#include <string> |
#include "base/bind.h" |
#include "base/bind_helpers.h" |
+#include "base/bind_helpers.h" |
#include "base/memory/ref_counted_memory.h" |
#include "base/prefs/pref_registry_simple.h" |
#include "base/prefs/pref_service.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/values.h" |
-#include "chrome/browser/about_flags.h" |
-#include "chrome/browser/browser_process.h" |
-#include "chrome/browser/lifetime/application_lifetime.h" |
-#include "chrome/browser/profiles/profile.h" |
-#include "chrome/common/channel_info.h" |
-#include "chrome/common/pref_names.h" |
-#include "chrome/common/url_constants.h" |
#include "components/flags_ui/flags_ui_constants.h" |
#include "components/flags_ui/flags_ui_pref_names.h" |
#include "components/flags_ui/pref_service_flags_storage.h" |
#include "components/version_info/version_info.h" |
-#include "content/public/browser/web_contents.h" |
-#include "content/public/browser/web_ui.h" |
-#include "content/public/browser/web_ui_data_source.h" |
-#include "content/public/browser/web_ui_message_handler.h" |
#include "grit/components_chromium_strings.h" |
#include "grit/components_google_chrome_strings.h" |
#include "grit/components_resources.h" |
#include "grit/components_scaled_resources.h" |
#include "grit/components_strings.h" |
+#include "ios/chrome/browser/about_flags.h" |
+#include "ios/chrome/browser/application_context.h" |
+#include "ios/chrome/browser/chrome_url_constants.h" |
+#include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h" |
+#include "ios/public/provider/web/web_ui_ios.h" |
+#include "ios/public/provider/web/web_ui_ios_message_handler.h" |
+#include "ios/web/public/web_ui_ios_data_source.h" |
+#include "ios/web/public/web_ui_ios_data_source.h" |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/resource/resource_bundle.h" |
-#if defined(OS_CHROMEOS) |
-#include "base/sys_info.h" |
-#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
-#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h" |
-#include "chrome/browser/chromeos/settings/cros_settings.h" |
-#include "chrome/browser/chromeos/settings/owner_flags_storage.h" |
-#include "chromeos/dbus/dbus_thread_manager.h" |
-#include "chromeos/dbus/session_manager_client.h" |
-#include "components/pref_registry/pref_registry_syncable.h" |
-#include "components/user_manager/user_manager.h" |
-#endif |
- |
-using content::WebContents; |
-using content::WebUIMessageHandler; |
- |
namespace { |
-content::WebUIDataSource* CreateFlagsUIHTMLSource() { |
- content::WebUIDataSource* source = |
- content::WebUIDataSource::Create(chrome::kChromeUIFlagsHost); |
- |
- source->AddLocalizedString(flags_ui::kFlagsLongTitle, |
- IDS_FLAGS_UI_LONG_TITLE); |
- source->AddLocalizedString(flags_ui::kFlagsTableTitle, |
- IDS_FLAGS_UI_TABLE_TITLE); |
+web::WebUIIOSDataSource* CreateFlagsUIHTMLSource( |
+ BaseFlagsUI::FlagsUIKind flags_ui_kind) { |
+ web::WebUIIOSDataSource* source = web::WebUIIOSDataSource::Create( |
+ flags_ui_kind == BaseFlagsUI::FLAGS_UI_APPLE ? kChromeUIAppleFlagsHost |
+ : kChromeUIFlagsHost); |
+ |
+ if (flags_ui_kind == BaseFlagsUI::FLAGS_UI_APPLE) { |
+ source->AddLocalizedString(flags_ui::kFlagsTableTitle, |
+ IDS_FLAGS_UI_ALTERNATIVES_UI_TABLE_TITLE); |
+ source->AddLocalizedString( |
+ flags_ui::kFlagsNoExperimentsAvailable, |
+ IDS_FLAGS_UI_ALTERNATIVES_UI_NO_EXPERIMENTS_AVAILABLE); |
+ } else { |
+ source->AddLocalizedString(flags_ui::kFlagsLongTitle, |
+ IDS_FLAGS_UI_LONG_TITLE); |
+ source->AddLocalizedString(flags_ui::kFlagsTableTitle, |
+ IDS_FLAGS_UI_TABLE_TITLE); |
+ } |
source->AddLocalizedString(flags_ui::kFlagsWarningHeader, |
IDS_FLAGS_UI_WARNING_HEADER); |
source->AddLocalizedString(flags_ui::kFlagsBlurb, IDS_FLAGS_UI_WARNING_TEXT); |
- source->AddLocalizedString(flags_ui::kChannelPromoBeta, |
- IDS_FLAGS_UI_PROMOTE_BETA_CHANNEL); |
- source->AddLocalizedString(flags_ui::kChannelPromoDev, |
- IDS_FLAGS_UI_PROMOTE_DEV_CHANNEL); |
source->AddLocalizedString(flags_ui::kFlagsUnsupportedTableTitle, |
IDS_FLAGS_UI_UNSUPPORTED_TABLE_TITLE); |
source->AddLocalizedString(flags_ui::kFlagsNotSupported, |
@@ -81,25 +70,11 @@ content::WebUIDataSource* CreateFlagsUIHTMLSource() { |
source->AddLocalizedString(flags_ui::kDisable, IDS_FLAGS_UI_DISABLE); |
source->AddLocalizedString(flags_ui::kEnable, IDS_FLAGS_UI_ENABLE); |
-#if defined(OS_CHROMEOS) |
- if (!user_manager::UserManager::Get()->IsCurrentUserOwner() && |
- base::SysInfo::IsRunningOnChromeOS()) { |
- // Set the strings to show which user can actually change the flags. |
- std::string owner; |
- chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner); |
- source->AddString(flags_ui::kOwnerWarning, |
- l10n_util::GetStringFUTF16(IDS_FLAGS_UI_SYSTEM_OWNER_ONLY, |
- base::UTF8ToUTF16(owner))); |
- } else { |
- // The warning will be only shown on ChromeOS, when the current user is not |
- // the owner. |
- source->AddString(flags_ui::kOwnerWarning, base::string16()); |
- } |
-#endif |
- |
source->SetJsonPath("strings.js"); |
source->AddResourcePath(flags_ui::kFlagsJS, IDR_FLAGS_UI_FLAGS_JS); |
- source->SetDefaultResource(IDR_FLAGS_UI_FLAGS_HTML); |
+ source->SetDefaultResource(flags_ui_kind == BaseFlagsUI::FLAGS_UI_APPLE |
+ ? IDR_APPLE_FLAGS_HTML |
+ : IDR_FLAGS_UI_FLAGS_HTML); |
return source; |
} |
@@ -110,18 +85,17 @@ content::WebUIDataSource* CreateFlagsUIHTMLSource() { |
//////////////////////////////////////////////////////////////////////////////// |
// The handler for Javascript messages for the about:flags page. |
-class FlagsDOMHandler : public WebUIMessageHandler { |
+class FlagsDOMHandler : public web::WebUIIOSMessageHandler { |
public: |
- FlagsDOMHandler() : access_(flags_ui::kGeneralAccessFlagsOnly), |
- experimental_features_requested_(false) { |
- } |
+ FlagsDOMHandler() |
+ : access_(flags_ui::kGeneralAccessFlagsOnly), |
+ experimental_features_requested_(false) {} |
~FlagsDOMHandler() override {} |
// Initializes the DOM handler with the provided flags storage and flags |
// access. If there were flags experiments requested from javascript before |
// this was called, it calls |HandleRequestExperimentalFeatures| again. |
- void Init(flags_ui::FlagsStorage* flags_storage, |
- flags_ui::FlagAccess access); |
+ void Init(flags_ui::FlagsStorage* flags_storage, flags_ui::FlagAccess access); |
// WebUIMessageHandler implementation. |
void RegisterMessages() override; |
@@ -186,27 +160,17 @@ void FlagsDOMHandler::HandleRequestExperimentalFeatures( |
scoped_ptr<base::ListValue> supported_features(new base::ListValue); |
scoped_ptr<base::ListValue> unsupported_features(new base::ListValue); |
- about_flags::GetFlagFeatureEntries(flags_storage_.get(), |
- access_, |
- supported_features.get(), |
- unsupported_features.get()); |
+ GetFlagFeatureEntries(flags_storage_.get(), access_, supported_features.get(), |
+ unsupported_features.get()); |
results.Set(flags_ui::kSupportedFeatures, supported_features.release()); |
results.Set(flags_ui::kUnsupportedFeatures, unsupported_features.release()); |
- results.SetBoolean(flags_ui::kNeedsRestart, |
- about_flags::IsRestartNeededToCommitChanges()); |
+ // Cannot restart the browser on iOS. |
+ results.SetBoolean(flags_ui::kNeedsRestart, false); |
results.SetBoolean(flags_ui::kShowOwnerWarning, |
access_ == flags_ui::kGeneralAccessFlagsOnly); |
-#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
- version_info::Channel channel = chrome::GetChannel(); |
- results.SetBoolean(flags_ui::kShowBetaChannelPromotion, |
- channel == version_info::Channel::STABLE); |
- results.SetBoolean(flags_ui::kShowDevChannelPromotion, |
- channel == version_info::Channel::BETA); |
-#else |
results.SetBoolean(flags_ui::kShowBetaChannelPromotion, false); |
results.SetBoolean(flags_ui::kShowDevChannelPromotion, false); |
-#endif |
web_ui()->CallJavascriptFunction(flags_ui::kReturnExperimentalFeatures, |
results); |
} |
@@ -224,114 +188,75 @@ void FlagsDOMHandler::HandleEnableExperimentalFeatureMessage( |
!args->GetString(1, &enable_str)) |
return; |
- about_flags::SetFeatureEntryEnabled(flags_storage_.get(), entry_internal_name, |
- enable_str == "true"); |
+ SetFeatureEntryEnabled(flags_storage_.get(), entry_internal_name, |
+ enable_str == "true"); |
} |
void FlagsDOMHandler::HandleRestartBrowser(const base::ListValue* args) { |
- DCHECK(flags_storage_); |
-#if defined(OS_CHROMEOS) |
- // On ChromeOS be less intrusive and restart inside the user session after |
- // we apply the newly selected flags. |
- base::CommandLine user_flags(base::CommandLine::NO_PROGRAM); |
- about_flags::ConvertFlagsToSwitches(flags_storage_.get(), |
- &user_flags, |
- flags_ui::kAddSentinels); |
- base::CommandLine::StringVector flags; |
- // argv[0] is the program name |base::CommandLine::NO_PROGRAM|. |
- flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end()); |
- VLOG(1) << "Restarting to apply per-session flags..."; |
- chromeos::DBusThreadManager::Get() |
- ->GetSessionManagerClient() |
- ->SetFlagsForUser( |
- user_manager::UserManager::Get()->GetActiveUser()->email(), flags); |
-#endif |
- chrome::AttemptRestart(); |
+ NOTREACHED(); |
} |
void FlagsDOMHandler::HandleResetAllFlags(const base::ListValue* args) { |
DCHECK(flags_storage_); |
- about_flags::ResetAllFlags(flags_storage_.get()); |
+ ResetAllFlags(flags_storage_.get()); |
} |
- |
-#if defined(OS_CHROMEOS) |
-// On ChromeOS verifying if the owner is signed in is async operation and only |
-// after finishing it the UI can be properly populated. This function is the |
-// callback for whether the owner is signed in. It will respectively pick the |
-// proper PrefService for the flags interface. |
-void FinishInitialization(base::WeakPtr<FlagsUI> flags_ui, |
- Profile* profile, |
- FlagsDOMHandler* dom_handler, |
- bool current_user_is_owner) { |
- // If the flags_ui has gone away, there's nothing to do. |
- if (!flags_ui) |
- return; |
- |
- // On Chrome OS the owner can set system wide flags and other users can only |
- // set flags for their own session. |
- // Note that |dom_handler| is owned by the web ui that owns |flags_ui|, so |
- // it is still alive if |flags_ui| is. |
- if (current_user_is_owner) { |
- chromeos::OwnerSettingsServiceChromeOS* service = |
- chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( |
- profile); |
- dom_handler->Init(new chromeos::about_flags::OwnerFlagsStorage( |
- profile->GetPrefs(), service), |
- flags_ui::kOwnerAccessToFlags); |
- } else { |
- dom_handler->Init( |
- new flags_ui::PrefServiceFlagsStorage(profile->GetPrefs()), |
- flags_ui::kGeneralAccessFlagsOnly); |
- } |
-} |
-#endif |
- |
} // namespace |
/////////////////////////////////////////////////////////////////////////////// |
// |
-// FlagsUI |
+// BaseFlagsUI |
// |
/////////////////////////////////////////////////////////////////////////////// |
-FlagsUI::FlagsUI(content::WebUI* web_ui) |
- : WebUIController(web_ui), |
- weak_factory_(this) { |
- Profile* profile = Profile::FromWebUI(web_ui); |
+BaseFlagsUI::BaseFlagsUI(web::WebUIIOS* web_ui, FlagsUIKind flags_ui_kind) |
+ : web::WebUIIOSController(web_ui), weak_factory_(this) { |
+ Initialize(web_ui, flags_ui_kind); |
+} |
+void BaseFlagsUI::Initialize(web::WebUIIOS* web_ui, FlagsUIKind flags_ui_kind) { |
FlagsDOMHandler* handler = new FlagsDOMHandler(); |
web_ui->AddMessageHandler(handler); |
-#if defined(OS_CHROMEOS) |
- if (base::SysInfo::IsRunningOnChromeOS() && |
- chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( |
- profile)) { |
- chromeos::OwnerSettingsServiceChromeOS* service = |
- chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( |
- profile); |
- service->IsOwnerAsync(base::Bind( |
- &FinishInitialization, weak_factory_.GetWeakPtr(), profile, handler)); |
- } else { |
- FinishInitialization(weak_factory_.GetWeakPtr(), profile, handler, |
- false /* current_user_is_owner */); |
- } |
-#else |
- handler->Init( |
- new flags_ui::PrefServiceFlagsStorage(g_browser_process->local_state()), |
- flags_ui::kOwnerAccessToFlags); |
-#endif |
+ flags_ui::FlagAccess flag_access = flags_ui::kOwnerAccessToFlags; |
+ if (flags_ui_kind == FLAGS_UI_APPLE) |
+ flag_access = flags_ui::kAppleReviewAccessToFlags; |
+ handler->Init(new flags_ui::PrefServiceFlagsStorage( |
+ GetApplicationContext()->GetLocalState()), |
+ flag_access); |
// Set up the about:flags source. |
- content::WebUIDataSource::Add(profile, CreateFlagsUIHTMLSource()); |
+ web::WebUIIOSDataSource::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui), |
+ CreateFlagsUIHTMLSource(flags_ui_kind)); |
} |
-FlagsUI::~FlagsUI() { |
-} |
+BaseFlagsUI::~BaseFlagsUI() {} |
// static |
-base::RefCountedMemory* FlagsUI::GetFaviconResourceBytes( |
- ui::ScaleFactor scale_factor) { |
- return ResourceBundle::GetSharedInstance(). |
- LoadDataResourceBytesForScale(IDR_FLAGS_FAVICON, scale_factor); |
+base::RefCountedMemory* BaseFlagsUI::GetFaviconResourceBytes( |
+ ui::ScaleFactor scale_factor) { |
+ return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( |
+ IDR_FLAGS_FAVICON, scale_factor); |
} |
+ |
+/////////////////////////////////////////////////////////////////////////////// |
+// |
+// FlagsUI |
+// |
+/////////////////////////////////////////////////////////////////////////////// |
+ |
+FlagsUI::FlagsUI(web::WebUIIOS* web_ui) |
+ : BaseFlagsUI(web_ui, BaseFlagsUI::FLAGS_UI_GENERIC) {} |
+ |
+FlagsUI::~FlagsUI() {} |
+ |
+/////////////////////////////////////////////////////////////////////////////// |
+// |
+// AppleFlagsUI |
+// |
+/////////////////////////////////////////////////////////////////////////////// |
+ |
+AppleFlagsUI::AppleFlagsUI(web::WebUIIOS* web_ui) |
+ : BaseFlagsUI(web_ui, BaseFlagsUI::FLAGS_UI_APPLE) {} |
+ |
+AppleFlagsUI::~AppleFlagsUI() {} |