Commit ec057339 authored by mgiuca@chromium.org's avatar mgiuca@chromium.org

Experimental app list: Custom launcher pages have app APIs and style.

Added CustomLauncherPageContents, which is copied from AppWindowContents
and modified to provide launcher pages instead. This correctly
dispatches messages to the extensions system.

The extension inside the launcher page is now "activated" which ensures
that it is styled as a platform app and given the correct APIs by the
extension dispatcher.

BUG=391137
BUG=391202

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282530 0039d316-1c4b-4281-b951-d872f2087c98
parent 54bc61b2
......@@ -47,6 +47,8 @@
'apps_client.h',
'browser_context_keyed_service_factories.cc',
'browser_context_keyed_service_factories.h',
'custom_launcher_page_contents.cc',
'custom_launcher_page_contents.h',
'launcher.cc',
'launcher.h',
'metrics_names.h',
......
// Copyright 2014 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 "apps/custom_launcher_page_contents.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/renderer_preferences.h"
#include "extensions/common/extension_messages.h"
namespace apps {
CustomLauncherPageContents::CustomLauncherPageContents() {
}
CustomLauncherPageContents::~CustomLauncherPageContents() {
}
void CustomLauncherPageContents::Initialize(content::BrowserContext* context,
const GURL& url) {
extension_function_dispatcher_.reset(
new extensions::ExtensionFunctionDispatcher(context, this));
web_contents_.reset(
content::WebContents::Create(content::WebContents::CreateParams(
context, content::SiteInstance::CreateForURL(context, url))));
Observe(web_contents());
web_contents_->GetMutableRendererPrefs()
->browser_handles_all_top_level_requests = true;
web_contents_->GetRenderViewHost()->SyncRendererPrefs();
// This observer will activate the extension when it is navigated to, which
// allows Dispatcher to give it the proper context and makes it behave like an
// extension.
extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
web_contents());
web_contents_->GetController().LoadURL(url,
content::Referrer(),
content::PAGE_TRANSITION_AUTO_TOPLEVEL,
std::string());
}
bool CustomLauncherPageContents::OnMessageReceived(
const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(CustomLauncherPageContents, message)
IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
extensions::WindowController*
CustomLauncherPageContents::GetExtensionWindowController() const {
return NULL;
}
content::WebContents* CustomLauncherPageContents::GetAssociatedWebContents()
const {
return web_contents();
}
void CustomLauncherPageContents::OnRequest(
const ExtensionHostMsg_Request_Params& params) {
extension_function_dispatcher_->Dispatch(params,
web_contents_->GetRenderViewHost());
}
} // namespace apps
// Copyright 2014 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 APPS_CUSTOM_LAUNCHER_PAGE_CONTENTS_H_
#define APPS_CUSTOM_LAUNCHER_PAGE_CONTENTS_H_
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/web_contents_observer.h"
#include "extensions/browser/extension_function_dispatcher.h"
class GURL;
namespace content {
class BrowserContext;
}
namespace apps {
// Manages the web contents for extension-hosted launcher pages. The
// implementation for this class should create and maintain the WebContents for
// the page, and handle any message passing between the web contents and the
// extension system.
class CustomLauncherPageContents
: public content::WebContentsObserver,
public extensions::ExtensionFunctionDispatcher::Delegate {
public:
CustomLauncherPageContents();
virtual ~CustomLauncherPageContents();
// Called to initialize and load the WebContents.
void Initialize(content::BrowserContext* context, const GURL& url);
content::WebContents* web_contents() const { return web_contents_.get(); }
private:
// content::WebContentsObserver overrides:
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
// extensions::ExtensionFunctionDispatcher::Delegate overrides:
virtual extensions::WindowController* GetExtensionWindowController()
const OVERRIDE;
virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE;
void OnRequest(const ExtensionHostMsg_Request_Params& params);
scoped_ptr<content::WebContents> web_contents_;
scoped_ptr<extensions::ExtensionFunctionDispatcher>
extension_function_dispatcher_;
DISALLOW_COPY_AND_ASSIGN(CustomLauncherPageContents);
};
} // namespace apps
#endif // APPS_CUSTOM_LAUNCHER_PAGE_CONTENTS_H_
......@@ -6,6 +6,7 @@
#include <vector>
#include "apps/custom_launcher_page_contents.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
......@@ -162,13 +163,8 @@ AppListViewDelegate::AppListViewDelegate(Profile* profile,
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());
custom_page_contents_.reset(new apps::CustomLauncherPageContents());
custom_page_contents_->Initialize(profile, custom_launcher_page_url);
}
}
}
......@@ -472,6 +468,7 @@ views::View* AppListViewDelegate::CreateStartPageWebView(
if (!web_contents)
return NULL;
DCHECK_EQ(profile_, web_contents->GetBrowserContext());
views::WebView* web_view = new views::WebView(
web_contents->GetBrowserContext());
web_view->SetPreferredSize(size);
......@@ -481,13 +478,16 @@ views::View* AppListViewDelegate::CreateStartPageWebView(
views::View* AppListViewDelegate::CreateCustomPageWebView(
const gfx::Size& size) {
if (!custom_page_web_contents_)
if (!custom_page_contents_)
return NULL;
views::WebView* web_view = new views::WebView(
custom_page_web_contents_->GetBrowserContext());
content::WebContents* web_contents = custom_page_contents_->web_contents();
// TODO(mgiuca): DCHECK_EQ(profile_, web_contents->GetBrowserContext()) after
// http://crbug.com/392763 resolved.
views::WebView* web_view =
new views::WebView(web_contents->GetBrowserContext());
web_view->SetPreferredSize(size);
web_view->SetWebContents(custom_page_web_contents_.get());
web_view->SetWebContents(web_contents);
return web_view;
}
#endif
......
......@@ -23,6 +23,10 @@
class AppListControllerDelegate;
class Profile;
namespace apps {
class CustomLauncherPageContents;
}
namespace app_list {
class SearchController;
class SpeechUIModel;
......@@ -32,10 +36,6 @@ namespace base {
class FilePath;
}
namespace content {
class WebContents;
}
namespace gfx {
class ImageSkia;
}
......@@ -154,8 +154,8 @@ 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_;
// Window contents of the additional custom launcher page. May be NULL.
scoped_ptr<apps::CustomLauncherPageContents> custom_page_contents_;
DISALLOW_COPY_AND_ASSIGN(AppListViewDelegate);
};
......
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