Chromium Code Reviews| 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/extensions/api/app_runtime/app_runtime_api.h" | 5 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" | 12 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
| 13 #include "chrome/browser/extensions/event_names.h" | |
| 13 #include "chrome/browser/extensions/event_router.h" | 14 #include "chrome/browser/extensions/event_router.h" |
| 14 #include "chrome/browser/extensions/extension_system.h" | 15 #include "chrome/browser/extensions/extension_system.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 19 | 20 |
| 20 namespace extensions { | 21 namespace extensions { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 const char kOnLaunchedEvent[] = "app.runtime.onLaunched"; | 25 using event_names::kOnLaunched; |
| 25 const char kOnRestartedEvent[] = "app.runtime.onRestarted"; | 26 using event_names::kOnRestarted; |
| 26 | 27 |
| 27 void DispatchOnLaunchedEventImpl(const std::string& extension_id, | 28 void DispatchOnLaunchedEventImpl(const std::string& extension_id, |
| 28 scoped_ptr<base::ListValue> args, | 29 scoped_ptr<base::ListValue> args, |
| 29 Profile* profile) { | 30 Profile* profile) { |
| 30 extensions::ExtensionSystem* system = | 31 extensions::ExtensionSystem* system = |
| 31 extensions::ExtensionSystem::Get(profile); | 32 extensions::ExtensionSystem::Get(profile); |
| 32 // Special case: normally, extensions add their own lazy event listeners. | 33 // Special case: normally, extensions add their own lazy event listeners. |
| 33 // However, since the extension might have just been enabled, it hasn't had a | 34 // However, since the extension might have just been enabled, it hasn't had a |
| 34 // chance to register for events. So we register on its behalf. If the | 35 // chance to register for events. So we register on its behalf. If the |
| 35 // extension does not actually have a listener, the event will just be | 36 // extension does not actually have a listener, the event will just be |
| 36 // ignored (but an app that doesn't listen for the onLaunched event doesn't | 37 // ignored (but an app that doesn't listen for the onLaunched event doesn't |
| 37 // make sense anyway). | 38 // make sense anyway). |
| 38 system->event_router()->AddLazyEventListener(kOnLaunchedEvent, extension_id); | 39 system->event_router()->AddLazyEventListener(kOnLaunched, |
| 39 scoped_ptr<Event> event(new Event(kOnLaunchedEvent, args.Pass())); | 40 extension_id); |
|
not at google - send to devlin
2013/04/19 14:16:52
1 line?
koz (OOO until 15th September)
2013/04/21 23:33:03
Done.
| |
| 41 scoped_ptr<Event> event(new Event(kOnLaunched, args.Pass())); | |
| 40 event->restrict_to_profile = profile; | 42 event->restrict_to_profile = profile; |
| 41 system->event_router()->DispatchEventToExtension(extension_id, event.Pass()); | 43 system->event_router()->DispatchEventToExtension(extension_id, event.Pass()); |
| 42 system->event_router()->RemoveLazyEventListener(kOnLaunchedEvent, | 44 system->event_router()->RemoveLazyEventListener(kOnLaunched, |
| 43 extension_id); | 45 extension_id); |
|
not at google - send to devlin
2013/04/19 14:16:52
1 line?
koz (OOO until 15th September)
2013/04/21 23:33:03
Done.
| |
| 44 } | 46 } |
| 45 | 47 |
| 46 } // anonymous namespace | 48 } // anonymous namespace |
| 47 | 49 |
| 48 // static. | 50 // static. |
| 49 void AppEventRouter::DispatchOnLaunchedEvent( | 51 void AppEventRouter::DispatchOnLaunchedEvent( |
| 50 Profile* profile, const Extension* extension) { | 52 Profile* profile, const Extension* extension) { |
| 51 scoped_ptr<ListValue> arguments(new ListValue()); | 53 scoped_ptr<ListValue> arguments(new ListValue()); |
| 52 DispatchOnLaunchedEventImpl(extension->id(), arguments.Pass(), profile); | 54 DispatchOnLaunchedEventImpl(extension->id(), arguments.Pass(), profile); |
| 53 } | 55 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 67 const Extension* extension, | 69 const Extension* extension, |
| 68 const std::vector<app_file_handler_util::GrantedFileEntry>& file_entries) { | 70 const std::vector<app_file_handler_util::GrantedFileEntry>& file_entries) { |
| 69 ListValue* file_entries_list = new ListValue(); | 71 ListValue* file_entries_list = new ListValue(); |
| 70 for (std::vector<extensions::app_file_handler_util::GrantedFileEntry> | 72 for (std::vector<extensions::app_file_handler_util::GrantedFileEntry> |
| 71 ::const_iterator it = file_entries.begin(); it != file_entries.end(); | 73 ::const_iterator it = file_entries.begin(); it != file_entries.end(); |
| 72 ++it) { | 74 ++it) { |
| 73 file_entries_list->Append(DictionaryFromSavedFileEntry(*it)); | 75 file_entries_list->Append(DictionaryFromSavedFileEntry(*it)); |
| 74 } | 76 } |
| 75 scoped_ptr<ListValue> arguments(new ListValue()); | 77 scoped_ptr<ListValue> arguments(new ListValue()); |
| 76 arguments->Append(file_entries_list); | 78 arguments->Append(file_entries_list); |
| 77 scoped_ptr<Event> event(new Event(kOnRestartedEvent, arguments.Pass())); | 79 scoped_ptr<Event> event(new Event(kOnRestarted, arguments.Pass())); |
| 78 event->restrict_to_profile = profile; | 80 event->restrict_to_profile = profile; |
| 79 extensions::ExtensionSystem::Get(profile)->event_router()-> | 81 extensions::ExtensionSystem::Get(profile)->event_router()-> |
| 80 DispatchEventToExtension(extension->id(), event.Pass()); | 82 DispatchEventToExtension(extension->id(), event.Pass()); |
| 81 } | 83 } |
| 82 | 84 |
| 83 // static. | 85 // static. |
| 84 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( | 86 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
| 85 Profile* profile, const Extension* extension, | 87 Profile* profile, const Extension* extension, |
| 86 const std::string& handler_id, const std::string& mime_type, | 88 const std::string& handler_id, const std::string& mime_type, |
| 87 const std::string& file_system_id, const std::string& base_name) { | 89 const std::string& file_system_id, const std::string& base_name) { |
| 88 scoped_ptr<ListValue> args(new ListValue()); | 90 scoped_ptr<ListValue> args(new ListValue()); |
| 89 DictionaryValue* launch_data = new DictionaryValue(); | 91 DictionaryValue* launch_data = new DictionaryValue(); |
| 90 launch_data->SetString("id", handler_id); | 92 launch_data->SetString("id", handler_id); |
| 91 DictionaryValue* launch_item = new DictionaryValue; | 93 DictionaryValue* launch_item = new DictionaryValue; |
| 92 launch_item->SetString("fileSystemId", file_system_id); | 94 launch_item->SetString("fileSystemId", file_system_id); |
| 93 launch_item->SetString("baseName", base_name); | 95 launch_item->SetString("baseName", base_name); |
| 94 launch_item->SetString("mimeType", mime_type); | 96 launch_item->SetString("mimeType", mime_type); |
| 95 ListValue* items = new ListValue; | 97 ListValue* items = new ListValue; |
| 96 items->Append(launch_item); | 98 items->Append(launch_item); |
| 97 launch_data->Set("items", items); | 99 launch_data->Set("items", items); |
| 98 args->Append(launch_data); | 100 args->Append(launch_data); |
| 99 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile); | 101 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile); |
| 100 } | 102 } |
| 101 | 103 |
| 102 } // namespace extensions | 104 } // namespace extensions |
| OLD | NEW |