OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/frame/DOMWindow.h" | 5 #include "core/frame/DOMWindow.h" |
6 | 6 |
| 7 #include "bindings/core/v8/WindowProxyManager.h" |
7 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
8 #include "core/dom/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
9 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
10 #include "core/dom/SecurityContext.h" | 11 #include "core/dom/SecurityContext.h" |
11 #include "core/events/MessageEvent.h" | 12 #include "core/events/MessageEvent.h" |
12 #include "core/frame/External.h" | 13 #include "core/frame/External.h" |
13 #include "core/frame/Frame.h" | 14 #include "core/frame/Frame.h" |
14 #include "core/frame/FrameClient.h" | 15 #include "core/frame/FrameClient.h" |
15 #include "core/frame/FrameConsole.h" | 16 #include "core/frame/FrameConsole.h" |
16 #include "core/frame/LocalDOMWindow.h" | 17 #include "core/frame/LocalDOMWindow.h" |
(...skipping 10 matching lines...) Expand all Loading... |
27 #include "core/page/ChromeClient.h" | 28 #include "core/page/ChromeClient.h" |
28 #include "core/page/FocusController.h" | 29 #include "core/page/FocusController.h" |
29 #include "core/page/Page.h" | 30 #include "core/page/Page.h" |
30 #include "platform/weborigin/KURL.h" | 31 #include "platform/weborigin/KURL.h" |
31 #include "platform/weborigin/SecurityOrigin.h" | 32 #include "platform/weborigin/SecurityOrigin.h" |
32 #include "platform/weborigin/Suborigin.h" | 33 #include "platform/weborigin/Suborigin.h" |
33 #include <memory> | 34 #include <memory> |
34 | 35 |
35 namespace blink { | 36 namespace blink { |
36 | 37 |
37 DOMWindow::DOMWindow(Frame& frame) : m_frame(frame), m_windowIsClosing(false) {} | 38 DOMWindow::DOMWindow(Frame& frame) |
| 39 : m_frame(frame), |
| 40 m_windowProxyManager(frame.getWindowProxyManager()), |
| 41 m_windowIsClosing(false) {} |
38 | 42 |
39 DOMWindow::~DOMWindow() { | 43 DOMWindow::~DOMWindow() { |
40 // The frame must be disconnected before finalization. | 44 // The frame must be disconnected before finalization. |
41 DCHECK(!m_frame); | 45 DCHECK(!m_frame); |
42 } | 46 } |
43 | 47 |
| 48 v8::Local<v8::Object> DOMWindow::globalProxy(DOMWrapperWorld& world) { |
| 49 return m_windowProxyManager->globalProxy(world); |
| 50 } |
| 51 |
44 v8::Local<v8::Object> DOMWindow::wrap(v8::Isolate*, | 52 v8::Local<v8::Object> DOMWindow::wrap(v8::Isolate*, |
45 v8::Local<v8::Object> creationContext) { | 53 v8::Local<v8::Object> creationContext) { |
46 LOG(FATAL) << "DOMWindow must never be wrapped with wrap method. The " | 54 LOG(FATAL) << "DOMWindow must never be wrapped with wrap method. The " |
47 "wrappers must be created at WindowProxy::createContext() and " | 55 "wrappers must be created at WindowProxy::createContext() and " |
48 "setupWindowPrototypeChain()."; | 56 "setupWindowPrototypeChain()."; |
49 return v8::Local<v8::Object>(); | 57 return v8::Local<v8::Object>(); |
50 } | 58 } |
51 | 59 |
52 v8::Local<v8::Object> DOMWindow::associateWithWrapper( | 60 v8::Local<v8::Object> DOMWindow::associateWithWrapper( |
53 v8::Isolate*, | 61 v8::Isolate*, |
(...skipping 20 matching lines...) Expand all Loading... |
74 } | 82 } |
75 | 83 |
76 bool DOMWindow::closed() const { | 84 bool DOMWindow::closed() const { |
77 return m_windowIsClosing || !frame() || !frame()->host(); | 85 return m_windowIsClosing || !frame() || !frame()->host(); |
78 } | 86 } |
79 | 87 |
80 unsigned DOMWindow::length() const { | 88 unsigned DOMWindow::length() const { |
81 return frame() ? frame()->tree().scopedChildCount() : 0; | 89 return frame() ? frame()->tree().scopedChildCount() : 0; |
82 } | 90 } |
83 | 91 |
84 v8::Local<v8::Object> DOMWindow::self(ScriptState* scriptState) const { | |
85 return scriptState->context()->Global(); | |
86 } | |
87 | |
88 DOMWindow* DOMWindow::opener() const { | 92 DOMWindow* DOMWindow::opener() const { |
89 // FIXME: Use FrameTree to get opener as well, to simplify logic here. | 93 // FIXME: Use FrameTree to get opener as well, to simplify logic here. |
90 if (!frame() || !frame()->client()) | 94 if (!frame() || !frame()->client()) |
91 return nullptr; | 95 return nullptr; |
92 | 96 |
93 Frame* opener = frame()->client()->opener(); | 97 Frame* opener = frame()->client()->opener(); |
94 return opener ? opener->domWindow() : nullptr; | 98 return opener ? opener->domWindow() : nullptr; |
95 } | 99 } |
96 | 100 |
97 DOMWindow* DOMWindow::parent() const { | 101 DOMWindow* DOMWindow::parent() { |
| 102 // TODO(dcheng): Per the spec, this should only return null if there is no |
| 103 // browsing context with the window proxy as its WindowProxy object. |
98 if (!frame()) | 104 if (!frame()) |
99 return nullptr; | 105 return nullptr; |
100 | 106 |
101 Frame* parent = frame()->tree().parent(); | 107 Frame* parent = frame()->tree().parent(); |
102 return parent ? parent->domWindow() : frame()->domWindow(); | 108 return parent ? parent->domWindow() : this; |
103 } | 109 } |
104 | 110 |
105 DOMWindow* DOMWindow::top() const { | 111 DOMWindow* DOMWindow::top() const { |
106 if (!frame()) | 112 if (!frame()) |
107 return nullptr; | 113 return nullptr; |
108 | 114 |
109 return frame()->tree().top()->domWindow(); | 115 return frame()->tree().top()->domWindow(); |
110 } | 116 } |
111 | 117 |
112 External* DOMWindow::external() const { | 118 External* DOMWindow::external() const { |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 | 434 |
429 // If we're a top level window, bring the window to the front. | 435 // If we're a top level window, bring the window to the front. |
430 if (frame()->isMainFrame() && allowFocus) | 436 if (frame()->isMainFrame() && allowFocus) |
431 page->chromeClient().focus(); | 437 page->chromeClient().focus(); |
432 | 438 |
433 page->focusController().focusDocumentView(frame(), true /* notifyEmbedder */); | 439 page->focusController().focusDocumentView(frame(), true /* notifyEmbedder */); |
434 } | 440 } |
435 | 441 |
436 DEFINE_TRACE(DOMWindow) { | 442 DEFINE_TRACE(DOMWindow) { |
437 visitor->trace(m_frame); | 443 visitor->trace(m_frame); |
| 444 visitor->trace(m_windowProxyManager); |
438 visitor->trace(m_location); | 445 visitor->trace(m_location); |
439 EventTargetWithInlineData::trace(visitor); | 446 EventTargetWithInlineData::trace(visitor); |
440 } | 447 } |
441 | 448 |
442 } // namespace blink | 449 } // namespace blink |
OLD | NEW |