Skip to content

Commit

Permalink
Convert app_shell onLaunched stub to use chrome.shell.onLaunched
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jamescook@chromium.org committed May 1, 2014
1 parent 44eda8f commit 7d27834
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 205 deletions.
4 changes: 0 additions & 4 deletions apps/shell/app_shell.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
16 changes: 16 additions & 0 deletions apps/shell/browser/api/shell/shell_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() {
}

Expand Down
16 changes: 16 additions & 0 deletions apps/shell/browser/api/shell/shell_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 0 additions & 28 deletions apps/shell/browser/shell_app_runtime_api.cc

This file was deleted.

28 changes: 0 additions & 28 deletions apps/shell/browser/shell_app_runtime_api.h

This file was deleted.

83 changes: 0 additions & 83 deletions apps/shell/browser/shell_app_window_api.cc

This file was deleted.

31 changes: 0 additions & 31 deletions apps/shell/browser/shell_app_window_api.h

This file was deleted.

5 changes: 2 additions & 3 deletions apps/shell/browser/shell_extension_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 0 additions & 4 deletions apps/shell/browser/shell_extensions_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions apps/shell/common/api/shell.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
};
9 changes: 1 addition & 8 deletions apps/shell/common/shell_extensions_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand All @@ -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);
}

Expand Down
6 changes: 0 additions & 6 deletions chrome/common/extensions/api/_api_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions extensions/common/api/_api_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Loading

0 comments on commit 7d27834

Please sign in to comment.