Commit 76154fc5 authored by John Z Wu's avatar John Z Wu Committed by Commit Bot

Refactor sync internals web ui code to be shareable with ios/web_view

Define a provider that needs to be implemented by embedders to provide
embedder specific values.

Change-Id: I33f929b7a26b997a293dd9e080126214c58fdefe
Bug: 1062743
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2119765Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: John Wu <jzw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754556}
parent c45efd66
...@@ -90,6 +90,7 @@ source_set("webui_internal") { ...@@ -90,6 +90,7 @@ source_set("webui_internal") {
sources = [ sources = [
"chrome_web_ui_ios_controller_factory.h", "chrome_web_ui_ios_controller_factory.h",
"chrome_web_ui_ios_controller_factory.mm", "chrome_web_ui_ios_controller_factory.mm",
"chrome_web_ui_provider.cc",
"omaha_ui.cc", "omaha_ui.cc",
"omaha_ui.h", "omaha_ui.h",
"signin_internals_ui_ios.cc", "signin_internals_ui_ios.cc",
...@@ -105,11 +106,14 @@ source_set("webui_internal") { ...@@ -105,11 +106,14 @@ source_set("webui_internal") {
"//ios/chrome/browser/omaha", "//ios/chrome/browser/omaha",
"//ios/chrome/browser/policy:feature_flags", "//ios/chrome/browser/policy:feature_flags",
"//ios/chrome/browser/signin", "//ios/chrome/browser/signin",
"//ios/chrome/browser/sync",
"//ios/chrome/browser/ui/webui/gcm", "//ios/chrome/browser/ui/webui/gcm",
"//ios/chrome/browser/ui/webui/net_export", "//ios/chrome/browser/ui/webui/net_export",
"//ios/chrome/browser/ui/webui/policy", "//ios/chrome/browser/ui/webui/policy",
"//ios/chrome/browser/ui/webui/sync_internals",
"//ios/chrome/browser/ui/webui/translate_internals", "//ios/chrome/browser/ui/webui/translate_internals",
"//ios/chrome/common",
"//ios/components/webui:provider",
"//ios/components/webui/sync_internals",
"//url", "//url",
] ]
......
include_rules = [ include_rules = [
"+mojo/public", "+mojo/public",
"+ios/components/webui",
] ]
...@@ -25,12 +25,12 @@ ...@@ -25,12 +25,12 @@
#include "ios/chrome/browser/ui/webui/prefs_internals_ui.h" #include "ios/chrome/browser/ui/webui/prefs_internals_ui.h"
#include "ios/chrome/browser/ui/webui/signin_internals_ui_ios.h" #include "ios/chrome/browser/ui/webui/signin_internals_ui_ios.h"
#include "ios/chrome/browser/ui/webui/suggestions_ui.h" #include "ios/chrome/browser/ui/webui/suggestions_ui.h"
#include "ios/chrome/browser/ui/webui/sync_internals/sync_internals_ui.h"
#include "ios/chrome/browser/ui/webui/terms_ui.h" #include "ios/chrome/browser/ui/webui/terms_ui.h"
#include "ios/chrome/browser/ui/webui/translate_internals/translate_internals_ui.h" #include "ios/chrome/browser/ui/webui/translate_internals/translate_internals_ui.h"
#include "ios/chrome/browser/ui/webui/ukm_internals_ui.h" #include "ios/chrome/browser/ui/webui/ukm_internals_ui.h"
#include "ios/chrome/browser/ui/webui/user_actions_ui.h" #include "ios/chrome/browser/ui/webui/user_actions_ui.h"
#include "ios/chrome/browser/ui/webui/version_ui.h" #include "ios/chrome/browser/ui/webui/version_ui.h"
#include "ios/components/webui/sync_internals/sync_internals_ui.h"
#include "url/gurl.h" #include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -105,7 +105,7 @@ WebUIIOSFactoryFunction GetWebUIIOSFactoryFunction(const GURL& url) { ...@@ -105,7 +105,7 @@ WebUIIOSFactoryFunction GetWebUIIOSFactoryFunction(const GURL& url) {
if (url_host == kChromeUIUserActionsHost) if (url_host == kChromeUIUserActionsHost)
return &NewWebUIIOS<UserActionsUI>; return &NewWebUIIOS<UserActionsUI>;
if (url_host == kChromeUISyncInternalsHost) if (url_host == kChromeUISyncInternalsHost)
return &NewWebUIIOS<SyncInternalsUI>; return &NewWebUIIOSWithHost<SyncInternalsUI>;
if (url_host == kChromeUITermsHost) if (url_host == kChromeUITermsHost)
return &NewWebUIIOSWithHost<TermsUI>; return &NewWebUIIOSWithHost<TermsUI>;
if (url_host == kChromeUIVersionHost) if (url_host == kChromeUIVersionHost)
......
// Copyright 2020 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 "ios/components/webui/web_ui_provider.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/sync/profile_sync_service_factory.h"
#include "ios/chrome/common/channel_info.h"
namespace web_ui {
syncer::SyncService* GetSyncServiceForWebUI(web::WebUIIOS* web_ui) {
ChromeBrowserState* browser_state = ChromeBrowserState::FromWebUIIOS(web_ui);
return ProfileSyncServiceFactory::GetForBrowserState(
browser_state->GetOriginalChromeBrowserState());
}
version_info::Channel GetChannel() {
return ::GetChannel();
}
} // namespace web_ui
# Copyright 2020 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.
source_set("provider") {
sources = [ "web_ui_provider.h" ]
}
# Copyright 2016 The Chromium Authors. All rights reserved. # Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
source_set("sync_internals") { source_set("sync_internals") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
"sync_internals_message_handler.cc",
"sync_internals_message_handler.h", "sync_internals_message_handler.h",
"sync_internals_ui.cc", "sync_internals_message_handler.mm",
"sync_internals_ui.h", "sync_internals_ui.h",
"sync_internals_ui.mm",
] ]
deps = [ deps = [
"//base", "//base",
...@@ -15,11 +16,10 @@ source_set("sync_internals") { ...@@ -15,11 +16,10 @@ source_set("sync_internals") {
"//components/resources", "//components/resources",
"//components/sync", "//components/sync",
"//components/sync/driver:resources", "//components/sync/driver:resources",
"//ios/chrome/browser", "//components/version_info:version_info",
"//ios/chrome/browser/browser_state", "//ios/components/webui:provider",
"//ios/chrome/browser/signin", "//ios/web/public",
"//ios/chrome/browser/sync", "//ios/web/public/thread",
"//ios/chrome/common",
"//ios/web/public/webui", "//ios/web/public/webui",
] ]
} }
include_rules = [
"+components/grit",
"+components/sync",
]
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_SYNC_INTERNALS_MESSAGE_HANDLER_H_ #ifndef IOS_COMPONENTS_WEBUI_SYNC_INTERNALS_SYNC_INTERNALS_MESSAGE_HANDLER_H_
#define IOS_CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_SYNC_INTERNALS_MESSAGE_HANDLER_H_ #define IOS_COMPONENTS_WEBUI_SYNC_INTERNALS_SYNC_INTERNALS_MESSAGE_HANDLER_H_
#include <memory> #include <memory>
#include <string> #include <string>
...@@ -126,4 +126,4 @@ class SyncInternalsMessageHandler : public web::WebUIIOSMessageHandler, ...@@ -126,4 +126,4 @@ class SyncInternalsMessageHandler : public web::WebUIIOSMessageHandler,
DISALLOW_COPY_AND_ASSIGN(SyncInternalsMessageHandler); DISALLOW_COPY_AND_ASSIGN(SyncInternalsMessageHandler);
}; };
#endif // IOS_CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_SYNC_INTERNALS_MESSAGE_HANDLER_H_ #endif // IOS_COMPONENTS_WEBUI_SYNC_INTERNALS_SYNC_INTERNALS_MESSAGE_HANDLER_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ios/chrome/browser/ui/webui/sync_internals/sync_internals_message_handler.h" #include "ios/components/webui/sync_internals/sync_internals_message_handler.h"
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -21,12 +21,14 @@ ...@@ -21,12 +21,14 @@
#include "components/sync/engine/cycle/update_counters.h" #include "components/sync/engine/cycle/update_counters.h"
#include "components/sync/engine/events/protocol_event.h" #include "components/sync/engine/events/protocol_event.h"
#include "components/sync/js/js_event_details.h" #include "components/sync/js/js_event_details.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/components/webui/web_ui_provider.h"
#include "ios/chrome/browser/sync/profile_sync_service_factory.h"
#include "ios/chrome/common/channel_info.h"
#include "ios/web/public/thread/web_thread.h" #include "ios/web/public/thread/web_thread.h"
#include "ios/web/public/webui/web_ui_ios.h" #include "ios/web/public/webui/web_ui_ios.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace { namespace {
// Returns the initial state of the "include specifics" flag, based on whether // Returns the initial state of the "include specifics" flag, based on whether
...@@ -326,16 +328,13 @@ void SyncInternalsMessageHandler::SendAboutInfo() { ...@@ -326,16 +328,13 @@ void SyncInternalsMessageHandler::SendAboutInfo() {
syncer::SyncService* sync_service = GetSyncService(); syncer::SyncService* sync_service = GetSyncService();
std::unique_ptr<base::DictionaryValue> value = std::unique_ptr<base::DictionaryValue> value =
syncer::sync_ui_util::ConstructAboutInformation(sync_service, syncer::sync_ui_util::ConstructAboutInformation(sync_service,
GetChannel()); web_ui::GetChannel());
DispatchEvent(syncer::sync_ui_util::kOnAboutInfoUpdated, *value); DispatchEvent(syncer::sync_ui_util::kOnAboutInfoUpdated, *value);
} }
// Gets the SyncService of the underlying original profile. May return null. // Gets the SyncService of the underlying original profile. May return null.
syncer::SyncService* SyncInternalsMessageHandler::GetSyncService() { syncer::SyncService* SyncInternalsMessageHandler::GetSyncService() {
ChromeBrowserState* browser_state = return web_ui::GetSyncServiceForWebUI(web_ui());
ChromeBrowserState::FromWebUIIOS(web_ui());
return ProfileSyncServiceFactory::GetForBrowserState(
browser_state->GetOriginalChromeBrowserState());
} }
void SyncInternalsMessageHandler::DispatchEvent( void SyncInternalsMessageHandler::DispatchEvent(
......
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_SYNC_INTERNALS_UI_H_ #ifndef IOS_COMPONENTS_WEBUI_SYNC_INTERNALS_SYNC_INTERNALS_UI_H_
#define IOS_CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_SYNC_INTERNALS_UI_H_ #define IOS_COMPONENTS_WEBUI_SYNC_INTERNALS_SYNC_INTERNALS_UI_H_
#include <string>
#include "base/macros.h" #include "base/macros.h"
#include "ios/web/public/webui/web_ui_ios_controller.h" #include "ios/web/public/webui/web_ui_ios_controller.h"
...@@ -15,11 +17,11 @@ class WebUIIOS; ...@@ -15,11 +17,11 @@ class WebUIIOS;
// The implementation for the chrome://sync-internals page. // The implementation for the chrome://sync-internals page.
class SyncInternalsUI : public web::WebUIIOSController { class SyncInternalsUI : public web::WebUIIOSController {
public: public:
explicit SyncInternalsUI(web::WebUIIOS* web_ui); explicit SyncInternalsUI(web::WebUIIOS* web_ui, const std::string& host);
~SyncInternalsUI() override; ~SyncInternalsUI() override;
private: private:
DISALLOW_COPY_AND_ASSIGN(SyncInternalsUI); DISALLOW_COPY_AND_ASSIGN(SyncInternalsUI);
}; };
#endif // IOS_CHROME_BROWSER_UI_WEBUI_SYNC_INTERNALS_SYNC_INTERNALS_UI_H_ #endif // IOS_COMPONENTS_WEBUI_SYNC_INTERNALS_SYNC_INTERNALS_UI_H_
...@@ -2,23 +2,27 @@ ...@@ -2,23 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ios/chrome/browser/ui/webui/sync_internals/sync_internals_ui.h" #include "ios/components/webui/sync_internals/sync_internals_ui.h"
#include <memory> #include <memory>
#include "components/grit/sync_driver_resources.h" #include "components/grit/sync_driver_resources.h"
#include "components/sync/driver/about_sync_util.h" #include "components/sync/driver/about_sync_util.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/components/webui/sync_internals/sync_internals_message_handler.h"
#include "ios/chrome/browser/chrome_url_constants.h" #include "ios/web/public/browser_state.h"
#include "ios/chrome/browser/ui/webui/sync_internals/sync_internals_message_handler.h" #include "ios/web/public/web_state.h"
#include "ios/web/public/webui/web_ui_ios.h" #include "ios/web/public/webui/web_ui_ios.h"
#include "ios/web/public/webui/web_ui_ios_data_source.h" #include "ios/web/public/webui/web_ui_ios_data_source.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace { namespace {
web::WebUIIOSDataSource* CreateSyncInternalsHTMLSource() { web::WebUIIOSDataSource* CreateSyncInternalsHTMLSource(
web::WebUIIOSDataSource* source = const std::string& host) {
web::WebUIIOSDataSource::Create(kChromeUISyncInternalsHost); web::WebUIIOSDataSource* source = web::WebUIIOSDataSource::Create(host);
source->UseStringsJs(); source->UseStringsJs();
source->AddResourcePath(syncer::sync_ui_util::kSyncIndexJS, source->AddResourcePath(syncer::sync_ui_util::kSyncIndexJS,
...@@ -51,10 +55,10 @@ web::WebUIIOSDataSource* CreateSyncInternalsHTMLSource() { ...@@ -51,10 +55,10 @@ web::WebUIIOSDataSource* CreateSyncInternalsHTMLSource() {
} // namespace } // namespace
SyncInternalsUI::SyncInternalsUI(web::WebUIIOS* web_ui) SyncInternalsUI::SyncInternalsUI(web::WebUIIOS* web_ui, const std::string& host)
: web::WebUIIOSController(web_ui) { : web::WebUIIOSController(web_ui) {
web::WebUIIOSDataSource::Add(ChromeBrowserState::FromWebUIIOS(web_ui), web::WebUIIOSDataSource::Add(web_ui->GetWebState()->GetBrowserState(),
CreateSyncInternalsHTMLSource()); CreateSyncInternalsHTMLSource(host));
web_ui->AddMessageHandler(std::make_unique<SyncInternalsMessageHandler>()); web_ui->AddMessageHandler(std::make_unique<SyncInternalsMessageHandler>());
} }
......
// Copyright 2020 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.
#ifndef IOS_COMPONENTS_WEBUI_WEB_UI_PROVIDER_H_
#define IOS_COMPONENTS_WEBUI_WEB_UI_PROVIDER_H_
namespace syncer {
class SyncService;
} // namespace syncer
namespace version_info {
enum class Channel;
} // namespace version_info
namespace web {
class WebUIIOS;
} // namespace web
// Declares functions that must be implemented by the embedder, such as
// ios/chrome and ios/web_view.
namespace web_ui {
// Gets the SyncService of the underlying original profile. May return null.
syncer::SyncService* GetSyncServiceForWebUI(web::WebUIIOS* web_ui);
// Returns the app channel .
version_info::Channel GetChannel();
} // namespace web_ui
#endif // IOS_COMPONENTS_WEBUI_WEB_UI_PROVIDER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment