OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" | 5 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "apps/custom_launcher_page_contents.h" | 9 #include "apps/custom_launcher_page_contents.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 #include "chrome/browser/ui/app_list/search/search_controller_factory.h" | 26 #include "chrome/browser/ui/app_list/search/search_controller_factory.h" |
27 #include "chrome/browser/ui/app_list/search/search_resource_manager.h" | 27 #include "chrome/browser/ui/app_list/search/search_resource_manager.h" |
28 #include "chrome/browser/ui/app_list/start_page_service.h" | 28 #include "chrome/browser/ui/app_list/start_page_service.h" |
29 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 29 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
30 #include "chrome/browser/ui/browser_finder.h" | 30 #include "chrome/browser/ui/browser_finder.h" |
31 #include "chrome/browser/ui/chrome_pages.h" | 31 #include "chrome/browser/ui/chrome_pages.h" |
32 #include "chrome/browser/ui/host_desktop.h" | 32 #include "chrome/browser/ui/host_desktop.h" |
33 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 33 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
34 #include "chrome/browser/web_applications/web_app.h" | 34 #include "chrome/browser/web_applications/web_app.h" |
35 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
36 #include "chrome/common/extensions/api/launcher_page_private.h" | |
36 #include "chrome/common/extensions/extension_constants.h" | 37 #include "chrome/common/extensions/extension_constants.h" |
37 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
38 #include "components/signin/core/browser/signin_manager.h" | 39 #include "components/signin/core/browser/signin_manager.h" |
39 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
40 #include "content/public/browser/notification_service.h" | 41 #include "content/public/browser/notification_service.h" |
41 #include "content/public/browser/page_navigator.h" | 42 #include "content/public/browser/page_navigator.h" |
42 #include "content/public/browser/user_metrics.h" | 43 #include "content/public/browser/user_metrics.h" |
43 #include "content/public/browser/web_contents.h" | 44 #include "content/public/browser/web_contents.h" |
45 #include "extensions/browser/event_router.h" | |
44 #include "extensions/browser/extension_registry.h" | 46 #include "extensions/browser/extension_registry.h" |
45 #include "extensions/common/constants.h" | 47 #include "extensions/common/constants.h" |
46 #include "extensions/common/extension_set.h" | 48 #include "extensions/common/extension_set.h" |
47 #include "extensions/common/manifest_constants.h" | 49 #include "extensions/common/manifest_constants.h" |
48 #include "extensions/common/manifest_handlers/launcher_page_info.h" | 50 #include "extensions/common/manifest_handlers/launcher_page_info.h" |
49 #include "grit/theme_resources.h" | 51 #include "grit/theme_resources.h" |
52 #include "ui/app_list/app_list_model_observer.h" | |
50 #include "ui/app_list/app_list_switches.h" | 53 #include "ui/app_list/app_list_switches.h" |
51 #include "ui/app_list/app_list_view_delegate_observer.h" | 54 #include "ui/app_list/app_list_view_delegate_observer.h" |
52 #include "ui/app_list/search_box_model.h" | 55 #include "ui/app_list/search_box_model.h" |
53 #include "ui/app_list/search_controller.h" | 56 #include "ui/app_list/search_controller.h" |
54 #include "ui/app_list/speech_ui_model.h" | 57 #include "ui/app_list/speech_ui_model.h" |
55 #include "ui/base/resource/resource_bundle.h" | 58 #include "ui/base/resource/resource_bundle.h" |
56 #include "ui/views/controls/webview/webview.h" | 59 #include "ui/views/controls/webview/webview.h" |
57 | 60 |
58 #if defined(TOOLKIT_VIEWS) | 61 #if defined(TOOLKIT_VIEWS) |
59 #include "ui/views/controls/webview/webview.h" | 62 #include "ui/views/controls/webview/webview.h" |
60 #endif | 63 #endif |
61 | 64 |
62 #if defined(USE_AURA) | 65 #if defined(USE_AURA) |
63 #include "ui/keyboard/keyboard_util.h" | 66 #include "ui/keyboard/keyboard_util.h" |
64 #endif | 67 #endif |
65 | 68 |
66 #if defined(USE_ASH) | 69 #if defined(USE_ASH) |
67 #include "ash/shell.h" | 70 #include "ash/shell.h" |
68 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 71 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
69 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" | 72 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" |
70 #endif | 73 #endif |
71 | 74 |
72 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
73 #include "chrome/browser/web_applications/web_app_win.h" | 76 #include "chrome/browser/web_applications/web_app_win.h" |
74 #endif | 77 #endif |
75 | 78 |
79 namespace OnPageExpand = extensions::api::launcher_page_private::OnPageExpand; | |
80 namespace OnPageCollapse = | |
81 extensions::api::launcher_page_private::OnPageCollapse; | |
76 | 82 |
77 namespace chrome { | 83 namespace chrome { |
78 const char kAppLauncherCategoryTag[] = "AppLauncher"; | 84 const char kAppLauncherCategoryTag[] = "AppLauncher"; |
79 } // namespace chrome | 85 } // namespace chrome |
80 | 86 |
81 namespace { | 87 namespace { |
82 | 88 |
83 const int kAutoLaunchDefaultTimeoutMilliSec = 50; | 89 const int kAutoLaunchDefaultTimeoutMilliSec = 50; |
84 | 90 |
85 #if defined(OS_WIN) | 91 #if defined(OS_WIN) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 extensions::LauncherPageHandler::GetInfo(extension); | 149 extensions::LauncherPageHandler::GetInfo(extension); |
144 if (!info) | 150 if (!info) |
145 continue; | 151 continue; |
146 | 152 |
147 urls->push_back(extension->GetResourceURL(info->page)); | 153 urls->push_back(extension->GetResourceURL(info->page)); |
148 } | 154 } |
149 } | 155 } |
150 | 156 |
151 } // namespace | 157 } // namespace |
152 | 158 |
159 // A class which observes the AppListModel and sends events to the custom | |
160 // launcher page. | |
161 class AppListViewDelegate::LauncherPageEventDispatcher | |
162 : public app_list::AppListModelObserver { | |
163 public: | |
164 LauncherPageEventDispatcher(Profile* profile, const std::string& extension_id) | |
165 : profile_(profile), extension_id_(extension_id) {} | |
166 | |
167 ~LauncherPageEventDispatcher() override {} | |
168 | |
169 // 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
| |
170 void OnAppListModelStateChanged( | |
171 app_list::AppListModel::State old_state, | |
172 app_list::AppListModel::State new_state) override { | |
173 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.
| |
174 scoped_ptr<extensions::Event> event(new extensions::Event( | |
175 OnPageExpand::kEventName, OnPageExpand::Create())); | |
176 extensions::EventRouter::Get(profile_) | |
177 ->DispatchEventToExtension(extension_id_, event.Pass()); | |
178 } else if (old_state == | |
179 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.
| |
180 scoped_ptr<extensions::Event> event(new extensions::Event( | |
181 OnPageCollapse::kEventName, OnPageCollapse::Create())); | |
182 extensions::EventRouter::Get(profile_) | |
183 ->DispatchEventToExtension(extension_id_, event.Pass()); | |
184 } | |
185 }; | |
186 | |
187 private: | |
188 Profile* profile_; | |
189 std::string extension_id_; | |
190 | |
191 DISALLOW_COPY_AND_ASSIGN(LauncherPageEventDispatcher); | |
192 }; | |
193 | |
153 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller) | 194 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller) |
154 : controller_(controller), | 195 : controller_(controller), |
155 profile_(NULL), | 196 profile_(NULL), |
156 model_(NULL), | 197 model_(NULL), |
157 scoped_observer_(this) { | 198 scoped_observer_(this) { |
158 CHECK(controller_); | 199 CHECK(controller_); |
159 // The SigninManagerFactor and the SigninManagers are observed to keep the | 200 // The SigninManagerFactor and the SigninManagers are observed to keep the |
160 // profile switcher menu up to date, with the correct list of profiles and the | 201 // profile switcher menu up to date, with the correct list of profiles and the |
161 // correct email address (or none for signed out users) for each. | 202 // correct email address (or none for signed out users) for each. |
162 SigninManagerFactory::GetInstance()->AddObserver(this); | 203 SigninManagerFactory::GetInstance()->AddObserver(this); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 | 240 |
200 SigninManagerFactory* factory = SigninManagerFactory::GetInstance(); | 241 SigninManagerFactory* factory = SigninManagerFactory::GetInstance(); |
201 if (factory) | 242 if (factory) |
202 factory->RemoveObserver(this); | 243 factory->RemoveObserver(this); |
203 } | 244 } |
204 | 245 |
205 void AppListViewDelegate::SetProfile(Profile* new_profile) { | 246 void AppListViewDelegate::SetProfile(Profile* new_profile) { |
206 if (profile_ == new_profile) | 247 if (profile_ == new_profile) |
207 return; | 248 return; |
208 | 249 |
250 if (model_ && launcher_page_event_dispatcher_) | |
251 model_->RemoveObserver(launcher_page_event_dispatcher_.get()); | |
252 | |
209 if (profile_) { | 253 if (profile_) { |
210 // Note: |search_resource_manager_| has a reference to |speech_ui_| so must | 254 // Note: |search_resource_manager_| has a reference to |speech_ui_| so must |
211 // be destroyed first. | 255 // be destroyed first. |
212 search_resource_manager_.reset(); | 256 search_resource_manager_.reset(); |
213 search_controller_.reset(); | 257 search_controller_.reset(); |
214 custom_page_contents_.clear(); | 258 custom_page_contents_.clear(); |
215 app_list::StartPageService* start_page_service = | 259 app_list::StartPageService* start_page_service = |
216 app_list::StartPageService::Get(profile_); | 260 app_list::StartPageService::Get(profile_); |
217 if (start_page_service) | 261 if (start_page_service) |
218 start_page_service->RemoveObserver(this); | 262 start_page_service->RemoveObserver(this); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 profile_->GetPath(), | 323 profile_->GetPath(), |
280 &users_); | 324 &users_); |
281 | 325 |
282 FOR_EACH_OBSERVER( | 326 FOR_EACH_OBSERVER( |
283 app_list::AppListViewDelegateObserver, observers_, OnProfilesChanged()); | 327 app_list::AppListViewDelegateObserver, observers_, OnProfilesChanged()); |
284 } | 328 } |
285 | 329 |
286 void AppListViewDelegate::SetUpCustomLauncherPages() { | 330 void AppListViewDelegate::SetUpCustomLauncherPages() { |
287 std::vector<GURL> custom_launcher_page_urls; | 331 std::vector<GURL> custom_launcher_page_urls; |
288 GetCustomLauncherPageUrls(profile_, &custom_launcher_page_urls); | 332 GetCustomLauncherPageUrls(profile_, &custom_launcher_page_urls); |
333 | |
334 // Only the first custom launcher page gets events dispatched to it. | |
335 if (!custom_launcher_page_urls.empty()) { | |
336 launcher_page_event_dispatcher_.reset(new LauncherPageEventDispatcher( | |
337 profile_, custom_launcher_page_urls[0].host())); | |
338 model_->AddObserver(launcher_page_event_dispatcher_.get()); | |
339 } | |
340 | |
289 for (std::vector<GURL>::const_iterator it = custom_launcher_page_urls.begin(); | 341 for (std::vector<GURL>::const_iterator it = custom_launcher_page_urls.begin(); |
290 it != custom_launcher_page_urls.end(); | 342 it != custom_launcher_page_urls.end(); |
291 ++it) { | 343 ++it) { |
292 std::string extension_id = it->host(); | 344 std::string extension_id = it->host(); |
293 apps::CustomLauncherPageContents* page_contents = | 345 apps::CustomLauncherPageContents* page_contents = |
294 new apps::CustomLauncherPageContents( | 346 new apps::CustomLauncherPageContents( |
295 scoped_ptr<extensions::AppDelegate>( | 347 scoped_ptr<extensions::AppDelegate>( |
296 new ChromeAppDelegate(scoped_ptr<ScopedKeepAlive>())), | 348 new ChromeAppDelegate(scoped_ptr<ScopedKeepAlive>())), |
297 extension_id); | 349 extension_id); |
298 page_contents->Initialize(profile_, *it); | 350 page_contents->Initialize(profile_, *it); |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
695 | 747 |
696 // SigninManagerFactory is not a leaky singleton (unlike this class), and | 748 // SigninManagerFactory is not a leaky singleton (unlike this class), and |
697 // its destructor will check that it has no remaining observers. | 749 // its destructor will check that it has no remaining observers. |
698 scoped_observer_.RemoveAll(); | 750 scoped_observer_.RemoveAll(); |
699 SigninManagerFactory::GetInstance()->RemoveObserver(this); | 751 SigninManagerFactory::GetInstance()->RemoveObserver(this); |
700 break; | 752 break; |
701 default: | 753 default: |
702 NOTREACHED(); | 754 NOTREACHED(); |
703 } | 755 } |
704 } | 756 } |
OLD | NEW |