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.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_BROWSER_COMMON_WEB_CONTENTS_DELEGATE_H_
|
|
|
|
#define SHELL_BROWSER_COMMON_WEB_CONTENTS_DELEGATE_H_
|
2015-06-05 05:49:12 +00:00
|
|
|
|
2015-06-05 06:55:07 +00:00
|
|
|
#include <map>
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
2015-06-05 09:01:17 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2015-06-05 06:55:07 +00:00
|
|
|
|
2018-09-12 13:45:08 +00:00
|
|
|
#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"
|
2018-10-11 13:14:01 +00:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/inspectable_web_contents_delegate.h"
|
|
|
|
#include "shell/browser/ui/inspectable_web_contents_impl.h"
|
|
|
|
#include "shell/browser/ui/inspectable_web_contents_view_delegate.h"
|
2015-06-05 05:49:12 +00:00
|
|
|
|
2018-04-09 09:16:52 +00:00
|
|
|
namespace base {
|
|
|
|
class SequencedTaskRunner;
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2015-06-05 05:49:12 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
class ElectronBrowserContext;
|
2015-06-05 06:55:07 +00:00
|
|
|
class NativeWindow;
|
2015-06-05 07:12:38 +00:00
|
|
|
class WebDialogHelper;
|
2015-06-05 06:55:07 +00:00
|
|
|
|
2018-10-11 13:14:01 +00:00
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2018-11-30 05:25:02 +00:00
|
|
|
class OffScreenWebContentsView;
|
2018-10-11 13:14:01 +00:00
|
|
|
#endif
|
|
|
|
|
2018-10-19 13:50:30 +00:00
|
|
|
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();
|
2018-04-17 23:03:51 +00:00
|
|
|
~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
|
2015-06-05 06:55:07 +00:00
|
|
|
// |web_contents|.
|
2016-05-17 12:49:05 +00:00
|
|
|
void InitWithWebContents(content::WebContents* web_contents,
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext* browser_context,
|
2018-08-16 22:57:40 +00:00
|
|
|
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);
|
2015-06-05 06:55:07 +00:00
|
|
|
|
|
|
|
// Returns the WebContents managed by this delegate.
|
|
|
|
content::WebContents* GetWebContents() const;
|
|
|
|
|
|
|
|
// Returns the WebContents of devtools.
|
|
|
|
content::WebContents* GetDevToolsWebContents() const;
|
|
|
|
|
2018-10-19 13:50:30 +00:00
|
|
|
InspectableWebContents* managed_web_contents() const {
|
2015-06-05 06:55:07 +00:00
|
|
|
return web_contents_.get();
|
|
|
|
}
|
|
|
|
|
2015-06-24 14:29:44 +00:00
|
|
|
NativeWindow* owner_window() const { return owner_window_.get(); }
|
|
|
|
|
2015-08-18 17:02:34 +00:00
|
|
|
bool is_html_fullscreen() const { return html_fullscreen_; }
|
|
|
|
|
2019-06-13 21:02:56 +00:00
|
|
|
void set_fullscreen_frame(content::RenderFrameHost* rfh) {
|
|
|
|
fullscreen_frame_ = rfh;
|
|
|
|
}
|
|
|
|
|
2015-06-05 06:55:07 +00:00
|
|
|
protected:
|
2018-10-11 13:14:01 +00:00
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2018-11-30 05:25:02 +00:00
|
|
|
virtual OffScreenWebContentsView* GetOffScreenWebContentsView() const;
|
2018-10-11 13:14:01 +00:00
|
|
|
#endif
|
|
|
|
|
2015-06-05 06:55:07 +00:00
|
|
|
// content::WebContentsDelegate:
|
2015-06-05 09:45:17 +00:00
|
|
|
content::WebContents* OpenURLFromTab(
|
|
|
|
content::WebContents* source,
|
|
|
|
const content::OpenURLParams& params) override;
|
2019-07-03 01:22:09 +00:00
|
|
|
bool CanOverscrollContent() override;
|
2015-06-05 07:12:38 +00:00
|
|
|
content::ColorChooser* OpenColorChooser(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
SkColor color,
|
2018-04-08 16:17:23 +00:00
|
|
|
const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions)
|
|
|
|
override;
|
2016-09-06 08:24:37 +00:00
|
|
|
void RunFileChooser(content::RenderFrameHost* render_frame_host,
|
2019-01-12 01:00:43 +00:00
|
|
|
std::unique_ptr<content::FileSelectListener> listener,
|
|
|
|
const blink::mojom::FileChooserParams& params) override;
|
2015-06-05 07:12:38 +00:00
|
|
|
void EnumerateDirectory(content::WebContents* web_contents,
|
2019-01-12 01:00:43 +00:00
|
|
|
std::unique_ptr<content::FileSelectListener> listener,
|
2015-06-05 07:12:38 +00:00
|
|
|
const base::FilePath& path) override;
|
2018-09-15 00:17:50 +00:00
|
|
|
void EnterFullscreenModeForTab(
|
2020-06-01 20:34:34 +00:00
|
|
|
content::RenderFrameHost* requesting_frame,
|
2019-10-28 22:12:35 +00:00
|
|
|
const blink::mojom::FullscreenOptions& options) override;
|
2015-06-05 09:27:24 +00:00
|
|
|
void ExitFullscreenModeForTab(content::WebContents* source) override;
|
2019-07-03 01:22:09 +00:00
|
|
|
bool IsFullscreenForTabOrPending(const content::WebContents* source) override;
|
2019-10-28 22:12:35 +00:00
|
|
|
blink::SecurityStyle GetSecurityStyle(
|
2016-04-11 09:36:33 +00:00
|
|
|
content::WebContents* web_contents,
|
|
|
|
content::SecurityStyleExplanations* explanations) override;
|
2018-12-19 06:44:51 +00:00
|
|
|
bool TakeFocus(content::WebContents* source, bool reverse) override;
|
2019-01-09 20:01:49 +00:00
|
|
|
bool HandleKeyboardEvent(
|
2016-05-18 04:47:50 +00:00
|
|
|
content::WebContents* source,
|
|
|
|
const content::NativeWebKeyboardEvent& event) override;
|
2019-08-22 10:17:50 +00:00
|
|
|
content::PictureInPictureResult EnterPictureInPicture(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
const viz::SurfaceId&,
|
|
|
|
const gfx::Size& natural_size) override;
|
|
|
|
void ExitPictureInPicture() override;
|
2015-06-05 06:55:07 +00:00
|
|
|
|
2018-10-19 13:50:30 +00:00
|
|
|
// InspectableWebContentsDelegate:
|
2015-06-05 06:55:07 +00:00
|
|
|
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;
|
2016-03-15 02:21:36 +00:00
|
|
|
void DevToolsRequestFileSystems() override;
|
2018-09-12 13:45:08 +00:00
|
|
|
void DevToolsAddFileSystem(const std::string& type,
|
|
|
|
const base::FilePath& file_system_path) override;
|
2015-07-24 09:39:11 +00:00
|
|
|
void DevToolsRemoveFileSystem(
|
|
|
|
const base::FilePath& file_system_path) override;
|
2016-05-06 23:02:54 +00:00
|
|
|
void DevToolsIndexPath(int request_id,
|
2018-09-12 13:45:08 +00:00
|
|
|
const std::string& file_system_path,
|
|
|
|
const std::string& excluded_folders_message) override;
|
2016-05-06 23:02:54 +00:00
|
|
|
void DevToolsStopIndexing(int request_id) override;
|
|
|
|
void DevToolsSearchInPath(int request_id,
|
|
|
|
const std::string& file_system_path,
|
|
|
|
const std::string& query) override;
|
2015-06-05 06:55:07 +00:00
|
|
|
|
2018-10-19 13:50:30 +00:00
|
|
|
// InspectableWebContentsViewDelegate:
|
2018-05-10 20:52:17 +00:00
|
|
|
#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
|
|
|
|
|
2017-03-22 02:00:36 +00:00
|
|
|
// Destroy the managed InspectableWebContents object.
|
2017-04-03 20:03:51 +00:00
|
|
|
void ResetManagedWebContents(bool async);
|
2017-03-22 02:00:36 +00:00
|
|
|
|
2015-06-05 05:49:12 +00:00
|
|
|
private:
|
2018-04-05 00:53:51 +00:00
|
|
|
// DevTools index event callbacks.
|
2016-05-06 23:02:54 +00:00
|
|
|
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);
|
|
|
|
|
2015-06-05 09:27:24 +00:00
|
|
|
// Set fullscreen mode triggered by html api.
|
|
|
|
void SetHtmlApiFullscreen(bool enter_fullscreen);
|
|
|
|
|
2015-06-05 06:55:07 +00:00
|
|
|
// The window that this WebContents belongs to.
|
2015-06-24 14:29:44 +00:00
|
|
|
base::WeakPtr<NativeWindow> owner_window_;
|
2015-06-05 06:55:07 +00:00
|
|
|
|
2018-05-21 22:18:38 +00:00
|
|
|
bool offscreen_ = false;
|
2017-06-25 19:01:05 +00:00
|
|
|
|
2015-06-05 09:27:24 +00:00
|
|
|
// Whether window is fullscreened by HTML5 api.
|
2018-05-21 22:18:38 +00:00
|
|
|
bool html_fullscreen_ = false;
|
2015-06-05 09:27:24 +00:00
|
|
|
|
|
|
|
// Whether window is fullscreened by window api.
|
2018-05-21 22:18:38 +00:00
|
|
|
bool native_fullscreen_ = false;
|
2015-06-05 09:27:24 +00:00
|
|
|
|
2018-04-05 00:53:51 +00:00
|
|
|
// UI related helper classes.
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<WebDialogHelper> web_dialog_helper_;
|
2018-04-05 00:53:51 +00:00
|
|
|
|
2016-05-06 23:02:54 +00:00
|
|
|
scoped_refptr<DevToolsFileSystemIndexer> devtools_file_system_indexer_;
|
2015-06-05 06:55:07 +00:00
|
|
|
|
2016-05-17 12:49:05 +00:00
|
|
|
// Make sure BrowserContext is alwasys destroyed after WebContents.
|
2020-02-04 20:19:40 +00:00
|
|
|
scoped_refptr<ElectronBrowserContext> browser_context_;
|
2016-05-17 12:49:05 +00:00
|
|
|
|
2015-06-05 06:55:07 +00:00
|
|
|
// 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.
|
2018-10-19 13:50:30 +00:00
|
|
|
std::unique_ptr<InspectableWebContents> web_contents_;
|
2015-06-05 06:55:07 +00:00
|
|
|
|
|
|
|
// Maps url to file path, used by the file requests sent from devtools.
|
|
|
|
typedef std::map<std::string, base::FilePath> PathsMap;
|
|
|
|
PathsMap saved_files_;
|
|
|
|
|
2016-05-06 23:02:54 +00:00
|
|
|
// 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;
|
2016-05-06 23:02:54 +00:00
|
|
|
DevToolsIndexingJobsMap devtools_indexing_jobs_;
|
|
|
|
|
2018-04-09 09:16:52 +00:00
|
|
|
scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
|
|
|
|
|
2019-06-13 21:02:56 +00:00
|
|
|
// Stores the frame thats currently in fullscreen, nullptr if there is none.
|
|
|
|
content::RenderFrameHost* fullscreen_frame_ = nullptr;
|
|
|
|
|
2018-09-12 13:45:08 +00:00
|
|
|
base::WeakPtrFactory<CommonWebContentsDelegate> weak_factory_;
|
|
|
|
|
2015-06-05 05:49:12 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CommonWebContentsDelegate);
|
|
|
|
};
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2015-06-05 05:49:12 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_COMMON_WEB_CONTENTS_DELEGATE_H_
|