summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/apps.gypi2
-rw-r--r--apps/custom_launcher_page_contents.cc76
-rw-r--r--apps/custom_launcher_page_contents.h56
-rw-r--r--chrome/browser/ui/app_list/app_list_view_delegate.cc22
-rw-r--r--chrome/browser/ui/app_list/app_list_view_delegate.h12
5 files changed, 151 insertions, 17 deletions
diff --git a/apps/apps.gypi b/apps/apps.gypi
index f52151a..b5fd397 100644
--- a/apps/apps.gypi
+++ b/apps/apps.gypi
@@ -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',
diff --git a/apps/custom_launcher_page_contents.cc b/apps/custom_launcher_page_contents.cc
new file mode 100644
index 0000000..896d9da
--- /dev/null
+++ b/apps/custom_launcher_page_contents.cc
@@ -0,0 +1,76 @@
+// 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
diff --git a/apps/custom_launcher_page_contents.h b/apps/custom_launcher_page_contents.h
new file mode 100644
index 0000000..964a44d
--- /dev/null
+++ b/apps/custom_launcher_page_contents.h
@@ -0,0 +1,56 @@
+// 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_
diff --git a/chrome/browser/ui/app_list/app_list_view_delegate.cc b/chrome/browser/ui/app_list/app_list_view_delegate.cc
index 6c2bf69..c813ca9 100644
--- a/chrome/browser/ui/app_list/app_list_view_delegate.cc
+++ b/chrome/browser/ui/app_list/app_list_view_delegate.cc
@@ -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
diff --git a/chrome/browser/ui/app_list/app_list_view_delegate.h b/chrome/browser/ui/app_list/app_list_view_delegate.h
index b5dba63..31899f9 100644
--- a/chrome/browser/ui/app_list/app_list_view_delegate.h
+++ b/chrome/browser/ui/app_list/app_list_view_delegate.h
@@ -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);
};