From 55eb56af0d17a4ae54258ae664e70b22892d9df9 Mon Sep 17 00:00:00 2001 From: Simon Hong Date: Mon, 18 Feb 2019 13:52:50 +0900 Subject: [PATCH] Fix crash during the sync page loading in tor(guest) window Sync page should be disabled for now because BraveSyncService isn't instantiated for OTR profile. Instead, sync is disabled page is loaded. --- browser/ui/webui/sync/sync_ui.cc | 19 +++++++++++++++---- .../render_view_context_menu.cc | 4 +++- components/brave_sync/brave_sync_service.cc | 5 +---- components/brave_sync/resources.grd | 1 + .../brave_sync/ui/brave_sync_disabled.html | 11 +++++++++++ 5 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 components/brave_sync/ui/brave_sync_disabled.html diff --git a/browser/ui/webui/sync/sync_ui.cc b/browser/ui/webui/sync/sync_ui.cc index 428ffb79dc81..16b98c6a67c2 100644 --- a/browser/ui/webui/sync/sync_ui.cc +++ b/browser/ui/webui/sync/sync_ui.cc @@ -60,7 +60,7 @@ class SyncUIDOMHandler : public WebUIMessageHandler, std::unique_ptr settings, std::unique_ptr devices); - brave_sync::BraveSyncService *sync_service_; // NOT OWNED + brave_sync::BraveSyncService *sync_service_ = nullptr; // NOT OWNED base::WeakPtrFactory weak_ptr_factory_; @@ -119,11 +119,12 @@ void SyncUIDOMHandler::RegisterMessages() { void SyncUIDOMHandler::Init() { Profile* profile = Profile::FromWebUI(web_ui()); sync_service_ = brave_sync::BraveSyncServiceFactory::GetForProfile(profile); - DCHECK(sync_service_); - sync_service_->AddObserver(this); + if (sync_service_) + sync_service_->AddObserver(this); } void SyncUIDOMHandler::SetupSyncHaveCode(const base::ListValue* args) { + DCHECK(sync_service_); std::string sync_words, device_name; if (!args->GetString(0, &sync_words) || !args->GetString(1, &device_name)) // TODO(bridiver) - does this need to report an error? @@ -133,6 +134,7 @@ void SyncUIDOMHandler::SetupSyncHaveCode(const base::ListValue* args) { } void SyncUIDOMHandler::SetupSyncNewToSync(const base::ListValue* args) { + DCHECK(sync_service_); std::string sync_words, device_name; if (!args->GetString(0, &device_name)) // TODO(bridiver) - does this need to report an error? @@ -142,20 +144,24 @@ void SyncUIDOMHandler::SetupSyncNewToSync(const base::ListValue* args) { } void SyncUIDOMHandler::PageLoaded(const base::ListValue* args) { + DCHECK(sync_service_); LoadSyncSettingsView(); } void SyncUIDOMHandler::NeedSyncWords(const base::ListValue* args) { + DCHECK(sync_service_); sync_service_->GetSyncWords(); } void SyncUIDOMHandler::NeedSyncQRcode(const base::ListValue* args) { + DCHECK(sync_service_); std::string seed = sync_service_->GetSeed(); web_ui()->CallJavascriptFunctionUnsafe( "sync_ui_exports.haveSeedForQrCode", base::Value(seed)); } void SyncUIDOMHandler::SyncBookmarks(const base::ListValue* args) { + DCHECK(sync_service_); bool new_value; if (!args->GetBoolean(0, &new_value)) // TODO(bridiver) - does this need to report an error? @@ -165,6 +171,7 @@ void SyncUIDOMHandler::SyncBookmarks(const base::ListValue* args) { } void SyncUIDOMHandler::SyncBrowsingHistory(const base::ListValue* args) { + DCHECK(sync_service_); bool new_value; if (!args->GetBoolean(0, &new_value)) // TODO(bridiver) - does this need to report an error? @@ -174,6 +181,7 @@ void SyncUIDOMHandler::SyncBrowsingHistory(const base::ListValue* args) { } void SyncUIDOMHandler::SyncSavedSiteSettings(const base::ListValue* args) { + DCHECK(sync_service_); bool new_value; if (!args->GetBoolean(0, &new_value)) // TODO(bridiver) - does this need to report an error? @@ -183,6 +191,7 @@ void SyncUIDOMHandler::SyncSavedSiteSettings(const base::ListValue* args) { } void SyncUIDOMHandler::DeleteDevice(const base::ListValue* args) { + DCHECK(sync_service_); int i_device_id = -1; if (!args->GetInteger(0, &i_device_id) || i_device_id == -1) { DCHECK(false) << "[Brave Sync] could not get device id"; @@ -193,6 +202,7 @@ void SyncUIDOMHandler::DeleteDevice(const base::ListValue* args) { } void SyncUIDOMHandler::ResetSync(const base::ListValue* args) { + DCHECK(sync_service_); sync_service_->OnResetSync(); } @@ -240,7 +250,8 @@ SyncUI::SyncUI(content::WebUI* web_ui, const std::string& name) : BasicUI(web_ui, name, kBraveSyncGenerated, kBraveSyncGeneratedSize, - IDR_BRAVE_SYNC_HTML) { + Profile::FromWebUI(web_ui)->IsOffTheRecord() ? + IDR_BRAVE_SYNC_DISABLED_HTML : IDR_BRAVE_SYNC_HTML) { auto handler_owner = std::make_unique(); SyncUIDOMHandler* handler = handler_owner.get(); web_ui->AddMessageHandler(std::move(handler_owner)); diff --git a/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc index e6a5c6435cbc..1d47d6c0421d 100644 --- a/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc +++ b/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc @@ -56,7 +56,9 @@ void BraveRenderViewContextMenu::AppendBraveLinkItems() { bool BraveRenderViewContextMenu::IsCommandIdEnabled(int id) const { switch (id) { case IDC_CONTENT_CONTEXT_OPENLINKTOR: - return params_.link_url.is_valid() && !browser_context_->IsTorProfile(); + return params_.link_url.is_valid() && + IsURLAllowedInIncognito(params_.link_url, browser_context_) && + !browser_context_->IsTorProfile(); default: return RenderViewContextMenu_Chromium::IsCommandIdEnabled(id); } diff --git a/components/brave_sync/brave_sync_service.cc b/components/brave_sync/brave_sync_service.cc index 4612a7491c30..20d180438766 100644 --- a/components/brave_sync/brave_sync_service.cc +++ b/components/brave_sync/brave_sync_service.cc @@ -24,10 +24,7 @@ void BraveSyncService::RemoveObserver(BraveSyncServiceObserver* observer) { bool BraveSyncService::is_enabled() { const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); - if (command_line.HasSwitch(switches::kDisableBraveSync)) - return false; - else - return true; + return !command_line.HasSwitch(switches::kDisableBraveSync); } } // namespace brave_sync diff --git a/components/brave_sync/resources.grd b/components/brave_sync/resources.grd index 16c0a366ef92..f01b9f123505 100644 --- a/components/brave_sync/resources.grd +++ b/components/brave_sync/resources.grd @@ -18,6 +18,7 @@ + diff --git a/components/brave_sync/ui/brave_sync_disabled.html b/components/brave_sync/ui/brave_sync_disabled.html new file mode 100644 index 000000000000..cdd159e1a7bf --- /dev/null +++ b/components/brave_sync/ui/brave_sync_disabled.html @@ -0,0 +1,11 @@ + + + + + + Sync(Disabled) + + + Sync in tor(guest) window is disabled. + +