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