<commit_before>// Copyright (c) 2011 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/common/extensions/extension_messages.h"

#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/manifest.h"
#include "content/public/common/common_param_traits.h"

ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params()
    : location(Extension::INVALID),
      creation_flags(Extension::NO_FLAGS){}

ExtensionMsg_Loaded_Params::~ExtensionMsg_Loaded_Params() {}

ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params(
    const ExtensionMsg_Loaded_Params& other)
    : manifest(other.manifest),
      location(other.location),
      path(other.path),
      apis(other.apis),
      explicit_hosts(other.explicit_hosts),
      scriptable_hosts(other.scriptable_hosts),
      id(other.id),
      creation_flags(other.creation_flags) {}

ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params(
    const Extension* extension)
    : manifest(new DictionaryValue()),
      location(extension->location()),
      path(extension->path()),
      apis(extension->GetActivePermissions()->apis()),
      explicit_hosts(extension->GetActivePermissions()->explicit_hosts()),
      scriptable_hosts(extension->GetActivePermissions()->scriptable_hosts()),
      id(extension->id()),
      creation_flags(extension->creation_flags()) {
  // As we need more bits of extension data in the renderer, add more keys to
  // this list.
  const char* kRendererExtensionKeys[] = {
    extension_manifest_keys::kApp,
    extension_manifest_keys::kContentScripts,
    extension_manifest_keys::kIcons,
    extension_manifest_keys::kName,
    extension_manifest_keys::kPageAction,
    extension_manifest_keys::kPageActions,
    extension_manifest_keys::kPermissions,
    extension_manifest_keys::kPlatformApp,
    extension_manifest_keys::kPublicKey,
    extension_manifest_keys::kVersion,
  };

  // Copy only the data we need and bypass the manifest type checks.
  DictionaryValue* source = extension->manifest()->value();
  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRendererExtensionKeys); ++i) {
    Value* temp = NULL;
    if (source->Get(kRendererExtensionKeys[i], &temp))
      manifest->Set(kRendererExtensionKeys[i], temp->DeepCopy());
  }
}

scoped_refptr<Extension>
    ExtensionMsg_Loaded_Params::ConvertToExtension() const {
  std::string error;

  scoped_refptr<Extension> extension(
      Extension::Create(path, location, *manifest, creation_flags,
                        &error));<commit_msg>Apparently we're supposed to forward the manifest_version attribute to the renderer so it knows how to interpret manifests.<commit_after>// Copyright (c) 2011 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/common/extensions/extension_messages.h"

#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/manifest.h"
#include "content/public/common/common_param_traits.h"

ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params()
    : location(Extension::INVALID),
      creation_flags(Extension::NO_FLAGS){}

ExtensionMsg_Loaded_Params::~ExtensionMsg_Loaded_Params() {}

ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params(
    const ExtensionMsg_Loaded_Params& other)
    : manifest(other.manifest),
      location(other.location),
      path(other.path),
      apis(other.apis),
      explicit_hosts(other.explicit_hosts),
      scriptable_hosts(other.scriptable_hosts),
      id(other.id),
      creation_flags(other.creation_flags) {}

ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params(
    const Extension* extension)
    : manifest(new DictionaryValue()),
      location(extension->location()),
      path(extension->path()),
      apis(extension->GetActivePermissions()->apis()),
      explicit_hosts(extension->GetActivePermissions()->explicit_hosts()),
      scriptable_hosts(extension->GetActivePermissions()->scriptable_hosts()),
      id(extension->id()),
      creation_flags(extension->creation_flags()) {
  // As we need more bits of extension data in the renderer, add more keys to
  // this list.
  const char* kRendererExtensionKeys[] = {
    extension_manifest_keys::kApp,
    extension_manifest_keys::kContentScripts,
    extension_manifest_keys::kIcons,
    extension_manifest_keys::kManifestVersion,
    extension_manifest_keys::kName,
    extension_manifest_keys::kPageAction,
    extension_manifest_keys::kPageActions,
    extension_manifest_keys::kPermissions,
    extension_manifest_keys::kPlatformApp,
    extension_manifest_keys::kPublicKey,
    extension_manifest_keys::kVersion,
  };

  // Copy only the data we need and bypass the manifest type checks.
  DictionaryValue* source = extension->manifest()->value();
  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRendererExtensionKeys); ++i) {
    Value* temp = NULL;
    if (source->Get(kRendererExtensionKeys[i], &temp))
      manifest->Set(kRendererExtensionKeys[i], temp->DeepCopy());
  }
}

scoped_refptr<Extension>
    ExtensionMsg_Loaded_Params::ConvertToExtension() const {
  std::string error;

  scoped_refptr<Extension> extension(
      Extension::Create(path, location, *manifest, creation_flags,
                        &error));
{'fraction_non_alphanumeric': 0.11090538789113127, 'fraction_numerical': 0.0018515089798185522, 'mean_word_length': 4.9362637362637365, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2003732', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1504, 'n_words': 293}