blob: 73a6d7124218beb4575a5721c64d626b279d84ba [file] [log] [blame]
lfg048201a2014-09-16 19:09:361// 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
jam6adb8c22016-10-13 17:14:278#include <string>
9
Charlie Reise2c2c492018-06-15 21:34:0410#include "base/optional.h"
11#include "base/strings/string_piece.h"
Ken Rockot6414c4d92017-11-08 19:58:3212#include "content/public/common/resource_type.h"
jam6adb8c22016-10-13 17:14:2713#include "ui/base/page_transition_types.h"
14
Ken Rockot6414c4d92017-11-08 19:58:3215class GURL;
16
lfg048201a2014-09-16 19:09:3617namespace net {
18class URLRequest;
19}
20
21namespace extensions {
22class Extension;
Ken Rockot6414c4d92017-11-08 19:58:3223class ExtensionSet;
24class ProcessMap;
lfg048201a2014-09-16 19:09:3625
26// Utilities related to URLRequest jobs for extension resources. See
27// chrome/browser/extensions/extension_protocols_unittest.cc for related tests.
28namespace url_request_util {
29
30// Sets allowed=true to allow a chrome-extension:// resource request coming from
vivek.vg33f197b2014-09-17 15:26:1831// renderer A to access a resource in an extension running in renderer B.
lfg048201a2014-09-16 19:09:3632// Returns false when it couldn't determine if the resource is allowed or not
Ken Rockot6414c4d92017-11-08 19:58:3233bool AllowCrossRendererResourceLoad(const GURL& url,
34 content::ResourceType resource_type,
35 ui::PageTransition page_transition,
36 int child_id,
lfg048201a2014-09-16 19:09:3637 bool is_incognito,
38 const Extension* extension,
Ken Rockot6414c4d92017-11-08 19:58:3239 const ExtensionSet& extensions,
40 const ProcessMap& process_map,
lfg048201a2014-09-16 19:09:3641 bool* allowed);
42
jam6adb8c22016-10-13 17:14:2743// 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
48bool AllowCrossRendererResourceLoadHelper(bool is_guest,
49 const Extension* extension,
50 const Extension* owner_extension,
51 const std::string& partition_id,
Charlie Reise2c2c492018-06-15 21:34:0452 base::StringPiece resource_path,
jam6adb8c22016-10-13 17:14:2753 ui::PageTransition page_transition,
54 bool* allowed);
55
Charlie Reise2c2c492018-06-15 21:34:0456// 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.
64bool AllowSpecialCaseExtensionURLInGuest(
65 const Extension* extension,
66 base::Optional<base::StringPiece> resource_path);
67
lfg048201a2014-09-16 19:09:3668} // namespace url_request_util
69} // namespace extensions
70
71#endif // EXTENSIONS_BROWSER_URL_REQUEST_UTIL_H_