Index: chrome/browser/ui/app_list/app_list_view_delegate.cc |
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 c62666cc116babbc1ed5d7f09be697a07e711aad..bad6dc29cf20bdbe01e121e50664b579874e80be 100644 |
--- a/chrome/browser/ui/app_list/app_list_view_delegate.cc |
+++ b/chrome/browser/ui/app_list/app_list_view_delegate.cc |
@@ -33,6 +33,7 @@ |
#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/api/launcher_page_private.h" |
#include "chrome/common/extensions/extension_constants.h" |
#include "chrome/common/url_constants.h" |
#include "components/signin/core/browser/signin_manager.h" |
@@ -41,12 +42,14 @@ |
#include "content/public/browser/page_navigator.h" |
#include "content/public/browser/user_metrics.h" |
#include "content/public/browser/web_contents.h" |
+#include "extensions/browser/event_router.h" |
#include "extensions/browser/extension_registry.h" |
#include "extensions/common/constants.h" |
#include "extensions/common/extension_set.h" |
#include "extensions/common/manifest_constants.h" |
#include "extensions/common/manifest_handlers/launcher_page_info.h" |
#include "grit/theme_resources.h" |
+#include "ui/app_list/app_list_model_observer.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" |
@@ -73,6 +76,9 @@ |
#include "chrome/browser/web_applications/web_app_win.h" |
#endif |
+namespace OnPageExpand = extensions::api::launcher_page_private::OnPageExpand; |
+namespace OnPageCollapse = |
+ extensions::api::launcher_page_private::OnPageCollapse; |
namespace chrome { |
const char kAppLauncherCategoryTag[] = "AppLauncher"; |
@@ -150,6 +156,41 @@ void GetCustomLauncherPageUrls(content::BrowserContext* browser_context, |
} // namespace |
+// A class which observes the AppListModel and sends events to the custom |
+// launcher page. |
+class AppListViewDelegate::LauncherPageEventDispatcher |
+ : public app_list::AppListModelObserver { |
+ public: |
+ LauncherPageEventDispatcher(Profile* profile, const std::string& extension_id) |
+ : profile_(profile), extension_id_(extension_id) {} |
+ |
+ ~LauncherPageEventDispatcher() override {} |
+ |
+ // Overridden from app_list::AppListModelObserver: |
Matt Giuca
2014/10/28 05:41:22
Nit: overrides ;)
calamity
2014/10/28 06:34:21
git grep '// Overridden from ' | wc -l
1770
git g
|
+ void OnAppListModelStateChanged( |
+ app_list::AppListModel::State old_state, |
+ app_list::AppListModel::State new_state) override { |
+ if (new_state == app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE) { |
Matt Giuca
2014/10/28 05:41:22
// If transitioning to the custom launcher page, s
calamity
2014/10/28 06:34:21
Done.
|
+ scoped_ptr<extensions::Event> event(new extensions::Event( |
+ OnPageExpand::kEventName, OnPageExpand::Create())); |
+ extensions::EventRouter::Get(profile_) |
+ ->DispatchEventToExtension(extension_id_, event.Pass()); |
+ } else if (old_state == |
+ app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE) { |
Matt Giuca
2014/10/28 05:41:22
// If transitioning from the custom launcher page,
calamity
2014/10/28 06:34:21
Done.
|
+ scoped_ptr<extensions::Event> event(new extensions::Event( |
+ OnPageCollapse::kEventName, OnPageCollapse::Create())); |
+ extensions::EventRouter::Get(profile_) |
+ ->DispatchEventToExtension(extension_id_, event.Pass()); |
+ } |
+ }; |
+ |
+ private: |
+ Profile* profile_; |
+ std::string extension_id_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(LauncherPageEventDispatcher); |
+}; |
+ |
AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller) |
: controller_(controller), |
profile_(NULL), |
@@ -206,6 +247,9 @@ void AppListViewDelegate::SetProfile(Profile* new_profile) { |
if (profile_ == new_profile) |
return; |
+ if (model_ && launcher_page_event_dispatcher_) |
+ model_->RemoveObserver(launcher_page_event_dispatcher_.get()); |
+ |
if (profile_) { |
// Note: |search_resource_manager_| has a reference to |speech_ui_| so must |
// be destroyed first. |
@@ -286,6 +330,14 @@ void AppListViewDelegate::SetUpProfileSwitcher() { |
void AppListViewDelegate::SetUpCustomLauncherPages() { |
std::vector<GURL> custom_launcher_page_urls; |
GetCustomLauncherPageUrls(profile_, &custom_launcher_page_urls); |
+ |
+ // Only the first custom launcher page gets events dispatched to it. |
+ if (!custom_launcher_page_urls.empty()) { |
+ launcher_page_event_dispatcher_.reset(new LauncherPageEventDispatcher( |
+ profile_, custom_launcher_page_urls[0].host())); |
+ model_->AddObserver(launcher_page_event_dispatcher_.get()); |
+ } |
+ |
for (std::vector<GURL>::const_iterator it = custom_launcher_page_urls.begin(); |
it != custom_launcher_page_urls.end(); |
++it) { |