Commit 8a6cc7ee authored by Hector Carmona's avatar Hector Carmona Committed by Commit Bot

NUX Email: Create initial files for Email NUX.

These files were copied from Google Apps NUX and modified slightly.

Bug: 832933
Change-Id: I8fd79b2e00d2224e20c6159f478e54defaad0d73
Reviewed-on: https://chromium-review.googlesource.com/1185919Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Commit-Queue: Hector Carmona <hcarmona@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585534}
parent f8437822
......@@ -3899,7 +3899,10 @@ jumbo_split_static_library("ui") {
}
if (is_win && is_chrome_branded) {
deps += [ "//components/nux:google_apps_feature" ]
deps += [
"//components/nux:email_feature",
"//components/nux:google_apps_feature",
]
}
if (enable_plugins) {
......
......@@ -25,6 +25,8 @@
#if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
#include "base/metrics/histogram_macros.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "components/nux/email/constants.h"
#include "components/nux/email/email_handler.h"
#include "components/nux/google_apps/constants.h"
#include "components/nux/google_apps/google_apps_handler.h"
#include "components/nux/show_promo_delegate.h"
......@@ -111,6 +113,18 @@ WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
}
#if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
if (base::FeatureList::IsEnabled(nux::kNuxEmailFeature)) {
content::BrowserContext* browser_context =
web_ui->GetWebContents()->GetBrowserContext();
web_ui->AddMessageHandler(std::make_unique<nux::EmailHandler>(
profile->GetPrefs(),
FaviconServiceFactory::GetForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS),
BookmarkModelFactory::GetForBrowserContext(browser_context)));
nux::EmailHandler::AddSources(html_source);
}
if (base::FeatureList::IsEnabled(nux::kNuxGoogleAppsFeature)) {
content::BrowserContext* browser_context =
web_ui->GetWebContents()->GetBrowserContext();
......
......@@ -5,6 +5,34 @@
import("//build/config/chrome_build.gni")
if (is_win && is_chrome_branded) {
static_library("email_feature") {
sources = [
"email/constants.cc",
"email/constants.h",
"email/email_handler.cc",
"email/email_handler.h",
]
public_deps = [
"//base",
"//net",
"//url",
]
deps = [
"//components/bookmarks/browser",
"//components/bookmarks/common",
"//components/favicon/core",
"//components/pref_registry",
"//components/prefs",
"//components/resources",
"//components/strings",
"//components/variations",
"//content/public/browser",
"//ui/base",
]
}
static_library("google_apps_feature") {
sources = [
"google_apps/constants.cc",
......
// Copyright 2018 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 "components/nux/email/constants.h"
#include "base/feature_list.h"
namespace nux {
extern const base::Feature kNuxEmailFeature{"NuxEmail",
base::FEATURE_DISABLED_BY_DEFAULT};
extern const char kNuxEmailUrl[] = "chrome://welcome/email";
} // namespace nux
\ No newline at end of file
// Copyright 2018 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 COMPONENTS_NUX_EMAIL_CONSTANTS_H_
#define COMPONENTS_NUX_EMAIL_CONSTANTS_H_
namespace base {
struct Feature;
} // namespace base
namespace nux {
extern const base::Feature kNuxEmailFeature;
extern const char kNuxEmailUrl[];
} // namespace nux
#endif // COMPONENTS_NUX_EMAIL_CONSTANTS_H_
// Copyright 2018 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 "components/nux/email/email_handler.h"
#include "base/bind.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/common/bookmark_pref_names.h"
#include "components/favicon/core/favicon_service.h"
#include "components/grit/components_resources.h"
#include "components/grit/components_scaled_resources.h"
#include "components/nux/email/constants.h"
#include "components/nux/show_promo_delegate.h"
#include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/base/resource/resource_bundle.h"
namespace nux {
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class EmailProviders {
kGmail = 0,
kYahoo = 1,
kOutlook = 2,
kAol = 3,
kiCloud = 4,
kCount,
};
const char* kEmailInteractionHistogram =
"FirstRun.NewUserExperience.EmailInteraction";
// Strings in costants not translated because this is an experiment.
// Translate before wide release.
constexpr const char* kEmailNames[] = {
"Gmail", "Yahoo", "Outlook", "AOL", "iCloud",
};
// TODO(hcarmona): get correct URLs
constexpr const char* kEmailUrls[] = {
"https://gmail.com", "https://youtube.com",
"https://maps.google.com", "https://translate.google.com",
"https://news.google.com",
};
constexpr const int kEmailIconSize = 48; // Pixels.
constexpr const int kEmailIcons[] = {
// TODO(hcarmona): populate list of icons
};
static_assert(base::size(kEmailNames) == base::size(kEmailUrls),
"names and urls must match");
static_assert(base::size(kEmailNames) == (size_t)EmailProviders::kCount,
"names and histograms must match");
/*static_assert(base::size(kEmailNames) == base::size(kEmailIcons),
"names and icons must match");*/
EmailHandler::EmailHandler(PrefService* prefs,
favicon::FaviconService* favicon_service,
bookmarks::BookmarkModel* bookmark_model)
: prefs_(prefs),
favicon_service_(favicon_service),
bookmark_model_(bookmark_model) {}
EmailHandler::~EmailHandler() {}
void EmailHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"rejectEmails", base::BindRepeating(&EmailHandler::HandleRejectEmails,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"addEmails", base::BindRepeating(&EmailHandler::HandleAddEmails,
base::Unretained(this)));
}
void EmailHandler::HandleRejectEmails(const base::ListValue* args) {
/* TODO(hcarmona): Add histograms and uncomment this code.
UMA_HISTOGRAM_ENUMERATION(kEmailInteractionHistogram,
EmailInteraction::kNoThanks,
EmailInteraction::kCount);
*/
}
void EmailHandler::HandleAddEmails(const base::ListValue* args) {
// Add bookmarks for all selected emails.
int bookmarkIndex = 0;
for (size_t i = 0; i < (size_t)EmailProviders::kCount; ++i) {
bool selected = false;
CHECK(args->GetBoolean(i, &selected));
if (selected) {
/* TODO(hcarmona): Add histograms and uncomment this code.
UMA_HISTOGRAM_ENUMERATION("FirstRun.NewUserExperience.EmailSelection",
(EmailProviders)i,
EmailProviders::kCount);
*/
GURL app_url = GURL(kEmailUrls[i]);
bookmark_model_->AddURL(bookmark_model_->bookmark_bar_node(),
bookmarkIndex++,
base::ASCIIToUTF16(kEmailNames[i]), app_url);
// Preload the favicon cache with Chrome-bundled images. Otherwise, the
// pre-populated bookmarks don't have favicons and look bad. Favicons are
// updated automatically when a user visits a site.
favicon_service_->MergeFavicon(
app_url, app_url, favicon_base::IconType::kFavicon,
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
kEmailIcons[i]),
gfx::Size(kEmailIconSize, kEmailIconSize));
}
}
// Enable bookmark bar.
prefs_->SetBoolean(bookmarks::prefs::kShowBookmarkBar, true);
// Show bookmark bubble.
/* TODO(hcarmona): Show promo bubble.
ShowPromoDelegate::CreatePromoDelegate(
IDS_NUX_EMAIL_DESCRIPTION_PROMO_BUBBLE)
->ShowForNode(bookmark_model_->bookmark_bar_node()->GetChild(0));
*/
/* TODO(hcarmona): Add histograms and uncomment this code.
UMA_HISTOGRAM_ENUMERATION(kEmailInteractionHistogram,
EmailInteraction::kGetStarted,
EmailInteraction::kCount);
*/
}
void EmailHandler::AddSources(content::WebUIDataSource* html_source) {
// Localized strings.
// Add required resources.
html_source->AddResourcePath("email", IDR_NUX_EMAIL_HTML);
// Add icons
}
} // namespace nux
\ No newline at end of file
// Copyright 2018 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 COMPONENTS_NUX_EMAIL_EMAIL_HANDLER_H_
#define COMPONENTS_NUX_EMAIL_EMAIL_HANDLER_H_
#include "base/macros.h"
#include "base/values.h"
#include "content/public/browser/web_ui_message_handler.h"
class PrefService;
namespace bookmarks {
class BookmarkModel;
} // namespace bookmarks
namespace content {
class WebUIDataSource;
} // namespace content
namespace favicon {
class FaviconService;
} // namespace favicon
namespace nux {
extern const char* kEmailInteractionHistogram;
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class EmailInteraction {
kPromptShown = 0,
kNoThanks = 1,
kGetStarted = 2,
kCount,
};
class EmailHandler : public content::WebUIMessageHandler {
public:
EmailHandler(PrefService* prefs,
favicon::FaviconService* favicon_service,
bookmarks::BookmarkModel* bookmark_model);
~EmailHandler() override;
// WebUIMessageHandler:
void RegisterMessages() override;
// Callbacks for JS APIs.
void HandleRejectEmails(const base::ListValue* args);
void HandleAddEmails(const base::ListValue* args);
// Adds webui sources.
static void AddSources(content::WebUIDataSource* html_source);
private:
// Weak reference.
PrefService* prefs_;
// Weak reference.
favicon::FaviconService* favicon_service_;
// Weak reference.
bookmarks::BookmarkModel* bookmark_model_;
DISALLOW_COPY_AND_ASSIGN(EmailHandler);
};
} // namespace nux
#endif // COMPONENTS_NUX_GOOGLE_APPS_GOOGLE_APPS_HANDLER_H_
# Copyright 2018 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.
import("//third_party/closure_compiler/compile_js.gni")
js_type_check("closure_compile") {
deps = [
":nux_email",
]
}
js_library("nux_email") {
deps = []
}
<!DOCTYPE html>
<html dir="$i18n{textdirection}" lang="$i18n{language}">
<meta charset="utf-8">
<title></title>
<div>Hello World</div>
</html>
\ No newline at end of file
......@@ -17,6 +17,7 @@
<part file="neterror_resources.grdp" />
<part file="ntp_tiles_resources.grdp" />
<if expr="is_win">
<part file="nux_email.grdp" />
<part file="nux_google_apps.grdp" />
</if>
<part file="offline_pages_resources.grdp" />
......
<?xml version="1.0" encoding="utf-8"?>
<grit-part>
<include name="IDR_NUX_EMAIL_HTML" file="../nux/email/resources/nux_email.html" type="BINDATA" />
</grit-part>
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