Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/app_runtime/app_runtime_api.h" | 5 #include "extensions/browser/api/app_runtime/app_runtime_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/memory/ptr_util.h" | |
| 11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "extensions/browser/entry_info.h" | 15 #include "extensions/browser/entry_info.h" |
| 15 #include "extensions/browser/event_router.h" | 16 #include "extensions/browser/event_router.h" |
| 16 #include "extensions/browser/extension_prefs.h" | 17 #include "extensions/browser/extension_prefs.h" |
| 17 #include "extensions/browser/extensions_browser_client.h" | 18 #include "extensions/browser/extensions_browser_client.h" |
| 18 #include "extensions/browser/granted_file_entry.h" | 19 #include "extensions/browser/granted_file_entry.h" |
| 19 #include "extensions/common/api/app_runtime.h" | 20 #include "extensions/common/api/app_runtime.h" |
| 20 #include "extensions/common/constants.h" | 21 #include "extensions/common/constants.h" |
| 21 #include "extensions/common/feature_switch.h" | 22 #include "extensions/common/feature_switch.h" |
| 22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 23 | 24 |
| 24 using content::BrowserContext; | 25 using content::BrowserContext; |
| 25 | 26 |
| 26 namespace extensions { | 27 namespace extensions { |
| 27 | 28 |
| 28 namespace app_runtime = api::app_runtime; | 29 namespace app_runtime = api::app_runtime; |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 33 // Converts an ActionType instance to an app_runtime::ActionType instance. | |
| 34 app_runtime::ActionType MapActionType(ActionType action_type) { | |
| 35 switch (action_type) { | |
| 36 case ActionType::NEW_NOTE: | |
| 37 return app_runtime::ActionType::ACTION_TYPE_NEW_NOTE; | |
| 38 } | |
| 39 | |
| 40 NOTREACHED(); | |
|
Daniel Erat
2016/08/11 20:37:06
nit: also log the bad type, e.g.
NOTREACHED() <
jdufault
2016/08/12 18:56:55
Done, but I had to add a cast since action_type is
| |
| 41 return app_runtime::ActionType::ACTION_TYPE_NONE; | |
|
Daniel Erat
2016/08/11 20:37:06
random question: does this _NONE enum value get au
Devlin
2016/08/11 20:51:21
Yep.
| |
| 42 } | |
| 43 | |
| 44 // Converts an ActionData instance to an app_runtime::ActionData instance. | |
| 45 std::unique_ptr<app_runtime::ActionData> BuildActionData( | |
| 46 ActionData action_data) { | |
| 47 auto data = base::WrapUnique(new app_runtime::ActionData()); | |
| 48 data->action_type = MapActionType(action_data.action_type); | |
| 49 return data; | |
| 50 } | |
| 51 | |
| 32 void DispatchOnEmbedRequestedEventImpl( | 52 void DispatchOnEmbedRequestedEventImpl( |
| 33 const std::string& extension_id, | 53 const std::string& extension_id, |
| 34 std::unique_ptr<base::DictionaryValue> app_embedding_request_data, | 54 std::unique_ptr<base::DictionaryValue> app_embedding_request_data, |
| 35 content::BrowserContext* context) { | 55 content::BrowserContext* context) { |
| 36 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 56 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 37 args->Append(std::move(app_embedding_request_data)); | 57 args->Append(std::move(app_embedding_request_data)); |
| 38 std::unique_ptr<Event> event( | 58 std::unique_ptr<Event> event( |
| 39 new Event(events::APP_RUNTIME_ON_EMBED_REQUESTED, | 59 new Event(events::APP_RUNTIME_ON_EMBED_REQUESTED, |
| 40 app_runtime::OnEmbedRequested::kEventName, std::move(args))); | 60 app_runtime::OnEmbedRequested::kEventName, std::move(args))); |
| 41 event->restrict_to_browser_context = context; | 61 event->restrict_to_browser_context = context; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 std::unique_ptr<base::DictionaryValue> embed_app_data, | 150 std::unique_ptr<base::DictionaryValue> embed_app_data, |
| 131 const Extension* extension) { | 151 const Extension* extension) { |
| 132 DispatchOnEmbedRequestedEventImpl(extension->id(), std::move(embed_app_data), | 152 DispatchOnEmbedRequestedEventImpl(extension->id(), std::move(embed_app_data), |
| 133 context); | 153 context); |
| 134 } | 154 } |
| 135 | 155 |
| 136 // static | 156 // static |
| 137 void AppRuntimeEventRouter::DispatchOnLaunchedEvent( | 157 void AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
| 138 BrowserContext* context, | 158 BrowserContext* context, |
| 139 const Extension* extension, | 159 const Extension* extension, |
| 140 extensions::AppLaunchSource source) { | 160 extensions::AppLaunchSource source, |
| 161 base::Optional<ActionData> action_data) { | |
| 141 app_runtime::LaunchData launch_data; | 162 app_runtime::LaunchData launch_data; |
| 142 | 163 |
| 143 app_runtime::LaunchSource source_enum = getLaunchSourceEnum(source); | 164 app_runtime::LaunchSource source_enum = getLaunchSourceEnum(source); |
| 144 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { | 165 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { |
| 145 launch_data.source = source_enum; | 166 launch_data.source = source_enum; |
| 146 } | 167 } |
| 168 | |
| 169 if (action_data) | |
| 170 launch_data.action_data = BuildActionData(action_data.value()); | |
| 171 | |
| 147 DispatchOnLaunchedEventImpl(extension->id(), source_enum, | 172 DispatchOnLaunchedEventImpl(extension->id(), source_enum, |
| 148 launch_data.ToValue(), context); | 173 launch_data.ToValue(), context); |
| 149 } | 174 } |
| 150 | 175 |
| 151 // static | 176 // static |
| 152 void AppRuntimeEventRouter::DispatchOnRestartedEvent( | 177 void AppRuntimeEventRouter::DispatchOnRestartedEvent( |
| 153 BrowserContext* context, | 178 BrowserContext* context, |
| 154 const Extension* extension) { | 179 const Extension* extension) { |
| 155 std::unique_ptr<base::ListValue> arguments(new base::ListValue()); | 180 std::unique_ptr<base::ListValue> arguments(new base::ListValue()); |
| 156 std::unique_ptr<Event> event(new Event(events::APP_RUNTIME_ON_RESTARTED, | 181 std::unique_ptr<Event> event(new Event(events::APP_RUNTIME_ON_RESTARTED, |
| 157 app_runtime::OnRestarted::kEventName, | 182 app_runtime::OnRestarted::kEventName, |
| 158 std::move(arguments))); | 183 std::move(arguments))); |
| 159 event->restrict_to_browser_context = context; | 184 event->restrict_to_browser_context = context; |
| 160 EventRouter::Get(context) | 185 EventRouter::Get(context) |
| 161 ->DispatchEventToExtension(extension->id(), std::move(event)); | 186 ->DispatchEventToExtension(extension->id(), std::move(event)); |
| 162 } | 187 } |
| 163 | 188 |
| 164 // static | 189 // static |
| 165 void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( | 190 void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( |
| 166 BrowserContext* context, | 191 BrowserContext* context, |
| 167 const Extension* extension, | 192 const Extension* extension, |
| 193 extensions::AppLaunchSource source, | |
| 168 const std::string& handler_id, | 194 const std::string& handler_id, |
| 169 const std::vector<EntryInfo>& entries, | 195 const std::vector<EntryInfo>& entries, |
| 170 const std::vector<GrantedFileEntry>& file_entries) { | 196 const std::vector<GrantedFileEntry>& file_entries, |
| 197 base::Optional<ActionData> action_data) { | |
| 198 app_runtime::LaunchSource source_enum = getLaunchSourceEnum(source); | |
|
Devlin
2016/08/11 20:51:21
getLaunchSourceEnum -> GetLaunchSourceEnum
I know
jdufault
2016/08/12 18:56:55
Done.
| |
| 199 | |
| 171 // TODO(sergeygs): Use the same way of creating an event (using the generated | 200 // TODO(sergeygs): Use the same way of creating an event (using the generated |
| 172 // boilerplate) as below in DispatchOnLaunchedEventWithUrl. | 201 // boilerplate) as below in DispatchOnLaunchedEventWithUrl. |
| 173 std::unique_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue); | 202 std::unique_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue); |
| 174 launch_data->SetString("id", handler_id); | 203 launch_data->SetString("id", handler_id); |
| 175 | 204 |
| 176 app_runtime::LaunchSource source_enum = | |
| 177 app_runtime::LAUNCH_SOURCE_FILE_HANDLER; | |
| 178 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { | 205 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { |
|
Daniel Erat
2016/08/11 20:37:06
nit: move this up just below the line that initial
jdufault
2016/08/12 18:56:55
source_enum is used below as well (DispatchOnLaunc
| |
| 179 launch_data->SetString("source", app_runtime::ToString(source_enum)); | 206 launch_data->SetString("source", app_runtime::ToString(source_enum)); |
| 180 } | 207 } |
| 181 | 208 |
| 209 if (action_data) { | |
| 210 launch_data->Set("action_data", | |
|
Devlin
2016/08/11 20:51:21
this should be actionData.
If we used app_runtime
jdufault
2016/08/12 18:56:55
Done.
Devlin
2016/08/16 00:20:09
We should document the fields of the launch item,
jdufault
2016/08/16 21:30:57
Done.
| |
| 211 BuildActionData(action_data.value())->ToValue()); | |
| 212 } | |
| 213 | |
| 182 std::unique_ptr<base::ListValue> items(new base::ListValue); | 214 std::unique_ptr<base::ListValue> items(new base::ListValue); |
| 183 DCHECK(file_entries.size() == entries.size()); | 215 DCHECK(file_entries.size() == entries.size()); |
| 184 for (size_t i = 0; i < file_entries.size(); ++i) { | 216 for (size_t i = 0; i < file_entries.size(); ++i) { |
| 185 std::unique_ptr<base::DictionaryValue> launch_item( | 217 std::unique_ptr<base::DictionaryValue> launch_item( |
| 186 new base::DictionaryValue); | 218 new base::DictionaryValue); |
| 187 | 219 |
| 188 launch_item->SetString("fileSystemId", file_entries[i].filesystem_id); | 220 launch_item->SetString("fileSystemId", file_entries[i].filesystem_id); |
| 189 launch_item->SetString("baseName", file_entries[i].registered_name); | 221 launch_item->SetString("baseName", file_entries[i].registered_name); |
| 190 launch_item->SetString("mimeType", entries[i].mime_type); | 222 launch_item->SetString("mimeType", entries[i].mime_type); |
| 191 launch_item->SetString("entryId", file_entries[i].id); | 223 launch_item->SetString("entryId", file_entries[i].id); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 211 launch_data.url.reset(new std::string(url.spec())); | 243 launch_data.url.reset(new std::string(url.spec())); |
| 212 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); | 244 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); |
| 213 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { | 245 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { |
| 214 launch_data.source = source_enum; | 246 launch_data.source = source_enum; |
| 215 } | 247 } |
| 216 DispatchOnLaunchedEventImpl(extension->id(), source_enum, | 248 DispatchOnLaunchedEventImpl(extension->id(), source_enum, |
| 217 launch_data.ToValue(), context); | 249 launch_data.ToValue(), context); |
| 218 } | 250 } |
| 219 | 251 |
| 220 } // namespace extensions | 252 } // namespace extensions |
| OLD | NEW |