Skip to content

Commit

Permalink
Added --custom-launcher-page. Adds a page to the experimental launcher.
Browse files Browse the repository at this point in the history
This allows the user to specify a custom web page (which must be in the
chrome-extension:// scheme) which will appear as a third top-level page
in the experimental launcher, alongside the start and apps pages.

This command-line switch is intended to be temporary; eventually,
extensions will be able to specify their own custom launcher pages. For
now, the command-line switch is sufficient for testing.

Most of the Chrome APIs are not yet available for these pages.

BUG=386004
TBR=mukai@chromium.org,jamescook@chromium.org

Review URL: https://codereview.chromium.org/352033002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279685 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
mgiuca@chromium.org committed Jun 25, 2014
1 parent 387c792 commit d0c122e
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ash/shell/app_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ class ExampleAppListViewDelegate : public app_list::AppListViewDelegate {
return NULL;
}

virtual views::View* CreateCustomPageWebView(const gfx::Size& size) OVERRIDE {
return NULL;
}

virtual bool IsSpeechRecognitionEnabled() OVERRIDE {
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions athena/home/app_list_view_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ views::View* AppListViewDelegate::CreateStartPageWebView(
return NULL;
}

views::View* AppListViewDelegate::CreateCustomPageWebView(
const gfx::Size& size) {
return NULL;
}

bool AppListViewDelegate::IsSpeechRecognitionEnabled() {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions athena/home/app_list_view_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class AppListViewDelegate : public app_list::AppListViewDelegate {
virtual void ShowForProfileByPath(
const base::FilePath& profile_path) OVERRIDE;
virtual views::View* CreateStartPageWebView(const gfx::Size& size) OVERRIDE;
virtual views::View* CreateCustomPageWebView(const gfx::Size& size) OVERRIDE;
virtual bool IsSpeechRecognitionEnabled() OVERRIDE;
virtual const Users& GetUsers() const OVERRIDE;
virtual bool ShouldCenterWindow() const OVERRIDE;
Expand Down
39 changes: 39 additions & 0 deletions chrome/browser/ui/app_list/app_list_view_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <vector>

#include "base/callback.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/metrics/user_metrics.h"
#include "base/stl_util.h"
Expand All @@ -27,19 +28,23 @@
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/url_constants.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/constants.h"
#include "grit/theme_resources.h"
#include "ui/app_list/app_list_switches.h"
#include "ui/app_list/app_list_view_delegate_observer.h"
#include "ui/app_list/search_box_model.h"
#include "ui/app_list/speech_ui_model.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/controls/webview/webview.h"

#if defined(TOOLKIT_VIEWS)
#include "ui/views/controls/webview/webview.h"
Expand Down Expand Up @@ -144,6 +149,28 @@ AppListViewDelegate::AppListViewDelegate(Profile* profile,
OnProfileChanged(); // sets model_
if (service)
service->AddObserver(this);

// Set up the custom launcher page. There is currently only a single custom
// page allowed, which is specified as a command-line flag. In the future,
// arbitrary extensions may be able to specify their own custom pages.
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (app_list::switches::IsExperimentalAppListEnabled() &&
command_line->HasSwitch(switches::kCustomLauncherPage)) {
GURL custom_launcher_page_url(
command_line->GetSwitchValueASCII(switches::kCustomLauncherPage));
if (!custom_launcher_page_url.SchemeIs(extensions::kExtensionScheme)) {
LOG(ERROR) << "Invalid custom launcher page URL: "
<< custom_launcher_page_url.possibly_invalid_spec();
} else {
content::WebContents::CreateParams params(profile_);
custom_page_web_contents_.reset(content::WebContents::Create(params));
custom_page_web_contents_->GetController().LoadURL(
custom_launcher_page_url,
content::Referrer(),
content::PAGE_TRANSITION_AUTO_TOPLEVEL,
std::string());
}
}
}

AppListViewDelegate::~AppListViewDelegate() {
Expand Down Expand Up @@ -451,6 +478,18 @@ views::View* AppListViewDelegate::CreateStartPageWebView(
web_view->SetWebContents(web_contents);
return web_view;
}

views::View* AppListViewDelegate::CreateCustomPageWebView(
const gfx::Size& size) {
if (!custom_page_web_contents_)
return NULL;

views::WebView* web_view = new views::WebView(
custom_page_web_contents_->GetBrowserContext());
web_view->SetPreferredSize(size);
web_view->SetWebContents(custom_page_web_contents_.get());
return web_view;
}
#endif

bool AppListViewDelegate::IsSpeechRecognitionEnabled() {
Expand Down
8 changes: 8 additions & 0 deletions chrome/browser/ui/app_list/app_list_view_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ namespace base {
class FilePath;
}

namespace content {
class WebContents;
}

namespace gfx {
class ImageSkia;
}
Expand Down Expand Up @@ -85,6 +89,7 @@ class AppListViewDelegate : public app_list::AppListViewDelegate,
const base::FilePath& profile_path) OVERRIDE;
#if defined(TOOLKIT_VIEWS)
virtual views::View* CreateStartPageWebView(const gfx::Size& size) OVERRIDE;
virtual views::View* CreateCustomPageWebView(const gfx::Size& size) OVERRIDE;
#endif
virtual bool IsSpeechRecognitionEnabled() OVERRIDE;
virtual const Users& GetUsers() const OVERRIDE;
Expand Down Expand Up @@ -149,6 +154,9 @@ class AppListViewDelegate : public app_list::AppListViewDelegate,
// this instance can be removed as an observer on its destruction.
ScopedObserver<SigninManagerBase, AppListViewDelegate> scoped_observer_;

// Contents of the additional custom launcher page. May be NULL.
scoped_ptr<content::WebContents> custom_page_web_contents_;

DISALLOW_COPY_AND_ASSIGN(AppListViewDelegate);
};

Expand Down
4 changes: 4 additions & 0 deletions chrome/common/chrome_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ const char kCrashOnHangThreads[] = "crash-on-hang-threads";
const char kCreateBrowserOnStartupForTests[] =
"create-browser-on-startup-for-tests";

// Specifies the chrome-extension:// URL for the contents of an additional page
// added to the experimental app launcher.
const char kCustomLauncherPage[] = "custom-launcher-page";

// Enables a frame context menu item that toggles the frame in and out of glass
// mode (Windows Vista and up only).
const char kDebugEnableFrameToggle[] = "debug-enable-frame-toggle";
Expand Down
1 change: 1 addition & 0 deletions chrome/common/chrome_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extern const char kCloudPrintSetupProxy[];
extern const char kComponentUpdater[];
extern const char kCrashOnHangThreads[];
extern const char kCreateBrowserOnStartupForTests[];
extern const char kCustomLauncherPage[];
extern const char kDebugEnableFrameToggle[];
extern const char kDebugPackedApps[];
extern const char kDiagnostics[];
Expand Down
4 changes: 4 additions & 0 deletions ui/app_list/app_list_view_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ class APP_LIST_EXPORT AppListViewDelegate {
// Creates the web view for the start page. The caller takes the ownership of
// the returned view.
virtual views::View* CreateStartPageWebView(const gfx::Size& size) = 0;

// Creates the web view for the user-specified custom page. May return NULL.
// The caller takes ownership of the returned view.
virtual views::View* CreateCustomPageWebView(const gfx::Size& size) = 0;
#endif

// Returns true if the delegate supports speech recognition.
Expand Down
4 changes: 4 additions & 0 deletions ui/app_list/test/app_list_test_view_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ views::View* AppListTestViewDelegate::CreateStartPageWebView(
const gfx::Size& size) {
return NULL;
}
views::View* AppListTestViewDelegate::CreateCustomPageWebView(
const gfx::Size& size) {
return NULL;
}
#endif

bool AppListTestViewDelegate::IsSpeechRecognitionEnabled() {
Expand Down
1 change: 1 addition & 0 deletions ui/app_list/test/app_list_test_view_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class AppListTestViewDelegate : public AppListViewDelegate {
const base::FilePath& profile_path) OVERRIDE {}
#if defined(TOOLKIT_VIEWS)
virtual views::View* CreateStartPageWebView(const gfx::Size& size) OVERRIDE;
virtual views::View* CreateCustomPageWebView(const gfx::Size& size) OVERRIDE;
#endif
virtual bool IsSpeechRecognitionEnabled() OVERRIDE;
virtual const Users& GetUsers() const OVERRIDE;
Expand Down
5 changes: 5 additions & 0 deletions ui/app_list/views/contents_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ void ContentsView::InitNamedPages(AppListModel* model,
DCHECK(model);

if (app_list::switches::IsExperimentalAppListEnabled()) {
views::View* custom_page_view =
view_delegate->CreateCustomPageWebView(GetLocalBounds().size());
if (custom_page_view)
AddLauncherPage(custom_page_view, IDR_APP_LIST_NOTIFICATIONS_ICON);

start_page_view_ = new StartPageView(app_list_main_view_, view_delegate);
AddLauncherPage(
start_page_view_, IDR_APP_LIST_SEARCH_ICON, NAMED_PAGE_START);
Expand Down

0 comments on commit d0c122e

Please sign in to comment.