Commit 5e4bcd0c authored by Orin Jaworski's avatar Orin Jaworski Committed by Commit Bot

[omnibox] Add Pedal to launch incognito window

This CL introduces another experimental action Pedal to launch
an incognito tab in a new browser window.

Bug: 893183
Change-Id: I9b0a671f80037ee646a8bfa6401474d9315e430d
Reviewed-on: https://chromium-review.googlesource.com/c/1274204
Commit-Queue: Orin Jaworski <orinj@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600082}
parent de532b65
......@@ -88,17 +88,18 @@ IN_PROC_BROWSER_TEST_F(ChromeMainTest, MAYBE_SecondLaunchWithIncognitoUrl) {
}
IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunchFromIncognitoWithNormalUrl) {
Profile* const profile = browser()->profile();
// We should start with one normal window.
ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(browser()->profile()));
ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(profile));
// Create an incognito window.
chrome::NewIncognitoWindow(browser());
chrome::NewIncognitoWindow(profile);
ASSERT_EQ(2u, chrome::GetTotalBrowserCount());
ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(browser()->profile()));
ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(profile));
// Close the first window.
Profile* profile = browser()->profile();
CloseBrowserSynchronously(browser());
// There should only be the incognito window open now.
......
......@@ -190,7 +190,7 @@ void ProcessMirrorHeaderUIThread(
BrowserWindow::AvatarBubbleMode bubble_mode;
switch (service_type) {
case GAIA_SERVICE_TYPE_INCOGNITO:
chrome::NewIncognitoWindow(browser);
chrome::NewIncognitoWindow(profile);
return;
case GAIA_SERVICE_TYPE_ADDSESSION:
bubble_mode = BrowserWindow::AVATAR_BUBBLE_MODE_ADD_ACCOUNT;
......
......@@ -342,7 +342,7 @@ bool BrowserCommandController::ExecuteCommandWithDisposition(
NewWindow(browser_);
break;
case IDC_NEW_INCOGNITO_WINDOW:
NewIncognitoWindow(browser_);
NewIncognitoWindow(profile());
break;
case IDC_CLOSE_WINDOW:
base::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
......
......@@ -577,13 +577,13 @@ void NewWindow(Browser* browser) {
NewEmptyWindow(browser->profile()->GetOriginalProfile());
}
void NewIncognitoWindow(Browser* browser) {
void NewIncognitoWindow(Profile* profile) {
#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
feature_engagement::IncognitoWindowTrackerFactory::GetInstance()
->GetForProfile(browser->profile())
->GetForProfile(profile)
->OnIncognitoWindowOpened();
#endif
NewEmptyWindow(browser->profile()->GetOffTheRecordProfile());
NewEmptyWindow(profile->GetOffTheRecordProfile());
}
void CloseWindow(Browser* browser) {
......
......@@ -70,7 +70,7 @@ void Home(Browser* browser, WindowOpenDisposition disposition);
void OpenCurrentURL(Browser* browser);
void Stop(Browser* browser);
void NewWindow(Browser* browser);
void NewIncognitoWindow(Browser* browser);
void NewIncognitoWindow(Profile* profile);
void CloseWindow(Browser* browser);
void NewTab(Browser* browser);
void CloseTab(Browser* browser);
......
......@@ -37,6 +37,8 @@
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/omnibox/chrome_omnibox_edit_controller.h"
#include "chrome/browser/ui/omnibox/chrome_omnibox_navigation_observer.h"
......@@ -483,6 +485,10 @@ void ChromeOmniboxClient::DiscardNonCommittedNavigations() {
controller_->GetWebContents()->GetController().DiscardNonCommittedEntries();
}
void ChromeOmniboxClient::NewIncognitoWindow() {
chrome::NewIncognitoWindow(profile_);
}
void ChromeOmniboxClient::PromptPageTranslation() {
content::WebContents* contents = controller_->GetWebContents();
if (contents) {
......
......@@ -80,6 +80,7 @@ class ChromeOmniboxClient : public OmniboxClient {
void OnURLOpenedFromOmnibox(OmniboxLog* log) override;
void OnBookmarkLaunched() override;
void DiscardNonCommittedNavigations() override;
void NewIncognitoWindow() override;
void PromptPageTranslation() override;
private:
......
......@@ -650,7 +650,7 @@ void ProfileChooserView::ButtonPressed(views::Button* sender,
PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_OPEN_USER_MANAGER);
} else if (sender == go_incognito_button_) {
DCHECK(ShouldShowGoIncognito());
chrome::NewIncognitoWindow(browser_);
chrome::NewIncognitoWindow(browser_->profile());
PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_GO_INCOGNITO);
} else if (sender == lock_button_) {
profiles::LockProfile(browser_->profile());
......
......@@ -170,6 +170,9 @@ class OmniboxClient {
// Discards the state for all pending and transient navigations.
virtual void DiscardNonCommittedNavigations() {}
// Opens and shows a new incognito browser window.
virtual void NewIncognitoWindow() {}
// Presents translation prompt for current tab web contents.
virtual void PromptPageTranslation() {}
};
......
......@@ -149,6 +149,26 @@ class OmniboxPedalUpdateCreditCard : public OmniboxPedalCommon {
// =============================================================================
class OmniboxPedalLaunchIncognito : public OmniboxPedalCommon {
public:
OmniboxPedalLaunchIncognito()
: OmniboxPedalCommon(
LabelStrings(
IDS_OMNIBOX_PEDAL_LAUNCH_INCOGNITO_HINT,
IDS_OMNIBOX_PEDAL_LAUNCH_INCOGNITO_HINT_SHORT,
IDS_OMNIBOX_PEDAL_LAUNCH_INCOGNITO_SUGGESTION_CONTENTS),
GURL(),
{
"what is incognito", "what's incognito mode",
}) {}
void Execute(ExecutionContext& context) const override {
context.client_.NewIncognitoWindow();
}
};
// =============================================================================
class OmniboxPedalTranslate : public OmniboxPedalCommon {
public:
OmniboxPedalTranslate()
......@@ -182,6 +202,7 @@ std::vector<std::unique_ptr<OmniboxPedal>> GetPedalImplementations() {
add(new OmniboxPedalManagePasswords());
add(new OmniboxPedalChangeHomePage());
add(new OmniboxPedalUpdateCreditCard());
add(new OmniboxPedalLaunchIncognito());
add(new OmniboxPedalTranslate());
return pedals;
}
......@@ -128,6 +128,16 @@
Update credit card autofill info in Chrome settings
</message>
<message name="IDS_OMNIBOX_PEDAL_LAUNCH_INCOGNITO_HINT" desc="The button text contents to suggest pedal action, launch incognito.">
Open Incognito Window
</message>
<message name="IDS_OMNIBOX_PEDAL_LAUNCH_INCOGNITO_HINT_SHORT" desc="The short one-word button text contents to suggest pedal action, launch incognito.">
Open
</message>
<message name="IDS_OMNIBOX_PEDAL_LAUNCH_INCOGNITO_SUGGESTION_CONTENTS" desc="The suggestion content text to suggest pedal action, launch incognito.">
Open new Chrome incognito window
</message>
<message name="IDS_OMNIBOX_PEDAL_TRANSLATE_HINT" desc="The button text contents to suggest pedal action, translate.">
Translate Page
</message>
......
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