2015-02-14 00:17:08 +01:00
|
|
|
// Copyright (c) 2015 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 CEF_LIBCEF_BROWSER_RESOURCE_CONTEXT_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_RESOURCE_CONTEXT_H_
|
|
|
|
#pragma once
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "include/cef_request_context.h"
|
2015-09-25 13:59:30 +02:00
|
|
|
#include "include/cef_request_context_handler.h"
|
2019-07-29 23:27:12 +02:00
|
|
|
#include "include/cef_scheme.h"
|
2015-09-25 13:59:30 +02:00
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
#include "base/files/file_path.h"
|
2017-12-07 22:44:24 +01:00
|
|
|
#include "chrome/common/plugin.mojom.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
#include "content/public/browser/resource_context.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "extensions/browser/info_map.h"
|
2016-07-06 21:34:09 +02:00
|
|
|
#include "net/ssl/client_cert_store.h"
|
2017-01-19 00:37:56 +01:00
|
|
|
#include "url/origin.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
|
|
|
|
// Acts as a bridge for resource loading. Life span is controlled by
|
|
|
|
// CefBrowserContext. Created on the UI thread but accessed and destroyed on the
|
2019-07-29 23:27:12 +02:00
|
|
|
// IO thread. Network request objects are associated with the ResourceContext
|
|
|
|
// via ProxyURLLoaderFactory. When the ResourceContext is destroyed all
|
|
|
|
// outstanding network request objects will be canceled.
|
2015-02-14 00:17:08 +01:00
|
|
|
// See browser_context.h for an object relationship diagram.
|
|
|
|
class CefResourceContext : public content::ResourceContext {
|
|
|
|
public:
|
2019-03-24 00:40:32 +01:00
|
|
|
explicit CefResourceContext(bool is_off_the_record);
|
2015-02-14 00:17:08 +01:00
|
|
|
~CefResourceContext() override;
|
|
|
|
|
2016-07-06 21:34:09 +02:00
|
|
|
std::unique_ptr<net::ClientCertStore> CreateClientCertStore();
|
2015-02-14 00:17:08 +01:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
void set_extensions_info_map(extensions::InfoMap* extensions_info_map);
|
2015-02-14 00:17:08 +01:00
|
|
|
|
2019-03-24 00:40:32 +01:00
|
|
|
// Keep track of handlers associated with specific frames. This information
|
|
|
|
// originates from frame create/delete notifications in CefBrowserHostImpl or
|
|
|
|
// CefMimeHandlerViewGuestDelegate which are forwarded via
|
|
|
|
// CefRequestContextImpl and CefBrowserContext.
|
|
|
|
void AddHandler(int render_process_id,
|
|
|
|
int render_frame_id,
|
2019-04-24 04:50:25 +02:00
|
|
|
int frame_tree_node_id,
|
2019-03-24 00:40:32 +01:00
|
|
|
CefRefPtr<CefRequestContextHandler> handler);
|
2019-04-24 04:50:25 +02:00
|
|
|
void RemoveHandler(int render_process_id,
|
|
|
|
int render_frame_id,
|
|
|
|
int frame_tree_node_id);
|
|
|
|
|
|
|
|
// Returns the handler that matches the specified IDs. Pass -1 for unknown
|
|
|
|
// values. If |require_frame_match| is true only exact matches will be
|
|
|
|
// returned. If |require_frame_match| is false, and there is not an exact
|
|
|
|
// match, then the first handler for the same |render_process_id| will be
|
|
|
|
// returned.
|
2019-03-24 00:40:32 +01:00
|
|
|
CefRefPtr<CefRequestContextHandler> GetHandler(int render_process_id,
|
|
|
|
int render_frame_id,
|
2019-04-24 04:50:25 +02:00
|
|
|
int frame_tree_node_id,
|
2019-03-24 00:40:32 +01:00
|
|
|
bool require_frame_match);
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
// Remember the plugin load decision for plugin status requests that arrive
|
|
|
|
// via CefPluginServiceFilter::IsPluginAvailable.
|
|
|
|
void AddPluginLoadDecision(int render_process_id,
|
|
|
|
const base::FilePath& plugin_path,
|
2017-01-19 00:37:56 +01:00
|
|
|
bool is_main_frame,
|
|
|
|
const url::Origin& main_frame_origin,
|
2017-12-07 22:44:24 +01:00
|
|
|
chrome::mojom::PluginStatus status);
|
2016-10-17 20:14:44 +02:00
|
|
|
bool HasPluginLoadDecision(int render_process_id,
|
|
|
|
const base::FilePath& plugin_path,
|
2017-01-19 00:37:56 +01:00
|
|
|
bool is_main_frame,
|
|
|
|
const url::Origin& main_frame_origin,
|
2017-12-07 22:44:24 +01:00
|
|
|
chrome::mojom::PluginStatus* status) const;
|
2016-10-17 20:14:44 +02:00
|
|
|
|
|
|
|
// Clear the plugin load decisions associated with |render_process_id|, or all
|
|
|
|
// plugin load decisions if |render_process_id| is -1.
|
|
|
|
void ClearPluginLoadDecision(int render_process_id);
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
// Manage scheme handler factories associated with this context.
|
|
|
|
void RegisterSchemeHandlerFactory(const std::string& scheme_name,
|
|
|
|
const std::string& domain_name,
|
|
|
|
CefRefPtr<CefSchemeHandlerFactory> factory);
|
|
|
|
void ClearSchemeHandlerFactories();
|
|
|
|
CefRefPtr<CefSchemeHandlerFactory> GetSchemeHandlerFactory(const GURL& url);
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
// State transferred from the BrowserContext for use on the IO thread.
|
|
|
|
bool IsOffTheRecord() const { return is_off_the_record_; }
|
|
|
|
const extensions::InfoMap* GetExtensionInfoMap() const {
|
|
|
|
return extension_info_map_.get();
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
private:
|
2019-04-30 22:45:13 +02:00
|
|
|
void InitOnIOThread();
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
// Only accessed on the IO thread.
|
2015-07-16 23:40:01 +02:00
|
|
|
bool is_off_the_record_;
|
|
|
|
scoped_refptr<extensions::InfoMap> extension_info_map_;
|
2019-03-24 00:40:32 +01:00
|
|
|
|
|
|
|
// Map of (render_process_id, render_frame_id) to handler.
|
|
|
|
typedef std::map<std::pair<int, int>, CefRefPtr<CefRequestContextHandler>>
|
2019-04-24 04:50:25 +02:00
|
|
|
RenderIdHandlerMap;
|
|
|
|
RenderIdHandlerMap render_id_handler_map_;
|
|
|
|
|
|
|
|
// Map of frame_tree_node_id to handler. Keeping this map is necessary
|
2019-07-29 23:27:12 +02:00
|
|
|
// because, when navigating the main frame, a new (pre-commit) network request
|
2019-04-24 04:50:25 +02:00
|
|
|
// will be created before the RenderFrameHost. Consequently we can't rely
|
|
|
|
// on valid render IDs. See https://crbug.com/776884 for background.
|
|
|
|
typedef std::map<int, CefRefPtr<CefRequestContextHandler>> NodeIdHandlerMap;
|
|
|
|
NodeIdHandlerMap node_id_handler_map_;
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2017-01-19 00:37:56 +01:00
|
|
|
// Map (render_process_id, plugin_path, is_main_frame, main_frame_origin) to
|
|
|
|
// plugin load decision.
|
2017-05-17 11:29:28 +02:00
|
|
|
typedef std::map<
|
|
|
|
std::pair<std::pair<int, base::FilePath>, std::pair<bool, url::Origin>>,
|
2017-12-07 22:44:24 +01:00
|
|
|
chrome::mojom::PluginStatus>
|
2016-10-17 20:14:44 +02:00
|
|
|
PluginLoadDecisionMap;
|
|
|
|
PluginLoadDecisionMap plugin_load_decision_map_;
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
// Map (scheme, domain) to factories.
|
|
|
|
typedef std::map<std::pair<std::string, std::string>,
|
|
|
|
CefRefPtr<CefSchemeHandlerFactory>>
|
|
|
|
SchemeHandlerFactoryMap;
|
|
|
|
SchemeHandlerFactoryMap scheme_handler_factory_map_;
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefResourceContext);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_RESOURCE_CONTEXT_H_
|