diff options
author | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-31 01:54:38 +0000 |
---|---|---|
committer | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-31 01:54:38 +0000 |
commit | e3a8ebb9866a207a123d7a5f165d35c2f7019b7d (patch) | |
tree | 590cb6c1e3af05fceeaab487c041b17e09cf4d66 /chrome/browser | |
parent | 64304a7356d23cbbe30cc7a61d2a63cc4de90990 (diff) | |
download | chromium_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 'chrome/browser')
9 files changed, 30 insertions, 198 deletions
diff --git a/chrome/browser/apps/app_browsertest.cc b/chrome/browser/apps/app_browsertest.cc index 10c6636c..da15e6f 100644 --- a/chrome/browser/apps/app_browsertest.cc +++ b/chrome/browser/apps/app_browsertest.cc @@ -4,6 +4,7 @@ #include "apps/app_window.h" #include "apps/app_window_registry.h" +#include "apps/common/api/app_runtime.h" #include "apps/launcher.h" #include "apps/ui/native_app_window.h" #include "base/bind.h" @@ -29,7 +30,6 @@ #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/extensions/api/app_runtime.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/test_switches.h" @@ -61,9 +61,9 @@ using apps::AppWindowRegistry; using content::WebContents; using web_modal::WebContentsModalDialogManager; -namespace extensions { +namespace app_runtime = apps::api::app_runtime; -namespace app_runtime = api::app_runtime; +namespace extensions { namespace { diff --git a/chrome/browser/apps/app_launch_for_metro_restart_win.cc b/chrome/browser/apps/app_launch_for_metro_restart_win.cc index f4e8a1d..50c3ce8 100644 --- a/chrome/browser/apps/app_launch_for_metro_restart_win.cc +++ b/chrome/browser/apps/app_launch_for_metro_restart_win.cc @@ -4,6 +4,7 @@ #include "chrome/browser/apps/app_launch_for_metro_restart_win.h" +#include "apps/browser/api/app_runtime/app_runtime_api.h" #include "apps/launcher.h" #include "apps/pref_names.h" #include "base/bind.h" @@ -13,7 +14,6 @@ #include "base/prefs/pref_service.h" #include "base/time/time.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" @@ -40,7 +40,7 @@ void LaunchAppWithId(Profile* profile, if (!extension) return; - extensions::AppEventRouter::DispatchOnLaunchedEvent(profile, extension); + apps::AppEventRouter::DispatchOnLaunchedEvent(profile, extension); } } // namespace diff --git a/chrome/browser/extensions/DEPS b/chrome/browser/extensions/DEPS index b4ab256..b603eef 100644 --- a/chrome/browser/extensions/DEPS +++ b/chrome/browser/extensions/DEPS @@ -16,3 +16,11 @@ include_rules = [ # For access to testing command line switches. "+ppapi/shared_impl", ] + +specific_include_rules = { + # The extensions client interface is the master arbiter of which + # API functions exist, so it needs to know about app APIs. + "chrome_extensions_browser_client\.cc": [ + "+apps/common/api/generated_api.h", + ], +} diff --git a/chrome/browser/extensions/api/app_runtime/app_runtime_api.cc b/chrome/browser/extensions/api/app_runtime/app_runtime_api.cc deleted file mode 100644 index ff40876..0000000 --- a/chrome/browser/extensions/api/app_runtime/app_runtime_api.cc +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) 2012 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 "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" - -#include "base/time/time.h" -#include "base/values.h" -#include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" -#include "chrome/common/extensions/api/app_runtime.h" -#include "extensions/browser/event_router.h" -#include "extensions/browser/extension_prefs.h" -#include "extensions/browser/extension_system.h" -#include "extensions/common/extension.h" -#include "url/gurl.h" - -#if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/login/user_manager.h" -#endif - -using content::BrowserContext; - -namespace extensions { - -namespace app_runtime = api::app_runtime; - -namespace { - -void DispatchOnLaunchedEventImpl(const std::string& extension_id, - scoped_ptr<base::DictionaryValue> launch_data, - BrowserContext* context) { -#if defined(OS_CHROMEOS) - launch_data->SetBoolean("isKioskSession", - chromeos::UserManager::Get()->IsLoggedInAsKioskApp()); -#else - launch_data->SetBoolean("isKioskSession", false); -#endif - 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 extensions::app_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 extensions diff --git a/chrome/browser/extensions/api/app_runtime/app_runtime_api.h b/chrome/browser/extensions/api/app_runtime/app_runtime_api.h deleted file mode 100644 index c34e0a9..0000000 --- a/chrome/browser/extensions/api/app_runtime/app_runtime_api.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_API_APP_RUNTIME_APP_RUNTIME_API_H_ -#define CHROME_BROWSER_EXTENSIONS_API_APP_RUNTIME_APP_RUNTIME_API_H_ - -#include <string> - -class GURL; - -namespace content { -class BrowserContext; -class WebContents; -} - -namespace extensions { - -class Extension; - -namespace app_file_handler_util { -struct GrantedFileEntry; -} - -class AppEventRouter { - public: - // Dispatches the onLaunched event to the given app. - static void DispatchOnLaunchedEvent(content::BrowserContext* context, - const 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 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 Extension* extension, - const std::string& handler_id, - const std::string& mime_type, - const extensions::app_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 Extension* extension, - const std::string& handler_id, - const GURL& url, - const GURL& referrer_url); -}; - -} // namespace extensions - -#endif // CHROME_BROWSER_EXTENSIONS_API_APP_RUNTIME_APP_RUNTIME_API_H_ diff --git a/chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc b/chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc index 2cea377..d27ccac 100644 --- a/chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc +++ b/chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc @@ -4,6 +4,7 @@ #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" +#include "apps/browser/file_handler_util.h" #include "base/file_util.h" #include "base/files/file.h" #include "base/files/file_path.h" @@ -20,6 +21,8 @@ #include "chrome/browser/chromeos/drive/file_system_util.h" #endif +using apps::file_handler_util::GrantedFileEntry; + namespace extensions { namespace app_file_handler_util { @@ -348,8 +351,6 @@ void CheckWritableFiles( checker->Check(); } -GrantedFileEntry::GrantedFileEntry() {} - bool HasFileSystemWritePermission(const Extension* extension) { return extension->HasAPIPermission(APIPermission::kFileSystemWrite); } diff --git a/chrome/browser/extensions/api/file_handlers/app_file_handler_util.h b/chrome/browser/extensions/api/file_handlers/app_file_handler_util.h index 4dd7300..14bd11c 100644 --- a/chrome/browser/extensions/api/file_handlers/app_file_handler_util.h +++ b/chrome/browser/extensions/api/file_handlers/app_file_handler_util.h @@ -16,6 +16,12 @@ class Profile; +namespace apps { +namespace file_handler_util { +struct GrantedFileEntry; +} +} + namespace extensions { class ExtensionPrefs; @@ -51,18 +57,9 @@ bool FileHandlerCanHandleFile( const std::string& mime_type, const base::FilePath& path); -// Refers to a file entry that a renderer has been given access to. -struct GrantedFileEntry { - GrantedFileEntry(); - - std::string id; - std::string filesystem_id; - std::string registered_name; -}; - // Creates a new file entry and allows |renderer_id| to access |path|. This // registers a new file system for |path|. -GrantedFileEntry CreateFileEntry( +apps::file_handler_util::GrantedFileEntry CreateFileEntry( Profile* profile, const Extension* extension, int renderer_id, diff --git a/chrome/browser/extensions/api/file_system/file_system_api.cc b/chrome/browser/extensions/api/file_system/file_system_api.cc index 2e4d2e2..cff70ff 100644 --- a/chrome/browser/extensions/api/file_system/file_system_api.cc +++ b/chrome/browser/extensions/api/file_system/file_system_api.cc @@ -6,6 +6,7 @@ #include "apps/app_window.h" #include "apps/app_window_registry.h" +#include "apps/browser/file_handler_util.h" #include "apps/saved_files_service.h" #include "base/bind.h" #include "base/file_util.h" @@ -322,7 +323,7 @@ void FileSystemEntryFunction::AddEntryToResponse( const base::FilePath& path, const std::string& id_override) { DCHECK(response_); - extensions::app_file_handler_util::GrantedFileEntry file_entry = + apps::file_handler_util::GrantedFileEntry file_entry = extensions::app_file_handler_util::CreateFileEntry( GetProfile(), GetExtension(), diff --git a/chrome/browser/extensions/chrome_extensions_browser_client.cc b/chrome/browser/extensions/chrome_extensions_browser_client.cc index 88d497f..67d76bd 100644 --- a/chrome/browser/extensions/chrome_extensions_browser_client.cc +++ b/chrome/browser/extensions/chrome_extensions_browser_client.cc @@ -4,6 +4,7 @@ #include "chrome/browser/extensions/chrome_extensions_browser_client.h" +#include "apps/common/api/generated_api.h" #include "base/command_line.h" #include "base/version.h" #include "chrome/browser/app_mode/app_mode_utils.h" @@ -228,8 +229,11 @@ void ChromeExtensionsBrowserClient::RegisterExtensionFunctions( registry->RegisterFunction< extensions::chromedirectsetting::ClearDirectSettingFunction>(); - // Generated APIs. + // Generated APIs from lower-level modules. extensions::core_api::GeneratedFunctionRegistry::RegisterAll(registry); + apps::api::GeneratedFunctionRegistry::RegisterAll(registry); + + // Generated APIs from Chrome. extensions::api::GeneratedFunctionRegistry::RegisterAll(registry); #endif } |