| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | |
| 12 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | |
| 14 #include "base/metrics/user_metrics.h" | 12 #include "base/metrics/user_metrics.h" |
| 15 #include "base/profiler/scoped_tracker.h" | 13 #include "base/profiler/scoped_tracker.h" |
| 16 #include "base/stl_util.h" | |
| 17 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 18 #include "chrome/browser/browser_process.h" | |
| 19 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 20 #include "chrome/browser/lifetime/scoped_keep_alive.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/profiles/profile_attributes_entry.h" | |
| 22 #include "chrome/browser/profiles/profile_attributes_storage.h" | |
| 23 #include "chrome/browser/profiles/profile_manager.h" | |
| 24 #include "chrome/browser/search/hotword_service.h" | 17 #include "chrome/browser/search/hotword_service.h" |
| 25 #include "chrome/browser/search/hotword_service_factory.h" | 18 #include "chrome/browser/search/hotword_service_factory.h" |
| 26 #include "chrome/browser/search_engines/template_url_service_factory.h" | 19 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 27 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 20 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| 28 #include "chrome/browser/ui/app_list/app_list_service.h" | |
| 29 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" | 21 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
| 30 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 22 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
| 31 #include "chrome/browser/ui/app_list/custom_launcher_page_contents.h" | 23 #include "chrome/browser/ui/app_list/custom_launcher_page_contents.h" |
| 32 #include "chrome/browser/ui/app_list/launcher_page_event_dispatcher.h" | 24 #include "chrome/browser/ui/app_list/launcher_page_event_dispatcher.h" |
| 33 #include "chrome/browser/ui/app_list/search/search_controller_factory.h" | 25 #include "chrome/browser/ui/app_list/search/search_controller_factory.h" |
| 34 #include "chrome/browser/ui/app_list/search/search_resource_manager.h" | 26 #include "chrome/browser/ui/app_list/search/search_resource_manager.h" |
| 35 #include "chrome/browser/ui/app_list/start_page_service.h" | 27 #include "chrome/browser/ui/app_list/start_page_service.h" |
| 36 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 28 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
| 37 #include "chrome/browser/ui/browser_finder.h" | 29 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" |
| 38 #include "chrome/browser/ui/chrome_pages.h" | 30 #include "chrome/browser/ui/chrome_pages.h" |
| 39 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | |
| 40 #include "chrome/browser/web_applications/web_app.h" | |
| 41 #include "chrome/common/chrome_switches.h" | |
| 42 #include "chrome/common/extensions/extension_constants.h" | |
| 43 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 44 #include "chrome/common/url_constants.h" | |
| 45 #include "chrome/grit/theme_resources.h" | 32 #include "chrome/grit/theme_resources.h" |
| 46 #include "components/prefs/pref_service.h" | 33 #include "components/prefs/pref_service.h" |
| 47 #include "components/signin/core/browser/signin_manager.h" | |
| 48 #include "components/user_prefs/user_prefs.h" | 34 #include "components/user_prefs/user_prefs.h" |
| 49 #include "content/public/browser/browser_thread.h" | |
| 50 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 51 #include "content/public/browser/page_navigator.h" | |
| 52 #include "content/public/browser/render_view_host.h" | 36 #include "content/public/browser/render_view_host.h" |
| 53 #include "content/public/browser/render_widget_host.h" | 37 #include "content/public/browser/render_widget_host.h" |
| 54 #include "content/public/browser/render_widget_host_view.h" | 38 #include "content/public/browser/render_widget_host_view.h" |
| 55 #include "content/public/browser/speech_recognition_session_preamble.h" | 39 #include "content/public/browser/speech_recognition_session_preamble.h" |
| 56 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 57 #include "extensions/browser/extension_registry.h" | 41 #include "extensions/browser/extension_registry.h" |
| 58 #include "extensions/common/constants.h" | 42 #include "extensions/common/constants.h" |
| 59 #include "extensions/common/extension_set.h" | 43 #include "extensions/common/extension_set.h" |
| 60 #include "extensions/common/manifest_constants.h" | 44 #include "extensions/common/manifest_constants.h" |
| 61 #include "extensions/common/manifest_handlers/launcher_page_info.h" | 45 #include "extensions/common/manifest_handlers/launcher_page_info.h" |
| 62 #include "ui/app_list/app_list_switches.h" | 46 #include "ui/app_list/app_list_switches.h" |
| 63 #include "ui/app_list/search_box_model.h" | 47 #include "ui/app_list/search_box_model.h" |
| 64 #include "ui/app_list/search_controller.h" | 48 #include "ui/app_list/search_controller.h" |
| 65 #include "ui/app_list/speech_ui_model.h" | 49 #include "ui/app_list/speech_ui_model.h" |
| 66 #include "ui/base/resource/resource_bundle.h" | 50 #include "ui/base/resource/resource_bundle.h" |
| 51 #include "ui/keyboard/keyboard_util.h" |
| 67 #include "ui/views/controls/webview/webview.h" | 52 #include "ui/views/controls/webview/webview.h" |
| 68 | 53 |
| 69 #if defined(USE_AURA) | |
| 70 #include "ui/keyboard/keyboard_util.h" | |
| 71 #endif | |
| 72 | |
| 73 #if defined(USE_ASH) | |
| 74 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" | |
| 75 #endif | |
| 76 | |
| 77 namespace chrome { | |
| 78 const char kAppLauncherCategoryTag[] = "AppLauncher"; | |
| 79 } // namespace chrome | |
| 80 | |
| 81 namespace { | 54 namespace { |
| 82 | 55 |
| 83 const int kAutoLaunchDefaultTimeoutMilliSec = 50; | 56 const int kAutoLaunchDefaultTimeoutMilliSec = 50; |
| 84 | 57 |
| 85 void PopulateUsers(const base::FilePath& active_profile_path, | |
| 86 app_list::AppListViewDelegate::Users* users) { | |
| 87 users->clear(); | |
| 88 std::vector<ProfileAttributesEntry*> entries = g_browser_process-> | |
| 89 profile_manager()->GetProfileAttributesStorage(). | |
| 90 GetAllProfilesAttributesSortedByName(); | |
| 91 for (const auto* entry : entries) { | |
| 92 app_list::AppListViewDelegate::User user; | |
| 93 user.name = entry->GetName(); | |
| 94 user.email = entry->GetUserName(); | |
| 95 user.profile_path = entry->GetPath(); | |
| 96 user.active = active_profile_path == user.profile_path; | |
| 97 users->push_back(user); | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 // Gets a list of URLs of the custom launcher pages to show in the launcher. | 58 // Gets a list of URLs of the custom launcher pages to show in the launcher. |
| 102 // Returns a URL for each installed launcher page. If --custom-launcher-page is | 59 // Returns a URL for each installed launcher page. If --custom-launcher-page is |
| 103 // specified and valid, also includes that URL. | 60 // specified and valid, also includes that URL. |
| 104 void GetCustomLauncherPageUrls(content::BrowserContext* browser_context, | 61 void GetCustomLauncherPageUrls(content::BrowserContext* browser_context, |
| 105 std::vector<GURL>* urls) { | 62 std::vector<GURL>* urls) { |
| 106 // First, check the command line. | 63 // First, check the command line. |
| 107 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 64 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 108 if (command_line->HasSwitch(app_list::switches::kCustomLauncherPage)) { | 65 if (command_line->HasSwitch(app_list::switches::kCustomLauncherPage)) { |
| 109 GURL custom_launcher_page_url(command_line->GetSwitchValueASCII( | 66 GURL custom_launcher_page_url(command_line->GetSwitchValueASCII( |
| 110 app_list::switches::kCustomLauncherPage)); | 67 app_list::switches::kCustomLauncherPage)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 101 } |
| 145 } | 102 } |
| 146 | 103 |
| 147 } // namespace | 104 } // namespace |
| 148 | 105 |
| 149 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller) | 106 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller) |
| 150 : controller_(controller), | 107 : controller_(controller), |
| 151 profile_(NULL), | 108 profile_(NULL), |
| 152 model_(NULL), | 109 model_(NULL), |
| 153 is_voice_query_(false), | 110 is_voice_query_(false), |
| 154 template_url_service_observer_(this), | 111 template_url_service_observer_(this) { |
| 155 scoped_observer_(this) { | |
| 156 CHECK(controller_); | 112 CHECK(controller_); |
| 157 // The SigninManagerFactor and the SigninManagers are observed to keep the | |
| 158 // profile switcher menu up to date, with the correct list of profiles and the | |
| 159 // correct email address (or none for signed out users) for each. | |
| 160 SigninManagerFactory::GetInstance()->AddObserver(this); | |
| 161 | |
| 162 // Start observing all already-created SigninManagers. | |
| 163 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 164 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); | |
| 165 | |
| 166 for (std::vector<Profile*>::iterator i = profiles.begin(); | |
| 167 i != profiles.end(); | |
| 168 ++i) { | |
| 169 SigninManagerBase* manager = | |
| 170 SigninManagerFactory::GetForProfileIfExists(*i); | |
| 171 if (manager) { | |
| 172 DCHECK(!scoped_observer_.IsObserving(manager)); | |
| 173 scoped_observer_.Add(manager); | |
| 174 } | |
| 175 } | |
| 176 | |
| 177 profile_manager->GetProfileAttributesStorage().AddObserver(this); | |
| 178 speech_ui_.reset(new app_list::SpeechUIModel); | 113 speech_ui_.reset(new app_list::SpeechUIModel); |
| 179 | 114 |
| 180 #if defined(GOOGLE_CHROME_BUILD) | 115 #if defined(GOOGLE_CHROME_BUILD) |
| 181 gfx::ImageSkia* image; | 116 gfx::ImageSkia* image; |
| 182 { | 117 { |
| 183 // TODO(tapted): Remove ScopedTracker below once crbug.com/431326 is fixed. | 118 // TODO(tapted): Remove ScopedTracker below once crbug.com/431326 is fixed. |
| 184 tracked_objects::ScopedTracker tracking_profile( | 119 tracked_objects::ScopedTracker tracking_profile( |
| 185 FROM_HERE_WITH_EXPLICIT_FUNCTION("431326 GetImageSkiaNamed()")); | 120 FROM_HERE_WITH_EXPLICIT_FUNCTION("431326 GetImageSkiaNamed()")); |
| 186 image = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 121 image = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 187 IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH); | 122 IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH); |
| 188 } | 123 } |
| 189 | 124 |
| 190 speech_ui_->set_logo(*image); | 125 speech_ui_->set_logo(*image); |
| 191 #endif | 126 #endif |
| 192 | 127 |
| 193 registrar_.Add(this, | 128 registrar_.Add(this, |
| 194 chrome::NOTIFICATION_APP_TERMINATING, | 129 chrome::NOTIFICATION_APP_TERMINATING, |
| 195 content::NotificationService::AllSources()); | 130 content::NotificationService::AllSources()); |
| 196 } | 131 } |
| 197 | 132 |
| 198 AppListViewDelegate::~AppListViewDelegate() { | 133 AppListViewDelegate::~AppListViewDelegate() { |
| 199 // Note that the destructor is not always called. E.g. on Mac, this is owned | 134 // The destructor might not be called since the delegate is owned by a leaky |
| 200 // by a leaky singleton. Essential shutdown work must be done by observing | 135 // singleton. This matches the shutdown work done in Observe() in response to |
| 201 // chrome::NOTIFICATION_APP_TERMINATING. | 136 // chrome::NOTIFICATION_APP_TERMINATING, which may happen before this. |
| 202 SetProfile(NULL); | 137 SetProfile(nullptr); |
| 203 g_browser_process->profile_manager()->GetProfileAttributesStorage(). | |
| 204 RemoveObserver(this); | |
| 205 | |
| 206 SigninManagerFactory* factory = SigninManagerFactory::GetInstance(); | |
| 207 if (factory) | |
| 208 factory->RemoveObserver(this); | |
| 209 } | 138 } |
| 210 | 139 |
| 211 void AppListViewDelegate::SetProfile(Profile* new_profile) { | 140 void AppListViewDelegate::SetProfile(Profile* new_profile) { |
| 212 if (profile_ == new_profile) | 141 if (profile_ == new_profile) |
| 213 return; | 142 return; |
| 214 | 143 |
| 215 if (profile_) { | 144 if (profile_) { |
| 216 // Note: |search_resource_manager_| has a reference to |speech_ui_| so must | 145 // Note: |search_resource_manager_| has a reference to |speech_ui_| so must |
| 217 // be destroyed first. | 146 // be destroyed first. |
| 218 search_resource_manager_.reset(); | 147 search_resource_manager_.reset(); |
| 219 search_controller_.reset(); | 148 search_controller_.reset(); |
| 220 launcher_page_event_dispatcher_.reset(); | 149 launcher_page_event_dispatcher_.reset(); |
| 221 custom_page_contents_.clear(); | 150 custom_page_contents_.clear(); |
| 222 app_list::StartPageService* start_page_service = | 151 app_list::StartPageService* start_page_service = |
| 223 app_list::StartPageService::Get(profile_); | 152 app_list::StartPageService::Get(profile_); |
| 224 if (start_page_service) | 153 if (start_page_service) |
| 225 start_page_service->RemoveObserver(this); | 154 start_page_service->RemoveObserver(this); |
| 226 #if defined(USE_ASH) | |
| 227 app_sync_ui_state_watcher_.reset(); | 155 app_sync_ui_state_watcher_.reset(); |
| 228 #endif | |
| 229 model_ = NULL; | 156 model_ = NULL; |
| 230 } | 157 } |
| 231 | 158 |
| 232 template_url_service_observer_.RemoveAll(); | 159 template_url_service_observer_.RemoveAll(); |
| 233 | 160 |
| 234 profile_ = new_profile; | 161 profile_ = new_profile; |
| 235 if (!profile_) { | 162 if (!profile_) { |
| 236 speech_ui_->SetSpeechRecognitionState(app_list::SPEECH_RECOGNITION_OFF, | 163 speech_ui_->SetSpeechRecognitionState(app_list::SPEECH_RECOGNITION_OFF, |
| 237 false); | 164 false); |
| 238 return; | 165 return; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 250 tracked_objects::ScopedTracker tracking_profile( | 177 tracked_objects::ScopedTracker tracking_profile( |
| 251 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 178 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 252 "431326 AppListViewDelegate TemplateURL etc.")); | 179 "431326 AppListViewDelegate TemplateURL etc.")); |
| 253 TemplateURLService* template_url_service = | 180 TemplateURLService* template_url_service = |
| 254 TemplateURLServiceFactory::GetForProfile(profile_); | 181 TemplateURLServiceFactory::GetForProfile(profile_); |
| 255 template_url_service_observer_.Add(template_url_service); | 182 template_url_service_observer_.Add(template_url_service); |
| 256 | 183 |
| 257 model_ = app_list::AppListSyncableServiceFactory::GetForProfile(profile_) | 184 model_ = app_list::AppListSyncableServiceFactory::GetForProfile(profile_) |
| 258 ->GetModel(); | 185 ->GetModel(); |
| 259 | 186 |
| 260 #if defined(USE_ASH) | |
| 261 app_sync_ui_state_watcher_.reset( | 187 app_sync_ui_state_watcher_.reset( |
| 262 new AppSyncUIStateWatcher(profile_, model_)); | 188 new AppSyncUIStateWatcher(profile_, model_)); |
| 263 #endif | |
| 264 | 189 |
| 265 SetUpSearchUI(); | 190 SetUpSearchUI(); |
| 266 SetUpProfileSwitcher(); | |
| 267 SetUpCustomLauncherPages(); | 191 SetUpCustomLauncherPages(); |
| 268 OnTemplateURLServiceChanged(); | 192 OnTemplateURLServiceChanged(); |
| 269 } | 193 } |
| 270 | 194 |
| 271 // Clear search query. | 195 // Clear search query. |
| 272 model_->search_box()->SetText(base::string16()); | 196 model_->search_box()->SetText(base::string16()); |
| 273 } | 197 } |
| 274 | 198 |
| 275 void AppListViewDelegate::SetUpSearchUI() { | 199 void AppListViewDelegate::SetUpSearchUI() { |
| 276 app_list::StartPageService* start_page_service = | 200 app_list::StartPageService* start_page_service = |
| 277 app_list::StartPageService::Get(profile_); | 201 app_list::StartPageService::Get(profile_); |
| 278 if (start_page_service) | 202 if (start_page_service) |
| 279 start_page_service->AddObserver(this); | 203 start_page_service->AddObserver(this); |
| 280 | 204 |
| 281 speech_ui_->SetSpeechRecognitionState(start_page_service | 205 speech_ui_->SetSpeechRecognitionState(start_page_service |
| 282 ? start_page_service->state() | 206 ? start_page_service->state() |
| 283 : app_list::SPEECH_RECOGNITION_OFF, | 207 : app_list::SPEECH_RECOGNITION_OFF, |
| 284 false); | 208 false); |
| 285 | 209 |
| 286 search_resource_manager_.reset(new app_list::SearchResourceManager( | 210 search_resource_manager_.reset(new app_list::SearchResourceManager( |
| 287 profile_, | 211 profile_, |
| 288 model_->search_box(), | 212 model_->search_box(), |
| 289 speech_ui_.get())); | 213 speech_ui_.get())); |
| 290 | 214 |
| 291 search_controller_ = CreateSearchController(profile_, model_, controller_); | 215 search_controller_ = CreateSearchController(profile_, model_, controller_); |
| 292 } | 216 } |
| 293 | 217 |
| 294 void AppListViewDelegate::SetUpProfileSwitcher() { | |
| 295 // If a profile change is observed when there is no app list, there is nothing | |
| 296 // to update until SetProfile() calls this function again. | |
| 297 if (!profile_) | |
| 298 return; | |
| 299 | |
| 300 #if defined(USE_ASH) | |
| 301 // Don't populate the app list users if we are on the ash desktop. | |
| 302 return; | |
| 303 #endif // USE_ASH | |
| 304 | |
| 305 // Populate the app list users. | |
| 306 PopulateUsers(profile_->GetPath(), &users_); | |
| 307 } | |
| 308 | |
| 309 void AppListViewDelegate::SetUpCustomLauncherPages() { | 218 void AppListViewDelegate::SetUpCustomLauncherPages() { |
| 310 std::vector<GURL> custom_launcher_page_urls; | 219 std::vector<GURL> custom_launcher_page_urls; |
| 311 GetCustomLauncherPageUrls(profile_, &custom_launcher_page_urls); | 220 GetCustomLauncherPageUrls(profile_, &custom_launcher_page_urls); |
| 312 if (custom_launcher_page_urls.empty()) | 221 if (custom_launcher_page_urls.empty()) |
| 313 return; | 222 return; |
| 314 | 223 |
| 315 for (auto it = custom_launcher_page_urls.begin(); | 224 for (auto it = custom_launcher_page_urls.begin(); |
| 316 it != custom_launcher_page_urls.end(); ++it) { | 225 it != custom_launcher_page_urls.end(); ++it) { |
| 317 std::string extension_id = it->host(); | 226 std::string extension_id = it->host(); |
| 318 auto page_contents = base::MakeUnique<app_list::CustomLauncherPageContents>( | 227 auto page_contents = base::MakeUnique<app_list::CustomLauncherPageContents>( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 345 } | 254 } |
| 346 } | 255 } |
| 347 | 256 |
| 348 void AppListViewDelegate::OnHotwordRecognized( | 257 void AppListViewDelegate::OnHotwordRecognized( |
| 349 const scoped_refptr<content::SpeechRecognitionSessionPreamble>& preamble) { | 258 const scoped_refptr<content::SpeechRecognitionSessionPreamble>& preamble) { |
| 350 DCHECK_EQ(app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING, | 259 DCHECK_EQ(app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING, |
| 351 speech_ui_->state()); | 260 speech_ui_->state()); |
| 352 StartSpeechRecognitionForHotword(preamble); | 261 StartSpeechRecognitionForHotword(preamble); |
| 353 } | 262 } |
| 354 | 263 |
| 355 void AppListViewDelegate::SigninManagerCreated(SigninManagerBase* manager) { | |
| 356 scoped_observer_.Add(manager); | |
| 357 } | |
| 358 | |
| 359 void AppListViewDelegate::SigninManagerShutdown(SigninManagerBase* manager) { | |
| 360 if (scoped_observer_.IsObserving(manager)) | |
| 361 scoped_observer_.Remove(manager); | |
| 362 } | |
| 363 | |
| 364 void AppListViewDelegate::GoogleSigninFailed( | |
| 365 const GoogleServiceAuthError& error) { | |
| 366 SetUpProfileSwitcher(); | |
| 367 } | |
| 368 | |
| 369 void AppListViewDelegate::GoogleSigninSucceeded(const std::string& account_id, | |
| 370 const std::string& username, | |
| 371 const std::string& password) { | |
| 372 SetUpProfileSwitcher(); | |
| 373 } | |
| 374 | |
| 375 void AppListViewDelegate::GoogleSignedOut(const std::string& account_id, | |
| 376 const std::string& username) { | |
| 377 SetUpProfileSwitcher(); | |
| 378 } | |
| 379 | |
| 380 void AppListViewDelegate::OnProfileAdded(const base::FilePath& profile_path) { | |
| 381 SetUpProfileSwitcher(); | |
| 382 } | |
| 383 | |
| 384 void AppListViewDelegate::OnProfileWasRemoved( | |
| 385 const base::FilePath& profile_path, | |
| 386 const base::string16& profile_name) { | |
| 387 SetUpProfileSwitcher(); | |
| 388 } | |
| 389 | |
| 390 void AppListViewDelegate::OnProfileNameChanged( | |
| 391 const base::FilePath& profile_path, | |
| 392 const base::string16& old_profile_name) { | |
| 393 SetUpProfileSwitcher(); | |
| 394 } | |
| 395 | |
| 396 bool AppListViewDelegate::ForceNativeDesktop() const { | |
| 397 return controller_->ForceNativeDesktop(); | |
| 398 } | |
| 399 | |
| 400 void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) { | |
| 401 DCHECK(model_); | |
| 402 // The profile must be loaded before this is called. | |
| 403 SetProfile( | |
| 404 g_browser_process->profile_manager()->GetProfileByPath(profile_path)); | |
| 405 } | |
| 406 | |
| 407 app_list::AppListModel* AppListViewDelegate::GetModel() { | 264 app_list::AppListModel* AppListViewDelegate::GetModel() { |
| 408 return model_; | 265 return model_; |
| 409 } | 266 } |
| 410 | 267 |
| 411 app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() { | 268 app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() { |
| 412 return speech_ui_.get(); | 269 return speech_ui_.get(); |
| 413 } | 270 } |
| 414 | 271 |
| 415 void AppListViewDelegate::StartSearch() { | 272 void AppListViewDelegate::StartSearch() { |
| 416 if (search_controller_) { | 273 if (search_controller_) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 // the launcher to open. | 356 // the launcher to open. |
| 500 // TODO(amistry): This only works on ChromeOS since Chrome hides the | 357 // TODO(amistry): This only works on ChromeOS since Chrome hides the |
| 501 // launcher instead of destroying it. Make this work on Chrome. | 358 // launcher instead of destroying it. Make this work on Chrome. |
| 502 if (hotword_service->IsAlwaysOnEnabled()) | 359 if (hotword_service->IsAlwaysOnEnabled()) |
| 503 hotword_service->RequestHotwordSession(nullptr); | 360 hotword_service->RequestHotwordSession(nullptr); |
| 504 } | 361 } |
| 505 } | 362 } |
| 506 } | 363 } |
| 507 } | 364 } |
| 508 | 365 |
| 509 void AppListViewDelegate::OpenHelp() { | |
| 510 chrome::ScopedTabbedBrowserDisplayer displayer(profile_); | |
| 511 content::OpenURLParams params(GURL(chrome::kAppLauncherHelpURL), | |
| 512 content::Referrer(), | |
| 513 WindowOpenDisposition::NEW_FOREGROUND_TAB, | |
| 514 ui::PAGE_TRANSITION_LINK, false); | |
| 515 displayer.browser()->OpenURL(params); | |
| 516 } | |
| 517 | |
| 518 void AppListViewDelegate::OpenFeedback() { | |
| 519 Browser* browser = chrome::FindTabbedBrowser(profile_, false); | |
| 520 chrome::ShowFeedbackPage(browser, std::string(), | |
| 521 chrome::kAppLauncherCategoryTag); | |
| 522 } | |
| 523 | |
| 524 void AppListViewDelegate::StartSpeechRecognition() { | 366 void AppListViewDelegate::StartSpeechRecognition() { |
| 525 StartSpeechRecognitionForHotword(nullptr); | 367 StartSpeechRecognitionForHotword(nullptr); |
| 526 } | 368 } |
| 527 | 369 |
| 528 void AppListViewDelegate::StopSpeechRecognition() { | 370 void AppListViewDelegate::StopSpeechRecognition() { |
| 529 app_list::StartPageService* service = | 371 app_list::StartPageService* service = |
| 530 app_list::StartPageService::Get(profile_); | 372 app_list::StartPageService::Get(profile_); |
| 531 if (service) | 373 if (service) |
| 532 service->StopSpeechRecognition(); | 374 service->StopSpeechRecognition(); |
| 533 } | 375 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 558 // To get around this, always stop the session when switching to speech | 400 // To get around this, always stop the session when switching to speech |
| 559 // recognition. | 401 // recognition. |
| 560 if (service && service->HotwordEnabled()) { | 402 if (service && service->HotwordEnabled()) { |
| 561 HotwordService* hotword_service = | 403 HotwordService* hotword_service = |
| 562 HotwordServiceFactory::GetForProfile(profile_); | 404 HotwordServiceFactory::GetForProfile(profile_); |
| 563 if (hotword_service) | 405 if (hotword_service) |
| 564 hotword_service->StopHotwordSession(this); | 406 hotword_service->StopHotwordSession(this); |
| 565 } | 407 } |
| 566 } | 408 } |
| 567 | 409 |
| 568 void AppListViewDelegate::ShowForProfileByPath( | |
| 569 const base::FilePath& profile_path) { | |
| 570 controller_->ShowForProfileByPath(profile_path); | |
| 571 } | |
| 572 | |
| 573 void AppListViewDelegate::OnSpeechResult(const base::string16& result, | 410 void AppListViewDelegate::OnSpeechResult(const base::string16& result, |
| 574 bool is_final) { | 411 bool is_final) { |
| 575 speech_ui_->SetSpeechResult(result, is_final); | 412 speech_ui_->SetSpeechResult(result, is_final); |
| 576 if (is_final) { | 413 if (is_final) { |
| 577 auto_launch_timeout_ = base::TimeDelta::FromMilliseconds( | 414 auto_launch_timeout_ = base::TimeDelta::FromMilliseconds( |
| 578 kAutoLaunchDefaultTimeoutMilliSec); | 415 kAutoLaunchDefaultTimeoutMilliSec); |
| 579 is_voice_query_ = true; | 416 is_voice_query_ = true; |
| 580 model_->search_box()->SetText(result); | 417 model_->search_box()->SetText(result); |
| 581 } | 418 } |
| 582 } | 419 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 598 service && service->HotwordEnabled() && | 435 service && service->HotwordEnabled() && |
| 599 controller_->GetAppListWindow()) { | 436 controller_->GetAppListWindow()) { |
| 600 HotwordService* hotword_service = | 437 HotwordService* hotword_service = |
| 601 HotwordServiceFactory::GetForProfile(profile_); | 438 HotwordServiceFactory::GetForProfile(profile_); |
| 602 if (hotword_service) { | 439 if (hotword_service) { |
| 603 hotword_service->RequestHotwordSession(this); | 440 hotword_service->RequestHotwordSession(this); |
| 604 } | 441 } |
| 605 } | 442 } |
| 606 } | 443 } |
| 607 | 444 |
| 608 #if defined(TOOLKIT_VIEWS) | |
| 609 views::View* AppListViewDelegate::CreateStartPageWebView( | 445 views::View* AppListViewDelegate::CreateStartPageWebView( |
| 610 const gfx::Size& size) { | 446 const gfx::Size& size) { |
| 611 app_list::StartPageService* service = | 447 app_list::StartPageService* service = |
| 612 app_list::StartPageService::Get(profile_); | 448 app_list::StartPageService::Get(profile_); |
| 613 if (!service) | 449 if (!service) |
| 614 return NULL; | 450 return NULL; |
| 615 | 451 |
| 616 service->LoadContentsIfNeeded(); | 452 service->LoadContentsIfNeeded(); |
| 617 | 453 |
| 618 content::WebContents* web_contents = service->GetStartPageContents(); | 454 content::WebContents* web_contents = service->GetStartPageContents(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 | 494 |
| 659 void AppListViewDelegate::CustomLauncherPageAnimationChanged(double progress) { | 495 void AppListViewDelegate::CustomLauncherPageAnimationChanged(double progress) { |
| 660 if (launcher_page_event_dispatcher_) | 496 if (launcher_page_event_dispatcher_) |
| 661 launcher_page_event_dispatcher_->ProgressChanged(progress); | 497 launcher_page_event_dispatcher_->ProgressChanged(progress); |
| 662 } | 498 } |
| 663 | 499 |
| 664 void AppListViewDelegate::CustomLauncherPagePopSubpage() { | 500 void AppListViewDelegate::CustomLauncherPagePopSubpage() { |
| 665 if (launcher_page_event_dispatcher_) | 501 if (launcher_page_event_dispatcher_) |
| 666 launcher_page_event_dispatcher_->PopSubpage(); | 502 launcher_page_event_dispatcher_->PopSubpage(); |
| 667 } | 503 } |
| 668 #endif | |
| 669 | 504 |
| 670 bool AppListViewDelegate::IsSpeechRecognitionEnabled() { | 505 bool AppListViewDelegate::IsSpeechRecognitionEnabled() { |
| 671 app_list::StartPageService* service = | 506 app_list::StartPageService* service = |
| 672 app_list::StartPageService::Get(profile_); | 507 app_list::StartPageService::Get(profile_); |
| 673 return service && service->GetSpeechRecognitionContents(); | 508 return service && service->GetSpeechRecognitionContents(); |
| 674 } | 509 } |
| 675 | 510 |
| 676 const app_list::AppListViewDelegate::Users& | |
| 677 AppListViewDelegate::GetUsers() const { | |
| 678 return users_; | |
| 679 } | |
| 680 | |
| 681 void AppListViewDelegate::OnTemplateURLServiceChanged() { | 511 void AppListViewDelegate::OnTemplateURLServiceChanged() { |
| 682 TemplateURLService* template_url_service = | 512 TemplateURLService* template_url_service = |
| 683 TemplateURLServiceFactory::GetForProfile(profile_); | 513 TemplateURLServiceFactory::GetForProfile(profile_); |
| 684 const TemplateURL* default_provider = | 514 const TemplateURL* default_provider = |
| 685 template_url_service->GetDefaultSearchProvider(); | 515 template_url_service->GetDefaultSearchProvider(); |
| 686 bool is_google = | 516 bool is_google = |
| 687 default_provider->GetEngineType( | 517 default_provider->GetEngineType( |
| 688 template_url_service->search_terms_data()) == | 518 template_url_service->search_terms_data()) == |
| 689 SEARCH_ENGINE_GOOGLE; | 519 SEARCH_ENGINE_GOOGLE; |
| 690 | 520 |
| 691 model_->SetSearchEngineIsGoogle(is_google); | 521 model_->SetSearchEngineIsGoogle(is_google); |
| 692 | 522 |
| 693 app_list::StartPageService* start_page_service = | 523 app_list::StartPageService* start_page_service = |
| 694 app_list::StartPageService::Get(profile_); | 524 app_list::StartPageService::Get(profile_); |
| 695 if (start_page_service) | 525 if (start_page_service) |
| 696 start_page_service->set_search_engine_is_google(is_google); | 526 start_page_service->set_search_engine_is_google(is_google); |
| 697 } | 527 } |
| 698 | 528 |
| 699 void AppListViewDelegate::Observe(int type, | 529 void AppListViewDelegate::Observe(int type, |
| 700 const content::NotificationSource& source, | 530 const content::NotificationSource& source, |
| 701 const content::NotificationDetails& details) { | 531 const content::NotificationDetails& details) { |
| 702 DCHECK_EQ(chrome::NOTIFICATION_APP_TERMINATING, type); | 532 DCHECK_EQ(chrome::NOTIFICATION_APP_TERMINATING, type); |
| 703 | 533 |
| 704 SetProfile(nullptr); // Ensures launcher page web contents are torn down. | 534 SetProfile(nullptr); // Ensures launcher page web contents are torn down. |
| 705 | |
| 706 // SigninManagerFactory is not a leaky singleton (unlike this class), and | |
| 707 // its destructor will check that it has no remaining observers. | |
| 708 scoped_observer_.RemoveAll(); | |
| 709 SigninManagerFactory::GetInstance()->RemoveObserver(this); | |
| 710 } | 535 } |
| OLD | NEW |