This repository has been archived by the owner on Jan 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow loading cryptotoken extension from pak via brave extension API
- Loading branch information
Showing
9 changed files
with
201 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
atom/browser/extensions/atom_component_extension_resource_manager.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// 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 "atom/browser/extensions/atom_component_extension_resource_manager.h" | ||
|
||
#include "base/logging.h" | ||
#include "base/macros.h" | ||
#include "base/path_service.h" | ||
#include "build/build_config.h" | ||
#include "brave/grit/brave_resources.h" | ||
#include "chrome/common/chrome_paths.h" | ||
#include "chrome/grit/component_extension_resources_map.h" | ||
|
||
namespace extensions { | ||
|
||
AtomComponentExtensionResourceManager:: | ||
AtomComponentExtensionResourceManager() { | ||
static const GritResourceMap kExtraComponentExtensionResources[] = { | ||
{"cryptotoken/manifest.json", IDR_CRYPTOTOKEN_MANIFEST}, | ||
}; | ||
|
||
AddComponentResourceEntries( | ||
kComponentExtensionResources, | ||
kComponentExtensionResourcesSize); | ||
AddComponentResourceEntries( | ||
kExtraComponentExtensionResources, | ||
arraysize(kExtraComponentExtensionResources)); | ||
} | ||
|
||
AtomComponentExtensionResourceManager:: | ||
~AtomComponentExtensionResourceManager() {} | ||
|
||
bool AtomComponentExtensionResourceManager::IsComponentExtensionResource( | ||
const base::FilePath& extension_path, | ||
const base::FilePath& resource_path, | ||
int* resource_id) const { | ||
base::FilePath directory_path = extension_path; | ||
base::FilePath resources_dir; | ||
base::FilePath relative_path; | ||
|
||
if (!PathService::Get(chrome::DIR_RESOURCES, &resources_dir) || | ||
!resources_dir.AppendRelativePath(directory_path, &relative_path)) { | ||
return false; | ||
} | ||
relative_path = relative_path.Append(resource_path); | ||
relative_path = relative_path.NormalizePathSeparators(); | ||
|
||
std::map<base::FilePath, int>::const_iterator entry = | ||
path_to_resource_id_.find(relative_path); | ||
if (entry != path_to_resource_id_.end()) | ||
*resource_id = entry->second; | ||
|
||
return entry != path_to_resource_id_.end(); | ||
} | ||
|
||
void AtomComponentExtensionResourceManager::AddComponentResourceEntries( | ||
const GritResourceMap* entries, | ||
size_t size) { | ||
for (size_t i = 0; i < size; ++i) { | ||
base::FilePath resource_path = base::FilePath().AppendASCII( | ||
entries[i].name); | ||
resource_path = resource_path.NormalizePathSeparators(); | ||
|
||
DCHECK(path_to_resource_id_.find(resource_path) == | ||
path_to_resource_id_.end()); | ||
path_to_resource_id_[resource_path] = entries[i].value; | ||
} | ||
} | ||
|
||
} // namespace extensions |
43 changes: 43 additions & 0 deletions
43
atom/browser/extensions/atom_component_extension_resource_manager.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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 ATOM_BROWSER_EXTENSIONS_CHROME_COMPONENT_EXTENSION_RESOURCE_MANAGER_H_ | ||
#define ATOM_BROWSER_EXTENSIONS_CHROME_COMPONENT_EXTENSION_RESOURCE_MANAGER_H_ | ||
|
||
#include <stddef.h> | ||
|
||
#include <map> | ||
|
||
#include "base/files/file_path.h" | ||
#include "base/macros.h" | ||
#include "extensions/browser/component_extension_resource_manager.h" | ||
|
||
struct GritResourceMap; | ||
|
||
namespace extensions { | ||
|
||
class AtomComponentExtensionResourceManager | ||
: public ComponentExtensionResourceManager { | ||
public: | ||
AtomComponentExtensionResourceManager(); | ||
~AtomComponentExtensionResourceManager() override; | ||
|
||
// Overridden from ComponentExtensionResourceManager: | ||
bool IsComponentExtensionResource(const base::FilePath& extension_path, | ||
const base::FilePath& resource_path, | ||
int* resource_id) const override; | ||
|
||
private: | ||
void AddComponentResourceEntries(const GritResourceMap* entries, size_t size); | ||
|
||
// A map from a resource path to the resource ID. Used by | ||
// IsComponentExtensionResource. | ||
std::map<base::FilePath, int> path_to_resource_id_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(AtomComponentExtensionResourceManager); | ||
}; | ||
|
||
} // namespace extensions | ||
|
||
#endif // ATOM_BROWSER_EXTENSIONS_CHROME_COMPONENT_EXTENSION_RESOURCE_MANAGER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters