Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1624)

Side by Side Diff: chrome/browser/chromeos/note_taking_helper.cc

Issue 2618493002: Chrome app manifest support for action handlers. (Closed)
Patch Set: Initial upload Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/note_taking_helper_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13 matching lines...) Expand all
24 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
25 #include "chromeos/chromeos_switches.h" 25 #include "chromeos/chromeos_switches.h"
26 #include "components/arc/arc_bridge_service.h" 26 #include "components/arc/arc_bridge_service.h"
27 #include "components/arc/common/intent_helper.mojom.h" 27 #include "components/arc/common/intent_helper.mojom.h"
28 #include "components/prefs/pref_service.h" 28 #include "components/prefs/pref_service.h"
29 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
31 #include "extensions/browser/extension_registry.h" 31 #include "extensions/browser/extension_registry.h"
32 #include "extensions/common/api/app_runtime.h" 32 #include "extensions/common/api/app_runtime.h"
33 #include "extensions/common/extension.h" 33 #include "extensions/common/extension.h"
34 #include "extensions/common/manifest_constants.h"
34 #include "url/gurl.h" 35 #include "url/gurl.h"
35 36
36 namespace app_runtime = extensions::api::app_runtime; 37 namespace app_runtime = extensions::api::app_runtime;
37 38
38 namespace chromeos { 39 namespace chromeos {
39 namespace { 40 namespace {
40 41
42 constexpr const char kNewNoteAction[] = "new_note";
Daniel Erat 2017/01/06 21:01:45 nit: mind renaming this to kChromeNewNoteAction or
Daniel Erat 2017/01/06 21:02:33 oh, and i'd also recommend making it a public stat
jdufault 2017/01/12 22:22:24 Done.
43
41 // Pointer to singleton instance. 44 // Pointer to singleton instance.
42 NoteTakingHelper* g_helper = nullptr; 45 NoteTakingHelper* g_helper = nullptr;
43 46
44 // Whitelisted Chrome note-taking apps. 47 // Whitelisted Chrome note-taking apps.
45 const char* const kExtensionIds[] = { 48 const char* const kExtensionIds[] = {
46 // TODO(jdufault): Remove dev version? See crbug.com/640828. 49 // TODO(jdufault): Remove dev version? See crbug.com/640828.
47 NoteTakingHelper::kDevKeepExtensionId, 50 NoteTakingHelper::kDevKeepExtensionId,
48 NoteTakingHelper::kProdKeepExtensionId, 51 NoteTakingHelper::kProdKeepExtensionId,
49 }; 52 };
50 53
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 } 259 }
257 260
258 std::vector<const extensions::Extension*> NoteTakingHelper::GetChromeApps( 261 std::vector<const extensions::Extension*> NoteTakingHelper::GetChromeApps(
259 Profile* profile) const { 262 Profile* profile) const {
260 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 263 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
261 const extensions::ExtensionRegistry* extension_registry = 264 const extensions::ExtensionRegistry* extension_registry =
262 extensions::ExtensionRegistry::Get(profile); 265 extensions::ExtensionRegistry::Get(profile);
263 const extensions::ExtensionSet& enabled_extensions = 266 const extensions::ExtensionSet& enabled_extensions =
264 extension_registry->enabled_extensions(); 267 extension_registry->enabled_extensions();
265 268
266 // TODO(derat): Query for additional Chrome apps once http://crbug.com/657139
267 // is resolved.
268 std::vector<const extensions::Extension*> extensions; 269 std::vector<const extensions::Extension*> extensions;
269 for (const auto& id : whitelisted_chrome_app_ids_) { 270 for (const auto& id : whitelisted_chrome_app_ids_) {
270 if (enabled_extensions.Contains(id)) { 271 if (enabled_extensions.Contains(id)) {
271 extensions.push_back(extension_registry->GetExtensionById( 272 extensions.push_back(extension_registry->GetExtensionById(
272 id, extensions::ExtensionRegistry::ENABLED)); 273 id, extensions::ExtensionRegistry::ENABLED));
273 } 274 }
274 } 275 }
276
277 // Add any extensions which have a "note" action in their manifest
278 // "action_handler" entry.
279 for (const auto& extension : enabled_extensions) {
280 // Find "action_handler" manifest entry.
281 const base::ListValue* action_handlers;
282 if (!extension->manifest()->GetList(
283 extensions::manifest_keys::kActionHandlers, &action_handlers)) {
284 continue;
285 }
286
287 // Check for "new_note" action.
288 for (const auto& wrapped_action_handler : *action_handlers) {
289 std::string action_handler;
290 if (!wrapped_action_handler->GetAsString(&action_handler))
291 continue;
292
293 if (action_handler == kNewNoteAction)
294 extensions.push_back(extension.get());
295 }
296 }
297
275 return extensions; 298 return extensions;
276 } 299 }
277 300
278 void NoteTakingHelper::UpdateAndroidApps() { 301 void NoteTakingHelper::UpdateAndroidApps() {
279 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 302 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
280 auto* helper = GetIntentHelper("RequestIntentHandlerList", 12); 303 auto* helper = GetIntentHelper("RequestIntentHandlerList", 12);
281 if (!helper) 304 if (!helper)
282 return; 305 return;
283 helper->RequestIntentHandlerList( 306 helper->RequestIntentHandlerList(
284 CreateIntentInfo(GURL()), base::Bind(&NoteTakingHelper::OnGotAndroidApps, 307 CreateIntentInfo(GURL()), base::Bind(&NoteTakingHelper::OnGotAndroidApps,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 for (auto& observer : observers_) 401 for (auto& observer : observers_)
379 observer.OnAvailableNoteTakingAppsUpdated(); 402 observer.OnAvailableNoteTakingAppsUpdated();
380 } 403 }
381 } 404 }
382 405
383 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { 406 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) {
384 extension_registry_observer_.Remove(registry); 407 extension_registry_observer_.Remove(registry);
385 } 408 }
386 409
387 } // namespace chromeos 410 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/note_taking_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698