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_
|
|
|
|
|
2015-06-05 06:55:07 +00:00
|
|
|
#include <map>
|
2015-06-05 09:01:17 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2015-06-05 06:55:07 +00:00
|
|
|
|
2015-06-05 05:49:12 +00:00
|
|
|
#include "brightray/browser/default_web_contents_delegate.h"
|
2015-06-05 06:55:07 +00:00
|
|
|
#include "brightray/browser/inspectable_web_contents_impl.h"
|
|
|
|
#include "brightray/browser/inspectable_web_contents_delegate.h"
|
2015-06-05 05:49:12 +00:00
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
2015-06-05 06:55:07 +00:00
|
|
|
class AtomJavaScriptDialogManager;
|
|
|
|
class NativeWindow;
|
2015-06-05 07:12:38 +00:00
|
|
|
class WebDialogHelper;
|
2015-06-05 06:55:07 +00:00
|
|
|
|
|
|
|
class CommonWebContentsDelegate
|
|
|
|
: public brightray::DefaultWebContentsDelegate,
|
|
|
|
public brightray::InspectableWebContentsDelegate {
|
2015-06-05 05:49:12 +00:00
|
|
|
public:
|
|
|
|
explicit CommonWebContentsDelegate(bool is_guest);
|
|
|
|
virtual ~CommonWebContentsDelegate();
|
|
|
|
|
2015-06-05 06:55:07 +00:00
|
|
|
// Create a InspectableWebContents object and takes onwership of
|
|
|
|
// |web_contents|.
|
|
|
|
void InitWithWebContents(content::WebContents* web_contents,
|
|
|
|
NativeWindow* owner_window);
|
|
|
|
|
|
|
|
// Destroy the managed InspectableWebContents object.
|
|
|
|
void DestroyWebContents();
|
|
|
|
|
|
|
|
// Returns the WebContents managed by this delegate.
|
|
|
|
content::WebContents* GetWebContents() const;
|
|
|
|
|
|
|
|
// Returns the WebContents of devtools.
|
|
|
|
content::WebContents* GetDevToolsWebContents() const;
|
|
|
|
|
2015-06-05 07:41:03 +00:00
|
|
|
brightray::InspectableWebContents* managed_web_contents() const {
|
2015-06-05 06:55:07 +00:00
|
|
|
return web_contents_.get();
|
|
|
|
}
|
|
|
|
|
2015-06-05 09:01:17 +00:00
|
|
|
bool is_guest() const { return is_guest_; }
|
2015-06-05 05:49:12 +00:00
|
|
|
|
2015-06-05 06:55:07 +00:00
|
|
|
protected:
|
|
|
|
// content::WebContentsDelegate:
|
2015-06-05 07:12:38 +00:00
|
|
|
void RequestToLockMouse(content::WebContents* web_contents,
|
|
|
|
bool user_gesture,
|
|
|
|
bool last_unlocked_by_target) override;
|
|
|
|
bool CanOverscrollContent() const override;
|
|
|
|
bool IsPopupOrPanel(const content::WebContents* source) const override;
|
2015-06-05 06:55:07 +00:00
|
|
|
content::JavaScriptDialogManager* GetJavaScriptDialogManager(
|
|
|
|
content::WebContents* source) override;
|
2015-06-05 07:12:38 +00:00
|
|
|
content::ColorChooser* OpenColorChooser(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
SkColor color,
|
|
|
|
const std::vector<content::ColorSuggestion>& suggestions) override;
|
|
|
|
void RunFileChooser(content::WebContents* web_contents,
|
|
|
|
const content::FileChooserParams& params) override;
|
|
|
|
void EnumerateDirectory(content::WebContents* web_contents,
|
|
|
|
int request_id,
|
|
|
|
const base::FilePath& path) override;
|
2015-06-05 06:55:07 +00:00
|
|
|
|
|
|
|
// brightray::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 DevToolsAddFileSystem() override;
|
|
|
|
void DevToolsRemoveFileSystem(const std::string& file_system_path) override;
|
|
|
|
|
2015-06-05 05:49:12 +00:00
|
|
|
private:
|
2015-06-05 06:55:07 +00:00
|
|
|
// Whether this is guest WebContents or NativeWindow.
|
2015-06-05 05:49:12 +00:00
|
|
|
const bool is_guest_;
|
|
|
|
|
2015-06-05 06:55:07 +00:00
|
|
|
// The window that this WebContents belongs to.
|
|
|
|
NativeWindow* owner_window_;
|
|
|
|
|
2015-06-05 07:12:38 +00:00
|
|
|
scoped_ptr<WebDialogHelper> web_dialog_helper_;
|
2015-06-05 06:55:07 +00:00
|
|
|
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
scoped_ptr<brightray::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_;
|
|
|
|
|
|
|
|
// Maps file system id to file path, used by the file system requests
|
|
|
|
// sent from devtools.
|
|
|
|
typedef std::map<std::string, base::FilePath> WorkspaceMap;
|
|
|
|
WorkspaceMap saved_paths_;
|
|
|
|
|
2015-06-05 05:49:12 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CommonWebContentsDelegate);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_COMMON_WEB_CONTENTS_DELEGATE_H_
|