mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Unfork streamsPrivate API and add resourcesPrivate and tabs zoom APIs required by the PDF extension (issue #1947)
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
This directory provides Mojo API definitions for CEF.
|
||||
|
||||
To add a new Mojo API:
|
||||
This directory provides API definitions for CEF. Some extensions are implemented
|
||||
using Mojo and others use an older JSON-based format.
|
||||
|
||||
<api> is the name of the API definition (e.g. 'streams_private').
|
||||
<class> is the name of the class implementation (e.g. 'StreamsPrivateAPI').
|
||||
|
||||
1. Add libcef/common/extensions/api/<api>.idl file which defines the API.
|
||||
2. Add <api>.idl to the 'schema_files' list in
|
||||
To add a new extension API implemented only in CEF ***:
|
||||
|
||||
1. Add libcef/common/extensions/api/<api>.idl or .json file which defines the
|
||||
API.
|
||||
2. Add <api>.idl or .json to the 'schema_files' list in
|
||||
libcef/common/extensions/api/schemas.gypi. Serialization code will be
|
||||
generated based on this list in step 5.
|
||||
3. Add an entry to libcef/common/extensions/api/_api_features.json if
|
||||
3. Add an entry in the libcef/common/extensions/api/_*_features.json files if
|
||||
necessary [1].
|
||||
4. Add libcef/browser/extensions/api/<api>/<api>_api.[h|cc] class implementation
|
||||
files and associated entries to the 'libcef_static' target in cef.gyp.
|
||||
@@ -23,11 +25,26 @@ To add a new Mojo API:
|
||||
CefExtensionSystemFactory::CefExtensionSystemFactory in
|
||||
libcef/browser/extensions/extension_system_factory.cc if necessary [2].
|
||||
|
||||
*** Note that CEF does not currently expose its own Mojo APIs. Related code is
|
||||
commented out in:
|
||||
BUILD.gn
|
||||
cef.gyp
|
||||
CefExtensionsBrowserClient::RegisterExtensionFunctions
|
||||
CefExtensionsClient::IsAPISchemaGenerated
|
||||
CefExtensionsClient::GetAPISchema
|
||||
|
||||
To add a new extension API implemented in Chrome:
|
||||
|
||||
1. Register the API in libcef/browser/extensions/chrome_api_registration.cc
|
||||
2. Perform steps 3, 6 and 7 above.
|
||||
|
||||
See https://www.chromium.org/developers/design-documents/mojo for more
|
||||
information.
|
||||
|
||||
[1] A feature can optionally express requirements for where it can be accessed.
|
||||
See the _api_features.json file for additional details.
|
||||
See the _api_features.json and _permission_features.json files for
|
||||
additional details. For Chrome extensions this should match the definitions
|
||||
in the chrome/common/extensions/api/_*_features.json files.
|
||||
|
||||
[2] Some Mojo APIs use singleton Factory objects that create a one-to-one
|
||||
relationship between a service and a BrowserContext. This is used primarily
|
||||
|
@@ -6,6 +6,9 @@
|
||||
// See extensions/common/features/* to understand this file, in particular
|
||||
// feature.h, simple_feature.h, and base_feature_provider.h.
|
||||
|
||||
// If APIs are defined in chrome then entries must also be added in
|
||||
// libcef/browser/extensions/chrome_api_registration.cc.
|
||||
|
||||
{
|
||||
// From chrome/common/extensions/api/_api_features.json.
|
||||
// Required by the PDF extension which is hosted in a guest view.
|
||||
@@ -14,5 +17,20 @@
|
||||
"contexts": "all",
|
||||
"channel": "stable",
|
||||
"matches": ["<all_urls>"]
|
||||
},
|
||||
"resourcesPrivate": [{
|
||||
"dependencies": ["permission:resourcesPrivate"],
|
||||
"contexts": ["blessed_extension"]
|
||||
}, {
|
||||
"channel": "stable",
|
||||
"contexts": ["webui"],
|
||||
"matches": [
|
||||
"chrome://print/*"
|
||||
]
|
||||
}],
|
||||
"tabs": {
|
||||
"channel": "stable",
|
||||
"extension_types": ["extension", "legacy_packaged_app"],
|
||||
"contexts": ["blessed_extension", "extension_service_worker"]
|
||||
}
|
||||
}
|
||||
|
37
libcef/common/extensions/api/_permission_features.json
Normal file
37
libcef/common/extensions/api/_permission_features.json
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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.
|
||||
|
||||
// This file defines permissions for extension APIs implemented by CEF.
|
||||
// See extensions/common/features/* to understand this file, in particular
|
||||
// feature.h, simple_feature.h, and base_feature_provider.h.
|
||||
|
||||
// If APIs are defined in chrome then entries must also be added in
|
||||
// libcef/browser/extensions/chrome_api_registration.cc.
|
||||
|
||||
{
|
||||
// From chrome/common/extensions/api/_permission_features.json.
|
||||
// Required by the PDF extension which is hosted in a guest view.
|
||||
"resourcesPrivate": {
|
||||
"channel": "stable",
|
||||
"extension_types": [
|
||||
"extension", "legacy_packaged_app", "platform_app"
|
||||
],
|
||||
"location": "component"
|
||||
},
|
||||
"tabs": [
|
||||
{
|
||||
"channel": "stable",
|
||||
"extension_types": ["extension", "legacy_packaged_app"]
|
||||
},
|
||||
{
|
||||
"channel": "stable",
|
||||
"extension_types": ["platform_app"],
|
||||
"whitelist": [
|
||||
"AE27D69DBE571F4B1694F05C89B710C646792231", // Published ADT.
|
||||
// TODO(grv): clean up once Apps developer tool is published.
|
||||
"5107DE9024C329EEA9C9A72D94C16723790C6422" // Apps Developer Tool.
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@@ -8,11 +8,11 @@
|
||||
],
|
||||
'variables': {
|
||||
'schema_files': [
|
||||
'streams_private.idl',
|
||||
# TODO(cef): Add CEF-specific Mojo APIs here.
|
||||
],
|
||||
'non_compiled_schema_files': [
|
||||
],
|
||||
|
||||
|
||||
'chromium_code': 1,
|
||||
'cc_dir': 'cef/libcef/common/extensions/api',
|
||||
'root_namespace': 'extensions::api::cef::%(namespace)s',
|
||||
|
@@ -1,57 +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.
|
||||
|
||||
// Streams Private API.
|
||||
namespace streamsPrivate {
|
||||
dictionary StreamInfo {
|
||||
// The MIME type of the intercepted URL request.
|
||||
DOMString mimeType;
|
||||
|
||||
// The original URL that was intercepted.
|
||||
DOMString originalUrl;
|
||||
|
||||
// The URL that the stream can be read from.
|
||||
DOMString streamUrl;
|
||||
|
||||
// The ID of the tab that opened the stream. If the stream is not opened in
|
||||
// a tab, it will be -1.
|
||||
long tabId;
|
||||
|
||||
// The ID of the view that will render the stream, if the viewer was opened
|
||||
// in a plugin.
|
||||
DOMString? viewId;
|
||||
|
||||
// The amount of data the Stream should contain, if known. If there is no
|
||||
// information on the size it will be -1.
|
||||
long expectedContentSize;
|
||||
|
||||
// The HTTP response headers of the intercepted request stored as a
|
||||
// dictionary mapping header name to header value. If a header name appears
|
||||
// multiple times, the header values are merged in the dictionary and
|
||||
// separated by a ", ".
|
||||
object responseHeaders;
|
||||
|
||||
// Whether the stream is embedded within another document.
|
||||
boolean embedded;
|
||||
};
|
||||
|
||||
callback AbortCallback = void ();
|
||||
|
||||
interface Functions {
|
||||
// Abort the URL request on the given stream.
|
||||
// |streamUrl| : The URL of the stream to abort.
|
||||
// |callback| : Called when the stream URL is guaranteed to be invalid. The
|
||||
// underlying URL request may not yet have been aborted when this is run.
|
||||
static void abort(DOMString streamUrl,
|
||||
optional AbortCallback callback);
|
||||
};
|
||||
|
||||
interface Events {
|
||||
// Fired when a resource is fetched which matches a mime type handled by
|
||||
// this extension. The resource request is cancelled, and the extension is
|
||||
// expected to handle the request. The event is restricted to a small number
|
||||
// of white-listed extensions.
|
||||
static void onExecuteMimeTypeHandler(StreamInfo streamInfo);
|
||||
};
|
||||
};
|
32
libcef/common/extensions/chrome_generated_schemas.cc
Normal file
32
libcef/common/extensions/chrome_generated_schemas.cc
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2016 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 "libcef/common/extensions/chrome_generated_schemas.h"
|
||||
|
||||
#include "libcef/browser/extensions/chrome_api_registration.h"
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "chrome/common/extensions/api/generated_schemas.h"
|
||||
|
||||
namespace extensions {
|
||||
namespace api {
|
||||
namespace cef {
|
||||
|
||||
// static
|
||||
base::StringPiece ChromeGeneratedSchemas::Get(const std::string& name) {
|
||||
if (!ChromeFunctionRegistry::IsSupported(name))
|
||||
return base::StringPiece();
|
||||
return extensions::api::ChromeGeneratedSchemas::Get(name);
|
||||
}
|
||||
|
||||
// static
|
||||
bool ChromeGeneratedSchemas::IsGenerated(std::string name) {
|
||||
if (!ChromeFunctionRegistry::IsSupported(name))
|
||||
return false;
|
||||
return extensions::api::ChromeGeneratedSchemas::IsGenerated(name);
|
||||
}
|
||||
|
||||
} // namespace cef
|
||||
} // namespace api
|
||||
} // namespace extensions
|
34
libcef/common/extensions/chrome_generated_schemas.h
Normal file
34
libcef/common/extensions/chrome_generated_schemas.h
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) 2016 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.
|
||||
|
||||
// GENERATED FROM THE API DEFINITIONS IN
|
||||
// chrome\common\extensions\api
|
||||
// DO NOT EDIT.
|
||||
|
||||
#ifndef CEF_LIBCEF_COMMON_EXTENSIONS_CHROME_GENERATED_SCHEMAS_H_
|
||||
#define CEF_LIBCEF_COMMON_EXTENSIONS_CHROME_GENERATED_SCHEMAS_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "base/strings/string_piece.h"
|
||||
|
||||
namespace extensions {
|
||||
namespace api {
|
||||
namespace cef {
|
||||
|
||||
class ChromeGeneratedSchemas {
|
||||
public:
|
||||
// Determines if schema named |name| is generated.
|
||||
static bool IsGenerated(std::string name);
|
||||
|
||||
// Gets the API schema named |name|.
|
||||
static base::StringPiece Get(const std::string& name);
|
||||
};
|
||||
|
||||
} // namespace cef
|
||||
} // namespace api
|
||||
} // namespace extensions
|
||||
|
||||
#endif // CEF_LIBCEF_COMMON_EXTENSIONS_CHROME_GENERATED_SCHEMAS_H_
|
@@ -8,11 +8,13 @@
|
||||
#include <utility>
|
||||
|
||||
#include "libcef/common/cef_switches.h"
|
||||
#include "libcef/common/extensions/chrome_generated_schemas.h"
|
||||
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/logging.h"
|
||||
#include "cef/grit/cef_resources.h"
|
||||
#include "cef/libcef/common/extensions/api/generated_schemas.h"
|
||||
//#include "cef/libcef/common/extensions/api/generated_schemas.h"
|
||||
#include "chrome/common/extensions/chrome_manifest_handlers.h"
|
||||
#include "chrome/grit/common_resources.h"
|
||||
#include "extensions/common/api/generated_schemas.h"
|
||||
#include "extensions/common/common_manifest_handlers.h"
|
||||
#include "extensions/common/extension_urls.h"
|
||||
@@ -39,44 +41,9 @@ SimpleFeature* CreateFeature() {
|
||||
return new FeatureClass;
|
||||
}
|
||||
|
||||
// TODO(jamescook): Refactor ChromePermissionsMessageProvider so we can share
|
||||
// code. For now, this implementation does nothing.
|
||||
class CefPermissionMessageProvider : public PermissionMessageProvider {
|
||||
public:
|
||||
CefPermissionMessageProvider() {}
|
||||
~CefPermissionMessageProvider() override {}
|
||||
|
||||
// PermissionMessageProvider implementation.
|
||||
PermissionMessages GetPermissionMessages(
|
||||
const PermissionIDSet& permissions) const override {
|
||||
return PermissionMessages();
|
||||
}
|
||||
|
||||
bool IsPrivilegeIncrease(const PermissionSet& old_permissions,
|
||||
const PermissionSet& new_permissions,
|
||||
Manifest::Type extension_type) const override {
|
||||
// Ensure we implement this before shipping.
|
||||
CHECK(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
PermissionIDSet GetAllPermissionIDs(
|
||||
const PermissionSet& permissions,
|
||||
Manifest::Type extension_type) const override {
|
||||
return PermissionIDSet();
|
||||
}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(CefPermissionMessageProvider);
|
||||
};
|
||||
|
||||
base::LazyInstance<CefPermissionMessageProvider>
|
||||
g_permission_message_provider = LAZY_INSTANCE_INITIALIZER;
|
||||
|
||||
} // namespace
|
||||
|
||||
CefExtensionsClient::CefExtensionsClient()
|
||||
: extensions_api_permissions_(ExtensionsAPIPermissions()) {
|
||||
CefExtensionsClient::CefExtensionsClient() {
|
||||
}
|
||||
|
||||
CefExtensionsClient::~CefExtensionsClient() {
|
||||
@@ -84,16 +51,18 @@ CefExtensionsClient::~CefExtensionsClient() {
|
||||
|
||||
void CefExtensionsClient::Initialize() {
|
||||
RegisterCommonManifestHandlers();
|
||||
RegisterChromeManifestHandlers();
|
||||
ManifestHandler::FinalizeRegistration();
|
||||
// TODO(jamescook): Do we need to whitelist any extensions?
|
||||
|
||||
// Set up permissions.
|
||||
PermissionsInfo::GetInstance()->AddProvider(chrome_api_permissions_);
|
||||
PermissionsInfo::GetInstance()->AddProvider(extensions_api_permissions_);
|
||||
}
|
||||
|
||||
const PermissionMessageProvider&
|
||||
CefExtensionsClient::GetPermissionMessageProvider() const {
|
||||
NOTIMPLEMENTED();
|
||||
return g_permission_message_provider.Get();
|
||||
return permission_message_provider_;
|
||||
}
|
||||
|
||||
const std::string CefExtensionsClient::GetProductName() {
|
||||
@@ -132,12 +101,19 @@ CefExtensionsClient::CreateFeatureProviderSource(
|
||||
source->LoadJSON(IDR_EXTENSION_API_FEATURES);
|
||||
|
||||
// Extension API features specific to CEF. See
|
||||
// libcef/common/extensions/api/README.txt for additional details.
|
||||
// libcef/common/extensions/api/README.txt for additional details.
|
||||
source->LoadJSON(IDR_CEF_EXTENSION_API_FEATURES);
|
||||
} else if (name == "manifest") {
|
||||
source->LoadJSON(IDR_EXTENSION_MANIFEST_FEATURES);
|
||||
|
||||
// Use the same manifest features as Chrome.
|
||||
source->LoadJSON(IDR_CHROME_EXTENSION_MANIFEST_FEATURES);
|
||||
} else if (name == "permission") {
|
||||
source->LoadJSON(IDR_EXTENSION_PERMISSION_FEATURES);
|
||||
|
||||
// Extension permission features specific to CEF. See
|
||||
// libcef/common/extensions/api/README.txt for additional details.
|
||||
source->LoadJSON(IDR_CEF_EXTENSION_PERMISSION_FEATURES);
|
||||
} else if (name == "behavior") {
|
||||
source->LoadJSON(IDR_EXTENSION_BEHAVIOR_FEATURES);
|
||||
} else {
|
||||
@@ -178,15 +154,34 @@ bool CefExtensionsClient::IsScriptableURL(const GURL& url,
|
||||
|
||||
bool CefExtensionsClient::IsAPISchemaGenerated(
|
||||
const std::string& name) const {
|
||||
return api::GeneratedSchemas::IsGenerated(name) ||
|
||||
api::cef::CefGeneratedSchemas::IsGenerated(name);
|
||||
// Schema for CEF-only APIs.
|
||||
// TODO(cef): Enable if/when CEF exposes its own Mojo APIs. See
|
||||
// libcef/common/extensions/api/README.txt for details.
|
||||
//if (api::cef::CefGeneratedSchemas::IsGenerated(name))
|
||||
// return true;
|
||||
|
||||
// Chrome APIs whitelisted by CEF.
|
||||
if (api::cef::ChromeGeneratedSchemas::IsGenerated(name))
|
||||
return true;
|
||||
|
||||
// Core extensions APIs.
|
||||
if (api::GeneratedSchemas::IsGenerated(name))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
base::StringPiece CefExtensionsClient::GetAPISchema(
|
||||
const std::string& name) const {
|
||||
// Schema for CEF-only APIs.
|
||||
if (api::cef::CefGeneratedSchemas::IsGenerated(name))
|
||||
return api::cef::CefGeneratedSchemas::Get(name);
|
||||
// TODO(cef): Enable if/when CEF exposes its own Mojo APIs. See
|
||||
// libcef/common/extensions/api/README.txt for details.
|
||||
//if (api::cef::CefGeneratedSchemas::IsGenerated(name))
|
||||
// return api::cef::CefGeneratedSchemas::Get(name);
|
||||
|
||||
// Chrome APIs whitelisted by CEF.
|
||||
if (api::cef::ChromeGeneratedSchemas::IsGenerated(name))
|
||||
return api::cef::ChromeGeneratedSchemas::Get(name);
|
||||
|
||||
// Core extensions APIs.
|
||||
return api::GeneratedSchemas::Get(name);
|
||||
|
@@ -8,6 +8,8 @@
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/macros.h"
|
||||
#include "chrome/common/extensions/permissions/chrome_api_permissions.h"
|
||||
#include "chrome/common/extensions/permissions/chrome_permission_message_provider.h"
|
||||
#include "extensions/common/extensions_client.h"
|
||||
#include "extensions/common/permissions/extensions_api_permissions.h"
|
||||
|
||||
@@ -47,7 +49,9 @@ class CefExtensionsClient : public ExtensionsClient {
|
||||
bool IsBlacklistUpdateURL(const GURL& url) const override;
|
||||
|
||||
private:
|
||||
const ChromeAPIPermissions chrome_api_permissions_;
|
||||
const ExtensionsAPIPermissions extensions_api_permissions_;
|
||||
const ChromePermissionMessageProvider permission_message_provider_;
|
||||
|
||||
ScriptingWhitelist scripting_whitelist_;
|
||||
|
||||
|
Reference in New Issue
Block a user