chromium/chrome/browser/ui/webui/extensions/extensions_internals_source.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/webui/extensions/extensions_internals_source.h"

#include <memory>
#include <string>
#include <string_view>
#include <utility>

#include "base/containers/flat_map.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/webui_url_constants.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/activity.h"
#include "extensions/browser/disable_reason.h"
#include "extensions/browser/event_listener_map.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/manifest_handlers/permissions_parser.h"
#include "extensions/common/permissions/permission_set.h"
#include "extensions/common/permissions/permissions_data.h"

ManifestLocation;

namespace {

const char* TypeToString(extensions::Manifest::Type type) {}

const char* LocationToString(ManifestLocation loc) {}

base::Value::List CreationFlagsToList(int creation_flags) {}

base::Value::List DisableReasonsToList(int disable_reasons) {}

// The JSON we generate looks like this:
// Note:
// - tab_specific permissions can have 0 or more DICT entries with each tab id
//   pointing to the api, explicit_host, manifest and scriptable_host permission
//   lists.
// - In some cases manifest or api permissions rather than just being a STRING
//   can be a DICT with the name keying a more complex object with detailed
//   information. This is the case for subclasses of ManifestPermission and
//   APIPermission which override the ToValue function.
// - "background_page_keepalives" and "service_worker_keepalives" are mutually
//    exclusive.
//
// [ {
//    "background_page_keepalives": {
//       "activities": [ {
//          "extra_data": "render-frame",
//          "type": "PROCESS_MANAGER"
//       } ],
//       "count": 1
//    },
//    "creation_flags": [ "ALLOW_FILE_ACCESS", "FROM_WEBSTORE" ],
//    "disable_reasons": ["DISABLE_USER_ACTION"],
//    "event_listeners": {
//       "count": 2,
//       "events": [ {
//          "name": "runtime.onInstalled"
//       }, {
//          "name": "runtime.onSuspend"
//       } ]
//    },
//    "id": "bhloflhklmhfpedakmangadcdofhnnoh",
//    "location": "INTERNAL",
//    "manifest_version": 2,
//    "name": "Earth View from Google Earth",
//    "path": "/user/Extensions/bhloflhklmhfpedakmangadcdofhnnoh/2.18.5_0",
//    "permissions": {
//       "active": {
//          "api": [ ],
//          "explicit_hosts": [ ],
//          "manifest": [ ],
//          "scriptable_hosts": [ ]
//       },
//       "optional": {
//          "api": [ ],
//          "explicit_hosts": [ ],
//          "manifest": [ ],
//          "scriptable_hosts": [ ]
//       },
//       "tab_specific": {
//          "4": {
//             "api": [ ],
//             "explicit_hosts": [ ],
//             "manifest": [ ],
//             "scriptable_hosts": [ ]
//          }
//       },
//       "withheld": {
//          "api": [ ],
//          "explicit_hosts": [ ],
//          "manifest": [ ],
//          "scriptable_hosts": [ ]
//       },
//    "service_worker_keepalives": {
//      "activities": [ {
//        "extra_data": "tabs.create",
//        "timeout_type": "Default",
//        "type": "API_FUNCTION"
//      } ]
//      "count": 1
//    }
//    "type": "TYPE_EXTENSION",
//    "version": "2.18.5"
// } ]
//
// Which is:
//
// LIST
//  DICT
//    "background_page_keepalives": DICT
//      "activities": LIST
//        DICT
//          "extra_data": STRING
//          "type": STRING
//      "count": INT
//    "creation_flags": LIST
//      STRING
//    "disable_reasons": LIST
//      STRING
//    "event_listeners": DICT
//      "count": INT
//      "listeners": LIST
//        DICT
//          "event_name": STRING
//          "filter": DICT
//          "is_for_service_worker": STRING
//          "is_lazy": STRING
//          "url": STRING
//    "id": STRING
//    "location": STRING
//    "manifest_version": INT
//    "name": STRING
//    "path": STRING
//    "permissions": DICT
//      "active": DICT
//        "api": LIST
//          STRING
//          (see note above for edge cases on all "api" and "manfest" entries)
//        "explicit_hosts": LIST
//          STRING
//        "manifest": LIST
//          STRING
//        "scriptable_hosts": LIST
//          STRING
//      "optional": DICT
//        "api": LIST
//          STRING
//        "explicit_hosts": LIST
//          STRING
//        "manifest": LIST
//          STRING
//        "scriptable_hosts": LIST
//          STRING
//      "tab_specific": DICT
//        (see note above for details)
//      "withheld": DICT
//        "api": LIST
//          STRING
//        "explicit_hosts": LIST
//          STRING
//        "manifest": LIST
//          STRING
//        "scriptable_hosts": LIST
//          STRING
//    "service_worker_keepalies": DICT
//      "activities": LIST
//        DICT
//          "extra_data": STRING
//          "timeout_type": STRING,
//          "type": STRING
//      "count": INT
//    "type": STRING
//    "version": STRING

constexpr std::string_view kActivitesKey =;
constexpr std::string_view kBackgroundPageKeepalivesKey =;
constexpr std::string_view kCountKey =;
constexpr std::string_view kEventNameKey =;
constexpr std::string_view kEventsListenersKey =;
constexpr std::string_view kExtraDataKey =;
constexpr std::string_view kFilterKey =;
constexpr std::string_view kInternalsCreationFlagsKey =;
constexpr std::string_view kInternalsDisableReasonsKey =;
constexpr std::string_view kInternalsIdKey =;
constexpr std::string_view kInternalsGuidKey =;
constexpr std::string_view kInternalsNameKey =;
constexpr std::string_view kInternalsVersionKey =;
constexpr std::string_view kIsForServiceWorkerKey =;
constexpr std::string_view kIsLazyKey =;
constexpr std::string_view kListenersKey =;
constexpr std::string_view kListenerUrlKey =;
constexpr std::string_view kLocationKey =;
constexpr std::string_view kManifestVersionKey =;
constexpr std::string_view kPathKey =;
constexpr std::string_view kPermissionsKey =;
constexpr std::string_view kPermissionsActiveKey =;
constexpr std::string_view kPermissionsOptionalKey =;
constexpr std::string_view kPermissionsTabSpecificKey =;
constexpr std::string_view kPermissionsWithheldKey =;
constexpr std::string_view kPermissionsApiKey =;
constexpr std::string_view kPermissionsManifestKey =;
constexpr std::string_view kPermissionsExplicitHostsKey =;
constexpr std::string_view kPermissionsScriptableHostsKey =;
constexpr std::string_view kServiceWorkerKeepalivesKey =;
constexpr std::string_view kTimeoutTypeKey =;
constexpr std::string_view kTypeKey =;

base::Value::Dict FormatBackgroundPageKeepaliveData(
    extensions::ProcessManager* process_manager,
    const extensions::Extension* extension) {}

base::Value::Dict FormatServiceWorkerKeepaliveData(
    extensions::ProcessManager& process_manager,
    const extensions::ExtensionId& extension_id) {}

// Formats API and Manifest permissions, which can have details that we add as a
// dictionary rather than just the string name
template <typename T>
base::Value::List FormatDetailedPermissionSet(const T& permissions) {}

base::Value::Dict FormatPermissionSet(
    const extensions::PermissionSet& permission_set) {}

base::Value::Dict FormatPermissionsData(
    const extensions::Extension& extension) {}

void AddEventListenerData(extensions::EventRouter* event_router,
                          base::Value::List* data) {}

}  // namespace

ExtensionsInternalsSource::ExtensionsInternalsSource(Profile* profile)
    :{}

ExtensionsInternalsSource::~ExtensionsInternalsSource() = default;

std::string ExtensionsInternalsSource::GetSource() {}

std::string ExtensionsInternalsSource::GetMimeType(const GURL& url) {}

void ExtensionsInternalsSource::StartDataRequest(
    const GURL& url,
    const content::WebContents::Getter& wc_getter,
    content::URLDataSource::GotDataCallback callback) {}

std::string ExtensionsInternalsSource::WriteToString() const {}