summaryrefslogtreecommitdiffstats
path: root/apps/browser
diff options
context:
space:
mode:
authorjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-31 01:54:38 +0000
committerjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-31 01:54:38 +0000
commite3a8ebb9866a207a123d7a5f165d35c2f7019b7d (patch)
tree590cb6c1e3af05fceeaab487c041b17e09cf4d66 /apps/browser
parent64304a7356d23cbbe30cc7a61d2a63cc4de90990 (diff)
downloadchromium_src-e3a8ebb9866a207a123d7a5f165d35c2f7019b7d.zip
chromium_src-e3a8ebb9866a207a123d7a5f165d35c2f7019b7d.tar.gz
chromium_src-e3a8ebb9866a207a123d7a5f165d35c2f7019b7d.tar.bz2
Introduce apps API target in //apps and move app.runtime API into it
This breaks a dependency from //apps onto //chrome, getting us closer to an app_shell build that does not include chrome. * Introduce apps/browser/api and apps/common/api to mirror extensions. * Introduce an apps_api build target. * Hook up schema and function registration in chrome and app_shell. * Move app_runtime_api.h/cc into //apps and switch to apps namespace. * Eliminate AppEventRouter dependencies on Chrome: ** Use ExtensionsBrowserClient to determine if we're in kiosk mode. ** Introduce apps::file_handler_util for GrantedFileEntry (anticipating more code from app_file_handler_util to move there in the future). BUG=357818 TEST=browser_tests *PlatformApp* Review URL: https://codereview.chromium.org/217533006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260480 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'apps/browser')
-rw-r--r--apps/browser/api/app_runtime/app_runtime_api.cc109
-rw-r--r--apps/browser/api/app_runtime/app_runtime_api.h72
-rw-r--r--apps/browser/file_handler_util.cc15
-rw-r--r--apps/browser/file_handler_util.h26
4 files changed, 222 insertions, 0 deletions
diff --git a/apps/browser/api/app_runtime/app_runtime_api.cc b/apps/browser/api/app_runtime/app_runtime_api.cc
new file mode 100644
index 0000000..5b52100
--- /dev/null
+++ b/apps/browser/api/app_runtime/app_runtime_api.cc
@@ -0,0 +1,109 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/browser/api/app_runtime/app_runtime_api.h"
+
+#include "apps/browser/file_handler_util.h"
+#include "apps/common/api/app_runtime.h"
+#include "base/time/time.h"
+#include "base/values.h"
+#include "extensions/browser/event_router.h"
+#include "extensions/browser/extension_prefs.h"
+#include "extensions/browser/extension_system.h"
+#include "extensions/browser/extensions_browser_client.h"
+#include "extensions/common/extension.h"
+#include "url/gurl.h"
+
+using content::BrowserContext;
+using extensions::Event;
+using extensions::Extension;
+using extensions::ExtensionPrefs;
+using extensions::ExtensionSystem;
+
+namespace apps {
+
+namespace app_runtime = api::app_runtime;
+
+namespace {
+
+void DispatchOnLaunchedEventImpl(const std::string& extension_id,
+ scoped_ptr<base::DictionaryValue> launch_data,
+ BrowserContext* context) {
+ // "Forced app mode" is true for Chrome OS kiosk mode.
+ launch_data->SetBoolean(
+ "isKioskSession",
+ extensions::ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode());
+ scoped_ptr<base::ListValue> args(new base::ListValue());
+ args->Append(launch_data.release());
+ ExtensionSystem* system = ExtensionSystem::Get(context);
+ scoped_ptr<Event> event(
+ new Event(app_runtime::OnLaunched::kEventName, args.Pass()));
+ event->restrict_to_browser_context = context;
+ event->can_load_ephemeral_apps = true;
+ system->event_router()->DispatchEventWithLazyListener(extension_id,
+ event.Pass());
+ ExtensionPrefs::Get(context)
+ ->SetLastLaunchTime(extension_id, base::Time::Now());
+}
+
+} // anonymous namespace
+
+// static.
+void AppEventRouter::DispatchOnLaunchedEvent(BrowserContext* context,
+ const Extension* extension) {
+ scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue());
+ DispatchOnLaunchedEventImpl(extension->id(), launch_data.Pass(), context);
+}
+
+// static.
+void AppEventRouter::DispatchOnRestartedEvent(BrowserContext* context,
+ const Extension* extension) {
+ scoped_ptr<base::ListValue> arguments(new base::ListValue());
+ scoped_ptr<Event> event(
+ new Event(app_runtime::OnRestarted::kEventName, arguments.Pass()));
+ event->restrict_to_browser_context = context;
+ event->can_load_ephemeral_apps = true;
+ extensions::ExtensionSystem::Get(context)
+ ->event_router()
+ ->DispatchEventToExtension(extension->id(), event.Pass());
+}
+
+// static.
+void AppEventRouter::DispatchOnLaunchedEventWithFileEntry(
+ BrowserContext* context,
+ const Extension* extension,
+ const std::string& handler_id,
+ const std::string& mime_type,
+ const file_handler_util::GrantedFileEntry& file_entry) {
+ // TODO(sergeygs): Use the same way of creating an event (using the generated
+ // boilerplate) as below in DispatchOnLaunchedEventWithUrl.
+ scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue);
+ launch_data->SetString("id", handler_id);
+ scoped_ptr<base::DictionaryValue> launch_item(new base::DictionaryValue);
+ launch_item->SetString("fileSystemId", file_entry.filesystem_id);
+ launch_item->SetString("baseName", file_entry.registered_name);
+ launch_item->SetString("mimeType", mime_type);
+ launch_item->SetString("entryId", file_entry.id);
+ scoped_ptr<base::ListValue> items(new base::ListValue);
+ items->Append(launch_item.release());
+ launch_data->Set("items", items.release());
+ DispatchOnLaunchedEventImpl(extension->id(), launch_data.Pass(), context);
+}
+
+// static.
+void AppEventRouter::DispatchOnLaunchedEventWithUrl(
+ BrowserContext* context,
+ const Extension* extension,
+ const std::string& handler_id,
+ const GURL& url,
+ const GURL& referrer_url) {
+ api::app_runtime::LaunchData launch_data;
+ launch_data.id.reset(new std::string(handler_id));
+ launch_data.url.reset(new std::string(url.spec()));
+ launch_data.referrer_url.reset(new std::string(referrer_url.spec()));
+ DispatchOnLaunchedEventImpl(
+ extension->id(), launch_data.ToValue().Pass(), context);
+}
+
+} // namespace apps
diff --git a/apps/browser/api/app_runtime/app_runtime_api.h b/apps/browser/api/app_runtime/app_runtime_api.h
new file mode 100644
index 0000000..829becf
--- /dev/null
+++ b/apps/browser/api/app_runtime/app_runtime_api.h
@@ -0,0 +1,72 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef APPS_BROWSER_API_APP_RUNTIME_APP_RUNTIME_API_H_
+#define APPS_BROWSER_API_APP_RUNTIME_APP_RUNTIME_API_H_
+
+#include <string>
+
+class GURL;
+
+namespace content {
+class BrowserContext;
+class WebContents;
+}
+
+namespace extensions {
+class Extension;
+}
+
+namespace apps {
+
+namespace file_handler_util {
+struct GrantedFileEntry;
+}
+
+class AppEventRouter {
+ public:
+ // Dispatches the onLaunched event to the given app.
+ static void DispatchOnLaunchedEvent(content::BrowserContext* context,
+ const extensions::Extension* extension);
+
+ // Dispatches the onRestarted event to the given app, providing a list of
+ // restored file entries from the previous run.
+ static void DispatchOnRestartedEvent(content::BrowserContext* context,
+ const extensions::Extension* extension);
+
+ // TODO(benwells): Update this comment, it is out of date.
+ // Dispatches the onLaunched event to the given app, providing launch data of
+ // the form:
+ // {
+ // "intent" : {
+ // "type" : "chrome-extension://fileentry",
+ // "data" : a FileEntry,
+ // "postResults" : a null function,
+ // "postFailure" : a null function
+ // }
+ // }
+
+ // The FileEntry is created from |file_system_id| and |base_name|.
+ // |handler_id| corresponds to the id of the file_handlers item in the
+ // manifest that resulted in a match which triggered this launch.
+ static void DispatchOnLaunchedEventWithFileEntry(
+ content::BrowserContext* context,
+ const extensions::Extension* extension,
+ const std::string& handler_id,
+ const std::string& mime_type,
+ const file_handler_util::GrantedFileEntry& file_entry);
+
+ // |handler_id| corresponds to the id of the url_handlers item
+ // in the manifest that resulted in a match which triggered this launch.
+ static void DispatchOnLaunchedEventWithUrl(
+ content::BrowserContext* context,
+ const extensions::Extension* extension,
+ const std::string& handler_id,
+ const GURL& url,
+ const GURL& referrer_url);
+};
+
+} // namespace apps
+
+#endif // APPS_BROWSER_API_APP_RUNTIME_APP_RUNTIME_API_H_
diff --git a/apps/browser/file_handler_util.cc b/apps/browser/file_handler_util.cc
new file mode 100644
index 0000000..073760a
--- /dev/null
+++ b/apps/browser/file_handler_util.cc
@@ -0,0 +1,15 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/browser/file_handler_util.h"
+
+namespace apps {
+namespace file_handler_util {
+
+GrantedFileEntry::GrantedFileEntry() {}
+
+GrantedFileEntry::~GrantedFileEntry() {}
+
+} // namespace file_handler_util
+} // namespace apps
diff --git a/apps/browser/file_handler_util.h b/apps/browser/file_handler_util.h
new file mode 100644
index 0000000..1d0cfa3
--- /dev/null
+++ b/apps/browser/file_handler_util.h
@@ -0,0 +1,26 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef APPS_BROWSER_FILE_HANDLER_UTIL_H_
+#define APPS_BROWSER_FILE_HANDLER_UTIL_H_
+
+#include <string>
+
+namespace apps {
+namespace file_handler_util {
+
+// Refers to a file entry that a renderer has been given access to.
+struct GrantedFileEntry {
+ GrantedFileEntry();
+ ~GrantedFileEntry();
+
+ std::string id;
+ std::string filesystem_id;
+ std::string registered_name;
+};
+
+} // namespace file_handler_util
+} // namespace apps
+
+#endif // APPS_BROWSER_FILE_HANDLER_UTIL_H_