Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit df3bd52

Browse files
authored
We add a special case for Selenium IDE extension. Selenium IDE extension needs to access its own windows and it requires specific hacks because the extension behaviour in Chromium relies on side-effects instead of conventions.
1 parent c400ca6 commit df3bd52

File tree

1 file changed

+30
-55
lines changed

1 file changed

+30
-55
lines changed

chrome/browser/extensions/api/tabs/tabs_api.cc

+30-55
Original file line numberDiff line numberDiff line change
@@ -733,46 +733,28 @@ ExtensionFunction::ResponseAction TabsGetSelectedFunction::Run() {
733733
EXTENSION_FUNCTION_VALIDATE(params.get());
734734

735735

736-
// LOG(INFO) << "[EXTENSIONS] TabsGetSelectedFunction::Run - Step 1";
737736

738737
std::unique_ptr<base::ListValue> result(new base::ListValue());
739-
// LOG(INFO) << "[EXTENSIONS] TabsGetSelectedFunction::Run - Step 4";
740-
// Profile* profile = Profile::FromBrowserContext(browser_context());
741-
// Browser* last_active_browser =
742-
// chrome::FindAnyBrowser(profile, include_incognito());
743-
// Browser* current_browser =
744-
// ChromeExtensionFunctionDetails(this).GetCurrentBrowser();
745-
// LOG(INFO) << "[EXTENSIONS] TabsGetSelectedFunction::Run - Step 5: " << profile;
746-
// LOG(INFO) << "[EXTENSIONS] TabsGetSelectedFunction::Run - Step 5-1: " << last_active_browser;
747-
// LOG(INFO) << "[EXTENSIONS] TabsGetSelectedFunction::Run - Step 5-2: " << current_browser;
748-
// LOG(INFO) << "[EXTENSIONS] TabsGetSelectedFunction::Run - IsOffTheRecordSessionActive: " << TabModelList::IsOffTheRecordSessionActive();
749738
TabModel *tab_strip = nullptr;
750739
if (!TabModelList::empty())
751740
tab_strip = *(TabModelList::begin());
752-
// LOG(INFO) << "[EXTENSIONS] TabsGetSelectedFunction::Run - TabModel: " << tab_strip;
753741
if (tab_strip) {
754-
// LOG(INFO) << "[EXTENSIONS] TabsGetSelectedFunction::Run - TabModel - Open tabs: " << tab_strip->GetTabCount();
755-
// LOG(INFO) << "[EXTENSIONS] TabsGetSelectedFunction::Run - TabModel - Active index: " << tab_strip->GetActiveIndex();
756-
// LOG(INFO) << "[EXTENSIONS] TabsGetSelectedFunction::Run - TabModel - Last user-interacted active index: " << tab_strip->GetLastNonExtensionActiveIndex();
757742
for (int i = 0; i < tab_strip->GetTabCount(); ++i) {
758743
WebContents* web_contents = tab_strip->GetWebContentsAt(i);
759-
// LOG(INFO) << "[EXTENSIONS] TabsGetSelectedFunction::Run - Step 5d-1 (tab loop)";
760744

761745
int openingTab = (tab_strip->GetLastNonExtensionActiveIndex());
746+
if (extension() && extension()->id() == "mooikfkahbdckldjjndioackbalphokd")
747+
openingTab = (tab_strip->GetActiveIndex());
762748
if (openingTab == -1)
763749
openingTab = 0;
764750

765751
if (i != openingTab)
766752
continue;
767753

768754
if (!web_contents) {
769-
// LOG(INFO) << "[EXTENSIONS] TabsGetSelectedFunction::Run - Step 5d-1b (there is no webcontents)";
770755
continue;
771756
}
772757

773-
// LOG(INFO) << "[EXTENSIONS] TabsGetSelectedFunction::Run - Step 5d-2";
774-
775-
// LOG(INFO) << "[EXTENSIONS] TabsGetSelectedFunction::Run - Step 5d-5";
776758

777759
return RespondNow(ArgumentList(
778760
tabs::Get::Results::Create(*ExtensionTabUtil::CreateTabObject(
@@ -837,13 +819,10 @@ ExtensionFunction::ResponseAction TabsQueryFunction::Run() {
837819
tabs::Query::Params::Create(*args_));
838820
EXTENSION_FUNCTION_VALIDATE(params.get());
839821

840-
// LOG(INFO) << "[EXTENSIONS] TabsQueryFunction::Run - Step 1";
841-
842822
bool loading_status_set = params->query_info.status != tabs::TAB_STATUS_NONE;
843823
bool loading = params->query_info.status == tabs::TAB_STATUS_LOADING;
844824

845825
URLPatternSet url_patterns;
846-
// LOG(INFO) << "[EXTENSIONS] TabsQueryFunction::Run - Step 2";
847826
if (params->query_info.url.get()) {
848827
std::vector<std::string> url_pattern_strings;
849828
if (params->query_info.url->as_string)
@@ -879,40 +858,44 @@ ExtensionFunction::ResponseAction TabsQueryFunction::Run() {
879858
window_type = tabs::ToString(params->query_info.window_type);
880859

881860
std::unique_ptr<base::ListValue> result(new base::ListValue());
882-
// LOG(INFO) << "[EXTENSIONS] TabsQueryFunction::Run - Step 4";
883-
// Profile* profile = Profile::FromBrowserContext(browser_context());
884-
// Browser* last_active_browser =
885-
// chrome::FindAnyBrowser(profile, include_incognito());
886-
// Browser* current_browser =
887-
// ChromeExtensionFunctionDetails(this).GetCurrentBrowser();
888-
// LOG(INFO) << "[EXTENSIONS] TabsQueryFunction::Run - Step 5: " << profile;
889-
// LOG(INFO) << "[EXTENSIONS] TabsQueryFunction::Run - Step 5-1: " << last_active_browser;
890-
// LOG(INFO) << "[EXTENSIONS] TabsQueryFunction::Run - Step 5-2: " << current_browser;
891-
// LOG(INFO) << "[EXTENSIONS] TabsQueryFunction::Run - IsOffTheRecordSessionActive: " << TabModelList::IsOffTheRecordSessionActive();
892861
TabModel *tab_strip = nullptr;
893862
if (!TabModelList::empty())
894863
tab_strip = *(TabModelList::begin());
895-
// LOG(INFO) << "[EXTENSIONS] TabsQueryFunction::Run - TabModel: " << tab_strip;
896864
if (tab_strip) {
897-
// LOG(INFO) << "[EXTENSIONS] TabsQueryFunction::Run - TabModel - Open tabs: " << tab_strip->GetTabCount();
898-
// LOG(INFO) << "[EXTENSIONS] TabsQueryFunction::Run - TabModel - Active index: " << tab_strip->GetActiveIndex();
899-
// LOG(INFO) << "[EXTENSIONS] TabsQueryFunction::Run - TabModel - Last user-interacted active index: " << tab_strip->GetLastNonExtensionActiveIndex();
900865
for (int i = 0; i < tab_strip->GetTabCount(); ++i) {
901866
WebContents* web_contents = tab_strip->GetWebContentsAt(i);
902-
// LOG(INFO) << "[EXTENSIONS] TabsQueryFunction::Run - Step 5d-1 (tab loop)";
903867

904868
if (index > -1 && i != index) {
905-
// LOG(INFO) << "[EXTENSIONS] TabsQueryFunction::Run - Step 5d-1a (oob-index): " << i << " vs " << index;
906869
continue;
907870
}
908871

909872
int openingTab = (tab_strip->GetLastNonExtensionActiveIndex());
910-
if (openingTab == -1)
873+
// To Selenium IDE we show the current active window even if it's an extension window
874+
// when they try to access a specific window because it means
875+
// that it Selenium is looking for its own IDE
876+
if (extension() && extension()->id() == "mooikfkahbdckldjjndioackbalphokd")
877+
openingTab = (tab_strip->GetActiveIndex());
878+
if (openingTab == -1)
911879
openingTab = 0;
912880

913-
if (!MatchesBool(params->query_info.active.get(),
914-
i == openingTab)) {
915-
continue;
881+
// For Selenium IDE we do not check the active flag
882+
if (extension() && extension()->id() != "mooikfkahbdckldjjndioackbalphokd") {
883+
if (!MatchesBool(params->query_info.active.get(),
884+
i == openingTab)) {
885+
continue;
886+
}
887+
}
888+
// except if there is status == complete
889+
if (extension() && extension()->id() == "mooikfkahbdckldjjndioackbalphokd" && params->query_info.status == tabs::TAB_STATUS_COMPLETE) {
890+
if (!MatchesBool(params->query_info.active.get(),
891+
i == openingTab)) {
892+
continue;
893+
}
894+
}
895+
896+
if (extension() && extension()->id() == "mooikfkahbdckldjjndioackbalphokd") {
897+
if (window_id >= 0 && window_id != SessionTabHelper::IdForTab(web_contents).id())
898+
continue;
916899
}
917900

918901
if (!web_contents) {
@@ -1154,6 +1137,8 @@ bool TabsUpdateFunction::RunAsync() {
11541137
if (tab_strip) {
11551138
for (int i = 0; i < tab_strip->GetTabCount(); ++i) {
11561139
int openingTab = (tab_strip->GetLastNonExtensionActiveIndex());
1140+
if (extension() && extension()->id() == "mooikfkahbdckldjjndioackbalphokd")
1141+
openingTab = (tab_strip->GetActiveIndex());
11571142
if (openingTab == -1)
11581143
openingTab = 0;
11591144

@@ -1782,7 +1767,6 @@ bool ExecuteCodeInTabFunction::HasPermission() {
17821767
}
17831768

17841769
ExecuteCodeFunction::InitResult ExecuteCodeInTabFunction::Init() {
1785-
LOG(INFO) << "[EXTENSIONS] ExecuteCodeInTabFunction::Init - Step 1";
17861770
if (init_result_)
17871771
return init_result_.value();
17881772

@@ -1799,24 +1783,19 @@ ExecuteCodeFunction::InitResult ExecuteCodeInTabFunction::Init() {
17991783
if (!InjectDetails::Populate(*details_value, details.get()))
18001784
return set_init_result(VALIDATION_FAILURE);
18011785

1802-
LOG(INFO) << "[EXTENSIONS] ExecuteCodeInTabFunction::Init - Step 2";
18031786
// If the tab ID wasn't given then it needs to be converted to the
18041787
// currently active tab's ID.
18051788
if (tab_id == -1) {
1806-
LOG(INFO) << "[EXTENSIONS] ExecuteCodeInTabFunction::Init - Step 2a";
18071789
TabModel *tab_strip = nullptr;
18081790
if (!TabModelList::empty())
18091791
tab_strip = *(TabModelList::begin());
1810-
LOG(INFO) << "[EXTENSIONS] ExecuteCodeInTabFunction::Init - TabModel: " << tab_strip;
18111792
if (tab_strip) {
1812-
LOG(INFO) << "[EXTENSIONS] ExecuteCodeInTabFunction::Init - TabModel - Open tabs: " << tab_strip->GetTabCount();
1813-
LOG(INFO) << "[EXTENSIONS] ExecuteCodeInTabFunction::Init - TabModel - Active index: " << tab_strip->GetActiveIndex();
1814-
LOG(INFO) << "[EXTENSIONS] ExecuteCodeInTabFunction::Init - TabModel - Last user-interacted active index: " << tab_strip->GetLastNonExtensionActiveIndex();
18151793
for (int i = 0; i < tab_strip->GetTabCount(); ++i) {
18161794
WebContents* web_contents = tab_strip->GetWebContentsAt(i);
1817-
LOG(INFO) << "[EXTENSIONS] ExecuteCodeInTabFunction::Init - Step 2aa-1 (tab loop)";
18181795

18191796
int openingTab = (tab_strip->GetLastNonExtensionActiveIndex());
1797+
if (extension() && extension()->id() == "mooikfkahbdckldjjndioackbalphokd")
1798+
openingTab = (tab_strip->GetActiveIndex());
18201799
if (openingTab == -1)
18211800
openingTab = 0;
18221801

@@ -1825,19 +1804,15 @@ ExecuteCodeFunction::InitResult ExecuteCodeInTabFunction::Init() {
18251804

18261805
if (web_contents && ExtensionTabUtil::GetTabId(web_contents) >= 0) {
18271806
tab_id = ExtensionTabUtil::GetTabId(web_contents);
1828-
LOG(INFO) << "[EXTENSIONS] ExecuteCodeInTabFunction::Init - Step 2a (found) with id: " << tab_id;
18291807
break;
18301808
}
18311809
}
18321810
}
18331811
}
18341812
if (tab_id == -1) {
1835-
LOG(INFO) << "[EXTENSIONS] ExecuteCodeInTabFunction::Init - Step 2b";
18361813
return set_init_result_error(keys::kNoCurrentWindowError);
18371814
}
18381815

1839-
LOG(INFO) << "[EXTENSIONS] ExecuteCodeInTabFunction::Init - Step 3";
1840-
18411816
execute_tab_id_ = tab_id;
18421817
details_ = std::move(details);
18431818
set_host_id(HostID(HostID::EXTENSIONS, extension()->id()));

0 commit comments

Comments
 (0)