| 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 <iostream> | 5 #include <iostream> | 
| 6 #include <memory> | 6 #include <memory> | 
| 7 #include <string> | 7 #include <string> | 
| 8 | 8 | 
| 9 #include "base/base64.h" | 9 #include "base/base64.h" | 
| 10 #include "base/bind.h" | 10 #include "base/bind.h" | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 49   HeadlessShell() | 49   HeadlessShell() | 
| 50       : browser_(nullptr), | 50       : browser_(nullptr), | 
| 51         devtools_client_(HeadlessDevToolsClient::Create()), | 51         devtools_client_(HeadlessDevToolsClient::Create()), | 
| 52         web_contents_(nullptr), | 52         web_contents_(nullptr), | 
| 53         processed_page_ready_(false) {} | 53         processed_page_ready_(false) {} | 
| 54   ~HeadlessShell() override {} | 54   ~HeadlessShell() override {} | 
| 55 | 55 | 
| 56   void OnStart(HeadlessBrowser* browser) { | 56   void OnStart(HeadlessBrowser* browser) { | 
| 57     browser_ = browser; | 57     browser_ = browser; | 
| 58 | 58 | 
|  | 59     HeadlessWebContents::Builder builder(browser_->CreateWebContentsBuilder()); | 
| 59     base::CommandLine::StringVector args = | 60     base::CommandLine::StringVector args = | 
| 60         base::CommandLine::ForCurrentProcess()->GetArgs(); | 61         base::CommandLine::ForCurrentProcess()->GetArgs(); | 
| 61 | 62 | 
| 62     const char kDefaultUrl[] = "about:blank"; | 63     if (!args.empty() && !args[0].empty()) | 
| 63     if (args.empty() || args[0].empty()) { | 64       builder.SetInitialURL(GURL(args[0])); | 
| 64       url_ = GURL(kDefaultUrl); |  | 
| 65     } else { |  | 
| 66       url_ = GURL(args[0]); |  | 
| 67     } |  | 
| 68 | 65 | 
| 69     web_contents_ = browser->CreateWebContents(url_, gfx::Size(800, 600)); | 66     web_contents_ = builder.Build(); | 
| 70     if (!web_contents_) { | 67     if (!web_contents_) { | 
| 71       LOG(ERROR) << "Navigation failed"; | 68       LOG(ERROR) << "Navigation failed"; | 
| 72       browser_->Shutdown(); | 69       browser_->Shutdown(); | 
| 73       return; | 70       return; | 
| 74     } | 71     } | 
| 75     web_contents_->AddObserver(this); | 72     web_contents_->AddObserver(this); | 
| 76   } | 73   } | 
| 77 | 74 | 
| 78   void Shutdown() { | 75   void Shutdown() { | 
| 79     if (!web_contents_) | 76     if (!web_contents_) | 
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 333 | 330 | 
| 334   if (command_line.HasSwitch(switches::kHostResolverRules)) { | 331   if (command_line.HasSwitch(switches::kHostResolverRules)) { | 
| 335     builder.SetHostResolverRules( | 332     builder.SetHostResolverRules( | 
| 336         command_line.GetSwitchValueASCII(switches::kHostResolverRules)); | 333         command_line.GetSwitchValueASCII(switches::kHostResolverRules)); | 
| 337   } | 334   } | 
| 338 | 335 | 
| 339   return HeadlessBrowserMain( | 336   return HeadlessBrowserMain( | 
| 340       builder.Build(), | 337       builder.Build(), | 
| 341       base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); | 338       base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); | 
| 342 } | 339 } | 
| OLD | NEW | 
|---|