Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(846)

Side by Side Diff: headless/app/headless_shell.cc

Issue 2626823003: [headless] Add default browser context to HeadlessBrowser. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 processed_page_ready_(false), 68 processed_page_ready_(false),
69 browser_context_(nullptr), 69 browser_context_(nullptr),
70 weak_factory_(this) {} 70 weak_factory_(this) {}
71 ~HeadlessShell() override {} 71 ~HeadlessShell() override {}
72 72
73 void OnStart(HeadlessBrowser* browser) { 73 void OnStart(HeadlessBrowser* browser) {
74 browser_ = browser; 74 browser_ = browser;
75 75
76 HeadlessBrowserContext::Builder context_builder = 76 HeadlessBrowserContext::Builder context_builder =
77 browser_->CreateBrowserContextBuilder(); 77 browser_->CreateBrowserContextBuilder();
78 // TODO(eseckler): These switches should also affect BrowserContexts that
79 // are created via DevTools later.
78 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 80 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
79 switches::kDeterministicFetch)) { 81 switches::kDeterministicFetch)) {
80 deterministic_dispatcher_.reset( 82 deterministic_dispatcher_.reset(
81 new DeterministicDispatcher(browser_->BrowserIOThread())); 83 new DeterministicDispatcher(browser_->BrowserIOThread()));
82 84
83 ProtocolHandlerMap protocol_handlers; 85 ProtocolHandlerMap protocol_handlers;
84 protocol_handlers[url::kHttpScheme] = 86 protocol_handlers[url::kHttpScheme] =
85 base::MakeUnique<DeterministicHttpProtocolHandler>( 87 base::MakeUnique<DeterministicHttpProtocolHandler>(
86 deterministic_dispatcher_.get(), browser->BrowserIOThread()); 88 deterministic_dispatcher_.get(), browser->BrowserIOThread());
87 protocol_handlers[url::kHttpsScheme] = 89 protocol_handlers[url::kHttpsScheme] =
88 base::MakeUnique<DeterministicHttpProtocolHandler>( 90 base::MakeUnique<DeterministicHttpProtocolHandler>(
89 deterministic_dispatcher_.get(), browser->BrowserIOThread()); 91 deterministic_dispatcher_.get(), browser->BrowserIOThread());
90 92
91 context_builder.SetProtocolHandlers(std::move(protocol_handlers)); 93 context_builder.SetProtocolHandlers(std::move(protocol_handlers));
92 } 94 }
93 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 95 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
94 switches::kHideScrollbars)) { 96 switches::kHideScrollbars)) {
95 context_builder.SetOverrideWebPreferencesCallback( 97 context_builder.SetOverrideWebPreferencesCallback(
96 base::Bind([](WebPreferences* preferences) { 98 base::Bind([](WebPreferences* preferences) {
97 preferences->hide_scrollbars = true; 99 preferences->hide_scrollbars = true;
98 })); 100 }));
99 } 101 }
100 browser_context_ = context_builder.Build(); 102 browser_context_ = context_builder.Build();
103 browser_->SetDefaultBrowserContext(browser_context_);
101 104
102 HeadlessWebContents::Builder builder( 105 HeadlessWebContents::Builder builder(
103 browser_context_->CreateWebContentsBuilder()); 106 browser_context_->CreateWebContentsBuilder());
104 base::CommandLine::StringVector args = 107 base::CommandLine::StringVector args =
105 base::CommandLine::ForCurrentProcess()->GetArgs(); 108 base::CommandLine::ForCurrentProcess()->GetArgs();
106 109
107 // TODO(alexclarke): Should we navigate to about:blank first if using 110 // TODO(alexclarke): Should we navigate to about:blank first if using
108 // virtual time? 111 // virtual time?
109 if (!args.empty() && !args[0].empty()) 112 if (!args.empty() && !args[0].empty())
110 builder.SetInitialURL(GURL(args[0])); 113 builder.SetInitialURL(GURL(args[0]));
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 } 474 }
472 builder.SetWindowSize(parsed_window_size); 475 builder.SetWindowSize(parsed_window_size);
473 } 476 }
474 477
475 return HeadlessBrowserMain( 478 return HeadlessBrowserMain(
476 builder.Build(), 479 builder.Build(),
477 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); 480 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell)));
478 } 481 }
479 482
480 } // namespace headless 483 } // namespace headless
OLDNEW
« no previous file with comments | « no previous file | headless/lib/browser/headless_browser_impl.h » ('j') | headless/lib/browser/headless_browser_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698