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 "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "extensions/browser/event_router.h" | 9 #include "extensions/browser/event_router.h" |
10 #include "extensions/browser/extension_prefs.h" | 10 #include "extensions/browser/extension_prefs.h" |
| 11 #include "extensions/browser/extension_system.h" |
11 #include "extensions/browser/extensions_browser_client.h" | 12 #include "extensions/browser/extensions_browser_client.h" |
12 #include "extensions/browser/granted_file_entry.h" | 13 #include "extensions/browser/granted_file_entry.h" |
13 #include "extensions/common/api/app_runtime.h" | 14 #include "extensions/common/api/app_runtime.h" |
14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
15 | 16 |
16 using content::BrowserContext; | 17 using content::BrowserContext; |
17 | 18 |
18 namespace extensions { | 19 namespace extensions { |
19 | 20 |
20 namespace app_runtime = core_api::app_runtime; | 21 namespace app_runtime = core_api::app_runtime; |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
| 25 void DispatchOnAppEmbeddingRequestEventImpl( |
| 26 const std::string& extension_id, |
| 27 scoped_ptr<base::DictionaryValue> app_embedding_request_data, |
| 28 content::BrowserContext* context) { |
| 29 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 30 args->Append(app_embedding_request_data.release()); |
| 31 extensions::ExtensionSystem* system = |
| 32 extensions::ExtensionSystem::Get(context); |
| 33 scoped_ptr<Event> event( |
| 34 new Event(app_runtime::OnAppEmbeddingRequest::kEventName, args.Pass())); |
| 35 event->restrict_to_browser_context = context; |
| 36 event->can_load_ephemeral_apps = true; |
| 37 extensions::EventRouter* event_router = system->event_router(); |
| 38 event_router->DispatchEventWithLazyListener(extension_id, event.Pass()); |
| 39 |
| 40 ExtensionPrefs::Get(context) |
| 41 ->SetLastLaunchTime(extension_id, base::Time::Now()); |
| 42 } |
| 43 |
24 void DispatchOnLaunchedEventImpl(const std::string& extension_id, | 44 void DispatchOnLaunchedEventImpl(const std::string& extension_id, |
25 scoped_ptr<base::DictionaryValue> launch_data, | 45 scoped_ptr<base::DictionaryValue> launch_data, |
26 BrowserContext* context) { | 46 BrowserContext* context) { |
27 // "Forced app mode" is true for Chrome OS kiosk mode. | 47 // "Forced app mode" is true for Chrome OS kiosk mode. |
28 launch_data->SetBoolean( | 48 launch_data->SetBoolean( |
29 "isKioskSession", | 49 "isKioskSession", |
30 ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode()); | 50 ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode()); |
31 scoped_ptr<base::ListValue> args(new base::ListValue()); | 51 scoped_ptr<base::ListValue> args(new base::ListValue()); |
32 args->Append(launch_data.release()); | 52 args->Append(launch_data.release()); |
33 scoped_ptr<Event> event( | 53 scoped_ptr<Event> event( |
34 new Event(app_runtime::OnLaunched::kEventName, args.Pass())); | 54 new Event(app_runtime::OnLaunched::kEventName, args.Pass())); |
35 event->restrict_to_browser_context = context; | 55 event->restrict_to_browser_context = context; |
36 event->can_load_ephemeral_apps = true; | 56 event->can_load_ephemeral_apps = true; |
37 EventRouter::Get(context) | 57 EventRouter::Get(context) |
38 ->DispatchEventWithLazyListener(extension_id, event.Pass()); | 58 ->DispatchEventWithLazyListener(extension_id, event.Pass()); |
39 ExtensionPrefs::Get(context) | 59 ExtensionPrefs::Get(context) |
40 ->SetLastLaunchTime(extension_id, base::Time::Now()); | 60 ->SetLastLaunchTime(extension_id, base::Time::Now()); |
41 } | 61 } |
42 | 62 |
43 } // namespace | 63 } // namespace |
44 | 64 |
| 65 // static. |
| 66 void AppRuntimeEventRouter::DispatchOnAppEmbeddingRequestEvent( |
| 67 content::BrowserContext* context, |
| 68 scoped_ptr<base::DictionaryValue> embed_app_data, |
| 69 const Extension* extension) { |
| 70 DispatchOnAppEmbeddingRequestEventImpl( |
| 71 extension->id(), embed_app_data.Pass(), context); |
| 72 } |
| 73 |
45 // static | 74 // static |
46 void AppRuntimeEventRouter::DispatchOnLaunchedEvent( | 75 void AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
47 BrowserContext* context, | 76 BrowserContext* context, |
48 const Extension* extension) { | 77 const Extension* extension) { |
49 scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue()); | 78 scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue()); |
50 DispatchOnLaunchedEventImpl(extension->id(), launch_data.Pass(), context); | 79 DispatchOnLaunchedEventImpl(extension->id(), launch_data.Pass(), context); |
51 } | 80 } |
52 | 81 |
53 // static | 82 // static |
54 void AppRuntimeEventRouter::DispatchOnRestartedEvent( | 83 void AppRuntimeEventRouter::DispatchOnRestartedEvent( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 const GURL& referrer_url) { | 126 const GURL& referrer_url) { |
98 app_runtime::LaunchData launch_data; | 127 app_runtime::LaunchData launch_data; |
99 launch_data.id.reset(new std::string(handler_id)); | 128 launch_data.id.reset(new std::string(handler_id)); |
100 launch_data.url.reset(new std::string(url.spec())); | 129 launch_data.url.reset(new std::string(url.spec())); |
101 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); | 130 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); |
102 DispatchOnLaunchedEventImpl( | 131 DispatchOnLaunchedEventImpl( |
103 extension->id(), launch_data.ToValue().Pass(), context); | 132 extension->id(), launch_data.ToValue().Pass(), context); |
104 } | 133 } |
105 | 134 |
106 } // namespace extensions | 135 } // namespace extensions |
OLD | NEW |