lfg | 048201a | 2014-09-16 19:09:36 | [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 | |
| 5 | #ifndef EXTENSIONS_BROWSER_URL_REQUEST_UTIL_H_ |
| 6 | #define EXTENSIONS_BROWSER_URL_REQUEST_UTIL_H_ |
| 7 | |
jam | 6adb8c2 | 2016-10-13 17:14:27 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Charlie Reis | e2c2c49 | 2018-06-15 21:34:04 | [diff] [blame^] | 10 | #include "base/optional.h" |
| 11 | #include "base/strings/string_piece.h" |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 12 | #include "content/public/common/resource_type.h" |
jam | 6adb8c2 | 2016-10-13 17:14:27 | [diff] [blame] | 13 | #include "ui/base/page_transition_types.h" |
| 14 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 15 | class GURL; |
| 16 | |
lfg | 048201a | 2014-09-16 19:09:36 | [diff] [blame] | 17 | namespace net { |
| 18 | class URLRequest; |
| 19 | } |
| 20 | |
| 21 | namespace extensions { |
| 22 | class Extension; |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 23 | class ExtensionSet; |
| 24 | class ProcessMap; |
lfg | 048201a | 2014-09-16 19:09:36 | [diff] [blame] | 25 | |
| 26 | // Utilities related to URLRequest jobs for extension resources. See |
| 27 | // chrome/browser/extensions/extension_protocols_unittest.cc for related tests. |
| 28 | namespace url_request_util { |
| 29 | |
| 30 | // Sets allowed=true to allow a chrome-extension:// resource request coming from |
vivek.vg | 33f197b | 2014-09-17 15:26:18 | [diff] [blame] | 31 | // renderer A to access a resource in an extension running in renderer B. |
lfg | 048201a | 2014-09-16 19:09:36 | [diff] [blame] | 32 | // 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] | 33 | bool AllowCrossRendererResourceLoad(const GURL& url, |
| 34 | content::ResourceType resource_type, |
| 35 | ui::PageTransition page_transition, |
| 36 | int child_id, |
lfg | 048201a | 2014-09-16 19:09:36 | [diff] [blame] | 37 | bool is_incognito, |
| 38 | const Extension* extension, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 39 | const ExtensionSet& extensions, |
| 40 | const ProcessMap& process_map, |
lfg | 048201a | 2014-09-16 19:09:36 | [diff] [blame] | 41 | bool* allowed); |
| 42 | |
jam | 6adb8c2 | 2016-10-13 17:14:27 | [diff] [blame] | 43 | // Helper method that is called by both AllowCrossRendererResourceLoad and |
| 44 | // ExtensionNavigationThrottle to share logic. |
| 45 | // Sets allowed=true to allow a chrome-extension:// resource request coming from |
| 46 | // renderer A to access a resource in an extension running in renderer B. |
| 47 | // Returns false when it couldn't determine if the resource is allowed or not |
| 48 | bool AllowCrossRendererResourceLoadHelper(bool is_guest, |
| 49 | const Extension* extension, |
| 50 | const Extension* owner_extension, |
| 51 | const std::string& partition_id, |
Charlie Reis | e2c2c49 | 2018-06-15 21:34:04 | [diff] [blame^] | 52 | base::StringPiece resource_path, |
jam | 6adb8c2 | 2016-10-13 17:14:27 | [diff] [blame] | 53 | ui::PageTransition page_transition, |
| 54 | bool* allowed); |
| 55 | |
Charlie Reis | e2c2c49 | 2018-06-15 21:34:04 | [diff] [blame^] | 56 | // Checks whether the given |extension| and |resource_path| are part of a |
| 57 | // special case where an extension URL is permitted to load in any guest |
| 58 | // process, rather than only in guests of a given platform app. If |
| 59 | // |resource_path| is base::nullopt, then the check is based solely on which |
| 60 | // extension is passed in, allowing this to be used for origin checks as well as |
| 61 | // URL checks. |
| 62 | // TODO(creis): Remove this method when the special cases (listed by bug number |
| 63 | // in the definition of this method) are gone. |
| 64 | bool AllowSpecialCaseExtensionURLInGuest( |
| 65 | const Extension* extension, |
| 66 | base::Optional<base::StringPiece> resource_path); |
| 67 | |
lfg | 048201a | 2014-09-16 19:09:36 | [diff] [blame] | 68 | } // namespace url_request_util |
| 69 | } // namespace extensions |
| 70 | |
| 71 | #endif // EXTENSIONS_BROWSER_URL_REQUEST_UTIL_H_ |