-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement keyboard shortcut for Lens Region Search.
Keyboard shortcut (Ctrl/Cmd + Shift + L) is temporary as the keyboard shortcut has not yet been finalized. All code is flag-guarded so keyboard behavior is unaffected when flag is disabled. Tested on Linux, Mac, and Windows; with flag disabled and enabled; and with search engine set to Google, Bing (third-party search engine that supports region search), and Yahoo (does not support region search). Availability of keyboard shortcut is identical to that of region search when flag is enabled. Screenshot of context menu item with keyboard shortcut label: https://screenshot.googleplex.com/3MSyZ2kn9iGHDef Bug: 1392456 Change-Id: Ifa4fb6297879d9ae4de3c0d9dc970c4878e52c04 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4043546 Reviewed-by: Juan Mojica <juanmojica@google.com> Reviewed-by: Avi Drissman <avi@chromium.org> Commit-Queue: Bryan Nguyen <nguyenbryan@google.com> Cr-Commit-Position: refs/heads/main@{#1076590}
- Loading branch information
Bryan Nguyen
authored and
Chromium LUCI CQ
committed
Nov 29, 2022
1 parent
6544fc8
commit 422b5c3
Showing
14 changed files
with
192 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
chrome/browser/lens/region_search/lens_region_search_helper.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/lens/region_search/lens_region_search_helper.h" | ||
|
||
#include "base/feature_list.h" | ||
#include "build/branding_buildflags.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/search_engines/template_url_service_factory.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/common/pref_names.h" | ||
#include "components/lens/lens_features.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "components/search_engines/template_url.h" | ||
#include "components/search_engines/template_url_service.h" | ||
#include "content/public/browser/navigation_entry.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "content/public/common/url_constants.h" | ||
#include "url/gurl.h" | ||
|
||
namespace lens { | ||
|
||
bool IsRegionSearchEnabled(Browser* browser, | ||
Profile* profile, | ||
const GURL& url) { | ||
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) | ||
if (!browser) | ||
return false; | ||
|
||
TemplateURLService* service = | ||
TemplateURLServiceFactory::GetForProfile(profile); | ||
if (!service) | ||
return false; | ||
|
||
// Region selection is broken in PWAs on Mac b/250074889 | ||
#if BUILDFLAG(IS_MAC) | ||
if (IsInProgressiveWebApp(browser)) | ||
return false; | ||
#endif // BUILDFLAG(IS_MAC) | ||
|
||
const TemplateURL* provider = service->GetDefaultSearchProvider(); | ||
const bool provider_supports_image_search = | ||
provider && !provider->image_url().empty() && | ||
provider->image_url_ref().IsValid(service->search_terms_data()); | ||
return base::FeatureList::IsEnabled(lens::features::kLensStandalone) && | ||
provider_supports_image_search && | ||
!url.SchemeIs(content::kChromeUIScheme) && | ||
profile->GetPrefs()->GetBoolean(prefs::kLensRegionSearchEnabled); | ||
#else | ||
return false; | ||
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING) | ||
} | ||
|
||
bool IsInProgressiveWebApp(Browser* browser) { | ||
return browser && (browser->is_type_app() || browser->is_type_app_popup()); | ||
} | ||
|
||
} // namespace lens |
20 changes: 20 additions & 0 deletions
20
chrome/browser/lens/region_search/lens_region_search_helper.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_LENS_REGION_SEARCH_LENS_REGION_SEARCH_HELPER_H_ | ||
#define CHROME_BROWSER_LENS_REGION_SEARCH_LENS_REGION_SEARCH_HELPER_H_ | ||
|
||
class Browser; | ||
class Profile; | ||
class GURL; | ||
|
||
namespace lens { | ||
|
||
bool IsRegionSearchEnabled(Browser* browser, Profile* profile, const GURL& url); | ||
|
||
bool IsInProgressiveWebApp(Browser* browser); | ||
|
||
} // namespace lens | ||
|
||
#endif // CHROME_BROWSER_LENS_REGION_SEARCH_LENS_REGION_SEARCH_HELPER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters