| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | |
| 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). | |
| 4 * | |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions are | |
| 7 * met: | |
| 8 * | |
| 9 * * Redistributions of source code must retain the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer. | |
| 11 * * Redistributions in binary form must reproduce the above | |
| 12 * copyright notice, this list of conditions and the following disclaimer | |
| 13 * in the documentation and/or other materials provided with the | |
| 14 * distribution. | |
| 15 * * Neither the name of Google Inc. nor the names of its | |
| 16 * contributors may be used to endorse or promote products derived from | |
| 17 * this software without specific prior written permission. | |
| 18 * | |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 30 */ | |
| 31 | |
| 32 #include "sky/engine/web/ChromeClientImpl.h" | |
| 33 | |
| 34 #include "base/logging.h" | |
| 35 #include "gen/sky/platform/RuntimeEnabledFeatures.h" | |
| 36 #include "sky/engine/core/dom/Document.h" | |
| 37 #include "sky/engine/core/dom/Element.h" | |
| 38 #include "sky/engine/core/dom/Node.h" | |
| 39 #include "sky/engine/core/events/KeyboardEvent.h" | |
| 40 #include "sky/engine/core/frame/FrameView.h" | |
| 41 #include "sky/engine/core/frame/Settings.h" | |
| 42 #include "sky/engine/core/page/Page.h" | |
| 43 #include "sky/engine/core/rendering/HitTestResult.h" | |
| 44 #include "sky/engine/platform/NotImplemented.h" | |
| 45 #include "sky/engine/platform/PlatformScreen.h" | |
| 46 #include "sky/engine/platform/exported/WrappedResourceRequest.h" | |
| 47 #include "sky/engine/platform/geometry/FloatRect.h" | |
| 48 #include "sky/engine/platform/geometry/IntRect.h" | |
| 49 #include "sky/engine/public/platform/Platform.h" | |
| 50 #include "sky/engine/public/platform/WebInputEvent.h" | |
| 51 #include "sky/engine/public/platform/WebRect.h" | |
| 52 #include "sky/engine/public/platform/WebURLRequest.h" | |
| 53 #include "sky/engine/public/web/Sky.h" | |
| 54 #include "sky/engine/public/web/WebConsoleMessage.h" | |
| 55 #include "sky/engine/public/web/WebFrameClient.h" | |
| 56 #include "sky/engine/public/web/WebNode.h" | |
| 57 #include "sky/engine/public/web/WebSettings.h" | |
| 58 #include "sky/engine/public/web/WebTextDirection.h" | |
| 59 #include "sky/engine/public/web/WebViewClient.h" | |
| 60 #include "sky/engine/web/WebLocalFrameImpl.h" | |
| 61 #include "sky/engine/web/WebSettingsImpl.h" | |
| 62 #include "sky/engine/web/WebViewImpl.h" | |
| 63 #include "sky/engine/wtf/text/CString.h" | |
| 64 #include "sky/engine/wtf/text/StringBuilder.h" | |
| 65 #include "sky/engine/wtf/text/StringConcatenate.h" | |
| 66 #include "sky/engine/wtf/unicode/CharacterNames.h" | |
| 67 | |
| 68 namespace blink { | |
| 69 | |
| 70 ChromeClientImpl::ChromeClientImpl(WebViewImpl* webView) | |
| 71 : m_webView(webView) | |
| 72 { | |
| 73 } | |
| 74 | |
| 75 ChromeClientImpl::~ChromeClientImpl() | |
| 76 { | |
| 77 } | |
| 78 | |
| 79 void* ChromeClientImpl::webView() const | |
| 80 { | |
| 81 return static_cast<void*>(m_webView); | |
| 82 } | |
| 83 | |
| 84 void ChromeClientImpl::setWindowRect(const FloatRect& r) | |
| 85 { | |
| 86 if (m_webView->client()) | |
| 87 m_webView->client()->setWindowRect(IntRect(r)); | |
| 88 } | |
| 89 | |
| 90 FloatRect ChromeClientImpl::windowRect() | |
| 91 { | |
| 92 WebRect rect; | |
| 93 if (m_webView->client()) | |
| 94 rect = m_webView->client()->rootWindowRect(); | |
| 95 else { | |
| 96 // These numbers will be fairly wrong. The window's x/y coordinates will | |
| 97 // be the top left corner of the screen and the size will be the content | |
| 98 // size instead of the window size. | |
| 99 rect.width = m_webView->size().width; | |
| 100 rect.height = m_webView->size().height; | |
| 101 } | |
| 102 return FloatRect(rect); | |
| 103 } | |
| 104 | |
| 105 void ChromeClientImpl::focus() | |
| 106 { | |
| 107 } | |
| 108 | |
| 109 bool ChromeClientImpl::canTakeFocus(FocusType) | |
| 110 { | |
| 111 // For now the browser can always take focus if we're not running layout | |
| 112 // tests. | |
| 113 return !layoutTestMode(); | |
| 114 } | |
| 115 | |
| 116 void ChromeClientImpl::takeFocus(FocusType type) | |
| 117 { | |
| 118 if (!m_webView->client()) | |
| 119 return; | |
| 120 if (type == FocusTypeBackward) | |
| 121 m_webView->client()->focusPrevious(); | |
| 122 else | |
| 123 m_webView->client()->focusNext(); | |
| 124 } | |
| 125 | |
| 126 void ChromeClientImpl::focusedNodeChanged(Node* node) | |
| 127 { | |
| 128 m_webView->client()->focusedNodeChanged(WebNode(node)); | |
| 129 } | |
| 130 | |
| 131 void ChromeClientImpl::focusedFrameChanged(LocalFrame* frame) | |
| 132 { | |
| 133 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame); | |
| 134 if (webframe && webframe->client()) | |
| 135 webframe->client()->frameFocused(); | |
| 136 } | |
| 137 | |
| 138 WebNavigationPolicy ChromeClientImpl::getNavigationPolicy() | |
| 139 { | |
| 140 return WebNavigationPolicyCurrentTab; | |
| 141 } | |
| 142 | |
| 143 bool ChromeClientImpl::shouldReportDetailedMessageForSource(const String& url) | |
| 144 { | |
| 145 WebLocalFrameImpl* webframe = m_webView->mainFrameImpl(); | |
| 146 return webframe->client() && webframe->client()->shouldReportDetailedMessage
ForSource(url); | |
| 147 } | |
| 148 | |
| 149 inline static String messageLevelAsString(MessageLevel level) | |
| 150 { | |
| 151 switch(level) { | |
| 152 case DebugMessageLevel: | |
| 153 return "DEBUG"; | |
| 154 case LogMessageLevel: | |
| 155 return "LOG"; | |
| 156 case WarningMessageLevel: | |
| 157 return "WARNING"; | |
| 158 case ErrorMessageLevel: | |
| 159 return "ERROR"; | |
| 160 case InfoMessageLevel: | |
| 161 return "INFO"; | |
| 162 } | |
| 163 return "MESSAGE:"; | |
| 164 } | |
| 165 | |
| 166 | |
| 167 void ChromeClientImpl::addMessageToConsole(LocalFrame* localFrame, MessageSource
source, MessageLevel level, const String& message, unsigned lineNumber, const S
tring& sourceID, const String& stackTrace) | |
| 168 { | |
| 169 | |
| 170 if (level == ErrorMessageLevel) { | |
| 171 printf("ERROR: %s \nSOURCE: %s:%u\n", message.utf8().data(), sourceID.ut
f8().data(), lineNumber); | |
| 172 } else { | |
| 173 #if OS(ANDROID) | |
| 174 LOG(INFO) << "CONSOLE: " << messageLevelAsString(level).utf8().data() | |
| 175 << ": " << message.utf8().data(); | |
| 176 #else | |
| 177 printf("CONSOLE: %s: %s\n", messageLevelAsString(level).utf8().data(), m
essage.utf8().data()); | |
| 178 #endif | |
| 179 } | |
| 180 fflush(stdout); | |
| 181 | |
| 182 WebLocalFrameImpl* frame = WebLocalFrameImpl::fromFrame(localFrame); | |
| 183 if (frame && frame->client()) { | |
| 184 frame->client()->didAddMessageToConsole( | |
| 185 WebConsoleMessage(static_cast<WebConsoleMessage::Level>(level), mess
age), | |
| 186 sourceID, | |
| 187 lineNumber, | |
| 188 stackTrace); | |
| 189 } | |
| 190 } | |
| 191 | |
| 192 void ChromeClientImpl::scheduleVisualUpdate() | |
| 193 { | |
| 194 m_webView->scheduleVisualUpdate(); | |
| 195 } | |
| 196 | |
| 197 IntRect ChromeClientImpl::rootViewToScreen(const IntRect& rect) const | |
| 198 { | |
| 199 IntRect screenRect(rect); | |
| 200 | |
| 201 if (m_webView->client()) { | |
| 202 WebRect windowRect = m_webView->client()->windowRect(); | |
| 203 screenRect.move(windowRect.x, windowRect.y); | |
| 204 } | |
| 205 | |
| 206 return screenRect; | |
| 207 } | |
| 208 | |
| 209 WebScreenInfo ChromeClientImpl::screenInfo() const | |
| 210 { | |
| 211 return m_webView->client() ? m_webView->client()->screenInfo() : WebScreenIn
fo(); | |
| 212 } | |
| 213 | |
| 214 String ChromeClientImpl::acceptLanguages() | |
| 215 { | |
| 216 return m_webView->client()->acceptLanguages(); | |
| 217 } | |
| 218 | |
| 219 } // namespace blink | |
| OLD | NEW |