| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 82 #include "platform/graphics/GraphicsContext.h" | 82 #include "platform/graphics/GraphicsContext.h" | 
| 83 #include "platform/graphics/paint/DisplayItemList.h" | 83 #include "platform/graphics/paint/DisplayItemList.h" | 
| 84 #include "public/platform/Platform.h" | 84 #include "public/platform/Platform.h" | 
| 85 #include "public/platform/WebRect.h" | 85 #include "public/platform/WebRect.h" | 
| 86 #include "public/platform/WebString.h" | 86 #include "public/platform/WebString.h" | 
| 87 #include "public/web/WebDevToolsAgentClient.h" | 87 #include "public/web/WebDevToolsAgentClient.h" | 
| 88 #include "public/web/WebDeviceEmulationParams.h" | 88 #include "public/web/WebDeviceEmulationParams.h" | 
| 89 #include "public/web/WebSettings.h" | 89 #include "public/web/WebSettings.h" | 
| 90 #include "public/web/WebViewClient.h" | 90 #include "public/web/WebViewClient.h" | 
| 91 #include "web/DevToolsEmulator.h" | 91 #include "web/DevToolsEmulator.h" | 
|  | 92 #include "web/WebFrameWidgetImpl.h" | 
| 92 #include "web/WebInputEventConversion.h" | 93 #include "web/WebInputEventConversion.h" | 
| 93 #include "web/WebLocalFrameImpl.h" | 94 #include "web/WebLocalFrameImpl.h" | 
| 94 #include "web/WebSettingsImpl.h" | 95 #include "web/WebSettingsImpl.h" | 
| 95 #include "web/WebViewImpl.h" | 96 #include "web/WebViewImpl.h" | 
| 96 #include "wtf/MathExtras.h" | 97 #include "wtf/MathExtras.h" | 
| 97 #include "wtf/Noncopyable.h" | 98 #include "wtf/Noncopyable.h" | 
| 98 #include "wtf/ProcessID.h" | 99 #include "wtf/ProcessID.h" | 
| 99 #include "wtf/text/WTFString.h" | 100 #include "wtf/text/WTFString.h" | 
| 100 | 101 | 
| 101 namespace blink { | 102 namespace blink { | 
| 102 | 103 | 
| 103 class ClientMessageLoopAdapter : public PageScriptDebugServer::ClientMessageLoop
      { | 104 class ClientMessageLoopAdapter : public PageScriptDebugServer::ClientMessageLoop
      { | 
| 104 public: | 105 public: | 
| 105     ~ClientMessageLoopAdapter() override | 106     ~ClientMessageLoopAdapter() override | 
| 106     { | 107     { | 
| 107         s_instance = nullptr; | 108         s_instance = nullptr; | 
| 108     } | 109     } | 
| 109 | 110 | 
| 110     static void ensurePageScriptDebugServerCreated(WebDevToolsAgentClient* clien
     t) | 111     static void ensurePageScriptDebugServerCreated(WebDevToolsAgentClient* clien
     t) | 
| 111     { | 112     { | 
| 112         if (s_instance) | 113         if (s_instance) | 
| 113             return; | 114             return; | 
| 114         OwnPtr<ClientMessageLoopAdapter> instance = adoptPtr(new ClientMessageLo
     opAdapter(adoptPtr(client->createClientMessageLoop()))); | 115         OwnPtr<ClientMessageLoopAdapter> instance = adoptPtr(new ClientMessageLo
     opAdapter(adoptPtr(client->createClientMessageLoop()))); | 
| 115         s_instance = instance.get(); | 116         s_instance = instance.get(); | 
| 116         v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); | 117         v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); | 
| 117         V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 118         V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 
| 118         data->setScriptDebugServer(adoptPtrWillBeNoop(new PageScriptDebugServer(
     instance.release(), isolate))); | 119         data->setScriptDebugServer(adoptPtrWillBeNoop(new PageScriptDebugServer(
     instance.release(), isolate))); | 
| 119     } | 120     } | 
| 120 | 121 | 
| 121     static void inspectedViewClosed(WebViewImpl* view) | 122     static void webViewImplClosed(WebViewImpl* view) | 
| 122     { | 123     { | 
| 123         if (s_instance) | 124         if (s_instance) | 
| 124             s_instance->m_frozenViews.remove(view); | 125             s_instance->m_frozenViews.remove(view); | 
| 125     } | 126     } | 
| 126 | 127 | 
| 127     static void didNavigate() | 128     static void webFrameWidgetImplClosed(WebFrameWidgetImpl* widget) | 
|  | 129     { | 
|  | 130         if (s_instance) | 
|  | 131             s_instance->m_frozenWidgets.remove(widget); | 
|  | 132     } | 
|  | 133 | 
|  | 134     static void continueProgram() | 
| 128     { | 135     { | 
| 129         // Release render thread if necessary. | 136         // Release render thread if necessary. | 
| 130         if (s_instance && s_instance->m_running) | 137         if (s_instance && s_instance->m_running) | 
| 131             PageScriptDebugServer::instance()->continueProgram(); | 138             PageScriptDebugServer::instance()->continueProgram(); | 
| 132     } | 139     } | 
| 133 | 140 | 
| 134 private: | 141 private: | 
| 135     ClientMessageLoopAdapter(PassOwnPtr<WebDevToolsAgentClient::WebKitClientMess
     ageLoop> messageLoop) | 142     ClientMessageLoopAdapter(PassOwnPtr<WebDevToolsAgentClient::WebKitClientMess
     ageLoop> messageLoop) | 
| 136         : m_running(false) | 143         : m_running(false) | 
| 137         , m_messageLoop(messageLoop) { } | 144         , m_messageLoop(messageLoop) { } | 
| 138 | 145 | 
| 139     void run(LocalFrame* frame) override | 146     void run(LocalFrame* frame) override | 
| 140     { | 147     { | 
| 141         if (m_running) | 148         if (m_running) | 
| 142             return; | 149             return; | 
| 143         m_running = true; | 150         m_running = true; | 
| 144 | 151 | 
| 145         // 0. Flush pending frontend messages. | 152         // 0. Flush pending frontend messages. | 
| 146         WebViewImpl* viewImpl = WebViewImpl::fromPage(frame->page()); | 153         WebViewImpl* viewImpl = WebViewImpl::fromPage(frame->page()); | 
| 147         WebDevToolsAgentImpl* agent = static_cast<WebDevToolsAgentImpl*>(viewImp
     l->devToolsAgent()); | 154         WebDevToolsAgentImpl* agent = static_cast<WebDevToolsAgentImpl*>(viewImp
     l->devToolsAgent()); | 
| 148         agent->flushPendingProtocolNotifications(); | 155         agent->flushPendingProtocolNotifications(); | 
| 149 | 156 | 
| 150         Vector<WebViewImpl*> views; | 157         Vector<WebViewImpl*> views; | 
|  | 158         Vector<WebFrameWidgetImpl*> widgets; | 
| 151 | 159 | 
| 152         // 1. Disable input events. | 160         // 1. Disable input events. | 
| 153         const HashSet<Page*>& pages = Page::ordinaryPages(); | 161         const HashSet<WebViewImpl*>& viewImpls = WebViewImpl::allInstances(); | 
| 154         HashSet<Page*>::const_iterator end = pages.end(); | 162         HashSet<WebViewImpl*>::const_iterator viewImplsEnd = viewImpls.end(); | 
| 155         for (HashSet<Page*>::const_iterator it =  pages.begin(); it != end; ++it
     ) { | 163         for (HashSet<WebViewImpl*>::const_iterator it =  viewImpls.begin(); it !
     = viewImplsEnd; ++it) { | 
| 156             WebViewImpl* view = WebViewImpl::fromPage(*it); | 164             WebViewImpl* view = *it; | 
| 157             if (!view) |  | 
| 158                 continue; |  | 
| 159             m_frozenViews.add(view); | 165             m_frozenViews.add(view); | 
| 160             views.append(view); | 166             views.append(view); | 
| 161             view->setIgnoreInputEvents(true); | 167             view->setIgnoreInputEvents(true); | 
| 162         } | 168         } | 
| 163         // Notify embedder about pausing. | 169 | 
|  | 170         const HashSet<WebFrameWidgetImpl*>& widgetImpls = WebFrameWidgetImpl::al
     lInstances(); | 
|  | 171         HashSet<WebFrameWidgetImpl*>::const_iterator widgetImplsEnd = widgetImpl
     s.end(); | 
|  | 172         for (HashSet<WebFrameWidgetImpl*>::const_iterator it =  widgetImpls.begi
     n(); it != widgetImplsEnd; ++it) { | 
|  | 173             WebFrameWidgetImpl* widget = *it; | 
|  | 174             m_frozenWidgets.add(widget); | 
|  | 175             widgets.append(widget); | 
|  | 176             widget->setIgnoreInputEvents(true); | 
|  | 177         } | 
|  | 178 | 
|  | 179         // 2. Notify embedder about pausing. | 
| 164         agent->client()->willEnterDebugLoop(); | 180         agent->client()->willEnterDebugLoop(); | 
| 165 | 181 | 
| 166         // 2. Disable active objects | 182         // 3. Disable active objects | 
| 167         WebView::willEnterModalLoop(); | 183         WebView::willEnterModalLoop(); | 
| 168 | 184 | 
| 169         // 3. Process messages until quitNow is called. | 185         // 4. Process messages until quitNow is called. | 
| 170         m_messageLoop->run(); | 186         m_messageLoop->run(); | 
| 171 | 187 | 
| 172         // 4. Resume active objects | 188         // 5. Resume active objects | 
| 173         WebView::didExitModalLoop(); | 189         WebView::didExitModalLoop(); | 
| 174 | 190 | 
| 175         // 5. Resume input events. | 191         // 6. Resume input events. | 
| 176         for (Vector<WebViewImpl*>::iterator it = views.begin(); it != views.end(
     ); ++it) { | 192         for (Vector<WebViewImpl*>::iterator it = views.begin(); it != views.end(
     ); ++it) { | 
| 177             if (m_frozenViews.contains(*it)) { | 193             if (m_frozenViews.contains(*it)) { | 
| 178                 // The view was not closed during the dispatch. | 194                 // The view was not closed during the dispatch. | 
| 179                 (*it)->setIgnoreInputEvents(false); | 195                 (*it)->setIgnoreInputEvents(false); | 
| 180             } | 196             } | 
| 181         } | 197         } | 
|  | 198         for (Vector<WebFrameWidgetImpl*>::iterator it = widgets.begin(); it != w
     idgets.end(); ++it) { | 
|  | 199             if (m_frozenWidgets.contains(*it)) { | 
|  | 200                 // The widget was not closed during the dispatch. | 
|  | 201                 (*it)->setIgnoreInputEvents(false); | 
|  | 202             } | 
|  | 203         } | 
|  | 204 | 
|  | 205         // 7. Notify embedder about resuming. | 
| 182         agent->client()->didExitDebugLoop(); | 206         agent->client()->didExitDebugLoop(); | 
| 183 | 207 | 
| 184         // 6. All views have been resumed, clear the set. | 208         // 8. All views have been resumed, clear the set. | 
| 185         m_frozenViews.clear(); | 209         m_frozenViews.clear(); | 
|  | 210         m_frozenWidgets.clear(); | 
| 186 | 211 | 
| 187         m_running = false; | 212         m_running = false; | 
| 188     } | 213     } | 
| 189 | 214 | 
| 190     void quitNow() override | 215     void quitNow() override | 
| 191     { | 216     { | 
| 192         m_messageLoop->quitNow(); | 217         m_messageLoop->quitNow(); | 
| 193     } | 218     } | 
| 194 | 219 | 
| 195     bool m_running; | 220     bool m_running; | 
| 196     OwnPtr<WebDevToolsAgentClient::WebKitClientMessageLoop> m_messageLoop; | 221     OwnPtr<WebDevToolsAgentClient::WebKitClientMessageLoop> m_messageLoop; | 
| 197     typedef HashSet<WebViewImpl*> FrozenViewsSet; | 222     typedef HashSet<WebViewImpl*> FrozenViewsSet; | 
| 198     FrozenViewsSet m_frozenViews; | 223     FrozenViewsSet m_frozenViews; | 
|  | 224     typedef HashSet<WebFrameWidgetImpl*> FrozenWidgetsSet; | 
|  | 225     FrozenWidgetsSet m_frozenWidgets; | 
| 199     static ClientMessageLoopAdapter* s_instance; | 226     static ClientMessageLoopAdapter* s_instance; | 
| 200 }; | 227 }; | 
| 201 | 228 | 
| 202 ClientMessageLoopAdapter* ClientMessageLoopAdapter::s_instance = nullptr; | 229 ClientMessageLoopAdapter* ClientMessageLoopAdapter::s_instance = nullptr; | 
| 203 | 230 | 
| 204 class DebuggerTask : public PageScriptDebugServer::Task { | 231 class DebuggerTask : public PageScriptDebugServer::Task { | 
| 205 public: | 232 public: | 
| 206     DebuggerTask(PassOwnPtr<WebDevToolsAgent::MessageDescriptor> descriptor) | 233     DebuggerTask(PassOwnPtr<WebDevToolsAgent::MessageDescriptor> descriptor) | 
| 207         : m_descriptor(descriptor) | 234         : m_descriptor(descriptor) | 
| 208     { | 235     { | 
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 298 | 325 | 
| 299 WebDevToolsAgentImpl::~WebDevToolsAgentImpl() | 326 WebDevToolsAgentImpl::~WebDevToolsAgentImpl() | 
| 300 { | 327 { | 
| 301     ASSERT(m_hasBeenDisposed); | 328     ASSERT(m_hasBeenDisposed); | 
| 302 } | 329 } | 
| 303 | 330 | 
| 304 void WebDevToolsAgentImpl::dispose() | 331 void WebDevToolsAgentImpl::dispose() | 
| 305 { | 332 { | 
| 306     // Explicitly dispose of the agent before destructing to ensure | 333     // Explicitly dispose of the agent before destructing to ensure | 
| 307     // same behavior (and correctness) with and without Oilpan. | 334     // same behavior (and correctness) with and without Oilpan. | 
| 308     ClientMessageLoopAdapter::inspectedViewClosed(m_webViewImpl); |  | 
| 309     if (m_attached) | 335     if (m_attached) | 
| 310         Platform::current()->currentThread()->removeTaskObserver(this); | 336         Platform::current()->currentThread()->removeTaskObserver(this); | 
| 311 #if ENABLE(ASSERT) | 337 #if ENABLE(ASSERT) | 
| 312     ASSERT(!m_hasBeenDisposed); | 338     ASSERT(!m_hasBeenDisposed); | 
| 313     m_hasBeenDisposed = true; | 339     m_hasBeenDisposed = true; | 
| 314 #endif | 340 #endif | 
| 315 } | 341 } | 
| 316 | 342 | 
|  | 343 // static | 
|  | 344 void WebDevToolsAgentImpl::webViewImplClosed(WebViewImpl* webViewImpl) | 
|  | 345 { | 
|  | 346     ClientMessageLoopAdapter::webViewImplClosed(webViewImpl); | 
|  | 347 } | 
|  | 348 | 
|  | 349 // static | 
|  | 350 void WebDevToolsAgentImpl::webFrameWidgetImplClosed(WebFrameWidgetImpl* webFrame
     WidgetImpl) | 
|  | 351 { | 
|  | 352     ClientMessageLoopAdapter::webFrameWidgetImplClosed(webFrameWidgetImpl); | 
|  | 353 } | 
|  | 354 | 
| 317 DEFINE_TRACE(WebDevToolsAgentImpl) | 355 DEFINE_TRACE(WebDevToolsAgentImpl) | 
| 318 { | 356 { | 
| 319     visitor->trace(m_instrumentingAgents); | 357     visitor->trace(m_instrumentingAgents); | 
| 320     visitor->trace(m_injectedScriptManager); | 358     visitor->trace(m_injectedScriptManager); | 
| 321     visitor->trace(m_state); | 359     visitor->trace(m_state); | 
| 322     visitor->trace(m_overlay); | 360     visitor->trace(m_overlay); | 
| 323     visitor->trace(m_asyncCallTracker); | 361     visitor->trace(m_asyncCallTracker); | 
| 324     visitor->trace(m_domAgent); | 362     visitor->trace(m_domAgent); | 
| 325     visitor->trace(m_pageAgent); | 363     visitor->trace(m_pageAgent); | 
| 326     visitor->trace(m_cssAgent); | 364     visitor->trace(m_cssAgent); | 
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 445     // Release overlay resources. | 483     // Release overlay resources. | 
| 446     m_overlay->clear(); | 484     m_overlay->clear(); | 
| 447     InspectorInstrumentation::frontendDeleted(); | 485     InspectorInstrumentation::frontendDeleted(); | 
| 448     InspectorInstrumentation::unregisterInstrumentingAgents(m_instrumentingAgent
     s.get()); | 486     InspectorInstrumentation::unregisterInstrumentingAgents(m_instrumentingAgent
     s.get()); | 
| 449 | 487 | 
| 450     m_attached = false; | 488     m_attached = false; | 
| 451 } | 489 } | 
| 452 | 490 | 
| 453 void WebDevToolsAgentImpl::continueProgram() | 491 void WebDevToolsAgentImpl::continueProgram() | 
| 454 { | 492 { | 
| 455     ClientMessageLoopAdapter::didNavigate(); | 493     ClientMessageLoopAdapter::continueProgram(); | 
| 456 } | 494 } | 
| 457 | 495 | 
| 458 bool WebDevToolsAgentImpl::handleInputEvent(Page* page, const WebInputEvent& inp
     utEvent) | 496 bool WebDevToolsAgentImpl::handleInputEvent(Page* page, const WebInputEvent& inp
     utEvent) | 
| 459 { | 497 { | 
| 460     if (!m_attached) | 498     if (!m_attached) | 
| 461         return false; | 499         return false; | 
| 462 | 500 | 
| 463     if (WebInputEvent::isGestureEventType(inputEvent.type) && inputEvent.type ==
      WebInputEvent::GestureTap) { | 501     if (WebInputEvent::isGestureEventType(inputEvent.type) && inputEvent.type ==
      WebInputEvent::GestureTap) { | 
| 464         // Only let GestureTab in (we only need it and we know PlatformGestureEv
     entBuilder supports it). | 502         // Only let GestureTab in (we only need it and we know PlatformGestureEv
     entBuilder supports it). | 
| 465         PlatformGestureEvent gestureEvent = PlatformGestureEventBuilder(page->de
     precatedLocalMainFrame()->view(), static_cast<const WebGestureEvent&>(inputEvent
     )); | 503         PlatformGestureEvent gestureEvent = PlatformGestureEventBuilder(page->de
     precatedLocalMainFrame()->view(), static_cast<const WebGestureEvent&>(inputEvent
     )); | 
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 685     if (!InspectorBackendDispatcher::getCommandName(message, &commandName)) | 723     if (!InspectorBackendDispatcher::getCommandName(message, &commandName)) | 
| 686         return false; | 724         return false; | 
| 687     return commandName == InspectorBackendDispatcher::commandName(InspectorBacke
     ndDispatcher::kDebugger_pauseCmd) | 725     return commandName == InspectorBackendDispatcher::commandName(InspectorBacke
     ndDispatcher::kDebugger_pauseCmd) | 
| 688         || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
     ndDispatcher::kDebugger_setBreakpointCmd) | 726         || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
     ndDispatcher::kDebugger_setBreakpointCmd) | 
| 689         || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
     ndDispatcher::kDebugger_setBreakpointByUrlCmd) | 727         || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
     ndDispatcher::kDebugger_setBreakpointByUrlCmd) | 
| 690         || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
     ndDispatcher::kDebugger_removeBreakpointCmd) | 728         || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
     ndDispatcher::kDebugger_removeBreakpointCmd) | 
| 691         || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
     ndDispatcher::kDebugger_setBreakpointsActiveCmd); | 729         || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
     ndDispatcher::kDebugger_setBreakpointsActiveCmd); | 
| 692 } | 730 } | 
| 693 | 731 | 
| 694 } // namespace blink | 732 } // namespace blink | 
| OLD | NEW | 
|---|