diff options
Diffstat (limited to 'WebKit/chromium/src')
67 files changed, 3268 insertions, 355 deletions
diff --git a/WebKit/chromium/src/ApplicationCacheHost.cpp b/WebKit/chromium/src/ApplicationCacheHost.cpp index ef8f860..5fa4a66 100644 --- a/WebKit/chromium/src/ApplicationCacheHost.cpp +++ b/WebKit/chromium/src/ApplicationCacheHost.cpp @@ -33,14 +33,11 @@ #if ENABLE(OFFLINE_WEB_APPLICATIONS) +#include "ApplicationCacheHostInternal.h" #include "DocumentLoader.h" #include "DOMApplicationCache.h" #include "Frame.h" #include "Settings.h" -#include "WebApplicationCacheHost.h" -#include "WebApplicationCacheHostClient.h" -#include "WebKit.h" -#include "WebKitClient.h" #include "WebURL.h" #include "WebURLError.h" #include "WebURLResponse.h" @@ -51,27 +48,6 @@ using namespace WebKit; namespace WebCore { -// ApplicationCacheHostInternal ----------------------------------------------- - -class ApplicationCacheHostInternal : public WebApplicationCacheHostClient { -public: - ApplicationCacheHostInternal(ApplicationCacheHost* host) - : m_innerHost(host) - { - m_outerHost.set(WebKit::webKitClient()->createApplicationCacheHost(this)); - } - - virtual void notifyEventListener(WebApplicationCacheHost::EventID eventID) - { - m_innerHost->notifyDOMApplicationCache( - static_cast<ApplicationCacheHost::EventID>(eventID)); - } - - ApplicationCacheHost* m_innerHost; - OwnPtr<WebApplicationCacheHost> m_outerHost; -}; - -// ApplicationCacheHost ------------------------------------------------------- // We provide a custom implementation of this class that calls out to the // embedding application instead of using WebCore's built in appcache system. // This file replaces webcore/appcache/ApplicationCacheHost.cpp in our build. @@ -79,6 +55,7 @@ public: ApplicationCacheHost::ApplicationCacheHost(DocumentLoader* documentLoader) : m_domApplicationCache(0) , m_documentLoader(documentLoader) + , m_defersEvents(true) { ASSERT(m_documentLoader); } @@ -220,15 +197,32 @@ void ApplicationCacheHost::setDOMApplicationCache(DOMApplicationCache* domApplic void ApplicationCacheHost::notifyDOMApplicationCache(EventID id) { + if (m_defersEvents) { + m_deferredEvents.append(id); + return; + } if (m_domApplicationCache) { ExceptionCode ec = 0; - m_domApplicationCache->dispatchEvent( - Event::create(DOMApplicationCache::toEventType(id), false, false), - ec); + m_domApplicationCache->dispatchEvent(Event::create(DOMApplicationCache::toEventType(id), false, false), ec); ASSERT(!ec); } } +void ApplicationCacheHost::stopDeferringEvents() +{ + RefPtr<DocumentLoader> protect(documentLoader()); + for (unsigned i = 0; i < m_deferredEvents.size(); ++i) { + EventID id = m_deferredEvents[i]; + if (m_domApplicationCache) { + ExceptionCode ec = 0; + m_domApplicationCache->dispatchEvent(Event::create(DOMApplicationCache::toEventType(id), false, false), ec); + ASSERT(!ec); + } + } + m_deferredEvents.clear(); + m_defersEvents = false; +} + ApplicationCacheHost::Status ApplicationCacheHost::status() const { return m_internal ? static_cast<Status>(m_internal->m_outerHost->status()) : UNCACHED; diff --git a/WebKit/chromium/src/ApplicationCacheHostInternal.h b/WebKit/chromium/src/ApplicationCacheHostInternal.h new file mode 100644 index 0000000..3e52c1b --- /dev/null +++ b/WebKit/chromium/src/ApplicationCacheHostInternal.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ApplicationCacheHost.h" + +#if ENABLE(OFFLINE_WEB_APPLICATIONS) + +#include "WebApplicationCacheHostClient.h" +#include "WebKit.h" +#include "WebKitClient.h" + +namespace WebCore { + +class ApplicationCacheHostInternal : public WebKit::WebApplicationCacheHostClient { +public: + ApplicationCacheHostInternal(ApplicationCacheHost* host) + : m_innerHost(host) + { + m_outerHost.set(WebKit::webKitClient()->createApplicationCacheHost(this)); + } + + virtual void notifyEventListener(WebKit::WebApplicationCacheHost::EventID eventID) + { + m_innerHost->notifyDOMApplicationCache(static_cast<ApplicationCacheHost::EventID>(eventID)); + } + + static WebKit::WebApplicationCacheHost* toWebApplicationCacheHost(ApplicationCacheHost* innerHost) + { + if (innerHost && innerHost->m_internal.get()) + return innerHost->m_internal->m_outerHost.get(); + return 0; + } + +private: + friend class ApplicationCacheHost; + ApplicationCacheHost* m_innerHost; + OwnPtr<WebKit::WebApplicationCacheHost> m_outerHost; +}; + +} + +#endif // ENABLE(OFFLINE_WEB_APPLICATIONS) diff --git a/WebKit/chromium/src/AssertMatchingEnums.cpp b/WebKit/chromium/src/AssertMatchingEnums.cpp index 35e2057..1d2948f 100644 --- a/WebKit/chromium/src/AssertMatchingEnums.cpp +++ b/WebKit/chromium/src/AssertMatchingEnums.cpp @@ -116,6 +116,8 @@ COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleWebArea, WebAreaRole); COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleHeading, HeadingRole); COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleListBox, ListBoxRole); COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleListBoxOption, ListBoxOptionRole); +COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleMenuListOption, MenuListOptionRole); +COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleMenuListPopup, MenuListPopupRole); COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleTableHeaderContainer, TableHeaderContainerRole); COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleDefinitionListTerm, DefinitionListTermRole); COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleDefinitionListDefinition, DefinitionListDefinitionRole); @@ -126,8 +128,11 @@ COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleTab, TabRole); COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleTabList, TabListRole); COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleTabPanel, TabPanelRole); COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleTreeRole, TreeRole); +COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleTreeGrid, TreeGridRole); COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleTreeItemRole, TreeItemRole); COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleDirectory, DirectoryRole); +COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleEditableText, EditableTextRole); +COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleListItem, ListItemRole); COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleLandmarkApplication, LandmarkApplicationRole); COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleLandmarkBanner, LandmarkBannerRole); COMPILE_ASSERT_MATCHING_ENUM(WebAccessibilityRoleLandmarkComplementary, LandmarkComplementaryRole); @@ -245,6 +250,20 @@ COMPILE_ASSERT_MATCHING_ENUM(WebInputElement::Month, HTMLInputElement::MONTH); COMPILE_ASSERT_MATCHING_ENUM(WebInputElement::Time, HTMLInputElement::TIME); COMPILE_ASSERT_MATCHING_ENUM(WebInputElement::Week, HTMLInputElement::WEEK); +COMPILE_ASSERT_MATCHING_ENUM(WebNode::ElementNode, Node::ELEMENT_NODE); +COMPILE_ASSERT_MATCHING_ENUM(WebNode::AttributeNode, Node::ATTRIBUTE_NODE); +COMPILE_ASSERT_MATCHING_ENUM(WebNode::TextNode, Node::TEXT_NODE); +COMPILE_ASSERT_MATCHING_ENUM(WebNode::CDataSectionNode, Node::CDATA_SECTION_NODE); +COMPILE_ASSERT_MATCHING_ENUM(WebNode::EntityReferenceNode, Node::ENTITY_REFERENCE_NODE); +COMPILE_ASSERT_MATCHING_ENUM(WebNode::EntityNode, Node::ENTITY_NODE); +COMPILE_ASSERT_MATCHING_ENUM(WebNode::ProcessingInstructionsNode, Node::PROCESSING_INSTRUCTION_NODE); +COMPILE_ASSERT_MATCHING_ENUM(WebNode::CommentNode, Node::COMMENT_NODE); +COMPILE_ASSERT_MATCHING_ENUM(WebNode::DocumentNode, Node::DOCUMENT_NODE); +COMPILE_ASSERT_MATCHING_ENUM(WebNode::DocumentTypeNode, Node::DOCUMENT_TYPE_NODE); +COMPILE_ASSERT_MATCHING_ENUM(WebNode::DocumentFragmentNode, Node::DOCUMENT_FRAGMENT_NODE); +COMPILE_ASSERT_MATCHING_ENUM(WebNode::NotationNode, Node::NOTATION_NODE); +COMPILE_ASSERT_MATCHING_ENUM(WebNode::XPathNamespaceNode, Node::XPATH_NAMESPACE_NODE); + #if ENABLE(VIDEO) COMPILE_ASSERT_MATCHING_ENUM(WebMediaPlayer::Empty, MediaPlayer::Empty); COMPILE_ASSERT_MATCHING_ENUM(WebMediaPlayer::Idle, MediaPlayer::Idle); diff --git a/WebKit/chromium/src/ChromeClientImpl.cpp b/WebKit/chromium/src/ChromeClientImpl.cpp index 4e20124..9079094 100644 --- a/WebKit/chromium/src/ChromeClientImpl.cpp +++ b/WebKit/chromium/src/ChromeClientImpl.cpp @@ -560,22 +560,20 @@ void ChromeClientImpl::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> fileCh if (!client) return; - bool multipleFiles = fileChooser->allowsMultipleFiles(); - - WebString suggestion; - if (fileChooser->filenames().size() > 0) - suggestion = fileChooser->filenames()[0]; - + WebFileChooserParams params; + params.multiSelect = fileChooser->allowsMultipleFiles(); + params.acceptTypes = fileChooser->acceptTypes(); + params.selectedFiles = fileChooser->filenames(); + if (params.selectedFiles.size() > 0) + params.initialValue = params.selectedFiles[0]; WebFileChooserCompletionImpl* chooserCompletion = new WebFileChooserCompletionImpl(fileChooser); - bool ok = client->runFileChooser(multipleFiles, - WebString(), - suggestion, - chooserCompletion); - if (!ok) { - // Choosing failed, so do callback with an empty list. - chooserCompletion->didChooseFile(WebVector<WebString>()); - } + + if (client->runFileChooser(params, chooserCompletion)) + return; + + // Choosing failed, so do callback with an empty list. + chooserCompletion->didChooseFile(WebVector<WebString>()); } void ChromeClientImpl::popupOpened(PopupContainer* popupContainer, diff --git a/WebKit/chromium/src/ChromiumBridge.cpp b/WebKit/chromium/src/ChromiumBridge.cpp index 93d92ba..0fd0825 100644 --- a/WebKit/chromium/src/ChromiumBridge.cpp +++ b/WebKit/chromium/src/ChromiumBridge.cpp @@ -33,6 +33,7 @@ #include <googleurl/src/url_util.h> +#include "Chrome.h" #include "ChromeClientImpl.h" #include "WebClipboard.h" #include "WebCookie.h" @@ -54,13 +55,13 @@ #include "WebViewImpl.h" #include "WebWorkerClientImpl.h" -#if PLATFORM(WIN_OS) +#if OS(WINDOWS) #include "WebRect.h" #include "WebSandboxSupport.h" #include "WebThemeEngine.h" #endif -#if PLATFORM(LINUX) +#if OS(LINUX) #include "WebSandboxSupport.h" #include "WebFontInfo.h" #endif @@ -212,6 +213,12 @@ void ChromiumBridge::deleteCookie(const KURL& url, const String& cookieName) webKitClient()->deleteCookie(url, cookieName); } +bool ChromiumBridge::cookiesEnabled(const KURL& url, + const KURL& firstPartyForCookies) +{ + return webKitClient()->cookiesEnabled(url, firstPartyForCookies); +} + // DNS ------------------------------------------------------------------------ void ChromiumBridge::prefetchDNS(const String& hostname) @@ -278,7 +285,7 @@ KURL ChromiumBridge::filePathToURL(const String& path) // Font ----------------------------------------------------------------------- -#if PLATFORM(WIN_OS) +#if OS(WINDOWS) bool ChromiumBridge::ensureFontLoaded(HFONT font) { WebSandboxSupport* ss = webKitClient()->sandboxSupport(); @@ -289,7 +296,7 @@ bool ChromiumBridge::ensureFontLoaded(HFONT font) } #endif -#if PLATFORM(LINUX) +#if OS(LINUX) String ChromiumBridge::getFontFamilyForCharacters(const UChar* characters, size_t numCharacters) { if (webKitClient()->sandboxSupport()) @@ -473,7 +480,7 @@ double ChromiumBridge::currentTime() // Theming -------------------------------------------------------------------- -#if PLATFORM(WIN_OS) +#if OS(WINDOWS) void ChromiumBridge::paintButton( GraphicsContext* gc, int part, int state, int classicState, diff --git a/WebKit/chromium/src/ContextMenuClientImpl.cpp b/WebKit/chromium/src/ContextMenuClientImpl.cpp index f23919e..72b861f 100644 --- a/WebKit/chromium/src/ContextMenuClientImpl.cpp +++ b/WebKit/chromium/src/ContextMenuClientImpl.cpp @@ -79,11 +79,11 @@ static WebURL urlFromFrame(Frame* frame) return WebURL(); } -// Helper function to determine whether text is a single word or a sentence. +// Helper function to determine whether text is a single word. static bool isASingleWord(const String& text) { - TextBreakIterator* it = characterBreakIterator(text.characters(), text.length()); - return it && textBreakNext(it) == TextBreakDone; + TextBreakIterator* it = wordBreakIterator(text.characters(), text.length()); + return it && textBreakNext(it) == static_cast<int>(text.length()); } // Helper function to get misspelled word on which context menu diff --git a/WebKit/chromium/src/DOMUtilitiesPrivate.cpp b/WebKit/chromium/src/DOMUtilitiesPrivate.cpp index ffdd85d..4081db6 100644 --- a/WebKit/chromium/src/DOMUtilitiesPrivate.cpp +++ b/WebKit/chromium/src/DOMUtilitiesPrivate.cpp @@ -84,4 +84,53 @@ String nameOfInputElement(HTMLInputElement* element) return WebInputElement(element).nameForAutofill(); } +bool elementHasLegalLinkAttribute(const Element* element, + const QualifiedName& attrName) +{ + if (attrName == HTMLNames::srcAttr) { + // Check src attribute. + if (element->hasTagName(HTMLNames::imgTag) + || element->hasTagName(HTMLNames::scriptTag) + || element->hasTagName(HTMLNames::iframeTag) + || element->hasTagName(HTMLNames::frameTag)) + return true; + if (element->hasTagName(HTMLNames::inputTag)) { + const HTMLInputElement* input = + static_cast<const HTMLInputElement*>(element); + if (input->inputType() == HTMLInputElement::IMAGE) + return true; + } + } else if (attrName == HTMLNames::hrefAttr) { + // Check href attribute. + if (element->hasTagName(HTMLNames::linkTag) + || element->hasTagName(HTMLNames::aTag) + || element->hasTagName(HTMLNames::areaTag)) + return true; + } else if (attrName == HTMLNames::actionAttr) { + if (element->hasTagName(HTMLNames::formTag)) + return true; + } else if (attrName == HTMLNames::backgroundAttr) { + if (element->hasTagName(HTMLNames::bodyTag) + || element->hasTagName(HTMLNames::tableTag) + || element->hasTagName(HTMLNames::trTag) + || element->hasTagName(HTMLNames::tdTag)) + return true; + } else if (attrName == HTMLNames::citeAttr) { + if (element->hasTagName(HTMLNames::blockquoteTag) + || element->hasTagName(HTMLNames::qTag) + || element->hasTagName(HTMLNames::delTag) + || element->hasTagName(HTMLNames::insTag)) + return true; + } else if (attrName == HTMLNames::classidAttr + || attrName == HTMLNames::dataAttr) { + if (element->hasTagName(HTMLNames::objectTag)) + return true; + } else if (attrName == HTMLNames::codebaseAttr) { + if (element->hasTagName(HTMLNames::objectTag) + || element->hasTagName(HTMLNames::appletTag)) + return true; + } + return false; +} + } // namespace WebKit diff --git a/WebKit/chromium/src/DOMUtilitiesPrivate.h b/WebKit/chromium/src/DOMUtilitiesPrivate.h index c02bf84..253ab3f 100644 --- a/WebKit/chromium/src/DOMUtilitiesPrivate.h +++ b/WebKit/chromium/src/DOMUtilitiesPrivate.h @@ -32,11 +32,13 @@ #define DOMUtilitiesPrivate_h namespace WebCore { +class Element; class HTMLInputElement; class HTMLLinkElement; class HTMLMetaElement; class HTMLOptionElement; class Node; +class QualifiedName; class String; } @@ -53,6 +55,16 @@ WebCore::HTMLOptionElement* toHTMLOptionElement(WebCore::Node*); // FIXME: Deprecate. Use WebInputElement::nameForAutofill instead. WebCore::String nameOfInputElement(WebCore::HTMLInputElement*); +// For img, script, iframe, frame element, when attribute name is src, +// for link, a, area element, when attribute name is href, +// for form element, when attribute name is action, +// for input, type=image, when attribute name is src, +// for body, table, tr, td, when attribute name is background, +// for blockquote, q, del, ins, when attribute name is cite, +// we can consider the attribute value has legal link. +bool elementHasLegalLinkAttribute(const WebCore::Element* element, + const WebCore::QualifiedName& attrName); + } // namespace WebKit #endif diff --git a/WebKit/chromium/src/DragClientImpl.cpp b/WebKit/chromium/src/DragClientImpl.cpp index 5d8a9c3..671e7ca 100644 --- a/WebKit/chromium/src/DragClientImpl.cpp +++ b/WebKit/chromium/src/DragClientImpl.cpp @@ -79,9 +79,7 @@ void DragClientImpl::startDrag(DragImageRef dragImage, WebDragData dragData = static_cast<ClipboardChromium*>(clipboard)->dataObject(); - DragOperation dragOperationMask; - if (!clipboard->sourceOperation(dragOperationMask)) - dragOperationMask = DragOperationEvery; + DragOperation dragOperationMask = clipboard->sourceOperation(); m_webView->startDragging( eventPos, dragData, static_cast<WebDragOperationsMask>(dragOperationMask)); diff --git a/WebKit/chromium/src/EditorClientImpl.cpp b/WebKit/chromium/src/EditorClientImpl.cpp index 5db8ff7..e035e6a 100644 --- a/WebKit/chromium/src/EditorClientImpl.cpp +++ b/WebKit/chromium/src/EditorClientImpl.cpp @@ -105,7 +105,7 @@ bool EditorClientImpl::isSelectTrailingWhitespaceEnabled() { if (m_webView->client()) return m_webView->client()->isSelectTrailingWhitespaceEnabled(); -#if PLATFORM(WIN_OS) +#if OS(WINDOWS) return true; #else return false; @@ -357,7 +357,7 @@ static const unsigned CtrlKey = 1 << 0; static const unsigned AltKey = 1 << 1; static const unsigned ShiftKey = 1 << 2; static const unsigned MetaKey = 1 << 3; -#if PLATFORM(DARWIN) +#if OS(DARWIN) // Aliases for the generic key defintions to make kbd shortcuts definitions more // readable on OS X. static const unsigned OptionKey = AltKey; @@ -387,7 +387,7 @@ struct KeyPressEntry { static const KeyDownEntry keyDownEntries[] = { { VKEY_LEFT, 0, "MoveLeft" }, { VKEY_LEFT, ShiftKey, "MoveLeftAndModifySelection" }, -#if PLATFORM(DARWIN) +#if OS(DARWIN) { VKEY_LEFT, OptionKey, "MoveWordLeft" }, { VKEY_LEFT, OptionKey | ShiftKey, "MoveWordLeftAndModifySelection" }, @@ -398,7 +398,7 @@ static const KeyDownEntry keyDownEntries[] = { #endif { VKEY_RIGHT, 0, "MoveRight" }, { VKEY_RIGHT, ShiftKey, "MoveRightAndModifySelection" }, -#if PLATFORM(DARWIN) +#if OS(DARWIN) { VKEY_RIGHT, OptionKey, "MoveWordRight" }, { VKEY_RIGHT, OptionKey | ShiftKey, "MoveWordRightAndModifySelection" }, @@ -418,12 +418,12 @@ static const KeyDownEntry keyDownEntries[] = { { VKEY_HOME, 0, "MoveToBeginningOfLine" }, { VKEY_HOME, ShiftKey, "MoveToBeginningOfLineAndModifySelection" }, -#if PLATFORM(DARWIN) +#if OS(DARWIN) { VKEY_LEFT, CommandKey, "MoveToBeginningOfLine" }, { VKEY_LEFT, CommandKey | ShiftKey, "MoveToBeginningOfLineAndModifySelection" }, #endif -#if PLATFORM(DARWIN) +#if OS(DARWIN) { VKEY_UP, CommandKey, "MoveToBeginningOfDocument" }, { VKEY_UP, CommandKey | ShiftKey, "MoveToBeginningOfDocumentAndModifySelection" }, @@ -434,7 +434,7 @@ static const KeyDownEntry keyDownEntries[] = { #endif { VKEY_END, 0, "MoveToEndOfLine" }, { VKEY_END, ShiftKey, "MoveToEndOfLineAndModifySelection" }, -#if PLATFORM(DARWIN) +#if OS(DARWIN) { VKEY_DOWN, CommandKey, "MoveToEndOfDocument" }, { VKEY_DOWN, CommandKey | ShiftKey, "MoveToEndOfDocumentAndModifySelection" }, @@ -443,7 +443,7 @@ static const KeyDownEntry keyDownEntries[] = { { VKEY_END, CtrlKey | ShiftKey, "MoveToEndOfDocumentAndModifySelection" }, #endif -#if PLATFORM(DARWIN) +#if OS(DARWIN) { VKEY_RIGHT, CommandKey, "MoveToEndOfLine" }, { VKEY_RIGHT, CommandKey | ShiftKey, "MoveToEndOfLineAndModifySelection" }, @@ -451,7 +451,7 @@ static const KeyDownEntry keyDownEntries[] = { { VKEY_BACK, 0, "DeleteBackward" }, { VKEY_BACK, ShiftKey, "DeleteBackward" }, { VKEY_DELETE, 0, "DeleteForward" }, -#if PLATFORM(DARWIN) +#if OS(DARWIN) { VKEY_BACK, OptionKey, "DeleteWordBackward" }, { VKEY_DELETE, OptionKey, "DeleteWordForward" }, #else @@ -473,7 +473,7 @@ static const KeyDownEntry keyDownEntries[] = { { VKEY_INSERT, CtrlKey, "Copy" }, { VKEY_INSERT, ShiftKey, "Paste" }, { VKEY_DELETE, ShiftKey, "Cut" }, -#if !PLATFORM(DARWIN) +#if !OS(DARWIN) // On OS X, we pipe these back to the browser, so that it can do menu item // blinking. { 'C', CtrlKey, "Copy" }, @@ -600,13 +600,13 @@ bool EditorClientImpl::handleEditingKeyboardEvent(KeyboardEvent* evt) // unexpected behaviour if (ch < ' ') return false; -#if !PLATFORM(WIN_OS) +#if !OS(WINDOWS) // Don't insert ASCII character if ctrl w/o alt or meta is on. // On Mac, we should ignore events when meta is on (Command-<x>). if (ch < 0x80) { if (evt->keyEvent()->ctrlKey() && !evt->keyEvent()->altKey()) return false; -#if PLATFORM(DARWIN) +#if OS(DARWIN) if (evt->keyEvent()->metaKey()) return false; #endif diff --git a/WebKit/chromium/src/EventListenerWrapper.cpp b/WebKit/chromium/src/EventListenerWrapper.cpp new file mode 100644 index 0000000..f2d2979 --- /dev/null +++ b/WebKit/chromium/src/EventListenerWrapper.cpp @@ -0,0 +1,72 @@ +/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "EventListenerWrapper.h"
+
+#include "Event.h"
+#include "EventListener.h"
+
+#include "WebEvent.h"
+#include "WebEventListener.h"
+
+namespace WebKit {
+
+EventListenerWrapper::EventListenerWrapper(WebEventListener* webEventListener)
+ : EventListener(EventListener::JSEventListenerType)
+ , m_webEventListener(webEventListener)
+{
+}
+
+EventListenerWrapper::~EventListenerWrapper()
+{
+ if (m_webEventListener)
+ m_webEventListener->notifyEventListenerDeleted(this);
+}
+
+bool EventListenerWrapper::operator==(const EventListener& listener)
+{
+ return this == &listener;
+}
+
+void EventListenerWrapper::handleEvent(ScriptExecutionContext* context, Event* event)
+{
+ if (!m_webEventListener)
+ return;
+ WebEvent webEvent(event);
+ m_webEventListener->handleEvent(webEvent);
+}
+
+void EventListenerWrapper::webEventListenerDeleted()
+{
+ m_webEventListener = 0;
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/EventListenerWrapper.h b/WebKit/chromium/src/EventListenerWrapper.h new file mode 100644 index 0000000..2a0cbbb --- /dev/null +++ b/WebKit/chromium/src/EventListenerWrapper.h @@ -0,0 +1,62 @@ +/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EventListenerWrapper_h
+#define EventListenerWrapper_h
+
+#include "EventListener.h"
+
+namespace WebCore {
+class ScriptExecutionContext;
+}
+
+using namespace WebCore;
+
+namespace WebKit {
+
+class WebEventListener;
+
+class EventListenerWrapper : public EventListener {
+public:
+ EventListenerWrapper(WebEventListener*);
+ ~EventListenerWrapper();
+
+ virtual bool operator==(const EventListener&);
+ virtual void handleEvent(ScriptExecutionContext*, Event*);
+
+ void webEventListenerDeleted();
+
+private:
+ WebEventListener* m_webEventListener;
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/WebKit/chromium/src/FrameLoaderClientImpl.cpp b/WebKit/chromium/src/FrameLoaderClientImpl.cpp index 3ca8e8d..b984308 100644 --- a/WebKit/chromium/src/FrameLoaderClientImpl.cpp +++ b/WebKit/chromium/src/FrameLoaderClientImpl.cpp @@ -164,6 +164,22 @@ bool FrameLoaderClientImpl::allowJavaScript(bool enabledPerSettings) return enabledPerSettings; } +bool FrameLoaderClientImpl::allowPlugins(bool enabledPerSettings) +{ + if (m_webFrame->client()) + return m_webFrame->client()->allowPlugins(m_webFrame, enabledPerSettings); + + return enabledPerSettings; +} + +bool FrameLoaderClientImpl::allowImages(bool enabledPerSettings) +{ + if (m_webFrame->client()) + return m_webFrame->client()->allowImages(m_webFrame, enabledPerSettings); + + return enabledPerSettings; +} + bool FrameLoaderClientImpl::hasWebView() const { return m_webFrame->viewImpl(); @@ -1325,7 +1341,7 @@ PassRefPtr<Widget> FrameLoaderClientImpl::createPlugin( const String& mimeType, bool loadManually) { -#if !PLATFORM(WIN_OS) +#if !OS(WINDOWS) // WebCore asks us to make a plugin even if we don't have a // registered handler, with a comment saying it's so we can display // the broken plugin icon. In Chromium, we normally register a diff --git a/WebKit/chromium/src/FrameLoaderClientImpl.h b/WebKit/chromium/src/FrameLoaderClientImpl.h index 4ddfe5f..901600c 100644 --- a/WebKit/chromium/src/FrameLoaderClientImpl.h +++ b/WebKit/chromium/src/FrameLoaderClientImpl.h @@ -66,7 +66,7 @@ public: virtual void didCreateScriptContextForFrame(); virtual void didDestroyScriptContextForFrame(); - // A context untied to a frame was created (through evaluateInNewContext). + // A context untied to a frame was created (through evaluateInIsolatedWorld). // This context is not tied to the lifetime of its frame, and is destroyed // in garbage collection. virtual void didCreateIsolatedScriptContext(); @@ -192,6 +192,8 @@ public: virtual void registerForIconNotification(bool listen = true); virtual void didChangeScrollOffset(); virtual bool allowJavaScript(bool enabledPerSettings); + virtual bool allowPlugins(bool enabledPerSettings); + virtual bool allowImages(bool enabledPerSettings); private: void makeDocumentView(); diff --git a/WebKit/chromium/src/GraphicsContext3D.cpp b/WebKit/chromium/src/GraphicsContext3D.cpp index c9ba5a1..7fe31b0 100644 --- a/WebKit/chromium/src/GraphicsContext3D.cpp +++ b/WebKit/chromium/src/GraphicsContext3D.cpp @@ -56,7 +56,7 @@ #include <stdio.h> #include <wtf/FastMalloc.h> -#if PLATFORM(WIN_OS) +#if OS(WINDOWS) #include <windows.h> #endif @@ -76,11 +76,11 @@ #include "NativeImageSkia.h" #endif -#if PLATFORM(DARWIN) +#if OS(DARWIN) #define USE_TEXTURE_RECTANGLE_FOR_FRAMEBUFFER #endif -#if PLATFORM(LINUX) +#if OS(LINUX) #include <dlfcn.h> #include "GL/glxew.h" #endif @@ -98,7 +98,7 @@ namespace WebCore { class GraphicsContext3DInternal { public: - GraphicsContext3DInternal(); + GraphicsContext3DInternal(GraphicsContext3D::Attributes attrs); ~GraphicsContext3DInternal(); bool makeContextCurrent(); @@ -116,12 +116,15 @@ public: void activeTexture(unsigned long texture); void bindBuffer(unsigned long target, WebGLBuffer* buffer); + void bindFramebuffer(unsigned long target, + WebGLFramebuffer* framebuffer); void bindTexture(unsigned long target, WebGLTexture* texture); void bufferDataImpl(unsigned long target, int size, const void* data, unsigned long usage); void disableVertexAttribArray(unsigned long index); void enableVertexAttribArray(unsigned long index); unsigned long getError(); + GraphicsContext3D::Attributes getContextAttributes(); void vertexAttribPointer(unsigned long indx, int size, int type, bool normalized, unsigned long stride, unsigned long offset); void viewportImpl(long x, long y, unsigned long width, unsigned long height); @@ -129,11 +132,16 @@ public: void synthesizeGLError(unsigned long error); private: + GraphicsContext3D::Attributes m_attrs; + unsigned int m_texture; unsigned int m_fbo; unsigned int m_depthBuffer; unsigned int m_cachedWidth, m_cachedHeight; + // For tracking which FBO is bound + unsigned int m_boundFBO; + #ifdef FLIP_FRAMEBUFFER_VERTICALLY unsigned char* m_scanline; void flipVertically(unsigned char* framebuffer, @@ -176,7 +184,8 @@ private: SkBitmap* m_resizingBitmap; #endif -#if PLATFORM(WIN_OS) + static bool s_initializedGLEW; +#if OS(WINDOWS) HWND m_canvasWindow; HDC m_canvasDC; HGLRC m_contextObj; @@ -184,30 +193,170 @@ private: CGLPBufferObj m_pbuffer; CGLContextObj m_contextObj; unsigned char* m_renderOutput; - CGContextRef m_cgContext; -#elif PLATFORM(LINUX) - Display* m_display; +#elif OS(LINUX) GLXContext m_contextObj; GLXPbuffer m_pbuffer; + // In order to avoid problems caused by linking against libGL, we // dynamically look up all the symbols we need. // http://code.google.com/p/chromium/issues/detail?id=16800 - void* m_libGL; - PFNGLXCHOOSEFBCONFIGPROC m_glXChooseFBConfig; - PFNGLXCREATENEWCONTEXTPROC m_glXCreateNewContext; - PFNGLXCREATEPBUFFERPROC m_glXCreatePbuffer; - PFNGLXDESTROYPBUFFERPROC m_glXDestroyPbuffer; - typedef Bool (* PFNGLXMAKECURRENTPROC)(Display* dpy, GLXDrawable drawable, GLXContext ctx); - PFNGLXMAKECURRENTPROC m_glXMakeCurrent; - typedef void (* PFNGLXDESTROYCONTEXTPROC)(Display* dpy, GLXContext ctx); - PFNGLXDESTROYCONTEXTPROC m_glXDestroyContext; - typedef GLXContext (* PFNGLXGETCURRENTCONTEXTPROC)(void); - PFNGLXGETCURRENTCONTEXTPROC m_glXGetCurrentContext; + class GLConnection { + public: + ~GLConnection(); + + static GLConnection* create(); + + GLXFBConfig* chooseFBConfig(int screen, const int *attrib_list, int *nelements) + { + return m_glXChooseFBConfig(m_display, screen, attrib_list, nelements); + } + + GLXContext createNewContext(GLXFBConfig config, int renderType, GLXContext shareList, Bool direct) + { + return m_glXCreateNewContext(m_display, config, renderType, shareList, direct); + } + + GLXPbuffer createPbuffer(GLXFBConfig config, const int *attribList) + { + return m_glXCreatePbuffer(m_display, config, attribList); + } + + void destroyPbuffer(GLXPbuffer pbuf) + { + m_glXDestroyPbuffer(m_display, pbuf); + } + + Bool makeCurrent(GLXDrawable drawable, GLXContext ctx) + { + return m_glXMakeCurrent(m_display, drawable, ctx); + } + + void destroyContext(GLXContext ctx) + { + m_glXDestroyContext(m_display, ctx); + } + + GLXContext getCurrentContext() + { + return m_glXGetCurrentContext(); + } + + private: + Display* m_display; + void* m_libGL; + PFNGLXCHOOSEFBCONFIGPROC m_glXChooseFBConfig; + PFNGLXCREATENEWCONTEXTPROC m_glXCreateNewContext; + PFNGLXCREATEPBUFFERPROC m_glXCreatePbuffer; + PFNGLXDESTROYPBUFFERPROC m_glXDestroyPbuffer; + typedef Bool (* PFNGLXMAKECURRENTPROC)(Display* dpy, GLXDrawable drawable, GLXContext ctx); + PFNGLXMAKECURRENTPROC m_glXMakeCurrent; + typedef void (* PFNGLXDESTROYCONTEXTPROC)(Display* dpy, GLXContext ctx); + PFNGLXDESTROYCONTEXTPROC m_glXDestroyContext; + typedef GLXContext (* PFNGLXGETCURRENTCONTEXTPROC)(void); + PFNGLXGETCURRENTCONTEXTPROC m_glXGetCurrentContext; + + GLConnection(Display* display, + void* libGL, + PFNGLXCHOOSEFBCONFIGPROC chooseFBConfig, + PFNGLXCREATENEWCONTEXTPROC createNewContext, + PFNGLXCREATEPBUFFERPROC createPbuffer, + PFNGLXDESTROYPBUFFERPROC destroyPbuffer, + PFNGLXMAKECURRENTPROC makeCurrent, + PFNGLXDESTROYCONTEXTPROC destroyContext, + PFNGLXGETCURRENTCONTEXTPROC getCurrentContext) + : m_libGL(libGL) + , m_display(display) + , m_glXChooseFBConfig(chooseFBConfig) + , m_glXCreateNewContext(createNewContext) + , m_glXCreatePbuffer(createPbuffer) + , m_glXDestroyPbuffer(destroyPbuffer) + , m_glXMakeCurrent(makeCurrent) + , m_glXDestroyContext(destroyContext) + , m_glXGetCurrentContext(getCurrentContext) + { + } + + static void* tryLoad(const char* libName) + { + // We use RTLD_GLOBAL semantics so that GLEW initialization works; + // GLEW expects to be able to open the current process's handle + // and do dlsym's of GL entry points from there. + return dlopen(libName, RTLD_LAZY | RTLD_GLOBAL); + } + }; + + static GLConnection* s_gl; #else #error Must port GraphicsContext3D to your platform #endif }; +bool GraphicsContext3DInternal::s_initializedGLEW = false; + +#if OS(LINUX) +GraphicsContext3DInternal::GLConnection* GraphicsContext3DInternal::s_gl = 0; + +GraphicsContext3DInternal::GLConnection* GraphicsContext3DInternal::GLConnection::create() +{ + Display* dpy = XOpenDisplay(0); + if (!dpy) { + printf("GraphicsContext3D: error opening X display\n"); + return 0; + } + + void* libGL = 0; + const char* libNames[] = { + "/usr/lib/libGL.so.1", + "/usr/lib32/libGL.so.1", + "/usr/lib64/libGL.so.1", + }; + for (int i = 0; i < sizeof(libNames) / sizeof(const char*); i++) { + libGL = tryLoad(libNames[i]); + if (libGL) + break; + } + if (!libGL) { + printf("GraphicsContext3D: error opening libGL.so.1\n"); + printf("GraphicsContext3D: tried:\n"); + for (int i = 0; i < sizeof(libNames) / sizeof(const char*); i++) + printf(" %s\n", libNames[i]); + return 0; + } + + PFNGLXCHOOSEFBCONFIGPROC chooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC) dlsym(libGL, "glXChooseFBConfig"); + PFNGLXCREATENEWCONTEXTPROC createNewContext = (PFNGLXCREATENEWCONTEXTPROC) dlsym(libGL, "glXCreateNewContext"); + PFNGLXCREATEPBUFFERPROC createPbuffer = (PFNGLXCREATEPBUFFERPROC) dlsym(libGL, "glXCreatePbuffer"); + PFNGLXDESTROYPBUFFERPROC destroyPbuffer = (PFNGLXDESTROYPBUFFERPROC) dlsym(libGL, "glXDestroyPbuffer"); + PFNGLXMAKECURRENTPROC makeCurrent = (PFNGLXMAKECURRENTPROC) dlsym(libGL, "glXMakeCurrent"); + PFNGLXDESTROYCONTEXTPROC destroyContext = (PFNGLXDESTROYCONTEXTPROC) dlsym(libGL, "glXDestroyContext"); + PFNGLXGETCURRENTCONTEXTPROC getCurrentContext = (PFNGLXGETCURRENTCONTEXTPROC) dlsym(libGL, "glXGetCurrentContext"); + if (!chooseFBConfig || !createNewContext || !createPbuffer + || !destroyPbuffer || !makeCurrent || !destroyContext + || !getCurrentContext) { + XCloseDisplay(dpy); + dlclose(libGL); + printf("GraphicsContext3D: error looking up bootstrapping entry points\n"); + return 0; + } + return new GLConnection(dpy, + libGL, + chooseFBConfig, + createNewContext, + createPbuffer, + destroyPbuffer, + makeCurrent, + destroyContext, + getCurrentContext); +} + +GraphicsContext3DInternal::GLConnection::~GLConnection() +{ + XCloseDisplay(m_display); + dlclose(m_libGL); +} + +#endif // OS(LINUX) + GraphicsContext3DInternal::VertexAttribPointerState::VertexAttribPointerState() : enabled(false) , buffer(0) @@ -220,20 +369,12 @@ GraphicsContext3DInternal::VertexAttribPointerState::VertexAttribPointerState() { } -#if PLATFORM(LINUX) -static void* tryLoad(const char* libName) -{ - // We use RTLD_GLOBAL semantics so that GLEW initialization works; - // GLEW expects to be able to open the current process's handle - // and do dlsym's of GL entry points from there. - return dlopen(libName, RTLD_LAZY | RTLD_GLOBAL); -} -#endif - -GraphicsContext3DInternal::GraphicsContext3DInternal() - : m_texture(0) +GraphicsContext3DInternal::GraphicsContext3DInternal(GraphicsContext3D::Attributes attrs) + : m_attrs(attrs) + , m_texture(0) , m_fbo(0) , m_depthBuffer(0) + , m_boundFBO(0) #ifdef FLIP_FRAMEBUFFER_VERTICALLY , m_scanline(0) #endif @@ -241,7 +382,7 @@ GraphicsContext3DInternal::GraphicsContext3DInternal() #if PLATFORM(SKIA) , m_resizingBitmap(0) #endif -#if PLATFORM(WIN_OS) +#if OS(WINDOWS) , m_canvasWindow(0) , m_canvasDC(0) , m_contextObj(0) @@ -249,23 +390,24 @@ GraphicsContext3DInternal::GraphicsContext3DInternal() , m_pbuffer(0) , m_contextObj(0) , m_renderOutput(0) - , m_cgContext(0) -#elif PLATFORM(LINUX) - , m_display(0) +#elif OS(LINUX) , m_contextObj(0) , m_pbuffer(0) - , m_glXChooseFBConfig(0) - , m_glXCreateNewContext(0) - , m_glXCreatePbuffer(0) - , m_glXDestroyPbuffer(0) - , m_glXMakeCurrent(0) - , m_glXDestroyContext(0) - , m_glXGetCurrentContext(0) #else #error Must port to your platform #endif { -#if PLATFORM(WIN_OS) + // FIXME: we need to take into account the user's requested + // context creation attributes, in particular stencil and + // antialias, and determine which could and could not be honored + // based on the capabilities of the OpenGL implementation. + m_attrs.alpha = true; + m_attrs.depth = true; + m_attrs.stencil = false; + m_attrs.antialias = false; + m_attrs.premultipliedAlpha = true; + +#if OS(WINDOWS) WNDCLASS wc; if (!GetClassInfo(GetModuleHandle(0), L"CANVASGL", &wc)) { ZeroMemory(&wc, sizeof(WNDCLASS)); @@ -377,43 +519,13 @@ GraphicsContext3DInternal::GraphicsContext3DInternal() } m_pbuffer = pbuffer; m_contextObj = context; -#elif PLATFORM(LINUX) - m_display = XOpenDisplay(0); - if (!m_display) { - printf("GraphicsContext3D: error opening X display\n"); - return; +#elif OS(LINUX) + if (!s_gl) { + s_gl = GLConnection::create(); + if (!s_gl) + return; } - const char* libNames[] = { - "/usr/lib/libGL.so.1", - "/usr/lib32/libGL.so.1", - "/usr/lib64/libGL.so.1", - }; - for (int i = 0; i < sizeof(libNames) / sizeof(const char*); i++) { - m_libGL = tryLoad(libNames[i]); - if (m_libGL) - break; - } - if (!m_libGL) { - printf("GraphicsContext3D: error opening libGL.so.1\n"); - printf("GraphicsContext3D: tried:"); - for (int i = 0; i < sizeof(libNames) / sizeof(const char*); i++) - printf(" %s", libNames[i]); - return; - } - m_glXChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC) dlsym(m_libGL, "glXChooseFBConfig"); - m_glXCreateNewContext = (PFNGLXCREATENEWCONTEXTPROC) dlsym(m_libGL, "glXCreateNewContext"); - m_glXCreatePbuffer = (PFNGLXCREATEPBUFFERPROC) dlsym(m_libGL, "glXCreatePbuffer"); - m_glXDestroyPbuffer = (PFNGLXDESTROYPBUFFERPROC) dlsym(m_libGL, "glXDestroyPbuffer"); - m_glXMakeCurrent = (PFNGLXMAKECURRENTPROC) dlsym(m_libGL, "glXMakeCurrent"); - m_glXDestroyContext = (PFNGLXDESTROYCONTEXTPROC) dlsym(m_libGL, "glXDestroyContext"); - m_glXGetCurrentContext = (PFNGLXGETCURRENTCONTEXTPROC) dlsym(m_libGL, "glXGetCurrentContext"); - if (!m_glXChooseFBConfig || !m_glXCreateNewContext || !m_glXCreatePbuffer - || !m_glXDestroyPbuffer || !m_glXMakeCurrent || !m_glXDestroyContext - || !m_glXGetCurrentContext) { - printf("GraphicsContext3D: error looking up bootstrapping entry points\n"); - return; - } int configAttrs[] = { GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, @@ -424,7 +536,7 @@ GraphicsContext3DInternal::GraphicsContext3DInternal() 0 }; int nelements = 0; - GLXFBConfig* config = m_glXChooseFBConfig(m_display, 0, configAttrs, &nelements); + GLXFBConfig* config = s_gl->chooseFBConfig(0, configAttrs, &nelements); if (!config) { printf("GraphicsContext3D: glXChooseFBConfig failed\n"); return; @@ -434,7 +546,7 @@ GraphicsContext3DInternal::GraphicsContext3DInternal() XFree(config); return; } - GLXContext context = m_glXCreateNewContext(m_display, config[0], GLX_RGBA_TYPE, 0, True); + GLXContext context = s_gl->createNewContext(config[0], GLX_RGBA_TYPE, 0, True); if (!context) { printf("GraphicsContext3D: glXCreateNewContext failed\n"); XFree(config); @@ -447,13 +559,13 @@ GraphicsContext3DInternal::GraphicsContext3DInternal() 1, 0 }; - GLXPbuffer pbuffer = m_glXCreatePbuffer(m_display, config[0], pbufferAttrs); + GLXPbuffer pbuffer = s_gl->createPbuffer(config[0], pbufferAttrs); XFree(config); if (!pbuffer) { printf("GraphicsContext3D: glxCreatePbuffer failed\n"); return; } - if (!m_glXMakeCurrent(m_display, pbuffer, context)) { + if (!s_gl->makeCurrent(pbuffer, context)) { printf("GraphicsContext3D: glXMakeCurrent failed\n"); return; } @@ -463,8 +575,7 @@ GraphicsContext3DInternal::GraphicsContext3DInternal() #error Must port to your platform #endif - static bool initializedGLEW = false; - if (!initializedGLEW) { + if (!s_initializedGLEW) { // Initialize GLEW and check for GL 2.0 support by the drivers. GLenum glewInitResult = glewInit(); if (glewInitResult != GLEW_OK) { @@ -475,7 +586,7 @@ GraphicsContext3DInternal::GraphicsContext3DInternal() printf("GraphicsContext3D: OpenGL 2.0 not supported\n"); return; } - initializedGLEW = true; + s_initializedGLEW = true; } } @@ -495,7 +606,7 @@ GraphicsContext3DInternal::~GraphicsContext3DInternal() if (m_resizingBitmap) delete m_resizingBitmap; #endif -#if PLATFORM(WIN_OS) +#if OS(WINDOWS) wglMakeCurrent(0, 0); wglDeleteContext(m_contextObj); ReleaseDC(m_canvasWindow, m_canvasDC); @@ -504,16 +615,12 @@ GraphicsContext3DInternal::~GraphicsContext3DInternal() CGLSetCurrentContext(0); CGLDestroyContext(m_contextObj); CGLDestroyPBuffer(m_pbuffer); - if (m_cgContext) - CGContextRelease(m_cgContext); if (m_renderOutput) delete[] m_renderOutput; -#elif PLATFORM(LINUX) - m_glXMakeCurrent(m_display, 0, 0); - m_glXDestroyContext(m_display, m_contextObj); - m_glXDestroyPbuffer(m_display, m_pbuffer); - XCloseDisplay(m_display); - dlclose(m_libGL); +#elif OS(LINUX) + s_gl->makeCurrent(0, 0); + s_gl->destroyContext(m_contextObj); + s_gl->destroyPbuffer(m_pbuffer); #else #error Must port to your platform #endif @@ -522,7 +629,7 @@ GraphicsContext3DInternal::~GraphicsContext3DInternal() bool GraphicsContext3DInternal::makeContextCurrent() { -#if PLATFORM(WIN_OS) +#if OS(WINDOWS) if (wglGetCurrentContext() != m_contextObj) if (wglMakeCurrent(m_canvasDC, m_contextObj)) return true; @@ -530,9 +637,9 @@ bool GraphicsContext3DInternal::makeContextCurrent() if (CGLGetCurrentContext() != m_contextObj) if (CGLSetCurrentContext(m_contextObj) == kCGLNoError) return true; -#elif PLATFORM(LINUX) - if (m_glXGetCurrentContext() != m_contextObj) - if (m_glXMakeCurrent(m_display, m_pbuffer, m_contextObj)) +#elif OS(LINUX) + if (s_gl->getCurrentContext() != m_contextObj) + if (s_gl->makeCurrent(m_pbuffer, m_contextObj)) return true; #else #error Must port to your platform @@ -594,6 +701,7 @@ void GraphicsContext3DInternal::reshape(int width, int height) glBindTexture(target, 0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); + m_boundFBO = m_fbo; glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); @@ -623,20 +731,12 @@ void GraphicsContext3DInternal::reshape(int width, int height) #if PLATFORM(CG) // Need to reallocate the client-side backing store. // FIXME: make this more efficient. - if (m_cgContext) { - CGContextRelease(m_cgContext); - m_cgContext = 0; - } if (m_renderOutput) { delete[] m_renderOutput; m_renderOutput = 0; } int rowBytes = width * 4; m_renderOutput = new unsigned char[height * rowBytes]; - CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); - m_cgContext = CGBitmapContextCreate(m_renderOutput, width, height, 8, rowBytes, - colorSpace, kCGImageAlphaPremultipliedLast); - CGColorSpaceRelease(colorSpace); #endif // PLATFORM(CG) } @@ -681,6 +781,9 @@ void GraphicsContext3DInternal::beginPaint(WebGLRenderingContext* context) HTMLCanvasElement* canvas = context->canvas(); ImageBuffer* imageBuffer = canvas->buffer(); unsigned char* pixels = 0; + bool mustRestoreFBO = (m_boundFBO != m_fbo); + if (mustRestoreFBO) + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); #if PLATFORM(SKIA) const SkBitmap* canvasBitmap = imageBuffer->context()->platformContext()->bitmap(); const SkBitmap* readbackBitmap = 0; @@ -721,15 +824,16 @@ void GraphicsContext3DInternal::beginPaint(WebGLRenderingContext* context) glReadPixels(0, 0, m_cachedWidth, m_cachedHeight, GL_BGRA, GL_UNSIGNED_BYTE, pixels); #elif PLATFORM(CG) if (m_renderOutput) { - ASSERT(CGBitmapContextGetWidth(m_cgContext) == m_cachedWidth); - ASSERT(CGBitmapContextGetHeight(m_cgContext) == m_cachedHeight); pixels = m_renderOutput; - glReadPixels(0, 0, m_cachedWidth, m_cachedHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + glReadPixels(0, 0, m_cachedWidth, m_cachedHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels); } #else #error Must port to your platform #endif + if (mustRestoreFBO) + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO); + #ifdef FLIP_FRAMEBUFFER_VERTICALLY if (pixels) flipVertically(pixels, m_cachedWidth, m_cachedHeight); @@ -745,7 +849,20 @@ void GraphicsContext3DInternal::beginPaint(WebGLRenderingContext* context) } #elif PLATFORM(CG) if (m_renderOutput) { - CGImageRef cgImage = CGBitmapContextCreateImage(m_cgContext); + int rowBytes = m_cachedWidth * 4; + CGDataProviderRef dataProvider = CGDataProviderCreateWithData(0, m_renderOutput, rowBytes * m_cachedHeight, 0); + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGImageRef cgImage = CGImageCreate(m_cachedWidth, + m_cachedHeight, + 8, + 32, + rowBytes, + colorSpace, + kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, + dataProvider, + 0, + false, + kCGRenderingIntentDefault); // CSS styling may cause the canvas's content to be resized on // the page. Go back to the Canvas to figure out the correct // width and height to draw. @@ -756,9 +873,13 @@ void GraphicsContext3DInternal::beginPaint(WebGLRenderingContext* context) // rendering results. CGContextSetBlendMode(imageBuffer->context()->platformContext(), kCGBlendModeCopy); + CGContextSetInterpolationQuality(imageBuffer->context()->platformContext(), + kCGInterpolationNone); CGContextDrawImage(imageBuffer->context()->platformContext(), rect, cgImage); CGImageRelease(cgImage); + CGColorSpaceRelease(colorSpace); + CGDataProviderRelease(dataProvider); } #else #error Must port to your platform @@ -788,6 +909,17 @@ void GraphicsContext3DInternal::bindBuffer(unsigned long target, glBindBuffer(target, bufID); } +void GraphicsContext3DInternal::bindFramebuffer(unsigned long target, + WebGLFramebuffer* framebuffer) +{ + makeContextCurrent(); + GLuint id = EXTRACT(framebuffer); + if (!id) + id = m_fbo; + glBindFramebufferEXT(target, id); + m_boundFBO = id; +} + // If we didn't have to hack GL_TEXTURE_WRAP_R for cube maps, // we could just use: // GL_SAME_METHOD_2_X2(BindTexture, bindTexture, unsigned long, WebGLTexture*) @@ -864,6 +996,11 @@ unsigned long GraphicsContext3DInternal::getError() return glGetError(); } +GraphicsContext3D::Attributes GraphicsContext3DInternal::getContextAttributes() +{ + return m_attrs; +} + void GraphicsContext3DInternal::vertexAttribPointer(unsigned long indx, int size, int type, bool normalized, unsigned long stride, unsigned long offset) { @@ -1012,17 +1149,17 @@ void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 gl##glname(a1, a2, a3, a4, a5, a6, a7, a8); \ } -PassOwnPtr<GraphicsContext3D> GraphicsContext3D::create() +PassOwnPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attrs) { - PassOwnPtr<GraphicsContext3D> context = new GraphicsContext3D(); + PassOwnPtr<GraphicsContext3D> context = new GraphicsContext3D(attrs); // FIXME: add error checking return context; } -GraphicsContext3D::GraphicsContext3D() +GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs) : m_currentWidth(0) , m_currentHeight(0) - , m_internal(new GraphicsContext3DInternal()) + , m_internal(new GraphicsContext3DInternal(attrs)) { } @@ -1190,7 +1327,10 @@ void GraphicsContext3D::bindBuffer(unsigned long target, m_internal->bindBuffer(target, buffer); } -GL_SAME_METHOD_2_X2(BindFramebufferEXT, bindFramebuffer, unsigned long, WebGLFramebuffer*) +void GraphicsContext3D::bindFramebuffer(unsigned long target, WebGLFramebuffer* framebuffer) +{ + m_internal->bindFramebuffer(target, framebuffer); +} GL_SAME_METHOD_2_X2(BindRenderbufferEXT, bindRenderbuffer, unsigned long, WebGLRenderbuffer*) @@ -1448,6 +1588,11 @@ void GraphicsContext3D::getBufferParameteriv(unsigned long target, unsigned long glGetBufferParameteriv(target, pname, value); } +GraphicsContext3D::Attributes GraphicsContext3D::getContextAttributes() +{ + return m_internal->getContextAttributes(); +} + unsigned long GraphicsContext3D::getError() { return m_internal->getError(); @@ -1735,7 +1880,7 @@ int GraphicsContext3D::texImage2D(unsigned target, unsigned border, unsigned format, unsigned type, - WebGLArray* pixels) + void* pixels) { // FIXME: must do validation similar to JOGL's to ensure that // the incoming array is of the appropriate length. @@ -1747,25 +1892,10 @@ int GraphicsContext3D::texImage2D(unsigned target, border, format, type, - pixels->baseAddress()); + pixels); return 0; } -int GraphicsContext3D::texImage2D(unsigned target, - unsigned level, - unsigned internalformat, - unsigned width, - unsigned height, - unsigned border, - unsigned format, - unsigned type, - ImageData* pixels) -{ - // FIXME: implement. - notImplemented(); - return -1; -} - // Remove premultiplied alpha from color channels. // FIXME: this is lossy. Must retrieve original values from HTMLImageElement. static void unmultiplyAlpha(unsigned char* rgbaData, int numPixels) @@ -1926,6 +2056,7 @@ int GraphicsContext3D::texImage2D(unsigned target, unsigned level, Image* image, colorSpace, kCGImageAlphaPremultipliedLast); CGColorSpaceRelease(colorSpace); + CGContextSetBlendMode(tmpContext, kCGBlendModeCopy); CGContextDrawImage(tmpContext, CGRectMake(0, 0, static_cast<CGFloat>(width), static_cast<CGFloat>(height)), cgImage); @@ -1939,14 +2070,6 @@ int GraphicsContext3D::texImage2D(unsigned target, unsigned level, Image* image, return res; } -int GraphicsContext3D::texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, - bool flipY, bool premultiplyAlpha) -{ - // FIXME: implement. - notImplemented(); - return -1; -} - GL_SAME_METHOD_3(TexParameterf, texParameterf, unsigned, unsigned, float); GL_SAME_METHOD_3(TexParameteri, texParameteri, unsigned, unsigned, int); @@ -1959,34 +2082,16 @@ int GraphicsContext3D::texSubImage2D(unsigned target, unsigned height, unsigned format, unsigned type, - WebGLArray* pixels) + void* pixels) { - // FIXME: implement. - notImplemented(); - return -1; -} - -int GraphicsContext3D::texSubImage2D(unsigned target, - unsigned level, - unsigned xoffset, - unsigned yoffset, - unsigned width, - unsigned height, - unsigned format, - unsigned type, - ImageData* pixels) -{ - // FIXME: implement. - notImplemented(); - return -1; + glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); + return 0; } int GraphicsContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, - unsigned height, Image* image, bool flipY, bool premultiplyAlpha) @@ -1996,21 +2101,6 @@ int GraphicsContext3D::texSubImage2D(unsigned target, return -1; } -int GraphicsContext3D::texSubImage2D(unsigned target, - unsigned level, - unsigned xoffset, - unsigned yoffset, - unsigned width, - unsigned height, - HTMLVideoElement* video, - bool flipY, - bool premultiplyAlpha) -{ - // FIXME: implement. - notImplemented(); - return -1; -} - GL_SAME_METHOD_2(Uniform1f, uniform1f, long, float) void GraphicsContext3D::uniform1fv(long location, float* v, int size) diff --git a/WebKit/chromium/src/LocalizedStrings.cpp b/WebKit/chromium/src/LocalizedStrings.cpp index 1121931..4e01848 100644 --- a/WebKit/chromium/src/LocalizedStrings.cpp +++ b/WebKit/chromium/src/LocalizedStrings.cpp @@ -165,6 +165,16 @@ String AXLinkActionVerb() return query(WebLocalizedString::AXLinkActionVerb); } +String AXMenuListPopupActionVerb() +{ + return String(); +} + +String AXMenuListActionVerb() +{ + return String(); +} + String multipleFileUploadText(unsigned numberOfFiles) { return query(WebLocalizedString::MultipleFileUploadText, numberOfFiles); diff --git a/WebKit/chromium/src/NotificationPresenterImpl.cpp b/WebKit/chromium/src/NotificationPresenterImpl.cpp index 6b22319..a38b8b5 100644 --- a/WebKit/chromium/src/NotificationPresenterImpl.cpp +++ b/WebKit/chromium/src/NotificationPresenterImpl.cpp @@ -33,12 +33,15 @@ #if ENABLE(NOTIFICATIONS) +#include "Document.h" #include "Notification.h" #include "SecurityOrigin.h" +#include "WebDocument.h" #include "WebNotification.h" #include "WebNotificationPermissionCallback.h" #include "WebNotificationPresenter.h" +#include "WebURL.h" #include <wtf/PassRefPtr.h> @@ -89,9 +92,13 @@ void NotificationPresenterImpl::notificationObjectDestroyed(Notification* notifi m_presenter->objectDestroyed(PassRefPtr<Notification>(notification)); } -NotificationPresenter::Permission NotificationPresenterImpl::checkPermission(SecurityOrigin* origin) +NotificationPresenter::Permission NotificationPresenterImpl::checkPermission(const KURL& url, Document* document) { - int result = m_presenter->checkPermission(origin->toString()); + WebDocument webDocument; + if (document) + webDocument = document; + + int result = m_presenter->checkPermission(url, document ? &webDocument : 0); return static_cast<NotificationPresenter::Permission>(result); } diff --git a/WebKit/chromium/src/NotificationPresenterImpl.h b/WebKit/chromium/src/NotificationPresenterImpl.h index 4afe9dc..8e3799c 100644 --- a/WebKit/chromium/src/NotificationPresenterImpl.h +++ b/WebKit/chromium/src/NotificationPresenterImpl.h @@ -54,7 +54,7 @@ public: virtual bool show(WebCore::Notification* object); virtual void cancel(WebCore::Notification* object); virtual void notificationObjectDestroyed(WebCore::Notification* object); - virtual WebCore::NotificationPresenter::Permission checkPermission(WebCore::SecurityOrigin* origin); + virtual WebCore::NotificationPresenter::Permission checkPermission(const WebCore::KURL& url, WebCore::Document* document); virtual void requestPermission(WebCore::SecurityOrigin* origin, WTF::PassRefPtr<WebCore::VoidCallback> callback); private: diff --git a/WebKit/chromium/src/PlatformMessagePortChannel.cpp b/WebKit/chromium/src/PlatformMessagePortChannel.cpp index f8c41d3..aa42a10 100644 --- a/WebKit/chromium/src/PlatformMessagePortChannel.cpp +++ b/WebKit/chromium/src/PlatformMessagePortChannel.cpp @@ -179,7 +179,7 @@ void PlatformMessagePortChannel::postMessageToRemote(PassOwnPtr<MessagePortChann if (!m_localPort || !m_webChannel) return; - WebString messageString = message->message()->toString(); + WebString messageString = message->message()->toWireString(); OwnPtr<WebCore::MessagePortChannelArray> channels = message->channels(); WebMessagePortChannelArray* webChannels = 0; if (channels.get() && channels->size()) { @@ -211,7 +211,7 @@ bool PlatformMessagePortChannel::tryGetMessageFromRemote(OwnPtr<MessagePortChann (*channels)[i] = MessagePortChannel::create(platformChannel); } } - RefPtr<SerializedScriptValue> serializedMessage = SerializedScriptValue::create(message); + RefPtr<SerializedScriptValue> serializedMessage = SerializedScriptValue::createFromWire(message); result = MessagePortChannel::EventData::create(serializedMessage.release(), channels.release()); } diff --git a/WebKit/chromium/src/StorageAreaProxy.cpp b/WebKit/chromium/src/StorageAreaProxy.cpp index 551507f..c9185fe 100644 --- a/WebKit/chromium/src/StorageAreaProxy.cpp +++ b/WebKit/chromium/src/StorageAreaProxy.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Google Inc. All Rights Reserved. + * (C) 2008 Apple Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,11 +29,16 @@ #if ENABLE(DOM_STORAGE) +#include "DOMWindow.h" #include "Document.h" +#include "EventNames.h" #include "ExceptionCode.h" #include "Frame.h" +#include "Page.h" +#include "PageGroup.h" #include "SecurityOrigin.h" #include "StorageAreaImpl.h" +#include "StorageEvent.h" #include "WebStorageArea.h" #include "WebString.h" @@ -40,8 +46,9 @@ namespace WebCore { -StorageAreaProxy::StorageAreaProxy(WebKit::WebStorageArea* storageArea) +StorageAreaProxy::StorageAreaProxy(WebKit::WebStorageArea* storageArea, StorageType storageType) : m_storageArea(storageArea) + , m_storageType(storageType) { } @@ -64,21 +71,34 @@ String StorageAreaProxy::getItem(const String& key) const return m_storageArea->getItem(key); } -void StorageAreaProxy::setItem(const String& key, const String& value, ExceptionCode& ec, Frame* frame) +String StorageAreaProxy::setItem(const String& key, const String& value, ExceptionCode& ec, Frame* frame) { bool quotaException = false; - m_storageArea->setItem(key, value, frame->document()->url(), quotaException); + WebKit::WebString oldValue; + m_storageArea->setItem(key, value, frame->document()->url(), quotaException, oldValue); ec = quotaException ? QUOTA_EXCEEDED_ERR : 0; + String oldValueString = oldValue; + if (oldValueString != value) + storageEvent(key, oldValue, value, m_storageType, frame->document()->securityOrigin(), frame); + return oldValue; } -void StorageAreaProxy::removeItem(const String& key, Frame* frame) +String StorageAreaProxy::removeItem(const String& key, Frame* frame) { - m_storageArea->removeItem(key, frame->document()->url()); + WebKit::WebString oldValue; + m_storageArea->removeItem(key, frame->document()->url(), oldValue); + if (!oldValue.isNull()) + storageEvent(key, oldValue, String(), m_storageType, frame->document()->securityOrigin(), frame); + return oldValue; } -void StorageAreaProxy::clear(Frame* frame) +bool StorageAreaProxy::clear(Frame* frame) { - m_storageArea->clear(frame->document()->url()); + bool clearedSomething; + m_storageArea->clear(frame->document()->url(), clearedSomething); + if (clearedSomething) + storageEvent(String(), String(), String(), m_storageType, frame->document()->securityOrigin(), frame); + return clearedSomething; } bool StorageAreaProxy::contains(const String& key) const @@ -86,6 +106,41 @@ bool StorageAreaProxy::contains(const String& key) const return !getItem(key).isNull(); } +// Copied from WebCore/storage/StorageEventDispatcher.cpp out of necessity. It's probably best to keep it current. +void StorageAreaProxy::storageEvent(const String& key, const String& oldValue, const String& newValue, StorageType storageType, SecurityOrigin* securityOrigin, Frame* sourceFrame) +{ + Page* page = sourceFrame->page(); + if (!page) + return; + + // We need to copy all relevant frames from every page to a vector since sending the event to one frame might mutate the frame tree + // of any given page in the group or mutate the page group itself. + Vector<RefPtr<Frame> > frames; + if (storageType == SessionStorage) { + // Send events only to our page. + for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext()) { + if (sourceFrame != frame && frame->document()->securityOrigin()->equal(securityOrigin)) + frames.append(frame); + } + + for (unsigned i = 0; i < frames.size(); ++i) + frames[i]->document()->enqueueStorageEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, sourceFrame->document()->url(), frames[i]->domWindow()->sessionStorage())); + } else { + // Send events to every page. + const HashSet<Page*>& pages = page->group().pages(); + HashSet<Page*>::const_iterator end = pages.end(); + for (HashSet<Page*>::const_iterator it = pages.begin(); it != end; ++it) { + for (Frame* frame = (*it)->mainFrame(); frame; frame = frame->tree()->traverseNext()) { + if (sourceFrame != frame && frame->document()->securityOrigin()->equal(securityOrigin)) + frames.append(frame); + } + } + + for (unsigned i = 0; i < frames.size(); ++i) + frames[i]->document()->enqueueStorageEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, sourceFrame->document()->url(), frames[i]->domWindow()->localStorage())); + } +} + } // namespace WebCore #endif // ENABLE(DOM_STORAGE) diff --git a/WebKit/chromium/src/StorageAreaProxy.h b/WebKit/chromium/src/StorageAreaProxy.h index 5d09d82..b169828 100644 --- a/WebKit/chromium/src/StorageAreaProxy.h +++ b/WebKit/chromium/src/StorageAreaProxy.h @@ -34,22 +34,28 @@ namespace WebKit { class WebStorageArea; } namespace WebCore { +class Frame; +class SecurityOrigin; + class StorageAreaProxy : public StorageArea { public: - StorageAreaProxy(WebKit::WebStorageArea* storageArea); + StorageAreaProxy(WebKit::WebStorageArea*, StorageType); virtual ~StorageAreaProxy(); // The HTML5 DOM Storage API virtual unsigned length() const; virtual String key(unsigned index) const; virtual String getItem(const String& key) const; - virtual void setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame); - virtual void removeItem(const String& key, Frame* sourceFrame); - virtual void clear(Frame* sourceFrame); + virtual String setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame); + virtual String removeItem(const String& key, Frame* sourceFrame); + virtual bool clear(Frame* sourceFrame); virtual bool contains(const String& key) const; private: + void storageEvent(const String& key, const String& oldValue, const String& newValue, StorageType, SecurityOrigin*, Frame* sourceFrame); + OwnPtr<WebKit::WebStorageArea> m_storageArea; + StorageType m_storageType; }; } // namespace WebCore diff --git a/WebKit/chromium/src/StorageNamespaceProxy.cpp b/WebKit/chromium/src/StorageNamespaceProxy.cpp index e22bbef..1be1967 100644 --- a/WebKit/chromium/src/StorageNamespaceProxy.cpp +++ b/WebKit/chromium/src/StorageNamespaceProxy.cpp @@ -28,27 +28,35 @@ #if ENABLE(DOM_STORAGE) +#include "Chrome.h" +#include "ChromeClientImpl.h" +#include "Page.h" #include "SecurityOrigin.h" #include "StorageAreaProxy.h" #include "WebKit.h" #include "WebKitClient.h" #include "WebStorageNamespace.h" #include "WebString.h" +#include "WebViewClient.h" +#include "WebViewImpl.h" namespace WebCore { PassRefPtr<StorageNamespace> StorageNamespace::localStorageNamespace(const String& path, unsigned quota) { - return new StorageNamespaceProxy(WebKit::webKitClient()->createLocalStorageNamespace(path, quota)); + return adoptRef(new StorageNamespaceProxy(WebKit::webKitClient()->createLocalStorageNamespace(path, quota), LocalStorage)); } -PassRefPtr<StorageNamespace> StorageNamespace::sessionStorageNamespace() +PassRefPtr<StorageNamespace> StorageNamespace::sessionStorageNamespace(Page* page) { - return new StorageNamespaceProxy(WebKit::webKitClient()->createSessionStorageNamespace()); + WebKit::ChromeClientImpl* chromeClientImpl = static_cast<WebKit::ChromeClientImpl*>(page->chrome()->client()); + WebKit::WebViewClient* webViewClient = chromeClientImpl->webView()->client(); + return adoptRef(new StorageNamespaceProxy(webViewClient->createSessionStorageNamespace(), SessionStorage)); } -StorageNamespaceProxy::StorageNamespaceProxy(WebKit::WebStorageNamespace* storageNamespace) +StorageNamespaceProxy::StorageNamespaceProxy(WebKit::WebStorageNamespace* storageNamespace, StorageType storageType) : m_storageNamespace(storageNamespace) + , m_storageType(storageType) { } @@ -58,12 +66,19 @@ StorageNamespaceProxy::~StorageNamespaceProxy() PassRefPtr<StorageNamespace> StorageNamespaceProxy::copy() { - return adoptRef(new StorageNamespaceProxy(m_storageNamespace->copy())); + ASSERT(m_storageType == SessionStorage); + // The WebViewClient knows what its session storage namespace id is but we + // do not. Returning 0 here causes it to be fetched (via the WebViewClient) + // on its next use. Note that it is WebViewClient::createView's + // responsibility to clone the session storage namespace id and that the + // only time copy() is called is directly after the createView call...which + // is why all of this is safe. + return 0; } PassRefPtr<StorageArea> StorageNamespaceProxy::storageArea(PassRefPtr<SecurityOrigin> origin) { - return adoptRef(new StorageAreaProxy(m_storageNamespace->createStorageArea(origin->toString()))); + return adoptRef(new StorageAreaProxy(m_storageNamespace->createStorageArea(origin->toString()), m_storageType)); } void StorageNamespaceProxy::close() diff --git a/WebKit/chromium/src/StorageNamespaceProxy.h b/WebKit/chromium/src/StorageNamespaceProxy.h index 9ff624b..28d7a23 100644 --- a/WebKit/chromium/src/StorageNamespaceProxy.h +++ b/WebKit/chromium/src/StorageNamespaceProxy.h @@ -28,6 +28,7 @@ #if ENABLE(DOM_STORAGE) +#include "StorageArea.h" #include "StorageNamespace.h" namespace WebKit { class WebStorageNamespace; } @@ -36,7 +37,7 @@ namespace WebCore { class StorageNamespaceProxy : public StorageNamespace { public: - StorageNamespaceProxy(WebKit::WebStorageNamespace* storageNamespace); + StorageNamespaceProxy(WebKit::WebStorageNamespace*, StorageType); virtual ~StorageNamespaceProxy(); virtual PassRefPtr<StorageArea> storageArea(PassRefPtr<SecurityOrigin>); virtual PassRefPtr<StorageNamespace> copy(); @@ -45,6 +46,7 @@ public: private: OwnPtr<WebKit::WebStorageNamespace> m_storageNamespace; + StorageType m_storageType; }; } // namespace WebCore diff --git a/WebKit/chromium/src/WebAccessibilityObject.cpp b/WebKit/chromium/src/WebAccessibilityObject.cpp index bdbd260..c386d44 100644 --- a/WebKit/chromium/src/WebAccessibilityObject.cpp +++ b/WebKit/chromium/src/WebAccessibilityObject.cpp @@ -231,13 +231,13 @@ bool WebAccessibilityObject::isIndeterminate() const return m_private->isIndeterminate(); } -bool WebAccessibilityObject::isMultiSelect() const +bool WebAccessibilityObject::isMultiSelectable() const { if (!m_private) return 0; m_private->updateBackingStore(); - return m_private->isMultiSelect(); + return m_private->isMultiSelectable(); } bool WebAccessibilityObject::isOffScreen() const diff --git a/WebKit/chromium/src/WebAnimationControllerImpl.cpp b/WebKit/chromium/src/WebAnimationControllerImpl.cpp new file mode 100644 index 0000000..32a7a61 --- /dev/null +++ b/WebKit/chromium/src/WebAnimationControllerImpl.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebAnimationControllerImpl.h" + +#include "AnimationController.h" +#include "Element.h" + +#include "WebElement.h" +#include "WebFrameImpl.h" +#include "WebString.h" + +using namespace WebCore; + +namespace WebKit { + +WebAnimationControllerImpl::WebAnimationControllerImpl(WebFrameImpl* frameImpl) + : m_frameImpl(frameImpl) +{ + ASSERT(m_frameImpl); +} + +AnimationController* WebAnimationControllerImpl::animationController() const +{ + if (!m_frameImpl->frame()) + return 0; + return m_frameImpl->frame()->animation(); +} + +bool WebAnimationControllerImpl::pauseAnimationAtTime(WebElement& element, + const WebString& animationName, + double time) +{ + AnimationController* controller = animationController(); + if (!controller) + return 0; + return controller->pauseAnimationAtTime(PassRefPtr<Element>(element)->renderer(), + animationName, + time); +} + +bool WebAnimationControllerImpl::pauseTransitionAtTime(WebElement& element, + const WebString& propertyName, + double time) +{ + AnimationController* controller = animationController(); + if (!controller) + return 0; + return controller->pauseTransitionAtTime(PassRefPtr<Element>(element)->renderer(), + propertyName, + time); +} + +unsigned WebAnimationControllerImpl::numberOfActiveAnimations() const +{ + AnimationController* controller = animationController(); + if (!controller) + return 0; + return controller->numberOfActiveAnimations(); +} + +} // namespace WebKit diff --git a/WebKit/chromium/src/WebAnimationControllerImpl.h b/WebKit/chromium/src/WebAnimationControllerImpl.h new file mode 100644 index 0000000..8b0676e --- /dev/null +++ b/WebKit/chromium/src/WebAnimationControllerImpl.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebAnimationControllerImpl_h +#define WebAnimationControllerImpl_h + +// FIXME: This relative path is a temporary hack to support using this +// header from webkit/glue. +#include "../public/WebAnimationController.h" + +namespace WebCore { +class AnimationController; +} + +namespace WebKit { +class WebFrameImpl; + +class WebAnimationControllerImpl : public WebAnimationController { +public: + explicit WebAnimationControllerImpl(WebFrameImpl*); + virtual ~WebAnimationControllerImpl() { } + + virtual bool pauseAnimationAtTime(WebElement&, + const WebString& animationName, + double time); + virtual bool pauseTransitionAtTime(WebElement&, + const WebString& propertyName, + double time); + virtual unsigned numberOfActiveAnimations() const; +private: + WebFrameImpl* m_frameImpl; + WebCore::AnimationController* animationController() const; +}; + +} // namespace WebKit + +#endif diff --git a/WebKit/chromium/src/WebBindings.cpp b/WebKit/chromium/src/WebBindings.cpp index 0bc67b6..04f2f85 100644 --- a/WebKit/chromium/src/WebBindings.cpp +++ b/WebKit/chromium/src/WebBindings.cpp @@ -44,9 +44,12 @@ #include "MouseEvent.h" #include "NPV8Object.h" // for PrivateIdentifier #include "Range.h" +#include "V8BindingState.h" #include "V8DOMWrapper.h" +#include "V8Event.h" #include "V8Helpers.h" #include "V8Proxy.h" +#include "V8Range.h" #elif USE(JSC) #include "bridge/c/c_utility.h" #endif @@ -223,20 +226,20 @@ static bool getDragDataImpl(NPObject* npobj, int* eventId, WebDragData* data) // Get the current WebCore event. v8::Handle<v8::Value> currentEvent(getEvent(context)); - Event* event = V8DOMWrapper::convertToNativeEvent(currentEvent); + Event* event = V8Event::toNative(v8::Handle<v8::Object>::Cast(currentEvent)); if (!event) return false; // Check that the given npobj is that event. V8NPObject* object = reinterpret_cast<V8NPObject*>(npobj); - Event* given = V8DOMWrapper::convertToNativeEvent(object->v8Object); + Event* given = V8Event::toNative(object->v8Object); if (given != event) return false; // Check the execution frames are same origin. V8Proxy* current = V8Proxy::retrieve(V8Proxy::retrieveFrameForCurrentContext()); Frame* frame = V8Proxy::retrieveFrame(context); - if (!current || !current->canAccessFrame(frame, false)) + if (!current || !V8BindingSecurity::canAccessFrame(V8BindingState::Only(), frame, false)) return false; const EventNames& names(eventNames()); @@ -284,7 +287,7 @@ static bool getRangeImpl(NPObject* npobj, WebRange* range) if (V8ClassIndex::RANGE != V8DOMWrapper::domWrapperType(v8object)) return false; - Range* native = V8DOMWrapper::convertToNativeObject<WebCore::Range>(V8ClassIndex::RANGE, v8object); + Range* native = V8Range::toNative(v8object); if (!native) return false; diff --git a/WebKit/chromium/src/WebDataSourceImpl.cpp b/WebKit/chromium/src/WebDataSourceImpl.cpp index 456706a..5a315cf 100644 --- a/WebKit/chromium/src/WebDataSourceImpl.cpp +++ b/WebKit/chromium/src/WebDataSourceImpl.cpp @@ -31,6 +31,7 @@ #include "config.h" #include "WebDataSourceImpl.h" +#include "ApplicationCacheHostInternal.h" #include "WebURL.h" #include "WebURLError.h" #include "WebVector.h" @@ -108,6 +109,14 @@ void WebDataSourceImpl::setExtraData(ExtraData* extraData) m_extraData.set(extraData); } +WebApplicationCacheHost* WebDataSourceImpl::applicationCacheHost() { +#if ENABLE(OFFLINE_WEB_APPLICATIONS) + return ApplicationCacheHostInternal::toWebApplicationCacheHost(DocumentLoader::applicationCacheHost()); +#else + return 0; +#endif +} + WebNavigationType WebDataSourceImpl::toWebNavigationType(NavigationType type) { switch (type) { diff --git a/WebKit/chromium/src/WebDataSourceImpl.h b/WebKit/chromium/src/WebDataSourceImpl.h index 8860fe4..f868e95 100644 --- a/WebKit/chromium/src/WebDataSourceImpl.h +++ b/WebKit/chromium/src/WebDataSourceImpl.h @@ -46,7 +46,6 @@ #include <wtf/PassOwnPtr.h> #include <wtf/Vector.h> - namespace WebKit { class WebPluginLoadObserver; @@ -73,6 +72,7 @@ public: virtual double triggeringEventTime() const; virtual ExtraData* extraData() const; virtual void setExtraData(ExtraData*); + virtual WebApplicationCacheHost* applicationCacheHost(); static WebNavigationType toWebNavigationType(WebCore::NavigationType type); diff --git a/WebKit/chromium/src/WebDocument.cpp b/WebKit/chromium/src/WebDocument.cpp new file mode 100644 index 0000000..84f3004 --- /dev/null +++ b/WebKit/chromium/src/WebDocument.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebDocument.h" + +#include "Document.h" +#include "DocumentLoader.h" +#include "Element.h" +#include "HTMLAllCollection.h" +#include "HTMLBodyElement.h" +#include "HTMLCollection.h" +#include "HTMLElement.h" +#include "HTMLHeadElement.h" +#include "NodeList.h" + +#include "WebElement.h" +#include "WebFrameImpl.h" +#include "WebNodeCollection.h" +#include "WebURL.h" + +#include <wtf/PassRefPtr.h> + +using namespace WebCore; + +namespace WebKit { + +WebDocument::WebDocument(const PassRefPtr<Document>& elem) + : WebNode(elem.releaseRef()) +{ +} + +WebDocument& WebDocument::operator=(const PassRefPtr<Document>& elem) +{ + WebNode::assign(elem.releaseRef()); + return *this; +} + +WebDocument::operator PassRefPtr<Document>() const +{ + return PassRefPtr<Document>(static_cast<Document*>(m_private)); +} + +WebFrame* WebDocument::frame() const +{ + return WebFrameImpl::fromFrame(constUnwrap<Document>()->frame()); +} + +bool WebDocument::isHTMLDocument() const +{ + return constUnwrap<Document>()->isHTMLDocument(); +} + +WebURL WebDocument::baseURL() const +{ + return constUnwrap<Document>()->baseURL(); +} + +WebElement WebDocument::documentElement() const +{ + return WebElement(constUnwrap<Document>()->documentElement()); +} + +WebElement WebDocument::body() const +{ + return WebElement(constUnwrap<Document>()->body()); +} + +WebElement WebDocument::head() +{ + return WebElement(unwrap<Document>()->head()); +} + +WebNodeCollection WebDocument::all() +{ + return WebNodeCollection(unwrap<Document>()->all()); +} + +WebURL WebDocument::completeURL(const WebString& partialURL) const +{ + return constUnwrap<Document>()->completeURL(partialURL); +} + +WebElement WebDocument::getElementById(const WebString& id) const +{ + return WebElement(constUnwrap<Document>()->getElementById(id)); +} + +WebString WebDocument::applicationID() const +{ + const char* kChromeApplicationHeader = "x-chrome-application"; + + // First check if the document's response included a header indicating the + // application it should go with. + const Document* document = constUnwrap<Document>(); + Frame* frame = document->frame(); + if (!frame) + return WebString(); + + DocumentLoader* loader = frame->loader()->documentLoader(); + if (!loader) + return WebString(); + + WebString headerValue = + loader->response().httpHeaderField(kChromeApplicationHeader); + if (!headerValue.isEmpty()) + return headerValue; + + // Otherwise, fall back to looking for the meta tag. + RefPtr<NodeList> metaTags = + const_cast<Document*>(document)->getElementsByTagName("meta"); + for (unsigned i = 0; i < metaTags->length(); ++i) { + Element* element = static_cast<Element*>(metaTags->item(i)); + if (element->getAttribute("http-equiv").lower() == + kChromeApplicationHeader) { + return element->getAttribute("value"); + } + } + + return WebString(); +} + +} // namespace WebKit diff --git a/WebKit/chromium/src/WebDragData.cpp b/WebKit/chromium/src/WebDragData.cpp index 4af1119..3bd4a02 100644 --- a/WebKit/chromium/src/WebDragData.cpp +++ b/WebKit/chromium/src/WebDragData.cpp @@ -88,6 +88,18 @@ void WebDragData::setURLTitle(const WebString& urlTitle) m_private->urlTitle = urlTitle; } +WebURL WebDragData::downloadURL() const +{ + ASSERT(!isNull()); + return m_private->downloadURL; +} + +void WebDragData::setDownloadURL(const WebURL& downloadURL) +{ + ensureMutable(); + m_private->downloadURL = downloadURL; +} + WebString WebDragData::fileExtension() const { ASSERT(!isNull()); diff --git a/WebKit/chromium/src/WebElement.cpp b/WebKit/chromium/src/WebElement.cpp index 3f13ee1..d0a0862 100644 --- a/WebKit/chromium/src/WebElement.cpp +++ b/WebKit/chromium/src/WebElement.cpp @@ -54,5 +54,38 @@ WebElement::operator WTF::PassRefPtr<Element>() const return PassRefPtr<Element>(static_cast<Element*>(m_private)); } +WebString WebElement::tagName() const +{ + return constUnwrap<Element>()->tagName(); +} + +bool WebElement::hasTagName(const WebString& tagName) const +{ + return equalIgnoringCase(constUnwrap<Element>()->tagName(), + tagName.operator WebCore::String()); +} + +bool WebElement::hasAttribute(const WebString& attrName) const +{ + return constUnwrap<Element>()->hasAttribute(attrName); +} + +WebString WebElement::getAttribute(const WebString& attrName) const +{ + return constUnwrap<Element>()->getAttribute(attrName); +} + +bool WebElement::setAttribute(const WebString& attrName, const WebString& attrValue) +{ + ExceptionCode exceptionCode = 0; + unwrap<Element>()->setAttribute(attrName, attrValue, exceptionCode); + return !exceptionCode; +} + +WebString WebElement::innerText() const +{ + return constUnwrap<Element>()->innerText(); +} + } // namespace WebKit diff --git a/WebKit/chromium/src/WebEntities.cpp b/WebKit/chromium/src/WebEntities.cpp new file mode 100644 index 0000000..b9143d9 --- /dev/null +++ b/WebKit/chromium/src/WebEntities.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebEntities.h" + +#include <string.h> + +#include "PlatformString.h" +#include "StringBuilder.h" +#include <wtf/HashMap.h> + +#include "WebString.h" + +using namespace WebCore; + +namespace { +// Note that this file is also included by HTMLTokenizer.cpp so we are getting +// two copies of the data in memory. We can fix this by changing the script +// that generated the array to create a static const that is its length, but +// this is low priority since the data is less than 4K. We use anonymous +// namespace to prevent name collisions. +#include "HTMLEntityNames.c" // NOLINT +} + +namespace WebKit { + +void populateMap(WTF::HashMap<int, WebCore::String>& map, + const Entity* entities, + size_t entitiesCount, + bool standardHTML) +{ + ASSERT(map.isEmpty()); + const Entity* entity = &entities[0]; + for (size_t i = 0; i < entitiesCount; i++, entity++) { + int code = entity->code; + String name = entity->name; + // For consistency, use the lowe case for entities that have both. + if (map.contains(code) && map.get(code) == name.lower()) + continue; + // Don't register %, ⊅ and &supl;. + if (standardHTML && (code == '%' || code == 0x2285 || code == 0x00b9)) + continue; + map.set(code, name); + } + if (standardHTML) + map.set(static_cast<int>(0x0027), String("#39")); +} + +static const Entity xmlBuiltInEntityCodes[] = { + { "lt", 0x003c }, + { "gt", 0x003e }, + { "amp", 0x0026 }, + { "apos", 0x0027 }, + { "quot", 0x0022 } +}; + +WebEntities::WebEntities(bool xmlEntities) +{ + if (xmlEntities) + populateMap(m_entitiesMap, + xmlBuiltInEntityCodes, + sizeof(xmlBuiltInEntityCodes) / sizeof(Entity), + false); + else + populateMap(m_entitiesMap, + wordlist, + sizeof(wordlist) / sizeof(Entity), + true); +} + +String WebEntities::entityNameByCode(int code) const +{ + if (m_entitiesMap.contains(code)) + return m_entitiesMap.get(code); + return ""; +} + +String WebEntities::convertEntitiesInString(const String& value) const +{ + unsigned len = value.length(); + const UChar* startPos = value.characters(); + const UChar* curPos = startPos; + + // FIXME: Optimize - create StringBuilder only if value has any entities. + StringBuilder result; + while (len--) { + if (m_entitiesMap.contains(*curPos)) { + // Append content before entity code. + if (curPos > startPos) + result.append(String(startPos, curPos - startPos)); + result.append("&"); + result.append(m_entitiesMap.get(*curPos)); + result.append(";"); + startPos = ++curPos; + } else + curPos++; + } + // Append the remaining content. + if (curPos > startPos) + result.append(String(startPos, curPos - startPos)); + + return result.toString(); +} + +} // namespace WebKit diff --git a/WebKit/chromium/src/WebEntities.h b/WebKit/chromium/src/WebEntities.h new file mode 100644 index 0000000..ad3c310 --- /dev/null +++ b/WebKit/chromium/src/WebEntities.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebEntities_h +#define WebEntities_h + +#include "PlatformString.h" +#include <wtf/HashMap.h> + +namespace WebKit { + +class WebEntities { +public: + // ', %, ⊅, &supl; are not defined by the HTML standards. + // - IE does not support ' as an HTML entity (but support it as an XML + // entity.) + // - Firefox supports ' as an HTML entity. + // - Both of IE and Firefox don't support %, ⊅ and &supl;. + // + // A web page saved by Chromium should be able to be read by other browsers + // such as IE and Firefox. Chromium should produce only the standard entity + // references which other browsers can recognize. + // So if standard_html_entities_ is true, we will use a numeric character + // reference for ', and don't use entity references for %, ⊅ + // and &supl; for serialization. + // + // If xmlEntities is true, WebEntities will only contain standard XML + // entities. + explicit WebEntities(bool xmlEntities); + + // Check whether specified unicode has corresponding html or xml built-in + // entity name. If yes, return the entity notation. If not, returns an + // empty string. Parameter isHTML indicates check the code in html entity + // map or in xml entity map. + WebCore::String entityNameByCode(int code) const; + + // Returns a new string with corresponding entity names replaced. + WebCore::String convertEntitiesInString(const WebCore::String&) const; +private: + typedef HashMap<int, WebCore::String> EntitiesMapType; + // An internal object that maps the Unicode character to corresponding + // entity notation. + EntitiesMapType m_entitiesMap; +}; + +} // namespace WebKit + +#endif diff --git a/WebKit/chromium/src/WebEvent.cpp b/WebKit/chromium/src/WebEvent.cpp new file mode 100644 index 0000000..8c68959 --- /dev/null +++ b/WebKit/chromium/src/WebEvent.cpp @@ -0,0 +1,219 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebEvent.h" + +#include "Event.h" +#include "Node.h" +#include <wtf/PassRefPtr.h> + +namespace WebKit { + +class WebEventPrivate : public WebCore::Event { +}; + +void WebEvent::reset() +{ + assign(0); +} + +void WebEvent::assign(const WebEvent& other) +{ + WebEventPrivate* p = const_cast<WebEventPrivate*>(other.m_private); + if (p) + p->ref(); + assign(p); +} + +void WebEvent::assign(WebEventPrivate* p) +{ + // p is already ref'd for us by the caller + if (m_private) + m_private->deref(); + m_private = p; +} + +WebEvent::WebEvent(const WTF::PassRefPtr<WebCore::Event>& event) + : m_private(static_cast<WebEventPrivate*>(event.releaseRef())) +{ +} + +WebString WebEvent::type() const +{ + ASSERT(m_private); + return m_private->type(); +} + +WebNode WebEvent::target() const +{ + ASSERT(m_private); + return WebNode(m_private->target()->toNode()); +} + +WebNode WebEvent::currentTarget() const +{ + ASSERT(m_private); + return WebNode(m_private->currentTarget()->toNode()); +} + +WebEvent::PhaseType WebEvent::eventPhase() const +{ + ASSERT(m_private); + return static_cast<WebEvent::PhaseType>(m_private->eventPhase()); +} + +bool WebEvent::bubbles() const +{ + ASSERT(m_private); + return m_private->bubbles(); +} + +bool WebEvent::cancelable() const +{ + ASSERT(m_private); + return m_private->cancelable(); +} + +bool WebEvent::isUIEvent() const +{ + ASSERT(m_private); + return m_private->isUIEvent(); +} + +bool WebEvent::isMouseEvent() const +{ + ASSERT(m_private); + return m_private->isMouseEvent(); +} + +bool WebEvent::isMutationEvent() const +{ + ASSERT(m_private); + return m_private->isMutationEvent(); +} + +bool WebEvent::isKeyboardEvent() const +{ + ASSERT(m_private); + return m_private->isKeyboardEvent(); +} + +bool WebEvent::isTextEvent() const +{ + ASSERT(m_private); + return m_private->isTextEvent(); +} + +bool WebEvent::isCompositionEvent() const +{ + ASSERT(m_private); + return m_private->isCompositionEvent(); +} + +bool WebEvent::isDragEvent() const +{ + ASSERT(m_private); + return m_private->isDragEvent(); +} + +bool WebEvent::isClipboardEvent() const +{ + ASSERT(m_private); + return m_private->isClipboardEvent(); +} + +bool WebEvent::isMessageEvent() const +{ + ASSERT(m_private); + return m_private->isMessageEvent(); +} + +bool WebEvent::isWheelEvent() const +{ + ASSERT(m_private); + return m_private->isWheelEvent(); +} + +bool WebEvent::isBeforeTextInsertedEvent() const +{ + ASSERT(m_private); + return m_private->isBeforeTextInsertedEvent(); +} + +bool WebEvent::isOverflowEvent() const +{ + ASSERT(m_private); + return m_private->isOverflowEvent(); +} + +bool WebEvent::isPageTransitionEvent() const +{ + ASSERT(m_private); + return m_private->isPageTransitionEvent(); +} + +bool WebEvent::isPopStateEvent() const +{ + ASSERT(m_private); + return m_private->isPopStateEvent(); +} + +bool WebEvent::isProgressEvent() const +{ + ASSERT(m_private); + return m_private->isProgressEvent(); +} + +bool WebEvent::isXMLHttpRequestProgressEvent() const +{ + ASSERT(m_private); + return m_private->isXMLHttpRequestProgressEvent(); +} + +bool WebEvent::isWebKitAnimationEvent() const +{ + ASSERT(m_private); + return m_private->isWebKitAnimationEvent(); +} + +bool WebEvent::isWebKitTransitionEvent() const +{ + ASSERT(m_private); + return m_private->isWebKitTransitionEvent(); +} + +bool WebEvent::isBeforeLoadEvent() const +{ + ASSERT(m_private); + return m_private->isBeforeLoadEvent(); +} + +} // namespace WebKit diff --git a/WebKit/chromium/src/WebEventListener.cpp b/WebKit/chromium/src/WebEventListener.cpp new file mode 100644 index 0000000..8d9a887 --- /dev/null +++ b/WebKit/chromium/src/WebEventListener.cpp @@ -0,0 +1,64 @@ +/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebEventListener.h"
+
+#include "WebEventListenerPrivate.h"
+
+namespace WebKit {
+
+WebEventListener::WebEventListener()
+ : m_private(new WebEventListenerPrivate(this))
+{
+}
+
+WebEventListener::~WebEventListener()
+{
+ m_private->webEventListenerDeleted();
+ delete m_private;
+}
+
+void WebEventListener::notifyEventListenerDeleted(EventListenerWrapper* wrapper)
+{
+ m_private->eventListenerDeleted(wrapper);
+}
+
+EventListenerWrapper* WebEventListener::createEventListenerWrapper(const WebString& eventType, bool useCapture, Node* node)
+{
+ return m_private->createEventListenerWrapper(eventType, useCapture, node);
+}
+
+EventListenerWrapper* WebEventListener::getEventListenerWrapper(const WebString& eventType, bool useCapture, Node* node)
+{
+ return m_private->getEventListenerWrapper(eventType, useCapture, node);
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/WebEventListenerPrivate.cpp b/WebKit/chromium/src/WebEventListenerPrivate.cpp new file mode 100644 index 0000000..bd14baf --- /dev/null +++ b/WebKit/chromium/src/WebEventListenerPrivate.cpp @@ -0,0 +1,87 @@ +/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebEventListenerPrivate.h"
+
+#include "EventListenerWrapper.h"
+#include "WebEventListener.h"
+
+namespace WebKit {
+
+WebEventListenerPrivate::WebEventListenerPrivate(WebEventListener* webEventListener)
+ : m_webEventListener(webEventListener)
+{
+}
+
+WebEventListenerPrivate::~WebEventListenerPrivate()
+{
+}
+
+EventListenerWrapper* WebEventListenerPrivate::createEventListenerWrapper(const WebString& eventType, bool useCapture, Node* node)
+{
+ EventListenerWrapper* listenerWrapper = new EventListenerWrapper(m_webEventListener);
+ WebEventListenerPrivate::ListenerInfo listenerInfo(eventType, useCapture, listenerWrapper, node);
+ m_listenerWrappers.append(listenerInfo);
+ return listenerWrapper;
+}
+
+EventListenerWrapper* WebEventListenerPrivate::getEventListenerWrapper(const WebString& eventType, bool useCapture, Node* node)
+{
+ Vector<WebEventListenerPrivate::ListenerInfo>::const_iterator iter;
+ for (iter = m_listenerWrappers.begin(); iter != m_listenerWrappers.end(); ++iter) {
+ if (iter->node == node)
+ return iter->eventListenerWrapper;
+ }
+ ASSERT_NOT_REACHED();
+ return 0;
+}
+
+void WebEventListenerPrivate::webEventListenerDeleted()
+{
+ // Notifies all WebEventListenerWrappers that we are going away so they can
+ // invalidate their pointer to us.
+ Vector<WebEventListenerPrivate::ListenerInfo>::const_iterator iter;
+ for (iter = m_listenerWrappers.begin(); iter != m_listenerWrappers.end(); ++iter)
+ iter->eventListenerWrapper->webEventListenerDeleted();
+}
+
+void WebEventListenerPrivate::eventListenerDeleted(EventListenerWrapper* eventListener)
+{
+ for (size_t i = 0; i < m_listenerWrappers.size(); ++i) {
+ if (m_listenerWrappers[i].eventListenerWrapper == eventListener) {
+ m_listenerWrappers.remove(i);
+ return;
+ }
+ }
+ ASSERT_NOT_REACHED();
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/WebEventListenerPrivate.h b/WebKit/chromium/src/WebEventListenerPrivate.h new file mode 100644 index 0000000..0ba2b5d --- /dev/null +++ b/WebKit/chromium/src/WebEventListenerPrivate.h @@ -0,0 +1,95 @@ +/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebEventListenerPrivate_h
+#define WebEventListenerPrivate_h
+
+#include "WebString.h"
+
+#include <wtf/Vector.h>
+
+namespace WebCore {
+class Node;
+}
+
+using namespace WebCore;
+
+namespace WebKit {
+
+class EventListenerWrapper;
+class WebEventListener;
+
+class WebEventListenerPrivate {
+public:
+ WebEventListenerPrivate(WebEventListener* webEventListener);
+ ~WebEventListenerPrivate();
+
+ EventListenerWrapper* createEventListenerWrapper(
+ const WebString& eventType, bool useCapture, Node* node);
+
+ // Gets the ListenerEventWrapper for a specific node.
+ // Used by WebNode::removeEventListener().
+ EventListenerWrapper* getEventListenerWrapper(
+ const WebString& eventType, bool useCapture, Node* node);
+
+ // Called by the WebEventListener when it is about to be deleted.
+ void webEventListenerDeleted();
+
+ // Called by the EventListenerWrapper when it is about to be deleted.
+ void eventListenerDeleted(EventListenerWrapper* eventListener);
+
+ struct ListenerInfo {
+ ListenerInfo(const WebString& eventType, bool useCapture,
+ EventListenerWrapper* eventListenerWrapper,
+ Node* node)
+ : eventType(eventType)
+ , useCapture(useCapture)
+ , eventListenerWrapper(eventListenerWrapper)
+ , node(node)
+ {
+ }
+
+ WebString eventType;
+ bool useCapture;
+ EventListenerWrapper* eventListenerWrapper;
+ Node* node;
+ };
+
+private:
+ WebEventListener* m_webEventListener;
+
+ // We keep a list of the wrapper for the WebKit EventListener, it is needed
+ // to implement WebNode::removeEventListener().
+ Vector<ListenerInfo> m_listenerWrappers;
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/WebKit/chromium/src/WebFrameImpl.cpp b/WebKit/chromium/src/WebFrameImpl.cpp index ab6769f..28c27cc 100644 --- a/WebKit/chromium/src/WebFrameImpl.cpp +++ b/WebKit/chromium/src/WebFrameImpl.cpp @@ -84,7 +84,6 @@ #include "Editor.h" #include "EventHandler.h" #include "FormState.h" -#include "FrameChromium.h" #include "FrameLoader.h" #include "FrameLoadRequest.h" #include "FrameTree.h" @@ -104,6 +103,7 @@ #include "PlatformContextSkia.h" #include "PrintContext.h" #include "RenderFrame.h" +#include "RenderTreeAsText.h" #include "RenderView.h" #include "RenderWidget.h" #include "ReplaceSelectionCommand.h" @@ -120,8 +120,10 @@ #include "SubstituteData.h" #include "TextAffinity.h" #include "TextIterator.h" +#include "WebAnimationControllerImpl.h" #include "WebConsoleMessage.h" #include "WebDataSourceImpl.h" +#include "WebDocument.h" #include "WebFindOptions.h" #include "WebFormElement.h" #include "WebFrameClient.h" @@ -142,11 +144,11 @@ #include <wtf/CurrentTime.h> -#if PLATFORM(DARWIN) +#if OS(DARWIN) #include "LocalCurrentGraphicsContext.h" #endif -#if PLATFORM(LINUX) +#if OS(LINUX) #include <gdk/gdk.h> #endif @@ -154,6 +156,8 @@ using namespace WebCore; namespace WebKit { +static int frameCount = 0; + // Key for a StatsCounter tracking how many WebFrames are active. static const char* const webFrameActiveCount = "WebFrameActiveCount"; @@ -329,6 +333,11 @@ private: // WebFrame ------------------------------------------------------------------- +int WebFrame::instanceCount() +{ + return frameCount; +} + WebFrame* WebFrame::frameForEnteredContext() { Frame* frame = @@ -343,11 +352,22 @@ WebFrame* WebFrame::frameForCurrentContext() return WebFrameImpl::fromFrame(frame); } +WebFrame* WebFrame::fromFrameOwnerElement(const WebElement& element) +{ + return WebFrameImpl::fromFrameOwnerElement( + PassRefPtr<Element>(element).get()); +} + WebString WebFrameImpl::name() const { return m_frame->tree()->name(); } +void WebFrameImpl::clearName() +{ + m_frame->tree()->clearName(); +} + WebURL WebFrameImpl::url() const { const WebDataSource* ds = dataSource(); @@ -391,6 +411,11 @@ WebURL WebFrameImpl::openSearchDescriptionURL() const return WebURL(); } +WebString WebFrameImpl::encoding() const +{ + return frame()->loader()->encoding(); +} + WebSize WebFrameImpl::scrollOffset() const { FrameView* view = frameView(); @@ -515,6 +540,13 @@ WebFrame* WebFrameImpl::findChildByExpression(const WebString& xpath) const return fromFrame(frameElement->contentFrame()); } +WebDocument WebFrameImpl::document() const +{ + if (!m_frame || !m_frame->document()) + return WebDocument(); + return WebDocument(m_frame->document()); +} + void WebFrameImpl::forms(WebVector<WebFormElement>& results) const { if (!m_frame) @@ -533,6 +565,11 @@ void WebFrameImpl::forms(WebVector<WebFormElement>& results) const results.swap(temp); } +WebAnimationController* WebFrameImpl::animationController() +{ + return &m_animationController; +} + WebSecurityOrigin WebFrameImpl::securityOrigin() const { if (!m_frame || !m_frame->document()) @@ -559,7 +596,7 @@ NPObject* WebFrameImpl::windowObject() const void WebFrameImpl::bindToWindowObject(const WebString& name, NPObject* object) { ASSERT(m_frame); - if (!m_frame || !m_frame->script()->isEnabled()) + if (!m_frame || !m_frame->script()->canExecuteScripts()) return; String key = name; @@ -576,19 +613,6 @@ void WebFrameImpl::executeScript(const WebScriptSource& source) ScriptSourceCode(source.code, source.url, source.startLine)); } -void WebFrameImpl::executeScriptInNewContext( - const WebScriptSource* sourcesIn, unsigned numSources, int extensionGroup) -{ - Vector<ScriptSourceCode> sources; - - for (unsigned i = 0; i < numSources; ++i) { - sources.append(ScriptSourceCode( - sourcesIn[i].code, sourcesIn[i].url, sourcesIn[i].startLine)); - } - - m_frame->script()->evaluateInNewContext(sources, extensionGroup); -} - void WebFrameImpl::executeScriptInIsolatedWorld( int worldId, const WebScriptSource* sourcesIn, unsigned numSources, int extensionGroup) @@ -1037,7 +1061,7 @@ WebString WebFrameImpl::selectionAsText() const return WebString(); String text = range->text(); -#if PLATFORM(WIN_OS) +#if OS(WINDOWS) replaceNewlinesWithWindowsStyleNewlines(text); #endif replaceNBSPWithSpace(text); @@ -1087,10 +1111,10 @@ float WebFrameImpl::printPage(int page, WebCanvas* canvas) return 0; } -#if PLATFORM(WIN_OS) || PLATFORM(LINUX) || PLATFORM(FREEBSD) +#if OS(WINDOWS) || OS(LINUX) || OS(FREEBSD) PlatformContextSkia context(canvas); GraphicsContext spool(&context); -#elif PLATFORM(DARWIN) +#elif OS(DARWIN) GraphicsContext spool(canvas); LocalCurrentGraphicsContext localContext(&spool); #endif @@ -1212,8 +1236,7 @@ void WebFrameImpl::stopFinding(bool clearSelection) cancelPendingScopingEffort(); // Remove all markers for matches found and turn off the highlighting. - if (!parent()) - frame()->document()->removeMarkers(DocumentMarker::TextMatch); + frame()->document()->removeMarkers(DocumentMarker::TextMatch); frame()->setMarkedTextMatchesAreHighlighted(false); // Let the frame know that we don't want tickmarks or highlighting anymore. @@ -1456,9 +1479,24 @@ WebString WebFrameImpl::contentAsMarkup() const return createFullMarkup(m_frame->document()); } -// WebFrameImpl public --------------------------------------------------------- +WebString WebFrameImpl::renderTreeAsText() const +{ + return externalRepresentation(m_frame); +} + +WebString WebFrameImpl::counterValueForElementById(const WebString& id) const +{ + if (!m_frame) + return WebString(); + + Element* element = m_frame->document()->getElementById(id); + if (!element) + return WebString(); -int WebFrameImpl::m_liveObjectCount = 0; + return counterValueForElement(element); +} + +// WebFrameImpl public --------------------------------------------------------- PassRefPtr<WebFrameImpl> WebFrameImpl::create(WebFrameClient* client) { @@ -1477,15 +1515,16 @@ WebFrameImpl::WebFrameImpl(WebFrameClient* client) , m_framesScopingCount(-1) , m_scopingComplete(false) , m_nextInvalidateAfter(0) + , m_animationController(this) { ChromiumBridge::incrementStatsCounter(webFrameActiveCount); - m_liveObjectCount++; + frameCount++; } WebFrameImpl::~WebFrameImpl() { ChromiumBridge::decrementStatsCounter(webFrameActiveCount); - m_liveObjectCount--; + frameCount--; cancelPendingScopingEffort(); clearPasswordListeners(); @@ -1631,6 +1670,19 @@ WebFrameImpl* WebFrameImpl::fromFrame(Frame* frame) return static_cast<FrameLoaderClientImpl*>(frame->loader()->client())->webFrame(); } +WebFrameImpl* WebFrameImpl::fromFrameOwnerElement(Element* element) +{ + if (!element + || !element->isFrameOwnerElement() + || (!element->hasTagName(HTMLNames::iframeTag) + && !element->hasTagName(HTMLNames::frameTag))) + return 0; + + HTMLFrameOwnerElement* frameElement = + static_cast<HTMLFrameOwnerElement*>(element); + return fromFrame(frameElement->contentFrame()); +} + WebViewImpl* WebFrameImpl::viewImpl() const { if (!m_frame) diff --git a/WebKit/chromium/src/WebFrameImpl.h b/WebKit/chromium/src/WebFrameImpl.h index 2cd332a..ba8d279 100644 --- a/WebKit/chromium/src/WebFrameImpl.h +++ b/WebKit/chromium/src/WebFrameImpl.h @@ -39,6 +39,8 @@ #include <wtf/OwnPtr.h> #include <wtf/RefCounted.h> +#include "WebAnimationControllerImpl.h" + namespace WebCore { class HistoryItem; class KURL; @@ -62,9 +64,11 @@ class WebFrameImpl : public WebFrame, public RefCounted<WebFrameImpl> { public: // WebFrame methods: virtual WebString name() const; + virtual void clearName(); virtual WebURL url() const; virtual WebURL favIconURL() const; virtual WebURL openSearchDescriptionURL() const; + virtual WebString encoding() const; virtual WebSize scrollOffset() const; virtual WebSize contentsSize() const; virtual int contentsPreferredWidth() const; @@ -82,14 +86,14 @@ public: virtual WebFrame* traversePrevious(bool wrap) const; virtual WebFrame* findChildByName(const WebString&) const; virtual WebFrame* findChildByExpression(const WebString&) const; + virtual WebDocument document() const; virtual void forms(WebVector<WebFormElement>&) const; + virtual WebAnimationController* animationController(); virtual WebSecurityOrigin securityOrigin() const; virtual void grantUniversalAccess(); virtual NPObject* windowObject() const; virtual void bindToWindowObject(const WebString& name, NPObject*); virtual void executeScript(const WebScriptSource&); - virtual void executeScriptInNewContext( - const WebScriptSource* sources, unsigned numSources, int extensionGroup); virtual void executeScriptInIsolatedWorld( int worldId, const WebScriptSource* sources, unsigned numSources, int extensionGroup); @@ -157,12 +161,12 @@ public: virtual WebURL completeURL(const WebString& url) const; virtual WebString contentAsText(size_t maxChars) const; virtual WebString contentAsMarkup() const; + virtual WebString renderTreeAsText() const; + virtual WebString counterValueForElementById(const WebString& id) const; static PassRefPtr<WebFrameImpl> create(WebFrameClient* client); ~WebFrameImpl(); - static int liveObjectCount() { return m_liveObjectCount; } - // Called by the WebViewImpl to initialize its main frame: void initializeAsMainFrame(WebViewImpl*); @@ -174,6 +178,7 @@ public: void createFrameView(); static WebFrameImpl* fromFrame(WebCore::Frame* frame); + static WebFrameImpl* fromFrameOwnerElement(WebCore::Element* element); WebViewImpl* viewImpl() const; @@ -276,9 +281,6 @@ private: void loadJavaScriptURL(const WebCore::KURL&); - // Used to check for leaks of this object. - static int m_liveObjectCount; - FrameLoaderClientImpl m_frameLoaderClient; WebFrameClient* m_client; @@ -348,6 +350,9 @@ private: typedef HashMap<RefPtr<WebCore::HTMLInputElement>, WebPasswordAutocompleteListener*> PasswordListenerMap; PasswordListenerMap m_passwordListeners; + + // Keeps a reference to the frame's WebAnimationController. + WebAnimationControllerImpl m_animationController; }; } // namespace WebKit diff --git a/WebKit/chromium/src/WebGlyphCache.cpp b/WebKit/chromium/src/WebGlyphCache.cpp new file mode 100644 index 0000000..272c6cd --- /dev/null +++ b/WebKit/chromium/src/WebGlyphCache.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebGlyphCache.h" + +#include "GlyphPageTreeNode.h" + +using namespace WebCore; + +namespace WebKit { + +size_t WebGlyphCache::pageCount() +{ + return GlyphPageTreeNode::treeGlyphPageCount(); +} + +} // namespace WebKit diff --git a/WebKit/chromium/src/WebHistoryItem.cpp b/WebKit/chromium/src/WebHistoryItem.cpp index d4ee50a..4ca8cc7 100644 --- a/WebKit/chromium/src/WebHistoryItem.cpp +++ b/WebKit/chromium/src/WebHistoryItem.cpp @@ -218,6 +218,18 @@ void WebHistoryItem::setDocumentState(const WebVector<WebString>& state) m_private->setDocumentState(ds); } +long long WebHistoryItem::documentSequenceNumber() const +{ + ASSERT(!isNull()); + return m_private->documentSequenceNumber(); +} + +void WebHistoryItem::setDocumentSequenceNumber(long long documentSequenceNumber) +{ + ensureMutable(); + m_private->setDocumentSequenceNumber(documentSequenceNumber); +} + WebString WebHistoryItem::httpContentType() const { ASSERT(!isNull()); diff --git a/WebKit/chromium/src/WebInputElement.cpp b/WebKit/chromium/src/WebInputElement.cpp index d403120..ee799f6 100644 --- a/WebKit/chromium/src/WebInputElement.cpp +++ b/WebKit/chromium/src/WebInputElement.cpp @@ -56,6 +56,11 @@ WebInputElement::operator WTF::PassRefPtr<HTMLInputElement>() const return PassRefPtr<HTMLInputElement>(static_cast<HTMLInputElement*>(m_private)); } +bool WebInputElement::autoComplete() const +{ + return constUnwrap<HTMLInputElement>()->autoComplete(); +} + bool WebInputElement::isEnabledFormControl() const { return constUnwrap<HTMLInputElement>()->isEnabledFormControl(); diff --git a/WebKit/chromium/src/WebKit.cpp b/WebKit/chromium/src/WebKit.cpp index a129f85..a8e1851 100644 --- a/WebKit/chromium/src/WebKit.cpp +++ b/WebKit/chromium/src/WebKit.cpp @@ -33,6 +33,7 @@ #include "AtomicString.h" #include "DOMTimer.h" +#include "Logging.h" #include "Page.h" #include "RuntimeEnabledFeatures.h" #include "TextEncoding.h" @@ -94,6 +95,13 @@ bool layoutTestMode() return s_layoutTestMode; } +void enableLogChannel(const char* name) +{ + WTFLogChannel* channel = WebCore::getChannelFromName(name); + if (channel) + channel->state = WTFLogChannelOn; +} + void resetPluginCache(bool reloadPages) { WebCore::Page::refreshPlugins(reloadPages); diff --git a/WebKit/chromium/src/WebMutationEvent.cpp b/WebKit/chromium/src/WebMutationEvent.cpp new file mode 100644 index 0000000..511b615 --- /dev/null +++ b/WebKit/chromium/src/WebMutationEvent.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebMutationEvent.h" + +#include "MutationEvent.h" + +using namespace WebCore; + +namespace WebKit { + +WebNode WebMutationEvent::relatedNode() const +{ + return WebNode(constUnwrap<MutationEvent>()->relatedNode()); +} + +WebString WebMutationEvent::prevValue() const +{ + return WebString(constUnwrap<MutationEvent>()->prevValue()); +} + +WebString WebMutationEvent::newValue() const +{ + return WebString(constUnwrap<MutationEvent>()->newValue()); +} + +WebString WebMutationEvent::attrName() const +{ + return WebString(constUnwrap<MutationEvent>()->attrName()); +} + +WebMutationEvent::AttrChangeType WebMutationEvent::attrChange() const +{ + return static_cast<AttrChangeType>(constUnwrap<MutationEvent>()->attrChange()); +} + +} // namespace WebKit diff --git a/WebKit/chromium/src/WebNode.cpp b/WebKit/chromium/src/WebNode.cpp index 965c412..9fbf573 100644 --- a/WebKit/chromium/src/WebNode.cpp +++ b/WebKit/chromium/src/WebNode.cpp @@ -35,9 +35,18 @@ #include "Frame.h" #include "FrameLoaderClientImpl.h" #include "Node.h" +#include "NodeList.h" +#include "EventListenerWrapper.h" +#include "WebDocument.h" +#include "WebEvent.h" +#include "WebEventListener.h" #include "WebFrameImpl.h" +#include "WebNodeList.h" #include "WebString.h" +#include "WebVector.h" + +#include "markup.h" #include <wtf/PassRefPtr.h> @@ -61,6 +70,11 @@ void WebNode::assign(const WebNode& other) assign(p); } +WebNode::NodeType WebNode::nodeType() const +{ + return static_cast<NodeType>(m_private->nodeType()); +} + WebNode WebNode::parentNode() const { return PassRefPtr<Node>(const_cast<Node*>(m_private->parentNode())); @@ -71,18 +85,30 @@ WebString WebNode::nodeName() const return m_private->nodeName(); } -WebNode::WebNode(const WTF::PassRefPtr<WebCore::Node>& node) +WebString WebNode::nodeValue() const +{ + return m_private->nodeValue(); +} + +bool WebNode::setNodeValue(const WebString& value) +{ + ExceptionCode exceptionCode = 0; + m_private->setNodeValue(value, exceptionCode); + return !exceptionCode; +} + +WebNode::WebNode(const PassRefPtr<Node>& node) : m_private(static_cast<WebNodePrivate*>(node.releaseRef())) { } -WebNode& WebNode::operator=(const WTF::PassRefPtr<WebCore::Node>& node) +WebNode& WebNode::operator=(const PassRefPtr<Node>& node) { assign(static_cast<WebNodePrivate*>(node.releaseRef())); return *this; } -WebNode::operator WTF::PassRefPtr<WebCore::Node>() const +WebNode::operator PassRefPtr<Node>() const { return PassRefPtr<Node>(const_cast<WebNodePrivate*>(m_private)); } @@ -100,4 +126,72 @@ WebFrame* WebNode::frame() const return WebFrameImpl::fromFrame(m_private->document()->frame()); } +WebDocument WebNode::document() const +{ + return WebDocument(m_private->document()); +} + +WebNode WebNode::firstChild() const +{ + return WebNode(m_private->firstChild()); +} + +WebNode WebNode::lastChild() const +{ + return WebNode(m_private->lastChild()); +} + +WebNode WebNode::previousSibling() const +{ + return WebNode(m_private->previousSibling()); +} + +WebNode WebNode::nextSibling() const +{ + return WebNode(m_private->nextSibling()); +} + +bool WebNode::hasChildNodes() const +{ + return m_private->hasChildNodes(); +} + +WebNodeList WebNode::childNodes() +{ + return WebNodeList(m_private->childNodes()); +} + +WebString WebNode::createMarkup() const +{ + return WebCore::createMarkup(m_private); +} + +bool WebNode::isTextNode() const +{ + return m_private->isTextNode(); +} + +bool WebNode::isElementNode() const +{ + return m_private->isElementNode(); +} + +void WebNode::addEventListener(const WebString& eventType, WebEventListener* listener, bool useCapture) +{ + EventListenerWrapper* listenerWrapper = + listener->createEventListenerWrapper(eventType, useCapture, m_private); + // The listenerWrapper is only referenced by the actual Node. Once it goes + // away, the wrapper notifies the WebEventListener so it can clear its + // pointer to it. + m_private->addEventListener(eventType, adoptRef(listenerWrapper), useCapture); +} + +void WebNode::removeEventListener(const WebString& eventType, WebEventListener* listener, bool useCapture) +{ + EventListenerWrapper* listenerWrapper = + listener->getEventListenerWrapper(eventType, useCapture, m_private); + m_private->removeEventListener(eventType, listenerWrapper, useCapture); + // listenerWrapper is now deleted. +} + } // namespace WebKit diff --git a/WebKit/chromium/src/WebNodeCollection.cpp b/WebKit/chromium/src/WebNodeCollection.cpp new file mode 100644 index 0000000..a9e532f --- /dev/null +++ b/WebKit/chromium/src/WebNodeCollection.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebNodeCollection.h" + +#include "HTMLCollection.h" +#include "Node.h" +#include <wtf/PassRefPtr.h> + +#include "WebNode.h" + +using namespace WebCore; + +namespace WebKit { + +void WebNodeCollection::reset() +{ + assign(0); +} + +void WebNodeCollection::assign(const WebNodeCollection& other) +{ + HTMLCollection* p = const_cast<HTMLCollection*>(other.m_private); + if (p) + p->ref(); + assign(p); +} + +WebNodeCollection::WebNodeCollection(const PassRefPtr<HTMLCollection>& col) + : m_private(static_cast<HTMLCollection*>(col.releaseRef())) +{ +} + +void WebNodeCollection::assign(HTMLCollection* p) +{ + // p is already ref'd for us by the caller + if (m_private) + m_private->deref(); + m_private = p; +} + +unsigned WebNodeCollection::length() const +{ + return m_private->length(); +} + +WebNode WebNodeCollection::nextItem() const +{ + return WebNode(m_private->nextItem()); +} + +WebNode WebNodeCollection::firstItem() const +{ + return WebNode(m_private->firstItem()); +} + +} // namespace WebKit diff --git a/WebKit/chromium/src/WebNodeList.cpp b/WebKit/chromium/src/WebNodeList.cpp new file mode 100644 index 0000000..f68f961 --- /dev/null +++ b/WebKit/chromium/src/WebNodeList.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebNodeList.h" + +#include "Node.h" +#include "NodeList.h" +#include <wtf/PassRefPtr.h> + +#include "WebNode.h" + +using namespace WebCore; + +namespace WebKit { + +void WebNodeList::reset() +{ + assign(0); +} + +void WebNodeList::assign(const WebNodeList& other) +{ + NodeList* p = const_cast<NodeList*>(other.m_private); + if (p) + p->ref(); + assign(p); +} + +WebNodeList::WebNodeList(const PassRefPtr<NodeList>& col) + : m_private(static_cast<NodeList*>(col.releaseRef())) +{ +} + +void WebNodeList::assign(NodeList* p) +{ + // p is already ref'd for us by the caller + if (m_private) + m_private->deref(); + m_private = p; +} + +unsigned WebNodeList::length() const +{ + return m_private->length(); +} + +WebNode WebNodeList::item(size_t index) const +{ + return WebNode(m_private->item(index)); +} + +} // namespace WebKit diff --git a/WebKit/chromium/src/WebPageSerializer.cpp b/WebKit/chromium/src/WebPageSerializer.cpp new file mode 100644 index 0000000..1010285 --- /dev/null +++ b/WebKit/chromium/src/WebPageSerializer.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebPageSerializer.h" + +#include "KURL.h" +#include "PlatformString.h" + +#include "WebFrame.h" +#include "WebPageSerializerClient.h" +#include "WebPageSerializerImpl.h" +#include "WebString.h" +#include "WebURL.h" +#include "WebVector.h" + +using namespace WebCore; + +namespace WebKit { + +bool WebPageSerializer::serialize(WebFrame* frame, + bool recursive, + WebPageSerializerClient* client, + const WebVector<WebURL>& links, + const WebVector<WebString>& localPaths, + const WebString& localDirectoryName) +{ + WebPageSerializerImpl serializerImpl( + frame, recursive, client, links, localPaths, localDirectoryName); + return serializerImpl.serialize(); +} + +WebString WebPageSerializer::generateMetaCharsetDeclaration(const WebString& charset) +{ + return String::format("<META http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">", + charset.utf8().data()); +} + +WebString WebPageSerializer::generateMarkOfTheWebDeclaration(const WebURL& url) +{ + return String::format("\n<!-- saved from url=(%04d)%s -->\n", + static_cast<int>(url.spec().length()), + url.spec().data()); +} + +WebString WebPageSerializer::generateBaseTagDeclaration(const WebString& baseTarget) +{ + String targetDeclaration; + if (!baseTarget.isEmpty()) + targetDeclaration = String::format(" target=\"%s\"", baseTarget.utf8().data()); + return String::format("<BASE href=\".\"%s>", targetDeclaration.utf8().data()); +} + +} // namespace WebKit diff --git a/WebKit/chromium/src/WebPageSerializerImpl.cpp b/WebKit/chromium/src/WebPageSerializerImpl.cpp new file mode 100644 index 0000000..d5b2b7f --- /dev/null +++ b/WebKit/chromium/src/WebPageSerializerImpl.cpp @@ -0,0 +1,547 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// How we handle the base tag better. +// Current status: +// At now the normal way we use to handling base tag is +// a) For those links which have corresponding local saved files, such as +// savable CSS, JavaScript files, they will be written to relative URLs which +// point to local saved file. Why those links can not be resolved as absolute +// file URLs, because if they are resolved as absolute URLs, after moving the +// file location from one directory to another directory, the file URLs will +// be dead links. +// b) For those links which have not corresponding local saved files, such as +// links in A, AREA tags, they will be resolved as absolute URLs. +// c) We comment all base tags when serialzing DOM for the page. +// FireFox also uses above way to handle base tag. +// +// Problem: +// This way can not handle the following situation: +// the base tag is written by JavaScript. +// For example. The page "www.yahoo.com" use +// "document.write('<base href="http://www.yahoo.com/"...');" to setup base URL +// of page when loading page. So when saving page as completed-HTML, we assume +// that we save "www.yahoo.com" to "c:\yahoo.htm". After then we load the saved +// completed-HTML page, then the JavaScript will insert a base tag +// <base href="http://www.yahoo.com/"...> to DOM, so all URLs which point to +// local saved resource files will be resolved as +// "http://www.yahoo.com/yahoo_files/...", which will cause all saved resource +// files can not be loaded correctly. Also the page will be rendered ugly since +// all saved sub-resource files (such as CSS, JavaScript files) and sub-frame +// files can not be fetched. +// Now FireFox, IE and WebKit based Browser all have this problem. +// +// Solution: +// My solution is that we comment old base tag and write new base tag: +// <base href="." ...> after the previous commented base tag. In WebKit, it +// always uses the latest "href" attribute of base tag to set document's base +// URL. Based on this behavior, when we encounter a base tag, we comment it and +// write a new base tag <base href="."> after the previous commented base tag. +// The new added base tag can help engine to locate correct base URL for +// correctly loading local saved resource files. Also I think we need to inherit +// the base target value from document object when appending new base tag. +// If there are multiple base tags in original document, we will comment all old +// base tags and append new base tag after each old base tag because we do not +// know those old base tags are original content or added by JavaScript. If +// they are added by JavaScript, it means when loading saved page, the script(s) +// will still insert base tag(s) to DOM, so the new added base tag(s) can +// override the incorrect base URL and make sure we alway load correct local +// saved resource files. + +#include "config.h" +#include "WebPageSerializerImpl.h" + +#include "Document.h" +#include "DocumentType.h" +#include "Element.h" +#include "FrameLoader.h" +#include "HTMLAllCollection.h" +#include "HTMLElement.h" +#include "HTMLFormElement.h" +#include "HTMLMetaElement.h" +#include "HTMLNames.h" +#include "KURL.h" +#include "PlatformString.h" +#include "StringBuilder.h" +#include "TextEncoding.h" +#include "markup.h" + +#include "DOMUtilitiesPrivate.h" +#include "WebFrameImpl.h" +#include "WebURL.h" +#include "WebVector.h" + +using namespace WebCore; + +namespace WebKit { + +// Maximum length of data buffer which is used to temporary save generated +// html content data. This is a soft limit which might be passed if a very large +// contegious string is found in the page. +static const unsigned dataBufferCapacity = 65536; + +WebPageSerializerImpl::SerializeDomParam::SerializeDomParam(const KURL& currentFrameURL, + const TextEncoding& textEncoding, + Document* doc, + const String& directoryName) + : currentFrameURL(currentFrameURL) + , textEncoding(textEncoding) + , doc(doc) + , directoryName(directoryName) + , hasDoctype(false) + , hasCheckedMeta(false) + , skipMetaElement(0) + , isInScriptOrStyleTag(false) + , hasDocDeclaration(false) +{ + // Cache the value since we check it lots of times. + isHTMLDocument = doc->isHTMLDocument(); +} + +String WebPageSerializerImpl::preActionBeforeSerializeOpenTag( + const Element* element, SerializeDomParam* param, bool* needSkip) +{ + StringBuilder result; + + *needSkip = false; + if (param->isHTMLDocument) { + // Skip the open tag of original META tag which declare charset since we + // have overrided the META which have correct charset declaration after + // serializing open tag of HEAD element. + if (element->hasTagName(HTMLNames::metaTag)) { + const HTMLMetaElement* meta = static_cast<const HTMLMetaElement*>(element); + // Check whether the META tag has declared charset or not. + String equiv = meta->httpEquiv(); + if (equalIgnoringCase(equiv, "content-type")) { + String content = meta->content(); + if (content.length() && content.contains("charset", false)) { + // Find META tag declared charset, we need to skip it when + // serializing DOM. + param->skipMetaElement = element; + *needSkip = true; + } + } + } else if (element->hasTagName(HTMLNames::htmlTag)) { + // Check something before processing the open tag of HEAD element. + // First we add doc type declaration if original doc has it. + if (!param->hasDoctype) { + param->hasDoctype = true; + result.append(createMarkup(param->doc->doctype())); + } + + // Add MOTW declaration before html tag. + // See http://msdn2.microsoft.com/en-us/library/ms537628(VS.85).aspx. + result.append(WebPageSerializer::generateMarkOfTheWebDeclaration(param->currentFrameURL)); + } else if (element->hasTagName(HTMLNames::baseTag)) { + // Comment the BASE tag when serializing dom. + result.append("<!--"); + } + } else { + // Write XML declaration. + if (!param->hasDocDeclaration) { + param->hasDocDeclaration = true; + // Get encoding info. + String xmlEncoding = param->doc->xmlEncoding(); + if (xmlEncoding.isEmpty()) + xmlEncoding = param->doc->frame()->loader()->encoding(); + if (xmlEncoding.isEmpty()) + xmlEncoding = UTF8Encoding().name(); + result.append("<?xml version=\""); + result.append(param->doc->xmlVersion()); + result.append("\" encoding=\""); + result.append(xmlEncoding); + if (param->doc->xmlStandalone()) + result.append("\" standalone=\"yes"); + result.append("\"?>\n"); + } + // Add doc type declaration if original doc has it. + if (!param->hasDoctype) { + param->hasDoctype = true; + result.append(createMarkup(param->doc->doctype())); + } + } + return result.toString(); +} + +String WebPageSerializerImpl::postActionAfterSerializeOpenTag( + const Element* element, SerializeDomParam* param) +{ + StringBuilder result; + + param->hasAddedContentsBeforeEnd = false; + if (!param->isHTMLDocument) + return result.toString(); + // Check after processing the open tag of HEAD element + if (!param->hasCheckedMeta + && element->hasTagName(HTMLNames::headTag)) { + param->hasCheckedMeta = true; + // Check meta element. WebKit only pre-parse the first 512 bytes + // of the document. If the whole <HEAD> is larger and meta is the + // end of head part, then this kind of pages aren't decoded correctly + // because of this issue. So when we serialize the DOM, we need to + // make sure the meta will in first child of head tag. + // See http://bugs.webkit.org/show_bug.cgi?id=16621. + // First we generate new content for writing correct META element. + result.append(WebPageSerializer::generateMetaCharsetDeclaration( + String(param->textEncoding.name()))); + + param->hasAddedContentsBeforeEnd = true; + // Will search each META which has charset declaration, and skip them all + // in PreActionBeforeSerializeOpenTag. + } else if (element->hasTagName(HTMLNames::scriptTag) + || element->hasTagName(HTMLNames::styleTag)) { + param->isInScriptOrStyleTag = true; + } + + return result.toString(); +} + +String WebPageSerializerImpl::preActionBeforeSerializeEndTag( + const Element* element, SerializeDomParam* param, bool* needSkip) +{ + String result; + + *needSkip = false; + if (!param->isHTMLDocument) + return result; + // Skip the end tag of original META tag which declare charset. + // Need not to check whether it's META tag since we guarantee + // skipMetaElement is definitely META tag if it's not 0. + if (param->skipMetaElement == element) + *needSkip = true; + else if (element->hasTagName(HTMLNames::scriptTag) + || element->hasTagName(HTMLNames::styleTag)) { + ASSERT(param->isInScriptOrStyleTag); + param->isInScriptOrStyleTag = false; + } + + return result; +} + +// After we finish serializing end tag of a element, we give the target +// element a chance to do some post work to add some additional data. +String WebPageSerializerImpl::postActionAfterSerializeEndTag( + const Element* element, SerializeDomParam* param) +{ + StringBuilder result; + + if (!param->isHTMLDocument) + return result.toString(); + // Comment the BASE tag when serializing DOM. + if (element->hasTagName(HTMLNames::baseTag)) { + result.append("-->"); + // Append a new base tag declaration. + result.append(WebPageSerializer::generateBaseTagDeclaration( + param->doc->baseTarget())); + } + + return result.toString(); +} + +void WebPageSerializerImpl::saveHTMLContentToBuffer( + const String& result, SerializeDomParam* param) +{ + m_dataBuffer.append(result); + encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsNotFinished, + param, + 0); +} + +void WebPageSerializerImpl::encodeAndFlushBuffer( + WebPageSerializerClient::PageSerializationStatus status, + SerializeDomParam* param, + bool force) +{ + // Data buffer is not full nor do we want to force flush. + if (!force && m_dataBuffer.length() <= dataBufferCapacity) + return; + + String content = m_dataBuffer.toString(); + m_dataBuffer.clear(); + + // Convert the unicode content to target encoding + CString encodedContent = param->textEncoding.encode( + content.characters(), content.length(), EntitiesForUnencodables); + + // Send result to the client. + m_client->didSerializeDataForFrame(param->currentFrameURL, + WebCString(encodedContent.data(), encodedContent.length()), + status); +} + +void WebPageSerializerImpl::openTagToString(const Element* element, + SerializeDomParam* param) +{ + // FIXME: use StringBuilder instead of String. + bool needSkip; + // Do pre action for open tag. + String result = preActionBeforeSerializeOpenTag(element, param, &needSkip); + if (needSkip) + return; + // Add open tag + result += "<" + element->nodeName(); + // Go through all attributes and serialize them. + const NamedNodeMap *attrMap = element->attributes(true); + if (attrMap) { + unsigned numAttrs = attrMap->length(); + for (unsigned i = 0; i < numAttrs; i++) { + result += " "; + // Add attribute pair + const Attribute *attribute = attrMap->attributeItem(i); + result += attribute->name().toString(); + result += "=\""; + if (!attribute->value().isEmpty()) { + const String& attrValue = attribute->value(); + + // Check whether we need to replace some resource links + // with local resource paths. + const QualifiedName& attrName = attribute->name(); + if (elementHasLegalLinkAttribute(element, attrName)) { + // For links start with "javascript:", we do not change it. + if (attrValue.startsWith("javascript:", false)) + result += attrValue; + else { + // Get the absolute link + String completeURL = param->doc->completeURL(attrValue); + // Check whether we have local files for those link. + if (m_localLinks.contains(completeURL)) { + if (!m_localDirectoryName.isEmpty()) + result += "./" + m_localDirectoryName + "/"; + result += m_localLinks.get(completeURL); + } else + result += completeURL; + } + } else { + if (param->isHTMLDocument) + result += m_htmlEntities.convertEntitiesInString(attrValue); + else + result += m_xmlEntities.convertEntitiesInString(attrValue); + } + } + result += "\""; + } + } + + // Do post action for open tag. + String addedContents = postActionAfterSerializeOpenTag(element, param); + // Complete the open tag for element when it has child/children. + if (element->hasChildNodes() || param->hasAddedContentsBeforeEnd) + result += ">"; + // Append the added contents generate in post action of open tag. + result += addedContents; + // Save the result to data buffer. + saveHTMLContentToBuffer(result, param); +} + +// Serialize end tag of an specified element. +void WebPageSerializerImpl::endTagToString(const Element* element, + SerializeDomParam* param) +{ + bool needSkip; + // Do pre action for end tag. + String result = preActionBeforeSerializeEndTag(element, + param, + &needSkip); + if (needSkip) + return; + // Write end tag when element has child/children. + if (element->hasChildNodes() || param->hasAddedContentsBeforeEnd) { + result += "</"; + result += element->nodeName(); + result += ">"; + } else { + // Check whether we have to write end tag for empty element. + if (param->isHTMLDocument) { + result += ">"; + const HTMLElement* htmlElement = + static_cast<const HTMLElement*>(element); + if (htmlElement->endTagRequirement() == TagStatusRequired) { + // We need to write end tag when it is required. + result += "</"; + result += element->nodeName(); + result += ">"; + } + } else { + // For xml base document. + result += " />"; + } + } + // Do post action for end tag. + result += postActionAfterSerializeEndTag(element, param); + // Save the result to data buffer. + saveHTMLContentToBuffer(result, param); +} + +void WebPageSerializerImpl::buildContentForNode(const Node* node, + SerializeDomParam* param) +{ + switch (node->nodeType()) { + case Node::ELEMENT_NODE: + // Process open tag of element. + openTagToString(static_cast<const Element*>(node), param); + // Walk through the children nodes and process it. + for (const Node *child = node->firstChild(); child; child = child->nextSibling()) + buildContentForNode(child, param); + // Process end tag of element. + endTagToString(static_cast<const Element*>(node), param); + break; + case Node::TEXT_NODE: + saveHTMLContentToBuffer(createMarkup(node), param); + break; + case Node::ATTRIBUTE_NODE: + case Node::DOCUMENT_NODE: + case Node::DOCUMENT_FRAGMENT_NODE: + // Should not exist. + ASSERT_NOT_REACHED(); + break; + // Document type node can be in DOM? + case Node::DOCUMENT_TYPE_NODE: + param->hasDoctype = true; + default: + // For other type node, call default action. + saveHTMLContentToBuffer(createMarkup(node), param); + break; + } +} + +WebPageSerializerImpl::WebPageSerializerImpl(WebFrame* frame, + bool recursiveSerialization, + WebPageSerializerClient* client, + const WebVector<WebURL>& links, + const WebVector<WebString>& localPaths, + const WebString& localDirectoryName) + : m_client(client) + , m_recursiveSerialization(recursiveSerialization) + , m_framesCollected(false) + , m_localDirectoryName(localDirectoryName) + , m_htmlEntities(false) + , m_xmlEntities(true) +{ + // Must specify available webframe. + ASSERT(frame); + m_specifiedWebFrameImpl = static_cast<WebFrameImpl*>(frame); + // Make sure we have non 0 client. + ASSERT(client); + // Build local resources map. + ASSERT(links.size() == localPaths.size()); + for (size_t i = 0; i < links.size(); i++) { + KURL url = links[i]; + ASSERT(!m_localLinks.contains(url.string())); + m_localLinks.set(url.string(), localPaths[i]); + } + + ASSERT(!m_dataBuffer.length()); +} + +void WebPageSerializerImpl::collectTargetFrames() +{ + ASSERT(!m_framesCollected); + m_framesCollected = true; + + // First, process main frame. + m_frames.append(m_specifiedWebFrameImpl); + // Return now if user only needs to serialize specified frame, not including + // all sub-frames. + if (!m_recursiveSerialization) + return; + // Collect all frames inside the specified frame. + for (int i = 0; i < static_cast<int>(m_frames.size()); ++i) { + WebFrameImpl* currentFrame = m_frames[i]; + // Get current using document. + Document* currentDoc = currentFrame->frame()->document(); + // Go through sub-frames. + RefPtr<HTMLAllCollection> all = currentDoc->all(); + for (Node* node = all->firstItem(); node; node = all->nextItem()) { + if (!node->isHTMLElement()) + continue; + Element* element = static_cast<Element*>(node); + WebFrameImpl* webFrame = + WebFrameImpl::fromFrameOwnerElement(element); + if (webFrame) + m_frames.append(webFrame); + } + } +} + +bool WebPageSerializerImpl::serialize() +{ + // Collect target frames. + if (!m_framesCollected) + collectTargetFrames(); + bool didSerialization = false; + // Get KURL for main frame. + KURL mainPageURL = m_specifiedWebFrameImpl->frame()->loader()->url(); + + // Go through all frames for serializing DOM for whole page, include + // sub-frames. + for (int i = 0; i < static_cast<int>(m_frames.size()); ++i) { + // Get current serializing frame. + WebFrameImpl* currentFrame = m_frames[i]; + // Get current using document. + Document* currentDoc = currentFrame->frame()->document(); + // Get current frame's URL. + const KURL& currentFrameURL = currentFrame->frame()->loader()->url(); + + // Check whether we have done this document. + if (m_localLinks.contains(currentFrameURL.string())) { + // A new document, we will serialize it. + didSerialization = true; + // Get target encoding for current document. + String encoding = currentFrame->frame()->loader()->encoding(); + // Create the text encoding object with target encoding. + TextEncoding textEncoding(encoding); + // Construct serialize parameter for late processing document. + SerializeDomParam param(currentFrameURL, + encoding.length() ? textEncoding : UTF8Encoding(), + currentDoc, + currentFrameURL == mainPageURL ? m_localDirectoryName : ""); + + // Process current document. + Element* rootElement = currentDoc->documentElement(); + if (rootElement) + buildContentForNode(rootElement, ¶m); + + // Flush the remainder data and finish serializing current frame. + encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished, + ¶m, + 1); + } + } + + // We have done call frames, so we send message to embedder to tell it that + // frames are finished serializing. + ASSERT(!m_dataBuffer.length()); + m_client->didSerializeDataForFrame(KURL(), + WebCString("", 0), + WebPageSerializerClient::AllFramesAreFinished); + return didSerialization; +} + +} // namespace WebKit diff --git a/WebKit/chromium/src/WebPageSerializerImpl.h b/WebKit/chromium/src/WebPageSerializerImpl.h new file mode 100644 index 0000000..8f6a99f --- /dev/null +++ b/WebKit/chromium/src/WebPageSerializerImpl.h @@ -0,0 +1,199 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebPageSerializerImpl_h +#define WebPageSerializerImpl_h + +#include "PlatformString.h" +#include "StringBuilder.h" +#include "StringHash.h" +#include <wtf/HashMap.h> +#include <wtf/Vector.h> + +#include "WebEntities.h" +#include "WebPageSerializer.h" +#include "WebPageSerializerClient.h" +#include "WebString.h" +#include "WebURL.h" + +namespace WebCore { +class Document; +class Element; +class Node; +class String; +class TextEncoding; +} + +namespace WebKit { +class WebFrameImpl; + +// Get html data by serializing all frames of current page with lists +// which contain all resource links that have local copy. +// contain all saved auxiliary files included all sub frames and resources. +// This function will find out all frames and serialize them to HTML data. +// We have a data buffer to temporary saving generated html data. We will +// sequentially call WebViewDelegate::SendSerializedHtmlData once the data +// buffer is full. See comments of WebViewDelegate::SendSerializedHtmlData +// for getting more information. +class WebPageSerializerImpl { +public: + // Do serialization action. Return false means no available frame has been + // serialized, otherwise return true. + bool serialize(); + + // The parameter specifies which frame need to be serialized. + // The parameter recursive_serialization specifies whether we need to + // serialize all sub frames of the specified frame or not. + // The parameter delegate specifies the pointer of interface + // DomSerializerDelegate provide sink interface which can receive the + // individual chunks of data to be saved. + // The parameter links contain original URLs of all saved links. + // The parameter local_paths contain corresponding local file paths of all + // saved links, which matched with vector:links one by one. + // The parameter local_directory_name is relative path of directory which + // contain all saved auxiliary files included all sub frames and resources. + WebPageSerializerImpl(WebFrame* frame, + bool recursive, + WebPageSerializerClient* client, + const WebVector<WebURL>& links, + const WebVector<WebString>& localPaths, + const WebString& localDirectoryName); + +private: + // Specified frame which need to be serialized; + WebFrameImpl* m_specifiedWebFrameImpl; + // Pointer of WebPageSerializerClient + WebPageSerializerClient* m_client; + // This hash map is used to map resource URL of original link to its local + // file path. + typedef HashMap<WebCore::String, WebCore::String> LinkLocalPathMap; + // local_links_ include all pair of local resource path and corresponding + // original link. + LinkLocalPathMap m_localLinks; + // Data buffer for saving result of serialized DOM data. + WebCore::StringBuilder m_dataBuffer; + // Passing true to recursive_serialization_ indicates we will serialize not + // only the specified frame but also all sub-frames in the specific frame. + // Otherwise we only serialize the specified frame excluded all sub-frames. + bool m_recursiveSerialization; + // Flag indicates whether we have collected all frames which need to be + // serialized or not; + bool m_framesCollected; + // Local directory name of all local resource files. + WebCore::String m_localDirectoryName; + // Vector for saving all frames which need to be serialized. + Vector<WebFrameImpl*> m_frames; + + // Web entities conversion maps. + WebEntities m_htmlEntities; + WebEntities m_xmlEntities; + + struct SerializeDomParam { + // Frame URL of current processing document presented by GURL + const WebCore::KURL& currentFrameURL; + // Current using text encoding object. + const WebCore::TextEncoding& textEncoding; + + // Document object of current frame. + WebCore::Document* doc; + // Local directory name of all local resource files. + const WebCore::String& directoryName; + + // Flag indicates current doc is html document or not. It's a cache value + // of Document.isHTMLDocument(). + bool isHTMLDocument; + // Flag which indicate whether we have met document type declaration. + bool hasDoctype; + // Flag which indicate whether will process meta issue. + bool hasCheckedMeta; + // This meta element need to be skipped when serializing DOM. + const WebCore::Element* skipMetaElement; + // Flag indicates we are in script or style tag. + bool isInScriptOrStyleTag; + // Flag indicates whether we have written xml document declaration. + // It is only used in xml document + bool hasDocDeclaration; + // Flag indicates whether we have added additional contents before end tag. + // This flag will be re-assigned in each call of function + // PostActionAfterSerializeOpenTag and it could be changed in function + // PreActionBeforeSerializeEndTag if the function adds new contents into + // serialization stream. + bool hasAddedContentsBeforeEnd; + + // Constructor. + SerializeDomParam(const WebCore::KURL& currentFrameURL, + const WebCore::TextEncoding& textEncoding, + WebCore::Document* doc, + const WebCore::String& directoryName); + }; + + // Collect all target frames which need to be serialized. + void collectTargetFrames(); + // Before we begin serializing open tag of a element, we give the target + // element a chance to do some work prior to add some additional data. + WebCore::String preActionBeforeSerializeOpenTag(const WebCore::Element* element, + SerializeDomParam* param, + bool* needSkip); + // After we finish serializing open tag of a element, we give the target + // element a chance to do some post work to add some additional data. + WebCore::String postActionAfterSerializeOpenTag(const WebCore::Element* element, + SerializeDomParam* param); + // Before we begin serializing end tag of a element, we give the target + // element a chance to do some work prior to add some additional data. + WebCore::String preActionBeforeSerializeEndTag(const WebCore::Element* element, + SerializeDomParam* param, + bool* needSkip); + // After we finish serializing end tag of a element, we give the target + // element a chance to do some post work to add some additional data. + WebCore::String postActionAfterSerializeEndTag(const WebCore::Element* element, + SerializeDomParam* param); + // Save generated html content to data buffer. + void saveHTMLContentToBuffer(const WebCore::String& content, + SerializeDomParam* param); + // Flushes the content buffer by encoding and sending the content to the + // WebPageSerializerClient. Content is not flushed if the buffer is not full + // unless force is 1. + void encodeAndFlushBuffer(WebPageSerializerClient::PageSerializationStatus status, + SerializeDomParam* param, + bool force); + // Serialize open tag of an specified element. + void openTagToString(const WebCore::Element* element, + SerializeDomParam* param); + // Serialize end tag of an specified element. + void endTagToString(const WebCore::Element* element, + SerializeDomParam* param); + // Build content for a specified node + void buildContentForNode(const WebCore::Node* node, + SerializeDomParam* param); +}; + +} // namespace WebKit + +#endif diff --git a/WebKit/chromium/src/WebPluginContainerImpl.cpp b/WebKit/chromium/src/WebPluginContainerImpl.cpp index 43f3cef..86cac26 100644 --- a/WebKit/chromium/src/WebPluginContainerImpl.cpp +++ b/WebKit/chromium/src/WebPluginContainerImpl.cpp @@ -31,6 +31,7 @@ #include "config.h" #include "WebPluginContainerImpl.h" +#include "Chrome.h" #include "ChromeClientImpl.h" #include "WebCursorInfo.h" #include "WebDataSourceImpl.h" @@ -353,7 +354,7 @@ void WebPluginContainerImpl::handleMouseEvent(MouseEvent* event) WebCursorInfo cursorInfo; bool handled = m_webPlugin->handleInputEvent(webEvent, cursorInfo); -#if !PLATFORM(DARWIN) +#if !OS(DARWIN) // TODO(pkasting): http://b/1119691 This conditional seems exactly // backwards, but if I reverse it, giving focus to a transparent // (windowless) plugin fails. @@ -389,7 +390,7 @@ void WebPluginContainerImpl::handleKeyboardEvent(KeyboardEvent* event) WebCursorInfo cursor_info; bool handled = m_webPlugin->handleInputEvent(webEvent, cursor_info); -#if !PLATFORM(DARWIN) +#if !OS(DARWIN) // TODO(pkasting): http://b/1119691 See above. handled = !handled; #endif diff --git a/WebKit/chromium/src/WebRuntimeFeatures.cpp b/WebKit/chromium/src/WebRuntimeFeatures.cpp index b630a09..0ef8b9b 100644 --- a/WebKit/chromium/src/WebRuntimeFeatures.cpp +++ b/WebKit/chromium/src/WebRuntimeFeatures.cpp @@ -31,6 +31,7 @@ #include "config.h" #include "WebRuntimeFeatures.h" +#include "Database.h" #include "RuntimeEnabledFeatures.h" #include "WebMediaPlayerClientImpl.h" #include "WebSocket.h" @@ -42,14 +43,14 @@ namespace WebKit { void WebRuntimeFeatures::enableDatabase(bool enable) { #if ENABLE(DATABASE) - RuntimeEnabledFeatures::setDatabaseEnabled(enable); + Database::setIsAvailable(enable); #endif } bool WebRuntimeFeatures::isDatabaseEnabled() { #if ENABLE(DATABASE) - return RuntimeEnabledFeatures::databaseEnabled(); + return Database::isAvailable(); #else return false; #endif @@ -151,4 +152,36 @@ bool WebRuntimeFeatures::isApplicationCacheEnabled() #endif } +void WebRuntimeFeatures::enableGeolocation(bool enable) +{ +#if ENABLE(GEOLOCATION) + RuntimeEnabledFeatures::setGeolocationEnabled(enable); +#endif +} + +bool WebRuntimeFeatures::isGeolocationEnabled() +{ +#if ENABLE(GEOLOCATION) + return RuntimeEnabledFeatures::geolocationEnabled(); +#else + return false; +#endif +} + +void WebRuntimeFeatures::enableIndexedDatabase(bool enable) +{ +#if ENABLE(INDEXED_DATABASE) + RuntimeEnabledFeatures::setIndexedDatabaseEnabled(enable); +#endif +} + +bool WebRuntimeFeatures::isIndexedDatabaseEnabled() +{ +#if ENABLE(INDEXED_DATABASE) + return RuntimeEnabledFeatures::indexedDatabaseEnabled(); +#else + return false; +#endif +} + } // namespace WebKit diff --git a/WebKit/chromium/src/WebSecurityOrigin.cpp b/WebKit/chromium/src/WebSecurityOrigin.cpp index 3cf7364..87916ca 100644 --- a/WebKit/chromium/src/WebSecurityOrigin.cpp +++ b/WebKit/chromium/src/WebSecurityOrigin.cpp @@ -42,6 +42,11 @@ namespace WebKit { class WebSecurityOriginPrivate : public SecurityOrigin { }; +WebSecurityOrigin* WebSecurityOrigin::createFromDatabaseIdentifier(const WebString& databaseIdentifier) +{ + return new WebSecurityOrigin(SecurityOrigin::createFromDatabaseIdentifier(databaseIdentifier)); +} + void WebSecurityOrigin::reset() { assign(0); diff --git a/WebKit/chromium/src/WebSecurityPolicy.cpp b/WebKit/chromium/src/WebSecurityPolicy.cpp index c66c805..48b445c 100644 --- a/WebKit/chromium/src/WebSecurityPolicy.cpp +++ b/WebKit/chromium/src/WebSecurityPolicy.cpp @@ -66,4 +66,9 @@ void WebSecurityPolicy::resetOriginAccessWhiteLists() SecurityOrigin::resetOriginAccessWhiteLists(); } +bool WebSecurityPolicy::shouldHideReferrer(const WebURL& url, const WebString& referrer) +{ + return SecurityOrigin::shouldHideReferrer(url, referrer); +} + } // namespace WebKit diff --git a/WebKit/chromium/src/WebSettingsImpl.cpp b/WebKit/chromium/src/WebSettingsImpl.cpp index e019653..5cfbd4f 100644 --- a/WebKit/chromium/src/WebSettingsImpl.cpp +++ b/WebKit/chromium/src/WebSettingsImpl.cpp @@ -130,6 +130,11 @@ void WebSettingsImpl::setLoadsImagesAutomatically(bool loadsImagesAutomatically) m_settings->setLoadsImagesAutomatically(loadsImagesAutomatically); } +void WebSettingsImpl::setImagesEnabled(bool enabled) +{ + m_settings->setImagesEnabled(enabled); +} + void WebSettingsImpl::setPluginsEnabled(bool enabled) { m_settings->setPluginsEnabled(enabled); diff --git a/WebKit/chromium/src/WebSettingsImpl.h b/WebKit/chromium/src/WebSettingsImpl.h index 9c0f9f4..3b69fe6 100644 --- a/WebKit/chromium/src/WebSettingsImpl.h +++ b/WebKit/chromium/src/WebSettingsImpl.h @@ -60,6 +60,7 @@ public: virtual void setWebSecurityEnabled(bool); virtual void setJavaScriptCanOpenWindowsAutomatically(bool); virtual void setLoadsImagesAutomatically(bool); + virtual void setImagesEnabled(bool); virtual void setPluginsEnabled(bool); virtual void setDOMPasteAllowed(bool); virtual void setDeveloperExtrasEnabled(bool); diff --git a/WebKit/chromium/src/WebStorageAreaImpl.cpp b/WebKit/chromium/src/WebStorageAreaImpl.cpp index f24bee3..92a923a 100644 --- a/WebKit/chromium/src/WebStorageAreaImpl.cpp +++ b/WebKit/chromium/src/WebStorageAreaImpl.cpp @@ -66,12 +66,12 @@ WebString WebStorageAreaImpl::getItem(const WebString& key) return m_storageArea->getItem(key); } -void WebStorageAreaImpl::setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException) +void WebStorageAreaImpl::setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException, WebString& oldValue) { int exceptionCode = 0; ScopedStorageEventURL scope(url); - m_storageArea->setItem(key, value, exceptionCode, 0); + oldValue = m_storageArea->setItem(key, value, exceptionCode, 0); if (exceptionCode) { ASSERT(exceptionCode == WebCore::QUOTA_EXCEEDED_ERR); @@ -80,16 +80,16 @@ void WebStorageAreaImpl::setItem(const WebString& key, const WebString& value, c quotaException = false; } -void WebStorageAreaImpl::removeItem(const WebString& key, const WebURL& url) +void WebStorageAreaImpl::removeItem(const WebString& key, const WebURL& url, WebString& oldValue) { ScopedStorageEventURL scope(url); - m_storageArea->removeItem(key, 0); + oldValue = m_storageArea->removeItem(key, 0); } -void WebStorageAreaImpl::clear(const WebURL& url) +void WebStorageAreaImpl::clear(const WebURL& url, bool& somethingCleared) { ScopedStorageEventURL scope(url); - m_storageArea->clear(0); + somethingCleared = m_storageArea->clear(0); } } // namespace WebKit diff --git a/WebKit/chromium/src/WebStorageAreaImpl.h b/WebKit/chromium/src/WebStorageAreaImpl.h index e1f74e0..7e90531 100644 --- a/WebKit/chromium/src/WebStorageAreaImpl.h +++ b/WebKit/chromium/src/WebStorageAreaImpl.h @@ -45,9 +45,9 @@ public: virtual unsigned length(); virtual WebString key(unsigned index); virtual WebString getItem(const WebString& key); - virtual void setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException); - virtual void removeItem(const WebString& key, const WebURL& url); - virtual void clear(const WebURL& url); + virtual void setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException, WebString& oldValue); + virtual void removeItem(const WebString& key, const WebURL& url, WebString& oldValue); + virtual void clear(const WebURL& url, bool& somethingCleared); // For storage events in single-process mode and test shell. static const WebURL* currentStorageEventURL() { return storageEventURL; } diff --git a/WebKit/chromium/src/WebString.cpp b/WebKit/chromium/src/WebString.cpp index f45e05f..36d5f86 100644 --- a/WebKit/chromium/src/WebString.cpp +++ b/WebKit/chromium/src/WebString.cpp @@ -86,6 +86,11 @@ WebString WebString::fromUTF8(const char* data) return WebCore::String::fromUTF8(data); } +bool WebString::equals(const WebString& s) const +{ + return equal(m_private, s.m_private); +} + WebString::WebString(const WebCore::String& s) : m_private(static_cast<WebStringPrivate*>(s.impl())) { diff --git a/WebKit/chromium/src/WebURLResponse.cpp b/WebKit/chromium/src/WebURLResponse.cpp index 49f07f9..95e0be2 100644 --- a/WebKit/chromium/src/WebURLResponse.cpp +++ b/WebKit/chromium/src/WebURLResponse.cpp @@ -255,6 +255,16 @@ const ResourceResponse& WebURLResponse::toResourceResponse() const return *m_private->m_resourceResponse; } +bool WebURLResponse::wasFetchedViaSPDY() const +{ + return m_private->m_resourceResponse->wasFetchedViaSPDY(); +} + +void WebURLResponse::setWasFetchedViaSPDY(bool value) +{ + m_private->m_resourceResponse->setWasFetchedViaSPDY(value); +} + void WebURLResponse::assign(WebURLResponsePrivate* p) { // Subclasses may call this directly so a self-assignment check is needed diff --git a/WebKit/chromium/src/WebViewImpl.cpp b/WebKit/chromium/src/WebViewImpl.cpp index 030c4bd..97825e9 100644 --- a/WebKit/chromium/src/WebViewImpl.cpp +++ b/WebKit/chromium/src/WebViewImpl.cpp @@ -33,6 +33,7 @@ #include "AutocompletePopupMenuClient.h" #include "AXObjectCache.h" +#include "Chrome.h" #include "ContextMenu.h" #include "ContextMenuController.h" #include "ContextMenuItem.h" @@ -65,6 +66,7 @@ #include "NodeRenderStyle.h" #include "Page.h" #include "PageGroup.h" +#include "PageGroupLoadDeferrer.h" #include "Pasteboard.h" #include "PlatformContextSkia.h" #include "PlatformKeyboardEvent.h" @@ -96,11 +98,11 @@ #include "WebVector.h" #include "WebViewClient.h" -#if PLATFORM(WIN_OS) +#if OS(WINDOWS) #include "KeyboardCodesWin.h" #include "RenderThemeChromiumWin.h" #else -#if PLATFORM(LINUX) +#if OS(LINUX) #include "RenderThemeChromiumLinux.h" #endif #include "KeyboardCodesPosix.h" @@ -129,6 +131,10 @@ static const double maxTextSizeMultiplier = 3.0; // one page group. const char* pageGroupName = "default"; +// Used to defer all page activity in cases where the embedder wishes to run +// a nested event loop. +static PageGroupLoadDeferrer* pageGroupLoadDeferrer; + // Ensure that the WebDragOperation enum values stay in sync with the original // DragOperation constants. #define COMPILE_ASSERT_MATCHING_ENUM(coreName) \ @@ -174,6 +180,28 @@ void WebView::resetVisitedLinkState() Page::allVisitedStateChanged(PageGroup::pageGroup(pageGroupName)); } +void WebView::willEnterModalLoop() +{ + // It is not valid to nest more than once. + ASSERT(!pageGroupLoadDeferrer); + + PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName); + ASSERT(pageGroup); + ASSERT(!pageGroup->pages().isEmpty()); + + // Pick any page in the page group since we are deferring all pages. + pageGroupLoadDeferrer = new PageGroupLoadDeferrer(*pageGroup->pages().begin(), true); +} + +void WebView::didExitModalLoop() +{ + // The embedder must have called willEnterNestedEventLoop. + ASSERT(pageGroupLoadDeferrer); + + delete pageGroupLoadDeferrer; + pageGroupLoadDeferrer = 0; +} + void WebViewImpl::initializeMainFrame(WebFrameClient* frameClient) { // NOTE: The WebFrameImpl takes a reference to itself within InitMainFrame @@ -327,12 +355,12 @@ void WebViewImpl::mouseDown(const WebMouseEvent& event) // Dispatch the contextmenu event regardless of if the click was swallowed. // On Windows, we handle it on mouse up, not down. -#if PLATFORM(DARWIN) +#if OS(DARWIN) if (event.button == WebMouseEvent::ButtonRight || (event.button == WebMouseEvent::ButtonLeft && event.modifiers & WebMouseEvent::ControlKey)) mouseContextMenu(event); -#elif PLATFORM(LINUX) +#elif OS(LINUX) if (event.button == WebMouseEvent::ButtonRight) mouseContextMenu(event); #endif @@ -355,7 +383,7 @@ void WebViewImpl::mouseContextMenu(const WebMouseEvent& event) else targetFrame = m_page->focusController()->focusedOrMainFrame(); -#if PLATFORM(WIN_OS) +#if OS(WINDOWS) targetFrame->view()->setCursor(pointerCursor()); #endif @@ -371,7 +399,7 @@ void WebViewImpl::mouseUp(const WebMouseEvent& event) if (!mainFrameImpl() || !mainFrameImpl()->frameView()) return; -#if PLATFORM(LINUX) +#if OS(LINUX) // If the event was a middle click, attempt to copy text into the focused // frame. We execute this before we let the page have a go at the event // because the page may change what is focused during in its event handler. @@ -390,14 +418,14 @@ void WebViewImpl::mouseUp(const WebMouseEvent& event) // handleMouseReleaseEvent() earlier in this function if (event.button == WebMouseEvent::ButtonMiddle) { Frame* focused = focusedWebCoreFrame(); + FrameView* view = m_page->mainFrame()->view(); IntPoint clickPoint(m_lastMouseDownPoint.x, m_lastMouseDownPoint.y); - clickPoint = m_page->mainFrame()->view()->windowToContents(clickPoint); - HitTestResult hitTestResult = - focused->eventHandler()->hitTestResultAtPoint(clickPoint, false, false, - ShouldHitTestScrollbars); + IntPoint contentPoint = view->windowToContents(clickPoint); + HitTestResult hitTestResult = focused->eventHandler()->hitTestResultAtPoint(contentPoint, false, false, ShouldHitTestScrollbars); // We don't want to send a paste when middle clicking a scroll bar or a - // link (which will navigate later in the code). - if (!hitTestResult.scrollbar() && !hitTestResult.isLiveLink() && focused) { + // link (which will navigate later in the code). The main scrollbars + // have to be handled separately. + if (!hitTestResult.scrollbar() && !hitTestResult.isLiveLink() && focused && !view->scrollbarAtPoint(clickPoint)) { Editor* editor = focused->editor(); Pasteboard* pasteboard = Pasteboard::generalPasteboard(); bool oldSelectionMode = pasteboard->isSelectionMode(); @@ -412,7 +440,7 @@ void WebViewImpl::mouseUp(const WebMouseEvent& event) mainFrameImpl()->frame()->eventHandler()->handleMouseReleaseEvent( PlatformMouseEventBuilder(mainFrameImpl()->frameView(), event)); -#if PLATFORM(WIN_OS) +#if OS(WINDOWS) // Dispatch the contextmenu event regardless of if the click was swallowed. // On Mac/Linux, we handle it on mouse down, not up. if (event.button == WebMouseEvent::ButtonRight) @@ -452,9 +480,17 @@ bool WebViewImpl::keyEvent(const WebKeyboardEvent& event) if (!handler) return keyEventDefault(event); -#if PLATFORM(WIN_OS) || PLATFORM(LINUX) - if ((!event.modifiers && (event.windowsKeyCode == VKEY_APPS)) - || ((event.modifiers == WebInputEvent::ShiftKey) && (event.windowsKeyCode == VKEY_F10))) { +#if OS(WINDOWS) || OS(LINUX) + const WebInputEvent::Type contextMenuTriggeringEventType = +#if OS(WINDOWS) + WebInputEvent::KeyUp; +#elif OS(LINUX) + WebInputEvent::RawKeyDown; +#endif + + if (((!event.modifiers && (event.windowsKeyCode == VKEY_APPS)) + || ((event.modifiers == WebInputEvent::ShiftKey) && (event.windowsKeyCode == VKEY_F10))) + && event.type == contextMenuTriggeringEventType) { sendContextMenuEvent(event); return true; } @@ -574,7 +610,7 @@ bool WebViewImpl::charEvent(const WebKeyboardEvent& event) // // This function is an ugly copy/paste and should be cleaned up when the // WebKitWin version is cleaned: https://bugs.webkit.org/show_bug.cgi?id=20438 -#if PLATFORM(WIN_OS) || PLATFORM(LINUX) +#if OS(WINDOWS) || OS(LINUX) // FIXME: implement on Mac bool WebViewImpl::sendContextMenuEvent(const WebKeyboardEvent& event) { @@ -585,22 +621,19 @@ bool WebViewImpl::sendContextMenuEvent(const WebKeyboardEvent& event) return false; IntPoint coords(-1, -1); -#if PLATFORM(WIN_OS) +#if OS(WINDOWS) int rightAligned = ::GetSystemMetrics(SM_MENUDROPALIGNMENT); #else int rightAligned = 0; #endif IntPoint location; - // The context menu event was generated from the keyboard, so show the - // context menu by the current selection. - Position start = mainFrameImpl->selection()->selection().start(); - Position end = mainFrameImpl->selection()->selection().end(); Frame* focusedFrame = page()->focusController()->focusedOrMainFrame(); Node* focusedNode = focusedFrame->document()->focusedNode(); + Position start = mainFrameImpl->selection()->selection().start(); - if (start.node() && end.node()) { + if (focusedFrame->editor() && focusedFrame->editor()->canEdit() && start.node()) { RenderObject* renderer = start.node()->renderer(); if (!renderer) return false; @@ -1641,13 +1674,26 @@ bool WebViewImpl::isActive() const void WebViewImpl::setScrollbarColors(unsigned inactiveColor, unsigned activeColor, unsigned trackColor) { -#if PLATFORM(LINUX) +#if OS(LINUX) RenderThemeChromiumLinux::setScrollbarColors(inactiveColor, activeColor, trackColor); #endif } +void WebViewImpl::setSelectionColors(unsigned activeBackgroundColor, + unsigned activeForegroundColor, + unsigned inactiveBackgroundColor, + unsigned inactiveForegroundColor) { +#if OS(LINUX) + RenderThemeChromiumLinux::setSelectionColors(activeBackgroundColor, + activeForegroundColor, + inactiveBackgroundColor, + inactiveForegroundColor); + theme()->platformColorsDidChange(); +#endif +} + void WebViewImpl::didCommitLoad(bool* isNewNavigation) { if (isNewNavigation) @@ -1666,9 +1712,9 @@ bool WebViewImpl::navigationPolicyFromMouseEvent(unsigned short button, bool alt, bool meta, WebNavigationPolicy* policy) { -#if PLATFORM(WIN_OS) || PLATFORM(LINUX) || PLATFORM(FREEBSD) +#if OS(WINDOWS) || OS(LINUX) || OS(FREEBSD) const bool newTabModifier = (button == 1) || ctrl; -#elif PLATFORM(DARWIN) +#elif OS(DARWIN) const bool newTabModifier = (button == 1) || meta; #endif if (!newTabModifier && !shift && !alt) diff --git a/WebKit/chromium/src/WebViewImpl.h b/WebKit/chromium/src/WebViewImpl.h index dd5191e..ed5cc5f 100644 --- a/WebKit/chromium/src/WebViewImpl.h +++ b/WebKit/chromium/src/WebViewImpl.h @@ -157,6 +157,10 @@ public: virtual void setScrollbarColors(unsigned inactiveColor, unsigned activeColor, unsigned trackColor); + virtual void setSelectionColors(unsigned activeBackgroundColor, + unsigned activeForegroundColor, + unsigned inactiveBackgroundColor, + unsigned inactiveForegroundColor); virtual void performCustomContextMenuAction(unsigned action); // WebViewImpl diff --git a/WebKit/chromium/src/WebWorkerBase.cpp b/WebKit/chromium/src/WebWorkerBase.cpp index 85a263b..7fd3749 100644 --- a/WebKit/chromium/src/WebWorkerBase.cpp +++ b/WebKit/chromium/src/WebWorkerBase.cpp @@ -132,8 +132,7 @@ void WebWorkerBase::initializeLoader(const WebURL& url) int len = static_cast<int>(content.length()); RefPtr<SharedBuffer> buf(SharedBuffer::create(content.data(), len)); SubstituteData substData(buf, String("text/html"), String("UTF-8"), KURL()); - ResourceRequest request(url, CString()); - webFrame->frame()->loader()->load(request, substData, false); + webFrame->frame()->loader()->load(ResourceRequest(url), substData, false); // This document will be used as 'loading context' for the worker. m_loadingDocument = webFrame->frame()->document(); @@ -158,7 +157,7 @@ void WebWorkerBase::postMessageToWorkerObject(PassRefPtr<SerializedScriptValue> PassOwnPtr<MessagePortChannelArray> channels) { dispatchTaskToMainThread(createCallbackTask(&postMessageTask, this, - message->toString(), channels)); + message->toWireString(), channels)); } void WebWorkerBase::postMessageTask(ScriptExecutionContext* context, diff --git a/WebKit/chromium/src/WebWorkerClientImpl.cpp b/WebKit/chromium/src/WebWorkerClientImpl.cpp index 6be03a7..598a078 100644 --- a/WebKit/chromium/src/WebWorkerClientImpl.cpp +++ b/WebKit/chromium/src/WebWorkerClientImpl.cpp @@ -173,7 +173,7 @@ void WebWorkerClientImpl::postMessageToWorkerContext( if (!isMainThread()) { WebWorkerBase::dispatchTaskToMainThread(createCallbackTask(&postMessageToWorkerContextTask, this, - message->toString(), + message->toWireString(), channels)); return; } @@ -184,7 +184,7 @@ void WebWorkerClientImpl::postMessageToWorkerContext( webchannel->setClient(0); webChannels[i] = webchannel; } - m_webWorker->postMessageToWorkerContext(message->toString(), webChannels); + m_webWorker->postMessageToWorkerContext(message->toWireString(), webChannels); } bool WebWorkerClientImpl::hasPendingActivity() const @@ -356,7 +356,7 @@ void WebWorkerClientImpl::postMessageToWorkerObjectTask( OwnPtr<MessagePortArray> ports = MessagePort::entanglePorts(*context, channels.release()); RefPtr<SerializedScriptValue> serializedMessage = - SerializedScriptValue::create(message); + SerializedScriptValue::createFromWire(message); thisPtr->m_worker->dispatchEvent(MessageEvent::create(ports.release(), serializedMessage.release())); } diff --git a/WebKit/chromium/src/WebWorkerImpl.cpp b/WebKit/chromium/src/WebWorkerImpl.cpp index 744be30..5b5e053 100644 --- a/WebKit/chromium/src/WebWorkerImpl.cpp +++ b/WebKit/chromium/src/WebWorkerImpl.cpp @@ -88,7 +88,7 @@ void WebWorkerImpl::postMessageToWorkerContextTask(WebCore::ScriptExecutionConte OwnPtr<MessagePortArray> ports = MessagePort::entanglePorts(*context, channels.release()); RefPtr<SerializedScriptValue> serializedMessage = - SerializedScriptValue::create(message); + SerializedScriptValue::createFromWire(message); workerContext->dispatchEvent(MessageEvent::create( ports.release(), serializedMessage.release())); thisPtr->confirmMessageFromWorkerObject(workerContext->hasPendingActivity()); diff --git a/WebKit/chromium/src/mac/WebInputEventFactory.mm b/WebKit/chromium/src/mac/WebInputEventFactory.mm index d618228..46b0afe 100644 --- a/WebKit/chromium/src/mac/WebInputEventFactory.mm +++ b/WebKit/chromium/src/mac/WebInputEventFactory.mm @@ -92,6 +92,9 @@ static bool isKeypadEvent(NSEvent* event) return false; } + if ([event modifierFlags] & NSNumericPadKeyMask) + return true; + switch ([event keyCode]) { case 71: // Clear case 81: // = |