| OLD | NEW | 
|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> | 
| 6 #include <sstream> | 6 #include <sstream> | 
| 7 #include <string> | 7 #include <string> | 
| 8 #include <utility> | 8 #include <utility> | 
| 9 | 9 | 
| 10 #include "base/base64.h" | 10 #include "base/base64.h" | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 61 | 61 | 
| 62 HeadlessShell::~HeadlessShell() {} | 62 HeadlessShell::~HeadlessShell() {} | 
| 63 | 63 | 
| 64 void HeadlessShell::OnStart(HeadlessBrowser* browser) { | 64 void HeadlessShell::OnStart(HeadlessBrowser* browser) { | 
| 65   browser_ = browser; | 65   browser_ = browser; | 
| 66 | 66 | 
| 67   HeadlessBrowserContext::Builder context_builder = | 67   HeadlessBrowserContext::Builder context_builder = | 
| 68       browser_->CreateBrowserContextBuilder(); | 68       browser_->CreateBrowserContextBuilder(); | 
| 69   // TODO(eseckler): These switches should also affect BrowserContexts that | 69   // TODO(eseckler): These switches should also affect BrowserContexts that | 
| 70   // are created via DevTools later. | 70   // are created via DevTools later. | 
|  | 71   DeterministicHttpProtocolHandler* http_handler; | 
|  | 72   DeterministicHttpProtocolHandler* https_handler; | 
| 71   if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 73   if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| 72           switches::kDeterministicFetch)) { | 74           switches::kDeterministicFetch)) { | 
| 73     deterministic_dispatcher_.reset( | 75     deterministic_dispatcher_.reset( | 
| 74         new DeterministicDispatcher(browser_->BrowserIOThread())); | 76         new DeterministicDispatcher(browser_->BrowserIOThread())); | 
| 75 | 77 | 
| 76     ProtocolHandlerMap protocol_handlers; | 78     ProtocolHandlerMap protocol_handlers; | 
| 77     protocol_handlers[url::kHttpScheme] = | 79     protocol_handlers[url::kHttpScheme] = | 
| 78         base::MakeUnique<DeterministicHttpProtocolHandler>( | 80         base::MakeUnique<DeterministicHttpProtocolHandler>( | 
| 79             deterministic_dispatcher_.get(), browser->BrowserIOThread()); | 81             deterministic_dispatcher_.get(), browser->BrowserIOThread()); | 
|  | 82     http_handler = static_cast<DeterministicHttpProtocolHandler*>( | 
|  | 83         protocol_handlers[url::kHttpScheme].get()); | 
| 80     protocol_handlers[url::kHttpsScheme] = | 84     protocol_handlers[url::kHttpsScheme] = | 
| 81         base::MakeUnique<DeterministicHttpProtocolHandler>( | 85         base::MakeUnique<DeterministicHttpProtocolHandler>( | 
| 82             deterministic_dispatcher_.get(), browser->BrowserIOThread()); | 86             deterministic_dispatcher_.get(), browser->BrowserIOThread()); | 
|  | 87     https_handler = static_cast<DeterministicHttpProtocolHandler*>( | 
|  | 88         protocol_handlers[url::kHttpsScheme].get()); | 
| 83 | 89 | 
| 84     context_builder.SetProtocolHandlers(std::move(protocol_handlers)); | 90     context_builder.SetProtocolHandlers(std::move(protocol_handlers)); | 
| 85   } | 91   } | 
| 86   browser_context_ = context_builder.Build(); | 92   browser_context_ = context_builder.Build(); | 
|  | 93   if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 
|  | 94           switches::kDeterministicFetch)) { | 
|  | 95     http_handler->SetHeadlessBrowserContext(browser_context_); | 
|  | 96     https_handler->SetHeadlessBrowserContext(browser_context_); | 
|  | 97   } | 
| 87   browser_->SetDefaultBrowserContext(browser_context_); | 98   browser_->SetDefaultBrowserContext(browser_context_); | 
| 88 | 99 | 
| 89   HeadlessWebContents::Builder builder( | 100   HeadlessWebContents::Builder builder( | 
| 90       browser_context_->CreateWebContentsBuilder()); | 101       browser_context_->CreateWebContentsBuilder()); | 
| 91   base::CommandLine::StringVector args = | 102   base::CommandLine::StringVector args = | 
| 92       base::CommandLine::ForCurrentProcess()->GetArgs(); | 103       base::CommandLine::ForCurrentProcess()->GetArgs(); | 
| 93 | 104 | 
| 94   // TODO(alexclarke): Should we navigate to about:blank first if using | 105   // TODO(alexclarke): Should we navigate to about:blank first if using | 
| 95   // virtual time? | 106   // virtual time? | 
| 96   if (args.empty()) | 107   if (args.empty()) | 
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 622     if (net::HttpUtil::IsValidHeaderValue(ua)) | 633     if (net::HttpUtil::IsValidHeaderValue(ua)) | 
| 623       builder.SetUserAgent(ua); | 634       builder.SetUserAgent(ua); | 
| 624   } | 635   } | 
| 625 | 636 | 
| 626   return HeadlessBrowserMain( | 637   return HeadlessBrowserMain( | 
| 627       builder.Build(), | 638       builder.Build(), | 
| 628       base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); | 639       base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); | 
| 629 } | 640 } | 
| 630 | 641 | 
| 631 }  // namespace headless | 642 }  // namespace headless | 
| OLD | NEW | 
|---|