| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // triggering its deletion unless something else is still retaining a reference. | 67 // triggering its deletion unless something else is still retaining a reference. |
| 68 // | 68 // |
| 69 // Thie client is expected to be set whenever the WebLocalFrameImpl is attached
to | 69 // Thie client is expected to be set whenever the WebLocalFrameImpl is attached
to |
| 70 // the DOM. | 70 // the DOM. |
| 71 | 71 |
| 72 #include "sky/engine/config.h" | 72 #include "sky/engine/config.h" |
| 73 #include "sky/engine/web/WebLocalFrameImpl.h" | 73 #include "sky/engine/web/WebLocalFrameImpl.h" |
| 74 | 74 |
| 75 #include <algorithm> | 75 #include <algorithm> |
| 76 #include "mojo/public/cpp/system/data_pipe.h" | 76 #include "mojo/public/cpp/system/data_pipe.h" |
| 77 #include "sky/engine/bindings/core/v8/DOMWrapperWorld.h" | 77 #include "sky/engine/bindings2/exception_state.h" |
| 78 #include "sky/engine/bindings/core/v8/ExceptionState.h" | 78 #include "sky/engine/bindings2/exception_state_placeholder.h" |
| 79 #include "sky/engine/bindings/core/v8/ExceptionStatePlaceholder.h" | |
| 80 #include "sky/engine/bindings/core/v8/ScriptController.h" | |
| 81 #include "sky/engine/bindings/core/v8/ScriptSourceCode.h" | |
| 82 #include "sky/engine/bindings/core/v8/ScriptValue.h" | |
| 83 #include "sky/engine/bindings/core/v8/V8GCController.h" | |
| 84 #include "sky/engine/bindings/core/v8/V8PerIsolateData.h" | |
| 85 #include "sky/engine/core/dom/Document.h" | 79 #include "sky/engine/core/dom/Document.h" |
| 86 #include "sky/engine/core/dom/Node.h" | 80 #include "sky/engine/core/dom/Node.h" |
| 87 #include "sky/engine/core/dom/NodeTraversal.h" | 81 #include "sky/engine/core/dom/NodeTraversal.h" |
| 88 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | 82 #include "sky/engine/core/dom/shadow/ShadowRoot.h" |
| 89 #include "sky/engine/core/editing/Editor.h" | 83 #include "sky/engine/core/editing/Editor.h" |
| 90 #include "sky/engine/core/editing/FrameSelection.h" | 84 #include "sky/engine/core/editing/FrameSelection.h" |
| 91 #include "sky/engine/core/editing/InputMethodController.h" | 85 #include "sky/engine/core/editing/InputMethodController.h" |
| 92 #include "sky/engine/core/editing/PlainTextRange.h" | 86 #include "sky/engine/core/editing/PlainTextRange.h" |
| 93 #include "sky/engine/core/editing/SpellChecker.h" | 87 #include "sky/engine/core/editing/SpellChecker.h" |
| 94 #include "sky/engine/core/editing/TextAffinity.h" | 88 #include "sky/engine/core/editing/TextAffinity.h" |
| 95 #include "sky/engine/core/editing/TextIterator.h" | 89 #include "sky/engine/core/editing/TextIterator.h" |
| 96 #include "sky/engine/core/editing/htmlediting.h" | 90 #include "sky/engine/core/editing/htmlediting.h" |
| 97 #include "sky/engine/core/frame/Console.h" | |
| 98 #include "sky/engine/core/frame/FrameHost.h" | 91 #include "sky/engine/core/frame/FrameHost.h" |
| 99 #include "sky/engine/core/frame/FrameView.h" | 92 #include "sky/engine/core/frame/FrameView.h" |
| 100 #include "sky/engine/core/frame/LocalDOMWindow.h" | 93 #include "sky/engine/core/frame/LocalDOMWindow.h" |
| 101 #include "sky/engine/core/frame/Settings.h" | 94 #include "sky/engine/core/frame/Settings.h" |
| 102 #include "sky/engine/core/html/HTMLAnchorElement.h" | 95 #include "sky/engine/core/html/HTMLAnchorElement.h" |
| 103 #include "sky/engine/core/inspector/ConsoleMessage.h" | 96 #include "sky/engine/core/inspector/ConsoleMessage.h" |
| 104 #include "sky/engine/core/loader/MojoLoader.h" | 97 #include "sky/engine/core/loader/MojoLoader.h" |
| 105 #include "sky/engine/core/page/EventHandler.h" | 98 #include "sky/engine/core/page/EventHandler.h" |
| 106 #include "sky/engine/core/page/FocusController.h" | 99 #include "sky/engine/core/page/FocusController.h" |
| 107 #include "sky/engine/core/page/Page.h" | 100 #include "sky/engine/core/page/Page.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 130 #include "sky/engine/public/platform/WebSize.h" | 123 #include "sky/engine/public/platform/WebSize.h" |
| 131 #include "sky/engine/public/platform/WebURLError.h" | 124 #include "sky/engine/public/platform/WebURLError.h" |
| 132 #include "sky/engine/public/platform/WebVector.h" | 125 #include "sky/engine/public/platform/WebVector.h" |
| 133 #include "sky/engine/public/web/WebConsoleMessage.h" | 126 #include "sky/engine/public/web/WebConsoleMessage.h" |
| 134 #include "sky/engine/public/web/WebDocument.h" | 127 #include "sky/engine/public/web/WebDocument.h" |
| 135 #include "sky/engine/public/web/WebElement.h" | 128 #include "sky/engine/public/web/WebElement.h" |
| 136 #include "sky/engine/public/web/WebFrameClient.h" | 129 #include "sky/engine/public/web/WebFrameClient.h" |
| 137 #include "sky/engine/public/web/WebNode.h" | 130 #include "sky/engine/public/web/WebNode.h" |
| 138 #include "sky/engine/public/web/WebRange.h" | 131 #include "sky/engine/public/web/WebRange.h" |
| 139 #include "sky/engine/public/web/WebScriptSource.h" | 132 #include "sky/engine/public/web/WebScriptSource.h" |
| 140 #include "sky/engine/core/inspector/ScriptCallStack.h" | |
| 141 #include "sky/engine/web/CompositionUnderlineVectorBuilder.h" | 133 #include "sky/engine/web/CompositionUnderlineVectorBuilder.h" |
| 142 #include "sky/engine/web/WebViewImpl.h" | 134 #include "sky/engine/web/WebViewImpl.h" |
| 143 #include "sky/engine/wtf/CurrentTime.h" | 135 #include "sky/engine/wtf/CurrentTime.h" |
| 144 #include "sky/engine/wtf/HashMap.h" | 136 #include "sky/engine/wtf/HashMap.h" |
| 145 | 137 |
| 146 namespace blink { | 138 namespace blink { |
| 147 | 139 |
| 148 static int frameCount = 0; | 140 static int frameCount = 0; |
| 149 | 141 |
| 150 // Key for a StatsCounter tracking how many WebFrames are active. | 142 // Key for a StatsCounter tracking how many WebFrames are active. |
| 151 static const char webFrameActiveCount[] = "WebFrameActiveCount"; | 143 static const char webFrameActiveCount[] = "WebFrameActiveCount"; |
| 152 | 144 |
| 153 static void frameContentAsPlainText(size_t maxChars, LocalFrame* frame, StringBu
ilder& output) | 145 static void frameContentAsPlainText(size_t maxChars, LocalFrame* frame, StringBu
ilder& output) |
| 154 { | 146 { |
| 155 Document* document = frame->document(); | 147 Document* document = frame->document(); |
| 156 if (!document) | 148 if (!document) |
| 157 return; | 149 return; |
| 158 | 150 |
| 159 if (!frame->view()) | 151 if (!frame->view()) |
| 160 return; | 152 return; |
| 161 | 153 |
| 162 // Select the document body. | 154 // Select the document body. |
| 163 RefPtr<Range> range(document->createRange()); | 155 RefPtr<Range> range(document->createRange()); |
| 164 TrackExceptionState exceptionState; | 156 TrackExceptionState exceptionState; |
| 165 range->selectNodeContents(document->documentElement(), exceptionState); | 157 range->selectNodeContents(document->documentElement(), exceptionState); |
| 166 | 158 |
| 167 if (!exceptionState.hadException()) { | 159 if (!exceptionState.had_exception()) { |
| 168 // The text iterator will walk nodes giving us text. This is similar to | 160 // The text iterator will walk nodes giving us text. This is similar to |
| 169 // the plainText() function in core/editing/TextIterator.h, but we imple
ment the maximum | 161 // the plainText() function in core/editing/TextIterator.h, but we imple
ment the maximum |
| 170 // size and also copy the results directly into a wstring, avoiding the | 162 // size and also copy the results directly into a wstring, avoiding the |
| 171 // string conversion. | 163 // string conversion. |
| 172 for (TextIterator it(range.get()); !it.atEnd(); it.advance()) { | 164 for (TextIterator it(range.get()); !it.atEnd(); it.advance()) { |
| 173 it.appendTextToStringBuilder(output, 0, maxChars - output.length()); | 165 it.appendTextToStringBuilder(output, 0, maxChars - output.length()); |
| 174 if (output.length() >= maxChars) | 166 if (output.length() >= maxChars) |
| 175 return; // Filled up the buffer. | 167 return; // Filled up the buffer. |
| 176 } | 168 } |
| 177 } | 169 } |
| 178 } | 170 } |
| 179 | 171 |
| 180 // WebFrame ------------------------------------------------------------------- | 172 // WebFrame ------------------------------------------------------------------- |
| 181 | 173 |
| 182 int WebFrame::instanceCount() | 174 int WebFrame::instanceCount() |
| 183 { | 175 { |
| 184 return frameCount; | 176 return frameCount; |
| 185 } | 177 } |
| 186 | 178 |
| 187 WebLocalFrame* WebLocalFrame::frameForCurrentContext() | |
| 188 { | |
| 189 v8::Handle<v8::Context> context = v8::Isolate::GetCurrent()->GetCurrentConte
xt(); | |
| 190 if (context.IsEmpty()) | |
| 191 return 0; | |
| 192 return frameForContext(context); | |
| 193 } | |
| 194 | |
| 195 WebLocalFrame* WebLocalFrame::frameForContext(v8::Handle<v8::Context> context) | |
| 196 { | |
| 197 return WebLocalFrameImpl::fromFrame(toFrameIfNotDetached(context)); | |
| 198 } | |
| 199 | |
| 200 bool WebLocalFrameImpl::isWebLocalFrame() const | 179 bool WebLocalFrameImpl::isWebLocalFrame() const |
| 201 { | 180 { |
| 202 return true; | 181 return true; |
| 203 } | 182 } |
| 204 | 183 |
| 205 WebLocalFrame* WebLocalFrameImpl::toWebLocalFrame() | 184 WebLocalFrame* WebLocalFrameImpl::toWebLocalFrame() |
| 206 { | 185 { |
| 207 return this; | 186 return this; |
| 208 } | 187 } |
| 209 | 188 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 237 WebDocument WebLocalFrameImpl::document() const | 216 WebDocument WebLocalFrameImpl::document() const |
| 238 { | 217 { |
| 239 if (!frame() || !frame()->document()) | 218 if (!frame() || !frame()->document()) |
| 240 return WebDocument(); | 219 return WebDocument(); |
| 241 return WebDocument(frame()->document()); | 220 return WebDocument(frame()->document()); |
| 242 } | 221 } |
| 243 | 222 |
| 244 void WebLocalFrameImpl::executeScript(const WebScriptSource& source) | 223 void WebLocalFrameImpl::executeScript(const WebScriptSource& source) |
| 245 { | 224 { |
| 246 ASSERT(frame()); | 225 ASSERT(frame()); |
| 247 TextPosition position(OrdinalNumber::fromOneBasedInt(source.startLine), Ordi
nalNumber::first()); | 226 // TODO(dart) |
| 248 v8::HandleScope handleScope(toIsolate(frame())); | |
| 249 frame()->script().executeScriptInMainWorld(ScriptSourceCode(source.code, sou
rce.url, position)); | |
| 250 } | 227 } |
| 251 | 228 |
| 252 void WebLocalFrameImpl::addMessageToConsole(const WebConsoleMessage& message) | 229 void WebLocalFrameImpl::addMessageToConsole(const WebConsoleMessage& message) |
| 253 { | 230 { |
| 254 ASSERT(frame()); | 231 ASSERT(frame()); |
| 255 | 232 |
| 256 MessageLevel webCoreMessageLevel; | 233 MessageLevel webCoreMessageLevel; |
| 257 switch (message.level) { | 234 switch (message.level) { |
| 258 case WebConsoleMessage::LevelDebug: | 235 case WebConsoleMessage::LevelDebug: |
| 259 webCoreMessageLevel = DebugMessageLevel; | 236 webCoreMessageLevel = DebugMessageLevel; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 270 default: | 247 default: |
| 271 ASSERT_NOT_REACHED(); | 248 ASSERT_NOT_REACHED(); |
| 272 return; | 249 return; |
| 273 } | 250 } |
| 274 | 251 |
| 275 frame()->document()->addConsoleMessage(ConsoleMessage::create(OtherMessageSo
urce, webCoreMessageLevel, message.text)); | 252 frame()->document()->addConsoleMessage(ConsoleMessage::create(OtherMessageSo
urce, webCoreMessageLevel, message.text)); |
| 276 } | 253 } |
| 277 | 254 |
| 278 void WebLocalFrameImpl::collectGarbage() | 255 void WebLocalFrameImpl::collectGarbage() |
| 279 { | 256 { |
| 280 if (!frame()) | 257 // TODO(dart): Implement. |
| 281 return; | |
| 282 V8GCController::collectGarbage(v8::Isolate::GetCurrent()); | |
| 283 } | |
| 284 | |
| 285 v8::Handle<v8::Value> WebLocalFrameImpl::executeScriptAndReturnValue(const WebSc
riptSource& source) | |
| 286 { | |
| 287 ASSERT(frame()); | |
| 288 TextPosition position(OrdinalNumber::fromOneBasedInt(source.startLine), Ordi
nalNumber::first()); | |
| 289 return frame()->script().executeScriptInMainWorldAndReturnValue(ScriptSource
Code(source.code, source.url, position)); | |
| 290 } | |
| 291 | |
| 292 v8::Handle<v8::Value> WebLocalFrameImpl::callFunctionEvenIfScriptDisabled(v8::Ha
ndle<v8::Function> function, v8::Handle<v8::Value> receiver, int argc, v8::Handl
e<v8::Value> argv[]) | |
| 293 { | |
| 294 ASSERT(frame()); | |
| 295 return frame()->script().callFunction(function, receiver, argc, argv); | |
| 296 } | |
| 297 | |
| 298 v8::Local<v8::Context> WebLocalFrameImpl::mainWorldScriptContext() const | |
| 299 { | |
| 300 return toV8Context(frame(), DOMWrapperWorld::mainWorld()); | |
| 301 } | 258 } |
| 302 | 259 |
| 303 void WebLocalFrameImpl::load(const WebURL& url, mojo::ScopedDataPipeConsumerHand
le responseStream) | 260 void WebLocalFrameImpl::load(const WebURL& url, mojo::ScopedDataPipeConsumerHand
le responseStream) |
| 304 { | 261 { |
| 305 frame()->mojoLoader().load(url, responseStream.Pass()); | 262 frame()->mojoLoader().load(url, responseStream.Pass()); |
| 306 } | 263 } |
| 307 | 264 |
| 308 void WebLocalFrameImpl::replaceSelection(const WebString& text) | 265 void WebLocalFrameImpl::replaceSelection(const WebString& text) |
| 309 { | 266 { |
| 310 bool selectReplacement = false; | 267 bool selectReplacement = false; |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 | 610 |
| 654 void WebLocalFrameImpl::setInputEventsTransformForEmulation(const IntSize& offse
t, float contentScaleFactor) | 611 void WebLocalFrameImpl::setInputEventsTransformForEmulation(const IntSize& offse
t, float contentScaleFactor) |
| 655 { | 612 { |
| 656 m_inputEventsOffsetForEmulation = offset; | 613 m_inputEventsOffsetForEmulation = offset; |
| 657 m_inputEventsScaleFactorForEmulation = contentScaleFactor; | 614 m_inputEventsScaleFactorForEmulation = contentScaleFactor; |
| 658 if (frame()->view()) | 615 if (frame()->view()) |
| 659 frame()->view()->setInputEventsTransformForEmulation(m_inputEventsOffset
ForEmulation, m_inputEventsScaleFactorForEmulation); | 616 frame()->view()->setInputEventsTransformForEmulation(m_inputEventsOffset
ForEmulation, m_inputEventsScaleFactorForEmulation); |
| 660 } | 617 } |
| 661 | 618 |
| 662 } // namespace blink | 619 } // namespace blink |
| OLD | NEW |