Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(728)

Side by Side Diff: chrome/browser/extensions/api/app_runtime/app_runtime_api.cc

Issue 217533006: Introduce apps API target in //apps and move app.runtime API into it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix dependencies (app-runtime-move) Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h"
6
7 #include "base/time/time.h"
8 #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"
12 #include "extensions/browser/extension_prefs.h"
13 #include "extensions/browser/extension_system.h"
14 #include "extensions/common/extension.h"
15 #include "url/gurl.h"
16
17 #if defined(OS_CHROMEOS)
18 #include "chrome/browser/chromeos/login/user_manager.h"
19 #endif
20
21 using content::BrowserContext;
22
23 namespace extensions {
24
25 namespace app_runtime = api::app_runtime;
26
27 namespace {
28
29 void DispatchOnLaunchedEventImpl(const std::string& extension_id,
30 scoped_ptr<base::DictionaryValue> launch_data,
31 BrowserContext* context) {
32 #if defined(OS_CHROMEOS)
33 launch_data->SetBoolean("isKioskSession",
34 chromeos::UserManager::Get()->IsLoggedInAsKioskApp());
35 #else
36 launch_data->SetBoolean("isKioskSession", false);
37 #endif
38 scoped_ptr<base::ListValue> args(new base::ListValue());
39 args->Append(launch_data.release());
40 ExtensionSystem* system = ExtensionSystem::Get(context);
41 scoped_ptr<Event> event(new Event(app_runtime::OnLaunched::kEventName,
42 args.Pass()));
43 event->restrict_to_browser_context = context;
44 event->can_load_ephemeral_apps = true;
45 system->event_router()->DispatchEventWithLazyListener(extension_id,
46 event.Pass());
47 ExtensionPrefs::Get(context)
48 ->SetLastLaunchTime(extension_id, base::Time::Now());
49 }
50
51 } // anonymous namespace
52
53 // static.
54 void AppEventRouter::DispatchOnLaunchedEvent(BrowserContext* context,
55 const Extension* extension) {
56 scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue());
57 DispatchOnLaunchedEventImpl(extension->id(), launch_data.Pass(), context);
58 }
59
60 // static.
61 void AppEventRouter::DispatchOnRestartedEvent(BrowserContext* context,
62 const Extension* extension) {
63 scoped_ptr<base::ListValue> arguments(new base::ListValue());
64 scoped_ptr<Event> event(new Event(app_runtime::OnRestarted::kEventName,
65 arguments.Pass()));
66 event->restrict_to_browser_context = context;
67 event->can_load_ephemeral_apps = true;
68 extensions::ExtensionSystem::Get(context)
69 ->event_router()
70 ->DispatchEventToExtension(extension->id(), event.Pass());
71 }
72
73 // static.
74 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry(
75 BrowserContext* context,
76 const Extension* extension,
77 const std::string& handler_id,
78 const std::string& mime_type,
79 const extensions::app_file_handler_util::GrantedFileEntry& file_entry) {
80 // TODO(sergeygs): Use the same way of creating an event (using the generated
81 // boilerplate) as below in DispatchOnLaunchedEventWithUrl.
82 scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue);
83 launch_data->SetString("id", handler_id);
84 scoped_ptr<base::DictionaryValue> launch_item(new base::DictionaryValue);
85 launch_item->SetString("fileSystemId", file_entry.filesystem_id);
86 launch_item->SetString("baseName", file_entry.registered_name);
87 launch_item->SetString("mimeType", mime_type);
88 launch_item->SetString("entryId", file_entry.id);
89 scoped_ptr<base::ListValue> items(new base::ListValue);
90 items->Append(launch_item.release());
91 launch_data->Set("items", items.release());
92 DispatchOnLaunchedEventImpl(extension->id(), launch_data.Pass(), context);
93 }
94
95 // static.
96 void AppEventRouter::DispatchOnLaunchedEventWithUrl(
97 BrowserContext* context,
98 const Extension* extension,
99 const std::string& handler_id,
100 const GURL& url,
101 const GURL& referrer_url) {
102 api::app_runtime::LaunchData launch_data;
103 launch_data.id.reset(new std::string(handler_id));
104 launch_data.url.reset(new std::string(url.spec()));
105 launch_data.referrer_url.reset(new std::string(referrer_url.spec()));
106 DispatchOnLaunchedEventImpl(
107 extension->id(), launch_data.ToValue().Pass(), context);
108 }
109
110 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698