Chromium Code Reviews| 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" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "chromeos/chromeos_switches.h" | 26 #include "chromeos/chromeos_switches.h" |
| 27 #include "components/arc/arc_bridge_service.h" | 27 #include "components/arc/arc_bridge_service.h" |
| 28 #include "components/arc/arc_service_manager.h" | 28 #include "components/arc/arc_service_manager.h" |
| 29 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" | 29 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" |
| 30 #include "components/prefs/pref_service.h" | 30 #include "components/prefs/pref_service.h" |
| 31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
| 33 #include "extensions/browser/extension_registry.h" | 33 #include "extensions/browser/extension_registry.h" |
| 34 #include "extensions/common/api/app_runtime.h" | 34 #include "extensions/common/api/app_runtime.h" |
| 35 #include "extensions/common/extension.h" | 35 #include "extensions/common/extension.h" |
| 36 #include "extensions/common/manifest_handlers/action_handlers_handler.h" | |
| 36 #include "url/gurl.h" | 37 #include "url/gurl.h" |
| 37 | 38 |
| 38 namespace app_runtime = extensions::api::app_runtime; | 39 namespace app_runtime = extensions::api::app_runtime; |
| 39 | 40 |
| 40 namespace chromeos { | 41 namespace chromeos { |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 // Pointer to singleton instance. | 44 // Pointer to singleton instance. |
| 44 NoteTakingHelper* g_helper = nullptr; | 45 NoteTakingHelper* g_helper = nullptr; |
| 45 | 46 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 62 // Creates a new Mojo IntentInfo struct for launching an Android note-taking app | 63 // Creates a new Mojo IntentInfo struct for launching an Android note-taking app |
| 63 // with an optional ClipData URI. | 64 // with an optional ClipData URI. |
| 64 arc::mojom::IntentInfoPtr CreateIntentInfo(const GURL& clip_data_uri) { | 65 arc::mojom::IntentInfoPtr CreateIntentInfo(const GURL& clip_data_uri) { |
| 65 arc::mojom::IntentInfoPtr intent = arc::mojom::IntentInfo::New(); | 66 arc::mojom::IntentInfoPtr intent = arc::mojom::IntentInfo::New(); |
| 66 intent->action = NoteTakingHelper::kIntentAction; | 67 intent->action = NoteTakingHelper::kIntentAction; |
| 67 if (!clip_data_uri.is_empty()) | 68 if (!clip_data_uri.is_empty()) |
| 68 intent->clip_data_uri = clip_data_uri.spec(); | 69 intent->clip_data_uri = clip_data_uri.spec(); |
| 69 return intent; | 70 return intent; |
| 70 } | 71 } |
| 71 | 72 |
| 73 // Returns true if the given extension has a new note action handler. | |
| 74 bool HasNewNoteActionHandler(const extensions::Extension* extension) { | |
| 75 std::set<app_runtime::ActionType> action_handlers = | |
| 76 extensions::ActionHandlersInfo::GetActionHandlers(extension); | |
| 77 return action_handlers.count(app_runtime::ACTION_TYPE_NEW_NOTE) > 0; | |
| 78 } | |
| 79 | |
| 72 } // namespace | 80 } // namespace |
| 73 | 81 |
| 74 const char NoteTakingHelper::kIntentAction[] = | 82 const char NoteTakingHelper::kIntentAction[] = |
| 75 "org.chromium.arc.intent.action.CREATE_NOTE"; | 83 "org.chromium.arc.intent.action.CREATE_NOTE"; |
| 76 const char NoteTakingHelper::kDevKeepExtensionId[] = | 84 const char NoteTakingHelper::kDevKeepExtensionId[] = |
| 77 "ogfjaccbdfhecploibfbhighmebiffla"; | 85 "ogfjaccbdfhecploibfbhighmebiffla"; |
| 78 const char NoteTakingHelper::kProdKeepExtensionId[] = | 86 const char NoteTakingHelper::kProdKeepExtensionId[] = |
| 79 "hmjkmjkepdijhoojdojkdfohbdgmmhki"; | 87 "hmjkmjkepdijhoojdojkdfohbdgmmhki"; |
| 80 const char NoteTakingHelper::kPreferredLaunchResultHistogramName[] = | 88 const char NoteTakingHelper::kPreferredLaunchResultHistogramName[] = |
| 81 "Apps.NoteTakingApp.PreferredLaunchResult"; | 89 "Apps.NoteTakingApp.PreferredLaunchResult"; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 } | 275 } |
| 268 | 276 |
| 269 std::vector<const extensions::Extension*> NoteTakingHelper::GetChromeApps( | 277 std::vector<const extensions::Extension*> NoteTakingHelper::GetChromeApps( |
| 270 Profile* profile) const { | 278 Profile* profile) const { |
| 271 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 279 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 272 const extensions::ExtensionRegistry* extension_registry = | 280 const extensions::ExtensionRegistry* extension_registry = |
| 273 extensions::ExtensionRegistry::Get(profile); | 281 extensions::ExtensionRegistry::Get(profile); |
| 274 const extensions::ExtensionSet& enabled_extensions = | 282 const extensions::ExtensionSet& enabled_extensions = |
| 275 extension_registry->enabled_extensions(); | 283 extension_registry->enabled_extensions(); |
| 276 | 284 |
| 277 // TODO(derat): Query for additional Chrome apps once http://crbug.com/657139 | |
| 278 // is resolved. | |
| 279 std::vector<const extensions::Extension*> extensions; | 285 std::vector<const extensions::Extension*> extensions; |
| 280 for (const auto& id : whitelisted_chrome_app_ids_) { | 286 for (const auto& id : whitelisted_chrome_app_ids_) { |
| 281 if (enabled_extensions.Contains(id)) { | 287 if (enabled_extensions.Contains(id)) { |
| 282 extensions.push_back(extension_registry->GetExtensionById( | 288 extensions.push_back(extension_registry->GetExtensionById( |
| 283 id, extensions::ExtensionRegistry::ENABLED)); | 289 id, extensions::ExtensionRegistry::ENABLED)); |
| 284 } | 290 } |
| 285 } | 291 } |
| 292 | |
| 293 // Add any extensions which have a "note" action in their manifest | |
| 294 // "action_handler" entry. | |
| 295 for (const auto& extension : enabled_extensions) { | |
| 296 if (HasNewNoteActionHandler(extension.get())) | |
|
Daniel Erat
2017/01/12 23:55:03
we should probably skip whitelisted apps here to m
jdufault
2017/01/14 00:30:42
Done, nice catch.
| |
| 297 extensions.push_back(extension.get()); | |
| 298 } | |
| 299 | |
| 286 return extensions; | 300 return extensions; |
| 287 } | 301 } |
| 288 | 302 |
| 289 void NoteTakingHelper::UpdateAndroidApps() { | 303 void NoteTakingHelper::UpdateAndroidApps() { |
| 290 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 304 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 291 auto* helper = ARC_GET_INSTANCE_FOR_METHOD( | 305 auto* helper = ARC_GET_INSTANCE_FOR_METHOD( |
| 292 arc::ArcServiceManager::Get()->arc_bridge_service()->intent_helper(), | 306 arc::ArcServiceManager::Get()->arc_bridge_service()->intent_helper(), |
| 293 RequestIntentHandlerList); | 307 RequestIntentHandlerList); |
| 294 if (!helper) | 308 if (!helper) |
| 295 return; | 309 return; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_ADDED); | 390 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_ADDED); |
| 377 auto registry = extensions::ExtensionRegistry::Get( | 391 auto registry = extensions::ExtensionRegistry::Get( |
| 378 content::Source<Profile>(source).ptr()); | 392 content::Source<Profile>(source).ptr()); |
| 379 DCHECK(!extension_registry_observer_.IsObserving(registry)); | 393 DCHECK(!extension_registry_observer_.IsObserving(registry)); |
| 380 extension_registry_observer_.Add(registry); | 394 extension_registry_observer_.Add(registry); |
| 381 } | 395 } |
| 382 | 396 |
| 383 void NoteTakingHelper::OnExtensionLoaded( | 397 void NoteTakingHelper::OnExtensionLoaded( |
| 384 content::BrowserContext* browser_context, | 398 content::BrowserContext* browser_context, |
| 385 const extensions::Extension* extension) { | 399 const extensions::Extension* extension) { |
| 386 if (IsWhitelistedChromeApp(extension)) { | 400 if (IsWhitelistedChromeApp(extension) || HasNewNoteActionHandler(extension)) { |
| 387 for (auto& observer : observers_) | 401 for (auto& observer : observers_) |
| 388 observer.OnAvailableNoteTakingAppsUpdated(); | 402 observer.OnAvailableNoteTakingAppsUpdated(); |
| 389 } | 403 } |
| 390 } | 404 } |
| 391 | 405 |
| 392 void NoteTakingHelper::OnExtensionUnloaded( | 406 void NoteTakingHelper::OnExtensionUnloaded( |
| 393 content::BrowserContext* browser_context, | 407 content::BrowserContext* browser_context, |
| 394 const extensions::Extension* extension, | 408 const extensions::Extension* extension, |
| 395 extensions::UnloadedExtensionInfo::Reason reason) { | 409 extensions::UnloadedExtensionInfo::Reason reason) { |
| 396 if (IsWhitelistedChromeApp(extension)) { | 410 if (IsWhitelistedChromeApp(extension) || HasNewNoteActionHandler(extension)) { |
| 397 for (auto& observer : observers_) | 411 for (auto& observer : observers_) |
| 398 observer.OnAvailableNoteTakingAppsUpdated(); | 412 observer.OnAvailableNoteTakingAppsUpdated(); |
| 399 } | 413 } |
| 400 } | 414 } |
| 401 | 415 |
| 402 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { | 416 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { |
| 403 extension_registry_observer_.Remove(registry); | 417 extension_registry_observer_.Remove(registry); |
| 404 } | 418 } |
| 405 | 419 |
| 406 } // namespace chromeos | 420 } // namespace chromeos |
| OLD | NEW |