electron/atom/browser/common_web_contents_delegate.h

212 lines
7.9 KiB
C
Raw Normal View History

2015-06-05 05:49:12 +00:00
// Copyright (c) 2015 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_COMMON_WEB_CONTENTS_DELEGATE_H_
#define ATOM_BROWSER_COMMON_WEB_CONTENTS_DELEGATE_H_
#include <map>
#include <memory>
2015-06-05 09:01:17 +00:00
#include <string>
#include <vector>
#include "atom/browser/ui/inspectable_web_contents_delegate.h"
#include "atom/browser/ui/inspectable_web_contents_impl.h"
#include "atom/browser/ui/inspectable_web_contents_view_delegate.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/devtools/devtools_file_system_indexer.h"
2016-02-01 13:09:12 +00:00
#include "content/public/browser/web_contents_delegate.h"
#include "electron/buildflags/buildflags.h"
2015-06-05 05:49:12 +00:00
#if defined(TOOLKIT_VIEWS)
#include "atom/browser/ui/autofill_popup.h"
#endif
namespace base {
class SequencedTaskRunner;
}
2015-06-05 05:49:12 +00:00
namespace atom {
class AtomBrowserContext;
class NativeWindow;
class WebDialogHelper;
#if BUILDFLAG(ENABLE_OSR)
class OffScreenWebContentsView;
#endif
class CommonWebContentsDelegate : public content::WebContentsDelegate,
public InspectableWebContentsDelegate,
public InspectableWebContentsViewDelegate {
2015-06-05 05:49:12 +00:00
public:
2015-06-24 14:23:38 +00:00
CommonWebContentsDelegate();
~CommonWebContentsDelegate() override;
2015-06-05 05:49:12 +00:00
2015-06-24 15:29:32 +00:00
// Creates a InspectableWebContents object and takes onwership of
// |web_contents|.
void InitWithWebContents(content::WebContents* web_contents,
AtomBrowserContext* browser_context,
bool is_guest);
2015-06-24 15:29:32 +00:00
// Set the window as owner window.
void SetOwnerWindow(NativeWindow* owner_window);
2015-10-01 06:41:01 +00:00
void SetOwnerWindow(content::WebContents* web_contents,
NativeWindow* owner_window);
// Returns the WebContents managed by this delegate.
content::WebContents* GetWebContents() const;
// Returns the WebContents of devtools.
content::WebContents* GetDevToolsWebContents() const;
InspectableWebContents* managed_web_contents() const {
return web_contents_.get();
}
2015-06-24 14:29:44 +00:00
NativeWindow* owner_window() const { return owner_window_.get(); }
bool is_html_fullscreen() const { return html_fullscreen_; }
protected:
#if BUILDFLAG(ENABLE_OSR)
virtual OffScreenWebContentsView* GetOffScreenWebContentsView() const;
#endif
// content::WebContentsDelegate:
content::WebContents* OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) override;
bool CanOverscrollContent() const override;
content::ColorChooser* OpenColorChooser(
content::WebContents* web_contents,
SkColor color,
const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions)
override;
2016-09-06 08:24:37 +00:00
void RunFileChooser(content::RenderFrameHost* render_frame_host,
std::unique_ptr<content::FileSelectListener> listener,
const blink::mojom::FileChooserParams& params) override;
void EnumerateDirectory(content::WebContents* web_contents,
std::unique_ptr<content::FileSelectListener> listener,
const base::FilePath& path) override;
2018-09-15 00:17:50 +00:00
void EnterFullscreenModeForTab(
content::WebContents* source,
const GURL& origin,
const blink::WebFullscreenOptions& options) override;
void ExitFullscreenModeForTab(content::WebContents* source) override;
bool IsFullscreenForTabOrPending(
const content::WebContents* source) const override;
2017-01-23 09:59:40 +00:00
blink::WebSecurityStyle GetSecurityStyle(
content::WebContents* web_contents,
content::SecurityStyleExplanations* explanations) override;
bool TakeFocus(content::WebContents* source, bool reverse) override;
bool HandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) override;
// Autofill related events.
void ShowAutofillPopup(content::RenderFrameHost* frame_host,
content::RenderFrameHost* embedder_frame_host,
bool offscreen,
2018-04-18 01:44:10 +00:00
const gfx::RectF& bounds,
const std::vector<base::string16>& values,
const std::vector<base::string16>& labels);
void HideAutofillPopup();
// InspectableWebContentsDelegate:
void DevToolsSaveToFile(const std::string& url,
const std::string& content,
bool save_as) override;
void DevToolsAppendToFile(const std::string& url,
const std::string& content) override;
void DevToolsRequestFileSystems() override;
void DevToolsAddFileSystem(const std::string& type,
const base::FilePath& file_system_path) override;
void DevToolsRemoveFileSystem(
const base::FilePath& file_system_path) override;
void DevToolsIndexPath(int request_id,
const std::string& file_system_path,
const std::string& excluded_folders_message) override;
void DevToolsStopIndexing(int request_id) override;
void DevToolsSearchInPath(int request_id,
const std::string& file_system_path,
const std::string& query) override;
// InspectableWebContentsViewDelegate:
#if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX)
2015-10-01 03:14:19 +00:00
gfx::ImageSkia GetDevToolsWindowIcon() override;
#endif
#if defined(USE_X11)
2018-04-18 01:44:10 +00:00
void GetDevToolsWindowWMClass(std::string* name,
std::string* class_name) override;
2015-10-01 03:14:19 +00:00
#endif
// Destroy the managed InspectableWebContents object.
void ResetManagedWebContents(bool async);
2015-06-05 05:49:12 +00:00
private:
// DevTools index event callbacks.
void OnDevToolsIndexingWorkCalculated(int request_id,
const std::string& file_system_path,
int total_work);
void OnDevToolsIndexingWorked(int request_id,
const std::string& file_system_path,
int worked);
void OnDevToolsIndexingDone(int request_id,
const std::string& file_system_path);
void OnDevToolsSearchCompleted(int request_id,
const std::string& file_system_path,
const std::vector<std::string>& file_paths);
// Set fullscreen mode triggered by html api.
void SetHtmlApiFullscreen(bool enter_fullscreen);
// The window that this WebContents belongs to.
2015-06-24 14:29:44 +00:00
base::WeakPtr<NativeWindow> owner_window_;
bool offscreen_ = false;
// Whether window is fullscreened by HTML5 api.
bool html_fullscreen_ = false;
// Whether window is fullscreened by window api.
bool native_fullscreen_ = false;
// UI related helper classes.
#if defined(TOOLKIT_VIEWS)
std::unique_ptr<AutofillPopup> autofill_popup_;
#endif
2016-05-23 01:59:39 +00:00
std::unique_ptr<WebDialogHelper> web_dialog_helper_;
scoped_refptr<DevToolsFileSystemIndexer> devtools_file_system_indexer_;
// Make sure BrowserContext is alwasys destroyed after WebContents.
scoped_refptr<AtomBrowserContext> browser_context_;
// The stored InspectableWebContents object.
// Notice that web_contents_ must be placed after dialog_manager_, so we can
// make sure web_contents_ is destroyed before dialog_manager_, otherwise a
// crash would happen.
std::unique_ptr<InspectableWebContents> web_contents_;
// Maps url to file path, used by the file requests sent from devtools.
typedef std::map<std::string, base::FilePath> PathsMap;
PathsMap saved_files_;
// Map id to index job, used for file system indexing requests from devtools.
2018-04-18 01:44:10 +00:00
typedef std::
map<int, scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob>>
DevToolsIndexingJobsMap;
DevToolsIndexingJobsMap devtools_indexing_jobs_;
scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
base::WeakPtrFactory<CommonWebContentsDelegate> weak_factory_;
2015-06-05 05:49:12 +00:00
DISALLOW_COPY_AND_ASSIGN(CommonWebContentsDelegate);
};
} // namespace atom
#endif // ATOM_BROWSER_COMMON_WEB_CONTENTS_DELEGATE_H_