| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <signal.h> | 5 #include <signal.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 | 7 |
| 8 #if defined(OS_WIN) | 8 #if defined(OS_WIN) |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #endif | 10 #endif |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 break; | 70 break; |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 namespace webdriver { | 74 namespace webdriver { |
| 75 | 75 |
| 76 void InitCallbacks(struct mg_context* ctx, Dispatcher* dispatcher, | 76 void InitCallbacks(struct mg_context* ctx, Dispatcher* dispatcher, |
| 77 base::WaitableEvent* shutdown_event) { | 77 base::WaitableEvent* shutdown_event) { |
| 78 dispatcher->AddShutdown("/shutdown", shutdown_event); | 78 dispatcher->AddShutdown("/shutdown", shutdown_event); |
| 79 | 79 |
| 80 dispatcher->Add<CreateSession>( "/session"); | 80 dispatcher->Add<CreateSession>("/session"); |
| 81 dispatcher->Add<BackCommand>( "/session/*/back"); | |
| 82 dispatcher->Add<ExecuteCommand>( "/session/*/execute"); | |
| 83 dispatcher->Add<ForwardCommand>( "/session/*/forward"); | |
| 84 dispatcher->Add<SwitchFrameCommand>( "/session/*/frame"); | |
| 85 dispatcher->Add<RefreshCommand>( "/session/*/refresh"); | |
| 86 dispatcher->Add<SourceCommand>( "/session/*/source"); | |
| 87 dispatcher->Add<SpeedCommand>( "/session/*/speed"); | |
| 88 dispatcher->Add<TitleCommand>( "/session/*/title"); | |
| 89 dispatcher->Add<URLCommand>( "/session/*/url"); | |
| 90 dispatcher->Add<WindowCommand>( "/session/*/window"); | |
| 91 dispatcher->Add<WindowHandleCommand>( "/session/*/window_handle"); | |
| 92 dispatcher->Add<WindowHandlesCommand>("/session/*/window_handles"); | |
| 93 dispatcher->Add<ImplicitWaitCommand>( "/session/*/timeouts/implicit_wait"); | |
| 94 | |
| 95 // Cookie functions. | |
| 96 dispatcher->Add<CookieCommand>( "/session/*/cookie"); | |
| 97 dispatcher->Add<NamedCookieCommand>("/session/*/cookie/*"); | |
| 98 | 81 |
| 99 // WebElement commands | 82 // WebElement commands |
| 100 dispatcher->Add<FindOneElementCommand>( "/session/*/element"); | 83 dispatcher->Add<FindOneElementCommand>( "/session/*/element"); |
| 101 dispatcher->Add<FindManyElementsCommand>("/session/*/elements"); | 84 dispatcher->Add<FindManyElementsCommand>("/session/*/elements"); |
| 102 dispatcher->Add<ActiveElementCommand>( "/session/*/element/active"); | 85 dispatcher->Add<ActiveElementCommand>( "/session/*/element/active"); |
| 103 dispatcher->Add<FindOneElementCommand>( "/session/*/element/*/element"); | 86 dispatcher->Add<FindOneElementCommand>( "/session/*/element/*/element"); |
| 104 dispatcher->Add<FindManyElementsCommand>("/session/*/elements/*/elements"); | 87 dispatcher->Add<FindManyElementsCommand>("/session/*/elements/*/elements"); |
| 105 dispatcher->Add<ElementAttributeCommand>("/session/*/element/*/attribute/*"); | 88 dispatcher->Add<ElementAttributeCommand>("/session/*/element/*/attribute/*"); |
| 106 dispatcher->Add<ElementCssCommand>( "/session/*/element/*/css/*"); | 89 dispatcher->Add<ElementCssCommand>( "/session/*/element/*/css/*"); |
| 107 dispatcher->Add<ElementClearCommand>( "/session/*/element/*/clear"); | 90 dispatcher->Add<ElementClearCommand>( "/session/*/element/*/clear"); |
| 108 dispatcher->Add<ElementDisplayedCommand>("/session/*/element/*/displayed"); | 91 dispatcher->Add<ElementDisplayedCommand>("/session/*/element/*/displayed"); |
| 109 dispatcher->Add<ElementEnabledCommand>( "/session/*/element/*/enabled"); | 92 dispatcher->Add<ElementEnabledCommand>( "/session/*/element/*/enabled"); |
| 110 dispatcher->Add<ElementEqualsCommand>( "/session/*/element/*/equals/*"); | 93 dispatcher->Add<ElementEqualsCommand>( "/session/*/element/*/equals/*"); |
| 111 dispatcher->Add<ElementLocationCommand>( "/session/*/element/*/location"); | 94 dispatcher->Add<ElementLocationCommand>( "/session/*/element/*/location"); |
| 112 dispatcher->Add<ElementLocationInViewCommand>( | 95 dispatcher->Add<ElementLocationInViewCommand>( |
| 113 "/session/*/element/*/location_in_view"); | 96 "/session/*/element/*/location_in_view"); |
| 114 dispatcher->Add<ElementNameCommand>( "/session/*/element/*/name"); | 97 dispatcher->Add<ElementNameCommand>( "/session/*/element/*/name"); |
| 115 dispatcher->Add<ElementSelectedCommand>("/session/*/element/*/selected"); | 98 dispatcher->Add<ElementSelectedCommand>("/session/*/element/*/selected"); |
| 116 dispatcher->Add<ElementSizeCommand>( "/session/*/element/*/size"); | 99 dispatcher->Add<ElementSizeCommand>( "/session/*/element/*/size"); |
| 117 dispatcher->Add<ElementSubmitCommand>( "/session/*/element/*/submit"); | 100 dispatcher->Add<ElementSubmitCommand>( "/session/*/element/*/submit"); |
| 118 dispatcher->Add<ElementTextCommand>( "/session/*/element/*/text"); | 101 dispatcher->Add<ElementTextCommand>( "/session/*/element/*/text"); |
| 119 dispatcher->Add<ElementToggleCommand>( "/session/*/element/*/toggle"); | 102 dispatcher->Add<ElementToggleCommand>( "/session/*/element/*/toggle"); |
| 120 dispatcher->Add<ElementValueCommand>( "/session/*/element/*/value"); | 103 dispatcher->Add<ElementValueCommand>( "/session/*/element/*/value"); |
| 121 | 104 |
| 122 // Mouse Commands | 105 // Mouse Commands |
| 123 dispatcher->Add<ClickCommand>("/session/*/element/*/click"); | 106 dispatcher->Add<ClickCommand>("/session/*/element/*/click"); |
| 124 dispatcher->Add<DragCommand>( "/session/*/element/*/drag"); | 107 dispatcher->Add<DragCommand>( "/session/*/element/*/drag"); |
| 125 dispatcher->Add<HoverCommand>("/session/*/element/*/hover"); | 108 dispatcher->Add<HoverCommand>("/session/*/element/*/hover"); |
| 126 | 109 |
| 110 // All session based commands should be listed after the element based |
| 111 // commands to avoid potential mapping conflicts from an overzealous |
| 112 // wildcard match. For example, /session/*/title maps to the handler to |
| 113 // fetch the page title. If mapped first, this would overwrite the handler |
| 114 // for /session/*/element/*/attribute/title, which should fetch the title |
| 115 // attribute of the element. |
| 116 dispatcher->Add<BackCommand>( "/session/*/back"); |
| 117 dispatcher->Add<ExecuteCommand>( "/session/*/execute"); |
| 118 dispatcher->Add<ForwardCommand>( "/session/*/forward"); |
| 119 dispatcher->Add<SwitchFrameCommand>( "/session/*/frame"); |
| 120 dispatcher->Add<RefreshCommand>( "/session/*/refresh"); |
| 121 dispatcher->Add<SourceCommand>( "/session/*/source"); |
| 122 dispatcher->Add<SpeedCommand>( "/session/*/speed"); |
| 123 dispatcher->Add<TitleCommand>( "/session/*/title"); |
| 124 dispatcher->Add<URLCommand>( "/session/*/url"); |
| 125 dispatcher->Add<WindowCommand>( "/session/*/window"); |
| 126 dispatcher->Add<WindowHandleCommand>( "/session/*/window_handle"); |
| 127 dispatcher->Add<WindowHandlesCommand>("/session/*/window_handles"); |
| 128 dispatcher->Add<ImplicitWaitCommand>( "/session/*/timeouts/implicit_wait"); |
| 129 |
| 130 // Cookie functions. |
| 131 dispatcher->Add<CookieCommand>( "/session/*/cookie"); |
| 132 dispatcher->Add<NamedCookieCommand>("/session/*/cookie/*"); |
| 133 |
| 127 // Commands that have not been implemented yet. We list these out explicitly | 134 // Commands that have not been implemented yet. We list these out explicitly |
| 128 // so that tests that attempt to use them fail with a meaningful error. | 135 // so that tests that attempt to use them fail with a meaningful error. |
| 129 dispatcher->SetNotImplemented("/session/*/execute_async"); | 136 dispatcher->SetNotImplemented("/session/*/execute_async"); |
| 130 dispatcher->SetNotImplemented("/session/*/timeouts/async_script"); | 137 dispatcher->SetNotImplemented("/session/*/timeouts/async_script"); |
| 131 dispatcher->SetNotImplemented("/session/*/screenshot"); | 138 dispatcher->SetNotImplemented("/session/*/screenshot"); |
| 132 | 139 |
| 133 // Since the /session/* is a wild card that would match the above URIs, this | 140 // Since the /session/* is a wild card that would match the above URIs, this |
| 134 // line MUST be the last registered URI with the server. | 141 // line MUST be the last registered URI with the server. |
| 135 dispatcher->Add<SessionWithID>("/session/*"); | 142 dispatcher->Add<SessionWithID>("/session/*"); |
| 136 } | 143 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 246 |
| 240 // Run until we receive command to shutdown. | 247 // Run until we receive command to shutdown. |
| 241 shutdown_event.Wait(); | 248 shutdown_event.Wait(); |
| 242 | 249 |
| 243 // We should not reach here since the service should never quit. | 250 // We should not reach here since the service should never quit. |
| 244 // TODO(jmikhail): register a listener for SIGTERM and break the | 251 // TODO(jmikhail): register a listener for SIGTERM and break the |
| 245 // message loop gracefully. | 252 // message loop gracefully. |
| 246 mg_stop(ctx); | 253 mg_stop(ctx); |
| 247 return (EXIT_SUCCESS); | 254 return (EXIT_SUCCESS); |
| 248 } | 255 } |
| OLD | NEW |