| 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 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 namespace app_runtime = api::app_runtime; | 29 namespace app_runtime = api::app_runtime; |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 void DispatchOnEmbedRequestedEventImpl( | 33 void DispatchOnEmbedRequestedEventImpl( |
| 34 const std::string& extension_id, | 34 const std::string& extension_id, |
| 35 std::unique_ptr<base::DictionaryValue> app_embedding_request_data, | 35 std::unique_ptr<base::DictionaryValue> app_embedding_request_data, |
| 36 content::BrowserContext* context) { | 36 content::BrowserContext* context) { |
| 37 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 37 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 38 args->Append(std::move(app_embedding_request_data)); | 38 args->Append(std::move(app_embedding_request_data)); |
| 39 std::unique_ptr<Event> event( | 39 auto event = base::MakeUnique<Event>( |
| 40 new Event(events::APP_RUNTIME_ON_EMBED_REQUESTED, | 40 events::APP_RUNTIME_ON_EMBED_REQUESTED, |
| 41 app_runtime::OnEmbedRequested::kEventName, std::move(args))); | 41 app_runtime::OnEmbedRequested::kEventName, std::move(args), context); |
| 42 event->restrict_to_browser_context = context; | |
| 43 EventRouter::Get(context) | 42 EventRouter::Get(context) |
| 44 ->DispatchEventWithLazyListener(extension_id, std::move(event)); | 43 ->DispatchEventWithLazyListener(extension_id, std::move(event)); |
| 45 | 44 |
| 46 ExtensionPrefs::Get(context) | 45 ExtensionPrefs::Get(context) |
| 47 ->SetLastLaunchTime(extension_id, base::Time::Now()); | 46 ->SetLastLaunchTime(extension_id, base::Time::Now()); |
| 48 } | 47 } |
| 49 | 48 |
| 50 void DispatchOnLaunchedEventImpl( | 49 void DispatchOnLaunchedEventImpl( |
| 51 const std::string& extension_id, | 50 const std::string& extension_id, |
| 52 app_runtime::LaunchSource source, | 51 app_runtime::LaunchSource source, |
| 53 std::unique_ptr<base::DictionaryValue> launch_data, | 52 std::unique_ptr<base::DictionaryValue> launch_data, |
| 54 BrowserContext* context) { | 53 BrowserContext* context) { |
| 55 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLaunchSource", source, | 54 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLaunchSource", source, |
| 56 app_runtime::LaunchSource::LAUNCH_SOURCE_LAST + 1); | 55 app_runtime::LaunchSource::LAUNCH_SOURCE_LAST + 1); |
| 57 | 56 |
| 58 // "Forced app mode" is true for Chrome OS kiosk mode. | 57 // "Forced app mode" is true for Chrome OS kiosk mode. |
| 59 launch_data->SetBoolean( | 58 launch_data->SetBoolean( |
| 60 "isKioskSession", | 59 "isKioskSession", |
| 61 ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode()); | 60 ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode()); |
| 62 | 61 |
| 63 launch_data->SetBoolean( | 62 launch_data->SetBoolean( |
| 64 "isPublicSession", | 63 "isPublicSession", |
| 65 ExtensionsBrowserClient::Get()->IsLoggedInAsPublicAccount()); | 64 ExtensionsBrowserClient::Get()->IsLoggedInAsPublicAccount()); |
| 66 | 65 |
| 67 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 66 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 68 args->Append(std::move(launch_data)); | 67 args->Append(std::move(launch_data)); |
| 69 std::unique_ptr<Event> event(new Event(events::APP_RUNTIME_ON_LAUNCHED, | 68 auto event = base::MakeUnique<Event>(events::APP_RUNTIME_ON_LAUNCHED, |
| 70 app_runtime::OnLaunched::kEventName, | 69 app_runtime::OnLaunched::kEventName, |
| 71 std::move(args))); | 70 std::move(args), context); |
| 72 event->restrict_to_browser_context = context; | |
| 73 EventRouter::Get(context) | 71 EventRouter::Get(context) |
| 74 ->DispatchEventWithLazyListener(extension_id, std::move(event)); | 72 ->DispatchEventWithLazyListener(extension_id, std::move(event)); |
| 75 ExtensionPrefs::Get(context) | 73 ExtensionPrefs::Get(context) |
| 76 ->SetLastLaunchTime(extension_id, base::Time::Now()); | 74 ->SetLastLaunchTime(extension_id, base::Time::Now()); |
| 77 } | 75 } |
| 78 | 76 |
| 79 #define ASSERT_ENUM_EQUAL(Name) ASSERT_ENUM_EQUAL_FULL(Name, Name) | 77 #define ASSERT_ENUM_EQUAL(Name) ASSERT_ENUM_EQUAL_FULL(Name, Name) |
| 80 | 78 |
| 81 #define ASSERT_ENUM_EQUAL_FULL(Name, Name2) \ | 79 #define ASSERT_ENUM_EQUAL_FULL(Name, Name2) \ |
| 82 static_assert(static_cast<int>(extensions::Name) == \ | 80 static_assert(static_cast<int>(extensions::Name) == \ |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 138 |
| 141 DispatchOnLaunchedEventImpl(extension->id(), source_enum, | 139 DispatchOnLaunchedEventImpl(extension->id(), source_enum, |
| 142 launch_data->ToValue(), context); | 140 launch_data->ToValue(), context); |
| 143 } | 141 } |
| 144 | 142 |
| 145 // static | 143 // static |
| 146 void AppRuntimeEventRouter::DispatchOnRestartedEvent( | 144 void AppRuntimeEventRouter::DispatchOnRestartedEvent( |
| 147 BrowserContext* context, | 145 BrowserContext* context, |
| 148 const Extension* extension) { | 146 const Extension* extension) { |
| 149 std::unique_ptr<base::ListValue> arguments(new base::ListValue()); | 147 std::unique_ptr<base::ListValue> arguments(new base::ListValue()); |
| 150 std::unique_ptr<Event> event(new Event(events::APP_RUNTIME_ON_RESTARTED, | 148 auto event = base::MakeUnique<Event>(events::APP_RUNTIME_ON_RESTARTED, |
| 151 app_runtime::OnRestarted::kEventName, | 149 app_runtime::OnRestarted::kEventName, |
| 152 std::move(arguments))); | 150 std::move(arguments), context); |
| 153 event->restrict_to_browser_context = context; | |
| 154 EventRouter::Get(context) | 151 EventRouter::Get(context) |
| 155 ->DispatchEventToExtension(extension->id(), std::move(event)); | 152 ->DispatchEventToExtension(extension->id(), std::move(event)); |
| 156 } | 153 } |
| 157 | 154 |
| 158 // static | 155 // static |
| 159 void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( | 156 void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( |
| 160 BrowserContext* context, | 157 BrowserContext* context, |
| 161 const Extension* extension, | 158 const Extension* extension, |
| 162 extensions::AppLaunchSource source, | 159 extensions::AppLaunchSource source, |
| 163 const std::string& handler_id, | 160 const std::string& handler_id, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 launch_data.url.reset(new std::string(url.spec())); | 210 launch_data.url.reset(new std::string(url.spec())); |
| 214 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); | 211 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); |
| 215 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { | 212 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { |
| 216 launch_data.source = source_enum; | 213 launch_data.source = source_enum; |
| 217 } | 214 } |
| 218 DispatchOnLaunchedEventImpl(extension->id(), source_enum, | 215 DispatchOnLaunchedEventImpl(extension->id(), source_enum, |
| 219 launch_data.ToValue(), context); | 216 launch_data.ToValue(), context); |
| 220 } | 217 } |
| 221 | 218 |
| 222 } // namespace extensions | 219 } // namespace extensions |
| OLD | NEW |