2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-04-25 17:49:37 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2014-04-24 16:45:25 +08: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 20:57:44 +08:00
|
|
|
#include <string>
|
2015-04-18 01:25:31 +05:30
|
|
|
#include <vector>
|
2014-10-24 20:57:44 +08:00
|
|
|
|
2014-04-24 16:45:25 +08:00
|
|
|
#include "atom/browser/api/event_emitter.h"
|
2014-11-03 22:12:56 +08:00
|
|
|
#include "brightray/browser/default_web_contents_delegate.h"
|
2014-10-23 14:04:13 +08:00
|
|
|
#include "content/public/browser/browser_plugin_guest_delegate.h"
|
2015-04-18 01:25:31 +05:30
|
|
|
#include "content/public/common/favicon_url.h"
|
2014-10-23 23:08:48 +08:00
|
|
|
#include "content/public/browser/web_contents_delegate.h"
|
2014-04-25 11:22:51 +08:00
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
2014-04-24 16:45:25 +08:00
|
|
|
#include "native_mate/handle.h"
|
2015-04-20 12:20:04 +05:30
|
|
|
#include "ui/gfx/image/image.h"
|
2014-04-24 16:45:25 +08:00
|
|
|
|
2014-11-02 07:32:33 -08:00
|
|
|
namespace brightray {
|
2014-11-03 19:45:09 +08:00
|
|
|
class InspectableWebContents;
|
2014-11-02 06:34:22 -08:00
|
|
|
}
|
|
|
|
|
2014-11-03 22:12:56 +08:00
|
|
|
namespace mate {
|
|
|
|
class Dictionary;
|
|
|
|
}
|
|
|
|
|
2014-04-24 16:45:25 +08:00
|
|
|
namespace atom {
|
|
|
|
|
2015-05-01 13:48:39 +08:00
|
|
|
class AtomJavaScriptDialogManager;
|
2014-12-18 12:58:17 -08:00
|
|
|
class WebDialogHelper;
|
|
|
|
|
2014-04-24 16:45:25 +08:00
|
|
|
namespace api {
|
|
|
|
|
2014-04-25 11:22:51 +08:00
|
|
|
class WebContents : public mate::EventEmitter,
|
2014-10-23 14:04:13 +08:00
|
|
|
public content::BrowserPluginGuestDelegate,
|
2014-10-23 23:08:48 +08:00
|
|
|
public content::WebContentsDelegate,
|
2014-04-25 11:22:51 +08:00
|
|
|
public content::WebContentsObserver {
|
2014-04-24 16:45:25 +08:00
|
|
|
public:
|
2014-10-23 14:04:13 +08: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 16:45:25 +08:00
|
|
|
|
2014-10-23 14:04:13 +08:00
|
|
|
void Destroy();
|
2014-04-25 11:22:51 +08:00
|
|
|
bool IsAlive() const;
|
2014-11-06 14:29:41 -05:00
|
|
|
void LoadURL(const GURL& url, const mate::Dictionary& options);
|
2014-06-28 19:36:57 +08:00
|
|
|
base::string16 GetTitle() const;
|
2014-04-24 17:00:41 +08:00
|
|
|
bool IsLoading() const;
|
|
|
|
bool IsWaitingForResponse() const;
|
|
|
|
void Stop();
|
2015-04-26 21:28:30 +08:00
|
|
|
void ReloadIgnoringCache();
|
2015-05-11 14:30:26 +08:00
|
|
|
void GoBack();
|
|
|
|
void GoForward();
|
2015-05-11 16:44:01 +08:00
|
|
|
void GoToOffset(int offset);
|
2014-04-24 17:00:41 +08:00
|
|
|
int GetRoutingID() const;
|
|
|
|
int GetProcessID() const;
|
|
|
|
bool IsCrashed() const;
|
2014-10-24 20:57:44 +08:00
|
|
|
void SetUserAgent(const std::string& user_agent);
|
2014-10-24 21:04:50 +08:00
|
|
|
void InsertCSS(const std::string& css);
|
2014-06-28 19:36:57 +08:00
|
|
|
void ExecuteJavaScript(const base::string16& code);
|
2014-11-02 06:34:22 -08:00
|
|
|
void OpenDevTools();
|
2014-11-03 22:12:56 +08:00
|
|
|
void CloseDevTools();
|
|
|
|
bool IsDevToolsOpened();
|
2015-04-22 13:00:10 +05:30
|
|
|
void InspectElement(int x, int y);
|
2015-04-30 18:45:19 +05:30
|
|
|
void HasServiceWorker(const base::Callback<void(bool)>&);
|
|
|
|
void UnregisterServiceWorker(const base::Callback<void(bool)>&);
|
2015-01-19 12:09:47 -08: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 19:36:57 +08:00
|
|
|
bool SendIPCMessage(const base::string16& channel,
|
|
|
|
const base::ListValue& args);
|
2014-04-24 17:00:41 +08:00
|
|
|
|
2014-10-24 14:37:14 +08:00
|
|
|
// Toggles autosize mode for corresponding <webview>.
|
|
|
|
void SetAutoSize(bool enabled,
|
|
|
|
const gfx::Size& min_size,
|
|
|
|
const gfx::Size& max_size);
|
|
|
|
|
2014-10-24 16:48:21 +08:00
|
|
|
// Sets the transparency of the guest.
|
|
|
|
void SetAllowTransparency(bool allow);
|
|
|
|
|
2014-10-24 16:09:18 +08:00
|
|
|
// Returns whether this is a guest view.
|
|
|
|
bool is_guest() const { return guest_instance_id_ != -1; }
|
|
|
|
|
2014-10-24 14:37:14 +08:00
|
|
|
// Returns whether this guest has an associated embedder.
|
|
|
|
bool attached() const { return !!embedder_web_contents_; }
|
|
|
|
|
2014-10-23 23:08:48 +08:00
|
|
|
content::WebContents* web_contents() const {
|
|
|
|
return content::WebContentsObserver::web_contents();
|
|
|
|
}
|
|
|
|
|
2014-04-24 16:45:25 +08:00
|
|
|
protected:
|
|
|
|
explicit WebContents(content::WebContents* web_contents);
|
2014-10-23 14:04:13 +08:00
|
|
|
explicit WebContents(const mate::Dictionary& options);
|
|
|
|
~WebContents();
|
2014-04-24 16:45:25 +08:00
|
|
|
|
2014-10-23 17:54:52 +08:00
|
|
|
// mate::Wrappable:
|
2014-12-15 17:15:56 -08:00
|
|
|
mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
2014-10-23 23:08:48 +08:00
|
|
|
v8::Isolate* isolate) override;
|
2014-04-25 11:22:51 +08:00
|
|
|
|
2014-10-24 18:06:32 +08:00
|
|
|
// content::WebContentsDelegate:
|
2014-10-25 10:01:19 +08:00
|
|
|
bool AddMessageToConsole(content::WebContents* source,
|
|
|
|
int32 level,
|
|
|
|
const base::string16& message,
|
|
|
|
int32 line_no,
|
|
|
|
const base::string16& source_id) override;
|
2014-10-25 13:21:09 +08:00
|
|
|
bool ShouldCreateWebContents(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
int route_id,
|
2015-03-10 15:54:21 -07:00
|
|
|
int main_frame_route_id,
|
2014-10-25 13:21:09 +08:00
|
|
|
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 10:01:19 +08:00
|
|
|
void CloseContents(content::WebContents* source) override;
|
2014-10-24 21:46:47 +08:00
|
|
|
content::WebContents* OpenURLFromTab(
|
2014-10-24 18:06:32 +08:00
|
|
|
content::WebContents* source,
|
|
|
|
const content::OpenURLParams& params) override;
|
2015-05-01 13:48:39 +08:00
|
|
|
content::JavaScriptDialogManager* GetJavaScriptDialogManager(
|
|
|
|
content::WebContents* source) override;
|
2014-12-18 12:58:17 -08: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 15:13:49 -08:00
|
|
|
bool CheckMediaAccessPermission(content::WebContents* web_contents,
|
|
|
|
const GURL& security_origin,
|
|
|
|
content::MediaStreamType type) override;
|
2014-12-18 12:02:23 -08:00
|
|
|
void RequestMediaAccessPermission(
|
|
|
|
content::WebContents*,
|
|
|
|
const content::MediaStreamRequest&,
|
|
|
|
const content::MediaResponseCallback&) override;
|
2014-10-24 21:46:47 +08:00
|
|
|
void HandleKeyboardEvent(
|
|
|
|
content::WebContents* source,
|
|
|
|
const content::NativeWebKeyboardEvent& event) override;
|
2014-10-24 18:06:32 +08:00
|
|
|
|
2014-10-23 17:54:52 +08:00
|
|
|
// content::WebContentsObserver:
|
2014-12-09 14:38:43 -08:00
|
|
|
void RenderViewDeleted(content::RenderViewHost*) override;
|
|
|
|
void RenderProcessGone(base::TerminationStatus status) override;
|
2015-04-29 19:19:31 +05:30
|
|
|
void DocumentLoadedInFrame(
|
|
|
|
content::RenderFrameHost* render_frame_host) override;
|
2014-12-09 14:38:43 -08:00
|
|
|
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 08:58:30 +05:30
|
|
|
void DidFailProvisionalLoad(content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& validated_url,
|
|
|
|
int error_code,
|
|
|
|
const base::string16& error_description) override;
|
2014-12-09 14:38:43 -08:00
|
|
|
void DidStartLoading(content::RenderViewHost* render_view_host) override;
|
|
|
|
void DidStopLoading(content::RenderViewHost* render_view_host) override;
|
2015-04-08 19:14:47 +05:30
|
|
|
void DidGetResourceResponseStart(
|
|
|
|
const content::ResourceRequestDetails& details) override;
|
2014-12-09 14:38:43 -08:00
|
|
|
void DidGetRedirectForResourceRequest(
|
2015-03-10 15:54:21 -07:00
|
|
|
content::RenderFrameHost* render_frame_host,
|
2014-10-24 23:05:25 +08:00
|
|
|
const content::ResourceRedirectDetails& details) override;
|
2014-12-09 14:38:43 -08: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 20:09:27 +05:30
|
|
|
void NavigationEntryCommitted(
|
|
|
|
const content::LoadCommittedDetails& load_details) override;
|
2015-04-05 14:50:42 +05:30
|
|
|
void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override;
|
2015-04-18 01:25:31 +05:30
|
|
|
void DidUpdateFaviconURL(
|
|
|
|
const std::vector<content::FaviconURL>& urls) override;
|
2014-04-24 16:45:25 +08:00
|
|
|
|
2014-10-23 17:54:52 +08:00
|
|
|
// content::BrowserPluginGuestDelegate:
|
2014-12-07 07:43:26 -08:00
|
|
|
void DidAttach(int guest_proxy_routing_id) final;
|
2015-03-10 15:54:21 -07:00
|
|
|
void ElementSizeChanged(const gfx::Size& size) final;
|
2015-03-13 16:33:06 -07:00
|
|
|
content::WebContents* GetOwnerWebContents() const final;
|
2015-04-21 18:56:08 +08:00
|
|
|
void GuestSizeChanged(const gfx::Size& new_size) final;
|
2014-12-07 07:43:26 -08:00
|
|
|
void RegisterDestructionCallback(const DestructionCallback& callback) final;
|
2015-03-13 16:33:06 -07:00
|
|
|
void SetGuestSizer(content::GuestSizer* guest_sizer) final;
|
2014-12-07 07:43:26 -08:00
|
|
|
void WillAttach(content::WebContents* embedder_web_contents,
|
2015-03-10 15:54:21 -07:00
|
|
|
int element_instance_id,
|
|
|
|
bool is_full_page_plugin) final;
|
2014-10-23 17:54:52 +08:00
|
|
|
|
2014-04-24 16:45:25 +08:00
|
|
|
private:
|
2014-04-25 16:13:16 +08:00
|
|
|
// Called when received a message from renderer.
|
2014-06-28 19:36:57 +08:00
|
|
|
void OnRendererMessage(const base::string16& channel,
|
|
|
|
const base::ListValue& args);
|
2014-04-25 16:13:16 +08:00
|
|
|
|
|
|
|
// Called when received a synchronous message from renderer.
|
2014-06-28 19:36:57 +08:00
|
|
|
void OnRendererMessageSync(const base::string16& channel,
|
2014-04-25 16:13:16 +08:00
|
|
|
const base::ListValue& args,
|
|
|
|
IPC::Message* message);
|
|
|
|
|
2014-10-24 14:37:14 +08:00
|
|
|
void GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
|
|
|
|
const gfx::Size& new_size);
|
|
|
|
|
2014-12-18 12:58:17 -08:00
|
|
|
scoped_ptr<WebDialogHelper> web_dialog_helper_;
|
2015-05-01 13:48:39 +08:00
|
|
|
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
2014-12-18 12:58:17 -08:00
|
|
|
|
2014-10-23 17:54:52 +08:00
|
|
|
// Unique ID for a guest WebContents.
|
|
|
|
int guest_instance_id_;
|
|
|
|
|
2014-12-08 08:05:34 -08:00
|
|
|
// |element_instance_id_| is an identifer that's unique to a particular
|
|
|
|
// element.
|
|
|
|
int element_instance_id_;
|
|
|
|
|
2014-10-23 17:54:52 +08:00
|
|
|
DestructionCallback destruction_callback_;
|
|
|
|
|
2014-10-24 16:48:21 +08:00
|
|
|
// Stores whether the contents of the guest can be transparent.
|
|
|
|
bool guest_opaque_;
|
|
|
|
|
2014-10-23 14:04:13 +08:00
|
|
|
// Stores the WebContents that managed by this class.
|
2014-11-03 19:45:09 +08:00
|
|
|
scoped_ptr<brightray::InspectableWebContents> storage_;
|
2014-04-24 16:45:25 +08:00
|
|
|
|
2014-10-24 14:37:14 +08: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_;
|
|
|
|
|
2015-03-13 16:33:06 -07:00
|
|
|
// A pointer to the guest_sizer.
|
|
|
|
content::GuestSizer* guest_sizer_;
|
|
|
|
|
2014-10-24 14:37:14 +08:00
|
|
|
// 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 16:45:25 +08:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(WebContents);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_API_ATOM_API_WEB_CONTENTS_H_
|