| 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 "apps/browser/api/app_runtime/app_runtime_api.h" |
| 6 | 6 |
| 7 #include "apps/browser/file_handler_util.h" |
| 8 #include "apps/common/api/app_runtime.h" |
| 7 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 8 #include "base/values.h" | 10 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" | |
| 10 #include "chrome/common/extensions/api/app_runtime.h" | |
| 11 #include "extensions/browser/event_router.h" | 11 #include "extensions/browser/event_router.h" |
| 12 #include "extensions/browser/extension_prefs.h" | 12 #include "extensions/browser/extension_prefs.h" |
| 13 #include "extensions/browser/extension_system.h" | 13 #include "extensions/browser/extension_system.h" |
| 14 #include "extensions/browser/extensions_browser_client.h" |
| 14 #include "extensions/common/extension.h" | 15 #include "extensions/common/extension.h" |
| 15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 16 | 17 |
| 17 #if defined(OS_CHROMEOS) | 18 using content::BrowserContext; |
| 18 #include "chrome/browser/chromeos/login/user_manager.h" | 19 using extensions::Event; |
| 19 #endif | 20 using extensions::Extension; |
| 21 using extensions::ExtensionPrefs; |
| 22 using extensions::ExtensionSystem; |
| 20 | 23 |
| 21 using content::BrowserContext; | 24 namespace apps { |
| 22 | |
| 23 namespace extensions { | |
| 24 | 25 |
| 25 namespace app_runtime = api::app_runtime; | 26 namespace app_runtime = api::app_runtime; |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 void DispatchOnLaunchedEventImpl(const std::string& extension_id, | 30 void DispatchOnLaunchedEventImpl(const std::string& extension_id, |
| 30 scoped_ptr<base::DictionaryValue> launch_data, | 31 scoped_ptr<base::DictionaryValue> launch_data, |
| 31 BrowserContext* context) { | 32 BrowserContext* context) { |
| 32 #if defined(OS_CHROMEOS) | 33 // "Forced app mode" is true for Chrome OS kiosk mode. |
| 33 launch_data->SetBoolean("isKioskSession", | 34 launch_data->SetBoolean( |
| 34 chromeos::UserManager::Get()->IsLoggedInAsKioskApp()); | 35 "isKioskSession", |
| 35 #else | 36 extensions::ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode()); |
| 36 launch_data->SetBoolean("isKioskSession", false); | |
| 37 #endif | |
| 38 scoped_ptr<base::ListValue> args(new base::ListValue()); | 37 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 39 args->Append(launch_data.release()); | 38 args->Append(launch_data.release()); |
| 40 ExtensionSystem* system = ExtensionSystem::Get(context); | 39 ExtensionSystem* system = ExtensionSystem::Get(context); |
| 41 scoped_ptr<Event> event(new Event(app_runtime::OnLaunched::kEventName, | 40 scoped_ptr<Event> event( |
| 42 args.Pass())); | 41 new Event(app_runtime::OnLaunched::kEventName, args.Pass())); |
| 43 event->restrict_to_browser_context = context; | 42 event->restrict_to_browser_context = context; |
| 44 event->can_load_ephemeral_apps = true; | 43 event->can_load_ephemeral_apps = true; |
| 45 system->event_router()->DispatchEventWithLazyListener(extension_id, | 44 system->event_router()->DispatchEventWithLazyListener(extension_id, |
| 46 event.Pass()); | 45 event.Pass()); |
| 47 ExtensionPrefs::Get(context) | 46 ExtensionPrefs::Get(context) |
| 48 ->SetLastLaunchTime(extension_id, base::Time::Now()); | 47 ->SetLastLaunchTime(extension_id, base::Time::Now()); |
| 49 } | 48 } |
| 50 | 49 |
| 51 } // anonymous namespace | 50 } // anonymous namespace |
| 52 | 51 |
| 53 // static. | 52 // static. |
| 54 void AppEventRouter::DispatchOnLaunchedEvent(BrowserContext* context, | 53 void AppEventRouter::DispatchOnLaunchedEvent(BrowserContext* context, |
| 55 const Extension* extension) { | 54 const Extension* extension) { |
| 56 scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue()); | 55 scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue()); |
| 57 DispatchOnLaunchedEventImpl(extension->id(), launch_data.Pass(), context); | 56 DispatchOnLaunchedEventImpl(extension->id(), launch_data.Pass(), context); |
| 58 } | 57 } |
| 59 | 58 |
| 60 // static. | 59 // static. |
| 61 void AppEventRouter::DispatchOnRestartedEvent(BrowserContext* context, | 60 void AppEventRouter::DispatchOnRestartedEvent(BrowserContext* context, |
| 62 const Extension* extension) { | 61 const Extension* extension) { |
| 63 scoped_ptr<base::ListValue> arguments(new base::ListValue()); | 62 scoped_ptr<base::ListValue> arguments(new base::ListValue()); |
| 64 scoped_ptr<Event> event(new Event(app_runtime::OnRestarted::kEventName, | 63 scoped_ptr<Event> event( |
| 65 arguments.Pass())); | 64 new Event(app_runtime::OnRestarted::kEventName, arguments.Pass())); |
| 66 event->restrict_to_browser_context = context; | 65 event->restrict_to_browser_context = context; |
| 67 event->can_load_ephemeral_apps = true; | 66 event->can_load_ephemeral_apps = true; |
| 68 extensions::ExtensionSystem::Get(context) | 67 extensions::ExtensionSystem::Get(context) |
| 69 ->event_router() | 68 ->event_router() |
| 70 ->DispatchEventToExtension(extension->id(), event.Pass()); | 69 ->DispatchEventToExtension(extension->id(), event.Pass()); |
| 71 } | 70 } |
| 72 | 71 |
| 73 // static. | 72 // static. |
| 74 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( | 73 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
| 75 BrowserContext* context, | 74 BrowserContext* context, |
| 76 const Extension* extension, | 75 const Extension* extension, |
| 77 const std::string& handler_id, | 76 const std::string& handler_id, |
| 78 const std::string& mime_type, | 77 const std::string& mime_type, |
| 79 const extensions::app_file_handler_util::GrantedFileEntry& file_entry) { | 78 const file_handler_util::GrantedFileEntry& file_entry) { |
| 80 // TODO(sergeygs): Use the same way of creating an event (using the generated | 79 // TODO(sergeygs): Use the same way of creating an event (using the generated |
| 81 // boilerplate) as below in DispatchOnLaunchedEventWithUrl. | 80 // boilerplate) as below in DispatchOnLaunchedEventWithUrl. |
| 82 scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue); | 81 scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue); |
| 83 launch_data->SetString("id", handler_id); | 82 launch_data->SetString("id", handler_id); |
| 84 scoped_ptr<base::DictionaryValue> launch_item(new base::DictionaryValue); | 83 scoped_ptr<base::DictionaryValue> launch_item(new base::DictionaryValue); |
| 85 launch_item->SetString("fileSystemId", file_entry.filesystem_id); | 84 launch_item->SetString("fileSystemId", file_entry.filesystem_id); |
| 86 launch_item->SetString("baseName", file_entry.registered_name); | 85 launch_item->SetString("baseName", file_entry.registered_name); |
| 87 launch_item->SetString("mimeType", mime_type); | 86 launch_item->SetString("mimeType", mime_type); |
| 88 launch_item->SetString("entryId", file_entry.id); | 87 launch_item->SetString("entryId", file_entry.id); |
| 89 scoped_ptr<base::ListValue> items(new base::ListValue); | 88 scoped_ptr<base::ListValue> items(new base::ListValue); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 100 const GURL& url, | 99 const GURL& url, |
| 101 const GURL& referrer_url) { | 100 const GURL& referrer_url) { |
| 102 api::app_runtime::LaunchData launch_data; | 101 api::app_runtime::LaunchData launch_data; |
| 103 launch_data.id.reset(new std::string(handler_id)); | 102 launch_data.id.reset(new std::string(handler_id)); |
| 104 launch_data.url.reset(new std::string(url.spec())); | 103 launch_data.url.reset(new std::string(url.spec())); |
| 105 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); | 104 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); |
| 106 DispatchOnLaunchedEventImpl( | 105 DispatchOnLaunchedEventImpl( |
| 107 extension->id(), launch_data.ToValue().Pass(), context); | 106 extension->id(), launch_data.ToValue().Pass(), context); |
| 108 } | 107 } |
| 109 | 108 |
| 110 } // namespace extensions | 109 } // namespace apps |
| OLD | NEW |