| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/chromeos/note_taking_helper.h" | 5 #include "chrome/browser/chromeos/note_taking_helper.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "apps/launcher.h" | 10 #include "apps/launcher.h" |
| 11 #include "ash/common/system/chromeos/palette/palette_utils.h" | 11 #include "ash/common/system/chromeos/palette/palette_utils.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
| 19 #include "base/stl_util.h" |
| 19 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
| 20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/chromeos/file_manager/path_util.h" | 23 #include "chrome/browser/chromeos/file_manager/path_util.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 26 #include "chromeos/chromeos_switches.h" | 27 #include "chromeos/chromeos_switches.h" |
| 27 #include "components/arc/arc_bridge_service.h" | 28 #include "components/arc/arc_bridge_service.h" |
| 28 #include "components/arc/arc_service_manager.h" | 29 #include "components/arc/arc_service_manager.h" |
| 29 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" | 30 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" |
| 30 #include "components/prefs/pref_service.h" | 31 #include "components/prefs/pref_service.h" |
| 31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
| 33 #include "extensions/browser/extension_registry.h" | 34 #include "extensions/browser/extension_registry.h" |
| 34 #include "extensions/common/api/app_runtime.h" | 35 #include "extensions/common/api/app_runtime.h" |
| 35 #include "extensions/common/extension.h" | 36 #include "extensions/common/extension.h" |
| 37 #include "extensions/common/manifest_handlers/action_handlers_handler.h" |
| 36 #include "url/gurl.h" | 38 #include "url/gurl.h" |
| 37 | 39 |
| 38 namespace app_runtime = extensions::api::app_runtime; | 40 namespace app_runtime = extensions::api::app_runtime; |
| 39 | 41 |
| 40 namespace chromeos { | 42 namespace chromeos { |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 // Pointer to singleton instance. | 45 // Pointer to singleton instance. |
| 44 NoteTakingHelper* g_helper = nullptr; | 46 NoteTakingHelper* g_helper = nullptr; |
| 45 | 47 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>(); | 256 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>(); |
| 255 if (intent_helper_bridge) | 257 if (intent_helper_bridge) |
| 256 intent_helper_bridge->RemoveObserver(this); | 258 intent_helper_bridge->RemoveObserver(this); |
| 257 if (arc::ArcSessionManager::Get()) | 259 if (arc::ArcSessionManager::Get()) |
| 258 arc::ArcSessionManager::Get()->RemoveObserver(this); | 260 arc::ArcSessionManager::Get()->RemoveObserver(this); |
| 259 } | 261 } |
| 260 | 262 |
| 261 bool NoteTakingHelper::IsWhitelistedChromeApp( | 263 bool NoteTakingHelper::IsWhitelistedChromeApp( |
| 262 const extensions::Extension* extension) const { | 264 const extensions::Extension* extension) const { |
| 263 DCHECK(extension); | 265 DCHECK(extension); |
| 264 return std::find(whitelisted_chrome_app_ids_.begin(), | 266 return base::ContainsValue(whitelisted_chrome_app_ids_, extension->id()); |
| 265 whitelisted_chrome_app_ids_.end(), | |
| 266 extension->id()) != whitelisted_chrome_app_ids_.end(); | |
| 267 } | 267 } |
| 268 | 268 |
| 269 std::vector<const extensions::Extension*> NoteTakingHelper::GetChromeApps( | 269 std::vector<const extensions::Extension*> NoteTakingHelper::GetChromeApps( |
| 270 Profile* profile) const { | 270 Profile* profile) const { |
| 271 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 271 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 272 const extensions::ExtensionRegistry* extension_registry = | 272 const extensions::ExtensionRegistry* extension_registry = |
| 273 extensions::ExtensionRegistry::Get(profile); | 273 extensions::ExtensionRegistry::Get(profile); |
| 274 const extensions::ExtensionSet& enabled_extensions = | 274 const extensions::ExtensionSet& enabled_extensions = |
| 275 extension_registry->enabled_extensions(); | 275 extension_registry->enabled_extensions(); |
| 276 | 276 |
| 277 // TODO(derat): Query for additional Chrome apps once http://crbug.com/657139 | |
| 278 // is resolved. | |
| 279 std::vector<const extensions::Extension*> extensions; | 277 std::vector<const extensions::Extension*> extensions; |
| 280 for (const auto& id : whitelisted_chrome_app_ids_) { | 278 for (const auto& id : whitelisted_chrome_app_ids_) { |
| 281 if (enabled_extensions.Contains(id)) { | 279 if (enabled_extensions.Contains(id)) { |
| 282 extensions.push_back(extension_registry->GetExtensionById( | 280 extensions.push_back(extension_registry->GetExtensionById( |
| 283 id, extensions::ExtensionRegistry::ENABLED)); | 281 id, extensions::ExtensionRegistry::ENABLED)); |
| 284 } | 282 } |
| 285 } | 283 } |
| 284 |
| 285 // Add any extensions which have a "note" action in their manifest |
| 286 // "action_handler" entry. |
| 287 for (const auto& extension : enabled_extensions) { |
| 288 if (base::ContainsValue(extensions, extension.get())) |
| 289 continue; |
| 290 |
| 291 if (extensions::ActionHandlersInfo::HasActionHandler( |
| 292 extension.get(), app_runtime::ACTION_TYPE_NEW_NOTE)) { |
| 293 extensions.push_back(extension.get()); |
| 294 } |
| 295 } |
| 296 |
| 286 return extensions; | 297 return extensions; |
| 287 } | 298 } |
| 288 | 299 |
| 289 void NoteTakingHelper::UpdateAndroidApps() { | 300 void NoteTakingHelper::UpdateAndroidApps() { |
| 290 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 301 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 291 auto* helper = ARC_GET_INSTANCE_FOR_METHOD( | 302 auto* helper = ARC_GET_INSTANCE_FOR_METHOD( |
| 292 arc::ArcServiceManager::Get()->arc_bridge_service()->intent_helper(), | 303 arc::ArcServiceManager::Get()->arc_bridge_service()->intent_helper(), |
| 293 RequestIntentHandlerList); | 304 RequestIntentHandlerList); |
| 294 if (!helper) | 305 if (!helper) |
| 295 return; | 306 return; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_ADDED); | 387 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_ADDED); |
| 377 auto registry = extensions::ExtensionRegistry::Get( | 388 auto registry = extensions::ExtensionRegistry::Get( |
| 378 content::Source<Profile>(source).ptr()); | 389 content::Source<Profile>(source).ptr()); |
| 379 DCHECK(!extension_registry_observer_.IsObserving(registry)); | 390 DCHECK(!extension_registry_observer_.IsObserving(registry)); |
| 380 extension_registry_observer_.Add(registry); | 391 extension_registry_observer_.Add(registry); |
| 381 } | 392 } |
| 382 | 393 |
| 383 void NoteTakingHelper::OnExtensionLoaded( | 394 void NoteTakingHelper::OnExtensionLoaded( |
| 384 content::BrowserContext* browser_context, | 395 content::BrowserContext* browser_context, |
| 385 const extensions::Extension* extension) { | 396 const extensions::Extension* extension) { |
| 386 if (IsWhitelistedChromeApp(extension)) { | 397 if (IsWhitelistedChromeApp(extension) || |
| 398 extensions::ActionHandlersInfo::HasActionHandler( |
| 399 extension, app_runtime::ACTION_TYPE_NEW_NOTE)) { |
| 387 for (auto& observer : observers_) | 400 for (auto& observer : observers_) |
| 388 observer.OnAvailableNoteTakingAppsUpdated(); | 401 observer.OnAvailableNoteTakingAppsUpdated(); |
| 389 } | 402 } |
| 390 } | 403 } |
| 391 | 404 |
| 392 void NoteTakingHelper::OnExtensionUnloaded( | 405 void NoteTakingHelper::OnExtensionUnloaded( |
| 393 content::BrowserContext* browser_context, | 406 content::BrowserContext* browser_context, |
| 394 const extensions::Extension* extension, | 407 const extensions::Extension* extension, |
| 395 extensions::UnloadedExtensionInfo::Reason reason) { | 408 extensions::UnloadedExtensionInfo::Reason reason) { |
| 396 if (IsWhitelistedChromeApp(extension)) { | 409 if (IsWhitelistedChromeApp(extension) || |
| 410 extensions::ActionHandlersInfo::HasActionHandler( |
| 411 extension, app_runtime::ACTION_TYPE_NEW_NOTE)) { |
| 397 for (auto& observer : observers_) | 412 for (auto& observer : observers_) |
| 398 observer.OnAvailableNoteTakingAppsUpdated(); | 413 observer.OnAvailableNoteTakingAppsUpdated(); |
| 399 } | 414 } |
| 400 } | 415 } |
| 401 | 416 |
| 402 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { | 417 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { |
| 403 extension_registry_observer_.Remove(registry); | 418 extension_registry_observer_.Remove(registry); |
| 404 } | 419 } |
| 405 | 420 |
| 406 } // namespace chromeos | 421 } // namespace chromeos |
| OLD | NEW |