| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010-2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2010-2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "WebDevToolsAgentImpl.h" | 32 #include "WebDevToolsAgentImpl.h" |
| 33 | 33 |
| 34 #include "InspectorBackendDispatcher.h" | 34 #include "InspectorBackendDispatcher.h" |
| 35 #include "InspectorFrontend.h" | 35 #include "InspectorFrontend.h" |
| 36 #include "InspectorProtocolVersion.h" | 36 #include "InspectorProtocolVersion.h" |
| 37 #include "RuntimeEnabledFeatures.h" |
| 37 #include "WebDataSource.h" | 38 #include "WebDataSource.h" |
| 38 #include "WebDevToolsAgentClient.h" | 39 #include "WebDevToolsAgentClient.h" |
| 39 #include "WebFrameImpl.h" | 40 #include "WebFrameImpl.h" |
| 40 #include "WebInputEventConversion.h" | 41 #include "WebInputEventConversion.h" |
| 41 #include "WebMemoryUsageInfo.h" | 42 #include "WebMemoryUsageInfo.h" |
| 43 #include "WebSettings.h" |
| 42 #include "WebViewClient.h" | 44 #include "WebViewClient.h" |
| 43 #include "WebViewImpl.h" | 45 #include "WebViewImpl.h" |
| 44 #include "bindings/v8/PageScriptDebugServer.h" | 46 #include "bindings/v8/PageScriptDebugServer.h" |
| 45 #include "bindings/v8/ScriptController.h" | 47 #include "bindings/v8/ScriptController.h" |
| 46 #include "bindings/v8/V8Binding.h" | 48 #include "bindings/v8/V8Binding.h" |
| 47 #include "bindings/v8/V8Utilities.h" | 49 #include "bindings/v8/V8Utilities.h" |
| 48 #include "core/dom/ExceptionCode.h" | 50 #include "core/dom/ExceptionCode.h" |
| 49 #include "core/fetch/MemoryCache.h" | 51 #include "core/fetch/MemoryCache.h" |
| 50 #include "core/inspector/InjectedScriptHost.h" | 52 #include "core/inspector/InjectedScriptHost.h" |
| 51 #include "core/inspector/InspectorController.h" | 53 #include "core/inspector/InspectorController.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 virtual void run() | 182 virtual void run() |
| 181 { | 183 { |
| 182 if (WebDevToolsAgent* webagent = m_descriptor->agent()) | 184 if (WebDevToolsAgent* webagent = m_descriptor->agent()) |
| 183 webagent->dispatchOnInspectorBackend(m_descriptor->message()); | 185 webagent->dispatchOnInspectorBackend(m_descriptor->message()); |
| 184 } | 186 } |
| 185 | 187 |
| 186 private: | 188 private: |
| 187 OwnPtr<WebDevToolsAgent::MessageDescriptor> m_descriptor; | 189 OwnPtr<WebDevToolsAgent::MessageDescriptor> m_descriptor; |
| 188 }; | 190 }; |
| 189 | 191 |
| 190 class DeviceMetricsSupport { | |
| 191 public: | |
| 192 DeviceMetricsSupport(WebViewImpl* webView) | |
| 193 : m_webView(webView) | |
| 194 , m_fitWindow(false) | |
| 195 , m_originalZoomFactor(0) | |
| 196 { | |
| 197 } | |
| 198 | |
| 199 ~DeviceMetricsSupport() | |
| 200 { | |
| 201 restore(); | |
| 202 } | |
| 203 | |
| 204 void setDeviceMetrics(int width, int height, float textZoomFactor, bool fitW
indow) | |
| 205 { | |
| 206 WebCore::FrameView* view = frameView(); | |
| 207 if (!view) | |
| 208 return; | |
| 209 | |
| 210 m_emulatedFrameSize = WebSize(width, height); | |
| 211 m_fitWindow = fitWindow; | |
| 212 m_originalZoomFactor = 0; | |
| 213 m_webView->setTextZoomFactor(textZoomFactor); | |
| 214 applySizeOverrideInternal(view, FitWindowAllowed); | |
| 215 autoZoomPageToFitWidth(&view->frame()); | |
| 216 | |
| 217 m_webView->sendResizeEventAndRepaint(); | |
| 218 } | |
| 219 | |
| 220 void autoZoomPageToFitWidthOnNavigation(Frame* frame) | |
| 221 { | |
| 222 FrameView* frameView = frame->view(); | |
| 223 applySizeOverrideInternal(frameView, FitWindowNotAllowed); | |
| 224 m_originalZoomFactor = 0; | |
| 225 applySizeOverrideInternal(frameView, FitWindowAllowed); | |
| 226 autoZoomPageToFitWidth(frame); | |
| 227 } | |
| 228 | |
| 229 void autoZoomPageToFitWidth(Frame* frame) | |
| 230 { | |
| 231 frame->setTextZoomFactor(m_webView->textZoomFactor()); | |
| 232 ensureOriginalZoomFactor(frame->view()); | |
| 233 Document* document = frame->document(); | |
| 234 float numerator = document->renderView() ? document->renderView()->viewW
idth() : frame->view()->contentsWidth(); | |
| 235 float factor = m_originalZoomFactor * (numerator / m_emulatedFrameSize.w
idth); | |
| 236 frame->setPageAndTextZoomFactors(factor, m_webView->textZoomFactor()); | |
| 237 document->styleResolverChanged(RecalcStyleImmediately); | |
| 238 document->updateLayout(); | |
| 239 } | |
| 240 | |
| 241 void webViewResized() | |
| 242 { | |
| 243 if (!m_fitWindow) | |
| 244 return; | |
| 245 | |
| 246 applySizeOverrideIfNecessary(); | |
| 247 autoZoomPageToFitWidth(m_webView->mainFrameImpl()->frame()); | |
| 248 } | |
| 249 | |
| 250 void applySizeOverrideIfNecessary() | |
| 251 { | |
| 252 FrameView* view = frameView(); | |
| 253 if (!view) | |
| 254 return; | |
| 255 | |
| 256 applySizeOverrideInternal(view, FitWindowAllowed); | |
| 257 } | |
| 258 | |
| 259 private: | |
| 260 enum FitWindowFlag { FitWindowAllowed, FitWindowNotAllowed }; | |
| 261 | |
| 262 void ensureOriginalZoomFactor(FrameView* frameView) | |
| 263 { | |
| 264 if (m_originalZoomFactor) | |
| 265 return; | |
| 266 | |
| 267 m_webView->setPageScaleFactor(1, WebPoint()); | |
| 268 m_webView->setZoomLevel(0); | |
| 269 WebSize scaledEmulatedSize = scaledEmulatedFrameSize(frameView); | |
| 270 double denominator = frameView->contentsWidth(); | |
| 271 if (!denominator) | |
| 272 denominator = 1; | |
| 273 m_originalZoomFactor = static_cast<double>(scaledEmulatedSize.width) / d
enominator; | |
| 274 } | |
| 275 | |
| 276 void restore() | |
| 277 { | |
| 278 WebCore::FrameView* view = frameView(); | |
| 279 if (!view) | |
| 280 return; | |
| 281 | |
| 282 m_webView->setZoomLevel(0); | |
| 283 m_webView->setTextZoomFactor(1); | |
| 284 view->setHorizontalScrollbarLock(false); | |
| 285 view->setVerticalScrollbarLock(false); | |
| 286 view->setScrollbarModes(ScrollbarAuto, ScrollbarAuto, false, false); | |
| 287 view->setFrameRect(IntRect(IntPoint(), IntSize(m_webView->size()))); | |
| 288 m_webView->sendResizeEventAndRepaint(); | |
| 289 } | |
| 290 | |
| 291 WebSize scaledEmulatedFrameSize(FrameView* frameView) | |
| 292 { | |
| 293 if (!m_fitWindow) | |
| 294 return m_emulatedFrameSize; | |
| 295 | |
| 296 WebSize scrollbarDimensions = forcedScrollbarDimensions(frameView); | |
| 297 | |
| 298 int overrideWidth = m_emulatedFrameSize.width; | |
| 299 int overrideHeight = m_emulatedFrameSize.height; | |
| 300 | |
| 301 WebSize webViewSize = m_webView->size(); | |
| 302 int availableViewWidth = max(webViewSize.width - scrollbarDimensions.wid
th, 1); | |
| 303 int availableViewHeight = max(webViewSize.height - scrollbarDimensions.h
eight, 1); | |
| 304 | |
| 305 double widthRatio = static_cast<double>(overrideWidth) / availableViewWi
dth; | |
| 306 double heightRatio = static_cast<double>(overrideHeight) / availableView
Height; | |
| 307 double dimensionRatio = max(widthRatio, heightRatio); | |
| 308 overrideWidth = static_cast<int>(ceil(static_cast<double>(overrideWidth)
/ dimensionRatio)); | |
| 309 overrideHeight = static_cast<int>(ceil(static_cast<double>(overrideHeigh
t) / dimensionRatio)); | |
| 310 | |
| 311 return WebSize(overrideWidth, overrideHeight); | |
| 312 } | |
| 313 | |
| 314 WebSize forcedScrollbarDimensions(FrameView* frameView) | |
| 315 { | |
| 316 frameView->setScrollbarModes(ScrollbarAlwaysOn, ScrollbarAlwaysOn, true,
true); | |
| 317 | |
| 318 int verticalScrollbarWidth = 0; | |
| 319 int horizontalScrollbarHeight = 0; | |
| 320 if (Scrollbar* verticalBar = frameView->verticalScrollbar()) | |
| 321 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? vertic
alBar->width() : 0; | |
| 322 if (Scrollbar* horizontalBar = frameView->horizontalScrollbar()) | |
| 323 horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? h
orizontalBar->height() : 0; | |
| 324 return WebSize(verticalScrollbarWidth, horizontalScrollbarHeight); | |
| 325 } | |
| 326 | |
| 327 void applySizeOverrideInternal(FrameView* frameView, FitWindowFlag fitWindow
Flag) | |
| 328 { | |
| 329 WebSize scrollbarDimensions = forcedScrollbarDimensions(frameView); | |
| 330 | |
| 331 WebSize effectiveEmulatedSize = (fitWindowFlag == FitWindowAllowed) ? sc
aledEmulatedFrameSize(frameView) : m_emulatedFrameSize; | |
| 332 int overrideWidth = effectiveEmulatedSize.width + scrollbarDimensions.wi
dth; | |
| 333 int overrideHeight = effectiveEmulatedSize.height + scrollbarDimensions.
height; | |
| 334 | |
| 335 if (IntSize(overrideWidth, overrideHeight) != frameView->size()) | |
| 336 frameView->resize(overrideWidth, overrideHeight); | |
| 337 | |
| 338 Document* doc = frameView->frame().document(); | |
| 339 doc->styleResolverChanged(RecalcStyleImmediately); | |
| 340 doc->updateLayout(); | |
| 341 } | |
| 342 | |
| 343 WebCore::FrameView* frameView() | |
| 344 { | |
| 345 return m_webView->mainFrameImpl() ? m_webView->mainFrameImpl()->frameVie
w() : 0; | |
| 346 } | |
| 347 | |
| 348 WebViewImpl* m_webView; | |
| 349 WebSize m_emulatedFrameSize; | |
| 350 bool m_fitWindow; | |
| 351 double m_originalZoomFactor; | |
| 352 }; | |
| 353 | |
| 354 WebDevToolsAgentImpl::WebDevToolsAgentImpl( | 192 WebDevToolsAgentImpl::WebDevToolsAgentImpl( |
| 355 WebViewImpl* webViewImpl, | 193 WebViewImpl* webViewImpl, |
| 356 WebDevToolsAgentClient* client) | 194 WebDevToolsAgentClient* client) |
| 357 : m_hostId(client->hostIdentifier()) | 195 : m_hostId(client->hostIdentifier()) |
| 358 , m_client(client) | 196 , m_client(client) |
| 359 , m_webViewImpl(webViewImpl) | 197 , m_webViewImpl(webViewImpl) |
| 360 , m_attached(false) | 198 , m_attached(false) |
| 199 , m_deviceMetricsEnabled(false) |
| 200 , m_isOverlayScrollbarsEnabled(false) |
| 361 { | 201 { |
| 362 ASSERT(m_hostId > 0); | 202 ASSERT(m_hostId > 0); |
| 363 ClientMessageLoopAdapter::ensureClientMessageLoopCreated(m_client); | 203 ClientMessageLoopAdapter::ensureClientMessageLoopCreated(m_client); |
| 364 } | 204 } |
| 365 | 205 |
| 366 WebDevToolsAgentImpl::~WebDevToolsAgentImpl() | 206 WebDevToolsAgentImpl::~WebDevToolsAgentImpl() |
| 367 { | 207 { |
| 368 ClientMessageLoopAdapter::inspectedViewClosed(m_webViewImpl); | 208 ClientMessageLoopAdapter::inspectedViewClosed(m_webViewImpl); |
| 369 if (m_attached) | 209 if (m_attached) |
| 370 WebKit::Platform::current()->currentThread()->removeTaskObserver(this); | 210 WebKit::Platform::current()->currentThread()->removeTaskObserver(this); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 273 |
| 434 void WebDevToolsAgentImpl::didCreateScriptContext(WebFrameImpl* webframe, int wo
rldId) | 274 void WebDevToolsAgentImpl::didCreateScriptContext(WebFrameImpl* webframe, int wo
rldId) |
| 435 { | 275 { |
| 436 // Skip non main world contexts. | 276 // Skip non main world contexts. |
| 437 if (worldId) | 277 if (worldId) |
| 438 return; | 278 return; |
| 439 if (WebCore::Frame* frame = webframe->frame()) | 279 if (WebCore::Frame* frame = webframe->frame()) |
| 440 frame->script()->setContextDebugId(m_hostId); | 280 frame->script()->setContextDebugId(m_hostId); |
| 441 } | 281 } |
| 442 | 282 |
| 443 void WebDevToolsAgentImpl::mainFrameViewCreated(WebFrameImpl* webFrame) | |
| 444 { | |
| 445 if (m_metricsSupport) | |
| 446 m_metricsSupport->applySizeOverrideIfNecessary(); | |
| 447 } | |
| 448 | |
| 449 bool WebDevToolsAgentImpl::metricsOverridden() | |
| 450 { | |
| 451 return !!m_metricsSupport; | |
| 452 } | |
| 453 | |
| 454 void WebDevToolsAgentImpl::webViewResized(const WebSize& size) | 283 void WebDevToolsAgentImpl::webViewResized(const WebSize& size) |
| 455 { | 284 { |
| 456 if (m_metricsSupport) | |
| 457 m_metricsSupport->webViewResized(); | |
| 458 if (InspectorController* ic = inspectorController()) | 285 if (InspectorController* ic = inspectorController()) |
| 459 ic->webViewResized(m_metricsSupport ? IntSize(size.width, size.height) :
IntSize()); | 286 ic->webViewResized(IntSize()); |
| 460 } | 287 } |
| 461 | 288 |
| 462 bool WebDevToolsAgentImpl::handleInputEvent(WebCore::Page* page, const WebInputE
vent& inputEvent) | 289 bool WebDevToolsAgentImpl::handleInputEvent(WebCore::Page* page, const WebInputE
vent& inputEvent) |
| 463 { | 290 { |
| 464 if (!m_attached) | 291 if (!m_attached) |
| 465 return false; | 292 return false; |
| 466 | 293 |
| 467 InspectorController* ic = inspectorController(); | 294 InspectorController* ic = inspectorController(); |
| 468 if (!ic) | 295 if (!ic) |
| 469 return false; | 296 return false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 481 if (WebInputEvent::isTouchEventType(inputEvent.type)) { | 308 if (WebInputEvent::isTouchEventType(inputEvent.type)) { |
| 482 PlatformTouchEvent touchEvent = PlatformTouchEventBuilder(page->mainFram
e()->view(), *static_cast<const WebTouchEvent*>(&inputEvent)); | 309 PlatformTouchEvent touchEvent = PlatformTouchEventBuilder(page->mainFram
e()->view(), *static_cast<const WebTouchEvent*>(&inputEvent)); |
| 483 return ic->handleTouchEvent(page->mainFrame(), touchEvent); | 310 return ic->handleTouchEvent(page->mainFrame(), touchEvent); |
| 484 } | 311 } |
| 485 return false; | 312 return false; |
| 486 } | 313 } |
| 487 | 314 |
| 488 void WebDevToolsAgentImpl::overrideDeviceMetrics(int width, int height, float fo
ntScaleFactor, bool fitWindow) | 315 void WebDevToolsAgentImpl::overrideDeviceMetrics(int width, int height, float fo
ntScaleFactor, bool fitWindow) |
| 489 { | 316 { |
| 490 if (!width && !height) { | 317 if (!width && !height) { |
| 491 if (m_metricsSupport) | 318 if (m_deviceMetricsEnabled) { |
| 492 m_metricsSupport.clear(); | 319 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(m_isOverlayScrol
lbarsEnabled); |
| 493 if (InspectorController* ic = inspectorController()) | 320 m_client->disableDeviceEmulation(); |
| 494 ic->webViewResized(IntSize()); | 321 } |
| 495 return; | 322 m_deviceMetricsEnabled = false; |
| 323 } else { |
| 324 if (!m_deviceMetricsEnabled) { |
| 325 m_isOverlayScrollbarsEnabled = RuntimeEnabledFeatures::overlayScroll
barsEnabled(); |
| 326 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); |
| 327 } |
| 328 m_client->enableDeviceEmulation(IntSize(width, height), IntRect(0, 0, wi
dth, height), 2, fitWindow); |
| 329 m_deviceMetricsEnabled = true; |
| 496 } | 330 } |
| 497 | |
| 498 if (!m_metricsSupport) | |
| 499 m_metricsSupport = adoptPtr(new DeviceMetricsSupport(m_webViewImpl)); | |
| 500 | |
| 501 m_metricsSupport->setDeviceMetrics(width, height, fontScaleFactor, fitWindow
); | |
| 502 if (InspectorController* ic = inspectorController()) { | |
| 503 WebSize size = m_webViewImpl->size(); | |
| 504 ic->webViewResized(IntSize(size.width, size.height)); | |
| 505 } | |
| 506 } | |
| 507 | |
| 508 void WebDevToolsAgentImpl::autoZoomPageToFitWidth() | |
| 509 { | |
| 510 if (m_metricsSupport) | |
| 511 m_metricsSupport->autoZoomPageToFitWidthOnNavigation(m_webViewImpl->main
FrameImpl()->frame()); | |
| 512 } | 331 } |
| 513 | 332 |
| 514 void WebDevToolsAgentImpl::getAllocatedObjects(HashSet<const void*>& set) | 333 void WebDevToolsAgentImpl::getAllocatedObjects(HashSet<const void*>& set) |
| 515 { | 334 { |
| 516 class CountingVisitor : public WebDevToolsAgentClient::AllocatedObjectVisito
r { | 335 class CountingVisitor : public WebDevToolsAgentClient::AllocatedObjectVisito
r { |
| 517 public: | 336 public: |
| 518 CountingVisitor() : m_totalObjectsCount(0) | 337 CountingVisitor() : m_totalObjectsCount(0) |
| 519 { | 338 { |
| 520 } | 339 } |
| 521 | 340 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 || commandName == InspectorBackendDispatcher::commandNames[InspectorBack
endDispatcher::kProfiler_getCPUProfileCmd] | 579 || commandName == InspectorBackendDispatcher::commandNames[InspectorBack
endDispatcher::kProfiler_getCPUProfileCmd] |
| 761 || commandName == InspectorBackendDispatcher::commandNames[InspectorBack
endDispatcher::kHeapProfiler_getHeapSnapshotCmd]; | 580 || commandName == InspectorBackendDispatcher::commandNames[InspectorBack
endDispatcher::kHeapProfiler_getHeapSnapshotCmd]; |
| 762 } | 581 } |
| 763 | 582 |
| 764 void WebDevToolsAgent::processPendingMessages() | 583 void WebDevToolsAgent::processPendingMessages() |
| 765 { | 584 { |
| 766 PageScriptDebugServer::shared().runPendingTasks(); | 585 PageScriptDebugServer::shared().runPendingTasks(); |
| 767 } | 586 } |
| 768 | 587 |
| 769 } // namespace WebKit | 588 } // namespace WebKit |
| OLD | NEW |