diff options
author | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-01 06:22:16 +0000 |
---|---|---|
committer | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-01 06:22:16 +0000 |
commit | 7d27834c659857c372786c7f865fbdf1550e88df (patch) | |
tree | 2443295a057131918823aedd5d33a8a38685073c | |
parent | 44eda8f2d61ea6c8785f3bd007dc644c26d543cd (diff) | |
download | chromium_src-7d27834c659857c372786c7f865fbdf1550e88df.zip chromium_src-7d27834c659857c372786c7f865fbdf1550e88df.tar.gz chromium_src-7d27834c659857c372786c7f865fbdf1550e88df.tar.bz2 |
Convert app_shell onLaunched stub to use chrome.shell.onLaunched
This allows us to remove our hacky chrome.app.runtime stub schema in favor
of a real chrome.shell API generated from an IDL.
Also cleaned up the unused chrome.app.window.create stub and tweaked the
Calculator sample app to allow the use of chrome.shell.onLaunched.
This CL depends on https://codereview.chromium.org/254473011/
BUG=349042
TEST=app_shell --app=<path/to/calculator/app> loads calculator
Review URL: https://codereview.chromium.org/258053010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267462 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | apps/shell/app_shell.gyp | 4 | ||||
-rw-r--r-- | apps/shell/browser/api/shell/shell_api.cc | 16 | ||||
-rw-r--r-- | apps/shell/browser/api/shell/shell_api.h | 16 | ||||
-rw-r--r-- | apps/shell/browser/shell_app_runtime_api.cc | 28 | ||||
-rw-r--r-- | apps/shell/browser/shell_app_runtime_api.h | 28 | ||||
-rw-r--r-- | apps/shell/browser/shell_app_window_api.cc | 83 | ||||
-rw-r--r-- | apps/shell/browser/shell_app_window_api.h | 31 | ||||
-rw-r--r-- | apps/shell/browser/shell_extension_system.cc | 5 | ||||
-rw-r--r-- | apps/shell/browser/shell_extensions_browser_client.cc | 4 | ||||
-rw-r--r-- | apps/shell/common/api/shell.idl | 5 | ||||
-rw-r--r-- | apps/shell/common/shell_extensions_client.cc | 9 | ||||
-rw-r--r-- | chrome/common/extensions/api/_api_features.json | 6 | ||||
-rw-r--r-- | chrome/common/extensions/docs/examples/apps/calculator/app/controller.js | 19 | ||||
-rw-r--r-- | extensions/common/api/_api_features.json | 7 | ||||
-rw-r--r-- | extensions/test/data/platform_app/background.js | 13 |
15 files changed, 69 insertions, 205 deletions
diff --git a/apps/shell/app_shell.gyp b/apps/shell/app_shell.gyp index f655b62..1324ea5 100644 --- a/apps/shell/app_shell.gyp +++ b/apps/shell/app_shell.gyp @@ -108,14 +108,10 @@ 'app/shell_main_delegate.h', 'browser/api/shell/shell_api.cc', 'browser/api/shell/shell_api.h', - 'browser/shell_app_runtime_api.cc', - 'browser/shell_app_runtime_api.h', 'browser/shell_app_sorting.cc', 'browser/shell_app_sorting.h', 'browser/shell_app_window.cc', 'browser/shell_app_window.h', - 'browser/shell_app_window_api.cc', - 'browser/shell_app_window_api.h', 'browser/shell_browser_context.cc', 'browser/shell_browser_context.h', 'browser/shell_browser_main_parts.cc', diff --git a/apps/shell/browser/api/shell/shell_api.cc b/apps/shell/browser/api/shell/shell_api.cc index 6a51667..f06996c 100644 --- a/apps/shell/browser/api/shell/shell_api.cc +++ b/apps/shell/browser/api/shell/shell_api.cc @@ -7,11 +7,16 @@ #include "apps/shell/browser/shell_app_window.h" #include "apps/shell/browser/shell_desktop_controller.h" #include "apps/shell/common/api/shell.h" +#include "base/memory/scoped_ptr.h" #include "base/values.h" +#include "extensions/browser/event_router.h" +#include "extensions/common/extension.h" using base::DictionaryValue; +using base::ListValue; namespace CreateWindow = apps::shell_api::shell::CreateWindow; +namespace OnLaunched = apps::shell_api::shell::OnLaunched; namespace apps { namespace { @@ -27,6 +32,17 @@ DictionaryValue* CreateResult(apps::ShellAppWindow* app_window) { } // namespace +// static +void ShellAPI::DispatchOnLaunchedEvent(extensions::EventRouter* event_router, + const extensions::Extension* extension) { + scoped_ptr<DictionaryValue> launch_data(new DictionaryValue()); + scoped_ptr<ListValue> event_args(new ListValue()); + event_args->Append(launch_data.release()); + scoped_ptr<extensions::Event> event( + new extensions::Event(OnLaunched::kEventName, event_args.Pass())); + event_router->DispatchEventWithLazyListener(extension->id(), event.Pass()); +} + ShellCreateWindowFunction::ShellCreateWindowFunction() { } diff --git a/apps/shell/browser/api/shell/shell_api.h b/apps/shell/browser/api/shell/shell_api.h index d7f02eb..209fc99 100644 --- a/apps/shell/browser/api/shell/shell_api.h +++ b/apps/shell/browser/api/shell/shell_api.h @@ -10,8 +10,24 @@ #include "extensions/browser/extension_function.h" #include "extensions/browser/extension_function_histogram_value.h" +namespace extensions { +class EventRouter; +class Extension; +} + namespace apps { +// Utilities for the chrome.shell API. +class ShellAPI { + public: + // Dispatches the onLaunched event. + static void DispatchOnLaunchedEvent(extensions::EventRouter* event_router, + const extensions::Extension* extension); + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(ShellAPI); +}; + // Implementation of the chrome.shell.createWindow() function for app_shell. // Opens a fullscreen window and invokes the window callback to allow access to // the JS contentWindow. diff --git a/apps/shell/browser/shell_app_runtime_api.cc b/apps/shell/browser/shell_app_runtime_api.cc deleted file mode 100644 index b31610e..0000000 --- a/apps/shell/browser/shell_app_runtime_api.cc +++ /dev/null @@ -1,28 +0,0 @@ -// 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/shell/browser/shell_app_runtime_api.h" - -#include "base/memory/scoped_ptr.h" -#include "base/values.h" -#include "extensions/browser/event_router.h" -#include "extensions/common/extension.h" - -namespace extensions { - -// static -void ShellAppRuntimeAPI::DispatchOnLaunchedEvent(EventRouter* event_router, - const Extension* extension) { - // This is similar to apps::AppEventRouter::DispatchOnLaunchedEvent but - // avoids the dependency on apps. - scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue()); - launch_data->SetBoolean("isKioskSession", false); - scoped_ptr<base::ListValue> event_args(new base::ListValue()); - event_args->Append(launch_data.release()); - scoped_ptr<Event> event( - new Event("app.runtime.onLaunched", event_args.Pass())); - event_router->DispatchEventWithLazyListener(extension->id(), event.Pass()); -} - -} // namespace extensions diff --git a/apps/shell/browser/shell_app_runtime_api.h b/apps/shell/browser/shell_app_runtime_api.h deleted file mode 100644 index 76600da..0000000 --- a/apps/shell/browser/shell_app_runtime_api.h +++ /dev/null @@ -1,28 +0,0 @@ -// 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_SHELL_BROWSER_SHELL_APP_RUNTIME_API_H_ -#define APPS_SHELL_BROWSER_SHELL_APP_RUNTIME_API_H_ - -#include "base/macros.h" - -namespace extensions { - -class EventRouter; -class Extension; - -// A simplified implementation of the chrome.app.runtime API. -class ShellAppRuntimeAPI { - public: - // Dispatches the onLaunched event. - static void DispatchOnLaunchedEvent(EventRouter* event_router, - const Extension* extension); - - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(ShellAppRuntimeAPI); -}; - -} // namespace extensions - -#endif // APPS_SHELL_BROWSER_SHELL_APP_RUNTIME_API_H_ diff --git a/apps/shell/browser/shell_app_window_api.cc b/apps/shell/browser/shell_app_window_api.cc deleted file mode 100644 index 136a0ce..0000000 --- a/apps/shell/browser/shell_app_window_api.cc +++ /dev/null @@ -1,83 +0,0 @@ -// 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/shell/browser/shell_app_window_api.h" - -#include "apps/shell/browser/shell_app_window.h" -#include "apps/shell/browser/shell_desktop_controller.h" -#include "base/values.h" - -using base::DictionaryValue; - -namespace extensions { -namespace { - -// Returns stub values for window bounds. -DictionaryValue* CreateStubBoundsProperties() { - DictionaryValue* properties = new DictionaryValue; - properties->SetInteger("left", 0); - properties->SetInteger("top", 0); - properties->SetInteger("width", 0); - properties->SetInteger("height", 0); - return properties; -} - -// Creates a function call result to send to the renderer. -DictionaryValue* CreateResult(apps::ShellAppWindow* app_window) { - int view_id = app_window->GetRenderViewRoutingID(); - - DictionaryValue* result = new DictionaryValue; - result->Set("viewId", new base::FundamentalValue(view_id)); - result->Set("injectTitlebar", new base::FundamentalValue(false)); - result->Set("id", new base::StringValue("app_shell")); - - // Add stub window property data. - result->SetBoolean("fullscreen", true); - result->SetBoolean("minimized", false); - result->SetBoolean("maximized", false); - result->SetBoolean("alwaysOnTop", false); - result->SetBoolean("hasFrameColor", false); - result->SetInteger("frameColor", 0); - result->Set("innerBounds", CreateStubBoundsProperties()); - result->Set("outerBounds", CreateStubBoundsProperties()); - - return result; -} - -} // namespace - -ShellAppWindowCreateFunction::ShellAppWindowCreateFunction() {} - -ShellAppWindowCreateFunction::~ShellAppWindowCreateFunction() {} - -bool ShellAppWindowCreateFunction::RunImpl() { - // Arguments must contain a URL and may contain options and a callback. - if (args_->GetSize() < 1 || args_->GetSize() > 3) - return false; - - // Extract the URL for the window contents, e.g. "main.html". - std::string url_string; - if (!args_->GetString(0, &url_string)) - return false; - - // Convert "main.html" to "chrome-extension:/<id>/main.html". - GURL url = GetExtension()->GetResourceURL(url_string); - if (!url.is_valid()) - return false; - - // The desktop keeps ownership of the window. - apps::ShellAppWindow* app_window = - apps::ShellDesktopController::instance()->CreateAppWindow( - browser_context()); - app_window->LoadURL(url); - - // Create the reply to send to the renderer. - DictionaryValue* result = CreateResult(app_window); - SetResult(result); - - SendResponse(true /* success */); - return true; -} - -} // namespace extensions diff --git a/apps/shell/browser/shell_app_window_api.h b/apps/shell/browser/shell_app_window_api.h deleted file mode 100644 index d805dff..0000000 --- a/apps/shell/browser/shell_app_window_api.h +++ /dev/null @@ -1,31 +0,0 @@ -// 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_SHELL_BROWSER_SHELL_APP_WINDOW_API_H_ -#define APPS_SHELL_BROWSER_SHELL_APP_WINDOW_API_H_ - -#include "base/compiler_specific.h" -#include "extensions/browser/extension_function.h" - -namespace extensions { - -// A simplified implementation of the chrome.app.window.create() function for -// app_shell. Opens a fullscreen window and invokes the window callback. Most -// of the response is stub data, but the JS contentWindow is valid. -class ShellAppWindowCreateFunction : public UIThreadExtensionFunction { - public: - ShellAppWindowCreateFunction(); - - // Don't use the APP_WINDOW_CREATE histogram so we don't pollute the - // statistics for the real Chrome implementation. - DECLARE_EXTENSION_FUNCTION("app.window.create", UNKNOWN); - - private: - virtual ~ShellAppWindowCreateFunction(); - virtual bool RunImpl() OVERRIDE; -}; - -} // namespace extensions - -#endif // APPS_SHELL_BROWSER_SHELL_APP_WINDOW_API_H_ diff --git a/apps/shell/browser/shell_extension_system.cc b/apps/shell/browser/shell_extension_system.cc index 37bb147..f6a3b85 100644 --- a/apps/shell/browser/shell_extension_system.cc +++ b/apps/shell/browser/shell_extension_system.cc @@ -6,7 +6,7 @@ #include <string> -#include "apps/shell/browser/shell_app_runtime_api.h" +#include "apps/shell/browser/api/shell/shell_api.h" #include "base/files/file_path.h" #include "chrome/browser/chrome_notification_types.h" #include "content/public/browser/browser_context.h" @@ -71,8 +71,7 @@ bool ShellExtensionSystem::LoadAndLaunchApp(const base::FilePath& app_dir) { content::NotificationService::NoDetails()); // Send the onLaunched event. - ShellAppRuntimeAPI::DispatchOnLaunchedEvent(event_router_.get(), - extension.get()); + apps::ShellAPI::DispatchOnLaunchedEvent(event_router_.get(), extension.get()); return true; } diff --git a/apps/shell/browser/shell_extensions_browser_client.cc b/apps/shell/browser/shell_extensions_browser_client.cc index e84bf09..769350c 100644 --- a/apps/shell/browser/shell_extensions_browser_client.cc +++ b/apps/shell/browser/shell_extensions_browser_client.cc @@ -5,7 +5,6 @@ #include "apps/shell/browser/shell_extensions_browser_client.h" #include "apps/shell/browser/shell_app_sorting.h" -#include "apps/shell/browser/shell_app_window_api.h" #include "apps/shell/browser/shell_extension_system_factory.h" #include "apps/shell/browser/shell_extension_web_contents_observer.h" #include "apps/shell/common/api/generated_api.h" @@ -234,9 +233,6 @@ void ShellExtensionsBrowserClient::RegisterExtensionFunctions( // Register chrome.shell APIs. apps::shell_api::GeneratedFunctionRegistry::RegisterAll(registry); - - // Register our simplified implementation for chrome.app.window.create(). - registry->RegisterFunction<ShellAppWindowCreateFunction>(); } } // namespace extensions diff --git a/apps/shell/common/api/shell.idl b/apps/shell/common/api/shell.idl index c57512f..7734a71 100644 --- a/apps/shell/common/api/shell.idl +++ b/apps/shell/common/api/shell.idl @@ -47,4 +47,9 @@ namespace shell { [nocompile] static AppWindow currentWindow(); [nocompile, nodoc] static void initializeAppWindow(); }; + + interface Events { + // Fired when the app is launched at app_shell startup. + static void onLaunched(optional object launchDataPlaceholder); + }; }; diff --git a/apps/shell/common/shell_extensions_client.cc b/apps/shell/common/shell_extensions_client.cc index 959464c..4d08fc6 100644 --- a/apps/shell/common/shell_extensions_client.cc +++ b/apps/shell/common/shell_extensions_client.cc @@ -5,7 +5,6 @@ #include "apps/shell/common/shell_extensions_client.h" #include "apps/shell/common/api/generated_schemas.h" -#include "apps/shell/common/shell_app_runtime.h" #include "base/logging.h" #include "chrome/common/extensions/api/generated_schemas.h" #include "chrome/common/extensions/permissions/chrome_api_permissions.h" @@ -193,8 +192,7 @@ bool ShellExtensionsClient::IsAPISchemaGenerated( // have the Chrome app APIs available. return extensions::api::GeneratedSchemas::IsGenerated(name) || extensions::core_api::GeneratedSchemas::IsGenerated(name) || - apps::shell_api::GeneratedSchemas::IsGenerated(name) || - name == extensions::ShellAppRuntime::GetName(); + apps::shell_api::GeneratedSchemas::IsGenerated(name); } base::StringPiece ShellExtensionsClient::GetAPISchema( @@ -208,11 +206,6 @@ base::StringPiece ShellExtensionsClient::GetAPISchema( if (apps::shell_api::GeneratedSchemas::IsGenerated(name)) return apps::shell_api::GeneratedSchemas::Get(name); - // Special-case our simplified app.runtime implementation. - // TODO(jamescook): Move this into a chrome.shell.onLaunched() event. - if (name == extensions::ShellAppRuntime::GetName()) - return extensions::ShellAppRuntime::GetSchema(); - return extensions::core_api::GeneratedSchemas::Get(name); } diff --git a/chrome/common/extensions/api/_api_features.json b/chrome/common/extensions/api/_api_features.json index 4592b02..e1775c4 100644 --- a/chrome/common/extensions/api/_api_features.json +++ b/chrome/common/extensions/api/_api_features.json @@ -644,12 +644,6 @@ "dependencies": ["permission:sessions"], "contexts": ["blessed_extension"] }, - // TODO(jamescook): Move this to app_shell _api_features.json once that file - // exists. - "shell": { - "contexts": ["blessed_extension"], - "extension_types": ["platform_app"] - }, "signedInDevices": { "dependencies": ["permission:signedInDevices"], "contexts": ["blessed_extension"] diff --git a/chrome/common/extensions/docs/examples/apps/calculator/app/controller.js b/chrome/common/extensions/docs/examples/apps/calculator/app/controller.js index 1441990..2859080 100644 --- a/chrome/common/extensions/docs/examples/apps/calculator/app/controller.js +++ b/chrome/common/extensions/docs/examples/apps/calculator/app/controller.js @@ -4,15 +4,20 @@ * found in the LICENSE file. **/ -// Checking for "chrome.app.runtime" availability allows this Chrome app code to -// be tested in a regular web page (like tests/manual.html). Checking for -// "chrome" and "chrome.app" availability further allows this code to be tested -// in non-Chrome browsers, which is useful for example to test touch support -// with a non-Chrome touch device. -if (typeof chrome !== 'undefined' && chrome.app && chrome.app.runtime) { +// Checking for "chrome" availability allows this app code to be tested in +// non-Chrome browsers, which is useful for example to test touch support with +// a non-Chrome touch device. +// Checking for "chrome.shell" allows testing under app_shell, which does not +// have chrome.app APIs. +// Checking for "chrome.app.runtime" availability allows testing in a regular +// web page (like tests/manual.html). +if (typeof chrome !== 'undefined' && + (chrome.shell || (chrome.app && chrome.app.runtime))) { // Compatibility for running under app_shell, which does not have app.window. var createWindow = chrome.shell ? chrome.shell.createWindow : chrome.app.window.create; + var onLaunched = + chrome.shell ? chrome.shell.onLaunched : chrome.app.runtime.onLaunched; var showCalculatorWindow = function () { createWindow('calculator.html', { @@ -28,7 +33,7 @@ if (typeof chrome !== 'undefined' && chrome.app && chrome.app.runtime) { }); } - chrome.app.runtime.onLaunched.addListener(showCalculatorWindow); + onLaunched.addListener(showCalculatorWindow); } function Controller(model, view) { diff --git a/extensions/common/api/_api_features.json b/extensions/common/api/_api_features.json index cae93b1..8dbeb14 100644 --- a/extensions/common/api/_api_features.json +++ b/extensions/common/api/_api_features.json @@ -14,6 +14,13 @@ "dependencies": ["permission:dns"], "contexts": ["blessed_extension"] }, + // TODO(jamescook): Move this to app_shell _api_features.json once that file + // exists. + "shell": { + "channel": "dev", + "contexts": ["blessed_extension"], + "extension_types": ["platform_app"] + }, "socket": { "dependencies": ["permission:socket"], "contexts": ["blessed_extension"] diff --git a/extensions/test/data/platform_app/background.js b/extensions/test/data/platform_app/background.js index 9820db7..6e788e0 100644 --- a/extensions/test/data/platform_app/background.js +++ b/extensions/test/data/platform_app/background.js @@ -1,9 +1,16 @@ // 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. -chrome.app.runtime.onLaunched.addListener(function() { - chrome.app.window.create('hello.html', { - 'bounds': { + +// Stub for app_shell. +var createWindow = + chrome.shell ? chrome.shell.createWindow : chrome.app.window.create; +var onLaunched = + chrome.shell ? chrome.shell.onLaunched : chrome.app.runtime.onLaunched; + +onLaunched.addListener(function() { + createWindow('hello.html', { + 'innerBounds': { 'width': 400, 'height': 300 } |