Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter internal URLs when importing Muon tabs #1021

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions utility/importer/brave_importer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,19 @@ void BraveImporter::ImportReferral() {
bridge_->UpdateReferral(referral);
}

bool CanImportURL(const GURL& url) {
if (!url.is_valid())
return false;

const char* const kInvalidSchemes[] = {"about", "chrome-extension"};
darkdh marked this conversation as resolved.
Show resolved Hide resolved
for (size_t i = 0; i < arraysize(kInvalidSchemes); i++) {
if (url.SchemeIs(kInvalidSchemes[i]))
return false;
}

return true;
}

std::vector<ImportedBrowserTab> ParseTabs(const base::Value* frames) {
std::vector<ImportedBrowserTab> tabs;

Expand All @@ -684,11 +697,14 @@ std::vector<ImportedBrowserTab> ParseTabs(const base::Value* frames) {
if (!(key && location))
continue;

auto url = GURL(location->GetString());
// Filter internal URLs from Muon that won't resolve correctly in brave-core
if (!CanImportURL(url))
continue;

ImportedBrowserTab tab;
tab.key = key->GetInt();
// TODO filter locations that won't work in b-c, e.g. about:preferences, about:newtab, chrome-extension:// (for PDFs), etc.
tab.location = GURL(location->GetString());

tab.location = url;
tabs.push_back(tab);
}

Expand Down Expand Up @@ -739,15 +755,18 @@ std::vector<ImportedBrowserWindow> ParseWindows(
continue;
}

auto tabs = ParseTabs(frames);
if (tabs.size() == 0)
continue;

window.top = top->GetInt();
window.left = left->GetInt();
window.width = width->GetInt();
window.height = height->GetInt();
window.focused = focused->GetBool();
window.state = state->GetString();
window.activeFrameKey = activeFrameKey->GetInt();

window.tabs = ParseTabs(frames);
window.tabs = tabs;

windows.push_back(window);
}
Expand All @@ -774,9 +793,14 @@ std::vector<ImportedBrowserTab> ParsePinnedTabs(
if (!(location && order))
continue;

auto url = GURL(location->GetString());
// Filter internal URLs from Muon that won't resolve correctly in brave-core
if (!CanImportURL(url))
continue;

ImportedBrowserTab tab;
tab.key = order->GetInt();
tab.location = GURL(location->GetString());
tab.location = url;
pinnedTabs.push_back(tab);
}

Expand Down