2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2014-04-24 08:45:25 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_API_ATOM_API_WEB_CONTENTS_H_
|
|
|
|
#define ATOM_BROWSER_API_ATOM_API_WEB_CONTENTS_H_
|
|
|
|
|
2014-10-24 12:57:44 +00:00
|
|
|
#include <string>
|
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
#include "atom/browser/api/event_emitter.h"
|
2014-11-03 14:12:56 +00:00
|
|
|
#include "brightray/browser/default_web_contents_delegate.h"
|
2014-10-23 06:04:13 +00:00
|
|
|
#include "content/public/browser/browser_plugin_guest_delegate.h"
|
2014-10-23 15:08:48 +00:00
|
|
|
#include "content/public/browser/web_contents_delegate.h"
|
2014-04-25 03:22:51 +00:00
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
2014-04-24 08:45:25 +00:00
|
|
|
#include "native_mate/handle.h"
|
|
|
|
|
2014-11-02 15:32:33 +00:00
|
|
|
namespace brightray {
|
2014-11-03 11:45:09 +00:00
|
|
|
class InspectableWebContents;
|
2014-11-02 14:34:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-03 14:12:56 +00:00
|
|
|
namespace mate {
|
|
|
|
class Dictionary;
|
|
|
|
}
|
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2014-12-18 20:58:17 +00:00
|
|
|
class WebDialogHelper;
|
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
namespace api {
|
|
|
|
|
2014-04-25 03:22:51 +00:00
|
|
|
class WebContents : public mate::EventEmitter,
|
2014-10-23 06:04:13 +00:00
|
|
|
public content::BrowserPluginGuestDelegate,
|
2014-10-23 15:08:48 +00:00
|
|
|
public content::WebContentsDelegate,
|
2014-04-25 03:22:51 +00:00
|
|
|
public content::WebContentsObserver {
|
2014-04-24 08:45:25 +00:00
|
|
|
public:
|
2014-10-23 06:04:13 +00:00
|
|
|
// Create from an existing WebContents.
|
|
|
|
static mate::Handle<WebContents> CreateFrom(
|
|
|
|
v8::Isolate* isolate, content::WebContents* web_contents);
|
|
|
|
|
|
|
|
// Create a new WebContents.
|
|
|
|
static mate::Handle<WebContents> Create(
|
|
|
|
v8::Isolate* isolate, const mate::Dictionary& options);
|
2014-04-24 08:45:25 +00:00
|
|
|
|
2014-10-23 06:04:13 +00:00
|
|
|
void Destroy();
|
2014-04-25 03:22:51 +00:00
|
|
|
bool IsAlive() const;
|
2014-11-06 19:29:41 +00:00
|
|
|
void LoadURL(const GURL& url, const mate::Dictionary& options);
|
2014-04-24 09:00:41 +00:00
|
|
|
GURL GetURL() const;
|
2014-06-28 11:36:57 +00:00
|
|
|
base::string16 GetTitle() const;
|
2014-04-24 09:00:41 +00:00
|
|
|
bool IsLoading() const;
|
|
|
|
bool IsWaitingForResponse() const;
|
|
|
|
void Stop();
|
2014-11-06 19:29:41 +00:00
|
|
|
void Reload(const mate::Dictionary& options);
|
|
|
|
void ReloadIgnoringCache(const mate::Dictionary& options);
|
2014-04-25 04:52:30 +00:00
|
|
|
bool CanGoBack() const;
|
|
|
|
bool CanGoForward() const;
|
|
|
|
bool CanGoToOffset(int offset) const;
|
|
|
|
void GoBack();
|
|
|
|
void GoForward();
|
|
|
|
void GoToIndex(int index);
|
|
|
|
void GoToOffset(int offset);
|
2014-04-24 09:00:41 +00:00
|
|
|
int GetRoutingID() const;
|
|
|
|
int GetProcessID() const;
|
|
|
|
bool IsCrashed() const;
|
2014-10-24 12:57:44 +00:00
|
|
|
void SetUserAgent(const std::string& user_agent);
|
2014-10-24 13:04:50 +00:00
|
|
|
void InsertCSS(const std::string& css);
|
2014-06-28 11:36:57 +00:00
|
|
|
void ExecuteJavaScript(const base::string16& code);
|
2014-11-02 14:34:22 +00:00
|
|
|
void OpenDevTools();
|
2014-11-03 14:12:56 +00:00
|
|
|
void CloseDevTools();
|
|
|
|
bool IsDevToolsOpened();
|
2015-01-19 20:09:47 +00:00
|
|
|
|
|
|
|
// Editing commands.
|
|
|
|
void Undo();
|
|
|
|
void Redo();
|
|
|
|
void Cut();
|
|
|
|
void Copy();
|
|
|
|
void Paste();
|
|
|
|
void Delete();
|
|
|
|
void SelectAll();
|
|
|
|
void Unselect();
|
|
|
|
void Replace(const base::string16& word);
|
|
|
|
void ReplaceMisspelling(const base::string16& word);
|
|
|
|
|
|
|
|
// Sending messages to browser.
|
2014-06-28 11:36:57 +00:00
|
|
|
bool SendIPCMessage(const base::string16& channel,
|
|
|
|
const base::ListValue& args);
|
2014-04-24 09:00:41 +00:00
|
|
|
|
2014-10-24 06:37:14 +00:00
|
|
|
// Toggles autosize mode for corresponding <webview>.
|
|
|
|
void SetAutoSize(bool enabled,
|
|
|
|
const gfx::Size& min_size,
|
|
|
|
const gfx::Size& max_size);
|
|
|
|
|
2014-10-24 08:48:21 +00:00
|
|
|
// Sets the transparency of the guest.
|
|
|
|
void SetAllowTransparency(bool allow);
|
|
|
|
|
2014-10-24 08:09:18 +00:00
|
|
|
// Returns whether this is a guest view.
|
|
|
|
bool is_guest() const { return guest_instance_id_ != -1; }
|
|
|
|
|
2014-10-24 06:37:14 +00:00
|
|
|
// Returns whether this guest has an associated embedder.
|
|
|
|
bool attached() const { return !!embedder_web_contents_; }
|
|
|
|
|
2014-10-23 15:08:48 +00:00
|
|
|
content::WebContents* web_contents() const {
|
|
|
|
return content::WebContentsObserver::web_contents();
|
|
|
|
}
|
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
protected:
|
|
|
|
explicit WebContents(content::WebContents* web_contents);
|
2014-10-23 06:04:13 +00:00
|
|
|
explicit WebContents(const mate::Dictionary& options);
|
|
|
|
~WebContents();
|
2014-04-24 08:45:25 +00:00
|
|
|
|
2014-10-23 09:54:52 +00:00
|
|
|
// mate::Wrappable:
|
2014-12-16 01:15:56 +00:00
|
|
|
mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
2014-10-23 15:08:48 +00:00
|
|
|
v8::Isolate* isolate) override;
|
2014-04-25 03:22:51 +00:00
|
|
|
|
2014-10-24 10:06:32 +00:00
|
|
|
// content::WebContentsDelegate:
|
2014-10-25 02:01:19 +00:00
|
|
|
bool AddMessageToConsole(content::WebContents* source,
|
|
|
|
int32 level,
|
|
|
|
const base::string16& message,
|
|
|
|
int32 line_no,
|
|
|
|
const base::string16& source_id) override;
|
2014-10-25 05:21:09 +00:00
|
|
|
bool ShouldCreateWebContents(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
int route_id,
|
|
|
|
WindowContainerType window_container_type,
|
|
|
|
const base::string16& frame_name,
|
|
|
|
const GURL& target_url,
|
|
|
|
const std::string& partition_id,
|
|
|
|
content::SessionStorageNamespace* session_storage_namespace) override;
|
2014-10-25 02:01:19 +00:00
|
|
|
void CloseContents(content::WebContents* source) override;
|
2014-10-24 13:46:47 +00:00
|
|
|
content::WebContents* OpenURLFromTab(
|
2014-10-24 10:06:32 +00:00
|
|
|
content::WebContents* source,
|
|
|
|
const content::OpenURLParams& params) override;
|
2014-12-18 20:58:17 +00:00
|
|
|
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-01-23 23:13:49 +00:00
|
|
|
bool CheckMediaAccessPermission(content::WebContents* web_contents,
|
|
|
|
const GURL& security_origin,
|
|
|
|
content::MediaStreamType type) override;
|
2014-12-18 20:02:23 +00:00
|
|
|
void RequestMediaAccessPermission(
|
|
|
|
content::WebContents*,
|
|
|
|
const content::MediaStreamRequest&,
|
|
|
|
const content::MediaResponseCallback&) override;
|
2014-10-24 13:46:47 +00:00
|
|
|
void HandleKeyboardEvent(
|
|
|
|
content::WebContents* source,
|
|
|
|
const content::NativeWebKeyboardEvent& event) override;
|
2014-10-24 10:06:32 +00:00
|
|
|
|
2014-10-23 09:54:52 +00:00
|
|
|
// content::WebContentsObserver:
|
2014-12-09 22:38:43 +00:00
|
|
|
void RenderViewDeleted(content::RenderViewHost*) override;
|
|
|
|
void RenderProcessGone(base::TerminationStatus status) override;
|
|
|
|
void DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& validated_url) override;
|
|
|
|
void DidFailLoad(content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& validated_url,
|
|
|
|
int error_code,
|
|
|
|
const base::string16& error_description) override;
|
2015-03-14 03:28:30 +00:00
|
|
|
void DidFailProvisionalLoad(content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& validated_url,
|
|
|
|
int error_code,
|
|
|
|
const base::string16& error_description) override;
|
2014-12-09 22:38:43 +00:00
|
|
|
void DidStartLoading(content::RenderViewHost* render_view_host) override;
|
|
|
|
void DidStopLoading(content::RenderViewHost* render_view_host) override;
|
|
|
|
void DidGetRedirectForResourceRequest(
|
2014-10-24 15:05:25 +00:00
|
|
|
content::RenderViewHost* render_view_host,
|
|
|
|
const content::ResourceRedirectDetails& details) override;
|
2014-12-09 22:38:43 +00:00
|
|
|
void DidNavigateMainFrame(
|
|
|
|
const content::LoadCommittedDetails& details,
|
|
|
|
const content::FrameNavigateParams& params) override;
|
|
|
|
bool OnMessageReceived(const IPC::Message& message) override;
|
|
|
|
void RenderViewReady() override;
|
|
|
|
void WebContentsDestroyed() override;
|
2015-03-05 14:39:27 +00:00
|
|
|
void NavigationEntryCommitted(
|
|
|
|
const content::LoadCommittedDetails& load_details) override;
|
2014-04-24 08:45:25 +00:00
|
|
|
|
2014-10-23 09:54:52 +00:00
|
|
|
// content::BrowserPluginGuestDelegate:
|
2014-12-07 15:43:26 +00:00
|
|
|
void DidAttach(int guest_proxy_routing_id) final;
|
|
|
|
void ElementSizeChanged(const gfx::Size& old_size,
|
|
|
|
const gfx::Size& new_size) final;
|
|
|
|
void GuestSizeChanged(const gfx::Size& old_size,
|
|
|
|
const gfx::Size& new_size) final;
|
|
|
|
void RegisterDestructionCallback(const DestructionCallback& callback) final;
|
|
|
|
void WillAttach(content::WebContents* embedder_web_contents,
|
|
|
|
int browser_plugin_instance_id) final;
|
2014-10-23 09:54:52 +00:00
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
private:
|
2014-04-25 08:13:16 +00:00
|
|
|
// Called when received a message from renderer.
|
2014-06-28 11:36:57 +00:00
|
|
|
void OnRendererMessage(const base::string16& channel,
|
|
|
|
const base::ListValue& args);
|
2014-04-25 08:13:16 +00:00
|
|
|
|
|
|
|
// Called when received a synchronous message from renderer.
|
2014-06-28 11:36:57 +00:00
|
|
|
void OnRendererMessageSync(const base::string16& channel,
|
2014-04-25 08:13:16 +00:00
|
|
|
const base::ListValue& args,
|
|
|
|
IPC::Message* message);
|
|
|
|
|
2014-10-24 06:37:14 +00:00
|
|
|
void GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
|
|
|
|
const gfx::Size& new_size);
|
|
|
|
|
2014-12-18 20:58:17 +00:00
|
|
|
scoped_ptr<WebDialogHelper> web_dialog_helper_;
|
|
|
|
|
2014-10-23 09:54:52 +00:00
|
|
|
// Unique ID for a guest WebContents.
|
|
|
|
int guest_instance_id_;
|
|
|
|
|
2014-12-08 16:05:34 +00:00
|
|
|
// |element_instance_id_| is an identifer that's unique to a particular
|
|
|
|
// element.
|
|
|
|
int element_instance_id_;
|
|
|
|
|
2014-10-23 09:54:52 +00:00
|
|
|
DestructionCallback destruction_callback_;
|
|
|
|
|
2014-10-24 08:48:21 +00:00
|
|
|
// Stores whether the contents of the guest can be transparent.
|
|
|
|
bool guest_opaque_;
|
|
|
|
|
2014-10-23 06:04:13 +00:00
|
|
|
// Stores the WebContents that managed by this class.
|
2014-11-03 11:45:09 +00:00
|
|
|
scoped_ptr<brightray::InspectableWebContents> storage_;
|
2014-04-24 08:45:25 +00:00
|
|
|
|
2014-10-24 06:37:14 +00:00
|
|
|
// The WebContents that attaches this guest view.
|
|
|
|
content::WebContents* embedder_web_contents_;
|
|
|
|
|
|
|
|
// The size of the container element.
|
|
|
|
gfx::Size element_size_;
|
|
|
|
|
|
|
|
// The size of the guest content. Note: In autosize mode, the container
|
|
|
|
// element may not match the size of the guest.
|
|
|
|
gfx::Size guest_size_;
|
|
|
|
|
|
|
|
// Indicates whether autosize mode is enabled or not.
|
|
|
|
bool auto_size_enabled_;
|
|
|
|
|
|
|
|
// The maximum size constraints of the container element in autosize mode.
|
|
|
|
gfx::Size max_auto_size_;
|
|
|
|
|
|
|
|
// The minimum size constraints of the container element in autosize mode.
|
|
|
|
gfx::Size min_auto_size_;
|
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(WebContents);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_API_ATOM_API_WEB_CONTENTS_H_
|