cef/libcef/renderer/content_renderer_client.h

203 lines
7.7 KiB
C
Raw Normal View History

// Copyright (c) 2013 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2011 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_RENDERER_CONTENT_RENDERER_CLIENT_H_
#define CEF_LIBCEF_RENDERER_CONTENT_RENDERER_CLIENT_H_
#pragma once
#include <list>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "libcef/renderer/browser_impl.h"
#include "base/compiler_specific.h"
#include "base/message_loop/message_loop_current.h"
#include "base/optional.h"
#include "base/sequenced_task_runner.h"
#include "chrome/common/plugin.mojom.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/public/renderer/render_thread.h"
#include "mojo/public/cpp/bindings/generic_pending_receiver.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/local_interface_provider.h"
namespace blink {
class WebURLLoaderFactory;
}
namespace extensions {
class CefExtensionsRendererClient;
class Dispatcher;
class DispatcherDelegate;
class ExtensionsClient;
class ExtensionsGuestViewContainerDispatcher;
class ExtensionsRendererClient;
class ResourceRequestPolicy;
} // namespace extensions
namespace web_cache {
class WebCacheImpl;
}
class CefGuestView;
class CefRenderThreadObserver;
struct Cef_CrossOriginWhiteListEntry_Params;
class ChromePDFPrintClient;
Add spell checking support (issue #137). This includes: - Red underline of misspelled words in html text areas. - Right-click context menu options to correct the misspelled word. - New CefBrowser::ReplaceMisspelling method for accepting a word replacement. - Methods added to CefContextMenuParams for retrieving spelling-related information. - Uses the unified text checker when auto-correct is not enabled to match Google Chrome behavior. - On Windows and Linux a hunspell dictionary file will be downloaded to the "<cache_path>/Dictionaries" directory as needed, or used from the <cache_path> directory if the file already exists there. The dictionary file will be downloaded from http://cache.pack.google.com/edgedl/chrome/dict/<LANG>-3-0.bdic where <LANG> is the language abbreviation. - On OS X the spell checking implementation will use the system NSSpellChecker implementation. The following command-line flags have been added: --disable-spell-checking => Disable spell-checking support (no red underline, no dictionary file download, etc). --enable-spelling-auto-correct => Automatically correct common misspellings while typing (like 'omre' to 'more' on Windows/Linux or 'ehlo' to 'helo' on OS X). --enable-spelling-service => Enable use of the remote Google spelling service (this requires Google API keys). --override-spell-check-lang=<LANG> => Use the specified dictionary language <LANG> instead of the language specified in the locales.pak file. To see the default/supported dictionary languages: https://code.google.com/p/chromium/codesearch#search/&q=IDS_SPELLCHECK_DICTIONARY%20xtb&sq=package:chromium git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1859 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
2014-10-07 22:44:33 +02:00
class SpellCheck;
class CefContentRendererClient
: public content::ContentRendererClient,
public service_manager::LocalInterfaceProvider,
public base::MessageLoopCurrent::DestructionObserver {
public:
CefContentRendererClient();
~CefContentRendererClient() override;
// Returns the singleton CefContentRendererClient instance.
static CefContentRendererClient* Get();
// Returns the browser associated with the specified RenderView.
CefRefPtr<CefBrowserImpl> GetBrowserForView(content::RenderView* view);
// Returns the browser associated with the specified main WebFrame.
CefRefPtr<CefBrowserImpl> GetBrowserForMainFrame(blink::WebFrame* frame);
// Called from CefBrowserImpl::OnDestruct().
void OnBrowserDestroyed(CefBrowserImpl* browser);
// Returns the guest view associated with the specified RenderView if any.
CefGuestView* GetGuestViewForView(content::RenderView* view);
// Called from CefGuestView::OnDestruct().
void OnGuestViewDestroyed(CefGuestView* guest_view);
// Render thread task runner.
2017-09-21 13:57:40 +02:00
base::SingleThreadTaskRunner* render_task_runner() const {
return render_task_runner_.get();
}
int uncaught_exception_stack_size() const {
return uncaught_exception_stack_size_;
}
// Returns a factory that only supports unintercepted http(s) and blob
// requests. Used by CefRenderURLRequest.
blink::WebURLLoaderFactory* GetDefaultURLLoaderFactory();
void WebKitInitialized();
// Returns the task runner for the current thread. Returns NULL if the current
// thread is not the main render process thread.
2017-09-21 13:57:40 +02:00
scoped_refptr<base::SingleThreadTaskRunner> GetCurrentTaskRunner();
// Perform cleanup work that needs to occur before shutdown when running in
// single-process mode. Blocks until cleanup is complete.
void RunSingleProcessCleanup();
// ContentRendererClient implementation.
void RenderThreadStarted() override;
void RenderThreadConnected() override;
void RenderFrameCreated(content::RenderFrame* render_frame) override;
void RenderViewCreated(content::RenderView* render_view) override;
bool IsPluginHandledExternally(content::RenderFrame* render_frame,
const blink::WebElement& plugin_element,
const GURL& original_url,
const std::string& mime_type) override;
bool OverrideCreatePlugin(content::RenderFrame* render_frame,
const blink::WebPluginParams& params,
blink::WebPlugin** plugin) override;
void WillSendRequest(blink::WebLocalFrame* frame,
ui::PageTransition transition_type,
const blink::WebURL& url,
const url::Origin* initiator_origin,
GURL* new_url,
bool* attach_same_site_cookies) override;
uint64_t VisitedLinkHash(const char* canonical_url, size_t length) override;
bool IsLinkVisited(uint64_t link_hash) override;
bool IsOriginIsolatedPepperPlugin(const base::FilePath& plugin_path) override;
content::BrowserPluginDelegate* CreateBrowserPluginDelegate(
content::RenderFrame* render_frame,
const content::WebPluginInfo& info,
const std::string& mime_type,
const GURL& original_url) override;
void AddSupportedKeySystems(
std::vector<std::unique_ptr<::media::KeySystemProperties>>* key_systems)
override;
void RunScriptsAtDocumentStart(content::RenderFrame* render_frame) override;
void RunScriptsAtDocumentEnd(content::RenderFrame* render_frame) override;
void RunScriptsAtDocumentIdle(content::RenderFrame* render_frame) override;
void DevToolsAgentAttached() override;
void DevToolsAgentDetached() override;
std::unique_ptr<content::URLLoaderThrottleProvider>
CreateURLLoaderThrottleProvider(
content::URLLoaderThrottleProviderType provider_type) override;
void BindReceiverOnMainThread(mojo::GenericPendingReceiver receiver) override;
// service_manager::LocalInterfaceProvider implementation.
void GetInterface(const std::string& name,
mojo::ScopedMessagePipeHandle request_handle) override;
// MessageLoopCurrent::DestructionObserver implementation.
void WillDestroyCurrentMessageLoop() override;
private:
Move message routing from CefBrowser to CefFrame (see issue #2498). This change moves the SendProcessMessage method from CefBrowser to CefFrame and adds CefBrowser parameters to OnProcessMessageReceived and OnDraggableRegionsChanged. The internal implementation has changed as follows: - Frame IDs are now a 64-bit combination of the 32-bit render_process_id and render_routing_id values that uniquely identify a RenderFrameHost (RFH). - CefFrameHostImpl objects are now managed by CefBrowserInfo with life span tied to RFH expectations. Specifically, a CefFrameHostImpl object representing a sub-frame will be created when a RenderFrame is created in the renderer process and detached when the associated RenderFrame is deleted or the renderer process in which it runs has died. - The CefFrameHostImpl object representing the main frame will always be valid but the underlying RFH (and associated frame ID) may change over time as a result of cross-origin navigations. Despite these changes calling LoadURL on the main frame object in the browser process will always navigate as expected. - Speculative RFHs, which may be created as a result of a cross-origin navigation and discarded if that navigation is not committed, are now handled correctly (e.g. ignored in most cases until they're committed). - It is less likely, but still possible, to receive a CefFrame object with an invalid frame ID (ID < 0). This can happen in cases where a RFH has not yet been created for a sub-frame. For example, when OnBeforeBrowse is called before initiating navigation in a previously nonexisting sub-frame. To test: All tests pass with NetworkService enabled and disabled.
2019-05-24 22:23:43 +02:00
// Maybe create a new browser object, return the existing one, or return
// nullptr for guest views.
CefRefPtr<CefBrowserImpl> MaybeCreateBrowser(
content::RenderView* render_view,
content::RenderFrame* render_frame,
base::Optional<bool>* is_windowless);
// Perform cleanup work for single-process mode.
void RunSingleProcessCleanupOnUIThread();
// Time at which this object was created. This is very close to the time at
// which the RendererMain function was entered.
base::TimeTicks main_entry_time_;
2017-09-21 13:57:40 +02:00
scoped_refptr<base::SingleThreadTaskRunner> render_task_runner_;
std::unique_ptr<CefRenderThreadObserver> observer_;
std::unique_ptr<web_cache::WebCacheImpl> web_cache_impl_;
std::unique_ptr<SpellCheck> spellcheck_;
std::unique_ptr<blink::WebURLLoaderFactory> default_url_loader_factory_;
// Map of RenderView pointers to CefBrowserImpl references.
typedef std::map<content::RenderView*, CefRefPtr<CefBrowserImpl>> BrowserMap;
BrowserMap browsers_;
// Map of RenderView poiners to CefGuestView implementations.
typedef std::map<content::RenderView*, std::unique_ptr<CefGuestView>>
GuestViewMap;
GuestViewMap guest_views_;
// Cross-origin white list entries that need to be registered with WebKit.
typedef std::vector<Cef_CrossOriginWhiteListEntry_Params> CrossOriginList;
CrossOriginList cross_origin_whitelist_entries_;
std::unique_ptr<ChromePDFPrintClient> pdf_print_client_;
std::unique_ptr<extensions::ExtensionsClient> extensions_client_;
std::unique_ptr<extensions::CefExtensionsRendererClient>
extensions_renderer_client_;
int devtools_agent_count_;
int uncaught_exception_stack_size_;
// Used in single-process mode to test when cleanup is complete.
// Access must be protected by |single_process_cleanup_lock_|.
bool single_process_cleanup_complete_;
base::Lock single_process_cleanup_lock_;
service_manager::BinderRegistry registry_;
DISALLOW_COPY_AND_ASSIGN(CefContentRendererClient);
};
#endif // CEF_LIBCEF_RENDERER_CONTENT_RENDERER_CLIENT_H_