Commit 4aaf38d5 authored by Leonard Grey's avatar Leonard Grey Committed by Commit Bot

Commander: Add Google Apps command source

This command source adds commands to create a new Doc, Sheet, Meet etc.
It doesn't require any integration, since it takes advantage of the new
docs.new etc. URLs.

(This change also populates CommanderController's default command sources)

Bug: 1014639
Change-Id: I1acef15e9eac2cda11b0087419ee8ccb6328dd9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2442871
Commit-Queue: Leonard Grey <lgrey@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812940}
parent 67c29b07
...@@ -911,6 +911,8 @@ static_library("ui") { ...@@ -911,6 +911,8 @@ static_library("ui") {
"chrome_web_modal_dialog_manager_delegate.h", "chrome_web_modal_dialog_manager_delegate.h",
"collected_cookies_infobar_delegate.cc", "collected_cookies_infobar_delegate.cc",
"collected_cookies_infobar_delegate.h", "collected_cookies_infobar_delegate.h",
"commander/apps_command_source.cc",
"commander/apps_command_source.h",
"commander/command_source.cc", "commander/command_source.cc",
"commander/command_source.h", "commander/command_source.h",
"commander/commander_backend.h", "commander/commander_backend.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/commander/apps_command_source.h"
#include "base/i18n/case_conversion.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/commander/fuzzy_finder.h"
#include "url/gurl.h"
namespace commander {
AppsCommandSource::AppsCommandSource() = default;
AppsCommandSource::~AppsCommandSource() = default;
CommandSource::CommandResults AppsCommandSource::GetCommands(
const base::string16& input,
Browser* browser) const {
// TODO(lgrey): Strings are temporarily unlocalized since this is
// experimental.
static constexpr struct {
const char* title;
const char* url;
} command_map[] = {
{"New Google Doc", "https://docs.new"},
{"New Google Sheet", "https://sheets.new"},
{"New Google Slides", "https://slides.new"},
{"New Google Form", "https://forms.new"},
{"New Google Meet", "https://meet.new"},
};
CommandSource::CommandResults results;
const base::string16& folded_input = base::i18n::FoldCase(input);
std::vector<gfx::Range> ranges;
for (const auto& command_spec : command_map) {
base::string16 title = base::ASCIIToUTF16(command_spec.title);
double score = FuzzyFind(folded_input, title, &ranges);
if (score == 0)
continue;
auto item = std::make_unique<CommandItem>();
item->title = title;
item->score = score;
item->matched_ranges = ranges;
// base::Unretained is safe because commands are reset when a browser is
// closed.
item->command =
base::BindOnce(&chrome::AddTabAt, base::Unretained(browser),
GURL(command_spec.url), -1, true, base::nullopt);
results.push_back(std::move(item));
}
return results;
}
} // namespace commander
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_COMMANDER_APPS_COMMAND_SOURCE_H_
#define CHROME_BROWSER_UI_COMMANDER_APPS_COMMAND_SOURCE_H_
#include "chrome/browser/ui/commander/command_source.h"
namespace commander {
// A command source for interacting with GSuite.
class AppsCommandSource : public CommandSource {
public:
AppsCommandSource();
~AppsCommandSource() override;
// Disallow copy and assign.
AppsCommandSource(const AppsCommandSource& other) = delete;
AppsCommandSource& operator=(const AppsCommandSource& other) = delete;
// CommandSource overrides
CommandSource::CommandResults GetCommands(const base::string16& input,
Browser* browser) const override;
};
} // namespace commander
#endif // CHROME_BROWSER_UI_COMMANDER_APPS_COMMAND_SOURCE_H_
...@@ -5,15 +5,23 @@ ...@@ -5,15 +5,23 @@
#include "chrome/browser/ui/commander/commander_controller.h" #include "chrome/browser/ui/commander/commander_controller.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "build/branding_buildflags.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/commander/apps_command_source.h"
#include "chrome/browser/ui/commander/commander_view_model.h" #include "chrome/browser/ui/commander/commander_view_model.h"
#include "chrome/browser/ui/commander/simple_command_source.h"
namespace commander { namespace commander {
namespace { namespace {
CommanderController::CommandSources CreateDefaultSources() { CommanderController::CommandSources CreateDefaultSources() {
return {}; CommanderController::CommandSources sources;
sources.push_back(std::make_unique<SimpleCommandSource>());
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
sources.push_back(std::make_unique<AppsCommandSource>());
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
return sources;
} }
} // namespace } // namespace
......
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