NativeWindow* owner_window = nullptr;
WebContents* embedder = nullptr;
- if (options.Get("embedder", &embedder) && embedder)
- owner_window = NativeWindow::FromWebContents(embedder->web_contents());
+ if (options.Get("embedder", &embedder) && embedder) {
+ auto relay = NativeWindowRelay::FromWebContents(embedder->web_contents());
+ if (relay)
+ owner_window = relay->window.get();
+ }
AttachAsUserData(web_contents);
InitWithWebContents(web_contents, owner_window);
if (!item)
return;
+ NativeWindow* window = nullptr;
+ auto relay = NativeWindowRelay::FromWebContents(item->GetWebContents());
+ if (relay)
+ window = relay->window.get();
+
file_dialog::Filters filters;
base::FilePath path;
- auto owner_window_ = NativeWindow::FromWebContents(item->GetWebContents());
- if (!file_dialog::ShowSaveDialog(
- owner_window_, item->GetURL().spec(),
- default_path, filters, &path)) {
+ if (!file_dialog::ShowSaveDialog(window, item->GetURL().spec(), default_path,
+ filters, &path)) {
return;
}
owner_window_ = owner_window;
web_contents->SetDelegate(this);
+ NativeWindowRelay* relay = new NativeWindowRelay(owner_window_->GetWeakPtr());
+ web_contents->SetUserData(relay->key, relay);
+
printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents);
using content::RenderWidgetHostView;
using content::RenderWidgetHost;
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(atom::NativeWindowRelay);
+
namespace atom {
namespace {
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "content/public/browser/readback_types.h"
+#include "content/public/browser/web_contents_user_data.h"
#include "native_mate/persistent_dictionary.h"
#include "ui/gfx/image/image.h"
DISALLOW_COPY_AND_ASSIGN(NativeWindow);
};
+
+// This class provides a hook to get a NativeWindow from a WebContents.
+class NativeWindowRelay :
+ public content::WebContentsUserData<NativeWindowRelay> {
+ public:
+ explicit NativeWindowRelay(base::WeakPtr<NativeWindow> window)
+ : key(UserDataKey()), window(window) {}
+
+ void* key;
+ base::WeakPtr<NativeWindow> window;
+
+ private:
+ friend class content::WebContentsUserData<NativeWindow>;
+};
+
} // namespace atom
#endif // ATOM_BROWSER_NATIVE_WINDOW_H_