[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
lfg | 048201a | 2014-09-16 19:09:36 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_EXTENSIONS_CHROME_URL_REQUEST_UTIL_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_CHROME_URL_REQUEST_UTIL_H_ |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
Julie Jeongeun Kim | f65376f | 2019-11-05 03:54:55 | [diff] [blame] | 10 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
Julie Jeongeun Kim | 6dd4c7b | 2019-11-18 05:56:30 | [diff] [blame] | 11 | #include "mojo/public/cpp/bindings/pending_remote.h" |
Gyuyoung Kim | a6b7678 | 2020-01-17 00:56:04 | [diff] [blame] | 12 | #include "services/network/public/mojom/url_loader.mojom-forward.h" |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 13 | #include "third_party/blink/public/mojom/loader/resource_load_info.mojom-shared.h" |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 14 | #include "ui/base/page_transition_types.h" |
| 15 | |
| 16 | class GURL; |
| 17 | |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 18 | namespace base { |
| 19 | class FilePath; |
| 20 | } |
| 21 | |
Ken Rockot | 33f8dfb | 2020-08-31 20:17:40 | [diff] [blame] | 22 | namespace network { |
| 23 | struct ResourceRequest; |
| 24 | } |
| 25 | |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 26 | namespace extensions { |
| 27 | class Extension; |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 28 | class ExtensionSet; |
| 29 | class ProcessMap; |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 30 | |
jamescook | 8816ae5 | 2014-09-05 17:02:37 | [diff] [blame] | 31 | // Utilities related to URLRequest jobs for extension resources. See |
| 32 | // chrome/browser/extensions/extension_protocols_unittest.cc for related tests. |
lfg | 048201a | 2014-09-16 19:09:36 | [diff] [blame] | 33 | namespace chrome_url_request_util { |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 34 | |
lfg | 048201a | 2014-09-16 19:09:36 | [diff] [blame] | 35 | // Sets allowed=true to allow a chrome-extension:// resource request coming from |
vivek.vg | 33f197b | 2014-09-17 15:26:18 | [diff] [blame] | 36 | // renderer A to access a resource in an extension running in renderer B. |
lfg | 048201a | 2014-09-16 19:09:36 | [diff] [blame] | 37 | // Returns false when it couldn't determine if the resource is allowed or not |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 38 | bool AllowCrossRendererResourceLoad(const GURL& url, |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 39 | blink::mojom::ResourceType resource_type, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 40 | ui::PageTransition page_transition, |
| 41 | int child_id, |
lfg | 3be3033 | 2014-09-18 15:47:26 | [diff] [blame] | 42 | bool is_incognito, |
| 43 | const Extension* extension, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 44 | const ExtensionSet& extensions, |
| 45 | const ProcessMap& process_map, |
lfg | 3be3033 | 2014-09-18 15:47:26 | [diff] [blame] | 46 | bool* allowed); |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 47 | |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 48 | // Return the |request|'s resource path relative to the Chromium resources path |
| 49 | // (chrome::DIR_RESOURCES) *if* the request refers to a resource within the |
| 50 | // Chrome resource bundle. If not then the returned file path will be empty. |
dpapad | 669a8970 | 2019-05-10 18:00:49 | [diff] [blame] | 51 | // |resource_id| is used to check whether the requested resource is registered |
| 52 | // as a component extensions resource, via |
| 53 | // ChromeComponentExtensionResourceManager::IsComponentExtensionResource() |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 54 | base::FilePath GetBundleResourcePath( |
| 55 | const network::ResourceRequest& request, |
| 56 | const base::FilePath& extension_resources_path, |
dpapad | 669a8970 | 2019-05-10 18:00:49 | [diff] [blame] | 57 | int* resource_id); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 58 | |
| 59 | // Creates and starts a URLLoader for loading component extension resources out |
| 60 | // of a Chrome resource bundle. This should only be called if |
| 61 | // GetBundleResourcePath returns a valid path. |
| 62 | void LoadResourceFromResourceBundle( |
| 63 | const network::ResourceRequest& request, |
Julie Jeongeun Kim | f65376f | 2019-11-05 03:54:55 | [diff] [blame] | 64 | mojo::PendingReceiver<network::mojom::URLLoader> loader, |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 65 | const base::FilePath& resource_relative_path, |
dpapad | 669a8970 | 2019-05-10 18:00:49 | [diff] [blame] | 66 | int resource_id, |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 67 | const std::string& content_security_policy, |
Julie Jeongeun Kim | 6dd4c7b | 2019-11-18 05:56:30 | [diff] [blame] | 68 | mojo::PendingRemote<network::mojom::URLLoaderClient> client, |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 69 | bool send_cors_header); |
| 70 | |
lfg | 048201a | 2014-09-16 19:09:36 | [diff] [blame] | 71 | } // namespace chrome_url_request_util |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 72 | } // namespace extensions |
| 73 | |
lfg | 048201a | 2014-09-16 19:09:36 | [diff] [blame] | 74 | #endif // CHROME_BROWSER_EXTENSIONS_CHROME_URL_REQUEST_UTIL_H_ |