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
|
|
|
|
2015-09-18 15:57:43 +08:00
|
|
|
#include "atom/browser/api/frame_subscriber.h"
|
2015-06-24 14:36:05 +08:00
|
|
|
#include "atom/browser/api/trackable_object.h"
|
2015-06-05 13:49:12 +08:00
|
|
|
#include "atom/browser/common_web_contents_delegate.h"
|
2014-04-25 11:22:51 +08:00
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
2015-08-31 00:22:01 +05:30
|
|
|
#include "content/public/common/favicon_url.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
|
|
|
|
2015-09-18 11:06:38 +08:00
|
|
|
namespace blink {
|
|
|
|
struct WebDeviceEmulationParams;
|
|
|
|
}
|
|
|
|
|
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 {
|
2015-06-05 17:01:17 +08:00
|
|
|
class Arguments;
|
2014-11-03 22:12:56 +08:00
|
|
|
class Dictionary;
|
|
|
|
}
|
|
|
|
|
2014-04-24 16:45:25 +08:00
|
|
|
namespace atom {
|
|
|
|
|
2015-06-25 14:28:13 +08:00
|
|
|
struct SetSizeParams;
|
2015-07-14 12:13:25 -07:00
|
|
|
class AtomBrowserContext;
|
2015-06-25 14:28:13 +08:00
|
|
|
class WebViewGuestDelegate;
|
2014-04-24 16:45:25 +08:00
|
|
|
|
2015-06-25 14:28:13 +08:00
|
|
|
namespace api {
|
2015-05-29 11:12:55 +08:00
|
|
|
|
2015-06-24 17:58:12 +08:00
|
|
|
class WebContents : public mate::TrackableObject<WebContents>,
|
2015-06-05 13:49:12 +08:00
|
|
|
public CommonWebContentsDelegate,
|
2015-06-25 20:28:07 +08:00
|
|
|
public content::WebContentsObserver {
|
2014-04-24 16:45:25 +08:00
|
|
|
public:
|
2015-06-10 20:07:14 +08:00
|
|
|
// For node.js callback function type: function(error, buffer)
|
2015-07-24 15:09:11 +05:30
|
|
|
using PrintToPDFCallback =
|
|
|
|
base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>;
|
2015-06-10 11:34:16 +08:00
|
|
|
|
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
|
|
|
|
2015-09-06 10:30:59 +08:00
|
|
|
// mate::TrackableObject:
|
|
|
|
void Destroy() override;
|
|
|
|
|
2014-04-25 11:22:51 +08:00
|
|
|
bool IsAlive() const;
|
2015-06-23 16:16:10 +08:00
|
|
|
int GetID() const;
|
|
|
|
bool Equal(const WebContents* web_contents) const;
|
2014-11-06 14:29:41 -05:00
|
|
|
void LoadURL(const GURL& url, const mate::Dictionary& options);
|
2015-09-15 09:17:45 +08:00
|
|
|
GURL GetURL() const;
|
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
|
|
|
bool IsCrashed() const;
|
2014-10-24 20:57:44 +08:00
|
|
|
void SetUserAgent(const std::string& user_agent);
|
2015-07-22 12:25:10 +08:00
|
|
|
std::string GetUserAgent();
|
2014-10-24 21:04:50 +08:00
|
|
|
void InsertCSS(const std::string& css);
|
2015-07-30 14:42:03 +05:30
|
|
|
void ExecuteJavaScript(const base::string16& code,
|
|
|
|
bool has_user_gesture);
|
2015-06-05 17:01:17 +08:00
|
|
|
void OpenDevTools(mate::Arguments* args);
|
2014-11-03 22:12:56 +08:00
|
|
|
void CloseDevTools();
|
|
|
|
bool IsDevToolsOpened();
|
2015-06-05 17:01:17 +08:00
|
|
|
void ToggleDevTools();
|
2015-09-18 11:06:38 +08:00
|
|
|
void EnableDeviceEmulation(const blink::WebDeviceEmulationParams& params);
|
2015-08-31 11:19:19 +02:00
|
|
|
void DisableDeviceEmulation();
|
2015-04-22 13:00:10 +05:30
|
|
|
void InspectElement(int x, int y);
|
2015-06-05 15:41:03 +08:00
|
|
|
void InspectServiceWorker();
|
2015-06-18 18:38:32 +08:00
|
|
|
v8::Local<v8::Value> Session(v8::Isolate* isolate);
|
2015-04-30 18:45:19 +05:30
|
|
|
void HasServiceWorker(const base::Callback<void(bool)>&);
|
|
|
|
void UnregisterServiceWorker(const base::Callback<void(bool)>&);
|
2015-06-15 21:40:49 +08:00
|
|
|
void SetAudioMuted(bool muted);
|
|
|
|
bool IsAudioMuted();
|
2015-06-13 21:23:45 +08:00
|
|
|
void Print(mate::Arguments* args);
|
2015-01-19 12:09:47 -08:00
|
|
|
|
2015-06-09 13:07:40 +08:00
|
|
|
// Print current page as PDF.
|
2015-06-10 11:34:16 +08:00
|
|
|
void PrintToPDF(const base::DictionaryValue& setting,
|
2015-06-13 16:02:16 +08:00
|
|
|
const PrintToPDFCallback& callback);
|
2015-06-09 13:07:40 +08:00
|
|
|
|
2015-07-24 15:09:11 +05:30
|
|
|
// DevTools workspace api.
|
2015-09-07 16:12:31 +08:00
|
|
|
void AddWorkSpace(mate::Arguments* args, const base::FilePath& path);
|
|
|
|
void RemoveWorkSpace(mate::Arguments* args, const base::FilePath& path);
|
2015-07-24 15:09:11 +05:30
|
|
|
|
2015-01-19 12:09:47 -08:00
|
|
|
// Editing commands.
|
|
|
|
void Undo();
|
|
|
|
void Redo();
|
|
|
|
void Cut();
|
|
|
|
void Copy();
|
|
|
|
void Paste();
|
2015-05-15 00:15:19 -07:00
|
|
|
void PasteAndMatchStyle();
|
2015-01-19 12:09:47 -08:00
|
|
|
void Delete();
|
|
|
|
void SelectAll();
|
|
|
|
void Unselect();
|
|
|
|
void Replace(const base::string16& word);
|
|
|
|
void ReplaceMisspelling(const base::string16& word);
|
|
|
|
|
2015-07-24 12:58:28 +08:00
|
|
|
// Focus.
|
|
|
|
void Focus();
|
|
|
|
void TabTraverse(bool reverse);
|
|
|
|
|
2015-09-18 14:20:31 +08:00
|
|
|
// Send 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
|
|
|
|
2015-09-18 14:20:31 +08:00
|
|
|
// Send WebInputEvent to the page.
|
|
|
|
void SendInputEvent(v8::Isolate* isolate, v8::Local<v8::Value> input_event);
|
|
|
|
|
2015-09-18 15:57:43 +08:00
|
|
|
// Subscribe to the frame updates.
|
|
|
|
void BeginFrameSubscription(
|
|
|
|
const FrameSubscriber::FrameCaptureCallback& callback);
|
|
|
|
void EndFrameSubscription();
|
|
|
|
|
2015-06-25 14:28:13 +08:00
|
|
|
// Methods for creating <webview>.
|
2015-05-29 11:12:55 +08:00
|
|
|
void SetSize(const SetSizeParams& params);
|
2014-10-24 16:48:21 +08:00
|
|
|
void SetAllowTransparency(bool allow);
|
2015-06-05 15:18:15 +08:00
|
|
|
bool IsGuest() const;
|
2014-10-24 16:09:18 +08:00
|
|
|
|
2014-04-24 16:45:25 +08:00
|
|
|
protected:
|
|
|
|
explicit WebContents(content::WebContents* web_contents);
|
2015-09-05 01:44:22 +09:00
|
|
|
WebContents(v8::Isolate* isolate, const mate::Dictionary& options);
|
2014-10-23 14:04:13 +08:00
|
|
|
~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;
|
2015-07-06 18:21:04 +08:00
|
|
|
bool IsDestroyed() const 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,
|
2015-09-02 15:16:49 +08:00
|
|
|
const std::string& frame_name,
|
2014-10-25 13:21:09 +08:00
|
|
|
const GURL& target_url,
|
|
|
|
const std::string& partition_id,
|
|
|
|
content::SessionStorageNamespace* session_storage_namespace) 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-06-25 11:07:23 +08:00
|
|
|
void BeforeUnloadFired(content::WebContents* tab,
|
|
|
|
bool proceed,
|
|
|
|
bool* proceed_to_fire_unload) override;
|
|
|
|
void MoveContents(content::WebContents* source,
|
|
|
|
const gfx::Rect& pos) override;
|
|
|
|
void CloseContents(content::WebContents* source) override;
|
|
|
|
void ActivateContents(content::WebContents* contents) override;
|
2015-06-24 22:23:38 +08:00
|
|
|
bool IsPopupOrPanel(const content::WebContents* source) const override;
|
2014-10-24 21:46:47 +08:00
|
|
|
void HandleKeyboardEvent(
|
|
|
|
content::WebContents* source,
|
|
|
|
const content::NativeWebKeyboardEvent& event) override;
|
2015-05-09 17:47:40 +05:30
|
|
|
void EnterFullscreenModeForTab(content::WebContents* source,
|
2015-05-08 11:48:15 +05:30
|
|
|
const GURL& origin) override;
|
2015-05-09 17:47:40 +05:30
|
|
|
void ExitFullscreenModeForTab(content::WebContents* source) override;
|
2015-06-25 11:07:23 +08:00
|
|
|
void RendererUnresponsive(content::WebContents* source) override;
|
|
|
|
void RendererResponsive(content::WebContents* source) override;
|
2014-10-24 18:06:32 +08:00
|
|
|
|
2014-10-23 17:54:52 +08:00
|
|
|
// content::WebContentsObserver:
|
2015-06-25 11:07:23 +08:00
|
|
|
void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
|
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,
|
2015-09-02 15:16:49 +08:00
|
|
|
const base::string16& error_description,
|
|
|
|
bool was_ignored_by_handler) override;
|
2015-03-14 08:58:30 +05:30
|
|
|
void DidFailProvisionalLoad(content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& validated_url,
|
|
|
|
int error_code,
|
2015-09-02 15:16:49 +08:00
|
|
|
const base::string16& error_description,
|
|
|
|
bool was_ignored_by_handler) override;
|
2015-05-22 15:24:34 +08:00
|
|
|
void DidStartLoading() override;
|
|
|
|
void DidStopLoading() 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 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;
|
2015-05-13 01:05:56 +05:30
|
|
|
void PluginCrashed(const base::FilePath& plugin_path,
|
|
|
|
base::ProcessId plugin_pid) override;
|
2014-04-24 16:45:25 +08:00
|
|
|
|
|
|
|
private:
|
2015-06-24 21:44:27 +08:00
|
|
|
enum Type {
|
|
|
|
BROWSER_WINDOW, // Used by BrowserWindow.
|
|
|
|
WEB_VIEW, // Used by <webview>.
|
|
|
|
REMOTE, // Thin wrap around an existing WebContents.
|
|
|
|
};
|
|
|
|
|
2015-07-14 12:13:25 -07:00
|
|
|
AtomBrowserContext* GetBrowserContext() const;
|
|
|
|
|
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);
|
|
|
|
|
2015-06-16 17:23:29 +08:00
|
|
|
v8::Global<v8::Value> session_;
|
|
|
|
|
2015-06-25 14:28:13 +08:00
|
|
|
scoped_ptr<WebViewGuestDelegate> guest_delegate_;
|
2015-05-29 11:12:55 +08:00
|
|
|
|
2015-06-24 21:44:27 +08:00
|
|
|
// The type of current WebContents.
|
|
|
|
Type type_;
|
|
|
|
|
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_
|