#include <set>
#include "atom/browser/api/atom_api_session.h"
+#include "atom/browser/api/atom_api_window.h"
#include "atom/browser/atom_browser_client.h"
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/atom_browser_main_parts.h"
return mate::ConvertToV8(isolate, *web_preferences->web_preferences());
}
+v8::Local<v8::Value> WebContents::GetOwnerBrowserWindow() {
+ if (owner_window())
+ return Window::From(isolate(), owner_window());
+ else
+ return v8::Null(isolate());
+}
+
v8::Local<v8::Value> WebContents::Session(v8::Isolate* isolate) {
return v8::Local<v8::Value>::New(isolate, session_);
}
.SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency)
.SetMethod("isGuest", &WebContents::IsGuest)
.SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
+ .SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow)
.SetMethod("hasServiceWorker", &WebContents::HasServiceWorker)
.SetMethod("unregisterServiceWorker",
&WebContents::UnregisterServiceWorker)
// Returns the web preferences of current WebContents.
v8::Local<v8::Value> GetWebPreferences(v8::Isolate* isolate);
+ // Returns the owner window.
+ v8::Local<v8::Value> GetOwnerBrowserWindow();
+
// Properties.
v8::Local<v8::Value> Session(v8::Isolate* isolate);
v8::Local<v8::Value> DevToolsWebContents(v8::Isolate* isolate);
web_contents->SetOwnerWindow(window_.get());
window_->InitFromOptions(options);
window_->AddObserver(this);
+ AttachAsUserData(window_.get());
}
Window::~Window() {
.SetProperty("webContents", &Window::WebContents, true);
}
+// static
+v8::Local<v8::Value> Window::From(v8::Isolate* isolate,
+ NativeWindow* native_window) {
+ auto existing = TrackableObject::FromWrappedClass(isolate, native_window);
+ if (existing)
+ return existing->GetWrapper(isolate);
+ else
+ return v8::Null(isolate);
+}
+
} // namespace api
} // namespace atom
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
+ // Returns the BrowserWindow object from |native_window|.
+ static v8::Local<v8::Value> From(v8::Isolate* isolate,
+ NativeWindow* native_window);
+
NativeWindow* window() const { return window_.get(); }
protected:
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
+#include "base/supports_user_data.h"
#include "content/public/browser/readback_types.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
struct DraggableRegion;
-class NativeWindow : public content::WebContentsObserver {
+class NativeWindow : public base::SupportsUserData,
+ public content::WebContentsObserver {
public:
using CapturePageCallback = base::Callback<void(const SkBitmap& bitmap)>;